constructor(route: Route, amount: CurrencyAmount, tradeType: TradeType)
The Trade entity represents a fully specified trade along a route. This entity supplies all the information necessary to craft a router transaction.
Example
import { ChainId, Token, CurrencyAmount, TradeType } from '@swapx/sdk-core'
import { Pair, Trade, Route }
const HOT = new Token(ChainId.MAINNET, '0xc0FFee0000000000000000000000000000000000', 18, 'HOT', 'Caffeine')
const NOT = new Token(ChainId.MAINNET, '0xDeCAf00000000000000000000000000000000000', 18, 'NOT', 'Caffeine')
const HOT_NOT = new Pair(CurrencyAmount.fromRawAmount(HOT, '2000000000000000000'), CurrencyAmount.fromRawAmount(NOT, '1000000000000000000'))
const NOT_TO_HOT = new Route([HOT_NOT], NOT, HOT)
const trade = new Trade(NOT_TO_HOT, CurrencyAmount.fromRawAmount(NOT, '1000000000000000'), TradeType.EXACT_INPUT)
Properties
route
route: Route;
The path property of the route should be passed as the path parameter to router functions.
tradeType
tradeType: TradeType;
TradeType.EXACT_INPUT
corresponds to swapExact*For*
router functions. TradeType.EXACT_OUTPUT
corresponds to swap*ForExact*
router functions.
inputAmount
inputAmount: CurrencyAmount;
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.
outputAmount
outputAmount: CurrencyAmount;
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.
executionPrice
executionPrice: Price;
The average price that the trade would execute at.
priceImpact
priceImpact: Percent;
The percent difference between the mid price before the trade and the trade execution price.
Methods
In the context of the following two methods, slippage refers to the percent difference between the actual price and the trade executionPrice
.
minimumAmountOut (since 2.0.4)
minimumAmountOut(slippageTolerance: Percent): CurrencyAmount
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_INPUT
.
maximumAmountIn (since 2.0.4)
maximumAmountIn(slippageTolerance: Percent): CurrencyAmount
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_OUTPUT
.
worstExecutionPrice
Return the execution price after accounting for slippage tolerance
worstExecutionPrice(slippageTolerance: Percent): Price