Types Reference
Type definitions used in the zklsol program
Types Reference
Section titled “Types Reference”Type definitions for the zklsol program.
Instruction Arguments
Section titled “Instruction Arguments”DepositArgs
Section titled “DepositArgs”interface DepositArgs { commitment: number[]; // 32-byte commitment hash amount: BN; // Amount in token base units}WithdrawArgs
Section titled “WithdrawArgs”interface WithdrawArgs { nullifierHash: number[]; // 32-byte nullifier hash proof: number[]; // 256-byte ZK proof root: number[]; // 32-byte Merkle root depositSize: BN; // Original deposit amount}WithdrawSwapArgs
Section titled “WithdrawSwapArgs”interface WithdrawSwapArgs { nullifierHash: number[]; proof: number[]; root: number[]; depositSize: BN; minOutputAmount: BN; // Minimum output after swap}RevertArgs
Section titled “RevertArgs”interface RevertArgs { nullifier: number[]; // 32-byte original nullifier secret: number[]; // 32-byte original secret commitment: number[]; // 32-byte commitment}CreateMerkleArgs
Section titled “CreateMerkleArgs”interface CreateMerkleArgs { depth: number; // Tree depth (32) depositSize: BN; // Fixed deposit size depositFeeBps: number; // Deposit fee in bps withdrawFeeBps: number; // Withdrawal fee in bps}CreateAddressLookupTableArgs
Section titled “CreateAddressLookupTableArgs”interface CreateAddressLookupTableArgs { recentSlot: BN; // Recent slot for derivation}CreateAffiliateArgs
Section titled “CreateAffiliateArgs”interface CreateAffiliateArgs { affiliateCode: number[]; // Unique identifier (max 32 bytes) feeShareBps: number; // Fee share 0-10000}UpdateMerkleFeesArgs
Section titled “UpdateMerkleFeesArgs”interface UpdateMerkleFeesArgs { depositFeeBps: number; // New deposit fee withdrawFeeBps: number; // New withdrawal fee}CreateSettingsArgs
Section titled “CreateSettingsArgs”interface CreateSettingsArgs { depositFeeBps: number; withdrawFeeBps: number;}UpdateSettingsArgs
Section titled “UpdateSettingsArgs”interface UpdateSettingsArgs { newAuthority: PublicKey | null; depositFeeBps: number | null; withdrawFeeBps: number | null; isPaused: boolean | null;}MerkleStatus
Section titled “MerkleStatus”enum MerkleStatus { Active = 0, // Tree accepts deposits and withdrawals Paused = 1, // Temporarily paused Closed = 2, // Permanently closed}SwapStatus
Section titled “SwapStatus”enum SwapStatus { Pending = 0, // Swap initiated Completed = 1, // Swap successful Failed = 2, // Swap failed}Event Types
Section titled “Event Types”DepositEvent
Section titled “DepositEvent”Emitted when a deposit is made.
interface DepositEvent { mint: PublicKey; depositor: PublicKey; commitment: number[]; leafIndex: number; amount: BN; timestamp: BN;}WithdrawEvent
Section titled “WithdrawEvent”Emitted when a withdrawal is made.
interface WithdrawEvent { mint: PublicKey; recipient: PublicKey; nullifierHash: number[]; amount: BN; fee: BN; timestamp: BN;}RevertEvent
Section titled “RevertEvent”Emitted when a deposit is reverted.
interface RevertEvent { mint: PublicKey; depositor: PublicKey; commitment: number[]; amount: BN; timestamp: BN;}Constants
Section titled “Constants”// Program constantsconst MERKLE_DEPTH = 32;const MAX_DEPOSITS = 2 ** 32; // ~4.3 billion
// Fee constants (basis points)const MAX_FEE_BPS = 1000; // 10% maxconst BPS_DENOMINATOR = 10000;
// Size constants (bytes)const COMMITMENT_SIZE = 32;const NULLIFIER_SIZE = 32;const SECRET_SIZE = 32;const PROOF_SIZE = 256;const ROOT_SIZE = 32;TypeScript Type Helpers
Section titled “TypeScript Type Helpers”import { BN } from '@coral-xyz/anchor';import { PublicKey } from '@solana/web3.js';
// Convert byte array to Uint8Arrayfunction toBytes(arr: number[]): Uint8Array { return Uint8Array.from(arr);}
// Convert Uint8Array to number array (for IDL)function fromBytes(bytes: Uint8Array): number[] { return Array.from(bytes);}
// Convert BN to lamports-style numberfunction toLamports(amount: number, decimals: number): BN { return new BN(amount * 10 ** decimals);}
// Convert from base unitsfunction fromLamports(amount: BN, decimals: number): number { return amount.toNumber() / 10 ** decimals;}
// Calculate feefunction calculateFee(amount: BN, feeBps: number): BN { return amount.mul(new BN(feeBps)).div(new BN(10000));}