-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
c65c55c
commit 2eb4461
Showing
4 changed files
with
88 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
PoolSwapTest swapRouter = PoolSwapTest(0x01); | ||
|
||
// slippage tolerance to allow for unlimited price impact | ||
uint160 public constant MIN_PRICE_LIMIT = TickMath.MIN_SQRT_RATIO + 1; | ||
uint160 public constant MAX_PRICE_LIMIT = TickMath.MAX_SQRT_RATIO - 1; | ||
|
||
address token0 = address(0x11); | ||
address token1 = address(0x22); | ||
address hookAddr = address(0x33); | ||
|
||
PoolKey memory pool = PoolKey({ | ||
currency0: Currency.wrap(token0), | ||
currency1: Currency.wrap(token1), | ||
fee: 3000, | ||
tickSpacing: 60, | ||
hooks: IHooks(hookAddr) | ||
}); | ||
|
||
// approve tokens to the swap router | ||
IERC20(token0).approve(address(swapRouter), type(uint256).max); | ||
IERC20(token1).approve(address(swapRouter), type(uint256).max); | ||
|
||
// ---------------------------- // | ||
// Swap 1e18 token0 into token1 | ||
// ---------------------------- // | ||
bool zeroForOne = true; | ||
IPoolManager.SwapParams memory params = IPoolManager.SwapParams({ | ||
zeroForOne: zeroForOne, | ||
amountSpecified: 1e18, | ||
sqrtPriceLimitX96: zeroForOne ? MIN_PRICE_LIMIT : MAX_PRICE_LIMIT // unlimited impact | ||
}); | ||
|
||
// in v4, users have the option to receieve native ERC20s or wrapped ERC1155 tokens | ||
// here, we'll take the ERC20s | ||
PoolSwapTest.TestSettings memory testSettings = | ||
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true}); | ||
|
||
bytes memory hookData = new bytes(0); // no hook data on the hookless pool | ||
swapRouter.swap(key, params, testSettings, hookData); |
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