A minimal, production-ready Rust reference demonstrating atomic composable flash loans on Save Finance (formerly Solend) using solana-sdk 2.x and Versioned Transactions (v0).
Unlike legacy CPI callback patterns, composable flash loans on Save Finance utilize instructions introspection via sysvar::instructions:
FlashBorrowReserveLiquidity(#19) — Borrows reserve liquidity.- Arbitrage / Swaps — Arbitrary business logic executed between borrow and repay.
FlashRepayReserveLiquidity(#20) — Repays the borrowed amount + protocol fees, introspecting the earlier borrow instruction.
- Dynamic Introspection Indexing: The repay instruction requires the exact 0-based index of the matching borrow instruction (
borrow_instruction_index). This implementation dynamically computes the index regardless of prepended Compute Budget or setup instructions. - Fee Receiver Layout: Handles the protocol's requirement of using the Associated Token Account (ATA) of the reserve fee receiver rather than the wallet pubkey (
0xd / InvalidAccountInput).
- Rust
- A funded Solana keypair located at
~/.config/solana/id.json
git clone https://github.com/TrinityWeb3/save-flash-loan-rust.git
cd save-flash-loan-rustcargo runSolscan: 4ZTVMEjBnjDRHtjF14nd8jQ44aksN9Ln6nReP8TnhYfLYwrpeXeXgpB5An1zqrFBapTPL7EXSurfU1VxxuCLE1Rz