Skip to content

Commit

Permalink
move quoter structs into IQuoter interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Dec 6, 2023
1 parent cb15b3e commit 710705b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 116 deletions.
57 changes: 43 additions & 14 deletions contracts/interfaces/IQuoter.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.20;

import {
ExactInputSingleParams,
ExactInputParams,
ExactOutputSingleParams,
ExactOutputParams
} from "../libraries/SwapParameters.sol";
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol";
import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol";
import {PathKey} from "../libraries/PathKey.sol";

/// @title Quoter Interface
/// @notice Supports quoting the delta amounts from exact input or exact output swaps.
Expand All @@ -26,8 +22,41 @@ interface IQuoter {
int128 currency1Delta;
}

struct QuoteExactInputSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
uint128 amountIn;
uint160 sqrtPriceLimitX96;
bytes hookData;
}

struct QuoteExactInputParams {
Currency currencyIn;
PathKey[] path;
address recipient;
uint128 amountIn;
}

struct QuoteExactOutputSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
uint128 amountOut;
uint160 sqrtPriceLimitX96;
bytes hookData;
}

struct QuoteExactOutputParams {
Currency currencyOut;
PathKey[] path;
address recipient;
uint128 amountOut;
uint160 sqrtPriceLimitX96;
}

/// @notice Returns the delta amounts for a given exact input swap of a single pool
/// @param params The params for the quote, encoded as `ExactInputSingleParams`
/// @param params The params for the quote, encoded as `QuoteExactInputSingleParams`
/// poolKey The key for identifying a V4 pool
/// zeroForOne If the swap is from currency0 to currency1
/// recipient The indented recipient of the output tokens
Expand All @@ -37,20 +66,20 @@ interface IQuoter {
/// @return deltaAmounts Delta amounts resulted from the swap
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
/// @return initializedTicksLoaded The number of initialized ticks that the swap loaded
function quoteExactInputSingle(ExactInputSingleParams calldata params)
function quoteExactInputSingle(QuoteExactInputSingleParams calldata params)
external
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded);

/// @notice Returns the delta amounts along the swap path for a given exact input swap
/// @param params the params for the quote, encoded as 'ExactInputParams'
/// @param params the params for the quote, encoded as 'QuoteExactInputParams'
/// 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 indented recipient of the output tokens
/// amountIn 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(ExactInputParams memory params)
function quoteExactInput(QuoteExactInputParams memory params)
external
returns (
int128[] memory deltaAmounts,
Expand All @@ -59,7 +88,7 @@ interface IQuoter {
);

/// @notice Returns the delta amounts for a given exact output swap of a single pool
/// @param params The params for the quote, encoded as `ExactOutputSingleParams`
/// @param params The params for the quote, encoded as `QuoteExactOutputSingleParams`
/// poolKey The key for identifying a V4 pool
/// zeroForOne If the swap is from currency0 to currency1
/// recipient The indented recipient of the output tokens
Expand All @@ -69,20 +98,20 @@ interface IQuoter {
/// @return deltaAmounts Delta amounts resulted from the swap
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
/// @return initializedTicksLoaded The number of initialized ticks that the swap loaded
function quoteExactOutputSingle(ExactOutputSingleParams calldata params)
function quoteExactOutputSingle(QuoteExactOutputSingleParams calldata params)
external
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded);

/// @notice Returns the delta amounts along the swap path for a given exact output swap
/// @param params the params for the quote, encoded as 'ExactInputParams'
/// @param params the params for the quote, encoded as 'QuoteExactInputParams'
/// 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 indented recipient of the output tokens
/// amountOut 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(ExactOutputParams memory params)
function quoteExactOutput(QuoteExactOutputParams memory params)
external
returns (
int128[] memory deltaAmounts,
Expand Down
27 changes: 12 additions & 15 deletions contracts/lens/Quoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol";
import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol";
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol";
import {PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol";
import {
SwapType,
ExactInputSingleParams,
ExactInputParams,
ExactOutputSingleParams,
ExactOutputParams
} from "../libraries/SwapParameters.sol";
import {IQuoter} from "../interfaces/IQuoter.sol";
import {PoolTicksCounter} from "../libraries/PoolTicksCounter.sol";
import {PathKeyLib} from "../libraries/PathKey.sol";
Expand Down Expand Up @@ -53,7 +46,7 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @inheritdoc IQuoter
function quoteExactInputSingle(ExactInputSingleParams memory params)
function quoteExactInputSingle(QuoteExactInputSingleParams memory params)
public
override
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded)
Expand All @@ -65,7 +58,7 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @inheritdoc IQuoter
function quoteExactInput(ExactInputParams memory params)
function quoteExactInput(QuoteExactInputParams memory params)
external
returns (
int128[] memory deltaAmounts,
Expand All @@ -80,7 +73,7 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @inheritdoc IQuoter
function quoteExactOutputSingle(ExactOutputSingleParams memory params)
function quoteExactOutputSingle(QuoteExactOutputSingleParams memory params)
public
override
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded)
Expand All @@ -95,7 +88,7 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @inheritdoc IQuoter
function quoteExactOutput(ExactOutputParams memory params)
function quoteExactOutput(QuoteExactOutputParams memory params)
public
override
returns (
Expand Down Expand Up @@ -181,7 +174,7 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @dev quote an ExactInput swap along a path of tokens, then revert with the result
function _quoteExactInput(ExactInputParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactInput(QuoteExactInputParams memory params) public selfOnly returns (bytes memory) {
uint256 pathLength = params.path.length;

int128[] memory deltaAmounts = new int128[](pathLength + 1);
Expand Down Expand Up @@ -221,7 +214,7 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @dev quote an ExactInput swap on a pool, then revert with the result
function _quoteExactInputSingle(ExactInputSingleParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactInputSingle(QuoteExactInputSingleParams memory params) public selfOnly returns (bytes memory) {
(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap(
params.poolKey,
params.zeroForOne,
Expand All @@ -236,7 +229,7 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @dev quote an ExactOutput swap along a path of tokens, then revert with the result
function _quoteExactOutput(ExactOutputParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactOutput(QuoteExactOutputParams memory params) public selfOnly returns (bytes memory) {
uint256 pathLength = params.path.length;

int128[] memory deltaAmounts = new int128[](pathLength + 1);
Expand Down Expand Up @@ -278,7 +271,11 @@ contract Quoter is IQuoter, ILockCallback {
}

/// @dev quote an ExactOutput swap on a pool, then revert with the result
function _quoteExactOutputSingle(ExactOutputSingleParams memory params) public selfOnly returns (bytes memory) {
function _quoteExactOutputSingle(QuoteExactOutputSingleParams memory params)
public
selfOnly
returns (bytes memory)
{
(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap(
params.poolKey,
params.zeroForOne,
Expand Down
53 changes: 0 additions & 53 deletions contracts/libraries/SwapParameters.sol

This file was deleted.

Loading

0 comments on commit 710705b

Please sign in to comment.