Quote

Function Interface introduction

1. quoteExactInput

  1. Contract Interface

  2. function quoteExactInput(bytes memory path, uint256 amountIn)        
        external            
        returns (            
            uint256 amountOut,
            uint160[] memory sqrtPriceX96AfterList,
            uint32[] memory initializedTicksCrossedList,
            uint256 gasEstimate
        );
  3. Param Explanation

    • path(bytes): A byte array encoding the token swap path and any additional data needed for the swap. This typically includes the addresses of the tokens in the swap path and may include other data specific to the swap routing.

    • amountIn(uint256): This is the amount of the initial token that you are willing to swap. If you set this to 0, the contract will use the balance of the token that it holds at the time of the swap as the input amount, which allows for a pattern where tokens are sent to the contract before the swap is executed.

2. quoteExactInputSingle

  1. Contract Interface

  2. struct QuoteExactInputSingleParams {
            address tokenIn;
            address tokenOut;
            uint256 amountIn;
            uint24 fee;
            uint160 sqrtPriceLimitX96;
        }
    
    /// @notice Returns the amount out received for a given exact input but for a swap of a single pool
    /// @param params The params for the quote, encoded as `QuoteExactInputSingleParams`
    /// tokenIn The token being swapped in
    /// tokenOut The token being swapped out
    /// fee The fee of the token pool to consider for the pair
    /// amountIn The desired input amount
    /// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
    /// @return amountOut The amount of `tokenOut` that would be received
    /// @return sqrtPriceX96After The sqrt price of the pool after the swap
    /// @return initializedTicksCrossed The number of initialized ticks that the swap crossed
    /// @return gasEstimate The estimate of the gas that the swap consumes
    function quoteExactInputSingle(QuoteExactInputSingleParams memory params)
        external
        returns (
            uint256 amountOut,
            uint160 sqrtPriceX96After,
            uint32 initializedTicksCrossed,
            uint256 gasEstimate
        );
  3. Param Explanation

    • tokenIn (address): This is the contract address of the token that you are sending to the swap. It represents the "input" token in the trade.

    • tokenOut (address): This is the contract address of the token that you want to receive from the swap. This is the "output" token in the trade.

    • fee (uint24): This is the fee amount that will be paid for the swap, denoted in basis points. The fee is typically a small percentage of the trade amount, and it is paid to the liquidity providers of the pool.

    • amountIn (uint256): This is the amount of tokenIn that you want to swap. If you set amountIn to 0, the contract will use its own balance of tokenIn as the amount to be swapped.

    • sqrtPriceLimitX96 (uint160): This is a limit on the price to which the swap will occur. It's the square root of the price encoded in a fixed-point format. If the price exceeds this limit, the swap will not execute. This can be used to specify the worst exchange rate you are willing to accept for the swap, providing additional protection against slippage.

3. quoteExactOutput

  1. Contract Interface

  2. /// @notice Returns the amount in required for a given exact output swap without executing the swap
    /// @param path The path of the swap, i.e. each token pair and the pool fee. Path must be provided in reverse order
    /// @param amountOut The amount of the last token to receive
    /// @return amountIn The amount of first token required to be paid
    /// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
    /// @return initializedTicksCrossedList List of the initialized ticks that the swap crossed for each pool in the path
    /// @return gasEstimate The estimate of the gas that the swap consumes
    function quoteExactOutput(bytes memory path, uint256 amountOut)
        external
        returns (
            uint256 amountIn,
            uint160[] memory sqrtPriceX96AfterList,
            uint32[] memory initializedTicksCrossedList,
            uint256 gasEstimate
        );
  • Param Explanation

    • path(bytes): A byte array encoding the token swap path and any additional data needed for the swap. This typically includes the addresses of the tokens in the swap path and may include other data specific to the swap routing.

    • amountOut (uint256): The exact amount of the final token that you want to receive. This is the target amount that dictates the swap's execution.

4. quoteExactOutputSingle

  1. Contract Interface

  2. struct QuoteExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint256 amount;
        uint24 fee;
        uint160 sqrtPriceLimitX96;
    }
    
    /// @notice Returns the amount in required to receive the given exact output amount but for a swap of a single pool
    /// @param params The params for the quote, encoded as `QuoteExactOutputSingleParams`
    /// tokenIn The token being swapped in
    /// tokenOut The token being swapped out
    /// fee The fee of the token pool to consider for the pair
    /// amountOut The desired output amount
    /// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
    /// @return amountIn The amount required as the input for the swap in order to receive `amountOut`
    /// @return sqrtPriceX96After The sqrt price of the pool after the swap
    /// @return initializedTicksCrossed The number of initialized ticks that the swap crossed
    /// @return gasEstimate The estimate of the gas that the swap consumes
    function quoteExactOutputSingle(QuoteExactOutputSingleParams memory params)
        external
        returns (
            uint256 amountIn,
            uint160 sqrtPriceX96After,
            uint32 initializedTicksCrossed,
            uint256 gasEstimate
        );
  • Param Explanation

    • tokenIn (address): The contract address of the token you are providing in the swap. This is what you are swapping away.

    • tokenOut (address): The contract address of the token you want to receive from the swap. This is what you are swapping for.

    • fee (uint24): The fee associated with the pool from which you're swapping your tokens, represented in basis points. This fee is paid to liquidity providers of the pool.

    • amountOut (uint256): The exact amount of tokenOut that you wish to receive from the swap.

    • sqrtPriceLimitX96 (uint160): A price limit in the form of the square root of the price, encoded in a fixed-point format. The swap will not occur if the price is worse than this price limit, which means you cannot be forced to accept a swap at an unfavorable rate.

Last updated