| Crates.io | sol-parser-sdk |
| lib.rs | sol-parser-sdk |
| version | 0.1.0 |
| created_at | 2025-09-26 03:00:41.349468+00 |
| updated_at | 2025-09-26 03:00:41.349468+00 |
| description | A lightweight Rust library for real-time event streaming from Solana DEX trading programs. Supports PumpFun, PumpSwap, Bonk, and Raydium protocols with Yellowstone gRPC and ShredStream. |
| homepage | |
| repository | https://github.com/0xfnzero/sol-parser-sdk |
| max_upload_size | |
| id | 1855366 |
| size | 896,517 |
High-performance Rust library for parsing Solana DEX events with microsecond-level latency
δΈζ | English | Website | Telegram | Discord
cd your_project_dir
git clone https://github.com/0xfnzero/sol-parser-sdk
Test parsing latency with the optimized example:
# Run performance test (requires sudo for high-precision timing)
sudo cargo run --example basic --release
# Expected output:
# gRPCζ₯ζΆζΆι΄: 1234567890 ΞΌs
# δΊδ»Άζ₯ζΆζΆι΄: 1234567900 ΞΌs
# δΊδ»Άθ§£ζθζΆ: 10 ΞΌs <-- Ultra-low latency!
Why sudo? The example uses libc::clock_gettime(CLOCK_REALTIME) for microsecond-precision timing, which may require elevated permissions on some systems.
use sol_parser_sdk::grpc::{YellowstoneGrpc, EventTypeFilter, EventType};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create gRPC client
let grpc = YellowstoneGrpc::new(
"https://solana-yellowstone-grpc.publicnode.com:443".to_string(),
None,
)?;
// Filter for PumpFun Trade events only (ultra-fast path)
let event_filter = EventTypeFilter::include_only(vec![
EventType::PumpFunTrade
]);
// 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(())
}
Each protocol supports:
// 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()?;
// 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;
}
// 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
);
}
}
// 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
}
Reduce processing overhead by filtering specific events:
let event_filter = EventTypeFilter::include_only(vec![
EventType::PumpFunTrade,
EventType::RaydiumAmmV4Swap,
EventType::RaydiumClmmSwap,
EventType::OrcaWhirlpoolSwap,
]);
let event_filter = EventTypeFilter::include_only(vec![
EventType::PumpFunCreate,
EventType::RaydiumClmmCreatePool,
EventType::OrcaWhirlpoolInitialize,
]);
Performance Impact:
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;
}
Update filters without reconnecting:
grpc.update_subscription(
vec![new_transaction_filter],
vec![new_account_filter],
).await?;
let mut config = ClientConfig::default();
config.enable_metrics = true;
let grpc = YellowstoneGrpc::new_with_config(endpoint, token, config)?;
src/
βββ core/
β βββ events.rs # Event definitions
βββ grpc/
β βββ client.rs # Yellowstone gRPC client
β βββ types.rs # Filter & config types
βββ 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
βββ lib.rs
.contains() with memmem::Finder#[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
}
}
| 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 |
| Operation | Before (contains) | After (SIMD) | Speedup |
|---|---|---|---|
| Protocol detection | 50-100ns | 10-20ns | 3-10x |
| Create event detection | 150ns | 30ns | 5x |
MIT License
cargo build --release for full optimizationsudo cargo run --example basic --release for accurate timinggrpc_recv_us and queue latency in production# Run tests
cargo test
# Run performance example
sudo cargo run --example basic --release
# Build release binary
cargo build --release
# Generate docs
cargo doc --open