Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quoter snapshots #348

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
159043
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
166396
1 change: 1 addition & 0 deletions .forge-snapshots/Quoter_exactOutputSingle_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
93637
1 change: 1 addition & 0 deletions .forge-snapshots/Quoter_exactOutputSingle_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100303
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
141321
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
164528
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
98641
1 change: 1 addition & 0 deletions .forge-snapshots/Quoter_quoteExactInput_twoHops.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
234806
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
161346
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
191453
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
161661
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
136430
1 change: 1 addition & 0 deletions .forge-snapshots/Quoter_quoteExactOutput_twoHops.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
275720
30 changes: 25 additions & 5 deletions test/Quoter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

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

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -364,12 +377,14 @@ 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);

Expand All @@ -380,6 +395,7 @@ contract QuoterTest is Test, Deployers {
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksLoadedList
) = quoter.quoteExactOutput(params);
snapLastCall("Quoter_quoteExactOutput_oneHop_initializedAfter");

assertEq(deltaAmounts[0], 6200);
assertEq(sqrtPriceX96AfterList[0], 78757225449310403327341205211);
Expand All @@ -397,6 +413,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);
Expand All @@ -416,6 +433,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);
Expand Down Expand Up @@ -456,7 +474,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);

Expand Down Expand Up @@ -522,6 +540,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);
Expand Down
Loading