Skip to main content

Overview

The update_deposit_limit instruction allows the program authority to modify the maximum deposit amount for the SOL merkle tree. For SPL tokens, use update_deposit_limit_for_spl_token instead.
Only the program authority can call this instruction.

Function Signature

pub fn update_deposit_limit(
    ctx: Context<UpdateDepositLimit>,
    new_limit: u64
) -> Result<()>

Parameters

new_limit
u64
required
New maximum deposit amount in lamports. Examples:
  • 1 SOL: 1_000_000_000
  • 100 SOL: 100_000_000_000
  • 1,000 SOL: 1_000_000_000_000 (default)
  • 10,000 SOL: 10_000_000_000_000

Accounts

tree_account
AccountLoader<MerkleTreeAccount>
required
The merkle tree account to update. PDA: ["merkle_tree"].
  • Mutable: Yes
  • Authority check: Must be owned by the signer
authority
Signer
required
The program authority. Must match the tree’s authority field.
  • Signer: Yes

Code Example

import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { PublicKey, LAMPORTS_PER_SOL } from "@solana/web3.js";

const program = anchor.workspace.Zkcash as Program<Zkcash>;
const authority = anchor.web3.Keypair.generate();

// Derive tree PDA
const [treeAccountPDA] = PublicKey.findProgramAddressSync(
  [Buffer.from("merkle_tree")],
  program.programId
);

// Update to 5,000 SOL maximum
const newLimit = new anchor.BN(5000).mul(new anchor.BN(LAMPORTS_PER_SOL));

await program.methods
  .updateDepositLimit(newLimit)
  .accounts({
    treeAccount: treeAccountPDA,
    authority: authority.publicKey
  })
  .signers([authority])
  .rpc();

console.log(`Deposit limit updated to ${newLimit.toString()} lamports`);

Update SPL Token Deposit Limit

For SPL tokens, use the separate instruction with the mint-specific PDA:
// For SPL tokens
const mint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); // USDC

const [splTreePDA] = PublicKey.findProgramAddressSync(
  [Buffer.from("merkle_tree"), mint.toBuffer()],
  program.programId
);

// Update to 10 million USDC (with 6 decimals)
const newUsdcLimit = new anchor.BN(10_000_000_000_000);

await program.methods
  .updateDepositLimitForSplToken(newUsdcLimit)
  .accounts({
    treeAccount: splTreePDA,
    mint: mint,
    authority: authority.publicKey
  })
  .signers([authority])
  .rpc();

Common Use Cases

When transaction volume increases, raise the limit to accommodate larger deposits:
// Increase from 1,000 SOL to 10,000 SOL
const newLimit = new anchor.BN(10_000_000_000_000);
await updateDepositLimit(newLimit);
During security incidents or maintenance, lower the limit to reduce risk:
// Decrease from 1,000 SOL to 100 SOL
const newLimit = new anchor.BN(100_000_000_000);
await updateDepositLimit(newLimit);
Set limit to 0 to prevent all new deposits:
// Temporarily disable deposits
const newLimit = new anchor.BN(0);
await updateDepositLimit(newLimit);

State Changes

MerkleTreeAccount

  • max_deposit_amount: Updated to new_limit
All other fields remain unchanged.

Behavior

  1. Loads the tree account and verifies authority
  2. Updates the max_deposit_amount field
  3. Emits a program log message
  4. The new limit applies immediately to all subsequent deposits
Existing deposits are not affected. Only new deposits will be subject to the new limit.

Authorization

The signer must be the tree’s authority. This is verified through Anchor’s has_one constraint:
#[account(
    mut,
    seeds = [b"merkle_tree"],
    bump = tree_account.load()?.bump,
    has_one = authority @ ErrorCode::Unauthorized
)]
pub tree_account: AccountLoader<'info, MerkleTreeAccount>,

Errors

Unauthorized
Error
Thrown when the signer is not the tree’s authority.

Program Log Output

When successful, the instruction logs:
Deposit limit updated to: {new_limit} lamports
For SPL tokens:
Deposit limit updated to: {new_limit} for mint: {mint_address}

Monitoring Limit Changes

You can monitor limit changes by:
  1. Parsing transaction logs for “Deposit limit updated” messages
  2. Periodically fetching the tree account and checking max_deposit_amount
  3. Setting up event listeners for authority transactions
// Check current limit
const treeAccount = await program.account.merkleTreeAccount.fetch(treeAccountPDA);
console.log(`Current deposit limit: ${treeAccount.maxDepositAmount.toString()} lamports`);

See Also

Build docs developers (and LLMs) love