From 983e775ffd5359fbe8a0da5af8c3947dd65e1068 Mon Sep 17 00:00:00 2001 From: gretzke Date: Mon, 18 Nov 2024 16:44:00 +0100 Subject: [PATCH] Rename quoter --- ...eployQuoter.s.sol => DeployV4Quoter.s.sol} | 12 ++-- src/interfaces/{IQuoter.sol => IV4Quoter.sol} | 4 +- src/lens/{Quoter.sol => V4Quoter.sol} | 12 ++-- test/{Quoter.t.sol => V4Quoter.t.sol} | 62 +++++++++---------- 4 files changed, 45 insertions(+), 45 deletions(-) rename script/{DeployQuoter.s.sol => DeployV4Quoter.s.sol} (53%) rename src/interfaces/{IQuoter.sol => IV4Quoter.sol} (98%) rename src/lens/{Quoter.sol => V4Quoter.sol} (96%) rename test/{Quoter.t.sol => V4Quoter.t.sol} (89%) diff --git a/script/DeployQuoter.s.sol b/script/DeployV4Quoter.s.sol similarity index 53% rename from script/DeployQuoter.s.sol rename to script/DeployV4Quoter.s.sol index 501f77611..1c6a8430e 100644 --- a/script/DeployQuoter.s.sol +++ b/script/DeployV4Quoter.s.sol @@ -5,17 +5,17 @@ import "forge-std/console2.sol"; import "forge-std/Script.sol"; import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; -import {Quoter} from "../src/lens/Quoter.sol"; +import {V4Quoter} from "../src/lens/V4Quoter.sol"; -contract DeployQuoter is Script { +contract DeployV4Quoter is Script { function setUp() public {} - function run(address poolManager) public returns (Quoter state) { + function run(address poolManager) public returns (V4Quoter state) { vm.startBroadcast(); - // forge script --broadcast --sig 'run(address)' --rpc-url --private-key --verify script/DeployQuoter.s.sol:DeployQuoter - state = new Quoter(IPoolManager(poolManager)); - console2.log("Quoter", address(state)); + // forge script --broadcast --sig 'run(address)' --rpc-url --private-key --verify script/DeployV4Quoter.s.sol:DeployV4Quoter + state = new V4Quoter(IPoolManager(poolManager)); + console2.log("V4Quoter", address(state)); console2.log("PoolManager", address(state.poolManager())); vm.stopBroadcast(); diff --git a/src/interfaces/IQuoter.sol b/src/interfaces/IV4Quoter.sol similarity index 98% rename from src/interfaces/IQuoter.sol rename to src/interfaces/IV4Quoter.sol index 9815d74b7..a8483a894 100644 --- a/src/interfaces/IQuoter.sol +++ b/src/interfaces/IV4Quoter.sol @@ -5,12 +5,12 @@ import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; import {Currency} from "@uniswap/v4-core/src/types/Currency.sol"; import {PathKey} from "../libraries/PathKey.sol"; -/// @title Quoter Interface +/// @title V4 Quoter Interface /// @notice Supports quoting the delta amounts for exact input or exact output swaps. /// @notice For each pool also tells you the sqrt price of the pool after the swap. /// @dev These functions are not marked view because they rely on calling non-view functions and reverting /// to compute the result. They are also not gas efficient and should not be called on-chain. -interface IQuoter { +interface IV4Quoter { struct QuoteExactSingleParams { PoolKey poolKey; bool zeroForOne; diff --git a/src/lens/Quoter.sol b/src/lens/V4Quoter.sol similarity index 96% rename from src/lens/Quoter.sol rename to src/lens/V4Quoter.sol index fd1597978..1623ff59b 100644 --- a/src/lens/Quoter.sol +++ b/src/lens/V4Quoter.sol @@ -6,18 +6,18 @@ import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; import {Currency} from "@uniswap/v4-core/src/types/Currency.sol"; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol"; -import {IQuoter} from "../interfaces/IQuoter.sol"; +import {IV4Quoter} from "../interfaces/IV4Quoter.sol"; import {PathKey, PathKeyLibrary} from "../libraries/PathKey.sol"; import {QuoterRevert} from "../libraries/QuoterRevert.sol"; import {BaseV4Quoter} from "../base/BaseV4Quoter.sol"; -contract Quoter is IQuoter, BaseV4Quoter { +contract V4Quoter is IV4Quoter, BaseV4Quoter { using PathKeyLibrary for PathKey; using QuoterRevert for *; constructor(IPoolManager _poolManager) BaseV4Quoter(_poolManager) {} - /// @inheritdoc IQuoter + /// @inheritdoc IV4Quoter function quoteExactInputSingle(QuoteExactSingleParams memory params) external returns (uint256 amountOut, uint256 gasEstimate) @@ -31,7 +31,7 @@ contract Quoter is IQuoter, BaseV4Quoter { } } - /// @inheritdoc IQuoter + /// @inheritdoc IV4Quoter function quoteExactInput(QuoteExactParams memory params) external returns (uint256 amountOut, uint256 gasEstimate) @@ -45,7 +45,7 @@ contract Quoter is IQuoter, BaseV4Quoter { } } - /// @inheritdoc IQuoter + /// @inheritdoc IV4Quoter function quoteExactOutputSingle(QuoteExactSingleParams memory params) external returns (uint256 amountIn, uint256 gasEstimate) @@ -59,7 +59,7 @@ contract Quoter is IQuoter, BaseV4Quoter { } } - /// @inheritdoc IQuoter + /// @inheritdoc IV4Quoter function quoteExactOutput(QuoteExactParams memory params) external returns (uint256 amountIn, uint256 gasEstimate) diff --git a/test/Quoter.t.sol b/test/V4Quoter.t.sol similarity index 89% rename from test/Quoter.t.sol rename to test/V4Quoter.t.sol index 2dc1c8540..26b62d102 100644 --- a/test/Quoter.t.sol +++ b/test/V4Quoter.t.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.20; 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 {IV4Quoter} from "../src/interfaces/IV4Quoter.sol"; +import {V4Quoter} from "../src/lens/V4Quoter.sol"; import {BaseV4Quoter} from "../src/base/BaseV4Quoter.sol"; import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol"; @@ -40,7 +40,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { uint256 internal constant CONTROLLER_GAS_LIMIT = 500000; - Quoter quoter; + V4Quoter quoter; PoolModifyLiquidityTest positionManager; @@ -56,7 +56,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function setUp() public { deployFreshManagerAndRouters(); - quoter = new Quoter(IPoolManager(manager)); + quoter = new V4Quoter(IPoolManager(manager)); positionManager = new PoolModifyLiquidityTest(manager); // salts are chosen so that address(token0) < address(token1) && address(token1) < address(token2) @@ -86,7 +86,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { uint256 expectedAmountOut = 9871; (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInputSingle( - IQuoter.QuoteExactSingleParams({ + IV4Quoter.QuoteExactSingleParams({ poolKey: key02, zeroForOne: true, exactAmount: uint128(amountIn), @@ -105,7 +105,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { uint256 expectedAmountOut = 9871; (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInputSingle( - IQuoter.QuoteExactSingleParams({ + IV4Quoter.QuoteExactSingleParams({ poolKey: key02, zeroForOne: false, exactAmount: uint128(amountIn), @@ -122,7 +122,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactInput_0to2_2TicksLoaded() public { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -137,7 +137,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { // 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.QuoteExactParams memory params = getExactInputParams(tokenPath, 6200); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 6200); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -152,7 +152,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { // 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.QuoteExactParams memory params = getExactInputParams(tokenPath, 4000); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 4000); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -166,7 +166,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactInput_0to2_0TickLoaded_startingNotInitialized() public { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -179,7 +179,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { setupPoolWithZeroTickInitialized(key02); tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -191,7 +191,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactInput_2to0_2TicksLoaded() public { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -206,7 +206,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { // 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.QuoteExactParams memory params = getExactInputParams(tokenPath, 6250); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 6250); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -221,7 +221,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { setupPoolWithZeroTickInitialized(key02); tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 200); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 200); // Tick 0 initialized. Tick after = 1 (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -237,7 +237,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactInput_2to0_0TickLoaded_startingNotInitialized() public { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 103); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 103); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -249,7 +249,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactInput_2to1() public { tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); assertGt(gasEstimate, 50000); @@ -261,7 +261,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token0); tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); + IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 10000); (uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params); @@ -275,7 +275,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactOutputSingle_0to1() public { uint256 amountOut = 10000; (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutputSingle( - IQuoter.QuoteExactSingleParams({ + IV4Quoter.QuoteExactSingleParams({ poolKey: key01, zeroForOne: true, exactAmount: uint128(amountOut), @@ -292,7 +292,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactOutputSingle_1to0() public { uint256 amountOut = 10000; (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutputSingle( - IQuoter.QuoteExactSingleParams({ + IV4Quoter.QuoteExactSingleParams({ poolKey: key01, zeroForOne: false, exactAmount: uint128(amountOut), @@ -309,7 +309,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactOutput_0to2_2TicksLoaded() public { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 15000); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 15000); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -323,7 +323,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6143); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6143); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -337,7 +337,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 4000); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 4000); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -352,7 +352,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 100); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 100); // Tick 0 initialized. Tick after = 1 (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -367,7 +367,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token0); tokenPath.push(token2); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 10); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 10); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -379,7 +379,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function testQuoter_quoteExactOutput_2to0_2TicksLoaded() public { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 15000); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 15000); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -392,7 +392,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6223); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6223); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -405,7 +405,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token2); tokenPath.push(token0); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6000); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 6000); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); assertGt(gasEstimate, 50000); @@ -417,7 +417,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 9871); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 9871); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -431,7 +431,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { tokenPath.push(token2); tokenPath.push(token1); - IQuoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 9745); + IV4Quoter.QuoteExactParams memory params = getExactOutputParams(tokenPath, 9745); (uint256 amountIn, uint256 gasEstimate) = quoter.quoteExactOutput(params); @@ -548,7 +548,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function getExactInputParams(MockERC20[] memory _tokenPath, uint256 amountIn) internal pure - returns (IQuoter.QuoteExactParams memory params) + returns (IV4Quoter.QuoteExactParams memory params) { PathKey[] memory path = new PathKey[](_tokenPath.length - 1); for (uint256 i = 0; i < _tokenPath.length - 1; i++) { @@ -563,7 +563,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot { function getExactOutputParams(MockERC20[] memory _tokenPath, uint256 amountOut) internal pure - returns (IQuoter.QuoteExactParams memory params) + returns (IV4Quoter.QuoteExactParams memory params) { PathKey[] memory path = new PathKey[](_tokenPath.length - 1); for (uint256 i = _tokenPath.length - 1; i > 0; i--) {