๐Ÿ‘๏ธ readFlashState()

readFlashState()

Read the on-chain FlashState PDA to check loan status, compose with other protocols, and build advanced strategies.

What is readFlashState?

The FlashState PDA is the 98-byte account that tracks active flash loans. readFlashState() lets you deserialize and inspect this account โ€” useful for composability, monitoring, and building protocols on top of VAEA.

FieldTypeSizeDescription
payerPubkey32 BWallet that initiated the flash loan
token_mintPubkey32 BSPL token being borrowed
amountu648 BBorrowed amount in native units
feeu648 BFee in native units (amount ร— fee_bps / 10,000)
source_tieru81 BFee tier: 0=SDK, 1=UI, 2=Protocol
slotu648 BSlot when begin_flash was called
bumpu81 BPDA bump seed
Total98 BLightest flash loan state on Solana

Code Examples

import { readFlashState, deriveFlashStatePDA } from '@vaea/flash';

// Derive the PDA address for a given payer + token
const pda = deriveFlashStatePDA(walletPubkey, tokenMint);

// Read and deserialize the on-chain state
const state = await readFlashState(connection, pda);

if (state) {
  console.log('Active loan:', {
    payer: state.payer.toBase58(),
    token: state.tokenMint.toBase58(),
    amount: state.amount.toString(),
    fee: state.fee.toString(),
    tier: ['SDK', 'UI', 'Protocol'][state.sourceTier],
    slot: state.slot.toString(),
  });
} else {
  console.log('No active flash loan for this wallet/token');
}

Composability

Any on-chain program can read the FlashState PDA to verify a flash loan is active โ€” this is the foundation of Zero-CPI integration:

rust
// On-chain: read FlashState PDA without CPI
pub fn my_handler(ctx: Context<MyAccounts>) -> Result<()> {
    let flash = vaea_flash_ctx::verify(
        &ctx.accounts.flash_state,
        &ctx.accounts.sysvar_ix,
    )?;
    
    // Now you know:
    // - A VAEA flash loan IS active
    // - The exact amount and token borrowed
    // - The fee tier being used
    // All without consuming any CPI depth!
    
    msg!("Flash loan active: {} tokens", flash.amount);
    Ok(())
}

Use Cases

Protocol Composability
Let your protocol verify and react to active flash loans without CPI overhead
Monitoring Dashboard
Track active flash loans in real-time by polling FlashState PDAs
Conditional Logic
Execute different strategies based on whether a flash loan is active
Audit & Analytics
Read historical FlashState data for fee analysis and volume tracking
โ„น๏ธ Note
FlashState PDAs are ephemeral โ€” they exist only during the transaction. After the TX completes (success or revert), the account is closed and rent is returned. readFlashState() is primarily useful for on-chain composability and real-time monitoring.