Smart Router
Function Interface introduction
1. exactInputSingle
Contract Interface
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.recipient (
address
): This is the address that will receive thetokenOut
after the swap is completed. It could be the address of the caller, or another address if the caller is performing the swap on behalf of someone else.amountIn (
uint256
): This is the amount oftokenIn
that you want to swap. If you setamountIn
to 0, the contract will use its own balance oftokenIn
as the amount to be swapped.amountOutMinimum (
uint256
): This is the minimum amount oftokenOut
that you are willing to accept for your swap. If the swap cannot satisfy this minimum, the transaction should fail. This protects against slippage or unfavorable price movements during the swap.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.
2. exactInput
Contract Interface
Param Explanation
path (
bytes
): This is an encoded byte array that represents the swap path you want to take. It includes the sequence of token addresses that you will swap through and the fees for each pool in the path. The path must start with the address of the token you are giving and end with the address of the token you want to receive.recipient (
address
): This is the address that will receive the output token once the swap is complete. This can be the address of the person or contract that is initiating the swap, or it could be a different address if you are conducting the swap on someone else's behalf.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.amountOutMinimum (
uint256
): This is the minimum amount of the final token in the swap path that you are willing to accept for your initial tokens. If the swap cannot achieve this minimum amount due to price changes or slippage, the transaction should revert. This parameter helps to manage slippage risk and ensures that you receive at least this amount or the transaction fails.
3. exactOutputSingle
Contract Interface
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.recipient (
address
): The address that will receive thetokenOut
after the swap has been completed. This could be your own address or the address of someone else if you're performing the swap on their behalf.amountOut (
uint256
): The exact amount oftokenOut
that you wish to receive from the swap.amountInMaximum (uint256): The maximum amount of
tokenIn
that you are willing to spend to receive theamountOut
. This acts as a cap to protect you from spending too much in case of unfavorable price movements or slippage.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.
4. exactOutput
Contract Interface
Param Explanation
path (
bytes
): This is an encoded byte array specifying the path of tokens to swap through, reversed from the final token to the initial token. It includes the sequence of token addresses and pool fees for each intermediate swap.recipient (
address
): The address that will receive the final output token once the swap is completed. This can be your own address or another address if you are executing the swap on behalf of someone else.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.amountInMaximum (
uint256
): The maximum amount of the initial token that you are willing to spend to obtain theamountOut
. This parameter sets the upper limit on what you are prepared to trade away, providing protection against high slippage or unfavorable price changes.
Last updated