Skip to main content

Trade

The Trade entity represents a trade along a route. This entity provides all the information necessary to perform a router transaction.

Source Code

constructor(route: Route, amount: TokenAmount, tradeType: TradeType)

Properties#

route#

The path property of the route should be passed as the path parameter to router functions.

route: Route

tradeType#

TradeType.EXACT_INPUT corresponds to swapExact*For* router functions. TradeType.EXACT_OUTPUT corresponds to swap*ForExact* router functions.

tradeType: TradeType

inputAmount#

For exact input trades, this value should be passed as amountIn to router functions. For exact output trades, this value should be multiplied by a factor >1, representing slippage tolerance, and passed as amountInMax to router functions.

inputAmount: TokenAmount

outputAmount#

For exact output trades, this value should be passed as amountOut to router functions. For exact input trades, this value should be multiplied by a factor <1, representing slippage tolerance, and passed as amountOutMin to router functions.

outputAmount: TokenAmount

executionPrice#

The average price that the trade would execute at.

executionPrice: Price

nextMidPrice#

What the new mid price would be if the trade were to execute.

nextMidPrice: Price

slippage#

The slippage incurred by the trade.

  • Strictly > .30%.
slippage: Percent

Methods#

Note that slippage referred to in the below 2 methods is the percent difference between the actual price and the trade executionPrice.

minimumAmountOut#

Returns the minimum amount of the output token that should be received from a trade, given the slippage tolerance.

Useful when constructing a transaction for a trade of type EXACT_IN.

minimumAmountOut(slippageTolerance: Percent): TokenAmount

maximumAmountIn#

Returns the maximum amount of the input token that should be spent on the trade, given the slippage tolerance.

Useful when constructing a transaction for a trade of type EXACT_OUT.

maximumAmountIn(slippageTolerance: Percent): TokenAmount

Static methods#

These static methods provide a way to construct ideal trades from lists of pools.

bestTradeExactIn#

This method returns the best maxNumResults, trades that swaps an input token amount to output token, making maxHops.

  • The returned trades are sorted by output amount, in decreasing order, and all share the input amount.
Trade.bestTradeExactIn(
pairs: Pair[],
amountIn: TokenAmount,
tokenOut: Token,
{ maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {}): Trade[]

bestTradeExactOut#

Similar to bestTradeExactIn, but targets a fixed output token amount.

  • The returned trades are sorted by input amount, in increasing order, and all share the output amount.
Trade.bestTradeExactOut(
pairs: Pair[],
tokenIn: Token,
amountOut: TokenAmount,
{ maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {}): Trade[]