Skip to content

Commit

Permalink
Merge branch 'main' into from-amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
marktoda authored Nov 21, 2024
2 parents a8a197f + d767807 commit 442cb28
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
12 changes: 6 additions & 6 deletions script/DeployQuoter.s.sol → script/DeployV4Quoter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 <RPC_URL> --private-key <PRIV_KEY> --verify script/DeployQuoter.s.sol:DeployQuoter <POOL_MANAGER_ADDR>
state = new Quoter(IPoolManager(poolManager));
console2.log("Quoter", address(state));
// forge script --broadcast --sig 'run(address)' --rpc-url <RPC_URL> --private-key <PRIV_KEY> --verify script/DeployV4Quoter.s.sol:DeployV4Quoter <POOL_MANAGER_ADDR>
state = new V4Quoter(IPoolManager(poolManager));
console2.log("V4Quoter", address(state));
console2.log("PoolManager", address(state.poolManager()));

vm.stopBroadcast();
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/IQuoter.sol → src/interfaces/IV4Quoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/lens/Quoter.sol → src/lens/V4Quoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -31,7 +31,7 @@ contract Quoter is IQuoter, BaseV4Quoter {
}
}

/// @inheritdoc IQuoter
/// @inheritdoc IV4Quoter
function quoteExactInput(QuoteExactParams memory params)
external
returns (uint256 amountOut, uint256 gasEstimate)
Expand All @@ -45,7 +45,7 @@ contract Quoter is IQuoter, BaseV4Quoter {
}
}

/// @inheritdoc IQuoter
/// @inheritdoc IV4Quoter
function quoteExactOutputSingle(QuoteExactSingleParams memory params)
external
returns (uint256 amountIn, uint256 gasEstimate)
Expand All @@ -59,7 +59,7 @@ contract Quoter is IQuoter, BaseV4Quoter {
}
}

/// @inheritdoc IQuoter
/// @inheritdoc IV4Quoter
function quoteExactOutput(QuoteExactParams memory params)
external
returns (uint256 amountIn, uint256 gasEstimate)
Expand Down
62 changes: 31 additions & 31 deletions test/Quoter.t.sol → test/V4Quoter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -40,7 +40,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot {

uint256 internal constant CONTROLLER_GAS_LIMIT = 500000;

Quoter quoter;
V4Quoter quoter;

PoolModifyLiquidityTest positionManager;

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

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

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

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

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

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

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

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

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

Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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);

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

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

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

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

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

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

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

Expand Down Expand Up @@ -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++) {
Expand All @@ -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--) {
Expand Down

0 comments on commit 442cb28

Please sign in to comment.