UNPKG

@renec-foundation/redex-sdk

Version:

Typescript SDK to interact with Orca's Whirlpool program.

94 lines (93 loc) 4.93 kB
/// <reference types="bn.js" /> import { Percentage } from "@orca-so/common-sdk"; import { Address, BN } from "@project-serum/anchor"; import { u64 } from "@solana/spl-token"; import { SwapInput } from "../../instructions"; import { AccountFetcher } from "../../network/public"; import { TickArray, WhirlpoolData } from "../../types/public"; import { Whirlpool } from "../../whirlpool-client"; import { DevFeeSwapQuote } from "./dev-fee-swap-quote"; /** * @category Quotes * * @param tokenAmount - The amount of input or output token to swap from (depending on amountSpecifiedIsInput). * @param otherAmountThreshold - The maximum/minimum of input/output token to swap into (depending on amountSpecifiedIsInput). * @param sqrtPriceLimit - The maximum/minimum price the swap will swap to. * @param aToB - The direction of the swap. True if swapping from A to B. False if swapping from B to A. * @param amountSpecifiedIsInput - Specifies the token the parameter `amount`represents. If true, the amount represents * the input token of the swap. * @param tickArrays - An sequential array of tick-array objects in the direction of the trade to swap on */ export declare type SwapQuoteParam = { whirlpoolData: WhirlpoolData; tokenAmount: u64; otherAmountThreshold: u64; sqrtPriceLimit: BN; aToB: boolean; amountSpecifiedIsInput: boolean; tickArrays: TickArray[]; }; /** * A collection of estimated values from quoting a swap. * @category Quotes * @link {BaseSwapQuote} * @link {DevFeeSwapQuote} */ export declare type SwapQuote = NormalSwapQuote | DevFeeSwapQuote; /** * A collection of estimated values from quoting a swap. * @category Quotes * @param estimatedAmountIn - Approximate number of input token swapped in the swap * @param estimatedAmountOut - Approximate number of output token swapped in the swap * @param estimatedEndTickIndex - Approximate tick-index the Whirlpool will land on after this swap * @param estimatedEndSqrtPrice - Approximate sqrtPrice the Whirlpool will land on after this swap * @param estimatedFeeAmount - Approximate feeAmount (all fees) charged on this swap */ export declare type SwapEstimates = { estimatedAmountIn: u64; estimatedAmountOut: u64; estimatedEndTickIndex: number; estimatedEndSqrtPrice: BN; estimatedFeeAmount: u64; }; export declare type NormalSwapQuote = SwapInput & SwapEstimates; /** * Get an estimated swap quote using input token amount. * * @category Quotes * @param whirlpool - Whirlpool to perform the swap on * @param inputTokenMint - PublicKey for the input token mint to swap with * @param tokenAmount - The amount of input token to swap from * @param slippageTolerance - The amount of slippage to account for in this quote * @param programId - PublicKey for the Whirlpool ProgramId * @param fetcher - AccountFetcher object to fetch solana accounts * @param refresh - If true, fetcher would default to fetching the latest accounts * @returns a SwapQuote object with slippage adjusted SwapInput parameters & estimates on token amounts, fee & end whirlpool states. */ export declare function swapQuoteByInputToken(whirlpool: Whirlpool, inputTokenMint: Address, tokenAmount: u64, slippageTolerance: Percentage, programId: Address, fetcher: AccountFetcher, refresh: boolean): Promise<SwapQuote>; /** * Get an estimated swap quote using an output token amount. * * Use this quote to get an estimated amount of input token needed to receive * the defined output token amount. * * @category Quotes * @param whirlpool - Whirlpool to perform the swap on * @param outputTokenMint - PublicKey for the output token mint to swap into * @param tokenAmount - The maximum amount of output token to receive in this swap. * @param slippageTolerance - The amount of slippage to account for in this quote * @param programId - PublicKey for the Whirlpool ProgramId * @param fetcher - AccountFetcher object to fetch solana accounts * @param refresh - If true, fetcher would default to fetching the latest accounts * @returns a SwapQuote object with slippage adjusted SwapInput parameters & estimates on token amounts, fee & end whirlpool states. */ export declare function swapQuoteByOutputToken(whirlpool: Whirlpool, outputTokenMint: Address, tokenAmount: u64, slippageTolerance: Percentage, programId: Address, fetcher: AccountFetcher, refresh: boolean): Promise<SwapQuote>; /** * Perform a sync swap quote based on the basic swap instruction parameters. * * @category Quotes * @param params - SwapQuote parameters * @param slippageTolerance - The amount of slippage to account for when generating the final quote. * @returns a SwapQuote object with slippage adjusted SwapInput parameters & estimates on token amounts, fee & end whirlpool states. */ export declare function swapQuoteWithParams(params: SwapQuoteParam, slippageTolerance: Percentage): SwapQuote;