UNPKG

astra-router-sdk

Version:

An sdk for routing swaps using Astra Classic and Astra CL.

96 lines (95 loc) 4.78 kB
import { Currency, CurrencyAmount, Percent, Price, TradeType } from 'astra-sdk-core'; import { Pair, Route as ClassicRouteSDK } from 'astra-classic-sdk'; import { Pool as CLPool, Route as CLRouteSDK } from 'astra-cl-sdk-dev'; import { MixedRouteSDK } from './mixedRoute/route'; import { IRoute } from './route'; export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> { readonly routes: IRoute<TInput, TOutput, Pair | CLPool>[]; readonly tradeType: TTradeType; private _outputAmount; private _inputAmount; /** * The swaps of the trade, i.e. which routes and how much is swapped in each that * make up the trade. May consist of swaps in classic or cl. */ readonly swaps: { route: IRoute<TInput, TOutput, Pair | CLPool>; inputAmount: CurrencyAmount<TInput>; outputAmount: CurrencyAmount<TOutput>; }[]; constructor({ classicRoutes, clRoutes, mixedRoutes, tradeType, }: { classicRoutes?: { routeclassic: ClassicRouteSDK<TInput, TOutput>; inputAmount: CurrencyAmount<TInput>; outputAmount: CurrencyAmount<TOutput>; }[]; clRoutes?: { routecl: CLRouteSDK<TInput, TOutput>; inputAmount: CurrencyAmount<TInput>; outputAmount: CurrencyAmount<TOutput>; }[]; mixedRoutes?: { mixedRoute: MixedRouteSDK<TInput, TOutput>; inputAmount: CurrencyAmount<TInput>; outputAmount: CurrencyAmount<TOutput>; }[]; tradeType: TTradeType; }); get inputAmount(): CurrencyAmount<TInput>; get outputAmount(): CurrencyAmount<TOutput>; private _executionPrice; /** * The price expressed in terms of output amount/input amount. */ get executionPrice(): Price<TInput, TOutput>; /** * Returns the sell tax of the input token */ get inputTax(): Percent; /** * Returns the buy tax of the output token */ get outputTax(): Percent; /** * The cached result of the price impact computation * @private */ private _priceImpact; /** * Returns the percent difference between the route's mid price and the expected execution price * In order to exclude token taxes from the price impact calculation, the spot price is calculated * using a ratio of values that go into the pools, which are the post-tax input amount and pre-tax output amount. */ get priceImpact(): Percent; /** * Get the minimum amount that must be received from this trade for the given slippage tolerance * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade * @param amountOut * @returns The amount out */ minimumAmountOut(slippageTolerance: Percent, amountOut?: CurrencyAmount<TOutput>): CurrencyAmount<TOutput>; /** * Get the maximum amount in that can be spent via this trade for the given slippage tolerance * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade * @param amountIn * @returns The amount in */ maximumAmountIn(slippageTolerance: Percent, amountIn?: CurrencyAmount<TInput>): CurrencyAmount<TInput>; /** * Return the execution price after accounting for slippage tolerance * @param slippageTolerance the allowed tolerated slippage * @returns The execution price */ worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>; static fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(classicRoutes: { routeclassic: ClassicRouteSDK<TInput, TOutput>; amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>; }[], clRoutes: { routecl: CLRouteSDK<TInput, TOutput>; amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>; }[], tradeType: TTradeType, mixedRoutes?: { mixedRoute: MixedRouteSDK<TInput, TOutput>; amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>; }[]): Promise<Trade<TInput, TOutput, TTradeType>>; static fromRoute<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(route: ClassicRouteSDK<TInput, TOutput> | CLRouteSDK<TInput, TOutput> | MixedRouteSDK<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>; }