Skip to main content
Version: 3.0.0

Trade

Represents a trade executed against a list of pools. Does not account for slippage, i.e. trades that front run this trade and move the price.

Type parameters#

NameType
TInputCurrency
TOutputCurrency
TTradeTypeTradeType

Properties#

inputAmount#

Readonly inputAmount: CurrencyAmount<TInput>

The input amount for the trade assuming no slippage.

Defined in: entities/trade.ts:73


outputAmount#

Readonly outputAmount: CurrencyAmount<TOutput>

The output amount for the trade assuming no slippage.

Defined in: entities/trade.ts:77


route#

Readonly route: Route<TInput, TOutput>

The route of the trade, i.e. which pools the trade goes through.

Defined in: entities/trade.ts:65


tradeType#

Readonly tradeType: TTradeType

The type of the trade, either exact in or exact out.

Defined in: entities/trade.ts:69

Accessors#

executionPrice#

• get executionPrice(): Price<TInput, TOutput>

The price expressed in terms of output amount/input amount.

Returns: Price<TInput, TOutput>

Defined in: entities/trade.ts:87


priceImpact#

• get priceImpact(): Percent

Returns the percent difference between the route's mid price and the price impact

Returns: Percent

Defined in: entities/trade.ts:108

Methods#

maximumAmountIn#

maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput>

Get the maximum amount in that can be spent via this trade for the given slippage tolerance

Parameters#

NameTypeDescription
slippageTolerancePercenttolerance of unfavorable slippage from the execution price of this trade

Returns: CurrencyAmount<TInput>

Defined in: entities/trade.ts:252


minimumAmountOut#

minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput>

Get the minimum amount that must be received from this trade for the given slippage tolerance

Parameters#

NameTypeDescription
slippageTolerancePercenttolerance of unfavorable slippage from the execution price of this trade

Returns: CurrencyAmount<TOutput>

Defined in: entities/trade.ts:235


worstExecutionPrice#

worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>

Return the execution price after accounting for slippage tolerance

Parameters#

NameTypeDescription
slippageTolerancePercentthe allowed tolerated slippage

Returns: Price<TInput, TOutput>

Defined in: entities/trade.ts:267


bestTradeExactIn#

Static bestTradeExactIn<TInput, TOutput>(pools: Pool[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, __namedParameters?: BestTradeOptions, currentPools?: Pool[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, EXACT_INPUT>[]): Promise<Trade<TInput, TOutput, EXACT_INPUT>[]>

Given a list of pools, and a fixed amount in, returns the top maxNumResults trades that go from an input token amount to an output token, making at most maxHops hops. Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting the amount in among multiple routes.

Type parameters#

NameType
TInputCurrency
TOutputCurrency

Parameters#

NameTypeDefault valueDescription
poolsPool[]-the pools to consider in finding the best trade
currencyAmountInCurrencyAmount<TInput>-used in recursion; the original value of the currencyAmountIn parameter
currencyOutTOutput-the desired currency out
__namedParametersBestTradeOptions{}-
currentPoolsPool[][]used in recursion; the current list of pools
nextAmountInCurrencyAmount<Currency>-exact amount of input currency to spend
bestTradesTrade<TInput, TOutput, EXACT_INPUT>[][]used in recursion; the current list of best trades

Returns: Promise<Trade<TInput, TOutput, EXACT_INPUT>[]>

Defined in: entities/trade.ts:290


bestTradeExactOut#

Static bestTradeExactOut<TInput, TOutput>(pools: Pool[], currencyIn: Currency, currencyAmountOut: CurrencyAmount<TOutput>, __namedParameters?: BestTradeOptions, currentPools?: Pool[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, EXACT_OUTPUT>[]): Promise<Trade<TInput, TOutput, EXACT_OUTPUT>[]>

similar to the above method but instead targets a fixed output amount given a list of pools, and a fixed amount out, returns the top maxNumResults trades that go from an input token to an output token amount, making at most maxHops hops note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting the amount in among multiple routes.

Type parameters#

NameType
TInputCurrency
TOutputCurrency

Parameters#

NameTypeDefault valueDescription
poolsPool[]-the pools to consider in finding the best trade
currencyInCurrency-the currency to spend
currencyAmountOutCurrencyAmount<TOutput>-the desired currency amount out
__namedParametersBestTradeOptions{}-
currentPoolsPool[][]used in recursion; the current list of pools
nextAmountOutCurrencyAmount<Currency>-the exact amount of currency out
bestTradesTrade<TInput, TOutput, EXACT_OUTPUT>[][]used in recursion; the current list of best trades

Returns: Promise<Trade<TInput, TOutput, EXACT_OUTPUT>[]>

Defined in: entities/trade.ts:376


createUncheckedTrade#

Static createUncheckedTrade<TInput, TOutput, TTradeType>(constructorArguments: { inputAmount: CurrencyAmount<TInput> ; outputAmount: CurrencyAmount<TOutput> ; route: Route<TInput, TOutput> ; tradeType: TTradeType }): Trade<TInput, TOutput, TTradeType>

Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade elsewhere and do not have any tick data

Type parameters#

NameType
TInputCurrency
TOutputCurrency
TTradeTypeTradeType

Parameters#

NameTypeDescription
constructorArgumentsobjectthe arguments passed to the trade constructor
constructorArguments.inputAmountCurrencyAmount<TInput>-
constructorArguments.outputAmountCurrencyAmount<TOutput>-
constructorArguments.routeRoute<TInput, TOutput>-
constructorArguments.tradeTypeTTradeType-

Returns: Trade<TInput, TOutput, TTradeType>

Defined in: entities/trade.ts:192


exactIn#

Static exactIn<TInput, TOutput>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Promise<Trade<TInput, TOutput, EXACT_INPUT>>

Constructs an exact in trade with the given amount in and route

Type parameters#

NameType
TInputCurrency
TOutputCurrency

Parameters#

NameTypeDescription
routeRoute<TInput, TOutput>route of the exact in trade
amountInCurrencyAmount<TInput>the amount being passed in

Returns: Promise<Trade<TInput, TOutput, EXACT_INPUT>>

Defined in: entities/trade.ts:120


exactOut#

Static exactOut<TInput, TOutput>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Promise<Trade<TInput, TOutput, EXACT_OUTPUT>>

Constructs an exact out trade with the given amount out and route

Type parameters#

NameType
TInputCurrency
TOutputCurrency

Parameters#

NameTypeDescription
routeRoute<TInput, TOutput>route of the exact out trade
amountOutCurrencyAmount<TOutput>the amount returned by the trade

Returns: Promise<Trade<TInput, TOutput, EXACT_OUTPUT>>

Defined in: entities/trade.ts:132


fromRoute#

Static fromRoute<TInput, TOutput, TTradeType>(route: Route<TInput, TOutput>, amount: TTradeType extends EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>

Constructs a trade by simulating swaps through the given route

Type parameters#

NameType
TInputCurrency
TOutputCurrency
TTradeTypeTradeType

Parameters#

NameTypeDescription
routeRoute<TInput, TOutput>route to swap through
amountTTradeType extends EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>the amount specified, either input or output, depending on tradeType
tradeTypeTTradeTypewhether the trade is an exact input or exact output swap

Returns: Promise<Trade<TInput, TOutput, TTradeType>>

Defined in: entities/trade.ts:145