UNPKG

@pangolindex/sdk

Version:

🛠 An SDK for building applications on top of Pangolin.

207 lines (206 loc) • 9.67 kB
import { Currency, Percent, Price, CurrencyAmount } from '../../entities'; import { TradeType, BestTradeOptions } from '../../constants'; import { ElixirPool as Pool } from './pool'; import { ElixirRoute } from './elixirRoute'; /** * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them * @param a The first trade to compare * @param b The second trade to compare * @returns A sorted ordering for two neighboring elements in a trade array */ export declare function elixirTradeComparator(a: ElixirTrade, b: ElixirTrade): number; /** * 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. */ export declare class ElixirTrade { /** * This is kind of deprecated method in uni code but we are still using this as * we are not supporting MULTIPLE_ROUTES as of now * * 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. * * As of now we are not supporting MULTIPLE_ROUTES, so the invariant should not trigger * in future we might need multiple routes such that some swap will use v2 routing and some * swap will use elixir routing */ get route(): ElixirRoute; /** * The swaps of the trade, i.e. which routes and how much is swapped in each that * make up the trade. */ readonly swaps: { route: ElixirRoute; inputAmount: CurrencyAmount; outputAmount: CurrencyAmount; }[]; /** * The type of the trade, either exact in or exact out. */ readonly tradeType: TradeType; /** * The cached result of the input amount computation * @private */ private _inputAmount; /** * Chain identifier of the trade */ get chainId(): number; /** * The input amount for the trade assuming no slippage. */ get inputAmount(): CurrencyAmount; /** * The cached result of the output amount computation * @private */ private _outputAmount; /** * The output amount for the trade assuming no slippage. */ get outputAmount(): CurrencyAmount; /** * The cached result of the computed execution price * @private */ private _executionPrice; /** * The price expressed in terms of output amount/input amount. */ get executionPrice(): Price; /** * The cached result of the price impact computation * @private */ private _priceImpact; /** * Returns the percent difference between the route's mid price and the price impact */ get priceImpact(): Percent; /** * Constructs an exact in trade with the given amount in and route * @param route The route of the exact in trade * @param amountIn The amount being passed in * @returns The exact in trade */ static exactIn(route: ElixirRoute, amountIn: CurrencyAmount): Promise<ElixirTrade>; /** * Constructs an exact out trade with the given amount out and route * @param route The route of the exact out trade * @param amountOut The amount returned by the trade * @returns The exact out trade */ static exactOut(route: ElixirRoute, amountOut: CurrencyAmount): Promise<ElixirTrade>; /** * Constructs a trade by simulating swaps through the given route * @param route route to swap through * @param amount the amount specified, either input or output, depending on tradeType * @param tradeType whether the trade is an exact input or exact output swap * @returns The route */ static fromRoute(route: ElixirRoute, amount: CurrencyAmount, tradeType: TradeType): Promise<ElixirTrade>; /** * Constructs a trade from routes by simulating swaps * * @param routes the routes to swap through and how much of the amount should be routed through each * @param tradeType whether the trade is an exact input or exact output swap * @returns The trade */ static fromRoutes(routes: { amount: CurrencyAmount; route: ElixirRoute; }[], tradeType: TradeType): Promise<ElixirTrade>; /** * 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 * @param constructorArguments The arguments passed to the trade constructor * @returns The unchecked trade */ static createUncheckedTrade(constructorArguments: { route: ElixirRoute; inputAmount: CurrencyAmount; outputAmount: CurrencyAmount; tradeType: TradeType; }): ElixirTrade; /** * 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 * @param constructorArguments The arguments passed to the trade constructor * @returns The unchecked trade */ static createUncheckedTradeWithMultipleRoutes(constructorArguments: { routes: { route: ElixirRoute; inputAmount: CurrencyAmount; outputAmount: CurrencyAmount; }[]; tradeType: TradeType; }): ElixirTrade; /** * Construct a trade by passing in the pre-computed property values * @param routes The routes through which the trade occurs * @param tradeType The type of trade, exact input or exact output */ private constructor(); /** * 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): CurrencyAmount; /** * 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): CurrencyAmount; /** * Return the execution price after accounting for slippage tolerance * @param slippageTolerance the allowed tolerated slippage * @returns The execution price */ worstExecutionPrice(slippageTolerance: Percent): Price; /** * 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. * @param pools the pools to consider in finding the best trade * @param nextAmountIn exact amount of input currency to spend * @param currencyOut the desired currency out * @param maxNumResults maximum number of results to return * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool * @param currentPools used in recursion; the current list of pools * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter * @param bestTrades used in recursion; the current list of best trades * @returns The exact in trade */ static bestTradeExactIn(pools: Pool[], currencyAmountIn: CurrencyAmount, currencyOut: Currency, { maxNumResults, maxHops }?: BestTradeOptions, currentPools?: Pool[], nextAmountIn?: CurrencyAmount, bestTrades?: ElixirTrade[]): Promise<ElixirTrade[]>; /** * 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. * @param pools the pools to consider in finding the best trade * @param currencyIn the currency to spend * @param currencyAmountOut the desired currency amount out * @param nextAmountOut the exact amount of currency out * @param maxNumResults maximum number of results to return * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool * @param currentPools used in recursion; the current list of pools * @param bestTrades used in recursion; the current list of best trades * @returns The exact out trade */ static bestTradeExactOut(pools: Pool[], currencyIn: Currency, currencyAmountOut: CurrencyAmount, { maxNumResults, maxHops }?: BestTradeOptions, currentPools?: Pool[], nextAmountOut?: CurrencyAmount, bestTrades?: ElixirTrade[]): Promise<ElixirTrade[]>; }