Skip to content

About

Rust parser core for Solana DEX events from Yellowstone gRPC, Jito ShredStream, RPC transactions, and account data with Borsh/zero-copy backends.

Topics

Resources

Stars

43 stars

Watchers

2 watching

Forks

Repository files navigation

Sol Parser SDK β€” Rust

Solana DEX event parsing for Rust

sol-parser-sdk MIT License

English Β· δΈ­ζ–‡ Β· Examples Β· Documentation Β· Release and migration Β· Related SDKs

Parse typed events from gRPC, ShredStream, RPC transactions and protocol accounts for indexing, monitoring and trading systems.

Current version: 0.9.1. Read the migration notes before upgrading; see the changelog for historical changes.

Contents

πŸ“¦ SDK Versions and Related SDKs

Repositories are versioned independently; follow each SDK’s installation guide for compatible dependencies.

Language Repository Purpose Version
Rust sol-parser-sdk DEX transaction and account event parsing v0.9.1
Node.js sol-parser-sdk-nodejs DEX transaction and account event parsing v0.9.1
Python sol-parser-sdk-python DEX transaction and account event parsing v0.9.1
Go sol-parser-sdk-golang DEX transaction and account event parsing v0.9.1
Rust sol-trade-sdk Transaction building, signing and multi-channel submission v9.0.1
Node.js sol-trade-sdk-nodejs Transaction building, signing and multi-channel submission v9.0.1
Python sol-trade-sdk-python Transaction building, signing and multi-channel submission v9.0.1
Go sol-trade-sdk-golang Transaction building, signing and multi-channel submission v9.0.1
Rust sol-shred-sdk Raw shred decoding and ShredStream instruction events v6.0.1
Rust solana-streamer gRPC / ShredStream subscriptions and event streaming v5.0.0
Rust sol-trade-router-sdk On-chain multi-hop router and client SDK v0.3.0

πŸ”₯ Quick Start

Installation

# Add to your Cargo.toml
sol-parser-sdk = "0.9.1"

Or with the zero-copy parser (maximum performance):

sol-parser-sdk = { version = "0.9.1", default-features = false, features = ["parse-zero-copy"] }

Use from source

Clone the repository:

cd your_project_dir
git clone https://github.com/0xfnzero/sol-parser-sdk

Add to your Cargo.toml:

[dependencies]
# Default: Borsh parser
sol-parser-sdk = { path = "../sol-parser-sdk" }

# Or: Zero-copy parser (maximum performance)
sol-parser-sdk = { path = "../sol-parser-sdk", default-features = false, features = ["parse-zero-copy"] }

Performance Testing

Transaction-cost parsing is opt-in and does not run on the default DEX event path:

use sol_parser_sdk::{parse_yellowstone_transaction_cost, SwqosProvider};

let cost = parse_yellowstone_transaction_cost(&transaction, &meta).unwrap();
let jito_tip = cost.tip_lamports_for(SwqosProvider::Jito);

Yellowstone and RPC results use status metadata for the authoritative transaction fee and confirmed tip status. transaction_fee_lamports already includes the priority fee; relay tips are separate transfers and are added only in total_fee_and_tip_lamports. Tip recipients for every SWQoS provider supported by sol-trade-sdk are recognized automatically, and each TipPayment identifies its provider. ShredStream can expose requested compute-budget values and outer tip transfers, but cannot confirm fees, execution, inner instructions, or ALT-loaded tip recipients.

Test parsing latency with the optimized examples:

# PumpFun with detailed metrics (per-event + 10s stats)
cargo run --example pumpfun_with_metrics --release

# PumpSwap with detailed metrics (per-event + 10s stats)
cargo run --example pumpswap_with_metrics --release

# PumpSwap ultra-low latency test
cargo run --example pumpswap_low_latency --release

# PumpSwap with MicroBatch ordering
cargo run --example pumpswap_ordered --release

# Expected output:
# gRPC receive time: 1234567890 ΞΌs
# Event receive time: 1234567900 ΞΌs
# Latency: 10 ΞΌs  <-- Ultra-low latency!

Examples

