From 6719e56aef0d29f3c8ce3a45af12b669c81c8f53 Mon Sep 17 00:00:00 2001 From: prosperring Date: Mon, 20 May 2024 00:08:16 +0300 Subject: [PATCH] tests: Make and use a common SWAP_PARAMS in Deployers.sol Resolves Issue Uniswap#390 --- .forge-snapshots/ERC6909Claims approve.snap | 2 +- .forge-snapshots/ERC6909Claims burn.snap | 2 +- .forge-snapshots/ERC6909Claims mint.snap | 2 +- .forge-snapshots/ERC6909Claims transfer.snap | 2 +- ...RC6909Claims transferFrom as operator.snap | 2 +- ...6909Claims transferFrom with approval.snap | 2 +- ...s transferFrom with infinite approval.snap | 2 +- ...o already existing position with salt.snap | 2 +- .forge-snapshots/addLiquidity CA fee.snap | 2 +- .../addLiquidity with empty hook.snap | 2 +- .../addLiquidity with native token.snap | 2 +- ...new liquidity to a position with salt.snap | 2 +- .forge-snapshots/donate gas with 1 token.snap | 2 +- .../donate gas with 2 tokens.snap | 2 +- .../erc20 collect protocol fees.snap | 2 +- .forge-snapshots/initialize.snap | 2 +- .../native collect protocol fees.snap | 2 +- .forge-snapshots/removeLiquidity CA fee.snap | 2 +- .../removeLiquidity with empty hook.snap | 2 +- .../removeLiquidity with native token.snap | 2 +- .forge-snapshots/set protocol fee.snap | 2 +- ...dLiquidity second addition same range.snap | 2 +- .forge-snapshots/simple addLiquidity.snap | 2 +- ...emoveLiquidity some liquidity remains.snap | 2 +- .forge-snapshots/simple removeLiquidity.snap | 2 +- .forge-snapshots/simple swap with native.snap | 2 +- .forge-snapshots/simple swap.snap | 2 +- .../swap CA custom curve + swap noop.snap | 2 +- .../swap CA fee on unspecified.snap | 2 +- ...p against liquidity with native token.snap | 2 +- .forge-snapshots/swap against liquidity.snap | 2 +- .../swap burn 6909 for input.snap | 2 +- .../swap burn native 6909 for input.snap | 2 +- .../swap mint native output as 6909.snap | 2 +- .../swap mint output as 6909.snap | 2 +- ...wap skips hook call if hook is caller.snap | 2 +- .forge-snapshots/swap with dynamic fee.snap | 2 +- .forge-snapshots/swap with hooks.snap | 2 +- .../swap with lp fee and protocol fee.snap | 2 +- .../swap with return dynamic fee.snap | 2 +- .../update dynamic fee in before swap.snap | 2 +- test/DynamicFees.t.sol | 24 ++---- test/DynamicReturnFees.t.sol | 4 +- test/PoolManager.t.sol | 79 +++++-------------- test/SkipCallsTestHook.t.sol | 13 ++- test/Sync.t.sol | 5 +- test/utils/Deployers.sol | 2 + 47 files changed, 77 insertions(+), 132 deletions(-) diff --git a/.forge-snapshots/ERC6909Claims approve.snap b/.forge-snapshots/ERC6909Claims approve.snap index 57c3a1024..f68d7577a 100644 --- a/.forge-snapshots/ERC6909Claims approve.snap +++ b/.forge-snapshots/ERC6909Claims approve.snap @@ -1 +1 @@ -46492 \ No newline at end of file +24984 \ No newline at end of file diff --git a/.forge-snapshots/ERC6909Claims burn.snap b/.forge-snapshots/ERC6909Claims burn.snap index 22d8221b1..e3d3894ec 100644 --- a/.forge-snapshots/ERC6909Claims burn.snap +++ b/.forge-snapshots/ERC6909Claims burn.snap @@ -1 +1 @@ -29428 \ No newline at end of file +3272 \ No newline at end of file diff --git a/.forge-snapshots/ERC6909Claims mint.snap b/.forge-snapshots/ERC6909Claims mint.snap index 7c9bc2025..6b0e52f4b 100644 --- a/.forge-snapshots/ERC6909Claims mint.snap +++ b/.forge-snapshots/ERC6909Claims mint.snap @@ -1 +1 @@ -46815 \ No newline at end of file +25307 \ No newline at end of file diff --git a/.forge-snapshots/ERC6909Claims transfer.snap b/.forge-snapshots/ERC6909Claims transfer.snap index e15c713ac..aa8628ae1 100644 --- a/.forge-snapshots/ERC6909Claims transfer.snap +++ b/.forge-snapshots/ERC6909Claims transfer.snap @@ -1 +1 @@ -52046 \ No newline at end of file +25738 \ No newline at end of file diff --git a/.forge-snapshots/ERC6909Claims transferFrom as operator.snap b/.forge-snapshots/ERC6909Claims transferFrom as operator.snap index 5b633e5a9..5b9758278 100644 --- a/.forge-snapshots/ERC6909Claims transferFrom as operator.snap +++ b/.forge-snapshots/ERC6909Claims transferFrom as operator.snap @@ -1 +1 @@ -54699 \ No newline at end of file +26239 \ No newline at end of file diff --git a/.forge-snapshots/ERC6909Claims transferFrom with approval.snap b/.forge-snapshots/ERC6909Claims transferFrom with approval.snap index e7a90f539..4d24db1ea 100644 --- a/.forge-snapshots/ERC6909Claims transferFrom with approval.snap +++ b/.forge-snapshots/ERC6909Claims transferFrom with approval.snap @@ -1 +1 @@ -60247 \ No newline at end of file +28987 \ No newline at end of file diff --git a/.forge-snapshots/ERC6909Claims transferFrom with infinite approval.snap b/.forge-snapshots/ERC6909Claims transferFrom with infinite approval.snap index b26ab21a9..d9a0e09bc 100644 --- a/.forge-snapshots/ERC6909Claims transferFrom with infinite approval.snap +++ b/.forge-snapshots/ERC6909Claims transferFrom with infinite approval.snap @@ -1 +1 @@ -57049 \ No newline at end of file +28589 \ No newline at end of file diff --git a/.forge-snapshots/add liquidity to already existing position with salt.snap b/.forge-snapshots/add liquidity to already existing position with salt.snap index ff76e7f86..303761c2f 100644 --- a/.forge-snapshots/add liquidity to already existing position with salt.snap +++ b/.forge-snapshots/add liquidity to already existing position with salt.snap @@ -1 +1 @@ -153643 \ No newline at end of file +62251 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity CA fee.snap b/.forge-snapshots/addLiquidity CA fee.snap index b4678d19b..84c1c0895 100644 --- a/.forge-snapshots/addLiquidity CA fee.snap +++ b/.forge-snapshots/addLiquidity CA fee.snap @@ -1 +1 @@ -331309 \ No newline at end of file +283829 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity with empty hook.snap b/.forge-snapshots/addLiquidity with empty hook.snap index c59df0298..975569ac1 100644 --- a/.forge-snapshots/addLiquidity with empty hook.snap +++ b/.forge-snapshots/addLiquidity with empty hook.snap @@ -1 +1 @@ -286302 \ No newline at end of file +255822 \ No newline at end of file diff --git a/.forge-snapshots/addLiquidity with native token.snap b/.forge-snapshots/addLiquidity with native token.snap index c5bed833e..bf1f82f3d 100644 --- a/.forge-snapshots/addLiquidity with native token.snap +++ b/.forge-snapshots/addLiquidity with native token.snap @@ -1 +1 @@ -143853 \ No newline at end of file +120613 \ No newline at end of file diff --git a/.forge-snapshots/create new liquidity to a position with salt.snap b/.forge-snapshots/create new liquidity to a position with salt.snap index cbb3de708..6f438ef2b 100644 --- a/.forge-snapshots/create new liquidity to a position with salt.snap +++ b/.forge-snapshots/create new liquidity to a position with salt.snap @@ -1 +1 @@ -301821 \ No newline at end of file +278329 \ No newline at end of file diff --git a/.forge-snapshots/donate gas with 1 token.snap b/.forge-snapshots/donate gas with 1 token.snap index 73919dff7..1c6f165dd 100644 --- a/.forge-snapshots/donate gas with 1 token.snap +++ b/.forge-snapshots/donate gas with 1 token.snap @@ -1 +1 @@ -107894 \ No newline at end of file +85150 \ No newline at end of file diff --git a/.forge-snapshots/donate gas with 2 tokens.snap b/.forge-snapshots/donate gas with 2 tokens.snap index 1b78c96c4..abcb7e3e0 100644 --- a/.forge-snapshots/donate gas with 2 tokens.snap +++ b/.forge-snapshots/donate gas with 2 tokens.snap @@ -1 +1 @@ -148384 \ No newline at end of file +119128 \ No newline at end of file diff --git a/.forge-snapshots/erc20 collect protocol fees.snap b/.forge-snapshots/erc20 collect protocol fees.snap index 55214724a..4b6c38bb6 100644 --- a/.forge-snapshots/erc20 collect protocol fees.snap +++ b/.forge-snapshots/erc20 collect protocol fees.snap @@ -1 +1 @@ -57275 \ No newline at end of file +24275 \ No newline at end of file diff --git a/.forge-snapshots/initialize.snap b/.forge-snapshots/initialize.snap index 74aa20508..41c14e996 100644 --- a/.forge-snapshots/initialize.snap +++ b/.forge-snapshots/initialize.snap @@ -1 +1 @@ -61862 \ No newline at end of file +39246 \ No newline at end of file diff --git a/.forge-snapshots/native collect protocol fees.snap b/.forge-snapshots/native collect protocol fees.snap index 03f835fb2..f27b67fa0 100644 --- a/.forge-snapshots/native collect protocol fees.snap +++ b/.forge-snapshots/native collect protocol fees.snap @@ -1 +1 @@ -59520 \ No newline at end of file +36048 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity CA fee.snap b/.forge-snapshots/removeLiquidity CA fee.snap index 082d59d10..1e2acfb73 100644 --- a/.forge-snapshots/removeLiquidity CA fee.snap +++ b/.forge-snapshots/removeLiquidity CA fee.snap @@ -1 +1 @@ -186775 \ No newline at end of file +111807 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity with empty hook.snap b/.forge-snapshots/removeLiquidity with empty hook.snap index e7fddfb22..2b4248a21 100644 --- a/.forge-snapshots/removeLiquidity with empty hook.snap +++ b/.forge-snapshots/removeLiquidity with empty hook.snap @@ -1 +1 @@ -123143 \ No newline at end of file +54675 \ No newline at end of file diff --git a/.forge-snapshots/removeLiquidity with native token.snap b/.forge-snapshots/removeLiquidity with native token.snap index 8b983838d..3a1f1a4d4 100644 --- a/.forge-snapshots/removeLiquidity with native token.snap +++ b/.forge-snapshots/removeLiquidity with native token.snap @@ -1 +1 @@ -119930 \ No newline at end of file +125202 \ No newline at end of file diff --git a/.forge-snapshots/set protocol fee.snap b/.forge-snapshots/set protocol fee.snap index ba1ce5094..dd09f687e 100644 --- a/.forge-snapshots/set protocol fee.snap +++ b/.forge-snapshots/set protocol fee.snap @@ -1 +1 @@ -32415 \ No newline at end of file +10043 \ No newline at end of file diff --git a/.forge-snapshots/simple addLiquidity second addition same range.snap b/.forge-snapshots/simple addLiquidity second addition same range.snap index ccf9f3450..057ed26bb 100644 --- a/.forge-snapshots/simple addLiquidity second addition same range.snap +++ b/.forge-snapshots/simple addLiquidity second addition same range.snap @@ -1 +1 @@ -104932 \ No newline at end of file +36092 \ No newline at end of file diff --git a/.forge-snapshots/simple addLiquidity.snap b/.forge-snapshots/simple addLiquidity.snap index 8f3accdaa..416307aef 100644 --- a/.forge-snapshots/simple addLiquidity.snap +++ b/.forge-snapshots/simple addLiquidity.snap @@ -1 +1 @@ -167424 \ No newline at end of file +143584 \ No newline at end of file diff --git a/.forge-snapshots/simple removeLiquidity some liquidity remains.snap b/.forge-snapshots/simple removeLiquidity some liquidity remains.snap index fc72404ca..e5679cc91 100644 --- a/.forge-snapshots/simple removeLiquidity some liquidity remains.snap +++ b/.forge-snapshots/simple removeLiquidity some liquidity remains.snap @@ -1 +1 @@ -98529 \ No newline at end of file +31401 \ No newline at end of file diff --git a/.forge-snapshots/simple removeLiquidity.snap b/.forge-snapshots/simple removeLiquidity.snap index 0eb1ac8de..9c69e48cb 100644 --- a/.forge-snapshots/simple removeLiquidity.snap +++ b/.forge-snapshots/simple removeLiquidity.snap @@ -1 +1 @@ -90569 \ No newline at end of file +33041 \ No newline at end of file diff --git a/.forge-snapshots/simple swap with native.snap b/.forge-snapshots/simple swap with native.snap index 4fc9f9feb..7a5a00592 100644 --- a/.forge-snapshots/simple swap with native.snap +++ b/.forge-snapshots/simple swap with native.snap @@ -1 +1 @@ -116827 \ No newline at end of file +93923 \ No newline at end of file diff --git a/.forge-snapshots/simple swap.snap b/.forge-snapshots/simple swap.snap index 7a20c6b3d..1f89c4630 100644 --- a/.forge-snapshots/simple swap.snap +++ b/.forge-snapshots/simple swap.snap @@ -1 +1 @@ -131988 \ No newline at end of file +108856 \ No newline at end of file diff --git a/.forge-snapshots/swap CA custom curve + swap noop.snap b/.forge-snapshots/swap CA custom curve + swap noop.snap index eecbcb0de..cce0e0541 100644 --- a/.forge-snapshots/swap CA custom curve + swap noop.snap +++ b/.forge-snapshots/swap CA custom curve + swap noop.snap @@ -1 +1 @@ -134432 \ No newline at end of file +85152 \ No newline at end of file diff --git a/.forge-snapshots/swap CA fee on unspecified.snap b/.forge-snapshots/swap CA fee on unspecified.snap index 27c7f51ac..b6d1f9360 100644 --- a/.forge-snapshots/swap CA fee on unspecified.snap +++ b/.forge-snapshots/swap CA fee on unspecified.snap @@ -1 +1 @@ -183126 \ No newline at end of file +117446 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity with native token.snap b/.forge-snapshots/swap against liquidity with native token.snap index 8550686dc..9d918bb19 100644 --- a/.forge-snapshots/swap against liquidity with native token.snap +++ b/.forge-snapshots/swap against liquidity with native token.snap @@ -1 +1 @@ -112548 \ No newline at end of file +61040 \ No newline at end of file diff --git a/.forge-snapshots/swap against liquidity.snap b/.forge-snapshots/swap against liquidity.snap index 14ee97dfc..54c6055de 100644 --- a/.forge-snapshots/swap against liquidity.snap +++ b/.forge-snapshots/swap against liquidity.snap @@ -1 +1 @@ -123891 \ No newline at end of file +58055 \ No newline at end of file diff --git a/.forge-snapshots/swap burn 6909 for input.snap b/.forge-snapshots/swap burn 6909 for input.snap index b19efd36d..d7bc9bc65 100644 --- a/.forge-snapshots/swap burn 6909 for input.snap +++ b/.forge-snapshots/swap burn 6909 for input.snap @@ -1 +1 @@ -135923 \ No newline at end of file +76059 \ No newline at end of file diff --git a/.forge-snapshots/swap burn native 6909 for input.snap b/.forge-snapshots/swap burn native 6909 for input.snap index dc06b6c6a..d60247374 100644 --- a/.forge-snapshots/swap burn native 6909 for input.snap +++ b/.forge-snapshots/swap burn native 6909 for input.snap @@ -1 +1 @@ -125140 \ No newline at end of file +71992 \ No newline at end of file diff --git a/.forge-snapshots/swap mint native output as 6909.snap b/.forge-snapshots/swap mint native output as 6909.snap index fa5caa1ba..0a6902012 100644 --- a/.forge-snapshots/swap mint native output as 6909.snap +++ b/.forge-snapshots/swap mint native output as 6909.snap @@ -1 +1 @@ -147180 \ No newline at end of file +123728 \ No newline at end of file diff --git a/.forge-snapshots/swap mint output as 6909.snap b/.forge-snapshots/swap mint output as 6909.snap index 1acf3c68f..87cdef25b 100644 --- a/.forge-snapshots/swap mint output as 6909.snap +++ b/.forge-snapshots/swap mint output as 6909.snap @@ -1 +1 @@ -163842 \ No newline at end of file +140162 \ No newline at end of file diff --git a/.forge-snapshots/swap skips hook call if hook is caller.snap b/.forge-snapshots/swap skips hook call if hook is caller.snap index b2d6ca0cd..8fa352d87 100644 --- a/.forge-snapshots/swap skips hook call if hook is caller.snap +++ b/.forge-snapshots/swap skips hook call if hook is caller.snap @@ -1 +1 @@ -222199 \ No newline at end of file +145411 \ No newline at end of file diff --git a/.forge-snapshots/swap with dynamic fee.snap b/.forge-snapshots/swap with dynamic fee.snap index 96c9f4d55..d6d4dc9fc 100644 --- a/.forge-snapshots/swap with dynamic fee.snap +++ b/.forge-snapshots/swap with dynamic fee.snap @@ -1 +1 @@ -148043 \ No newline at end of file +84659 \ No newline at end of file diff --git a/.forge-snapshots/swap with hooks.snap b/.forge-snapshots/swap with hooks.snap index 897a376b0..54c6055de 100644 --- a/.forge-snapshots/swap with hooks.snap +++ b/.forge-snapshots/swap with hooks.snap @@ -1 +1 @@ -123903 \ No newline at end of file +58055 \ No newline at end of file diff --git a/.forge-snapshots/swap with lp fee and protocol fee.snap b/.forge-snapshots/swap with lp fee and protocol fee.snap index 9efd3b6c3..89e21ab2a 100644 --- a/.forge-snapshots/swap with lp fee and protocol fee.snap +++ b/.forge-snapshots/swap with lp fee and protocol fee.snap @@ -1 +1 @@ -180223 \ No newline at end of file +144899 \ No newline at end of file diff --git a/.forge-snapshots/swap with return dynamic fee.snap b/.forge-snapshots/swap with return dynamic fee.snap index cb2abe163..68c0d7487 100644 --- a/.forge-snapshots/swap with return dynamic fee.snap +++ b/.forge-snapshots/swap with return dynamic fee.snap @@ -1 +1 @@ -155902 \ No newline at end of file +123006 \ No newline at end of file diff --git a/.forge-snapshots/update dynamic fee in before swap.snap b/.forge-snapshots/update dynamic fee in before swap.snap index 265212952..75b6dc86d 100644 --- a/.forge-snapshots/update dynamic fee in before swap.snap +++ b/.forge-snapshots/update dynamic fee in before swap.snap @@ -1 +1 @@ -158505 \ No newline at end of file +125609 \ No newline at end of file diff --git a/test/DynamicFees.t.sol b/test/DynamicFees.t.sol index 863daadc6..1c1cbee0e 100644 --- a/test/DynamicFees.t.sol +++ b/test/DynamicFees.t.sol @@ -113,13 +113,11 @@ contract TestDynamicFees is Test, Deployers, GasSnapshot { dynamicFeesHooks.setFee(1000001); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); vm.expectRevert(LPFeeLibrary.FeeTooLarge.selector); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); } function test_updateDynamicLPFee_beforeSwap_succeeds_gas() public { @@ -127,15 +125,13 @@ contract TestDynamicFees is Test, Deployers, GasSnapshot { dynamicFeesHooks.setFee(123); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); vm.expectEmit(true, true, true, true, address(manager)); emit Swap(key.toId(), address(swapRouter), -100, 98, 79228162514264329749955861424, 1e18, -1, 123); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); snapLastCall("update dynamic fee in before swap"); assertEq(_fetchPoolLPFee(key), 123); @@ -146,15 +142,13 @@ contract TestDynamicFees is Test, Deployers, GasSnapshot { dynamicFeesHooks.setFee(1000000); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); vm.expectEmit(true, true, true, true, address(manager)); emit Swap(key.toId(), address(swapRouter), -100, 0, SQRT_PRICE_1_1, 1e18, -1, 1000000); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); assertEq(_fetchPoolLPFee(key), 1000000); } @@ -164,15 +158,13 @@ contract TestDynamicFees is Test, Deployers, GasSnapshot { dynamicFeesHooks.setFee(500000); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); vm.expectEmit(true, true, true, true, address(manager)); emit Swap(key.toId(), address(swapRouter), -100, 49, 79228162514264333632135824623, 1e18, -1, 500000); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); assertEq(_fetchPoolLPFee(key), 500000); } @@ -264,15 +256,13 @@ contract TestDynamicFees is Test, Deployers, GasSnapshot { vm.prank(address(feeController)); manager.setProtocolFee(key, 1000); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); vm.expectEmit(true, true, true, true, address(manager)); emit Swap(key.toId(), address(swapRouter), -100, 98, 79228162514264329749955861424, 1e18, -1, 1122); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); assertEq(_fetchPoolLPFee(key), 123); } @@ -316,15 +306,13 @@ contract TestDynamicFees is Test, Deployers, GasSnapshot { dynamicFeesNoHooks.forcePoolFeeUpdate(key, 123); assertEq(_fetchPoolLPFee(key), 123); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); vm.expectEmit(true, true, true, true, address(manager)); emit Swap(key.toId(), address(swapRouter), -100, 98, 79228162514264329749955861424, 1e18, -1, 123); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); snapLastCall("swap with dynamic fee"); } diff --git a/test/DynamicReturnFees.t.sol b/test/DynamicReturnFees.t.sol index 2ea8d579e..9552a6ba2 100644 --- a/test/DynamicReturnFees.t.sol +++ b/test/DynamicReturnFees.t.sol @@ -94,15 +94,13 @@ contract TestDynamicReturnFees is Test, Deployers, GasSnapshot { dynamicReturnFeesHook.setFee(123); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); vm.expectEmit(true, true, true, true, address(manager)); emit Swap(key.toId(), address(swapRouter), -100, 98, 79228162514264329749955861424, 1e18, -1, 123); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); snapLastCall("swap with return dynamic fee"); assertEq(_fetchPoolSwapFee(key), 0); diff --git a/test/PoolManager.t.sol b/test/PoolManager.t.sol index ed61daed8..7bd5bb82a 100644 --- a/test/PoolManager.t.sol +++ b/test/PoolManager.t.sol @@ -547,9 +547,6 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { } function test_swap_succeedsIfInitialized() public { - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: true, settleUsingBurn: false}); @@ -558,21 +555,15 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { key.toId(), address(swapRouter), int128(-100), int128(98), 79228162514264329749955861424, 1e18, -1, 3000 ); - swapRouter.swap(key, swapParams, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); } function test_swap_failsIfLocked() public { - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - vm.expectRevert(IPoolManager.ManagerLocked.selector); - manager.swap(key, swapParams, ZERO_BYTES); + manager.swap(key, SWAP_PARAMS, ZERO_BYTES); } function test_swap_succeedsWithNativeTokensIfInitialized() public { - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: true, settleUsingBurn: false}); @@ -588,7 +579,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { 3000 ); - swapRouter.swap{value: 100}(nativeKey, swapParams, testSettings, ZERO_BYTES); + swapRouter.swap{value: 100}(nativeKey, SWAP_PARAMS, testSettings, ZERO_BYTES); } function test_swap_succeedsWithHooksIfInitialized() public { @@ -603,19 +594,16 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { (key,) = initPoolAndAddLiquidity(currency0, currency1, IHooks(mockAddr), 3000, SQRT_PRICE_1_1, ZERO_BYTES); - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: true, settleUsingBurn: false}); - BalanceDelta balanceDelta = swapRouter.swap(key, swapParams, testSettings, ZERO_BYTES); + BalanceDelta balanceDelta = swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); bytes32 beforeSelector = MockHooks.beforeSwap.selector; - bytes memory beforeParams = abi.encode(address(swapRouter), key, swapParams, ZERO_BYTES); + bytes memory beforeParams = abi.encode(address(swapRouter), key, SWAP_PARAMS, ZERO_BYTES); bytes32 afterSelector = MockHooks.afterSwap.selector; - bytes memory afterParams = abi.encode(address(swapRouter), key, swapParams, balanceDelta, ZERO_BYTES); + bytes memory afterParams = abi.encode(address(swapRouter), key, SWAP_PARAMS, balanceDelta, ZERO_BYTES); assertEq(MockContract(mockAddr).timesCalledSelector(beforeSelector), 1); assertTrue(MockContract(mockAddr).calledWithSelector(beforeSelector, beforeParams)); @@ -676,38 +664,26 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { } function test_swap_succeeds() public { - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); - swapRouter.swap(key, swapParams, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); } function test_swap_gas() public { - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - - swapRouterNoChecks.swap(key, swapParams); + swapRouterNoChecks.swap(key, SWAP_PARAMS); snapLastCall("simple swap"); } function test_swap_withNative_succeeds() public { - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); - swapRouter.swap{value: 100}(nativeKey, swapParams, testSettings, ZERO_BYTES); + swapRouter.swap{value: 100}(nativeKey, SWAP_PARAMS, testSettings, ZERO_BYTES); } function test_swap_withNative_gas() public { - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - - swapRouterNoChecks.swap{value: 100}(nativeKey, swapParams); + swapRouterNoChecks.swap{value: 100}(nativeKey, SWAP_PARAMS); snapLastCall("simple swap with native"); } @@ -720,15 +696,12 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { (key,) = initPoolAndAddLiquidity(currency0, currency1, mockHooks, 3000, SQRT_PRICE_1_1, ZERO_BYTES); - IPoolManager.SwapParams memory swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); - swapRouter.swap(key, swapParams, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); - swapParams = + IPoolManager.SwapParams memory swapParams = IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_4}); testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); @@ -737,15 +710,12 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { } function test_swap_mint6909IfOutputNotTaken_gas() public { - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: true, settleUsingBurn: false}); vm.expectEmit(); emit Transfer(address(swapRouter), address(0), address(this), CurrencyLibrary.toId(currency1), 98); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); snapLastCall("swap mint output as 6909"); uint256 erc6909Balance = manager.balanceOf(address(this), CurrencyLibrary.toId(currency1)); @@ -769,15 +739,12 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { } function test_swap_burn6909AsInput_gas() public { - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: true, settleUsingBurn: false}); vm.expectEmit(); emit Transfer(address(swapRouter), address(0), address(this), CurrencyLibrary.toId(currency1), 98); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); uint256 erc6909Balance = manager.balanceOf(address(this), uint256(uint160(Currency.unwrap(currency1)))); assertEq(erc6909Balance, 98); @@ -786,7 +753,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { manager.setOperator(address(swapRouter), true); // swap from currency1 to currency0 again, using 6909s as input tokens - params = IPoolManager.SwapParams({zeroForOne: false, amountSpecified: 25, sqrtPriceLimitX96: SQRT_PRICE_4_1}); + IPoolManager.SwapParams memory params = IPoolManager.SwapParams({zeroForOne: false, amountSpecified: 25, sqrtPriceLimitX96: SQRT_PRICE_4_1}); testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: true}); vm.expectEmit(); @@ -830,30 +797,26 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot { } function test_swap_againstLiquidity_gas() public { - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); - swapRouter.swap(key, params, testSettings, ZERO_BYTES); + swapRouter.swap(key, SWAP_PARAMS, testSettings, ZERO_BYTES); - params = IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_4}); + IPoolManager.SwapParams memory params = + IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_4}); swapRouter.swap(key, params, testSettings, ZERO_BYTES); snapLastCall("swap against liquidity"); } function test_swap_againstLiqWithNative_gas() public { - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); - swapRouter.swap{value: 1 ether}(nativeKey, params, testSettings, ZERO_BYTES); + swapRouter.swap{value: 1 ether}(nativeKey, SWAP_PARAMS, testSettings, ZERO_BYTES); - params = IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_4}); + IPoolManager.SwapParams memory params = + IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_4}); swapRouter.swap{value: 1 ether}(nativeKey, params, testSettings, ZERO_BYTES); snapLastCall("swap against liquidity with native token"); diff --git a/test/SkipCallsTestHook.t.sol b/test/SkipCallsTestHook.t.sol index ed30227e0..9b7512fc4 100644 --- a/test/SkipCallsTestHook.t.sol +++ b/test/SkipCallsTestHook.t.sol @@ -21,9 +21,6 @@ import {SkipCallsTestHook} from "../src/test/SkipCallsTestHook.sol"; contract SkipCallsTest is Test, Deployers, GasSnapshot { using PoolIdLibrary for PoolKey; - IPoolManager.SwapParams swapParams = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); function deploy(SkipCallsTestHook skipCallsTestHook) private { @@ -144,10 +141,10 @@ contract SkipCallsTest is Test, Deployers, GasSnapshot { assertEq(skipCallsTestHook.counter(), 0); // swaps and increments counter - swapRouter.swap(key, swapParams, testSettings, abi.encode(address(this))); + swapRouter.swap(key, SWAP_PARAMS, testSettings, abi.encode(address(this))); assertEq(skipCallsTestHook.counter(), 1); // swaps again and increments counter - swapRouter.swap(key, swapParams, testSettings, abi.encode(address(this))); + swapRouter.swap(key, SWAP_PARAMS, testSettings, abi.encode(address(this))); assertEq(skipCallsTestHook.counter(), 2); } @@ -161,7 +158,7 @@ contract SkipCallsTest is Test, Deployers, GasSnapshot { assertEq(skipCallsTestHook.counter(), 0); // swaps and increments counter - swapRouter.swap(key, swapParams, testSettings, abi.encode(address(this))); + swapRouter.swap(key, SWAP_PARAMS, testSettings, abi.encode(address(this))); snapLastCall("swap skips hook call if hook is caller"); assertEq(skipCallsTestHook.counter(), 1); } @@ -176,10 +173,10 @@ contract SkipCallsTest is Test, Deployers, GasSnapshot { assertEq(skipCallsTestHook.counter(), 0); // swaps and increments counter - swapRouter.swap(key, swapParams, testSettings, abi.encode(address(this))); + swapRouter.swap(key, SWAP_PARAMS, testSettings, abi.encode(address(this))); assertEq(skipCallsTestHook.counter(), 1); // swaps again and increments counter - swapRouter.swap(key, swapParams, testSettings, abi.encode(address(this))); + swapRouter.swap(key, SWAP_PARAMS, testSettings, abi.encode(address(this))); assertEq(skipCallsTestHook.counter(), 2); } diff --git a/test/Sync.t.sol b/test/Sync.t.sol index 968d34918..4bd08413c 100644 --- a/test/Sync.t.sol +++ b/test/Sync.t.sol @@ -56,16 +56,13 @@ contract SyncTest is Test, Deployers, GasSnapshot { function test_settle_withStartingBalance() public noIsolate { assertGt(currency0.balanceOf(address(manager)), uint256(0)); - IPoolManager.SwapParams memory params = - IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); - PoolSwapTest.TestSettings memory testSettings = PoolSwapTest.TestSettings({takeClaims: false, settleUsingBurn: false}); // Sync has not been called. assertEq(manager.getReserves(currency0), 0); - swapRouter.swap(key, params, testSettings, new bytes(0)); + swapRouter.swap(key, SWAP_PARAMS, testSettings, new bytes(0)); (uint256 balanceCurrency0) = currency0.balanceOf(address(manager)); assertEq(manager.getReserves(currency0), balanceCurrency0); // Reserves are up to date since settle was called. } diff --git a/test/utils/Deployers.sol b/test/utils/Deployers.sol index 1ba6cb175..4f9b1bb95 100644 --- a/test/utils/Deployers.sol +++ b/test/utils/Deployers.sol @@ -51,6 +51,8 @@ contract Deployers { IPoolManager.ModifyLiquidityParams({tickLower: -120, tickUpper: 120, liquidityDelta: 1e18, salt: 0}); IPoolManager.ModifyLiquidityParams public REMOVE_LIQUIDITY_PARAMS = IPoolManager.ModifyLiquidityParams({tickLower: -120, tickUpper: 120, liquidityDelta: -1e18, salt: 0}); + IPoolManager.SwapParams public SWAP_PARAMS = + IPoolManager.SwapParams({zeroForOne: true, amountSpecified: -100, sqrtPriceLimitX96: SQRT_PRICE_1_2}); // Global variables Currency internal currency0;