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.
GitHub File: trade.ts
Extends
Properties
Public
Property | Type | Modifier | Description |
---|---|---|---|
swaps | {}[] | readonly | Array of objects, each representing a swap that makes up the trade. Each swap contains:
|
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. |
Private
Property | Type | Description |
---|---|---|
_inputAmount | CurrencyAmount<TInput> | The cached result of the input amount computation. |
_outputAmount | CurrencyAmount<TOutput> | The cached result of the output amount computation. |
_executionPrice | Price<TInput, TOutput> | The cached result of the computed execution price. |
_priceImpact | Percent | undefined | The cached result of the price impact calculation. |
Constructor
The Trade class implements a private constructor whose validation logic is enforced via the createUncheckedTrade()
static factory method.
Parameters
Params | Type | Description |
---|---|---|
{} | object | An object consisting of:
|
tradeType | TTradeType | The type of trade: exact in OR exact out. |
Methods
createUncheckedTrade() - public
static
public
static
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.
Parameters
Params | Type | Description |
---|---|---|
constructorArguments | {} | An object representing a single swap:
|
Returns
Type | Description |
---|---|
Trade<TInput, TOutput, TTradeType> | A new Trade instance consisting of the single hop unchecked trade. |
inputAmount() - public
get
public
get
Returns the mid price of the route.
Returns
Type | Description |
---|---|
Price<TInput, TOutput> | The mid price of the route. |
inputAmount() - public
get
public
get
Returns the amount of input tokens for the trade assuming no slippage.
Returns
Type | Description |
---|---|
CurrencyAmount<TInput> | The amount of input token for the trade. |
outputAmount() - public
get
public
get
Returns the amount of output tokens resulting from the trade assuming no slippage.
Returns
Type | Description |
---|---|
CurrencyAmount<TOutput> | The amount of output tokens for the trade assuming no slippage. |
executionPrice() - public
get
public
get
The price which the trade is executed at denoted in .
Returns
Type | Description |
---|---|
Price<TInput, TOutput> | The execution price of the trade. |
priceImpact() - public
get
public
get
Returns the percentage price difference between the route's mid price and the executed price (i.e. the price impact).
Returns
Type | Description |
---|---|
Percent | The price impact denoted in % of the executed price. |
minimumAmountOut() - public
public
Given a slippage tolerance value, returns the minimum amount of output tokens resulting from this trade.
Parameters
Params | Type | Description |
---|---|---|
slippageTolerance | The % amount that the final executed price can differ from the expected price before the transaction will revert. | |
amountOut | CurrencyAmount<TOutput> | The amount of output tokens required for the trade. Used when trade type is exact out. Default is |
Returns
Type | Description |
---|---|
CurrencyAmount<TOutput> | The minimum amount of output tokens for the trade. |
maximumAmountIn() - public
public
Given a slippage tolerance value, returns the maximum amount of input tokens that the trade requires to be executed successfully.
Parameters
Params | Type | Description |
---|---|---|
slippageTolerance | The % amount that the final executed price can differ from the expected price before the transaction will revert. | |
amountIn | CurrencyAmount<TOutput> | The amount of input tokens for the trade. Used when trade type is exact in. Default is |
Returns
Type | Description |
---|---|
CurrencyAmount<TOutput> | The maximum amount of input tokens for the trade. |
worstExecutionPrice() - public
public
Given a slippage tolerance value, returns the worst price that the trade can be executed at.
Parameters
Params | Type | Description |
---|---|---|
slippageTolerance | The % amount that the final executed price can differ from the expected price before the transaction will revert. |
Returns
Type | Description |
---|---|
CurrencyAmount<TOutput> | The worst price that the trade can be executed at. |
Last updated