⚪Getting a quote
Quote Interface Overview
The Quote interface comprises a set of functions that allow you to obtain estimated swap amounts based on various trade scenarios. It takes into account the trade type, tokens being swapped, token reserves, and trade amounts to provide accurate estimates. Before utilizing the Quote interface, familiarize yourself with the following core components:
TradeType Enum
The TradeType
enum defines the types of trades that can be executed:
EXACT_INPUT
: Specifies that the input token amount is fixed, and the output token amount may vary.EXACT_OUTPUT
: Specifies that the output token amount is fixed, and the input token amount may vary.
PoolState Type
The PoolState
type encapsulates the state of a liquidity pool and consists of the following properties:
reserve
: The reserve amount of the token being traded.ethReserve
: The Ether (ETH) reserve amount in the pool.
SwapAmount Type
The SwapAmount
type represents the result of a swap and includes:
amount
: The estimated output token amount after the swap.priceImpact
: An indication of the price impact of the swap, represented as a percentage.
Using the Quote Interface
To utilize the Quote interface and obtain swap amount estimates, you'll need to call the getSwapAmounts
function. The function signature is as follows:
Example Usage
Here's an example usage of the getSwapAmounts
function:
If you want to swap the native token (e.g., Ether), you can use xfai.nativeToken
as the input token. The native token or the wrapped version of the native token does not require pool state information, and you can include it in the tokenIn
parameter as follows:
Last updated