Description Run Command Source Code
PumpFun
PumpFun event parsing with metrics cargo run --example pumpfun_with_metrics --release examples/pumpfun_with_metrics.rs
PumpFun trade type filtering cargo run --example pumpfun_trade_filter --release examples/pumpfun_trade_filter.rs
PumpFun trade with ordered mode cargo run --example pumpfun_trade_filter_ordered --release examples/pumpfun_trade_filter_ordered.rs
Quick PumpFun connection test cargo run --example pumpfun_quick_test --release examples/pumpfun_quick_test.rs
Parse PumpFun tx by signature TX_SIGNATURE=<sig> cargo run --example parse_pump_tx --release examples/parse_pump_tx.rs
Parse PumpFun quote-mint cases TX_SIGNATURES=<sig1,sig2> cargo run --example parse_pumpfun_quote_cases --release examples/parse_pumpfun_quote_cases.rs
Fetch any transaction and replay offline (preserves raw meta/logs/accounts) cargo run --example rpc_transaction_replay -- --fetch <SIGNATURE> /tmp/transaction.json examples/rpc_transaction_replay.rs
PumpSwap
PumpSwap events with metrics cargo run --example pumpswap_with_metrics --release examples/pumpswap_with_metrics.rs
PumpSwap ultra-low latency cargo run --example pumpswap_low_latency --release examples/pumpswap_low_latency.rs
PumpSwap with MicroBatch ordering cargo run --example pumpswap_ordered --release examples/pumpswap_ordered.rs
Parse PumpSwap tx by signature TX_SIGNATURE=<sig> cargo run --example parse_pumpswap_tx --release examples/parse_pumpswap_tx.rs
Meteora DAMM
Meteora DAMM V2 events cargo run --example meteora_damm_grpc --release examples/meteora_damm_grpc.rs
Parse Meteora DAMM tx by signature TX_SIGNATURE=<sig> cargo run --example parse_meteora_damm_tx --release examples/parse_meteora_damm_tx.rs
Non-Pump DEX dry-run scenarios
LaunchLab migration filter cargo run --example raydium_launchlab_migration examples/raydium_launchlab_migration.rs
Raydium CPMM new pool filter cargo run --example raydium_cpmm_new_pool examples/raydium_cpmm_new_pool.rs
Raydium CLMM token price math cargo run --example raydium_clmm_token_price examples/raydium_clmm_token_price.rs
Orca Whirlpool token price math cargo run --example orca_whirlpool_token_price examples/orca_whirlpool_token_price.rs
Meteora DAMM new pool baseline cargo run --example meteora_damm_new_pool examples/meteora_damm_new_pool.rs
Meteora DBC token price math cargo run --example meteora_dbc_token_price examples/meteora_dbc_token_price.rs
Wallet trade filter cargo run --example wallet_trade_filter examples/wallet_trade_filter.rs
gRPC latency slot compare config cargo run --example grpc_latency_slot_compare examples/grpc_latency_slot_compare.rs
Account subscription
Token account balance updates TOKEN_ACCOUNT=<pubkey> cargo run --example token_balance_listen --release examples/token_balance_listen.rs
Nonce account state changes NONCE_ACCOUNT=<pubkey> cargo run --example nonce_listen --release examples/nonce_listen.rs
Mint account info MINT_ACCOUNT=<pubkey> cargo run --example token_decimals_listen --release examples/token_decimals_listen.rs
PumpSwap pool accounts via memcmp cargo run --example pumpswap_pool_account_listen --release examples/pumpswap_pool_account_listen.rs
All ATAs for mints cargo run --example mint_all_ata_account_listen --release examples/mint_all_ata_account_listen.rs
ShredStream
Jito ShredStream subscription cargo run --example shredstream_example --release examples/shredstream_example.rs
Utility
Dynamic subscription filters cargo run --example dynamic_subscription --release examples/dynamic_subscription.rs

Basic Usage

