Skip to content

Instruction to Log Mapping #186

@nooma-42

Description

@nooma-42

Context

Some DEX protocols (e.g., Boop, Raydium) emit actual trade results as events/logs rather than storing them in instruction data. To properly parse these swaps, we need to correlate the instruction with its corresponding event logs.

Problem

Currently there's no straightforward way to:

  1. Know which logs belong to which instruction
  2. Match an instruction with its emitted events before sending to handler

Proposed Solution

Add log assignment to InstructionUpdate:

pub struct InstructionUpdate {
    // ... existing fields
    /// Indices into `shared.log_messages` for logs emitted by this instruction
    pub log_indices: Vec<usize>,
}

Use Case Example

async fn handle(&self, ix: &SwapInstruction, input: &InstructionUpdate) -> HandlerResult<()> {
    // Get logs belonging to this specific instruction
    let logs: Vec<&str> = input.log_indices
        .iter()
        .filter_map(|&i| input.shared.log_messages.get(i))
        .collect();
    
    // Parse event from logs (e.g., PumpFun TradeEvent)
    let trade_event = parse_trade_event_from_logs(&logs)?;
    
    // Now we have both instruction data AND event data
    let swap = Swap {
        amount_in: trade_event.sol_amount,
        amount_out: trade_event.token_amount,
        // ...
    };
}

Notes

This is similar to how ix_path (PR #180) tracks instruction hierarchy, but for log assignment instead. The mapping can be derived from log messages like "Program XXX invoke [N]" and "Program XXX success".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions