Skip to content

Commit

Permalink
tests: Make and use a common SWAP_PARAMS in Deployers.sol
Browse files Browse the repository at this point in the history
Resolves Issue Uniswap#390
  • Loading branch information
prosperring committed May 19, 2024
1 parent 2df9bb3 commit 6719e56
Show file tree
Hide file tree
Showing 47 changed files with 77 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/ERC6909Claims approve.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46492
24984
2 changes: 1 addition & 1 deletion .forge-snapshots/ERC6909Claims burn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29428
3272
2 changes: 1 addition & 1 deletion .forge-snapshots/ERC6909Claims mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
46815
25307
2 changes: 1 addition & 1 deletion .forge-snapshots/ERC6909Claims transfer.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52046
25738
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54699
26239
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60247
28987
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57049
28589
Original file line number Diff line number Diff line change
@@ -1 +1 @@
153643
62251
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity CA fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
331309
283829
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
286302
255822
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with native token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
143853
120613
Original file line number Diff line number Diff line change
@@ -1 +1 @@
301821
278329
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 1 token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
107894
85150
2 changes: 1 addition & 1 deletion .forge-snapshots/donate gas with 2 tokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148384
119128
2 changes: 1 addition & 1 deletion .forge-snapshots/erc20 collect protocol fees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
57275
24275
2 changes: 1 addition & 1 deletion .forge-snapshots/initialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
61862
39246
2 changes: 1 addition & 1 deletion .forge-snapshots/native collect protocol fees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
59520
36048
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity CA fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186775
111807
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123143
54675
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with native token.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119930
125202
2 changes: 1 addition & 1 deletion .forge-snapshots/set protocol fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32415
10043
Original file line number Diff line number Diff line change
@@ -1 +1 @@
104932
36092
2 changes: 1 addition & 1 deletion .forge-snapshots/simple addLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
167424
143584
Original file line number Diff line number Diff line change
@@ -1 +1 @@
98529
31401
2 changes: 1 addition & 1 deletion .forge-snapshots/simple removeLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
90569
33041
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap with native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116827
93923
2 changes: 1 addition & 1 deletion .forge-snapshots/simple swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131988
108856
2 changes: 1 addition & 1 deletion .forge-snapshots/swap CA custom curve + swap noop.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134432
85152
2 changes: 1 addition & 1 deletion .forge-snapshots/swap CA fee on unspecified.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
183126
117446
Original file line number Diff line number Diff line change
@@ -1 +1 @@
112548
61040
2 changes: 1 addition & 1 deletion .forge-snapshots/swap against liquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123891
58055
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn 6909 for input.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135923
76059
2 changes: 1 addition & 1 deletion .forge-snapshots/swap burn native 6909 for input.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125140
71992
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint native output as 6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
147180
123728
2 changes: 1 addition & 1 deletion .forge-snapshots/swap mint output as 6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
163842
140162
Original file line number Diff line number Diff line change
@@ -1 +1 @@
222199
145411
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with dynamic fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148043
84659
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with hooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123903
58055
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with lp fee and protocol fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
180223
144899
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with return dynamic fee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
155902
123006
2 changes: 1 addition & 1 deletion .forge-snapshots/update dynamic fee in before swap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158505
125609
24 changes: 6 additions & 18 deletions test/DynamicFees.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,25 @@ 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 {
assertEq(_fetchPoolLPFee(key), 0);

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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}

Expand Down
4 changes: 1 addition & 3 deletions test/DynamicReturnFees.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 6719e56

Please sign in to comment.