use sol_parser_sdk::grpc::{
    AccountFilter, ClientConfig, EventType, EventTypeFilter, OrderMode, Protocol,
    TransactionFilter, YellowstoneGrpc,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create gRPC client with default config (Unordered mode)
    let grpc = YellowstoneGrpc::new(
        "https://solana-yellowstone-grpc.publicnode.com:443".to_string(),
        None,
    )?;

    // Or with custom config for ordered events
    let config = ClientConfig {
        order_mode: OrderMode::MicroBatch,  // Low latency + ordering
        micro_batch_us: 100,                // 100ΞΌs batch window
        ..ClientConfig::default()
    };
    let grpc = YellowstoneGrpc::new_with_config(
        "https://solana-yellowstone-grpc.publicnode.com:443".to_string(),
        None,
        config,
    )?;

    let protocols = vec![Protocol::PumpFun, Protocol::PumpSwap, Protocol::RaydiumCpmm];
    let transaction_filter = TransactionFilter::for_protocols(&protocols);
    let account_filter = AccountFilter::for_protocols(&protocols);

    // Filter before parsing for the lowest-latency path.
    let event_filter = EventTypeFilter::include_only(vec![
        EventType::PumpFunBuy,
        EventType::PumpFunSell,
        EventType::PumpSwapBuy,
        EventType::PumpSwapSell,
        EventType::RaydiumCpmmSwap,
    ]);

    // Subscribe and get lock-free queue
    let queue = grpc.subscribe_dex_events(
        vec![transaction_filter],
        vec![account_filter],
        Some(event_filter),
    ).await?;

    // Consume events with minimal latency
    tokio::spawn(async move {
        let mut spin_count = 0;
        loop {
            if let Some(event) = queue.pop() {
                spin_count = 0;
                // Process event (10-20ΞΌs latency!)
                println!("{:?}", event);
            } else {
                // Hybrid spin-wait strategy
                spin_count += 1;
                if spin_count < 1000 {
                    std::hint::spin_loop();
                } else {
                    tokio::task::yield_now().await;
                    spin_count = 0;
                }
            }
        }
    });

    Ok(())
}

ShredStream Usage (Jito)

ShredStream provides ultra-low latency (~50-100ms faster than gRPC) by directly subscribing to Jito's ShredStream service:

use sol_parser_sdk::grpc::{EventType, EventTypeFilter};
use sol_parser_sdk::shredstream::{ShredStreamClient, ShredStreamConfig};
use sol_parser_sdk::DexEvent;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create ShredStream client
    let client = ShredStreamClient::new("http://127.0.0.1:10800").await?;

    // Or with custom config
    let config = ShredStreamConfig {
        connection_timeout_ms: 5000,
        request_timeout_ms: 30000,
        max_decoding_message_size: 1024 * 1024 * 1024,
        reconnect_delay_ms: 1000,
        max_reconnect_attempts: 0, // 0 = infinite reconnect
    };
    let client = ShredStreamClient::new_with_config("http://127.0.0.1:10800", config).await?;

    // Subscribe with SDK-side filtering before event conversion.
    // Use `client.subscribe().await?` to receive every supported event.
    let event_filter = EventTypeFilter::include_only(vec![
        EventType::PumpFunBuy,
        EventType::PumpSwapBuy,
        EventType::RaydiumCpmmSwap,
    ]);
    let queue = client.subscribe_with_filter(Some(event_filter)).await?;

    // Consume events
    loop {
        if let Some(event) = queue.pop() {
            match &event {
                DexEvent::PumpFunTrade(e) => {
                    println!("PumpFun Trade: mint={}, is_buy={}", e.mint, e.is_buy);
                }
                DexEvent::PumpSwapBuy(e) => {
                    println!("PumpSwap Buy: pool={}", e.pool);
                }
                _ => {}
            }
        } else {
            std::hint::spin_loop();
        }
    }
}

ShredStream Limitations:

  • The default parser requires resolved instruction keys. Supply cached ALT addresses with parse_transaction_dex_events_with_loaded_addresses or with_address_lookup_resolver; unresolved instructions are skipped. An explicit best_effort API retains provisional legacy behavior.
  • No execution metadata: third-party instructions referencing Pump.fun produce unresolved trade candidates with original input in third_program; actual CPI trades and confirmed fills require gRPC/RPC execution metadata.
  • No block_time - always 0
  • tx_index is entry-level, not slot-level

What This SDK Is For

sol-parser-sdk is the low-level Rust parser core for Solana DEX events. It is designed for trading bots, copy-trading pipelines, sniper bots, indexers, and stream processors that need fast, typed parsing from Yellowstone gRPC transactions, Jito ShredStream entries, RPC transaction payloads, or account subscriptions.

