From fbb6d1b6ef73972b715885c29bac40eeef029103 Mon Sep 17 00:00:00 2001 From: ConjunctiveNormalForm Date: Mon, 18 Dec 2023 14:38:20 -0500 Subject: [PATCH] combine IQuoter structs --- contracts/interfaces/IQuoter.sol | 22 +++++-------- contracts/lens/Quoter.sol | 16 +++++----- test/Quoter.t.sol | 54 ++++++++++++++++---------------- 3 files changed, 42 insertions(+), 50 deletions(-) diff --git a/contracts/interfaces/IQuoter.sol b/contracts/interfaces/IQuoter.sol index dc128c6c..feda3d8e 100644 --- a/contracts/interfaces/IQuoter.sol +++ b/contracts/interfaces/IQuoter.sol @@ -32,19 +32,11 @@ interface IQuoter { bytes hookData; } - struct QuoteExactInputParams { - Currency currencyIn; + struct QuoteExactParams { + Currency exactCurrency; PathKey[] path; address recipient; - uint128 amountIn; - } - - struct QuoteExactOutputParams { - Currency currencyOut; - PathKey[] path; - address recipient; - uint128 amountOut; - uint160 sqrtPriceLimitX96; + uint128 exactAmount; } /// @notice Returns the delta amounts for a given exact input swap of a single pool @@ -67,11 +59,11 @@ interface IQuoter { /// currencyIn The input currency of the swap /// path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info /// recipient The intended recipient of the output tokens - /// amountIn The desired input amount + /// exactAmount The desired input amount /// @return deltaAmounts Delta amounts along the path resulted from the swap /// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path /// @return initializedTicksLoadedList List of the initialized ticks that the swap loaded for each pool in the path - function quoteExactInput(QuoteExactInputParams memory params) + function quoteExactInput(QuoteExactParams memory params) external returns ( int128[] memory deltaAmounts, @@ -99,11 +91,11 @@ interface IQuoter { /// currencyOut The output currency of the swap /// path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info /// recipient The intended recipient of the output tokens - /// amountOut The desired output amount + /// exactAmount The desired output amount /// @return deltaAmounts Delta amounts along the path resulted from the swap /// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path /// @return initializedTicksLoadedList List of the initialized ticks that the swap loaded for each pool in the path - function quoteExactOutput(QuoteExactOutputParams memory params) + function quoteExactOutput(QuoteExactParams memory params) external returns ( int128[] memory deltaAmounts, diff --git a/contracts/lens/Quoter.sol b/contracts/lens/Quoter.sol index ea7fa3eb..ea65dfa2 100644 --- a/contracts/lens/Quoter.sol +++ b/contracts/lens/Quoter.sol @@ -57,7 +57,7 @@ contract Quoter is IQuoter, ILockCallback { } /// @inheritdoc IQuoter - function quoteExactInput(QuoteExactInputParams memory params) + function quoteExactInput(QuoteExactParams memory params) external returns ( int128[] memory deltaAmounts, @@ -87,7 +87,7 @@ contract Quoter is IQuoter, ILockCallback { } /// @inheritdoc IQuoter - function quoteExactOutput(QuoteExactOutputParams memory params) + function quoteExactOutput(QuoteExactParams memory params) public override returns ( @@ -167,7 +167,7 @@ contract Quoter is IQuoter, ILockCallback { } /// @dev quote an ExactInput swap along a path of tokens, then revert with the result - function _quoteExactInput(QuoteExactInputParams memory params) public selfOnly returns (bytes memory) { + function _quoteExactInput(QuoteExactParams memory params) public selfOnly returns (bytes memory) { uint256 pathLength = params.path.length; int128[] memory deltaAmounts = new int128[](pathLength + 1); @@ -178,13 +178,13 @@ contract Quoter is IQuoter, ILockCallback { for (uint256 i = 0; i < pathLength; i++) { (PoolKey memory poolKey, bool zeroForOne) = - PathKeyLib.getPoolAndSwapDirection(params.path[i], i == 0 ? params.currencyIn : prevCurrencyOut); + PathKeyLib.getPoolAndSwapDirection(params.path[i], i == 0 ? params.exactCurrency : prevCurrencyOut); (, int24 tickBefore,) = manager.getSlot0(poolKey.toId()); (BalanceDelta curDeltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap( poolKey, zeroForOne, - int256(int128(i == 0 ? params.amountIn : prevAmountOut)), + int256(int128(i == 0 ? params.exactAmount : prevAmountOut)), 0, params.path[i].hookData ); @@ -232,7 +232,7 @@ contract Quoter is IQuoter, ILockCallback { } /// @dev quote an ExactOutput swap along a path of tokens, then revert with the result - function _quoteExactOutput(QuoteExactOutputParams memory params) public selfOnly returns (bytes memory) { + function _quoteExactOutput(QuoteExactParams memory params) public selfOnly returns (bytes memory) { uint256 pathLength = params.path.length; int128[] memory deltaAmounts = new int128[](pathLength + 1); @@ -243,7 +243,7 @@ contract Quoter is IQuoter, ILockCallback { for (uint256 i = pathLength; i > 0; i--) { (PoolKey memory poolKey, bool oneForZero) = PathKeyLib.getPoolAndSwapDirection( - params.path[i - 1], i == pathLength ? params.currencyOut : prevCurrencyIn + params.path[i - 1], i == pathLength ? params.exactCurrency : prevCurrencyIn ); (, int24 tickBefore,) = manager.getSlot0(poolKey.toId()); @@ -251,7 +251,7 @@ contract Quoter is IQuoter, ILockCallback { (BalanceDelta curDeltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap( poolKey, !oneForZero, - -int256(int128(i == pathLength ? params.amountOut : prevAmountIn)), + -int256(int128(i == pathLength ? params.exactAmount : prevAmountIn)), 0, params.path[i - 1].hookData ); diff --git a/test/Quoter.t.sol b/test/Quoter.t.sol index 627102a8..056b0818 100644 --- a/test/Quoter.t.sol +++ b/test/Quoter.t.sol @@ -125,7 +125,7 @@ contract QuoterTest is Test, Deployers { function testQuoter_quoteExactInput_0to2_2TicksLoaded() public { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 10000); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); ( int128[] memory deltaAmounts, @@ -144,7 +144,7 @@ contract QuoterTest is Test, Deployers { // The swap amount is set such that the active tick after the swap is -120. // -120 is an initialized tick for this pool. We check that we don't count it. - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 6200); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 6200); ( int128[] memory deltaAmounts, @@ -163,7 +163,7 @@ contract QuoterTest is Test, Deployers { // The swap amount is set such that the active tick after the swap is -60. // -60 is an initialized tick for this pool. We check that we don't count it. - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 4000); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 4000); ( int128[] memory deltaAmounts, @@ -179,7 +179,7 @@ contract QuoterTest is Test, Deployers { function testQuoter_quoteExactInput_0to2_0TickLoaded_startingNotInitialized() public { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 10); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10); ( int128[] memory deltaAmounts, @@ -196,7 +196,7 @@ contract QuoterTest is Test, Deployers { setupPoolWithZeroTickInitialized(key02); tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 10); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10); ( int128[] memory deltaAmounts, @@ -212,7 +212,7 @@ contract QuoterTest is Test, Deployers { function testQuoter_quoteExactInput_2to0_2TicksLoaded() public { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 10000); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); ( int128[] memory deltaAmounts, @@ -231,7 +231,7 @@ contract QuoterTest is Test, Deployers { // The swap amount is set such that the active tick after the swap is 120. // 120 is an initialized tick for this pool. We check that we don't count it. - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 6250); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 6250); ( int128[] memory deltaAmounts, @@ -248,7 +248,7 @@ contract QuoterTest is Test, Deployers { setupPoolWithZeroTickInitialized(key02); tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 200); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 200); // Tick 0 initialized. Tick after = 1 ( @@ -266,7 +266,7 @@ contract QuoterTest is Test, Deployers { function testQuoter_quoteExactInput_2to0_0TickLoaded_startingNotInitialized() public { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 103); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 103); ( int128[] memory deltaAmounts, @@ -282,7 +282,7 @@ contract QuoterTest is Test, Deployers { function testQuoter_quoteExactInput_2to1() public { tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 10000); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); ( int128[] memory deltaAmounts, @@ -298,7 +298,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token0); tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactInputParams memory params = getExactInputParams(tokenPath, 10000); + IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); ( int128[] memory deltaAmounts, @@ -352,7 +352,7 @@ contract QuoterTest is Test, Deployers { function testQuoter_quoteExactOutput_0to2_2TicksLoaded() public { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 15000); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 15000); ( int128[] memory deltaAmounts, @@ -369,7 +369,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 6143); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6143); ( int128[] memory deltaAmounts, @@ -386,7 +386,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 4000); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 4000); ( int128[] memory deltaAmounts, @@ -404,7 +404,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 100); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 100); // Tick 0 initialized. Tick after = 1 ( @@ -422,7 +422,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 10); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 10); ( int128[] memory deltaAmounts, @@ -438,7 +438,7 @@ contract QuoterTest is Test, Deployers { function testQuoter_quoteExactOutput_2to0_2TicksLoaded() public { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 15000); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 15000); ( int128[] memory deltaAmounts, @@ -456,7 +456,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 6223); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6223); ( int128[] memory deltaAmounts, @@ -474,7 +474,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 6000); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6000); ( int128[] memory deltaAmounts, uint160[] memory sqrtPriceX96AfterList, @@ -491,7 +491,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 9871); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 9871); ( int128[] memory deltaAmounts, @@ -510,7 +510,7 @@ contract QuoterTest is Test, Deployers { tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactOutputParams memory params = getExactOutputParams(tokenPath, 9745); + IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 9745); ( int128[] memory deltaAmounts, @@ -631,32 +631,32 @@ contract QuoterTest is Test, Deployers { function getExactInputParams(MockERC20[] memory _tokenPath, uint256 amountIn) internal view - returns (IQuoter.QuoteExactInputParams memory params) + returns (IQuoter.QuoteExactParams memory params) { PathKey[] memory path = new PathKey[](_tokenPath.length - 1); for (uint256 i = 0; i < _tokenPath.length - 1; i++) { path[i] = PathKey(Currency.wrap(address(_tokenPath[i + 1])), 3000, 60, IHooks(address(0)), bytes("")); } - params.currencyIn = Currency.wrap(address(_tokenPath[0])); + params.exactCurrency = Currency.wrap(address(_tokenPath[0])); params.path = path; params.recipient = address(this); - params.amountIn = uint128(amountIn); + params.exactAmount = uint128(amountIn); } function getExactOutputParams(MockERC20[] memory _tokenPath, uint256 amountOut) internal view - returns (IQuoter.QuoteExactOutputParams memory params) + returns (IQuoter.QuoteExactParams memory params) { PathKey[] memory path = new PathKey[](_tokenPath.length - 1); for (uint256 i = _tokenPath.length - 1; i > 0; i--) { path[i - 1] = PathKey(Currency.wrap(address(_tokenPath[i - 1])), 3000, 60, IHooks(address(0)), bytes("")); } - params.currencyOut = Currency.wrap(address(_tokenPath[_tokenPath.length - 1])); + params.exactCurrency = Currency.wrap(address(_tokenPath[_tokenPath.length - 1])); params.path = path; params.recipient = address(this); - params.amountOut = uint128(amountOut); + params.exactAmount = uint128(amountOut); } }