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

PropertyTypeModifierDescription

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.

Private

PropertyTypeDescription

_inputAmount

The cached result of the input amount computation.

_outputAmount

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

ParamsTypeDescription

{}

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.

Methods

createUncheckedTrade() - 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

ParamsTypeDescription

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

Returns

TypeDescription

Trade<TInput, TOutput, TTradeType>

A new Trade instance consisting of the single hop unchecked trade.


inputAmount() - public get

Returns the mid price of the route.

Returns

TypeDescription

Price<TInput, TOutput>

The mid price of the route.


inputAmount() - public get

Returns the amount of input tokens for the trade assuming no slippage.

Returns

TypeDescription

The amount of input token for the trade.


outputAmount() - public get

Returns the amount of output tokens resulting from the trade assuming no slippage.

Returns

TypeDescription

The amount of output tokens for the trade assuming no slippage.


executionPrice() - public get

The price which the trade is executed at denoted in outputAmountinputAmount\frac{outputAmount}{inputAmount}.

Returns

TypeDescription

Price<TInput, TOutput>

The execution price of the trade.


priceImpact() - public get

Returns the percentage price difference between the route's mid price and the executed price (i.e. the price impact).

Returns

TypeDescription

Percent

The price impact denoted in % of the executed price.


minimumAmountOut() - public

Given a slippage tolerance value, returns the minimum amount of output tokens resulting from this trade.

Parameters

ParamsTypeDescription

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.

Returns

TypeDescription

The minimum amount of output tokens for the trade.


maximumAmountIn() - public

Given a slippage tolerance value, returns the maximum amount of input tokens that the trade requires to be executed successfully.

Parameters

ParamsTypeDescription

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.

Returns

TypeDescription

The maximum amount of input tokens for the trade.


worstExecutionPrice() - public

Given a slippage tolerance value, returns the worst price that the trade can be executed at.

Parameters

ParamsTypeDescription

slippageTolerance

The % amount that the final executed price can differ from the expected price before the transaction will revert.

Returns

TypeDescription

The worst price that the trade can be executed at.

Last updated