๐Ÿ—๏ธ Architecture

Architecture

How VAEA Flash works under the hood โ€” the sandwich pattern, program accounts, multi-protocol routing, and security guarantees.

Sandwich Pattern

Every VAEA Flash loan is a single atomic Solana transaction. Your instructions are sandwiched between a begin_flash (borrow) and end_flash (repay) instruction.

text
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                Solana Transaction                 โ”‚
โ”‚                                                   โ”‚
โ”‚  IX 1:  begin_flash(SOL, 1000)                    โ”‚
โ”‚         โ†’ Transfer 1000 SOL from vault to wallet  โ”‚
โ”‚                                                   โ”‚
โ”‚  IX 2:  your_arbitrage_ix()                       โ”‚
โ”‚  IX 3:  your_swap_ix()                            โ”‚
โ”‚  IX 4:  ... (any number of instructions)          โ”‚
โ”‚                                                   โ”‚
โ”‚  IX N:  end_flash(SOL)                            โ”‚
โ”‚         โ†’ Transfer SOL + fee (2 bps) back to vault  โ”‚
โ”‚         โ†’ If insufficient balance โ†’ TX REVERTS    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ„น๏ธ Note
The atomicity guarantee means you can never end up in a state where you borrowed tokens but failed to repay. Either everything succeeds, or nothing happens. You only lose the base TX fee (~0.000005 SOL) on failure.

Program Accounts (PDAs)

The on-chain program uses Program Derived Addresses (PDAs) to manage state:

AccountPDA SeedsPurpose
Flash Vault["flash", token_mint]Holds borrowed tokens during the transaction
User State["flash", payer, token_mint]Tracks the active loan for a specific user/token pair
Config["config"]Global protocol configuration (fee rates, authority)
๐Ÿ’ก Tip
The SDK derives all PDAs automatically. You never need to compute them manually โ€” executeLocal() handles everything.

Multi-Protocol Routing

VAEA Flash doesn't hold any liquidity. It routes borrows through existing lending protocols with automatic fallback:

text
Your Request: "Borrow 1000 mSOL"
       โ†“
VAEA Router:
  1. Check Marginfi   โ†’ has mSOL?  โ†’ NO
  2. Check Kamino     โ†’ has mSOL?  โ†’ NO
  3. Check Jupiter Lend โ†’ has mSOL?  โ†’ NO
  4. No direct route  โ†’ Synthetic:
     โ†’ Borrow SOL from Marginfi (deepest pool)
     โ†’ Swap SOL โ†’ mSOL via Sanctum (~0.03% slippage)
     โ†’ You get mSOL โœ“
ProtocolRoleTokens Served
MarginfiPrimary lenderSOL, USDC, USDT, JupSOL, JitoSOL, JUP
KaminoFallbackSOL, USDC, cbBTC, JLP
Jupiter LendThird sourceSOL, USDC, USDT + 35 others

Address Lookup Tables

VAEA uses a pre-deployed Address Lookup Table (ALT) to compress transactions โ€” saving ~124 bytes per TX. Since Solana transactions are limited to 1232 bytes, this leaves maximum room for your instructions.

typescript
import { VAEA_LOOKUP_TABLE } from '@vaea/flash';
// DjncKSi9KqtnFx6hFYa7ARmwJ7B4Y7UH3XpR2XEuXNJr

// The ALT contains 4 fixed accounts:
// [0] Config PDA           โ€” 27qrSQk6xUGtdMQmMobsQWCSts67jtXqA2gZzPK1wubQ
// [1] Fee Vault PDA        โ€” BQNpRH1kahoFqxu5tiZaQYuKb7p41o3cmyXrFWsDmYPn
// [2] Sysvar Instructions  โ€” Sysvar1nstructions1111111111111111111111111
// [3] System Program       โ€” 11111111111111111111111111111111

// Auto-used by execute() / executeLocal() โ€” zero config
// Fetched once and cached for the lifetime of the VaeaFlash instance

Security Model

Security FeatureDetail
Instruction introspectionbegin_flash โ†” end_flash pairing verified within the same TX via sysvar
AtomicityIf repay fails, entire TX reverts โ€” no partial execution possible
Non-custodialTokens flow: lending protocol โ†’ you โ†’ lending protocol. VAEA never holds funds
PermissionlessAnyone can use โ€” no KYC, no registration, no approval needed
Fee floorMinimum 1 lamport fee prevents micro-loan evasion
Cross-token isolationPDA seeds include token_mint โ€” prevents collisions in multi-token flash
Zero data retentionNo database. On-chain state reads only. Zero user data stored