Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 committed Sep 9, 2024
2 parents de00f69 + 5d7fde2 commit d3b0261
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
149027
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
154511
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 @@
83641
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 @@
88449
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
128559
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
153480
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
87503
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 @@
212546
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
148306
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
178443
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
148374
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
125073
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 @@
252910
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 @@ -93,6 +94,7 @@ contract QuoterTest is Test, Deployers {
hookData: ZERO_BYTES
})
);
snapLastCall("Quoter_exactInputSingle_zeroForOne_multiplePositions");

assertEq(uint128(-deltaAmounts[1]), expectedAmountOut);
assertEq(sqrtPriceX96After, expectedSqrtPriceX96After);
Expand All @@ -112,6 +114,7 @@ contract QuoterTest is Test, Deployers {
hookData: ZERO_BYTES
})
);
snapLastCall("Quoter_exactInputSingle_oneForZero_multiplePositions");

assertEq(uint128(-deltaAmounts[0]), expectedAmountOut);
assertEq(sqrtPriceX96After, expectedSqrtPriceX96After);
Expand All @@ -135,7 +138,7 @@ contract QuoterTest is Test, Deployers {
assertEq(sqrtPriceX96AfterList[0], 78461846509168490764501028180);
}

function testQuoter_quoteExactInput_0to2_2TicksLoaded_initialiedAfter() public {
function testQuoter_quoteExactInput_0to2_2TicksLoaded_initializedAfter() public {
tokenPath.push(token0);
tokenPath.push(token2);

Expand All @@ -159,6 +162,8 @@ contract QuoterTest is Test, Deployers {

(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactInput(params);

snapLastCall("Quoter_quoteExactInput_oneHop_1TickLoaded");

assertEq(uint128(-deltaAmounts[1]), 3971);
assertEq(sqrtPriceX96AfterList[0], 78926452400586371254602774705);
}
Expand Down Expand Up @@ -197,7 +202,7 @@ contract QuoterTest is Test, Deployers {
assertEq(sqrtPriceX96AfterList[0], 80001962924147897865541384515);
}

function testQuoter_quoteExactInput_2to0_2TicksLoaded_initialiedAfter() public {
function testQuoter_quoteExactInput_2to0_2TicksLoaded_initializedAfter() public {
tokenPath.push(token2);
tokenPath.push(token0);

Expand All @@ -207,6 +212,8 @@ contract QuoterTest is Test, Deployers {

(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactInput(params);

snapLastCall("Quoter_quoteExactInput_oneHop_initializedAfter");

assertEq(-deltaAmounts[1], 6190);
assertEq(sqrtPriceX96AfterList[0], 79705728824507063507279123685);
}
Expand All @@ -220,6 +227,8 @@ contract QuoterTest is Test, Deployers {
// Tick 0 initialized. Tick after = 1
(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactInput(params);

snapLastCall("Quoter_quoteExactInput_oneHop_startingInitialized");

assertEq(-deltaAmounts[1], 198);
assertEq(sqrtPriceX96AfterList[0], 79235729830182478001034429156);
}
Expand Down Expand Up @@ -254,6 +263,8 @@ contract QuoterTest is Test, Deployers {

(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactInput(params);

snapLastCall("Quoter_quoteExactInput_twoHops");

assertEq(-deltaAmounts[2], 9745);
assertEq(sqrtPriceX96AfterList[0], 78461846509168490764501028180);
assertEq(sqrtPriceX96AfterList[1], 80007846861567212939802016351);
Expand All @@ -269,6 +280,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 @@ -284,6 +296,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 @@ -296,17 +309,20 @@ contract QuoterTest is Test, Deployers {

(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactOutput(params);

snapLastCall("Quoter_quoteExactOutput_oneHop_2TicksLoaded");

assertEq(deltaAmounts[0], 15273);
assertEq(sqrtPriceX96AfterList[0], 78055527257643669242286029831);
}

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);

(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactOutput(params);
snapLastCall("Quoter_quoteExactOutput_oneHop_initializedAfter");

assertEq(deltaAmounts[0], 6200);
assertEq(sqrtPriceX96AfterList[0], 78757225449310403327341205211);
Expand All @@ -319,6 +335,7 @@ contract QuoterTest is Test, Deployers {
IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 4000);

(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactOutput(params);
snapLastCall("Quoter_quoteExactOutput_oneHop_1TickLoaded");

assertEq(deltaAmounts[0], 4029);
assertEq(sqrtPriceX96AfterList[0], 78924219757724709840818372098);
Expand All @@ -333,6 +350,7 @@ contract QuoterTest is Test, Deployers {

// Tick 0 initialized. Tick after = 1
(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactOutput(params);
snapLastCall("Quoter_quoteExactOutput_oneHop_startingInitialized");

assertEq(deltaAmounts[0], 102);
assertEq(sqrtPriceX96AfterList[0], 79224329176051641448521403903);
Expand Down Expand Up @@ -361,7 +379,7 @@ contract QuoterTest is Test, Deployers {
assertEq(sqrtPriceX96AfterList[0], 80418414376567919517220409857);
}

function testQuoter_quoteExactOutput_2to0_2TicksLoaded_initialiedAfter() public {
function testQuoter_quoteExactOutput_2to0_2TicksLoaded_initializedAfter() public {
tokenPath.push(token2);
tokenPath.push(token0);

Expand Down Expand Up @@ -405,6 +423,8 @@ contract QuoterTest is Test, Deployers {

(int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList) = quoter.quoteExactOutput(params);

snapLastCall("Quoter_quoteExactOutput_twoHops");

assertEq(deltaAmounts[0], 10000);
assertEq(deltaAmounts[1], 0);
assertEq(deltaAmounts[2], -9745);
Expand Down

0 comments on commit d3b0261

Please sign in to comment.