import { type IdlTypes } from '@coral-xyz/anchor'; import { type AccountInfo, type AddressLookupTableAccount, type Connection, type Signer, type Transaction, type TransactionInstruction, PublicKey, VersionedTransaction } from '@solana/web3.js'; import type { ChainLog, WithLogger } from '../types.ts'; import type { IDL as BASE_TOKEN_POOL_IDL } from './idl/1.6.0/BASE_TOKEN_POOL.ts'; import type { UnsignedSolanaTx, Wallet } from './types.ts'; import type { RateLimiterState } from '../chain.ts'; /** * Result of resolving an Associated Token Account for a given mint and owner. */ export type ResolvedATA = { /** The derived ATA address */ ata: PublicKey; /** The token program that owns the mint (SPL Token or Token-2022) */ tokenProgram: PublicKey; /** The raw mint account info */ mintInfo: AccountInfo; }; /** * Resolves the Associated Token Account (ATA) for a given mint and owner. * Automatically detects the correct token program (SPL Token vs Token-2022). * * @param connection - Solana connection instance * @param mint - Token mint address * @param owner - Owner's wallet address * @returns ResolvedATA with ata, tokenProgram, and mintInfo * @throws CCIPTokenMintNotFoundError If the mint account doesn't exist * @throws CCIPTokenMintInvalidError If the mint exists but isn't a valid SPL token * * @example * ```typescript * const { ata, tokenProgram } = await resolveATA(connection, mintPubkey, ownerPubkey) * ``` */ export declare function resolveATA(connection: Connection, mint: PublicKey, owner: PublicKey): Promise; /** * Generates a hex-encoded discriminator for a Solana event. * @param eventName - Name of the event. * @returns Hex-encoded discriminator string. */ export declare function hexDiscriminator(eventName: string): string; /** * Waits for a Solana transaction to reach finalized status. * @param connection - Solana connection instance. * @param signature - Transaction signature to wait for. * @param intervalMs - Polling interval in milliseconds. * @param maxAttempts - Maximum polling attempts before timeout. */ export declare function waitForFinalization(connection: Connection, signature: string, intervalMs?: number, maxAttempts?: number): Promise; /** * Converts a camelCase string to snake_case. * @param str - String to convert. * @returns snake_case formatted string. */ export declare function camelToSnakeCase(str: string): string; type ParsedLog = Pick & { data: string; level: number; }; /** * Utility function to parse Solana logs with proper address and topic extraction. * * Solana logs are structured as a stack-based execution trace: * - "Program
invoke []" - Program call starts * - "Program log: " - Program emitted a log message * - "Program data: " - Program emitted structured data (Anchor events) * - "Program
success/failed" - Program call ends * * This function: * 1. Tracks the program call stack to determine which program emitted each log * 2. Extracts the first 8 bytes from base64 "Program data:" logs as topics (event discriminants) * 3. Converts logs to EVM-compatible ChainLog format for CCIP compatibility * 4. Returns ALL logs from the transaction - filtering should be done by the caller * * @param logs - Array of logMessages from Solana transaction * @returns Array of parsed log objects from all programs in the transaction */ export declare function parseSolanaLogs(logs: readonly string[]): ParsedLog[]; /** * Extracts error information from Solana transaction logs. * @param logs_ - Raw log strings or parsed log objects (may include `tx` field with error info). * @returns Parsed error info with program and error details. */ export declare function getErrorFromLogs(logs_: readonly string[] | readonly Pick[] | null): { program: string; [k: string]: string; } | undefined; /** * Simulates a Solana transaction to estimate compute units. * @param params - Simulation parameters including connection and payer. * @returns Simulation result with estimated compute units. */ export declare function simulateTransaction({ connection, logger }: { connection: Connection; } & WithLogger, { payerKey, computeUnitsOverride, ...rest }: { payerKey: PublicKey; computeUnitsOverride?: number; addressLookupTableAccounts?: AddressLookupTableAccount[]; } & ({ instructions: TransactionInstruction[]; } | { tx: Transaction | VersionedTransaction; })): Promise; /** * Used as `provider` in anchor's `Program` constructor, to support `.view()` simulations * without * requiring a full AnchorProvider with wallet * @param ctx - Context object containing connection and logger * @param feePayer - Fee payer for the simulated transaction * @returns Value returned by the simulated method */ export declare function simulationProvider(ctx: { connection: Connection; } & WithLogger, feePayer?: PublicKey): { connection: Connection; wallet: { publicKey: PublicKey; }; simulate: (tx: Transaction | VersionedTransaction, _signers?: Signer[]) => Promise; }; /** * Sign, simulate, send and confirm as many instructions as possible on each transaction * @param ctx - Context object containing connection and logger * @param wallet - Wallet to sign and pay for txs * @param unsignedTx - instructions to sign and send * - instructions - Instructions to send; they may not fit all in a single transaction, * in which case they will be split into multiple transactions * - mainIndex - Index of the main instruction * - lookupTables - lookupTables to be used for main instruction * @param computeUnits - max computeUnits limit to be used for main instruction * @returns - signature of successful transaction including main instruction * @throws {@link CCIPSolanaComputeUnitsExceededError} if simulation exceeds compute units limit */ export declare function simulateAndSendTxs(ctx: { connection: Connection; } & WithLogger, wallet: Wallet, { instructions, mainIndex, lookupTables }: Omit, computeUnits?: number): Promise; /** * Convert TokenPool's rate limit to RateLimiterState object. * @param input - On-chain rate limiter bucket from the TokenPool IDL. * @returns RateLimiterState with capacity, rate, and current tokens, or null if disabled. */ export declare function convertRateLimiter(input: IdlTypes['BaseChain']['inboundRateLimit']): RateLimiterState; export {}; //# sourceMappingURL=utils.d.ts.map