import { web3 } from "@coral-xyz/anchor"; import { type TransactionExecutionOptions } from "../utils"; /** * Async callback that receives the full batch of built transactions, signs * them all (typically via a single wallet prompt), and returns the signed * batch in the same order. * * Returning the array in the original order is required — downstream code * pairs the result with `transactionsData[i]` by index. */ export type SignAllTransactionsFunction = (transactions: T[]) => Promise; /** * Return shape of {@link MultiTransactionPayload.execute}. * * One entry per input transaction, preserving order, combining: * - the standard `PromiseSettledResult` (signature on success, * reason on failure — failures do **not** abort siblings), * - `transactionData`: a reference back to the input that produced this * result, useful for retrying just the failures, * - `transaction`: the built+signed `VersionedTransaction`, in case the * caller wants to re-broadcast it or inspect the wire payload. */ export type MultiTransactionPayloadExecuteReturn = (PromiseSettledResult & { transactionData: { readonly instructions: web3.TransactionInstruction[]; readonly feePayer: web3.PublicKey; readonly signers?: web3.Signer[]; readonly addressLookupTableAccounts?: web3.AddressLookupTableAccount[]; }; transaction: web3.VersionedTransaction; signature: string; })[]; /** * Builder for sending a batch of independent Solana transactions in one * call. Unlike {@link TransactionPayload}, failures are surfaced * per-transaction via `Promise.allSettled` semantics — one bad transaction * doesn't block the others from being sent or confirmed. */ export declare class MultiTransactionPayload { private readonly _connection; private readonly _errors; readonly transactionsData: { readonly instructions: web3.TransactionInstruction[]; readonly feePayer: web3.PublicKey; readonly signers?: web3.Signer[]; readonly addressLookupTableAccounts?: web3.AddressLookupTableAccount[]; }[]; private readonly _signAllTransactions?; private static readonly ERROR_MESSAGES; /** * @param _connection Solana RPC connection shared across all * transactions in the batch. * @param _errors Program error code → message map from the * IDL (forwarded to error translation). * @param transactionsData Ordered batch of transaction descriptors. * At least one is required; each entry must * have non-empty `instructions` and a * `feePayer`. Validated eagerly in the * constructor — see * {@link validateTransactionData}. * @param _signAllTransactions Bulk-signing callback. Required by * {@link execute}; for `simulate` it's only * required when `sigVerify: true`. */ constructor(_connection: web3.Connection, _errors: Map, transactionsData: { readonly instructions: web3.TransactionInstruction[]; readonly feePayer: web3.PublicKey; readonly signers?: web3.Signer[]; readonly addressLookupTableAccounts?: web3.AddressLookupTableAccount[]; }[], _signAllTransactions?: SignAllTransactionsFunction | undefined); /** * Convenience factory — same as calling `new MultiTransactionPayload(...)`. * Exists so callers can use a single named entry point and skip the `new` * keyword, which reads better in builder-style chains. */ static create(connection: web3.Connection, errors: Map, transactionData: { readonly instructions: web3.TransactionInstruction[]; readonly feePayer: web3.PublicKey; readonly signers?: web3.Signer[]; readonly addressLookupTableAccounts?: web3.AddressLookupTableAccount[]; }[], signAllTransactions?: SignAllTransactionsFunction): MultiTransactionPayload; /** * Validates the input batch up front so callers get a synchronous error * for malformed input instead of a confusing failure deep in `execute`. * * Invariants enforced: * - at least one transaction, * - every transaction has at least one instruction, * - every transaction has a fee payer. */ private validateTransactionData; /** * Simulates every transaction in the batch in parallel and returns a * `Map` keyed by the original input index. * * All transactions share the same freshly fetched blockhash so the * simulation snapshot is internally consistent. With `sigVerify: true`, * the bulk-sign callback runs once for the whole batch (matching the * UX of a single wallet prompt). * * If any individual `simulateTransaction` call **throws** * (e.g. RPC-level error, sigVerify failure), this method rejects with a * {@link MultiTransactionSimulationError} carrying per-index details for * every failure. Simulations that resolve with `value.err !== null` are * *not* treated as errors here — they're returned in the map for the * caller to inspect. */ simulate(options?: web3.SimulateTransactionConfig): Promise>>; /** * Builds (but does not send) one `VersionedTransaction` per * `transactionsData` entry, sharing the supplied `blockhash`. Any * per-transaction `signers` are applied here so the returned transactions * already have their non-fee-payer signatures populated. */ buildVersionTransactions(blockhash: string): Promise; /** * Prepends compute-budget instructions to a single transaction's * instruction list (in-place via `unshift`). Each kind * (`SetComputeUnitLimit` / `SetComputeUnitPrice`) is only added when the * caller hasn't already supplied one, so user-provided budget settings * always win. * * `unshift` is used because the Solana runtime only honors compute-budget * instructions that appear at the start of the instruction array. */ private addPriorityFeeInstructions; /** * Returns the per-CU priority fee in micro-lamports for a single * transaction in the batch. * * - If `exactPriorityFeeSol` is set: budget exactly that SOL amount as * priority fee, distributed across `computeUnit`. Caller takes * responsibility for the spend. * - Otherwise: sample recent network activity via * {@link getRecentPriorityFee} and cap by `maxPriorityFeeSol` so * bursty congestion can't drain wallets. */ private calculatePriorityFee; /** * End-to-end batch send: (optionally) simulate → attach priority fees → * build → bulk-sign → send & confirm each transaction in parallel. * * Failure semantics: each transaction is wrapped in its own try/catch * and surfaced as a `PromiseSettledResult`, so one bad transaction * doesn't cancel its siblings. Use the returned `transactionData` / * `transaction` fields to retry just the failures. * * @returns One result per input transaction, in the original order. * @throws Only for pre-flight failures that affect the whole batch * (missing sign function, batch-level simulation throw, * blockhash fetch failure). Individual transaction failures * surface as `status: "rejected"` entries. */ execute(options?: TransactionExecutionOptions): Promise; }