/** * @module escrow-v2 * @description V2 escrow settlement layer — supports settlement security * modes (CoSigned, DisputeWindow), receipt-based dispute resolution, * pending settlements, and automatic resolution via merkle proofs. * * @category Modules * @since v0.7.0 * @packageDocumentation */ import { type PublicKey, type TransactionSignature, type AccountMeta, type Signer } from "@solana/web3.js"; import { BN } from "@coral-xyz/anchor"; import { BaseModule } from "./base"; import type { EscrowAccountV2Data, PendingSettlementData, DisputeRecordData, CreateEscrowV2Args } from "../types"; import type { SettleOptions } from "../utils/priority-fee"; /** * @name EscrowV2Module * @description Manages V2 escrow accounts with settlement security modes, * dispute windows, and pending settlement flows. * * @category Modules * @since v0.7.0 * @extends BaseModule */ export declare class EscrowV2Module extends BaseModule { /** Convert BN | number | bigint → number for PDA seed functions. */ private toNum; deriveEscrow(agentPda: PublicKey, depositor?: PublicKey, nonce?: BN | number | bigint): readonly [PublicKey, number]; derivePendingSettlement(escrowV2Pda: PublicKey, settlementIndex: BN | number | bigint): readonly [PublicKey, number]; deriveDispute(pendingSettlementPda: PublicKey): readonly [PublicKey, number]; create(agentWallet: PublicKey, args: CreateEscrowV2Args, splAccounts?: AccountMeta[]): Promise; deposit(agentWallet: PublicKey, nonce: BN | number | bigint, amount: BN | number | bigint, splAccounts?: AccountMeta[]): Promise; /** * Settle a batch of calls against a V2 escrow. * * **v1.0.0 — Atomic DisputeWindow:** when the escrow's * `settlementSecurity` is `DisputeWindow`, `settleCallsV2` creates the * `PendingSettlement` PDA inside the same on-chain instruction. The SDK * passes that PDA as a remaining account; the old standalone * `createPendingSettlement` flow is deprecated. * * Flow per security mode: * - **CoSigned** — single IX (`settleCallsV2`) with co-signer in * remaining accounts; funds move immediately. * - **DisputeWindow** — one IX (`settleCallsV2`) that reserves funds * and initializes the dispute tracker PDA atomically. * * After this tx confirms, wait `escrow.disputeWindowSlots` slots and * call {@link finalizeSettlement} with the index returned via * `SettlementPendingEvent` or readable from `escrow.settlement_index - 1`. * * @param depositorWallet - Depositor of the escrow being settled. * @param nonce - Escrow nonce (default 0 for the canonical escrow). * @param callsToSettle - Number of calls to settle in this batch. * @param serviceHash - 32-byte sha256 of the service payload. * @param splAccounts - Optional remaining accounts (SPL transfer + co-signer). * @param opts - Priority-fee + auto-pending options. * @param coSigner - Required for CoSigned escrows. * @returns The transaction signature. * @since v0.7.0 — initial release * @since v1.0.0 — creates PendingSettlement atomically on-chain for DisputeWindow */ settle(depositorWallet: PublicKey, nonce: BN | number | bigint, callsToSettle: BN | number | bigint, serviceHash: number[], splAccounts?: AccountMeta[], opts?: SettleOptions, coSigner?: Signer): Promise; /** * Read the current `escrow.settlement_index` from chain. * * In DisputeWindow mode (`settlementSecurity = 2`), every successful * `settleCallsV2` increments this value. The PRE-increment value is the * pending PDA index that `settle()` passes to the program as a remaining * account. * * @returns the next pending settlement index as `bigint`. * @since v0.12.8 */ nextSettlementIndex(agentWallet: PublicKey, depositorWallet: PublicKey, nonce: BN | number | bigint): Promise; /** * @deprecated Since SAP 1.0.0. `settleCallsV2` creates the * PendingSettlement PDA atomically; call {@link settle}. */ createPendingSettlement(agentWallet: PublicKey, depositorWallet: PublicKey, nonce: BN | number | bigint, settlementIndex: BN | number | bigint, callsToSettle: BN | number | bigint, amount: BN | number | bigint, serviceHash: number[]): Promise; finalizeSettlement(agentWallet: PublicKey, depositorWallet: PublicKey, nonce: BN | number | bigint, settlementIndex: BN | number | bigint): Promise; /** * Identify orphan PendingSettlement PDAs that cannot be finalized. * * @returns `null` if the PDA is finalizable (or already finalized / disputed). * Otherwise an object describing the inconsistency, suitable for * logging or feeding into a quarantine list. Use this from a * recovery script to scan a range of `settlement_index` values: * * ```ts * for (let idx = 0n; idx < currentIdx; idx++) { * const orphan = await sap.escrowV2.diagnoseOrphanPending( * agentWallet, depositorWallet, nonce, idx, * ); * if (orphan) log.warn({ idx, ...orphan }, "skip orphan"); * } * ``` * * @since v0.12.9 */ diagnoseOrphanPending(agentWallet: PublicKey, depositorWallet: PublicKey, nonce: BN | number | bigint, settlementIndex: BN | number | bigint): Promise<{ pendingPda: PublicKey; psAmount: bigint; escrowPendingAmount: bigint; escrowBalance: bigint; isFinalized: boolean; isDisputed: boolean; reason: "ok" | "missing" | "amount_exceeds_pending" | "amount_exceeds_balance" | "already_finalized" | "disputed"; } | null>; fileDispute(agentWallet: PublicKey, nonce: BN | number | bigint, settlementIndex: BN | number | bigint, evidenceHash: number[]): Promise; resolveDispute(depositorWallet: PublicKey, agentWallet: PublicKey, nonce: BN | number | bigint, settlementIndex: BN | number | bigint, outcome: number): Promise; closeDispute(pendingSettlementPda: PublicKey): Promise; closePendingSettlement(pendingSettlementPda: PublicKey): Promise; withdraw(agentWallet: PublicKey, nonce: BN | number | bigint, amount: BN | number | bigint): Promise; close(agentWallet: PublicKey, nonce?: BN | number | bigint): Promise; /** * @deprecated Since v0.7.0 — Migration instruction removed from program. */ migrateFromV1(_agentWallet: PublicKey): Promise; fetch(agentPda: PublicKey, depositor?: PublicKey, nonce?: BN | number | bigint): Promise; fetchNullable(agentPda: PublicKey, depositor?: PublicKey, nonce?: BN | number | bigint): Promise; fetchByPda(escrowPda: PublicKey): Promise; fetchPendingSettlement(pendingPda: PublicKey): Promise; fetchPendingSettlementNullable(pendingPda: PublicKey): Promise; fetchDispute(disputePda: PublicKey): Promise; fetchDisputeNullable(disputePda: PublicKey): Promise; } //# sourceMappingURL=escrow-v2.d.ts.map