Solana Streamer
A lightweight Rust library for real-time event streaming from Solana DEX trading programs. This library provides efficient event parsing and subscription capabilities for PumpFun, PumpSwap, Bonk, and Raydium CPMM protocols.
Project Features
- Real-time Event Streaming: Subscribe to live trading events from multiple Solana DEX protocols
- Yellowstone gRPC Support: High-performance event subscription using Yellowstone gRPC
- ShredStream Support: Alternative event streaming using ShredStream protocol
- Multi-Protocol Support:
- PumpFun: Meme coin trading platform events
- PumpSwap: PumpFun's swap protocol events
- Bonk: Token launch platform events (letsbonk.fun)
- Raydium CPMM: Raydium's Concentrated Pool Market Maker events
- Raydium CLMM: Raydium's Concentrated Liquidity Market Maker events
- Unified Event Interface: Consistent event handling across all supported protocols
- Event Parsing System: Automatic parsing and categorization of protocol-specific events
- High Performance: Optimized for low-latency event processing
- Batch Processing: Efficient event batching to improve throughput and reduce overhead
- Performance Monitoring: Built-in performance metrics and monitoring capabilities
- Memory Optimization: Object pooling and caching to reduce memory allocations
Installation
Direct Clone
Clone this project to your project directory:
Add the dependency to your Cargo.toml:
# Add to your Cargo.toml
= { = "./solana-streamer", = "0.1.9" }
Use crates.io
# Add to your Cargo.toml
= "0.1.9"
Usage Examples
Basic Usage with Performance Monitoring
use ;
async
async
async
Supported Protocols
- PumpFun: Primary meme coin trading platform
- PumpSwap: PumpFun's swap protocol
- Bonk: Token launch platform (letsbonk.fun)
- Raydium CPMM: Raydium's Concentrated Pool Market Maker protocol
- Raydium CLMM: Raydium's Concentrated Liquidity Market Maker protocol
Event Streaming Services
- Yellowstone gRPC: High-performance Solana event streaming
- ShredStream: Alternative event streaming protocol
Architecture Features
Unified Event Interface
- UnifiedEvent Trait: All protocol events implement a common interface
- Protocol Enum: Easy identification of event sources
- Event Factory: Automatic event parsing and categorization
Event Parsing System
- Protocol-specific Parsers: Dedicated parsers for each supported protocol
- Event Factory: Centralized event creation and parsing
- Extensible Design: Easy to add new protocols and event types
Streaming Infrastructure
- Yellowstone gRPC Client: Optimized for Solana event streaming
- ShredStream Client: Alternative streaming implementation
- Async Processing: Non-blocking event handling
Project Structure
src/
βββ common/ # Common functionality and types
βββ protos/ # Protocol buffer definitions
βββ streaming/ # Event streaming system
β βββ event_parser/ # Event parsing system
β β βββ common/ # Common event parsing tools
β β βββ core/ # Core parsing traits and interfaces
β β βββ protocols/# Protocol-specific parsers
β β β βββ bonk/ # Bonk event parsing
β β β βββ pumpfun/ # PumpFun event parsing
β β β βββ pumpswap/ # PumpSwap event parsing
β β β βββ raydium_cpmm/ # Raydium CPMM event parsing
β β β βββ raydium_clmm/ # Raydium CLMM event parsing
β β βββ factory.rs # Parser factory
β βββ shred_stream.rs # ShredStream client
β βββ yellowstone_grpc.rs # Yellowstone gRPC client
β βββ yellowstone_sub_system.rs # Yellowstone subsystem
βββ lib.rs # Main library file
βββ main.rs # Example program
Performance Optimizations
Recent Performance Improvements
The latest version includes significant performance optimizations that dramatically improve event processing throughput:
1. Batch Processing System
- Event Batching: Events are now processed in batches (default: 100 events per batch) instead of individually
- Reduced Callback Overhead: Batch processing reduces the number of callback invocations by up to 100x
- Improved Throughput: Significantly higher event processing rates with lower CPU usage
- Configurable Batch Size: Adjustable batch size to balance latency vs throughput
2. Memory Optimization
- Object Pooling:
EventMetadataPoolandTransferDataPoolreduce memory allocations - Pre-allocated Vectors:
Vec::with_capacity()for collections to avoid dynamic resizing - Reduced Cloning: Minimized unnecessary data cloning operations
- Memory Usage Monitoring: Real-time memory usage tracking in performance metrics
3. Caching System
- Event Parse Cache:
EventParseCacheavoids redundant transaction parsing - Cache Hit Rate Monitoring: Track cache effectiveness in performance metrics
- Intelligent Cache Management: Automatic cache size management
4. Performance Monitoring
- Real-time Metrics: Built-in performance monitoring with automatic display
- Comprehensive Statistics: Events/second, processing times, memory usage, cache hit rates
- Configurable Monitoring: Enable/disable performance monitoring as needed
- Zero Overhead: Monitoring can be completely disabled for maximum performance
5. Concurrent Processing
- Async Event Processing: Non-blocking event handling with
tokio - Parallel Protocol Parsing: Multiple protocols parsed concurrently
- Optimized Channel Sizes: Increased channel capacity (5000) to handle high event volumes
Performance Metrics
The built-in performance monitoring provides detailed insights:
- Events Processed: Total number of events processed
- Events/Second: Real-time processing rate (5-second rolling window)
- Average Processing Time: Mean time to process events
- Min/Max Processing Time: Fastest and slowest processing times
- Cache Hit Rate: Percentage of cache hits for event parsing
- Memory Usage: Estimated memory consumption
Configuration Options
// Performance monitoring configuration
let grpc = new_with_config?;
// Batch processing is automatically enabled with optimal settings
// Batch size: 100 events
// Batch timeout: 10ms
// Channel size: 5000
Performance Considerations
- Connection Management: Properly handle connection lifecycle and reconnection
- Event Filtering: Use protocol filtering to reduce unnecessary event processing
- Memory Management: Implement proper cleanup for long-running streams
- Error Handling: Robust error handling for network issues and service disruptions
- Batch Processing: Leverage batch processing for high-throughput scenarios
- Performance Monitoring: Use built-in metrics to optimize your application
Configuration Options
Yellowstone gRPC Configuration
// Recommended: Create gRPC client with performance monitoring enabled
let grpc = new_with_config?;
// Alternative: Basic configuration (performance monitoring enabled by default)
let grpc = new?;
// Maximum performance: Disable performance monitoring
let grpc = new_with_config?;
ShredStream Configuration
// Recommended: Create ShredStream client with performance monitoring enabled
let shred_stream = new_with_config.await?;
// Alternative: Basic configuration (performance monitoring enabled by default)
let shred_stream = new.await?;
// Maximum performance: Disable performance monitoring
let shred_stream = new_with_config.await?;
Performance Tuning
// Runtime performance monitoring control
grpc.set_enable_metrics.await; // Enable monitoring
grpc.set_enable_metrics.await; // Disable monitoring
// Get current performance metrics
let metrics = grpc.get_metrics.await;
println!;
// Manual performance metrics display
grpc.print_metrics.await;
License
MIT License
Contact
- Project Repository: https://github.com/0xfnzero/solana-streamer
- Telegram Group: https://t.me/fnzero_group
Important Notes
- Network Stability: Ensure stable network connection for continuous event streaming
- Rate Limiting: Be aware of rate limits on public gRPC endpoints
- Error Recovery: Implement proper error handling and reconnection logic
- Resource Management: Monitor memory and CPU usage for long-running streams
- Compliance: Ensure compliance with relevant laws and regulations