VinuSwapQuoter

The VinuSwapQuoter simulates swaps to return expected amounts without executing on-chain.

Source: contracts/periphery/VinuSwapQuoter.sol

Overview

The quoter:

  • Estimates swap output amounts

  • Returns price impact information

  • Provides gas cost estimates via tick crossing counts

  • Uses a revert-based simulation pattern

How It Works

The quoter performs a "dry run" of swaps by:

  1. Calling the pool's swap function

  2. Reverting in the callback with encoded results

  3. Catching the revert and decoding the results

This allows simulation without state changes or token transfers.

Functions

quoteExactInputSingle

Quotes the output amount for an exact input single swap.

Parameters Struct:

Name
Type
Description

tokenIn

address

Input token address

tokenOut

address

Output token address

amountIn

uint256

Exact input amount

fee

uint24

Pool fee tier

sqrtPriceLimitX96

uint160

Price limit (0 for none)

Returns:

Name
Type
Description

amountOut

uint256

Expected output amount

sqrtPriceX96After

uint160

Price after swap

initializedTicksCrossed

uint32

Number of ticks crossed

gasEstimate

uint256

Estimated gas cost

Example:


quoteExactInput

Quotes the output amount for a multi-hop exact input swap.

Parameters:

Name
Type
Description

path

bytes

Encoded swap path

amountIn

uint256

Exact input amount

Returns:

Name
Type
Description

amountOut

uint256

Expected final output

sqrtPriceX96AfterList

uint160[]

Prices after each hop

initializedTicksCrossedList

uint32[]

Ticks crossed per hop

gasEstimate

uint256

Total estimated gas

Example:


quoteExactOutputSingle

Quotes the input amount needed for an exact output single swap.

Parameters Struct:

Name
Type
Description

tokenIn

address

Input token address

tokenOut

address

Output token address

amount

uint256

Exact output amount wanted

fee

uint24

Pool fee tier

sqrtPriceLimitX96

uint160

Price limit (0 for none)

Returns:

Name
Type
Description

amountIn

uint256

Required input amount

sqrtPriceX96After

uint160

Price after swap

initializedTicksCrossed

uint32

Number of ticks crossed

gasEstimate

uint256

Estimated gas cost

Example:


quoteExactOutput

Quotes the input amount needed for a multi-hop exact output swap.

Note: Path is encoded in reverse order (output token first).

Parameters:

Name
Type
Description

path

bytes

Encoded swap path (reversed)

amountOut

uint256

Exact output amount wanted

Returns:

Name
Type
Description

amountIn

uint256

Required input amount

sqrtPriceX96AfterList

uint160[]

Prices after each hop

initializedTicksCrossedList

uint32[]

Ticks crossed per hop

gasEstimate

uint256

Total estimated gas

Path Encoding

Exact Input Path

Encode tokens and fees in order:

Exact Output Path (Reversed)

Understanding Return Values

sqrtPriceX96After

The pool price after the swap in Q64.96 format:

initializedTicksCrossed

Number of tick boundaries crossed. Useful for:

  • Estimating gas costs (more ticks = more gas)

  • Understanding liquidity depth

gasEstimate

Estimated gas cost based on:

  • Base swap cost

  • Per-tick crossing cost

  • Path length (for multi-hop)

Usage Patterns

Compare Routes

Calculate Slippage

Estimate Gas Cost

Important Notes

Static Calls Required

Always use callStatic when calling quoter functions:

No State Changes

Quotes are simulations. Actual swap amounts may differ due to:

  • Price movements between quote and execution

  • MEV/frontrunning

  • Fee manager changes

Gas Limitations

Large swaps crossing many ticks may exceed block gas limits in simulation. Consider splitting into smaller amounts.

Interface

Last updated