Area Coverage
Parser inputs Yellowstone gRPC, ShredStream, RPC transactions, encoded transactions, protocol account data
DEX protocols PumpFun, PumpSwap, Pump Fees, LaunchLab (including StonkFun), Raydium CPMM, Raydium CLMM, Raydium AMM V4, Meteora DAMM v2, Meteora DLMM, Meteora DBC, Orca Whirlpool
Parser backends Default Borsh parser for maintainability, optional zero-copy parser for latency-sensitive hot paths
Related SDK Use solana-streamer (5.0.0) when you want a higher-level streaming facade over this parser core

πŸ”§ Advanced Features

Create+Buy Detection

Automatically detects when a token is created and immediately bought in the same transaction:

// Detects "Program data: GB7IKAUcB3c..." pattern
let has_create = detect_pumpfun_create(logs);

// Sets is_created_buy flag on Trade events
if has_create {
    trade_event.is_created_buy = true;
}

Pump.fun Bonding Curve v2 (buy_v2 / sell_v2 / buy_exact_quote_in_v2)

The SDK recognizes Pump.fun's new v2 trading instructions introduced in the Bonding Curve upgrade. Event logs from buy_v2, sell_v2, and buy_exact_quote_in_v2 are parsed with the same zero-copy path and mapped to the existing event types:

ix_name in TradeEvent DexEvent Variant
"buy" / "buy_v2" / "buy_exact_quote_in" / "buy_exact_quote_in_v2" DexEvent::PumpFunBuy
"sell" / "sell_v2" DexEvent::PumpFunSell
"buy_exact_sol_in" DexEvent::PumpFunBuyExactSolIn

No changes are required in your event handling code β€” v2 events arrive through the same PumpFunTradeEvent struct with the correct ix_name field populated. Instruction discriminators for buy_v2 ([184, 23, 238, 97, 103, 197, 211, 61]), sell_v2 ([93, 246, 130, 60, 231, 233, 64, 178]), and buy_exact_quote_in_v2 ([194, 171, 28, 70, 104, 77, 91, 47]) are recognized at the instruction parser level.

CreateEvent also exposes quote_mint and virtual_quote_reserves, so USDC quote pools can be distinguished from native SOL pools and initialized with the correct quote-side reserve.

Dynamic Subscription

Update filters without reconnecting:

grpc.update_subscription(
    vec![new_transaction_filter],
    vec![new_account_filter],
).await?;

Order Modes

Choose the right balance between latency and ordering:

use sol_parser_sdk::grpc::{ClientConfig, OrderMode};

// Ultra-low latency (no ordering guarantee)
let config = ClientConfig {
    order_mode: OrderMode::Unordered,
    ..ClientConfig::default()
};

// Low latency with micro-batch ordering (50-200ΞΌs)
let config = ClientConfig {
    order_mode: OrderMode::MicroBatch,
    micro_batch_us: 100,  // 100ΞΌs batch window
    ..ClientConfig::default()
};

// Stream ordering with continuous sequence release (0.1-5ms)
let config = ClientConfig {
    order_mode: OrderMode::StreamingOrdered,
    order_timeout_ms: 50,  // Timeout for incomplete sequences
    ..ClientConfig::default()
};

// Buffered slot ordering (flush on newer slot or timeout)
let config = ClientConfig {
    order_mode: OrderMode::Ordered,
    order_timeout_ms: 100,
    ..ClientConfig::default()
};

Performance Metrics

let config = ClientConfig {
    enable_metrics: true,
    ..ClientConfig::default()
};

let grpc = YellowstoneGrpc::new_with_config(endpoint, token, config)?;

Trade provenance and parsing boundaries

gRPC/RPC use supplied execution metadata and actual CPI instructions; Shred sees outer instructions and locally resolved accounts. An unknown third-party instruction referencing Pump.fun in its own accounts can produce a PumpFunTrade candidate with the original input in third_program and Unresolved status. This does not establish execution, direction or amounts. Buy/sell-only filters do not treat an unknown direction as a fill.

The parsing hot path performs no RPC. Check parse_status before interpreting defaults as amounts. Original account order and instruction bytes remain in third_program; transaction position and receive time remain in event metadata. A local Shred index is not confirmed slot-wide execution order. See wrapped transactions.

