Crate riglr_solana_events

Crate riglr_solana_events 

Source
Expand description

Standalone Solana event parsing library integrated with riglr-events-core.

This library provides comprehensive Solana event parsing capabilities with support for multiple protocols including Orca, Meteora, MarginFi, Jupiter, Raydium, and more.

§Migration to riglr-events-core

This crate has been enhanced to support both the legacy UnifiedEvent interface and the new riglr-events-core::Event interface for seamless migration.

§Legacy Usage (Maintained for backward compatibility)

use riglr_solana_events::prelude::*;

// Create a multi-parser for various protocols
let parser = EventParserFactory::with_all_parsers().build();

// Parse events using legacy interface
let events = parser.parse_events_from_instruction(
    &instruction,
    &accounts,
    "signature",
    slot,
    Some(block_time),
    received_time,
    "0".to_string(),
);

for event in events {
    println!("Legacy event: {}", event.id());
}

§New riglr-events-core Usage

use riglr_solana_events::prelude::*;
use riglr_events_core::prelude::*;

// Create a Solana event parser that implements riglr-events-core traits
let parser = SolanaEventParser::new();

let input = SolanaTransactionInput::new(
    instruction,
    accounts,
    "signature".to_string(),
    slot,
    Some(block_time),
    0,
);

// Parse events using new interface - returns Vec<Box<dyn Event>>
let events = parser.parse(input).await?;

for event in events {
    // Events implement both UnifiedEvent and Event traits
    println!("New event: {}", event.id());
    println!("Kind: {:?}", event.kind());
    println!("Source: {}", event.source());
}

§Hybrid Usage - Best of Both Worlds

use riglr_solana_events::prelude::*;

// Create SolanaEvent that implements both trait interfaces
let solana_event = SolanaEvent::swap(
    "event-1".to_string(),
    "signature123".to_string(),
    12345,
    1234567890,
    ProtocolType::Jupiter,
    program_id,
    input_mint,
    output_mint,
    1_000_000,
    950_000,
);

// Use legacy interface
println!("Slot: {}", solana_event.slot());
println!("Protocol: {}", solana_event.protocol_type());

// Use new interface
println!("Kind: {:?}", solana_event.kind());
let json = solana_event.to_json()?;
println!("JSON: {}", json);

§Features

  • Protocol Support: Orca, Meteora, MarginFi, Jupiter, Raydium AMM/CLMM/CPMM, PumpSwap, Bonk
  • Zero-copy Parsing: Efficient parsing with minimal allocations where possible
  • Dual Interface: Both legacy UnifiedEvent and new Event trait support
  • Type Safety: Strongly typed events with rich metadata
  • Async Ready: Full async/await support with proper Send/Sync bounds
  • Error Rich: Comprehensive error handling with context preservation

§Migration Guide

  1. Immediate: Use SolanaEvent for new event types - it implements both interfaces
  2. Gradual: Replace direct UnifiedEvent usage with Event trait where possible
  3. Parser Migration: Move from MultiEventParser to SolanaEventParser for new code
  4. Error Handling: Adopt EventError and EventResult types for better error context

The migration maintains 100% backward compatibility while providing access to enhanced functionality from riglr-events-core.

Re-exports§

pub use events::factory::EventParserRegistry;
pub use events::factory::Protocol;
pub use events::parser_types::GenericEventParseConfig;
pub use events::parser_types::GenericEventParser;
pub use types::EventType;
pub use types::ProtocolType;
pub use types::StreamMetadata;
pub use types::SwapData;
pub use types::TransferData;
pub use solana_events::SolanaEvent;
pub use solana_events::ToSolanaEvent;
pub use solana_parser::SolanaEventParser;
pub use solana_parser::SolanaInnerInstructionInput;
pub use solana_parser::SolanaInnerInstructionParser;
pub use solana_parser::SolanaTransactionInput;
pub use error::ParseError;
pub use error::ParseResult;

Modules§

constants
Constants used throughout the Solana events library
error
Error types and utilities for Solana event parsing
events
Core event structures and parsing logic Event parsing modules for Solana blockchain transactions.
metadata_helpers
Helper functions for working with Solana-specific metadata Helper functions for working with Solana-specific EventMetadata
parsers
High-performance parsers for specific protocols
pipelines
Event processing pipelines for validation and enrichment
prelude
Convenient re-exports for common types and traits used throughout the library
solana_events
Solana-specific event types that implement both legacy and new interfaces Solana-specific event implementations that bridge between old and new traits.
solana_metadata
Solana-specific metadata wrapper Solana-specific metadata wrapper for events
solana_parser
Parser implementation for the riglr-events-core Event trait Solana-specific event parser implementations using riglr-events-core.
types
Common types and data structures used across the library
utils
Utility functions for Solana event processing
zero_copy
Zero-copy parsing implementations for high-performance scenarios

Macros§

impl_to_solana_event
Macro to easily implement ToSolanaEvent for existing event types
match_event
Pattern matching macro for event types with type downcasting.

Enums§

EventError
Main error type for event processing operations.

Type Aliases§

EventResult
Specialized result type for event operations