CenturionDEX

@centurion-dex/v3-sdk / Exports / Trade

Class: TradeTInput, TOutput, TTradeType

Last modified:

Represents a trade executed against a set of routes where some percentage of the input is split across each route.

Each route has its own set of pools. Pools can not be re-used across routes.

Does not account for slippage, i.e., changes in price environment that can occur between the time the trade is submitted and when it is executed.

Type parameters

NameTypeDescription
TInputextends CurrencyThe input token, either Ether or an CRC-20
TOutputextends CurrencyThe output token, either Ether or an CRC-20
TTradeTypeextends TradeTypeThe trade type, either exact input or exact output

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

Private new TradeTInput, TOutput, TTradeType(__namedParameters)

Construct a trade by passing in the pre-computed property values

Type parameters

NameType
TInputextends Currency
TOutputextends Currency
TTradeTypeextends TradeType

Parameters

NameType
__namedParametersObject
__namedParameters.routes{ inputAmount: CurrencyAmount``TInput ; outputAmount: CurrencyAmount``TOutput ; route: RouteTInput, TOutput }[]
__namedParameters.tradeTypeTTradeType

Defined in

entities/trade.ts:397

Properties

_executionPrice

Private _executionPrice: undefined | Price``TInput, TOutput

The cached result of the computed execution price

Defined in

entities/trade.ts:143


_inputAmount

Private _inputAmount: undefined | CurrencyAmount``TInput

The cached result of the input amount computation

Defined in

entities/trade.ts:97


_outputAmount

Private _outputAmount: undefined | CurrencyAmount``TOutput

The cached result of the output amount computation

Defined in

entities/trade.ts:120


_priceImpact

Private _priceImpact: undefined | Percent

The cached result of the price impact computation

Defined in

entities/trade.ts:164


swaps

Readonly swaps: { inputAmount: CurrencyAmount``TInput ; outputAmount: CurrencyAmount``TOutput ; route: RouteTInput, TOutput }[]

The swaps of the trade, i.e. which routes and how much is swapped in each that make up the trade.

Defined in

entities/trade.ts:82


tradeType

Readonly tradeType: TTradeType

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

Defined in

entities/trade.ts:91

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:148


inputAmount

get inputAmount(): CurrencyAmount``TInput

The input amount for the trade assuming no slippage.

Returns

CurrencyAmount``TInput

Defined in

entities/trade.ts:102


outputAmount

get outputAmount(): CurrencyAmount``TOutput

The output amount for the trade assuming no slippage.

Returns

CurrencyAmount``TOutput

Defined in

entities/trade.ts:125


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:169


route

get route(): RouteTInput, TOutput

Deprecated

Deprecated in favor of 'swaps' property. If the trade consists of multiple routes this will return an error.

When the trade consists of just a single route, this returns the route of the trade, i.e. which pools the trade goes through.

Returns

RouteTInput, TOutput

Defined in

entities/trade.ts:73

Methods

maximumAmountIn

maximumAmountIn(slippageTolerance, amountIn?): CurrencyAmount``TInput

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

Parameters

NameTypeDescription
slippageTolerancePercentThe tolerance of unfavorable slippage from the execution price of this trade
amountInCurrencyAmount``TInput-

Returns

CurrencyAmount``TInput

The amount in

Defined in

entities/trade.ts:456


minimumAmountOut

minimumAmountOut(slippageTolerance, amountOut?): CurrencyAmount``TOutput

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

Parameters

NameTypeDescription
slippageTolerancePercentThe tolerance of unfavorable slippage from the execution price of this trade
amountOutCurrencyAmount``TOutput-

Returns

CurrencyAmount``TOutput

The amount out

Defined in

entities/trade.ts:438


worstExecutionPrice

worstExecutionPrice(slippageTolerance): Price``TInput, TOutput

Return the execution price after accounting for slippage tolerance

Parameters

NameTypeDescription
slippageTolerancePercentthe allowed tolerated slippage

Returns

Price``TInput, TOutput

The execution price

Defined in

entities/trade.ts:471


bestTradeExactIn

Static bestTradeExactInTInput, TOutput(pools, currencyAmountIn, currencyOut, __namedParameters?, currentPools?, nextAmountIn?, bestTrades?): PromiseTradeTInput, 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
TInputextends Currency
TOutputextends Currency

Parameters

NameTypeDefault valueDescription
poolsPool[]undefinedthe pools to consider in finding the best trade
currencyAmountInCurrencyAmount``TInputundefinedused in recursion; the original value of the currencyAmountIn parameter
currencyOutTOutputundefinedthe desired currency out
__namedParametersBestTradeOptions{}-
currentPoolsPool[][]used in recursion; the current list of pools
nextAmountInCurrencyAmount``CurrencycurrencyAmountInexact amount of input currency to spend
bestTradesTradeTInput, TOutput, EXACT_INPUT[][]used in recursion; the current list of best trades

Returns

PromiseTradeTInput, TOutput, EXACT_INPUT[]

The exact in trade

Defined in

entities/trade.ts:495


bestTradeExactOut

Static bestTradeExactOutTInput, TOutput(pools, currencyIn, currencyAmountOut, __namedParameters?, currentPools?, nextAmountOut?, bestTrades?): PromiseTradeTInput, 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
TInputextends Currency
TOutputextends Currency

Parameters

