Skip to content
Launch App >

Type definitions for the zklsol program.

interface DepositArgs {
commitment: number[]; // 32-byte commitment hash
amount: BN; // Amount in token base units
}
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
}
interface WithdrawSwapArgs {
nullifierHash: number[];
proof: number[];
root: number[];
depositSize: BN;
minOutputAmount: BN; // Minimum output after swap
}
interface RevertArgs {
nullifier: number[]; // 32-byte original nullifier
secret: number[]; // 32-byte original secret
commitment: number[]; // 32-byte commitment
}
interface CreateMerkleArgs {
depth: number; // Tree depth (32)
depositSize: BN; // Fixed deposit size
depositFeeBps: number; // Deposit fee in bps
withdrawFeeBps: number; // Withdrawal fee in bps
}
interface CreateAddressLookupTableArgs {
recentSlot: BN; // Recent slot for derivation
}
interface CreateAffiliateArgs {
affiliateCode: number[]; // Unique identifier (max 32 bytes)
feeShareBps: number; // Fee share 0-10000
}
interface UpdateMerkleFeesArgs {
depositFeeBps: number; // New deposit fee
withdrawFeeBps: number; // New withdrawal fee
}
interface CreateSettingsArgs {
depositFeeBps: number;
withdrawFeeBps: number;
}
interface UpdateSettingsArgs {
newAuthority: PublicKey | null;
depositFeeBps: number | null;
withdrawFeeBps: number | null;
isPaused: boolean | null;
}

enum MerkleStatus {
Active = 0, // Tree accepts deposits and withdrawals
Paused = 1, // Temporarily paused
Closed = 2, // Permanently closed
}
enum SwapStatus {
Pending = 0, // Swap initiated
Completed = 1, // Swap successful
Failed = 2, // Swap failed
}

Emitted when a deposit is made.

interface DepositEvent {
mint: PublicKey;
depositor: PublicKey;
commitment: number[];
leafIndex: number;
amount: BN;
timestamp: BN;
}

Emitted when a withdrawal is made.

interface WithdrawEvent {
mint: PublicKey;
recipient: PublicKey;
nullifierHash: number[];
amount: BN;
fee: BN;
timestamp: BN;
}

Emitted when a deposit is reverted.

interface RevertEvent {
mint: PublicKey;
depositor: PublicKey;
commitment: number[];
amount: BN;
timestamp: BN;
}

// Program constants
const MERKLE_DEPTH = 32;
const MAX_DEPOSITS = 2 ** 32; // ~4.3 billion
// Fee constants (basis points)
const MAX_FEE_BPS = 1000; // 10% max
const 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;

import { BN } from '@coral-xyz/anchor';
import { PublicKey } from '@solana/web3.js';
// Convert byte array to Uint8Array
function 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 number
function toLamports(amount: number, decimals: number): BN {
return new BN(amount * 10 ** decimals);
}
// Convert from base units
function fromLamports(amount: BN, decimals: number): number {
return amount.toNumber() / 10 ** decimals;
}
// Calculate fee
function calculateFee(amount: BN, feeBps: number): BN {
return amount.mul(new BN(feeBps)).div(new BN(10000));
}