import type { Program, Idl } from "@coral-xyz/anchor"; import { PublicKey, Transaction } from "@solana/web3.js"; import type { ExtData, TransactionProofBuilder } from "../proofs/types.js"; import type { SerializedUTXO } from "../notes/model.js"; import { MerkleTree } from "../merkle.js"; import { type NoteCiphers } from "../compactNote.js"; /** * Result of a deposit operation, produced by `DepositBuild.commit()` after the * caller has successfully submitted the deposit transaction on-chain. */ export type DepositResult = { /** The output UTXOs created by the deposit */ outputUTXOs: [SerializedUTXO, SerializedUTXO]; /** The leaf indices where the UTXOs were inserted */ leafIndices: [number, number]; /** The new Merkle root after insertion */ root: Uint8Array; }; /** * The return of `deposit()`. Instead of submitting the transaction itself, * `deposit()` hands back an unsigned {@link Transaction} so the caller can * sign it with whatever wallet they control (Solana wallet-adapter, Ledger, * anchor NodeWallet, etc.) and submit it on their own terms. * * Usage pattern (browser / wallet-adapter): * * const { transaction, commit } = await deposit({ ... }); * const signed = await wallet.signTransaction(transaction); * const sig = await connection.sendRawTransaction(signed.serialize()); * await connection.confirmTransaction(sig, "confirmed"); * const result = commit(); // updates the local tree, returns DepositResult */ export type DepositBuild = { /** * Unsigned {@link Transaction} for the deposit. `feePayer` and * `recentBlockhash` are already populated, so the caller only needs to sign * and send. */ transaction: Transaction; /** * Output UTXOs created by this deposit. Safe to read before submission — * the commitment values are deterministic from the circuit inputs and do * not depend on the on-chain result. */ outputUTXOs: [SerializedUTXO, SerializedUTXO]; /** * Inserts the two output commitments into the local {@link MerkleTree} and * returns the receipt. Call this **only after** the on-chain transaction * has been confirmed — deferring the insert keeps the local tree * consistent with chain state if the submission fails. * * Calling `commit()` more than once is unsupported and will corrupt the * local tree. */ commit: () => DepositResult; }; /** * Build an unsigned deposit {@link Transaction} for the privacy pool. * * For deposits, we use zero input UTXOs (amount=0) and create output UTXOs * with the deposit amount. `publicAmount` is positive. The caller is * responsible for signing and submitting the returned transaction, and then * calling `commit()` once it confirms. * * @param amount - Amount to deposit in lamports/token units * @param recipientPubkey - UTXO public key that will own the deposited funds * @param treeId - The tree ID to deposit into (defaults to 0) */ export declare function deposit(params: { program: Program; /** * Account that will pay for and sign the deposit transaction. Only * `publicKey` is read — `deposit()` never touches a secret key. A browser * wallet-adapter wallet, a Node `anchor.Wallet`, or a raw `Keypair` are all * structurally acceptable. */ depositor: { publicKey: PublicKey; }; amount: bigint; mintAddress: PublicKey; recipientPubkey: bigint; tree: MerkleTree; proofBuilder: TransactionProofBuilder; treeId?: number; extData?: Partial; /** Solana wallet key used to make output note 0 recoverable from chain events. */ noteRecipientWallet?: PublicKey | Uint8Array; /** Verified X25519 view-v2 target; takes precedence over noteRecipientWallet. */ noteRecipientViewKey?: Uint8Array; /** Prebuilt recovery payload. Takes precedence over noteRecipientWallet. */ noteCiphers?: NoteCiphers | null; }): Promise; /** * Result of a withdrawal operation. */