hermes-swap-router-sdk
Version:
An sdk for routing swaps using Uniswap v2, Uniswap v3 and Balancer Stable Pools.
113 lines (112 loc) • 5.89 kB
TypeScript
import { ComposableStablePool, ComposableStablePoolWrapper, IPool, Pool, TradeType, V2RouteSDK, Route as V3RouteSDK, Trade as V3TradeSDK } from 'hermes-v2-sdk';
import { Currency, CurrencyAmount, Percent, Price } from 'maia-core-sdk';
import { MixedRouteSDK, TPool } from './mixedRoute/route';
import { Protocol } from './protocol';
import { IRoute } from './route';
export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
readonly routes: IRoute<TInput, TOutput, TPool>[];
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 v2 or v3.
*/
readonly swaps: {
route: IRoute<TInput, TOutput, TPool>;
inputAmount: CurrencyAmount<TInput>;
outputAmount: CurrencyAmount<TOutput>;
}[];
constructor({ v2Routes, v3Routes, stableRoutes, stableWrapperRoutes, tradeType, mixedRoutes, allowDifferentTokenRoutes, }: {
v2Routes: {
routev2: V2RouteSDK<TInput, TOutput>;
inputAmount: CurrencyAmount<TInput>;
outputAmount: CurrencyAmount<TOutput>;
}[];
v3Routes: {
routev3: V3RouteSDK<Pool, TInput, TOutput>;
inputAmount: CurrencyAmount<TInput>;
outputAmount: CurrencyAmount<TOutput>;
}[];
stableRoutes: {
routeStable: V3RouteSDK<ComposableStablePool, TInput, TOutput>;
inputAmount: CurrencyAmount<TInput>;
outputAmount: CurrencyAmount<TOutput>;
}[];
stableWrapperRoutes: {
routeStableWrapper: V3RouteSDK<ComposableStablePoolWrapper, TInput, TOutput>;
inputAmount: CurrencyAmount<TInput>;
outputAmount: CurrencyAmount<TOutput>;
}[];
tradeType: TTradeType;
mixedRoutes?: {
mixedRoute: MixedRouteSDK<TInput, TOutput>;
inputAmount: CurrencyAmount<TInput>;
outputAmount: CurrencyAmount<TOutput>;
}[];
allowDifferentTokenRoutes?: boolean;
});
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
* @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
* @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>(v2Routes: {
routev2: V2RouteSDK<TInput, TOutput>;
amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
}[], v3Routes: {
routev3: V3RouteSDK<Pool, TInput, TOutput>;
amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
}[], stableRoutes: {
routeStable: V3RouteSDK<ComposableStablePool, TInput, TOutput>;
amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
}[], stableWrapperRoutes: {
routeStableWrapper: V3RouteSDK<ComposableStablePoolWrapper, 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: V2RouteSDK<TInput, TOutput> | V3RouteSDK<IPool, TInput, TOutput> | MixedRouteSDK<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
static tradeProtocol(trade: V3TradeSDK<IPool, any, any, any>): Protocol;
static routeProtocol(route: V3RouteSDK<IPool, any, any>): Protocol;
}