Instructions
The user-facing instructions exposed by lib.rs. They fall into four groups: transact / transfer (proof-bearing, one instruction), swap (proof staged by prepare_swap, then swap), proofless deposit, and admin / lifecycle.
All proof-bearing transactions are sent as Solana v1 transactions (4096 bytes, no address lookup tables).
Nullifier accounts
transact, transfer and swap declare their nullifier PDAs as named optional accounts (first_nullifier … sixth_nullifier for transact/transfer, up to twelfth_nullifier for swap) with init_if_needed, seeded by in_nullifiers[i]. A nullifier account is created and marked used in the same instruction, so a failed transaction never leaves an unused nullifier account behind. Unused slots are passed as the program id (Anchor's None); 2-input calls fill only the first slots.
Transact (deposit / withdraw)
transact(forbid_deposit, in_nullifiers, relayer_fee, dimensions, root_hash_index, proof: ProofData)
dimensions is 1×2×1 or 1×6×1. The proof, public signals and encrypted outputs travel in the instruction data (ProofData); nothing is staged.
Bridges a wallet's public balance to or from the shielded vault.
If
mintisNone→ SOL flow (perform_transact_funds); otherwise → SPL flow (perform_transact_tokens).forbid_deposit = truerejects flows whose netamount_changeis non-negative.Net positive
amount_change→deposit_fundsfrom signer to vault.Net negative → vault transfers
|amount_change| - relayer_feeto recipient andrelayer_feeto signer (signer is the relayer).The
1×6×1shape supports up to 6 input nullifiers, used when consolidating fragmented UTXOs.After movement,
validate_*_balance_diffenforces the closing balance equation.
Transfer (shielded → shielded)
transfer(in_nullifiers, relayer_fee, dimensions, root_hash_index, proof: ProofData)
dimensions is 1×2×2 or 1×6×2. Moves value between two shielded UTXOs without exiting the vault, via transfer_common. The only fund movement is paying relayer_fee from the vault to the signer.
Swap (shielded → DEX → shielded)
A swap's proof, outputs and router calldata do not fit in one transaction together with the route accounts, so it takes two:
prepare_swap(id, dimensions, proof: ProofData, on_chain_encrypted_output, instructions: Vec<SolanaInstructionData>)
Writes one SwapStagingAccount at ["hinkal_swap_staging", deployer, signer, id] holding the proof, public signals, encrypted outputs, the on-chain encrypted output and the CPI batch. It creates the account (or resizes it if it already exists) and checks the encrypted-output count and sizes. It does not touch nullifiers.
swap(id, swapper_account_additional_seed, in_nullifiers, relayer_fee, variable_rate, dimensions, root_hash_index)
dimensions is 2×2×1 or 2×6×1. Reads the staging account (version-checked), runs the swap, and closes the staging account back to the signer. Steps in swap_common:
validate_swap_atas- the suppliedmint_from/mint_toand their ATAs must be consistent (no SOL pretending to be a token, etc.).process_proof_and_statewithon_chain_creation = [false, true]- the input leg uses proof-derived nullifiers/commitments; the output leg's commitment is built on-chain from the actual swap result.swapper_account_additional_seedfrom the proof must match the seed used to derive the swapper PDA (SwapperAccountAdditionalSeedMismatch).determine_swap_mode→TokenToToken | TokenToSol | SolToToken.Vault → swapper PDA: input liquidity is moved to the swapper (which is the CPI authority).
perform_swapinvokes the staged CPI batch againstremaining_accounts. Account index255is replaced with the swapper PDA at execution time and the call is signed viainvoke_signedwith the swapper seeds. Self-CPI back into Hinkal is rejected (SelfCPIForbidden).swapped_amount= balance delta on the destination ATA / SOL account.calculate_total_fee = relayer_fee + swapped_amount * variable_rate / 10000.variable_rateis in basis points × 10 (i.e. denominator 10_000).Fee is paid to the signer; the remainder is the UTXO amount. A new commitment is built on-chain from
(amount, mint_to, stealth_address_structure, timestamp)and inserted into the Merkle tree.validate_token_balance_diff/validate_sol_balance_diffis run on both legs to enforce the closing equation.
The swap transaction holds at most 64 accounts. With 21 fixed Hinkal accounts (including the event-CPI authority) plus one per real input note, 37–42 accounts remain for the router.
Proofless deposits
proofless_deposit(amounts[], stealth_address_structure[], encrypted_blobs[], create_blocked_utxos, timestamp: Option<i64>)
1..N outputs in a single instruction. SOL or SPL, selected by whether mint is supplied. timestamp overrides the block clock for the resulting UTXO(s) when supplied (None falls back to the on-chain clock). When create_blocked_utxos = true, also emits BlockedUtxosCreated { sender, mint, amounts } so a downstream service can build "blocked" UTXOs (e.g. for cooldowns).
Calls proofless_deposit_common:
amount > 0for every output.If
access_token_owneris supplied as a signer, validate it againstAccessTokenStorageAccount.access_token_owner_key. Otherwise, fall back tois_access_token_required(total_amount, token_limit)— iftotal_amountexceeds the per-mint limit, revert withAccessTokenRequired.Run the deposit (SOL via
deposit_funds, SPL viadeposit_tokens) and assertbalance_diff == total_amount.For each output, build an on-chain UTXO via
build_onchain_utxoand insert it into the Merkle tree (process_onchain_commitments).
Admin & lifecycle
initialize
original_deployer
Allocates and seeds storage, both Merkle trees, ownership, and access-token storage. Funds the vault PDA with rent-minimum.
transfer_ownership(new_owner)
current owner
Sets pending_owner. Emits OwnershipTransferred.
accept_ownership
pending_owner
Promotes pending → current. Emits OwnershipAccepted.
update_relayer_status(status)
owner
Adds or removes a relayer from the whitelist. Emits RelayerStatusUpdated.
init_token_limit
anyone (rent payer)
Allocates a per-(deployer, mint) TokenLimitStorageAccount with amount_limit = 0.
update_token_limit(amount)
owner
Sets the per-mint deposit/withdraw threshold. Emits TokenLimitUpdated.
add_access_token(access_key)
access_token_owner
Creates the AccesskeyAccount lock and inserts access_key into the access-token Merkle tree. Emits NewAccessKeyAdded.
change_access_token_owner_key(new_owner)
owner
Rotates access_token_owner_key. Emits AccessTokenOwnerChanged.
Last updated

