UNPKG

orca-clmm-agent

Version:

Orca Whirlpool clmm library for automated position management

129 lines 5.31 kB
import { Rpc, TokenWithBalance } from "./solana"; import { BalanceChange, DetailedPosition, OrcaPosition, WhirlpoolInfo } from "./types"; import { Token } from "@lifi/sdk"; import { Address, TransactionSigner } from "@solana/kit"; import { OrcaError } from "./orca.types"; interface TokenWithTime extends Token { time: Date; } export declare const getTokens: () => Promise<TokenWithTime[]>; export declare const preloadTokens: () => Promise<TokenWithTime[]>; export declare const getPreloadedTokens: (maxAgeInSeconds?: number) => Promise<TokenWithTime[]>; /** * Token with balance and USD price information */ export interface TokenWithPrice extends TokenWithBalance { usdPrice: number; usdValue: number; } export declare const sleep: (ms: number) => Promise<unknown>; export declare function getUSDPrice({ mintAddress }: { mintAddress: string; }): Promise<number>; /** * Fetches tokens with balances and adds USD price information * @param walletAddress The wallet address to fetch tokens for * @param rpcUrl Optional RPC URL * @returns Promise resolving to an array of tokens with balances and USD prices */ export declare function fetchTokensWithPrices(walletAddress: string, rpcUrl?: string): Promise<TokenWithPrice[]>; /** * Computes the nearest total range deviation and finds the closest match from a set of range choices. * @param current Current pool price * @param lowerPrice Lower range price * @param upperPrice Upper range price * @param ranges Array of range choices (e.g. [0.05, 0.1, 0.15]) * @returns The closest range value */ export declare function computeNearestTotalRange(current: number, lowerPrice: number, upperPrice: number, ranges: number[]): number; export declare const getDetailedPositions: (walletAddress: string, rpc: Rpc, pools?: WhirlpoolInfo[], rangeChoices?: number[], funder?: TransactionSigner) => Promise<DetailedPosition[]>; /** * Converts a raw token amount (in smallest units) to decimal format * @param rawAmount The amount in smallest units (BigInt) * @param decimals The number of decimal places for the token * @returns The human-readable decimal amount */ export declare const convertRawToDecimal: (rawAmount: bigint, decimals: number) => number; export declare const convertDecimalToRaw: (decimalAmount: number, decimals: number) => bigint; export interface OpenUSDCPositionParams { rpc: Rpc; whirlpoolAddress: Address; wallet: TransactionSigner; walletByteArray: Uint8Array; baseTokenAddress: Address; baseTokenAmount: number; lowerMultiple: number; upperMultiple: number; maxSwapAttempts?: number; maxGasUSD?: number; maxPriceImpact?: number; swapDustToAddress?: Address; } /** * Opens a position with a base token * @returns A promise that resolves when the position is opened * @throws Error if the initialization cost is too high */ export declare function openPositionWithBaseToken({ rpc, whirlpoolAddress, wallet, walletByteArray, baseTokenAddress, baseTokenAmount, lowerMultiple, upperMultiple, maxSwapAttempts, maxGasUSD, maxPriceImpact, swapDustToAddress, }: OpenUSDCPositionParams): Promise<{ swapSignature: import("@solana/kit").Signature; swapLoss: number; swapPriceImpact: any; positionSignature: import("@solana/kit").Signature; positionMint: Address; feeUSD: number; tokenAPriceUSD: number; tokenBPriceUSD: number; signatures?: undefined; error?: undefined; } | { signatures: import("@solana/kit").Signature[]; swapLoss: number; feeUSD: number; error: OrcaError; swapSignature?: undefined; swapPriceImpact?: undefined; positionSignature?: undefined; positionMint?: undefined; tokenAPriceUSD?: undefined; tokenBPriceUSD?: undefined; } | undefined>; /** * Closes a position and harvests yield, handling errors gracefully * @param rpc The RPC client * @param wallet The wallet signer * @param position The position to close * @param maxRetries The maximum number of retries * @returns A promise that resolves when the position is closed */ export declare const closePositionGracefully: (rpc: any, wallet: TransactionSigner, position: OrcaPosition & { [key: string]: any; }, maxRetries?: number) => Promise<{ signature: import("@solana/kit").Signature; details: import("./types").TransactionDetails; } | undefined>; export interface ClosePositionWithBaseTokenParams { rpc: Rpc; wallet: TransactionSigner; position: OrcaPosition & { [key: string]: any; }; walletByteArray: Uint8Array; baseToken: string; maxPriceImpact?: number; maxGasUSD?: number; maxRetries?: number; } export declare const closePositionWithBaseToken: ({ rpc, wallet, position, walletByteArray, baseToken, maxPriceImpact, maxGasUSD, maxRetries, }: ClosePositionWithBaseTokenParams) => Promise<{ closeSignature: import("@solana/kit").Signature; feeUSD: number; swapLoss: number; swapSignature?: undefined; } | { closeSignature: import("@solana/kit").Signature; swapSignature: import("@solana/kit").Signature; swapLoss: number; feeUSD: number; }>; export declare const joinTransactionChanges: (earlierChanges: BalanceChange[], laterChanges: BalanceChange[]) => BalanceChange[]; export {}; //# sourceMappingURL=utils.d.ts.map