Skip to main content
End-to-end Bun + TypeScript example. ~60 lines including imports. Hits devnet, requires only a funded wallet.

Prereqs

  • A devnet wallet at ~/.config/solana/id.json with ≥ 0.5 SOL.
  • IDLs for mint_redeem and faucet in ./idl/.
  • bun add @coral-xyz/anchor@0.32 @solana/web3.js @solana/spl-token

The script

Run:
Expected output (approximate):
The 0.22 cUSDC delta is the round-trip fees: 0.10 cUSDC mint fee + 0.10 cUSDC redeem fee, plus tiny rounding losses. Net: ~22 bps for a full mint+redeem cycle.

What just happened

  • Step 3 dripped 1000 cUSDC if needed. Subsequent runs skip this.
  • Step 5 deposited 100 cUSDC, received ~0.104 QQQL + ~49.95 QQQS, paid 0.10 cUSDC fee.
  • Step 6 burned the entire position, received ~99.78 cUSDC, paid 0.10 cUSDC fee.
If redeem_paired ever returned an unexpected number, double-check L_NAV and S_NAV against the on-chain market state - see Reading state.

Asymmetric redeem

Modify step 6 to redeem only one side:
You’ll receive lToBurn × L_NAV - fee cUSDC and still hold sToBurn worth of S. Sell it on the book when convenient, or hold for short exposure.

Common errors

Full error catalog

Extending the example

  • Mint multiple markets in one tx: build separate mint instructions for QQQ, SPY, etc., bundle in one Transaction.
  • Reactive UI: subscribe to marketPDA via connection.onAccountChange to refresh NAV automatically.
  • Trade post-mint: after step 5, immediately sell the short leg (book or committed order) to express a directional view - see Trade flow.

See also

Reading prices

Read NAV from on-chain TWAP, Hermes, and pool active bin.

Composability

Use cases: arb bot, structured products, integrations.