operations·treasury top-up
供treasury top-up
the showcase vault drains its treasury at rate × principal × dt. operators must top it up before it hits zero. this page is the cadence and the automation pattern.
the instruction
1pub fn top_up_treasury(ctx: Context<TopUpTreasury>, amount: u64) -> Result<()>2 3#[derive(Accounts)]4pub struct TopUpTreasury<'info> {5 pub authority: Signer<'info>,6 #[account(seeds = [VAULT_SEED, authority.key().as_ref()], bump = vault.bump,7 has_one = authority)]8 pub vault: Account<'info, Vault>,9 #[account(mut, address = vault.treasury_account)]10 pub treasury_account: Account<'info, TokenAccount>,11 #[account(mut)]12 pub funder_token_account: Account<'info, TokenAccount>,13 #[account(mut)]14 pub funder: Signer<'info>,15 pub token_program: Program<'info, Token>,16}cadence formula
1per-day drain = principal × rate × 1 day in years2 = principal × rate / 365.253 4example:5 principal = 100,000 USDC (TVL, the actual money working)6 rate = 22%7 8 per-day drain = 100,000 × 0.22 / 365.259 ≈ 60.23 USDC / day10 11 if you top up monthly with a 50% buffer, send ≈ 2,710 USDC / monthautomation script
The shipped scripts/init-vault.ts includes top-up logic. For an ongoing operation, run a daily cron that checks the treasury balance and tops up if below threshold:
1const treasury = await getAccount(conn, treasuryPda);2const balance = Number(treasury.amount) / 1e6;3 4const principal = await getAccount(conn, principalPda);5const principalUsdc = Number(principal.amount) / 1e6;6 7const dailyDrain = principalUsdc * (RATE_BPS / 10_000) / 365.25;8const minBuffer = dailyDrain * 14; // 2 weeks runway9 10if (balance < minBuffer) {11 const topUpAmount = Math.ceil((dailyDrain * 30 - balance) * 1e6); // micro-USDC12 await vault.methods.topUpTreasury(new BN(topUpAmount)).accountsPartial({13 authority: wallet.publicKey,14 vault: vaultPda,15 treasuryAccount: treasuryPda,16 funderTokenAccount: walletAta,17 funder: wallet.publicKey,18 tokenProgram: TOKEN_PROGRAM_ID,19 }).rpc();20 console.log(`topped up ${topUpAmount / 1e6} usdc`);21}when to replace the treasury model
A pre-funded treasury is fine for a hackathon, a grant deliverable, or an early beta. For production at meaningful TVL, replace the synthetic source with one that produces real yield. See concepts/treasury-model for the roadmap.