Treasury Vault

Rate-limited treasury with configurable spending periods

Pending Anchor 0.32
Program ID D8ypRqJ45ZLAKmMPTLDuwJZubKgKbHZEXHrQ5T6ArVmE
Binary Size 271K
Cluster Devnet

Instructions

IX initialize_treasury

Creates a new rate-limited treasury with a spending limit and period configuration.

ParameterTypeDescription
spending_limitu64Maximum tokens that can be withdrawn per period
period_lengthi64Length of each spending period in seconds
IX deposit

Deposits tokens into the treasury vault. Can be called by anyone.

ParameterTypeDescription
amountu64Number of tokens to deposit
IX withdraw

Withdraws tokens from the treasury. Enforces the spending limit per period. Only callable by the authority.

ParameterTypeDescription
amountu64Number of tokens to withdraw
IX update_spending_limit

Updates the spending limit for the treasury. Only callable by the authority.

ParameterTypeDescription
new_limitu64New maximum withdrawal amount per period
IX update_period_length

Updates the spending period duration. Only callable by the authority.

ParameterTypeDescription
new_periodi64New period length in seconds

Accounts

Treasury

FieldTypeDescription
authorityPubkeyTreasury admin with withdrawal access
mintPubkeyToken mint managed by the treasury
spending_limitu64Maximum withdrawal per period
period_lengthi64Spending period duration in seconds
current_period_starti64Start timestamp of the current spending period
spent_this_periodu64Tokens already withdrawn in the current period
total_depositedu64Lifetime total tokens deposited
total_withdrawnu64Lifetime total tokens withdrawn
bumpu8PDA bump seed

PDA Derivation

treasury
seeds = [b"treasury", authority, mint]
vault
seeds = [b"vault", treasury]

Error Codes

SpendingLimitExceeded The withdrawal would exceed the spending limit for the current period
Overflow Arithmetic overflow in treasury accounting

Usage Example

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

// Create treasury: 10K token limit per 24h period
const [treasuryPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("treasury"), authority.publicKey.toBuffer(), mint.toBuffer()],
  program.programId
);

await program.methods
  .initializeTreasury(
    new BN(10_000_000_000),   // spending_limit (10K tokens)
    new BN(86400)             // period_length (24 hours)
  )
  .accounts({
    treasury: treasuryPda,
    authority: authority.publicKey,
    mint,
  })
  .signers([authority])
  .rpc();

// Deposit 100K tokens into the treasury
await program.methods
  .deposit(new BN(100_000_000_000))
  .accounts({
    treasury: treasuryPda,
    depositor: depositor.publicKey,
    mint,
  })
  .signers([depositor])
  .rpc();

// Withdraw 5K tokens (within the 10K daily limit)
await program.methods
  .withdraw(new BN(5_000_000_000))
  .accounts({
    treasury: treasuryPda,
    authority: authority.publicKey,
    mint,
  })
  .signers([authority])
  .rpc();