|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.13; |
| 3 | +import "foundry-huff/HuffDeployer.sol"; |
| 4 | +import "forge-std/Test.sol"; |
| 5 | +import "./Utils.sol"; |
| 6 | +import "./calls/CallNvm.sol"; |
| 7 | +import "./calls/GMXLong.sol"; |
| 8 | +import "./calls/IGMX.sol"; |
| 9 | +import "./ConstantsArbitrum.sol"; |
| 10 | + |
| 11 | +contract GMXTest is Test { |
| 12 | + address nvm; |
| 13 | + address doubleSwapHuff; |
| 14 | + address owner; |
| 15 | + uint256 balance = 1000 * 1e6; |
| 16 | + CallNvm callNvm; |
| 17 | + GMXLong gmxLong; |
| 18 | + bytes gmxLongNvmBytecode; |
| 19 | + |
| 20 | + // ===== Set up ===== |
| 21 | + function setUp() public { |
| 22 | + vm.createSelectFork(vm.rpcUrl("arbi")); |
| 23 | + owner = address(this); |
| 24 | + nvm = HuffDeployer.deploy("NVM"); |
| 25 | + callNvm = new CallNvm(); |
| 26 | + gmxLong = new GMXLong(); |
| 27 | + gmxLongNvmBytecode = type(GMXLong).runtimeCode; |
| 28 | + } |
| 29 | + |
| 30 | + receive() external payable {} |
| 31 | + |
| 32 | + function testGMXLongNative() public { |
| 33 | + // PositionRouter |
| 34 | + IGMXPositionRouter positionRouter = IGMXPositionRouter( |
| 35 | + 0x3D6bA331e3D9702C5e8A8d254e5d8a285F223aba |
| 36 | + ); |
| 37 | + // Admin of the Position Router |
| 38 | + address positionRouterAdmin = address( |
| 39 | + 0x5F799f365Fa8A2B60ac0429C48B153cA5a6f0Cf8 |
| 40 | + ); |
| 41 | + // Deal USDC and ETH to contract that will open a long position |
| 42 | + deal(USDC, address(gmxLong), 1000000000 * 10**6); |
| 43 | + deal(address(gmxLong), 1000000000 * 10**18); |
| 44 | + // opens long position |
| 45 | + gmxLong.gmxLong(); |
| 46 | + // Keeper that will execute the requests |
| 47 | + address keeper = address(123); |
| 48 | + // balance before for the keeper |
| 49 | + uint256 balanceBefore = keeper.balance; |
| 50 | + // Set keeper address as a keeper for the positionRouter |
| 51 | + // Only admin fuction |
| 52 | + changePrank(positionRouterAdmin); |
| 53 | + positionRouter.setPositionKeeper(keeper, true); |
| 54 | + // Execute transaction |
| 55 | + // The transaction is identified by a requestKey |
| 56 | + changePrank(keeper); |
| 57 | + bytes32 key = positionRouter.getRequestKey( |
| 58 | + address(gmxLong), |
| 59 | + uint256(1) |
| 60 | + ); |
| 61 | + positionRouter.executeIncreasePosition(key, payable(keeper)); |
| 62 | + // Balance of the keeper after |
| 63 | + uint256 balanceAfter = keeper.balance; |
| 64 | + // Verify keeper received fees |
| 65 | + assertEq(balanceAfter > balanceBefore, true); |
| 66 | + } |
| 67 | + |
| 68 | + function testGMXLongNvm() public { |
| 69 | + // PositionRouter |
| 70 | + IGMXPositionRouter positionRouter = IGMXPositionRouter( |
| 71 | + 0x3D6bA331e3D9702C5e8A8d254e5d8a285F223aba |
| 72 | + ); |
| 73 | + // Admin of the Position Router |
| 74 | + address positionRouterAdmin = address( |
| 75 | + 0x5F799f365Fa8A2B60ac0429C48B153cA5a6f0Cf8 |
| 76 | + ); |
| 77 | + // Deal USDC and ETH to contract that will open a long position |
| 78 | + deal(USDC, address(callNvm), 1000000000 * 10**6); |
| 79 | + deal(address(callNvm), 1000000000 * 10**18); |
| 80 | + // replace "gmxLong" selector and bypass calldata size check |
| 81 | + bytes memory finalBytecode = Utils |
| 82 | + .replaceSelectorBypassCalldataSizeCheck( |
| 83 | + gmxLongNvmBytecode, |
| 84 | + hex"9507c78f" |
| 85 | + ); |
| 86 | + // CallNvm |
| 87 | + callNvm.callNvm(nvm, finalBytecode); |
| 88 | + // Keeper that will execute the requests |
| 89 | + address keeper = address(123); |
| 90 | + // balance before for the keeper |
| 91 | + uint256 balanceBefore = keeper.balance; |
| 92 | + // Set keeper address as a keeper for the positionRouter |
| 93 | + // Only admin fuction |
| 94 | + changePrank(positionRouterAdmin); |
| 95 | + positionRouter.setPositionKeeper(keeper, true); |
| 96 | + // Execute transaction |
| 97 | + // The transaction is identified by a requestKey |
| 98 | + changePrank(keeper); |
| 99 | + bytes32 key = positionRouter.getRequestKey( |
| 100 | + address(callNvm), |
| 101 | + uint256(1) |
| 102 | + ); |
| 103 | + positionRouter.executeIncreasePosition(key, payable(keeper)); |
| 104 | + // Balance of the keeper after |
| 105 | + uint256 balanceAfter = keeper.balance; |
| 106 | + // Verify keeper received fees |
| 107 | + assertEq(balanceAfter > balanceBefore, true); |
| 108 | + } |
| 109 | +} |
0 commit comments