Skip to content

Commit

Permalink
Merge branch 'main' into update-native-snaps
Browse files Browse the repository at this point in the history
  • Loading branch information
marktoda committed Nov 20, 2024
2 parents 969a190 + d767807 commit ae07b9e
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";

// v4-core
Expand Down Expand Up @@ -39,7 +39,7 @@ contract QuoterTest is Test, Deployers {

uint256 internal constant CONTROLLER_GAS_LIMIT = 500000;

Quoter quoter;
V4Quoter quoter;

PoolModifyLiquidityTest positionManager;

Expand All @@ -55,7 +55,7 @@ contract QuoterTest is Test, Deployers {

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 @@ -85,7 +85,7 @@ contract QuoterTest is Test, Deployers {
uint256 expectedAmountOut = 9871;

(uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInputSingle(
IQuoter.QuoteExactSingleParams({
IV4Quoter.QuoteExactSingleParams({
poolKey: key02,
zeroForOne: true,
exactAmount: uint128(amountIn),
Expand All @@ -104,7 +104,7 @@ contract QuoterTest is Test, Deployers {
uint256 expectedAmountOut = 9871;

(uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInputSingle(
IQuoter.QuoteExactSingleParams({
IV4Quoter.QuoteExactSingleParams({
poolKey: key02,
zeroForOne: false,
exactAmount: uint128(amountIn),
Expand All @@ -121,7 +121,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -136,7 +136,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.QuoteExactParams memory params = getExactInputParams(tokenPath, 6200);
IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 6200);

(uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params);

Expand All @@ -151,7 +151,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.QuoteExactParams memory params = getExactInputParams(tokenPath, 4000);
IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 4000);

(uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params);

Expand All @@ -165,7 +165,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -178,7 +178,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -190,7 +190,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -205,7 +205,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.QuoteExactParams memory params = getExactInputParams(tokenPath, 6250);
IV4Quoter.QuoteExactParams memory params = getExactInputParams(tokenPath, 6250);

(uint256 amountOut, uint256 gasEstimate) = quoter.quoteExactInput(params);

Expand All @@ -220,7 +220,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -236,7 +236,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -248,7 +248,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -260,7 +260,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -274,7 +274,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -291,7 +291,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -308,7 +308,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -322,7 +322,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -336,7 +336,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -351,7 +351,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -366,7 +366,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -378,7 +378,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -391,7 +391,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -404,7 +404,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -416,7 +416,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -430,7 +430,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -547,7 +547,7 @@ contract QuoterTest is Test, Deployers {
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 @@ -562,7 +562,7 @@ contract QuoterTest is Test, Deployers {
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 ae07b9e

Please sign in to comment.