UNPKG

astra-router-sdk

Version:

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

96 lines (95 loc) 5.03 kB
import { Interface } from '@ethersproject/abi'; import { Currency, Percent, TradeType } from 'astra-sdk-core'; import { Trade as ClassicTrade } from 'astra-classic-sdk'; import { FeeOptions, MethodParameters, PermitOptions, Position, Trade as CLTrade } from 'astra-cl-sdk-dev'; import { ApprovalTypes, CondensedAddLiquidityOptions } from './approveAndCall'; import { Trade } from './entities/trade'; import { Validation } from './multicallExtended'; import { MixedRouteTrade } from './entities/mixedRoute/trade'; /** * Options for producing the arguments to send calls to the router. */ export interface SwapOptions { /** * How much the execution price is allowed to move unfavorably from the trade execution price. */ slippageTolerance: Percent; /** * The account that should receive the output. If omitted, output is sent to msg.sender. */ recipient?: string; /** * Either deadline (when the transaction expires, in epoch seconds), or previousBlockhash. */ deadlineOrPreviousBlockhash?: Validation; /** * The optional permit parameters for spending the input. */ inputTokenPermit?: PermitOptions; /** * Optional information for taking a fee on output. */ fee?: FeeOptions; } export interface SwapAndAddOptions extends SwapOptions { /** * The optional permit parameters for pulling in remaining output token. */ outputTokenPermit?: PermitOptions; } declare type AnyTradeType = Trade<Currency, Currency, TradeType> | ClassicTrade<Currency, Currency, TradeType> | CLTrade<Currency, Currency, TradeType> | MixedRouteTrade<Currency, Currency, TradeType> | (ClassicTrade<Currency, Currency, TradeType> | CLTrade<Currency, Currency, TradeType> | MixedRouteTrade<Currency, Currency, TradeType>)[]; /** * Represents the Astra Classic + CL SwapRouter02, and has static methods for helping execute trades. */ export declare abstract class SwapRouter { static INTERFACE: Interface; /** * Cannot be constructed. */ private constructor(); /** * @notice Generates the calldata for a Swap with a Classic Route. * @param trade The ClassicTrade to encode. * @param options SwapOptions to use for the trade. * @param routerMustCustody Flag for whether funds should be sent to the router * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check * @returns A string array of calldatas for the trade. */ private static encodeClassicSwap; /** * @notice Generates the calldata for a Swap with a CL Route. * @param trade The CLTrade to encode. * @param options SwapOptions to use for the trade. * @param routerMustCustody Flag for whether funds should be sent to the router * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check * @returns A string array of calldatas for the trade. */ private static encodeCLSwap; /** * @notice Generates the calldata for a MixedRouteSwap. Since single hop routes are not MixedRoutes, we will instead generate * them via the existing encodeCLSwap and encodeClassicSwap methods. * @param trade The MixedRouteTrade to encode. * @param options SwapOptions to use for the trade. * @param routerMustCustody Flag for whether funds should be sent to the router * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check * @returns A string array of calldatas for the trade. */ private static encodeMixedRouteSwap; private static encodeSwaps; /** * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade. * @param trades to produce call parameters for * @param options options for the call parameters */ static swapCallParameters(trades: Trade<Currency, Currency, TradeType> | ClassicTrade<Currency, Currency, TradeType> | CLTrade<Currency, Currency, TradeType> | MixedRouteTrade<Currency, Currency, TradeType> | (ClassicTrade<Currency, Currency, TradeType> | CLTrade<Currency, Currency, TradeType> | MixedRouteTrade<Currency, Currency, TradeType>)[], options: SwapOptions): MethodParameters; /** * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade. * @param trades to produce call parameters for * @param options options for the call parameters */ static swapAndAddCallParameters(trades: AnyTradeType, options: SwapAndAddOptions, position: Position, addLiquidityOptions: CondensedAddLiquidityOptions, tokenInApprovalType: ApprovalTypes, tokenOutApprovalType: ApprovalTypes): MethodParameters; private static riskOfPartialFill; private static clTradeWithHighPriceImpact; private static getPositionAmounts; } export {};