Stock price subscriptions

Uniform router provenance across supported gRPC trade families, plus an opt-in stock/ETF execution-price subscription with an extensible, screened multi-source catalog. No RPC in the parsing hot path. Missing live conversion or liquidity data stays unknown. See stock price subscriptions and trade provenance.

Cross-DEX stock routes: per-leg protocol/pool identification, Pump.fun v2 route support, and six signed mainnet replay cases. Run cargo run --example stock_route_replay offline.

Stock catalog admission uses at least $500 of verified liquid-side pool reserve, without a volume filter. Lower known fees take priority within each mint; historical fee snapshots distinguish pool fees from token transfer taxes. Parser and trade SDKs package the same 33-mint / 58-pool catalog and fee preference. Offline discovery includes Stonk, Pump.fun/PumpSwap and Raydium AMM v4/CPMM/CLMM; candidates require account, identity and depth validation.

πŸ“Š Performance Highlights

⚑ Ultra-Low Latency

  • 10-20ΞΌs parsing latency in release mode
  • Zero-copy parsing with stack-allocated buffers
  • SIMD-accelerated pattern matching (memchr)
  • Lock-free ArrayQueue for event delivery

🎚️ Flexible Order Modes

Mode Latency Description
Unordered 10-20ΞΌs Immediate output, ultra-low latency
MicroBatch 50-200ΞΌs Micro-batch ordering with time window
StreamingOrdered 0.1-5ms Stream ordering with continuous sequence release
Ordered 1-50ms Buffered slot ordering, flush on newer slot or timeout

Ordered output retains its last emitted (slot, tx_index) watermark. A newer-slot flush closes older slots; timeout flushing still accepts later transactions in the same slot with a higher index. Late data from closed slots or at/before the watermark is dropped with an Ordered continuity break warning. Events within one transaction preserve parser order. This mode cannot guarantee upstream completeness.

πŸš€ Optimization Highlights

  • βœ… Zero heap allocation for hot paths
  • βœ… SIMD pattern matching for all protocol detection
  • βœ… Static pre-compiled finders for string search
  • βœ… Inline functions with aggressive optimization
  • βœ… Event type filtering for targeted parsing
  • βœ… Conditional Create detection (only when needed)
  • βœ… Multiple order modes for latency vs ordering trade-off

πŸ—οΈ Supported Protocols

DEX Protocols

  • βœ… PumpFun - Meme coin trading (ultra-fast zero-copy path, incl. v2 instructions)
  • βœ… Pump Fees - Pump fee-sharing configuration events
  • βœ… PumpSwap - PumpFun swap protocol
  • βœ… LaunchLab - Token launch platform, including StonkFun attribution
  • βœ… Raydium AMM V4 - Automated Market Maker
  • βœ… Raydium CLMM - Concentrated Liquidity
  • βœ… Raydium CPMM - Concentrated Pool
  • βœ… Orca Whirlpool - Concentrated liquidity AMM
  • βœ… Meteora Pools - Dynamic AMM
  • βœ… Meteora DAMM v2 - Dynamic AMM V2
  • βœ… Meteora DLMM - Dynamic Liquidity Market Maker
  • 🚧 Meteora DBC - Program id and filters added; transaction/account parser pass pending

Event Types

Each protocol supports:

  • πŸ“ˆ Trade/Swap Events - Buy/sell transactions
  • πŸ’§ Liquidity Events - Deposits/withdrawals
  • 🏊 Pool Events - Pool creation/initialization
  • 🎯 Position Events - Open/close positions (CLMM)

Non-Pump DEX Support Matrix

Protocol Events Accounts Examples Language constants
LaunchLab Trade, pool create, migrate Pool/config snapshots Migration, buy/sell oracle planned Rust, Node, Python, Go
Raydium CPMM Swap, deposit, withdraw, initialize AmmConfig, PoolState New pool, token price Rust, Node, Python, Go
Raydium CLMM Swap, pool, position, liquidity AmmConfig, PoolState, TickArray Token price Rust, Node, Python, Go
Raydium AMM V4 Swap, deposit, withdraw, initialize2 Pending Token price oracle planned Rust, Node, Python, Go
Orca Whirlpool Swap, liquidity, pool init Whirlpool, Position, TickArray, FeeTier, Config Token price Rust, Node, Python, Go
Meteora Pools Swap, liquidity, pool create, fees Pending Token price oracle planned Rust, Node, Python, Go
Meteora DAMM V2 Swap, liquidity, position Pending New pool, token price oracle planned Rust, Node, Python, Go
Meteora DLMM Swap, liquidity, bin/position Pool/bin array/bitmap snapshots Token price oracle planned Rust, Node, Python, Go
Meteora DBC Swap, initialize pool, curve complete (Rust log parser) Pending Token price, migration oracle planned Rust, Node, Python, Go

