From 251c104e35393813445400f3be57e0324002dbd2 Mon Sep 17 00:00:00 2001 From: Alice Henshaw Date: Tue, 10 Sep 2024 17:47:18 -0400 Subject: [PATCH] cache path key --- ...uoter_quoteExactInput_oneHop_1TickLoaded.snap | 2 +- ..._quoteExactInput_oneHop_initializedAfter.snap | 2 +- ...oteExactInput_oneHop_startingInitialized.snap | 2 +- .../Quoter_quoteExactInput_twoHops.snap | 2 +- ...oter_quoteExactOutput_oneHop_1TickLoaded.snap | 2 +- ...ter_quoteExactOutput_oneHop_2TicksLoaded.snap | 2 +- ...quoteExactOutput_oneHop_initializedAfter.snap | 2 +- ...teExactOutput_oneHop_startingInitialized.snap | 2 +- .../Quoter_quoteExactOutput_twoHops.snap | 2 +- src/lens/Quoter.sol | 16 ++++++++++------ 10 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap b/.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap index 2e4f8e314..4c00c4951 100644 --- a/.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap +++ b/.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap @@ -1 +1 @@ -128285 \ No newline at end of file +127764 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap b/.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap index 2f3c1bba6..287ba61d7 100644 --- a/.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap +++ b/.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap @@ -1 +1 @@ -153188 \ No newline at end of file +152656 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap b/.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap index d71ed55ce..e4a3fc7d3 100644 --- a/.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap +++ b/.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap @@ -1 +1 @@ -87211 \ No newline at end of file +86679 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactInput_twoHops.snap b/.forge-snapshots/Quoter_quoteExactInput_twoHops.snap index 433912dea..6656c9162 100644 --- a/.forge-snapshots/Quoter_quoteExactInput_twoHops.snap +++ b/.forge-snapshots/Quoter_quoteExactInput_twoHops.snap @@ -1 +1 @@ -212035 \ No newline at end of file +210976 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap index 7869622be..70adf0b91 100644 --- a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap @@ -1 +1 @@ -148025 \ No newline at end of file +147458 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap index fbe64408c..ac5a8933f 100644 --- a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap @@ -1 +1 @@ -178162 \ No newline at end of file +177595 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap index 03cb97d1d..012cb790e 100644 --- a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap @@ -1 +1 @@ -148093 \ No newline at end of file +147526 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap index 76815c760..cbec599bd 100644 --- a/.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap +++ b/.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap @@ -1 +1 @@ -124792 \ No newline at end of file +124225 \ No newline at end of file diff --git a/.forge-snapshots/Quoter_quoteExactOutput_twoHops.snap b/.forge-snapshots/Quoter_quoteExactOutput_twoHops.snap index 97851c9b1..d8c5ead7d 100644 --- a/.forge-snapshots/Quoter_quoteExactOutput_twoHops.snap +++ b/.forge-snapshots/Quoter_quoteExactOutput_twoHops.snap @@ -1 +1 @@ -252373 \ No newline at end of file +251247 \ No newline at end of file diff --git a/src/lens/Quoter.sol b/src/lens/Quoter.sol index ae98a9f40..c5a75a9ab 100644 --- a/src/lens/Quoter.sol +++ b/src/lens/Quoter.sol @@ -106,12 +106,14 @@ contract Quoter is IQuoter, SafeCallback { BalanceDelta swapDelta; uint128 amountIn = params.exactAmount; Currency inputCurrency = params.exactCurrency; + PathKey calldata pathKey; for (uint256 i = 0; i < pathLength; i++) { - (PoolKey memory poolKey, bool zeroForOne) = params.path[i].getPoolAndSwapDirection(inputCurrency); + pathKey = params.path[i]; + (PoolKey memory poolKey, bool zeroForOne) = pathKey.getPoolAndSwapDirection(inputCurrency); (swapDelta, result.sqrtPriceX96AfterList[i]) = - _swap(poolKey, zeroForOne, -int256(int128(amountIn)), 0, params.path[i].hookData); + _swap(poolKey, zeroForOne, -int256(int128(amountIn)), 0, pathKey.hookData); if (zeroForOne) { result.deltaAmounts[i] += -swapDelta.amount0(); @@ -122,7 +124,7 @@ contract Quoter is IQuoter, SafeCallback { result.deltaAmounts[i + 1] += -swapDelta.amount0(); amountIn = uint128(swapDelta.amount0()); } - inputCurrency = params.path[i].intermediateCurrency; + inputCurrency = pathKey.intermediateCurrency; } bytes memory encodedResult = abi.encode(result.deltaAmounts, result.sqrtPriceX96AfterList); encodedResult.revertWith(); @@ -156,14 +158,16 @@ contract Quoter is IQuoter, SafeCallback { BalanceDelta swapDelta; uint128 amountOut = params.exactAmount; Currency outputCurrency = params.exactCurrency; + PathKey calldata pathKey; for (uint256 i = pathLength; i > 0; i--) { + pathKey = params.path[i - 1]; amountOutCached = amountOut; - (PoolKey memory poolKey, bool oneForZero) = params.path[i - 1].getPoolAndSwapDirection(outputCurrency); + (PoolKey memory poolKey, bool oneForZero) = pathKey.getPoolAndSwapDirection(outputCurrency); (swapDelta, result.sqrtPriceX96AfterList[i - 1]) = - _swap(poolKey, !oneForZero, int256(uint256(amountOut)), 0, params.path[i - 1].hookData); + _swap(poolKey, !oneForZero, int256(uint256(amountOut)), 0, pathKey.hookData); // always clear because sqrtPriceLimitX96 is set to 0 always delete amountOutCached; @@ -178,7 +182,7 @@ contract Quoter is IQuoter, SafeCallback { amountOut = uint128(-swapDelta.amount1()); } - outputCurrency = params.path[i - 1].intermediateCurrency; + outputCurrency = pathKey.intermediateCurrency; } bytes memory encodedResult = abi.encode(result.deltaAmounts, result.sqrtPriceX96AfterList); encodedResult.revertWith();