Full lesson
BondLadder
Robo-advisor for bond ladders on Solana — USDC in, five rated maturities out, one transaction. Devnet demo.
What it does
From the project README:
Deposit USDC, pick a risk profile, and the vault spreads it across five tokenized debt instruments with staggered maturities — selected by on-chain credit rating. Exit any time before maturity through a liquidity backstop, with the spread priced off the position's remaining duration.
- Original
- bondladder/BondLadder
- SuperStack fork
- Blockchains/BondLadder @
40b1e78 - Stars
- 0
- Last push (original)
- 2026-10-27
- Languages
- TypeScript, Rust, HTML, CSS, JavaScript
- Detected stack
- Anchorweb3.js
- Categories
- Other
- Licence
- Apache-2.0
- Homepage
- https://bondladder.github.io/BondLadder/
Architecture
83 source files. By extension: .ts ×38, .rs ×33, .tsx ×10, .js ×2.
| Top-level directory | Source files |
|---|---|
programs | 33 |
apps | 22 |
scripts | 15 |
packages | 13 |
On-chain programs: programs/bond-ladder, programs/mock-issuer, programs/rating-oracle
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/bondladder/. 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/rating-oracle/src/lib.rs L61–84 @ 40b1e78 · Apache-2.0 · original )] pub config: Account<'info, OracleConfig>, #[account(mut)] pub authority: Signer<'info>, pub system_program: Program<'info, System>,} #[derive(Accounts)]pub struct PublishRating<'info> { #[account( seeds = [OracleConfig::SEED], bump = config.bump, has_one = authority, )] pub config: Account<'info, OracleConfig>, // init_if_needed тут безпечний: запис перезаписується цілком, а доступ уже // звужений has_one на конфізі — повторна ініціалізація не дає authority // нічого понад те, що він і так може зробити наступною публікацією. #[account( init_if_needed, payer = authority,- Line 65
pub authority: Signer<'info>,: Requires this account to have signed the transaction. - Line 73
seeds = [OracleConfig::SEED],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 74
bump = config.bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 75
has_one = authority,: Checks that a stored pubkey field matches the passed account. - Line 79
// init_if_needed тут безпечний: запис перезаписується цілком, а доступ уже: Creates the account only if it doesn't exist. Watch for re-initialisation bugs.
programs/mock-issuer/src/lib.rs L73–96 @ 40b1e78 · Apache-2.0 · original #[account( init, payer = authority, space = 8 + IssuerConfig::INIT_SPACE, seeds = [IssuerConfig::SEED], bump, )] pub config: Account<'info, IssuerConfig>, pub usdc_mint: Account<'info, Mint>, #[account(mut)] pub authority: Signer<'info>, pub system_program: Program<'info, System>,} #[derive(Accounts)]pub struct RegisterInstrument<'info> { #[account( seeds = [IssuerConfig::SEED], bump = config.bump, has_one = authority, )]- Line 74
init,: Creates and pays for a new account. Space and payer must be specified. - Line 77
seeds = [IssuerConfig::SEED],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 78
bump,: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 85
pub authority: Signer<'info>,: Requires this account to have signed the transaction. - Line 95
has_one = authority,: Checks that a stored pubkey field matches the passed account.
programs/mock-issuer/src/instructions/mint_for_usdc.rs L25–48 @ 40b1e78 · Apache-2.0 · originalpub fn handler(ctx: Context<MintForUsdc>, amount_micro: u64) -> Result<Fill> { let price_micro = ctx.accounts.instrument.price_micro; require!(price_micro > 0, IssuerError::InvalidPrice); require!( Clock::get()?.unix_timestamp < ctx.accounts.instrument.maturity_ts, IssuerError::MaturityInThePast ); let Fill { units, spent_micro } = fill_for_share(amount_micro, price_micro); require!(units > 0, IssuerError::AmountBelowUnitPrice); token::transfer( CpiContext::new( ctx.accounts.token_program.to_account_info(), Transfer { from: ctx.accounts.buyer_usdc.to_account_info(), to: ctx.accounts.treasury.to_account_info(), authority: ctx.accounts.buyer.to_account_info(), }, ), spent_micro, )?; token::mint_to(- Line 27
require!(price_micro > 0, IssuerError::InvalidPrice);: An explicit validation that aborts the instruction with an error. - Line 29
Clock::get()?.unix_timestamp < ctx.accounts.instrument.maturity_ts,: Reads on-chain time from the Clock sysvar. - Line 36
token::transfer(: An SPL token transfer through the Token Program. - Line 37
CpiContext::new(: Makes a cross-program invocation into another program. - Line 48
token::mint_to(: Mints new tokens. The mint authority must sign.
programs/bond-ladder/src/instructions/exit_ladder.rs L181–203 @ 40b1e78 · Apache-2.0 · original .checked_sub(settled.principal_micro) .ok_or_else(|| error!(LadderError::MathOverflow))?; position.fee_accrued = settled.fee_carried_micro; position.last_fee_ts = now_ts; Ok(())} /// Holdings arrive in `remaining_accounts`, so the address is checked here/// rather than by a seeds constraint, and the first exit through an/// instrument creates its holding.fn credit_holding<'info>( holding: &AccountInfo<'info>, rung: &Rung, units: u64, payer: &Signer<'info>, system_program: &Program<'info, System>,) -> Result<()> { let (address, bump) = Pubkey::find_program_address( &[BackstopHolding::SEED, rung.instrument.as_ref()], &crate::ID, ); require_keys_eq!(holding.key(), address, ErrorCode::ConstraintSeeds);- Line 181
.checked_sub(settled.principal_micro): Uses checked arithmetic so overflow fails instead of wrapping. - Line 196
payer: &Signer<'info>,: Requires this account to have signed the transaction. - Line 199
let (address, bump) = Pubkey::find_program_address(: Derives a PDA from seeds and the program ID and returns the address with its canonical bump. - Line 199
let (address, bump) = Pubkey::find_program_address(: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 203
require_keys_eq!(holding.key(), address, ErrorCode::ConstraintSeeds);: An explicit validation that aborts the instruction with an error.
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 | turbo run build |
. | npm run test | turbo run test |
. | npm run lint | biome lint . |
packages/shared | npm run test | vitest run --passWithNoTests |
apps/web | npm run dev | vite |
apps/web | npm run build | tsc --noEmit && vite build |
apps/web | npm run test | vitest run |
apps/keeper | npm run dev | node --experimental-strip-types src/index.ts |
apps/keeper | npm run test | vitest run --passWithNoTests |
scripts | npm run test | vitest run --passWithNoTests |
. | anchor build | compile programs and generate IDLs |
. | anchor test | local validator + test suite |
. | anchor run test | pnpm vitest run tests/ |
. | cargo build | Rust workspace build |
. | cargo test | Rust tests |
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)