Trade Log

Instruction data (ABI)

pub struct TradeLogData {
    pub pool: Pubkey,
    pub trader: Pubkey,
    pub base_mint: Pubkey,
    pub quote_mint: Pubkey,

    /// Quote in (e.g., lamports or WSOL base units) charged by the pool for this trade
    pub base_amount: u64,
    /// Base tokens sent out to the trader (raw units)
    pub quote_amount: u64,

    /// Fees (quote units unless otherwise documented)
    pub creator_fee: u64,
    pub protocol_fee: u64,
    pub lp_fee: u64,

    /// true = buy, false = sell
    pub is_buy: bool,

    /// Balances around trade (pool vault balances, not "virtual" unless stated)
    pub base_balance_after: u64,
    pub quote_balance_after: u64,
    pub base_balance_before: u64,
    pub quote_balance_before: u64,

    /// Unix timestamp (seconds)
    pub timestamp: i64,
}

Where to find it (indexer checklist)

  1. Locate parent ix: a buy or sell

  2. Scan inner instructions for the same program id.

  3. Match discriminator: first 8 bytes of data equal sha256("log_trade_internal")[:8].

  4. Accounts: first account must be the event_authority PDA (["event_authority"]) and appear as a signer on the inner ix.

  5. Decode the remaining data[8..] as Borsh TradeLogData.


Suggested validations (indexer)

  • Asset sanity: Verify (base_mint, quote_mint) match the pool you track.

  • Delta check:

    • Compute Δbase = after_base − before_base and Δquote = after_quote − before_quote.

    • For is_buy = true, expect Δquote > 0 into pool and Δbase < 0 from pool.

  • Fee conservation: creator_fee + protocol_fee + lp_fee should equal total fees implied by your fee schedule and amounts.

  • Monotonic time: timestamp should not go backwards for the same pool.

Last updated