The canonical cross-language baseline is tracked in protocols/canonical.json. Raw account updates are opt-in via AccountRawSnapshot; specialized snapshots cover LaunchLab pools/configs, DLMM pools/bin arrays/bitmap extensions, Whirlpool dynamic arrays/adaptive Oracles and CLMM bitmap extensions.

⚑ Performance Features

Zero-Copy Parsing

// Stack-allocated 512-byte buffer for PumpFun Trade
const MAX_DECODE_SIZE: usize = 512;
let mut decode_buf: [u8; MAX_DECODE_SIZE] = [0u8; MAX_DECODE_SIZE];

// Decode directly to stack, no heap allocation
general_purpose::STANDARD
    .decode_slice(data_part.as_bytes(), &mut decode_buf)
    .ok()?;

SIMD Pattern Matching

// Pre-compiled SIMD finders (initialized once)
static PUMPFUN_FINDER: Lazy<memmem::Finder> =
    Lazy::new(|| memmem::Finder::new(b"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"));

// 3-10x faster than .contains()
if PUMPFUN_FINDER.find(log_bytes).is_some() {
    return LogType::PumpFun;
}

Event Type Filtering

// Ultra-fast path for single event type
if include_only.len() == 1 && include_only[0] == EventType::PumpFunTrade {
    if log_type == LogType::PumpFun {
        return parse_pumpfun_trade(  // Zero-copy path
            log, signature, slot, block_time, grpc_recv_us, is_created_buy
        );
    }
}

Lock-Free Queue

// ArrayQueue with 100,000 capacity
let queue = Arc::new(ArrayQueue::<DexEvent>::new(100_000));

// Non-blocking push/pop (no mutex overhead)
let _ = queue.push(event);
if let Some(event) = queue.pop() {
    // Process event
}

🎯 Event Filtering

Reduce processing overhead by filtering specific events:

Example: Trading Bot

let event_filter = EventTypeFilter::include_only(vec![
    EventType::PumpFunBuy,
    EventType::PumpFunSell,
    EventType::PumpFunBuyExactSolIn,
    EventType::PumpSwapBuy,
    EventType::PumpSwapSell,
    EventType::RaydiumLaunchlabTrade,
    EventType::RaydiumCpmmSwap,
    EventType::RaydiumAmmV4Swap,
    EventType::RaydiumClmmSwap,
    EventType::OrcaWhirlpoolSwap,
    EventType::MeteoraPoolsSwap,
    EventType::MeteoraDammV2Swap,
    EventType::MeteoraDlmmSwap,
]);

Example: Pool Monitor

let event_filter = EventTypeFilter::include_only(vec![
    EventType::PumpFunCreate,
    EventType::PumpFeesUpdateFeeShares,
    EventType::PumpSwapCreatePool,
    EventType::AccountPumpSwapPool,
    EventType::RaydiumCpmmInitialize,
    EventType::RaydiumClmmCreatePool,
    EventType::OrcaWhirlpoolPoolInitialized,
    EventType::MeteoraPoolsPoolCreated,
    EventType::MeteoraDammV2CreatePosition,
    EventType::MeteoraDlmmInitializePool,
]);

PumpSwapCreatePool includes is_mayhem_mode. For is_cashback_coin, ShredStream/outer-instruction parsing reads the flag from the create_pool instruction args, while log-only CreatePoolEvent payloads keep the default false because the log event IDL does not carry this field. The authoritative account value is also available from PumpSwapPoolAccountEvent.pool.is_cashback_coin.

Performance Impact:

  • Avoids decoding excluded event families; measure the benefit with your event mix
  • Lower memory usage
  • Reduced network bandwidth

