Comment on page
Trade
Represents a trade where a proportion of the trade can be routed via similar pair pools which consist of the input and output token. A Trade instance is created on the assumption that trade simulation has been correctly carried out elsewhere.
Property | Type | Modifier | Description |
---|---|---|---|
swaps | {}[] | readonly | Array of objects, each representing a swap that makes up the trade. Each swap contains:
route: Route <TInput, TOutput> = The swap route.
inputAmount: CurrencyAmount = The input token for the swap.
outputAmount: CurrencyAmount = The output token for the swap. |
tradeType | TTradeType | readonly | The type of trade: exact in OR exact out. |
input | TInput | readonly | The input token for the swap. |
output | TOutput | readonly | The output token for the swap. |
Property | Type | Description |
---|---|---|
_inputAmount | The cached result of the input amount computation. | |
_outputAmount | The cached result of the output amount computation. | |
_executionPrice | The cached result of the computed execution price. | |
_priceImpact | The cached result of the price impact calculation. |
The Trade class implements a private constructor whose validation logic is enforced via the
createUncheckedTrade()
static factory method.Params | Type | Description |
---|---|---|
{} | object | An object consisting of:
routes: {}[] = Array of swaps which makes up the trade.
tradeType: TTradeType = The type of trade: exact in OR exact out. |
tradeType | TTradeType | The type of trade: exact in OR exact out. |
Creates a Trade instance with a single hop. Does not validate the result of swapping through the route and is meant to be used when trade simulation has been done elsewhere.
Params | Type | Description |
---|---|---|
constructorArguments | {} | An object representing a single swap:
route: Route <TInput, TOutput> = The swap route.
inputAmount: CurrencyAmount = The input token for the swap.
outputAmount: CurrencyAmount = The output token for the swap.
tradeType: TTradeType = The type of trade: exact in OR exact out |
Type | Description |
---|---|
Trade<TInput, TOutput, TTradeType> | A new Trade instance consisting of the single hop unchecked trade. |
Returns the mid price of the route.
Type | Description |
---|---|
The mid price of the route. |
Returns the amount of input tokens for the trade assuming no slippage.
Type | Description |
---|---|
The amount of input token for the trade. |
Returns the amount of output tokens resulting from the trade assuming no slippage.
Type | Description |
---|---|
The amount of output tokens for the trade assuming no slippage. |
The price which the trade is executed at denoted in
.
Type | Description |
---|---|
The execution price of the trade. |
Returns the percentage price difference between the route's mid price and the executed price (i.e. the price impact).
Type | Description |
---|---|
Percent | The price impact denoted in % of the executed price. |
Given a slippage tolerance value, returns the minimum amount of output tokens resulting from this trade.
Params | Type | Description |
---|---|---|
slippageTolerance | The % amount that the final executed price can differ from the expected price before the transaction will revert. | |
amountOut | The amount of output tokens required for the trade. Used when trade type is exact out. Default is this.amountOut . |
Type | Description |
---|---|
The minimum amount of output tokens for the trade. |
Given a slippage tolerance value, returns the maximum amount of input tokens that the trade requires to be executed successfully.
Params | Type | Description |
---|---|---|
slippageTolerance | The % amount that the final executed price can differ from the expected price before the transaction will revert. | |
amountIn | The amount of input tokens for the trade. Used when trade type is exact in. Default is this.amountIn . |
Type | Description |
---|---|
The maximum amount of input tokens for the trade. |
Given a slippage tolerance value, returns the worst price that the trade can be executed at.
Params | Type | Description |
---|---|---|
slippageTolerance | The % amount that the final executed price can differ from the expected price before the transaction will revert. |
Type | Description |
---|---|
The worst price that the trade can be executed at. |
Last modified 2mo ago