From ae08e814a104934bd3f4a61b613b76d20c2a2177 Mon Sep 17 00:00:00 2001 From: Alice Henshaw Date: Mon, 9 Sep 2024 17:41:26 -0400 Subject: [PATCH 1/2] Quoter snapshots --- ...utSingle_oneForZero_multiplePositions.snap | 1 + ...utSingle_zeroForOne_multiplePositions.snap | 1 + .../Quoter_exactOutputSingle_oneForZero.snap | 1 + .../Quoter_exactOutputSingle_zeroForOne.snap | 1 + ...er_quoteExactInput_oneHop_1TickLoaded.snap | 1 + ...oteExactInput_oneHop_initializedAfter.snap | 1 + ...ExactInput_oneHop_startingInitialized.snap | 1 + .../Quoter_quoteExactInput_twoHops.snap | 1 + ...r_quoteExactOutput_oneHop_1TickLoaded.snap | 1 + ..._quoteExactOutput_oneHop_2TicksLoaded.snap | 1 + ...teExactOutput_oneHop_initializedAfter.snap | 1 + ...xactOutput_oneHop_startingInitialized.snap | 1 + .../Quoter_quoteExactOutput_twoHops.snap | 1 + test/Quoter.t.sol | 31 ++++++++++++++++--- 14 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 .forge-snapshots/Quoter_exactInputSingle_oneForZero_multiplePositions.snap create mode 100644 .forge-snapshots/Quoter_exactInputSingle_zeroForOne_multiplePositions.snap create mode 100644 .forge-snapshots/Quoter_exactOutputSingle_oneForZero.snap create mode 100644 .forge-snapshots/Quoter_exactOutputSingle_zeroForOne.snap create mode 100644 .forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap create mode 100644 .forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap create mode 100644 .forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap create mode 100644 .forge-snapshots/Quoter_quoteExactInput_twoHops.snap create mode 100644 .forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap create mode 100644 .forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap create mode 100644 .forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap create mode 100644 .forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap create mode 100644 .forge-snapshots/Quoter_quoteExactOutput_twoHops.snap diff --git a/.forge-snapshots/Quoter_exactInputSingle_oneForZero_multiplePositions.snap b/.forge-snapshots/Quoter_exactInputSingle_oneForZero_multiplePositions.snap new file mode 100644 index 000000000..0c97c3620 --- /dev/null +++ b/.forge-snapshots/Quoter_exactInputSingle_oneForZero_multiplePositions.snap @@ -0,0 +1 @@ +159043 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_exactInputSingle_zeroForOne_multiplePositions.snap b/.forge-snapshots/Quoter_exactInputSingle_zeroForOne_multiplePositions.snap new file mode 100644 index 000000000..af5fa0fa6 --- /dev/null +++ b/.forge-snapshots/Quoter_exactInputSingle_zeroForOne_multiplePositions.snap @@ -0,0 +1 @@ +166396 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_exactOutputSingle_oneForZero.snap b/.forge-snapshots/Quoter_exactOutputSingle_oneForZero.snap new file mode 100644 index 000000000..f43e94582 --- /dev/null +++ b/.forge-snapshots/Quoter_exactOutputSingle_oneForZero.snap @@ -0,0 +1 @@ +93637 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_exactOutputSingle_zeroForOne.snap b/.forge-snapshots/Quoter_exactOutputSingle_zeroForOne.snap new file mode 100644 index 000000000..66a68794e --- /dev/null +++ b/.forge-snapshots/Quoter_exactOutputSingle_zeroForOne.snap @@ -0,0 +1 @@ +100303 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap b/.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap new file mode 100644 index 000000000..87d96db17 --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap @@ -0,0 +1 @@ +141321 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap b/.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap new file mode 100644 index 000000000..3315258ee --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap @@ -0,0 +1 @@ +164528 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap b/.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap new file mode 100644 index 000000000..954792b66 --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap @@ -0,0 +1 @@ +98641 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactInput_twoHops.snap b/.forge-snapshots/Quoter_quoteExactInput_twoHops.snap new file mode 100644 index 000000000..b8ed8de2f --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactInput_twoHops.snap @@ -0,0 +1 @@ +234806 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap new file mode 100644 index 000000000..8a6db3df9 --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap @@ -0,0 +1 @@ +161346 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap new file mode 100644 index 000000000..7391d6be7 --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap @@ -0,0 +1 @@ +191453 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap new file mode 100644 index 000000000..e3e9a1fc3 --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap @@ -0,0 +1 @@ +28495083 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap new file mode 100644 index 000000000..5aed9cf81 --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap @@ -0,0 +1 @@ +136430 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_twoHops.snap b/.forge-snapshots/Quoter_quoteExactOutput_twoHops.snap new file mode 100644 index 000000000..da4bedcf8 --- /dev/null +++ b/.forge-snapshots/Quoter_quoteExactOutput_twoHops.snap @@ -0,0 +1 @@ +275720 \ No newline at end of file diff --git a/test/Quoter.t.sol b/test/Quoter.t.sol index b01d9c881..f93ab3505 100644 --- a/test/Quoter.t.sol +++ b/test/Quoter.t.sol @@ -6,6 +6,7 @@ import {Test} from "forge-std/Test.sol"; import {PathKey} from "../src/libraries/PathKey.sol"; import {IQuoter} from "../src/interfaces/IQuoter.sol"; import {Quoter} from "../src/lens/Quoter.sol"; +import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol"; // v4-core import {LiquidityAmounts} from "@uniswap/v4-core/test/utils/LiquidityAmounts.sol"; @@ -23,7 +24,7 @@ import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol"; // solmate import {MockERC20} from "solmate/src/test/utils/mocks/MockERC20.sol"; -contract QuoterTest is Test, Deployers { +contract QuoterTest is Test, Deployers, GasSnapshot { using SafeCast for *; using PoolIdLibrary for PoolKey; using StateLibrary for IPoolManager; @@ -94,6 +95,7 @@ contract QuoterTest is Test, Deployers { hookData: ZERO_BYTES }) ); + snapLastCall("Quoter_exactInputSingle_zeroForOne_multiplePositions"); assertEq(uint128(-deltaAmounts[1]), expectedAmountOut); assertEq(sqrtPriceX96After, expectedSqrtPriceX96After); @@ -115,6 +117,7 @@ contract QuoterTest is Test, Deployers { hookData: ZERO_BYTES }) ); + snapLastCall("Quoter_exactInputSingle_oneForZero_multiplePositions"); assertEq(uint128(-deltaAmounts[0]), expectedAmountOut); assertEq(sqrtPriceX96After, expectedSqrtPriceX96After); @@ -144,7 +147,7 @@ contract QuoterTest is Test, Deployers { assertEq(initializedTicksLoadedList[0], 2); } - function testQuoter_quoteExactInput_0to2_2TicksLoaded_initialiedAfter() public { + function testQuoter_quoteExactInput_0to2_2TicksLoaded_initializedAfter() public { tokenPath.push(token0); tokenPath.push(token2); @@ -177,6 +180,8 @@ contract QuoterTest is Test, Deployers { uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactInput(params); + snapLastCall("Quoter_quoteExactInput_oneHop_1TickLoaded"); + assertEq(uint128(-deltaAmounts[1]), 3971); assertEq(sqrtPriceX96AfterList[0], 78926452400586371254602774705); assertEq(initializedTicksLoadedList[0], 1); @@ -231,7 +236,7 @@ contract QuoterTest is Test, Deployers { assertEq(initializedTicksLoadedList[0], 2); } - function testQuoter_quoteExactInput_2to0_2TicksLoaded_initialiedAfter() public { + function testQuoter_quoteExactInput_2to0_2TicksLoaded_initializedAfter() public { tokenPath.push(token2); tokenPath.push(token0); @@ -245,6 +250,8 @@ contract QuoterTest is Test, Deployers { uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactInput(params); + snapLastCall("Quoter_quoteExactInput_oneHop_initializedAfter"); + assertEq(-deltaAmounts[1], 6190); assertEq(sqrtPriceX96AfterList[0], 79705728824507063507279123685); assertEq(initializedTicksLoadedList[0], 2); @@ -263,6 +270,8 @@ contract QuoterTest is Test, Deployers { uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactInput(params); + snapLastCall("Quoter_quoteExactInput_oneHop_startingInitialized"); + assertEq(-deltaAmounts[1], 198); assertEq(sqrtPriceX96AfterList[0], 79235729830182478001034429156); assertEq(initializedTicksLoadedList[0], 0); @@ -312,6 +321,8 @@ contract QuoterTest is Test, Deployers { uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactInput(params); + snapLastCall("Quoter_quoteExactInput_twoHops"); + assertEq(-deltaAmounts[2], 9745); assertEq(sqrtPriceX96AfterList[0], 78461846509168490764501028180); assertEq(sqrtPriceX96AfterList[1], 80007846861567212939802016351); @@ -330,6 +341,7 @@ contract QuoterTest is Test, Deployers { hookData: ZERO_BYTES }) ); + snapLastCall("Quoter_exactOutputSingle_zeroForOne"); assertEq(deltaAmounts[0], 9981); assertEq(sqrtPriceX96After, SQRT_PRICE_100_102); @@ -347,6 +359,7 @@ contract QuoterTest is Test, Deployers { hookData: ZERO_BYTES }) ); + snapLastCall("Quoter_exactOutputSingle_oneForZero"); assertEq(deltaAmounts[1], 9981); assertEq(sqrtPriceX96After, SQRT_PRICE_102_100); @@ -364,17 +377,21 @@ contract QuoterTest is Test, Deployers { uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactOutput(params); + snapLastCall("Quoter_quoteExactOutput_oneHop_2TicksLoaded"); + assertEq(deltaAmounts[0], 15273); assertEq(sqrtPriceX96AfterList[0], 78055527257643669242286029831); assertEq(initializedTicksLoadedList[0], 2); } - function testQuoter_quoteExactOutput_0to2_1TickLoaded_initialiedAfter() public { + function testQuoter_quoteExactOutput_0to2_1TickLoaded_initializedAfter() public { tokenPath.push(token0); tokenPath.push(token2); IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6143); + snapLastCall("Quoter_quoteExactOutput_oneHop_initializedAfter"); + ( int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList, @@ -397,6 +414,7 @@ contract QuoterTest is Test, Deployers { uint160[] memory sqrtPriceX96AfterList, uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactOutput(params); + snapLastCall("Quoter_quoteExactOutput_oneHop_1TickLoaded"); assertEq(deltaAmounts[0], 4029); assertEq(sqrtPriceX96AfterList[0], 78924219757724709840818372098); @@ -416,6 +434,7 @@ contract QuoterTest is Test, Deployers { uint160[] memory sqrtPriceX96AfterList, uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactOutput(params); + snapLastCall("Quoter_quoteExactOutput_oneHop_startingInitialized"); assertEq(deltaAmounts[0], 102); assertEq(sqrtPriceX96AfterList[0], 79224329176051641448521403903); @@ -456,7 +475,7 @@ contract QuoterTest is Test, Deployers { assertEq(initializedTicksLoadedList[0], 2); } - function testQuoter_quoteExactOutput_2to0_2TicksLoaded_initialiedAfter() public { + function testQuoter_quoteExactOutput_2to0_2TicksLoaded_initializedAfter() public { tokenPath.push(token2); tokenPath.push(token0); @@ -522,6 +541,8 @@ contract QuoterTest is Test, Deployers { uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactOutput(params); + snapLastCall("Quoter_quoteExactOutput_twoHops"); + assertEq(deltaAmounts[0], 10000); assertEq(deltaAmounts[1], 0); assertEq(deltaAmounts[2], -9745); From 6fda71af9d28f18bbbd52c91c81b67df4a65f5f7 Mon Sep 17 00:00:00 2001 From: Alice Henshaw Date: Mon, 9 Sep 2024 17:45:51 -0400 Subject: [PATCH 2/2] oops x --- .../Quoter_quoteExactOutput_oneHop_initializedAfter.snap | 2 +- test/Quoter.t.sol | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap index e3e9a1fc3..cc4af5c55 100644 --- a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap @@ -1 +1 @@ -28495083 \ No newline at end of file +161661 \ No newline at end of file diff --git a/test/Quoter.t.sol b/test/Quoter.t.sol index f93ab3505..dbe7eeb07 100644 --- a/test/Quoter.t.sol +++ b/test/Quoter.t.sol @@ -390,13 +390,12 @@ contract QuoterTest is Test, Deployers, GasSnapshot { IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6143); - snapLastCall("Quoter_quoteExactOutput_oneHop_initializedAfter"); - ( int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList, uint32[] memory initializedTicksLoadedList ) = quoter.quoteExactOutput(params); + snapLastCall("Quoter_quoteExactOutput_oneHop_initializedAfter"); assertEq(deltaAmounts[0], 6200); assertEq(sqrtPriceX96AfterList[0], 78757225449310403327341205211);