import { PublicKey } from '@solana/web3.js'; import BN from 'bn.js'; import { IAmmConfigLayout } from '../layout.js'; import { IPoolLayoutWithId } from '../models.js'; import { TickArrayContainer, TickArrayBitmapExtensionType } from './models.js'; export declare class PoolUtils { static isOverflowDefaultTickarrayBitmap(tickSpacing: number, tickarrayStartIndexs: number[]): boolean; static _tickRange(tickSpacing: number): { maxTickBoundary: number; minTickBoundary: number; }; /** * Calculate the maximum and minimum ticks selectable by users in the UI * Unlike _tickRange, this method directly returns the available tick value range, not the tickarray boundaries * * @param tickSpacing tick spacing * @returns Maximum and minimum tick values selectable by users */ static tickRange(tickSpacing: number): { maxTickBoundary: number; minTickBoundary: number; }; static nextInitializedTickArrayStartIndex(poolInfo: { tickCurrent: number; tickSpacing: number; tickArrayBitmap: BN[]; exBitmapInfo: TickArrayBitmapExtensionType; }, lastTickArrayStartIndex: number, zeroForOne: boolean): { isExist: boolean; nextStartIndex: number; }; static getFirstInitializedTickArray(poolInfo: { programId: PublicKey; poolId: PublicKey; tickCurrent: number; tickSpacing: number; tickArrayBitmap: BN[]; exBitmapInfo: TickArrayBitmapExtensionType; }, zeroForOne: boolean): { isExist: true; startIndex: number; nextAccountMeta: PublicKey; } | { isExist: false; startIndex: undefined; nextAccountMeta: undefined; }; /** * Calculate the output amount and required account list for token swap * * This function is the core of CLMM (Concentrated Liquidity Market Maker) swap logic, used to calculate the expected output amount for a given input amount, * and determine all tick array accounts that need to be accessed during trade execution. * * @param params Swap calculation parameter object * @param params.poolInfo - Complete information of the liquidity pool, including current price, liquidity, tick and other states * @param params.exBitmapInfo - Tick array bitmap extension information, used to handle ticks beyond the default range * @param params.ammConfig - AMM configuration information, including transaction fee rates and other parameters * @param params.tickArrayInfo - Loaded tick array information cache, with keys as tick array start indices * @param params.inputTokenMint - Input token mint address, used to determine trade direction * @param params.inputAmount - Input token amount (using minimum units) * @param params.sqrtPriceLimitX64 - Optional price limit, representing the worst price for the trade (Q64.64 format) * @param params.catchLiquidityInsufficient - Whether to catch liquidity insufficient situations, default false * * @returns Swap calculation result object * @returns allTrade - Boolean value indicating whether the specified input amount can be fully traded * true: All amount can be traded * false: Only partial trading due to insufficient liquidity or price limit * @returns expectedAmountOut - Expected output token amount to be obtained (using minimum units) * @returns remainingAccounts - List of all tick array account addresses that need to be accessed during trading * These accounts need to be passed as remaining accounts in the trade instruction * @returns executionPrice - Final price after trade execution (square root price in Q64.64 format) * @returns feeAmount - Total fees generated by the trade (using input token minimum units) * * @throws Error Throws 'Invalid tick array' error when no valid tick array is found */ static getOutputAmountAndRemainAccounts(params: { poolInfo: IPoolLayoutWithId; exBitmapInfo: TickArrayBitmapExtensionType; ammConfig: IAmmConfigLayout; tickArrayInfo: { [key: string]: TickArrayContainer; }; inputTokenMint: PublicKey; inputAmount: BN; sqrtPriceLimitX64?: BN; catchLiquidityInsufficient?: boolean; }): { allTrade: boolean; expectedAmountOut: BN; remainingAccounts: PublicKey[]; executionPrice: BN; feeAmount: BN; }; /** * Calculate the required input token amount and account list for exact output * * This function is used for "exact output" scenarios, where the user specifies the desired output token amount, * and the function calculates how many tokens need to be input to obtain the specified output amount. * * @param params Swap calculation parameter object * @param params.poolInfo - Complete information of the liquidity pool * @param params.exBitmapInfo - Tick array bitmap extension information * @param params.ammConfig - AMM configuration information * @param params.tickArrayInfo - Loaded tick array information cache * @param params.outputTokenMint - Output token mint address * @param params.outputAmount - Expected output token amount (using minimum units) * @param params.sqrtPriceLimitX64 - Optional price limit (Q64.64 format) * @param params.catchLiquidityInsufficient - Whether to catch liquidity insufficient situations * * @returns Swap calculation result object * @returns allTrade - Whether the specified output amount can be fully obtained * @returns expectedAmountIn - Required input token amount (including fees) * @returns remainingAccounts - List of tick array accounts that need to be accessed during trading * @returns executionPrice - Final price after trade execution * @returns feeAmount - Total fees generated by the trade */ static getInputAmountAndRemainAccounts(params: { poolInfo: IPoolLayoutWithId; exBitmapInfo: TickArrayBitmapExtensionType; ammConfig: IAmmConfigLayout; tickArrayInfo: { [key: string]: TickArrayContainer; }; outputTokenMint: PublicKey; outputAmount: BN; sqrtPriceLimitX64?: BN; catchLiquidityInsufficient?: boolean; }): { allTrade: boolean; expectedAmountIn: BN; remainingAccounts: PublicKey[]; executionPrice: BN; feeAmount: BN; }; } //# sourceMappingURL=poolUtils.d.ts.map