/** * Bounded wait-until-terminal barrier for queued DALP mutations. * * A v2 mutation may return a `202`-style async-accepted envelope when its * synchronous wait window elapses while the execution workflow is still * confirming. `waitForTransaction` turns that into a deterministic outcome: * poll the transaction status route at a FIXED interval bounded by a wall-clock * deadline, resolve on a terminal success, throw a typed error on a terminal * failure, and throw a loud timeout error if the deadline elapses first. * * This is a determinism barrier, not a masking retry — total wait is bounded by * `timeoutMs` (never exponential), and a never-terminating transaction fails * loud and bounded instead of hanging. * * Related: kit/sdk/src/types.ts * Related: packages/dalp/api-contract/src/routes/transaction/routes/transaction.status.schema.ts * * @module */ import type { DalpClient } from "./types.js"; /** Outcome shape returned by the transaction status route, narrowed to the fields this helper reads. */ export interface WaitForTransactionResult { readonly tokenAddress?: unknown; } export interface WaitForTransactionStatus { transactionId: string; status: string; subStatus: string | null; transactionHash: string | null; errorMessage: string | null; result?: WaitForTransactionResult; } export interface WaitForTransactionOptions { /** Wall-clock ceiling for the whole wait, in milliseconds. Default 120_000. */ timeoutMs?: number; /** Fixed delay between status polls, in milliseconds. Default 2_000. */ intervalMs?: number; /** * Resolve (instead of continuing to poll) when the transaction reaches * `PENDING_APPROVAL` — an external approval gate (DFNS / Fireblocks) that is * not a stall and may legitimately outlast the deadline. Default `true`. */ resolveOnPendingApproval?: boolean; /** * Cancels the wait when the owning context (React component, request handler, * workflow step) is torn down. An aborted signal stops the loop on the next * iteration, cancels the in-flight status request, and surfaces as a * {@link DalpTransactionWaitError} with `reason: "aborted"`. */ signal?: AbortSignal; } /** * Thrown when a transaction reaches a terminal failure state * (`FAILED` / `DEAD_LETTER` / `CANCELLED`), does not reach any terminal state * within the deadline (`reason: "timeout"`), or the caller's `AbortSignal` * fires (`reason: "aborted"`). */ export declare class DalpTransactionWaitError extends Error { readonly transactionId: string; readonly status: string; readonly subStatus: string | null; readonly reason: "terminal-failure" | "timeout" | "aborted"; readonly lastStatus: WaitForTransactionStatus | undefined; constructor(options: { message: string; transactionId: string; status: string; subStatus: string | null; reason: "terminal-failure" | "timeout" | "aborted"; lastStatus?: WaitForTransactionStatus; cause?: unknown; }); } /** * Poll the transaction status route until the transaction reaches a terminal * state or the deadline elapses. * * - `COMPLETED` → resolves with the final status (the handler already waited for * the indexer drain, so this is a true read-after-write guarantee). * - `FAILED` / `DEAD_LETTER` / `CANCELLED` → throws {@link DalpTransactionWaitError} * (`reason: "terminal-failure"`) carrying `status`, `subStatus`, and * `errorMessage` — fail fast, do not keep polling. * - `PENDING_APPROVAL` → resolves as pending (when `resolveOnPendingApproval`, * the default) so an external approval gate is never treated as a stall. * - deadline elapsed → throws {@link DalpTransactionWaitError} (`reason: "timeout"`) * carrying the last observed status — a loud, bounded failure, never an * indefinite hang. * * @param client A DALP API client. * @param transactionId The queue transaction identifier (UUIDv7) returned in the * async-accepted envelope. */ export declare function waitForTransaction(client: DalpClient, transactionId: string, options?: WaitForTransactionOptions): Promise; //# sourceMappingURL=wait-for-transaction.d.ts.map