import { Transaction, TxAdapter, PollingTrackerConfig, ITxTrackingStore, TrackerCallbacks, TransactionTracker } from '@tuwaio/pulsar-core'; import { SolanaClusterMoniker, SolanaClient } from '@tuwaio/orbit-solana'; import { TransactionError, TransactionSendingSigner, Instruction } from '@solana/kit'; /** * @file Defines the core types and enums specific to the @tuwaio/pulsar-solana package. */ /** * Represents the simplified configuration object for the Solana adapter. * * This configuration enables both wallet-based (connected) and read-only (disconnected) modes, * supporting operations like transaction tracking, name/identity resolution, and more. * * @property {Partial>} rpcUrls - A mapping of cluster names to their respective RPC endpoints. */ interface SolanaAdapterConfig { rpcUrls: Partial>; } /** * @file This file contains the factory function for creating the Solana adapter for Pulsar. */ /** * Creates a Solana adapter for the Pulsar transaction tracking engine. * This factory function produces a wallet-library-agnostic adapter that can be * configured for multiple Solana clusters (e.g., mainnet-beta, devnet) and * can operate even without a connected wallet for read-only tasks. * * @template T - The application-specific transaction type. * @param {SolanaAdapterConfig} config - The configuration object for the adapter. * @returns {TxAdapter} The configured Solana transaction adapter. * * @throws {Error} Throws an error if the wagmi `config` is not provided. */ declare function pulsarSolanaAdapter(config: SolanaAdapterConfig): TxAdapter; /** * @file This file defines custom error classes for the @tuwaio/pulsar-solana package. */ /** * Thrown when the connected Solana chain does not match the required chain for a transaction. * * This allows consuming applications to `catch` this specific error and * implement custom logic, such as prompting the user to switch networks. */ declare class SolanaChainMismatchError extends Error { /** The name identifier of the error class. */ name: string; /** The chain that the transaction requires (e.g., 'solana:mainnet'). */ requiredChain: string; /** The chain the wallet is currently connected to. */ currentChain: string; constructor(requiredChain: string, currentChain: string); } /** * @file Implements the transaction tracking logic for Solana transactions. * It integrates with the Pulsar store and uses a polling mechanism to query the * `getSignatureStatuses` RPC method for updates on transaction status. */ /** * @typedef SolanaSignatureStatusResponse * Represents the status of a Solana transaction and includes additional metadata. * * @property {number} slot - The slot in which the transaction was processed. * @property {number | null} confirmations - The number of confirmations received. * @property {TransactionError | null} err - The error, if any, associated with the transaction. * @property {'processed' | 'confirmed' | 'finalized' | null} confirmationStatus - The status of the transaction's confirmation. * @property {number} [fee] - The transaction fee in lamports. * @property {string} [recentBlockhash] - The blockhash used for the transaction. * @property {unknown[]} [instructions] - The instructions included in the transaction. */ type SolanaSignatureStatusResponse = { slot: number; confirmations: number | null; err: TransactionError | null; confirmationStatus: 'processed' | 'confirmed' | 'finalized' | null; fee?: number; recentBlockhash?: string; instructions?: unknown[]; }; /** * @typedef SolanaFetcherParams * Parameters used for the Solana fetcher function. */ type SolanaFetcherParams = Parameters['fetcher']>[0]; /** * Fetches and tracks Solana transactions using the `getSignatureStatuses` RPC method. * Transaction details (`getTransaction`) are only fetched once, if not already present in the transaction object. * * @param {SolanaFetcherParams} params - The fetcher parameters, automatically provided by the tracker. * @throws Will throw an error if the transaction adapter is not set to Solana. * @returns {Promise} Resolves when the fetcher completes execution for the current polling cycle. */ declare function solanaFetcher({ tx, stopPolling, onSuccess, onFailure, onIntervalTick, }: SolanaFetcherParams): Promise; /** * A higher-level tracker that integrates the Solana polling logic with the Pulsar store. * * @template T - The application-specific Solana transaction type. * * @param {object} params - Parameters to connect the Solana tracker with the store. * @param {T} params.tx - The Solana transaction being tracked. * @param {Function} params.updateTxParams - A callback to update specific fields of a transaction in the store. * @param {Function} [params.removeTxFromPool] - A function to remove a completed or canceled transaction from the store. * @returns {Promise} Resolves when the tracker is successfully initialized. */ declare function solanaTrackerForStore({ tx, onSuccess, onError, ...rest }: Pick, 'updateTxParams' | 'removeTxFromPool' | 'transactionsPool'> & { tx: T; } & TrackerCallbacks): Promise; /** * @file This file contains the primary router for initializing transaction trackers. */ /** * Initializes the correct background tracker for a given Solana transaction. * This function acts as a router, selecting the appropriate tracker based on the `tx.tracker` property. * * @template T - The transaction type. * @param {object} params - The parameters for initializing the tracker. * @param {T} params.tx - The transaction object to be tracked. * @param {TransactionTracker} params.tracker - The specific tracker to use. * @param {object} params.rest - The rest of the store's methods and state needed by the tracker. * @returns {Promise} A promise that resolves when the tracker has been initialized. */ declare function checkAndInitializeTrackerInStore({ tx, tracker, onSuccess, onError, ...rest }: { tx: T; tracker: TransactionTracker; } & TrackerCallbacks & Pick, 'updateTxParams' | 'removeTxFromPool' | 'transactionsPool'>): Promise; /** * @file This file contains a utility to verify the connected Solana chain. */ /** * Checks if the wallet's current chain matches the required chain for a transaction. * This function compares the `chain` property from the Wallet Standard account object * with the required chain identifier (e.g., 'solana:mainnet'). * * @param {string} requiredChain - The chain identifier that the transaction requires. * @param {string} currentChain - The chain identifier the wallet is currently connected to. * @throws {SolanaChainMismatchError} If the connected chain does not match the required chain. */ declare const checkSolanaChain: (requiredChain: string, currentChain: string) => void; /** * @file This file contains a utility function for signing and sending Solana transactions. * It simplifies the process of creating, signing, and broadcasting a transaction to the network. */ /** * Creates, signs, and sends a Solana transaction with one or more instructions. * * This async function orchestrates the common flow for broadcasting a transaction: * 1. Fetches the latest blockhash from the RPC. * 2. Creates a versioned transaction message (`v0`). * 3. Signs the transaction with the provided signer. * 4. Sends the transaction to the network. * 5. Decodes and returns the resulting transaction signature. * * @param {object} params - The parameters for signing and sending the transaction. * @param {SolanaClient} params.client - The Solana client instance for RPC communication. * @param {TransactionSendingSigner} params.signer - The signer (e.g., a wallet) responsible for signing the transaction. * @param {Instruction | Instruction[]} params.instruction - A single instruction or an array of instructions to include in the transaction. * @returns A promise that resolves to the transaction signature. * @throws Will throw an error if any of the async operations (fetching blockhash, signing, sending) fail. * * @example * const signature = await signAndSendSolanaTx({ * client: mySolanaClient, * signer: wallet, * instruction: myTransferInstruction, * }); * console.log('Transaction sent with signature:', signature); */ declare function signAndSendSolanaTx({ client, signer, instruction, }: { client: SolanaClient; signer: TransactionSendingSigner; instruction: Instruction | Instruction[]; }): Promise; export { type SolanaAdapterConfig, SolanaChainMismatchError, checkAndInitializeTrackerInStore, checkSolanaChain, pulsarSolanaAdapter, signAndSendSolanaTx, solanaFetcher, solanaTrackerForStore };