Developer Reference
Complete API reference for the vaea-flash-ctx crate โ function signatures, error types, constants, and protocol use cases.
verify()
Validates the flash loan context. Returns FlashContext on success, or a ProgramError if any check fails.
| Parameter | Type | Description |
|---|---|---|
| flash_state | &AccountInfo | The VAEA FlashState PDA โ must be owned by the VAEA program |
| sysvar_instructions | &AccountInfo | The instructions sysvar (Sysvar1nstructions...) |
FlashContext
| Field | Type | Notes |
|---|---|---|
| amount | u64 | In native token units (e.g. lamports for SOL, 1e6 for USDC) |
| token_mint | Pubkey | Use this to confirm which token was borrowed |
| fee | u64 | The VAEA fee, already calculated. 2 bps of borrowed amount |
| payer | Pubkey | The user who initiated the flash loan |
| source_tier | u8 | 0 = SDK bot, 1 = web UI, 2 = protocol-level CPI |
| slot_created | u64 | Should match the current slot โ used for freshness check |
Error Types
| Error | Code | Cause | Fix |
|---|---|---|---|
| InvalidOwner | 6000 | flash_state.owner is not the VAEA program | Pass the correct FlashState PDA |
| InvalidPDA | 6001 | PDA seeds don't match the expected derivation | Derive PDA correctly from payer + token_mint |
| NoBeginFlash | 6002 | begin_flash instruction not found before current IX | Ensure VAEA.begin_flash is in the TX before your IX |
| NoEndFlash | 6003 | end_flash instruction not found after current IX | Ensure VAEA.end_flash is in the TX after your IX |
| InvalidSysvar | 6004 | sysvar_instructions account is wrong | Pass Sysvar1nstructions... as the sysvar account |
| StaleSlot | 6005 | slot_created doesn't match current slot | The PDA is from a different transaction โ invalid |
Constants
Cost Breakdown
| Metric | Value | Notes |
|---|---|---|
| CPI consumed | 0 | PDA read โ not a cross-program call |
| Compute Units | ~2,000 CU | Owner check + deserialization + sysvar scan |
| Account rent | ~0.001 SOL | Reclaimed at end_flash |
| VAEA fee | 2 bps (0.02%) | Flat rate for all tiers |
Protocol Use Cases
| Use Case | How Your Program Uses CTX |
|---|---|
| Self-liquidation | Verify flash loan before releasing collateral โ prevent unauthorized withdrawals |
| Leverage vaults | Confirm initial deposit is flash-loaned โ enforce atomic rollback on failure |
| Risk gating | Read flash.amount to apply different risk parameters during flash loans |
| Atomic rebalancing | Compose with Jupiter + AMMs at full CPI depth โ impossible with CPI verification |
| Flash mint | Verify collateral backing before minting synthetic tokens |
FAQ
Does this work without Anchor?
Yes. The crate depends only on solana-program. Pass two AccountInfo references and call verify().
What happens if the user doesn't use VAEA?
If the user borrows directly from Kamino or Marginfi without VAEA, no FlashState PDA is created. verify() will fail with InvalidOwner or NoBeginFlash. Your program decides how to handle that โ reject the TX, or proceed without flash loan verification.
Can I make verification optional?
Yes. You can make the flash_state account optional in your Accounts struct and only call verify() if it's present. This lets your instruction work both inside and outside flash loans.
What if VAEA goes offline?
The VAEA on-chain program is immutable (no upgrade authority post-mainnet). verify() only reads on-chain data. It has zero dependency on VAEA's backend servers, API, or Smart Router. The verification is fully decentralized.