import { type Address, web3 } from "@coral-xyz/anchor"; import BigNumber from "bignumber.js"; /** * Fetches the decimal precision for an SPL token mint. * * Results are memoized in `mintToDecimalsMap` — the first call hits the RPC, * subsequent calls for the same mint are O(1). * * @param connection Solana RPC connection used on cache miss. * @param mint Token mint to look up. * @returns Decimal precision (e.g. 6 for USDC, 9 for SOL/WSOL). */ export declare function getMintDecimals(connection: web3.Connection, mint: web3.PublicKey): Promise; /** * Utility function for delays */ export declare function sleep(durationInMs: number): Promise; /** * Construct a CreateAssociatedTokenAccount instruction * * @param payer Payer of the initialization fees * @param associatedToken New associated token account * @param owner Owner of the new account * @param mint Token mint account * @param programId SPL Token program account * @param associatedTokenProgramId SPL Associated Token program account * * @return Instruction to add to a transaction */ export declare function createAssociatedTokenAccountInstruction(payer: web3.PublicKey, associatedToken: web3.PublicKey, owner: web3.PublicKey, mint: web3.PublicKey, programId?: web3.PublicKey, associatedTokenProgramId?: web3.PublicKey): web3.TransactionInstruction; /** * Get the address of the associated token account for a given mint and owner * * @param mint Token mint account * @param owner Owner of the new account * @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address) * @param programId SPL Token program account * @param associatedTokenProgramId SPL Associated Token program account * * @return Address of the associated token account */ export declare function getAssociatedTokenAddressSync(mint: web3.PublicKey, owner: web3.PublicKey, allowOwnerOffCurve?: boolean, programId?: web3.PublicKey, associatedTokenProgramId?: web3.PublicKey): web3.PublicKey; /** * Converts a given amount in SOL to lamports (the smallest unit of SOL) * @param amount Amount in SOL to be converted * @returns */ export declare function parseSol(amount: BigNumber.Value): bigint; /** * Converts a given amount in lamports to SOL * @param amount Amount in lamports to be converted * @returns */ export declare function formatSol(amount: BigNumber.Value): string; /** * Converts a given token amount in decimals to the smallest unit of that token * @param amount Amount of token in decimals (e.g., 1876.190996) * @param decimals decimals of the token (e.g., 6 for USDC) * @returns */ export declare function parseToken(amount: BigNumber.Value, decimals: number): bigint; /** * Converts a given token amount in smallest unit to a human-readable format with decimals * @param amount Amount of token in smallest unit without decimals (e.g., 1876190996) * @param decimals Decimals of the token (e.g., 6 for USDC) * @returns */ export declare function formatToken(amount: BigNumber.Value, decimals: number): string; export type FormattedBalance = string; export type PublicKeyString = string; /** * * @param connection Solana Connection * @param address Wallet address * @param commitmentOrConfig Solana Commitment or GetBalanceConfig * @returns SOL Balance in ui amount */ export declare function getSolBalance(connection: web3.Connection, address: Address, commitmentOrConfig?: web3.Commitment | web3.GetBalanceConfig): Promise; /** * * @param connection Solana connection * @param address Wallet address * @param tokenMints Array of token mints * @param allowOwnerOffCurve boolean value whether to allow off curve wallet address * @param config Solana GetBalanceConfig * @returns Records of token mint key and ui token amount value */ export declare function getTokenBalances(connection: web3.Connection, address: Address, tokenMints: Address[], allowOwnerOffCurve?: boolean, config?: web3.GetBalanceConfig): Promise>; /** * Normalizes any error thrown while sending or confirming a Solana transaction * into a single `Error` with a human-readable message. * * Resolution order (first match wins): * 1. Known Jupiter aggregator program errors → friendly message. * 2. Insufficient-SOL detection → friendly message. * 3. Anchor `AnchorError` → formatted program + error-code + origin. * 4. Anchor `ProgramError` → formatted program + code + msg. * 5. Fallback: the `transactionMessage` field if present, else the * translated error as-is. * * The earlier checks are intentionally before Anchor's class-based ones * because Jupiter / insufficient-funds errors arrive as plain `Error`s with * meaningful substrings, and surfacing those is more actionable than the raw * "custom program error: 0x…" string. * * @param error Raw error from `sendRawTransaction` / `confirmTransaction`. * @param idlErrors Map of program error codes → messages from a program's * IDL, forwarded to Anchor's `translateError`. * @returns A single `Error` ready to be thrown to callers. */ export declare function parseSolanaSendTransactionError(error: unknown, idlErrors: Map): any; /** * Filters and sorts prioritization fees in ascending order * @param recentPrioritizationFees Recent fee data from Solana RPC * @returns Sorted array of non-zero fees */ export declare function replaceNonZeroAndSortPrioritizationFeesAsc(recentPrioritizationFees: web3.RecentPrioritizationFees[]): web3.RecentPrioritizationFees[]; /** * Priority fee calculation levels */ export type PriorityLevel = "low" | "medium" | "high"; /** * Calculates optimal priority fee based on recent network activity * @param connection Solana RPC connection * @param instructions Transaction instructions to analyze * @param priorityLevel Fee calculation strategy * @param maxFeeCap Maximum fee cap to prevent overpaying * @returns Calculated priority fee in micro-lamports */ export declare function getRecentPriorityFee(connection: web3.Connection, instructions: web3.TransactionInstruction[], priorityLevel: PriorityLevel, maxFeeCap: BigNumber): Promise; /** * Transaction execution options */ export type TransactionExecutionOptions = web3.ConfirmOptions & { enablePriorityFee?: boolean; sendTransactionInterval?: number; maxSendTransactionRetries?: number; priorityLevel?: PriorityLevel; maxPriorityFeeSol?: number; exactPriorityFeeSol?: number; confirmationTimeout?: number; }; /** * Repeatedly broadcasts a signed transaction to the cluster until any of: * - the cluster's current block height passes `lastValidBlockHeight` * (blockhash has expired — caller must rebuild & resign), * - `maxSendTransactionRetries` is reached, * - the shared `abortSignal` fires (typically because confirmation * succeeded or failed), * - the RPC reports the transaction has already been processed * (treated as success — confirmation will pick it up). * * "Blockhash not found" errors are treated as transient and retried, since * leaders sometimes lag behind the blockhash that was just fetched. * * This is the "send" half of {@link sendAndConfirm}; pair it with * {@link confirmTransactionWithTimeout} via a shared `AbortController` so * either side can stop the other once a terminal state is reached. * * @param connection Solana RPC connection. * @param signedTransaction Fully signed legacy or versioned transaction. * @param signature bs58-encoded signature, used only for logging. * @param lastValidBlockHeight Upper-bound block height the signed blockhash * is valid for. Past this, the transaction is * guaranteed to be dropped. * @param abortSignal Cooperative cancellation signal from the * confirmation half. * @param options Retry tuning + standard `ConfirmOptions`. * @throws `Error("Block height exceeded before confirmation")` when the * loop terminates because the blockhash expired. */ export declare function sendTransactionWithRetry(connection: web3.Connection, signedTransaction: web3.VersionedTransaction | web3.Transaction, signature: string, lastValidBlockHeight: number, abortSignal: AbortSignal, options?: TransactionExecutionOptions): Promise; /** * Awaits cluster confirmation for a transaction. Once confirmation resolves * (either as success or failure), this aborts the shared `AbortController` * so the paired sender loop can stop retrying. * * Confirmation itself is bounded by blockhash expiry — `confirmTransaction` * resolves with `value.err === null` on success, with a non-null `err` if * the transaction landed but failed, and rejects if the blockhash expires * before the transaction is observed. * * @param connection Solana RPC connection. * @param signature bs58-encoded signature to wait on. * @param blockhash Blockhash used to sign the transaction. * @param lastValidBlockHeight Same value used in sending; bounds the wait. * @param abortController Shared controller — aborted on completion so * the sender loop exits. * @param options Forwarded for `commitment`. * @throws When the cluster reports a transaction-level error * (`response.value.err !== null`). */ export declare function confirmTransactionWithTimeout(connection: web3.Connection, signature: string, blockhash: string, lastValidBlockHeight: number, abortController: AbortController, options?: TransactionExecutionOptions): Promise; /** * Parameters for {@link sendAndConfirm}. */ export interface SendAndConfirmParams { /** Solana RPC connection used for both sending and confirming. */ connection: web3.Connection; /** * Already-signed transaction. Must carry at least one non-zero signature; * otherwise {@link sendAndConfirm} throws `TransactionNotSigned`. */ signedTransaction: web3.Transaction | web3.VersionedTransaction; /** Blockhash used to sign the transaction. */ blockhash: string; /** Block height after which the blockhash is no longer valid. */ lastValidBlockHeight: number; /** Retry / commitment / priority-fee tuning. */ options?: TransactionExecutionOptions; /** * Optional caller-supplied controller — useful when an outer flow needs * to cancel send+confirm together (e.g. an orchestrator timing out). If * omitted, a fresh controller is created internally. */ abortController?: AbortController; } /** * Sends a signed transaction and waits for confirmation, coordinating the * sender retry loop and the confirmation listener through a shared * `AbortController` so whichever side finishes first stops the other. * * Flow: * 1. Extract the first signature from the transaction (fail fast if * missing — `addSignature` must have been called before getting here). * 2. Launch `sendTransactionWithRetry` and `confirmTransactionWithTimeout` * in parallel via `Promise.all`. Both observe the same abort signal. * 3. Either branch's rejection aborts the controller and propagates out. * * @returns The bs58-encoded transaction signature on confirmation. * @throws `TransactionNotSigned` when no usable signature is present. * @throws Any error surfaced by the send loop or confirmation listener. */ export declare function sendAndConfirm({ blockhash, connection, lastValidBlockHeight, signedTransaction, abortController, options, }: SendAndConfirmParams): Promise;