NameTypeDefault valueDescription
poolsPool[]undefinedthe pools to consider in finding the best trade
currencyInTInputundefinedthe currency to spend
currencyAmountOutCurrencyAmount``TOutputundefinedthe desired currency amount out
__namedParametersBestTradeOptions{}-
currentPoolsPool[][]used in recursion; the current list of pools
nextAmountOutCurrencyAmount``CurrencycurrencyAmountOutthe exact amount of currency out
bestTradesTradeTInput, TOutput, EXACT_OUTPUT[][]used in recursion; the current list of best trades

Returns

PromiseTradeTInput, TOutput, EXACT_OUTPUT[]

The exact out trade

Defined in

entities/trade.ts:576


createUncheckedTrade

Static createUncheckedTradeTInput, TOutput, TTradeType(constructorArguments): TradeTInput, 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

NameTypeDescription
TInputextends CurrencyThe input token, either Ether or an CRC-20
TOutputextends CurrencyThe output token, either Ether or an CRC-20
TTradeTypeextends TradeTypeThe type of the trade, either exact in or exact out

Parameters

NameTypeDescription
constructorArgumentsObjectThe arguments passed to the trade constructor
constructorArguments.inputAmountCurrencyAmount``TInput-
constructorArguments.outputAmountCurrencyAmount``TOutput-
constructorArguments.routeRouteTInput, TOutput-
constructorArguments.tradeTypeTTradeType-

Returns

TradeTInput, TOutput, TTradeType

The unchecked trade

Defined in

entities/trade.ts:346


createUncheckedTradeWithMultipleRoutes

Static createUncheckedTradeWithMultipleRoutesTInput, TOutput, TTradeType(constructorArguments): TradeTInput, TOutput, TTradeType

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

Type parameters

NameTypeDescription
TInputextends CurrencyThe input token, either Ether or an CRC-20
TOutputextends CurrencyThe output token, either Ether or an CRC-20
TTradeTypeextends TradeTypeThe type of the trade, either exact in or exact out

Parameters

NameTypeDescription
constructorArgumentsObjectThe arguments passed to the trade constructor
constructorArguments.routes{ inputAmount: CurrencyAmount``TInput ; outputAmount: CurrencyAmount``TOutput ; route: RouteTInput, TOutput }[]-
constructorArguments.tradeTypeTTradeType-

Returns

TradeTInput, TOutput, TTradeType

The unchecked trade

Defined in

entities/trade.ts:377


exactIn

Static exactInTInput, TOutput(route, amountIn): PromiseTradeTInput, TOutput, EXACT_INPUT

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

Type parameters

NameTypeDescription
TInputextends CurrencyThe input token, either Ether or an CRC-20
TOutputextends CurrencyThe output token, either Ether or an CRC-20

Parameters

NameTypeDescription
routeRouteTInput, TOutputThe route of the exact in trade
amountInCurrencyAmount``TInputThe amount being passed in

Returns

PromiseTradeTInput, TOutput, EXACT_INPUT

The exact in trade

Defined in

entities/trade.ts:194


exactOut

Static exactOutTInput, TOutput(route, amountOut): PromiseTradeTInput, TOutput, EXACT_OUTPUT

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

Type parameters

NameTypeDescription
TInputextends CurrencyThe input token, either Ether or an CRC-20
TOutputextends CurrencyThe output token, either Ether or an CRC-20

Parameters

NameTypeDescription
routeRouteTInput, TOutputThe route of the exact out trade
amountOutCurrencyAmount``TOutputThe amount returned by the trade

Returns

PromiseTradeTInput, TOutput, EXACT_OUTPUT

The exact out trade

Defined in

entities/trade.ts:209


fromRoute

Static fromRouteTInput, TOutput, TTradeType(route, amount, tradeType): PromiseTradeTInput, TOutput, TTradeType

Constructs a trade by simulating swaps through the given route

Type parameters

NameTypeDescription
TInputextends CurrencyThe input token, either Ether or an CRC-20.
TOutputextends CurrencyThe output token, either Ether or an CRC-20.
TTradeTypeextends TradeTypeThe type of the trade, either exact in or exact out.

Parameters

NameTypeDescription
routeRouteTInput, TOutputroute to swap through
amountTTradeType extends EXACT_INPUT ? CurrencyAmount``TInput : CurrencyAmount``TOutputthe amount specified, either input or output, depending on tradeType
tradeTypeTTradeTypewhether the trade is an exact input or exact output swap

Returns

PromiseTradeTInput, TOutput, TTradeType

The route

Defined in

entities/trade.ts:226


fromRoutes

Static fromRoutesTInput, TOutput, TTradeType(routes, tradeType): PromiseTradeTInput, TOutput, TTradeType

Constructs a trade from routes by simulating swaps

Type parameters

NameTypeDescription
TInputextends CurrencyThe input token, either Ether or an CRC-20.
TOutputextends CurrencyThe output token, either Ether or an CRC-20.
TTradeTypeextends TradeTypeThe type of the trade, either exact in or exact out.

Parameters

NameTypeDescription
routes{ amount: TTradeType extends EXACT_INPUT ? CurrencyAmount``TInput : CurrencyAmount``TOutput ; route: RouteTInput, TOutput }[]the routes to swap through and how much of the amount should be routed through each
tradeTypeTTradeTypewhether the trade is an exact input or exact output swap

Returns

PromiseTradeTInput, TOutput, TTradeType

The trade

Defined in

entities/trade.ts:276