Full lesson
Fuin
What it does
From the project README:
A private key grants unlimited authority. Autonomous agents need *bounded* authority. Fuin splits the two apart: funds live in a keyless program-controlled vault, and agents get only a **scoped, on-chain-checked capability** — a budget, an allow-list, a time window, a kill-switch. If an agent is compromised or goes rogue, the blast radius is a number you chose up front.
- Original
- Fuin-Labs/Fuin
- SuperStack fork
- Blockchains/Fuin @
2963866 - Stars
- 0
- Last push (original)
- 2026-05-31
- Languages
- TypeScript, HTML, Rust, CSS, JavaScript, Swift
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- Other
- Licence
- MIT
- Homepage
- https://fuin-vault.vercel.app
Architecture
220 source files. By extension: .ts ×94, .tsx ×93, .rs ×27, .js ×6.
| Top-level directory | Source files |
|---|---|
apps | 143 |
packages | 44 |
programs | 31 |
submission | 1 |
scripts | 1 |
On-chain programs: programs/fuin/programs/fuin
Dapp: devnet deploy pending
⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/fuin/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
programs/fuin/programs/fuin/src/handlers/freeze_vault.rs L1–24 @ 2963866 · MIT · originaluse anchor_lang::prelude::*; use crate::state::{Vault, VaultState}; #[derive(Accounts)]#[instruction(nonce: u64)]pub struct FreezeVault<'info> { pub guardian: Signer<'info>, #[account( mut, seeds = [b"vault", guardian.key().as_ref(), &nonce.to_le_bytes()], bump = vault.bump, has_one = guardian, )] pub vault: Account<'info, Vault>,} pub fn freeze_vault(ctx: Context<FreezeVault>, _nonce: u64) -> Result<()> { let clock = Clock::get()?; let vault = &mut ctx.accounts.vault; vault.state = VaultState::Frozen; vault.recovery.last_guardian_activity = clock.unix_timestamp; msg!("Vault frozen");- Line 8
pub guardian: Signer<'info>,: Requires this account to have signed the transaction. - Line 12
seeds = [b"vault", guardian.key().as_ref(), &nonce.to_le_bytes()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 13
bump = vault.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 14
has_one = guardian,: Checks that a stored pubkey field matches the passed account. - Line 20
let clock = Clock::get()?;: Reads on-chain time from the Clock sysvar. - Line 24
msg!("Vault frozen");: Logs to the program log, which is visible in explorers and the test output.
programs/fuin/programs/fuin/src/handlers/issue_delegate.rs L1–24 @ 2963866 · MIT · originaluse anchor_lang::prelude::*; use crate::state::{Delegate, Vault}; #[derive(Accounts)]#[instruction(vault_nonce: u64, delegate_nonce: u64)]pub struct IssueDelegate<'info>{ #[account(mut)] pub guardian: Signer<'info>, #[account( mut, seeds = [ b"vault", guardian.key().as_ref(), &vault_nonce.to_le_bytes(), ], bump = vault.bump, has_one = guardian, )] pub vault: Account<'info, Vault>, #[account( init,- Line 9
pub guardian: Signer<'info>,: Requires this account to have signed the transaction. - Line 13
seeds = [: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 18
bump = vault.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 19
has_one = guardian,: Checks that a stored pubkey field matches the passed account. - Line 24
init,: Creates and pays for a new account. Space and payer must be specified.
programs/fuin/programs/fuin/src/handlers/update_vault.rs L13–36 @ 2963866 · MIT · original mut, seeds = [b"vault", guardian.key().as_ref(), &nonce.to_le_bytes()], bump = vault.bump, has_one = guardian )] pub vault : Account<'info, Vault>,} pub fn update_vault( ctx: Context<UpdateVault>, _nonce: u64, new_daily_cap: Option<u64>, new_per_tx_cap: Option<u64>, new_allow_list: Option<Vec<Pubkey>>, new_deny_list: Option<Vec<Pubkey>>,) -> Result<()> { let clock = Clock::get()?; let vault = &mut ctx.accounts.vault; vault.recovery.last_guardian_activity = clock.unix_timestamp; if let Some(cap) = new_daily_cap { vault.policies.spending.daily_cap = cap; msg!("Vault: Daily cap updated to {}", cap); }- Line 14
seeds = [b"vault", guardian.key().as_ref(), &nonce.to_le_bytes()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 15
bump = vault.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 16
has_one = guardian: Checks that a stored pubkey field matches the passed account. - Line 29
let clock = Clock::get()?;: Reads on-chain time from the Clock sysvar. - Line 35
msg!("Vault: Daily cap updated to {}", cap);: Logs to the program log, which is visible in explorers and the test output.
programs/fuin/programs/fuin/src/handlers/withdraw.rs L1–23 @ 2963866 · MIT · originaluse anchor_lang::prelude::*; use crate::state::Vault; #[derive(Accounts)]#[instruction(nonce: u64)]pub struct Withdraw<'info>{ #[account(mut)] pub guardian: Signer<'info>, #[account( mut, seeds = [b"vault", guardian.key().as_ref(), &nonce.to_le_bytes()], bump = vault.bump, has_one = guardian, )] pub vault: Account<'info, Vault>, pub system_program: Program<'info, System>,} pub fn withdraw(ctx:Context<Withdraw>, _nonce: u64, amount: u64)->Result<()>{ let clock = Clock::get()?;- Line 9
pub guardian: Signer<'info>,: Requires this account to have signed the transaction. - Line 13
seeds = [b"vault", guardian.key().as_ref(), &nonce.to_le_bytes()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 14
bump = vault.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 15
has_one = guardian,: Checks that a stored pubkey field matches the passed account. - Line 23
let clock = Clock::get()?;: Reads on-chain time from the Clock sysvar.
How to run, build and test
These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.
| Directory | Command | Runs |
|---|---|---|
. | npm run dev | turbo run dev |
. | npm run build | pnpm --filter @fuin-labs/db db:generate && turbo run build |
. | npm run lint | turbo run lint |
marketing/launch-film | npm run dev | npx --yes hyperframes@0.6.63 preview |
apps/agent | npm run test | echo "Error: no test specified" && exit 1 |
apps/relayer | npm run dev | tsx watch --env-file=.env src/index.ts |
apps/relayer | npm run start | tsx --env-file=.env src/index.ts |
apps/my-video | npm run dev | remotion studio |
apps/my-video | npm run build | remotion bundle |
apps/my-video | npm run lint | tsc && eslint src |
apps/vault | npm run dev | next dev --port 3000 |
apps/vault | npm run start | next start |
apps/vault | npm run build | next build |
apps/vault | npm run lint | eslint --max-warnings 0 |
programs/fuin | npm run build | anchor build |
programs/fuin | npm run test | anchor test |
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)