πŸ“ Project Structure

src/
β”œβ”€β”€ core/
β”‚   └── events.rs          # Event definitions
β”œβ”€β”€ grpc/
β”‚   β”œβ”€β”€ client.rs          # Yellowstone gRPC client
β”‚   β”œβ”€β”€ buffers.rs         # SlotBuffer & MicroBatchBuffer
β”‚   └── types.rs           # OrderMode, ClientConfig, filters
β”œβ”€β”€ shredstream/
β”‚   β”œβ”€β”€ client.rs          # Jito ShredStream client
β”‚   β”œβ”€β”€ config.rs          # ShredStreamConfig
β”‚   └── proto/             # Protobuf definitions
β”œβ”€β”€ logs/
β”‚   β”œβ”€β”€ optimized_matcher.rs  # SIMD log detection
β”‚   β”œβ”€β”€ zero_copy_parser.rs   # Zero-copy parsing
β”‚   β”œβ”€β”€ pumpfun.rs         # PumpFun parser
β”‚   β”œβ”€β”€ raydium_*.rs       # Raydium parsers
β”‚   β”œβ”€β”€ orca_*.rs          # Orca parsers
β”‚   └── meteora_*.rs       # Meteora parsers
β”œβ”€β”€ instr/
β”‚   └── *.rs               # Instruction parsers
β”œβ”€β”€ warmup/
β”‚   └── mod.rs             # Parser warmup (auto-called)
└── lib.rs

πŸš€ Optimization Techniques

1. SIMD String Matching

  • Replaced all .contains() with memmem::Finder
  • 3-10x performance improvement
  • Pre-compiled static finders

2. Zero-Copy Parsing

  • Stack-allocated buffers (512 bytes)
  • No heap allocation in hot path
  • Inline helper functions

3. Event Type Filtering

  • Early filtering at protocol level
  • Conditional Create detection
  • Single-type ultra-fast path

4. Lock-Free Queue

  • ArrayQueue (100K capacity)
  • Spin-wait hybrid strategy
  • No mutex overhead

5. Aggressive Inlining

#[inline(always)]
fn read_u64_le_inline(data: &[u8], offset: usize) -> Option<u64> {
    if offset + 8 <= data.len() {
        let mut bytes = [0u8; 8];
        bytes.copy_from_slice(&data[offset..offset + 8]);
        Some(u64::from_le_bytes(bytes))
    } else {
        None
    }
}

πŸ“Š Benchmarks

Parsing Latency (Release Mode)

Protocol Avg Latency Min Max
PumpFun Trade (zero-copy) 10-15ΞΌs 8ΞΌs 20ΞΌs
Raydium AMM V4 Swap 15-20ΞΌs 12ΞΌs 25ΞΌs
Orca Whirlpool Swap 15-20ΞΌs 12ΞΌs 25ΞΌs

SIMD Pattern Matching

Operation Before (contains) After (SIMD) Speedup
Protocol detection 50-100ns 10-20ns 3-10x
Create event detection 150ns 30ns 5x

⚠️ Performance Tips

  1. Use Event Filtering - Skip unneeded event families; measure with representative traffic
  2. Run in Release Mode - cargo build --release for full optimization
  3. Use repeatable measurements - Keep build profile, input corpus and machine load consistent; elevated privileges do not make timing accurate
  4. Monitor Latency - Check grpc_recv_us and queue latency in production
  5. Tune Queue Size - Adjust ArrayQueue capacity based on your throughput
  6. Spin-Wait Strategy - Tune spin count (default: 1000) for your use case

πŸ”¬ Development

# Run tests
cargo test

# Build release binary
cargo build --release

# Generate docs
cargo doc --open

Shared PumpFun create/create_v2 mainnet fixtures, replay instructions and verification limits are documented in the validation guide.

Usage documentation

πŸ“„ License

MIT License

πŸ“ž Contact

Shared stock bridges: 33 official stock/ETF mints and 58 pools. See eleven-SDK catalog and routing alignment for configuration, USDC routing and cache-only boundaries.

About

Rust parser core for Solana DEX events from Yellowstone gRPC, Jito ShredStream, RPC transactions, and account data with Borsh/zero-copy backends.

Topics

Resources

Stars

43 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages