import { PublicKey } from "@solana/web3.js"; import type { InputUTXO, SerializedUTXO } from "../notes/model.js"; import type { ExtData, RawProof } from "./types.js"; /** * Swap circuit inputs. Matches the signal shape declared by swap.circom's * main component (see zk-circuits/swap.circom lines 208-238). Unlike the * transaction circuit, the swap circuit distinguishes a "change" output * (same mint as source) from a "dest" output (dest mint) and takes a * swap-specific params hash and swapAmount alongside the usual inputs. */ export type SwapCircuitInputs = { sourceRoot: Uint8Array; swapParamsHash: Uint8Array; extDataHash: Uint8Array; sourceMint: PublicKey; destMint: PublicKey; inputNullifiers: [Uint8Array, Uint8Array]; changeCommitment: Uint8Array; destCommitment: Uint8Array; swapAmount: bigint; inAmount: [bigint, bigint]; inPubkey: [bigint, bigint]; inBlinding: [bigint, bigint]; inPathIndex: [number, number]; inPathElements: [bigint[], bigint[]]; inPrivateKey: [bigint, bigint]; changeAmount: bigint; changePubkey: bigint; changeBlinding: bigint; destAmount: bigint; destPubkey: bigint; destBlinding: bigint; minAmountOut: bigint; deadline: bigint; }; /** Proof builder accepted by SDK-side private swap flows. */ export type SwapProofBuilder = (inputs: SwapCircuitInputs) => Promise; /** * Prepare the exact witness/public inputs used by the relayer's swap circuit. * Output 0 must be source-mint change and output 1 the destination-mint note. */ export declare function prepareSwapInputs(params: { inputUTXOs: [InputUTXO, InputUTXO]; changeUTXO: SerializedUTXO; destUTXO: SerializedUTXO; sourceRoot: Uint8Array; sourceMint: PublicKey; destMint: PublicKey; swapAmount: bigint; minAmountOut: bigint; deadline: bigint; extData: ExtData; }): SwapCircuitInputs; /** * Convert SwapCircuitInputs into the shape expected by * snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a * decimal string (or string array) because snarkjs only accepts field * elements as strings. * * Mirrors `generateSwapProof` in * relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs * verify against the same circuit the relayer uses. */ export declare function formatSwapInputsForSnarkjs(inputs: SwapCircuitInputs): Record; /** * Compute the swap params hash that the swap circuit and on-chain program verify. * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`. * * Circuit formula (swap.circom lines 293-307): * mintPairHash = Poseidon(sourceMint, destMint) * swapTermsHash = Poseidon(minAmountOut, deadline, destAmount) * swapParamsHash = Poseidon(mintPairHash, swapTermsHash) * * @param sourceMint Source pool mint * @param destMint Destination pool mint * @param minAmountOut Minimum accepted output amount (slippage protected) * @param deadline Positive Unix timestamp deadline (the program rejects 0) * @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut - * relayerFee). If omitted, defaults to minAmountOut. */ export declare function computeSwapParamsHash(sourceMint: PublicKey, destMint: PublicKey, minAmountOut: bigint, deadline: bigint, destAmount?: bigint): Uint8Array; /** * Compute the swap data hash committed on-chain for Jupiter instruction integrity. * SHA-256 of the raw Jupiter swap instruction data bytes. * Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`. */ export declare function computeSwapDataHash(swapData: Uint8Array | Buffer): Uint8Array;