Treasury Vault
Rate-limited treasury with configurable spending periods
Pending
Anchor 0.32
Program ID
D8ypRqJ45ZLAKmMPTLDuwJZubKgKbHZEXHrQ5T6ArVmE
Repository
ExpertVagabond/solana-treasury-vault
Binary Size
271K
Cluster
Devnet
Instructions
IX
initialize_treasury
Creates a new rate-limited treasury with a spending limit and period configuration.
| Parameter | Type | Description |
|---|---|---|
spending_limit | u64 | Maximum tokens that can be withdrawn per period |
period_length | i64 | Length of each spending period in seconds |
IX
deposit
Deposits tokens into the treasury vault. Can be called by anyone.
| Parameter | Type | Description |
|---|---|---|
amount | u64 | Number of tokens to deposit |
IX
withdraw
Withdraws tokens from the treasury. Enforces the spending limit per period. Only callable by the authority.
| Parameter | Type | Description |
|---|---|---|
amount | u64 | Number of tokens to withdraw |
IX
update_spending_limit
Updates the spending limit for the treasury. Only callable by the authority.
| Parameter | Type | Description |
|---|---|---|
new_limit | u64 | New maximum withdrawal amount per period |
IX
update_period_length
Updates the spending period duration. Only callable by the authority.
| Parameter | Type | Description |
|---|---|---|
new_period | i64 | New period length in seconds |
Accounts
Treasury
| Field | Type | Description |
|---|---|---|
authority | Pubkey | Treasury admin with withdrawal access |
mint | Pubkey | Token mint managed by the treasury |
spending_limit | u64 | Maximum withdrawal per period |
period_length | i64 | Spending period duration in seconds |
current_period_start | i64 | Start timestamp of the current spending period |
spent_this_period | u64 | Tokens already withdrawn in the current period |
total_deposited | u64 | Lifetime total tokens deposited |
total_withdrawn | u64 | Lifetime total tokens withdrawn |
bump | u8 | PDA 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();