-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export ALCHEMY_KEY=XXXXX | ||
export ALCHEMY_KEY_ARBITRUM=YYYYY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.15; | ||
|
||
address constant WETH = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; | ||
address constant DAI = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1; | ||
address constant USDC = 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8; | ||
address constant ZERO_ADDRESS = address(0); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
import "foundry-huff/HuffDeployer.sol"; | ||
import "forge-std/Test.sol"; | ||
import "./Utils.sol"; | ||
import "./calls/CallNvm.sol"; | ||
import "./calls/GMXLong.sol"; | ||
import "./calls/IGMX.sol"; | ||
import "./ConstantsArbitrum.sol"; | ||
|
||
contract GMXTest is Test { | ||
address nvm; | ||
address doubleSwapHuff; | ||
address owner; | ||
uint256 balance = 1000 * 1e6; | ||
CallNvm callNvm; | ||
GMXLong gmxLong; | ||
bytes gmxLongNvmBytecode; | ||
|
||
// ===== Set up ===== | ||
function setUp() public { | ||
vm.createSelectFork(vm.rpcUrl("arbi")); | ||
owner = address(this); | ||
nvm = HuffDeployer.deploy("NVM"); | ||
callNvm = new CallNvm(); | ||
gmxLong = new GMXLong(); | ||
gmxLongNvmBytecode = type(GMXLong).runtimeCode; | ||
} | ||
|
||
receive() external payable {} | ||
|
||
function testGMXLongNative() public { | ||
// PositionRouter | ||
IGMXPositionRouter positionRouter = IGMXPositionRouter( | ||
0x3D6bA331e3D9702C5e8A8d254e5d8a285F223aba | ||
); | ||
// Admin of the Position Router | ||
address positionRouterAdmin = address( | ||
0x5F799f365Fa8A2B60ac0429C48B153cA5a6f0Cf8 | ||
); | ||
// Deal USDC and ETH to contract that will open a long position | ||
deal(USDC, address(gmxLong), 1000000000 * 10**6); | ||
deal(address(gmxLong), 1000000000 * 10**18); | ||
// opens long position | ||
gmxLong.gmxLong(); | ||
// Keeper that will execute the requests | ||
address keeper = address(123); | ||
// balance before for the keeper | ||
uint256 balanceBefore = keeper.balance; | ||
// Set keeper address as a keeper for the positionRouter | ||
// Only admin fuction | ||
changePrank(positionRouterAdmin); | ||
positionRouter.setPositionKeeper(keeper, true); | ||
// Execute transaction | ||
// The transaction is identified by a requestKey | ||
changePrank(keeper); | ||
bytes32 key = positionRouter.getRequestKey( | ||
address(gmxLong), | ||
uint256(1) | ||
); | ||
positionRouter.executeIncreasePosition(key, payable(keeper)); | ||
// Balance of the keeper after | ||
uint256 balanceAfter = keeper.balance; | ||
// Verify keeper received fees | ||
assertEq(balanceAfter > balanceBefore, true); | ||
} | ||
|
||
function testGMXLongNvm() public { | ||
// PositionRouter | ||
IGMXPositionRouter positionRouter = IGMXPositionRouter( | ||
0x3D6bA331e3D9702C5e8A8d254e5d8a285F223aba | ||
); | ||
// Admin of the Position Router | ||
address positionRouterAdmin = address( | ||
0x5F799f365Fa8A2B60ac0429C48B153cA5a6f0Cf8 | ||
); | ||
// Deal USDC and ETH to contract that will open a long position | ||
deal(USDC, address(callNvm), 1000000000 * 10**6); | ||
deal(address(callNvm), 1000000000 * 10**18); | ||
// replace "gmxLong" selector and bypass calldata size check | ||
bytes memory finalBytecode = Utils | ||
.replaceSelectorBypassCalldataSizeCheck( | ||
gmxLongNvmBytecode, | ||
hex"9507c78f" | ||
); | ||
// CallNvm | ||
callNvm.callNvm(nvm, finalBytecode); | ||
// Keeper that will execute the requests | ||
address keeper = address(123); | ||
// balance before for the keeper | ||
uint256 balanceBefore = keeper.balance; | ||
// Set keeper address as a keeper for the positionRouter | ||
// Only admin fuction | ||
changePrank(positionRouterAdmin); | ||
positionRouter.setPositionKeeper(keeper, true); | ||
// Execute transaction | ||
// The transaction is identified by a requestKey | ||
changePrank(keeper); | ||
bytes32 key = positionRouter.getRequestKey( | ||
address(callNvm), | ||
uint256(1) | ||
); | ||
positionRouter.executeIncreasePosition(key, payable(keeper)); | ||
// Balance of the keeper after | ||
uint256 balanceAfter = keeper.balance; | ||
// Verify keeper received fees | ||
assertEq(balanceAfter > balanceBefore, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.15; | ||
import "./IERC20.sol"; | ||
|
||
import "./IGMX.sol"; | ||
|
||
import "./../ConstantsArbitrum.sol"; | ||
|
||
contract GMXLong { | ||
|
||
uint256 private constant amountUSDC = 1000 * 10**6; | ||
IGMXRouter private constant GMXRouter = IGMXRouter(0xaBBc5F99639c9B6bCb58544ddf04EFA6802F4064); | ||
IGMXPositionRouter private constant positionRouter = IGMXPositionRouter(0x3D6bA331e3D9702C5e8A8d254e5d8a285F223aba); | ||
|
||
constructor(){} | ||
|
||
function gmxLong() public { | ||
IERC20(USDC).approve(address(GMXRouter), type(uint256).max); | ||
IERC20(USDC).approve(address(positionRouter), type(uint256).max); | ||
GMXRouter.approvePlugin(address(positionRouter)); | ||
// USD amounts are multiplied by (10 ** 30) | ||
address[] memory path = new address[](2); | ||
path[0] = USDC; | ||
path[1] = WETH; | ||
positionRouter.createIncreasePosition{value: 3000_000_000_000_000 }( | ||
path, // [tokenIn, collateralToken] _path | ||
WETH, // _indexToken (token we want to long) | ||
100 * 10**6, // _amountIn | ||
0, // minOut | ||
600 * 10**30, // _sizeDelta the USD value of the change in position size | ||
true, // _isLong | ||
3000 * 10**30, // _acceptablePrice | ||
3000_000_000_000_000, // _executionFee | ||
bytes32(0)); // _referralCode | ||
} | ||
receive() external payable {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.15; | ||
|
||
interface IGMXPositionRouter { | ||
function createIncreasePosition( | ||
address[] memory _path, | ||
address _indexToken, | ||
uint256 _amountIn, | ||
uint256 _minOut, | ||
uint256 _sizeDelta, | ||
bool _isLong, | ||
uint256 _acceptablePrice, | ||
uint256 _executionFee, | ||
bytes32 _referralCode | ||
) external payable; | ||
|
||
function executeIncreasePosition(bytes32 _key, address payable _executionFeeReceiver) external returns (bool); | ||
function getRequestKey(address _account, uint256 _index) external pure returns (bytes32); | ||
function setPositionKeeper(address _account, bool _isActive) external; | ||
} | ||
|
||
interface IGMXRouter { | ||
function approvePlugin(address _plugin) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters