2025-07-19 23:46:42 +08:00
# Solana Streamer
[中文 ](https://github.com/0xfnzero/solana-streamer/blob/main/README_CN.md ) | [English ](https://github.com/0xfnzero/solana-streamer/blob/main/README.md ) | [Telegram ](https://t.me/fnzero_group )
2024-12-31 16:51:58 +08:00
2025-07-19 23:46:42 +08:00
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.
2025-05-19 14:19:21 +08:00
2025-07-19 23:46:42 +08:00
## Project Features
2025-05-19 14:19:21 +08:00
2025-07-19 23:46:42 +08:00
1. **Real-time Event Streaming** : Subscribe to live trading events from multiple Solana DEX protocols
2. **Yellowstone gRPC Support** : High-performance event subscription using Yellowstone gRPC
3. **ShredStream Support** : Alternative event streaming using ShredStream protocol
4. **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
2025-08-11 22:02:09 +08:00
- **Raydium AMM V4**: Raydium's Automated Market Maker V4 events
2025-07-19 23:46:42 +08:00
5. **Unified Event Interface** : Consistent event handling across all supported protocols
6. **Event Parsing System** : Automatic parsing and categorization of protocol-specific events
2025-08-13 23:30:59 +08:00
7. **Account State Monitoring** : Real-time monitoring of protocol account states and configuration changes
8. **Transaction & Account Event Filtering** : Separate filtering for transaction events and account state changes
9. **High Performance** : Optimized for low-latency event processing
10. **Batch Processing Optimization** : Batch processing events to reduce callback overhead
11. **Performance Monitoring** : Built-in performance metrics monitoring, including event processing speed, etc.
12. **Memory Optimization** : Object pooling and caching mechanisms to reduce memory allocations
13. **Flexible Configuration System** : Support for custom batch sizes, backpressure strategies, channel sizes, and other parameters
2025-08-31 22:18:18 +08:00
14. **Preset Configurations** : Provides high-throughput and low-latency preset configurations optimized for different use cases
15. **Backpressure Handling** : Supports blocking and dropping backpressure strategies
2025-08-13 23:30:59 +08:00
16. **Runtime Configuration Updates** : Supports dynamic configuration parameter updates at runtime
17. **Full Function Performance Monitoring** : All subscribe_events functions support performance monitoring, automatically collecting and reporting performance metrics
2025-08-21 15:47:31 +08:00
18. **Graceful Shutdown** : Support for programmatic stop() method for clean shutdown
2025-08-25 17:09:14 -07:00
19. **Dynamic Subscription Management** : Runtime filter updates without reconnection, enabling adaptive monitoring strategies
2025-05-19 14:19:21 +08:00
2025-05-31 14:45:20 +08:00
## Installation
2025-07-20 00:39:42 +08:00
### Direct Clone
2025-07-19 23:46:42 +08:00
Clone this project to your project directory:
```bash
cd your_project_root_directory
git clone https://github.com/0xfnzero/solana-streamer
```
Add the dependency to your `Cargo.toml` :
2025-05-19 14:19:21 +08:00
```toml
2025-07-19 23:46:42 +08:00
# Add to your Cargo.toml
2025-08-31 22:26:35 +08:00
solana-streamer-sdk = { path = "./solana-streamer" , version = "0.4.0" }
2025-07-20 00:39:42 +08:00
```
### Use crates.io
```toml
# Add to your Cargo.toml
2025-08-31 22:26:35 +08:00
solana-streamer-sdk = "0.4.0"
2025-05-19 14:19:21 +08:00
```
2025-08-29 14:59:16 +08:00
## Configuration System
### Preset Configurations
The library provides three preset configurations optimized for different use cases:
#### 1. High Throughput Configuration (`high_throughput()`)
Optimized for high-concurrency scenarios, prioritizing throughput over latency:
```rust
let config = StreamClientConfig ::high_throughput ();
// Or use convenience methods
let grpc = YellowstoneGrpc ::new_high_throughput ( endpoint , token ) ? ;
let shred = ShredStreamGrpc ::new_high_throughput ( endpoint ). await ? ;
```
**Features:**
- **Backpressure Strategy**: Drop - drops messages during high load to avoid blocking
- **Buffer Size**: 5,000 permits to handle burst traffic
- **Use Case**: Scenarios where you need to process large volumes of data and can tolerate occasional message drops during peak loads
#### 2. Low Latency Configuration (`low_latency()`)
Optimized for real-time scenarios, prioritizing latency over throughput:
```rust
let config = StreamClientConfig ::low_latency ();
// Or use convenience methods
let grpc = YellowstoneGrpc ::new_low_latency ( endpoint , token ) ? ;
let shred = ShredStreamGrpc ::new_low_latency ( endpoint ). await ? ;
```
**Features:**
- **Backpressure Strategy**: Block - ensures no data loss
2025-08-31 22:18:18 +08:00
- **Buffer Size**: 4000 permits for balanced throughput and latency
2025-08-29 14:59:16 +08:00
- **Immediate Processing**: No buffering, processes events immediately
- **Use Case**: Scenarios where every millisecond counts and you cannot afford to lose any events, such as trading applications or real-time monitoring
### Custom Configuration
You can also create custom configurations:
```rust
let config = StreamClientConfig {
connection : ConnectionConfig {
connect_timeout : 30 ,
request_timeout : 120 ,
max_decoding_message_size : 20 * 1024 * 1024 , // 20MB
},
backpressure : BackpressureConfig {
permits : 2000 ,
strategy : BackpressureStrategy ::Block ,
},
enable_metrics : true ,
};
```
2025-05-31 14:45:20 +08:00
## Usage Examples
2025-08-11 01:04:16 +08:00
### Quick Start - Parse Transaction Events
You can quickly test the library by running the built-in example that parses transaction events:
```bash
cargo run --example parse_tx_events
```
This example demonstrates:
- How to parse transaction data from Solana mainnet using RPC
2025-08-11 22:02:09 +08:00
- Event parsing for multiple protocols (PumpFun, PumpSwap, Bonk, Raydium CPMM/CLMM/AMM V4)
2025-08-11 01:04:16 +08:00
- Transaction details extraction including fees, logs, and compute units
The example uses a predefined transaction signature and shows how to extract protocol-specific events from the transaction data.
2025-08-25 17:09:14 -07:00
### Dynamic Subscription Management Example
Test runtime filter updates without reconnection:
```bash
cargo run --example dynamic_subscription
```
This example demonstrates:
- Creating initial subscriptions with specific protocol filters
- Updating subscription filters at runtime without reconnection
- Single subscription enforcement and proper error handling
- Clean shutdown and resource management
2025-08-16 14:48:51 +08:00
### Advanced Usage - Complete Example
2025-08-03 05:37:04 +08:00
2025-05-19 14:19:21 +08:00
```rust
2025-07-19 23:55:37 +08:00
use solana_streamer_sdk ::{
2025-07-19 23:46:42 +08:00
match_event ,
streaming ::{
event_parser ::{
2025-08-16 14:48:51 +08:00
common ::{ filter ::EventTypeFilter , EventType },
2025-07-19 23:46:42 +08:00
protocols ::{
2025-08-11 01:04:16 +08:00
bonk ::{
2025-08-13 23:30:59 +08:00
parser ::BONK_PROGRAM_ID , BonkGlobalConfigAccountEvent , BonkMigrateToAmmEvent ,
BonkMigrateToCpswapEvent , BonkPlatformConfigAccountEvent , BonkPoolCreateEvent ,
BonkPoolStateAccountEvent , BonkTradeEvent ,
2025-08-11 01:04:16 +08:00
},
2025-08-11 22:02:09 +08:00
pumpfun ::{
2025-08-13 23:30:59 +08:00
parser ::PUMPFUN_PROGRAM_ID , PumpFunBondingCurveAccountEvent ,
PumpFunCreateTokenEvent , PumpFunGlobalAccountEvent , PumpFunMigrateEvent ,
2025-08-11 22:02:09 +08:00
PumpFunTradeEvent ,
},
2025-07-26 17:11:28 +08:00
pumpswap ::{
parser ::PUMPSWAP_PROGRAM_ID , PumpSwapBuyEvent , PumpSwapCreatePoolEvent ,
2025-08-13 23:30:59 +08:00
PumpSwapDepositEvent , PumpSwapGlobalConfigAccountEvent ,
PumpSwapPoolAccountEvent , PumpSwapSellEvent , PumpSwapWithdrawEvent ,
2025-07-26 17:11:28 +08:00
},
2025-08-11 22:02:09 +08:00
raydium_amm_v4 ::{
2025-08-13 23:30:59 +08:00
parser ::RAYDIUM_AMM_V4_PROGRAM_ID , RaydiumAmmV4AmmInfoAccountEvent ,
2025-08-11 22:02:09 +08:00
RaydiumAmmV4DepositEvent , RaydiumAmmV4Initialize2Event , RaydiumAmmV4SwapEvent ,
RaydiumAmmV4WithdrawEvent , RaydiumAmmV4WithdrawPnlEvent ,
2025-07-26 17:11:28 +08:00
},
2025-08-11 22:02:09 +08:00
raydium_clmm ::{
2025-08-13 23:30:59 +08:00
parser ::RAYDIUM_CLMM_PROGRAM_ID , RaydiumClmmAmmConfigAccountEvent ,
RaydiumClmmClosePositionEvent , RaydiumClmmCreatePoolEvent ,
RaydiumClmmDecreaseLiquidityV2Event , RaydiumClmmIncreaseLiquidityV2Event ,
RaydiumClmmOpenPositionV2Event , RaydiumClmmOpenPositionWithToken22NftEvent ,
RaydiumClmmPoolStateAccountEvent , RaydiumClmmSwapEvent , RaydiumClmmSwapV2Event ,
RaydiumClmmTickArrayStateAccountEvent ,
2025-08-11 22:02:09 +08:00
},
raydium_cpmm ::{
2025-08-13 23:30:59 +08:00
parser ::RAYDIUM_CPMM_PROGRAM_ID , RaydiumCpmmAmmConfigAccountEvent ,
RaydiumCpmmDepositEvent , RaydiumCpmmInitializeEvent ,
RaydiumCpmmPoolStateAccountEvent , RaydiumCpmmSwapEvent ,
RaydiumCpmmWithdrawEvent ,
2025-08-11 22:02:09 +08:00
},
BlockMetaEvent ,
2025-07-19 23:46:42 +08:00
},
Protocol , UnifiedEvent ,
2025-08-11 22:02:09 +08:00
},
grpc ::ClientConfig ,
2025-08-18 01:08:12 +08:00
shred ::StreamClientConfig ,
2025-08-13 23:30:59 +08:00
yellowstone_grpc ::{ AccountFilter , TransactionFilter },
2025-08-11 22:02:09 +08:00
ShredStreamGrpc , YellowstoneGrpc ,
2025-07-19 23:46:42 +08:00
},
};
2025-05-19 14:19:21 +08:00
2025-07-19 23:46:42 +08:00
#[tokio::main]
async fn main () -> Result < (), Box < dyn std ::error ::Error >> {
2025-08-03 05:37:04 +08:00
println! ( "Starting Solana Streamer..." );
2025-07-19 23:46:42 +08:00
test_grpc (). await ? ;
test_shreds (). await ? ;
Ok (())
2025-05-31 14:45:20 +08:00
}
2025-05-19 14:19:21 +08:00
2025-07-19 23:46:42 +08:00
async fn test_grpc () -> Result < (), Box < dyn std ::error ::Error >> {
2025-08-03 05:37:04 +08:00
println! ( "Subscribing to Yellowstone gRPC events..." );
2025-05-31 14:45:20 +08:00
2025-08-05 01:07:57 +08:00
// Create low-latency configuration
2025-08-04 21:30:55 +08:00
let mut config = ClientConfig ::low_latency ();
// Enable performance monitoring, has performance overhead, disabled by default
config . enable_metrics = true ;
2025-08-03 05:37:04 +08:00
let grpc = YellowstoneGrpc ::new_with_config (
2025-05-31 14:45:20 +08:00
"https://solana-yellowstone-grpc.publicnode.com:443" . to_string (),
None ,
2025-08-04 21:30:55 +08:00
config ,
2025-05-31 14:45:20 +08:00
) ? ;
2025-08-11 01:04:16 +08:00
println! ( "GRPC client created successfully" );
2025-07-19 23:46:42 +08:00
let callback = create_event_callback ();
2025-07-26 17:11:28 +08:00
2025-08-11 01:04:16 +08:00
// Will try to parse corresponding protocol events from transactions
2025-07-19 23:46:42 +08:00
let protocols = vec! [
Protocol ::PumpFun ,
Protocol ::PumpSwap ,
Protocol ::Bonk ,
Protocol ::RaydiumCpmm ,
Protocol ::RaydiumClmm ,
2025-08-13 23:30:59 +08:00
Protocol ::RaydiumAmmV4 ,
2025-07-19 23:46:42 +08:00
];
2025-08-11 01:04:16 +08:00
println! ( "Protocols to monitor: {:?} " , protocols );
// Filter accounts
2025-07-26 17:11:28 +08:00
let account_include = vec! [
2025-08-13 23:30:59 +08:00
PUMPFUN_PROGRAM_ID . to_string (), // Listen to pumpfun program ID
PUMPSWAP_PROGRAM_ID . to_string (), // Listen to pumpswap program ID
BONK_PROGRAM_ID . to_string (), // Listen to bonk program ID
RAYDIUM_CPMM_PROGRAM_ID . to_string (), // Listen to raydium_cpmm program ID
RAYDIUM_CLMM_PROGRAM_ID . to_string (), // Listen to raydium_clmm program ID
RAYDIUM_AMM_V4_PROGRAM_ID . to_string (), // Listen to raydium_amm_v4 program ID
2025-07-26 17:11:28 +08:00
];
let account_exclude = vec! [];
let account_required = vec! [];
2025-08-16 14:48:51 +08:00
// Transaction filter for monitoring transaction events
2025-08-13 23:30:59 +08:00
let transaction_filter = TransactionFilter {
account_include : account_include . clone (),
account_exclude ,
account_required ,
};
2025-08-16 14:48:51 +08:00
// Account filter for monitoring account state changes
2025-08-13 23:30:59 +08:00
let account_filter = AccountFilter { account : vec ! [], owner : account_include . clone () };
2025-08-16 14:48:51 +08:00
// Event type filtering - optional
// No event filtering, includes all events
let event_type_filter = None ;
// Only include PumpSwapBuy and PumpSwapSell events
// let event_type_filter = Some(EventTypeFilter { include: vec![EventType::PumpSwapBuy, EventType::PumpSwapSell] });
println! ( "Starting to listen for events, press Ctrl+C to stop..." );
println! ( "Monitoring programs: {:?} " , account_include );
println! ( "Starting subscription..." );
2025-08-11 01:04:16 +08:00
grpc . subscribe_events_immediate (
2025-07-26 17:11:28 +08:00
protocols ,
None ,
2025-08-13 23:30:59 +08:00
transaction_filter ,
account_filter ,
2025-08-16 14:48:51 +08:00
event_type_filter ,
2025-07-26 17:11:28 +08:00
None ,
callback ,
)
. await ? ;
2025-07-19 23:46:42 +08:00
2025-08-21 15:47:31 +08:00
// Support stop method, test code - stop after 1000 seconds asynchronously
let grpc_clone = grpc . clone ();
tokio ::spawn ( async move {
tokio ::time ::sleep ( std ::time ::Duration ::from_secs ( 1000 )). await ;
grpc_clone . stop (). await ;
});
println! ( "Waiting for Ctrl+C to stop..." );
tokio ::signal ::ctrl_c (). await ? ;
2025-05-31 14:45:20 +08:00
Ok (())
}
2025-07-19 23:46:42 +08:00
async fn test_shreds () -> Result < (), Box < dyn std ::error ::Error >> {
println! ( "Subscribing to ShredStream events..." );
2025-05-31 14:45:20 +08:00
2025-08-05 01:07:57 +08:00
// Create low-latency configuration
2025-08-18 01:08:12 +08:00
let mut config = StreamClientConfig ::low_latency ();
2025-08-04 21:30:55 +08:00
// Enable performance monitoring, has performance overhead, disabled by default
config . enable_metrics = true ;
let shred_stream =
ShredStreamGrpc ::new_with_config ( "http://127.0.0.1:10800" . to_string (), config ). await ? ;
2025-07-19 23:46:42 +08:00
let callback = create_event_callback ();
let protocols = vec! [
Protocol ::PumpFun ,
Protocol ::PumpSwap ,
Protocol ::Bonk ,
Protocol ::RaydiumCpmm ,
Protocol ::RaydiumClmm ,
2025-08-11 22:02:09 +08:00
Protocol ::RaydiumAmmV4 ,
2025-07-19 23:46:42 +08:00
];
2025-07-19 23:55:37 +08:00
2025-08-18 01:08:12 +08:00
// Event filtering
// No event filtering, includes all events
let event_type_filter = None ;
// Only include PumpSwapBuy events and PumpSwapSell events
// let event_type_filter =
// EventTypeFilter { include: vec![EventType::PumpSwapBuy, EventType::PumpSwapSell] };
2025-07-19 23:46:42 +08:00
println! ( "Listening for events, press Ctrl+C to stop..." );
2025-08-18 01:08:12 +08:00
shred_stream . shredstream_subscribe ( protocols , None , event_type_filter , callback ). await ? ;
2025-05-31 14:45:20 +08:00
2025-08-21 15:47:31 +08:00
// Support stop method, test code - stop after 1000 seconds asynchronously
let shred_clone = shred_stream . clone ();
tokio ::spawn ( async move {
tokio ::time ::sleep ( std ::time ::Duration ::from_secs ( 1000 )). await ;
shred_clone . stop (). await ;
});
println! ( "Waiting for Ctrl+C to stop..." );
tokio ::signal ::ctrl_c (). await ? ;
2025-07-19 23:46:42 +08:00
Ok (())
}
fn create_event_callback () -> impl Fn ( Box < dyn UnifiedEvent > ) {
| event : Box < dyn UnifiedEvent >| {
2025-08-03 05:37:04 +08:00
println! ( "🎉 Event received! Type: {:?} , ID: {} " , event . event_type (), event . id ());
2025-07-19 23:46:42 +08:00
match_event! ( event , {
2025-08-16 14:48:51 +08:00
// -------------------------- block meta -----------------------
2025-08-11 01:04:16 +08:00
BlockMetaEvent => | e : BlockMetaEvent | {
println! ( "BlockMetaEvent: {e:?} " );
},
2025-08-16 14:48:51 +08:00
// -------------------------- bonk -----------------------
2025-07-19 23:46:42 +08:00
BonkPoolCreateEvent => | e : BonkPoolCreateEvent | {
2025-07-25 16:43:06 +08:00
// When using grpc, you can get block_time from each event
println! ( "block_time: {:?} , block_time_ms: {:?} " , e . metadata . block_time , e . metadata . block_time_ms );
2025-07-19 23:46:42 +08:00
println! ( "BonkPoolCreateEvent: {:?} " , e . base_mint_param . symbol );
},
BonkTradeEvent => | e : BonkTradeEvent | {
2025-08-11 01:04:16 +08:00
println! ( "BonkTradeEvent: {e:?} " );
2025-07-19 23:46:42 +08:00
},
2025-08-03 21:59:08 +08:00
BonkMigrateToAmmEvent => | e : BonkMigrateToAmmEvent | {
println! ( "BonkMigrateToAmmEvent: {e:?} " );
},
BonkMigrateToCpswapEvent => | e : BonkMigrateToCpswapEvent | {
println! ( "BonkMigrateToCpswapEvent: {e:?} " );
},
2025-08-16 14:48:51 +08:00
// -------------------------- pumpfun -----------------------
2025-07-19 23:46:42 +08:00
PumpFunTradeEvent => | e : PumpFunTradeEvent | {
2025-08-11 01:04:16 +08:00
println! ( "PumpFunTradeEvent: {e:?} " );
2025-07-19 23:46:42 +08:00
},
2025-08-11 22:02:09 +08:00
PumpFunMigrateEvent => | e : PumpFunMigrateEvent | {
println! ( "PumpFunMigrateEvent: {e:?} " );
},
2025-07-19 23:46:42 +08:00
PumpFunCreateTokenEvent => | e : PumpFunCreateTokenEvent | {
2025-08-11 01:04:16 +08:00
println! ( "PumpFunCreateTokenEvent: {e:?} " );
2025-07-19 23:46:42 +08:00
},
2025-08-16 14:48:51 +08:00
// -------------------------- pumpswap -----------------------
2025-07-19 23:46:42 +08:00
PumpSwapBuyEvent => | e : PumpSwapBuyEvent | {
2025-08-11 01:04:16 +08:00
println! ( "Buy event: {e:?} " );
2025-07-19 23:46:42 +08:00
},
PumpSwapSellEvent => | e : PumpSwapSellEvent | {
2025-08-11 01:04:16 +08:00
println! ( "Sell event: {e:?} " );
2025-07-19 23:46:42 +08:00
},
PumpSwapCreatePoolEvent => | e : PumpSwapCreatePoolEvent | {
2025-08-11 01:04:16 +08:00
println! ( "CreatePool event: {e:?} " );
2025-07-19 23:46:42 +08:00
},
PumpSwapDepositEvent => | e : PumpSwapDepositEvent | {
2025-08-11 01:04:16 +08:00
println! ( "Deposit event: {e:?} " );
2025-07-19 23:46:42 +08:00
},
PumpSwapWithdrawEvent => | e : PumpSwapWithdrawEvent | {
2025-08-11 01:04:16 +08:00
println! ( "Withdraw event: {e:?} " );
2025-07-19 23:46:42 +08:00
},
2025-08-16 14:48:51 +08:00
// -------------------------- raydium_cpmm -----------------------
2025-07-19 23:46:42 +08:00
RaydiumCpmmSwapEvent => | e : RaydiumCpmmSwapEvent | {
2025-08-11 01:04:16 +08:00
println! ( "RaydiumCpmmSwapEvent: {e:?} " );
2025-07-19 23:46:42 +08:00
},
2025-08-11 22:02:09 +08:00
RaydiumCpmmDepositEvent => | e : RaydiumCpmmDepositEvent | {
println! ( "RaydiumCpmmDepositEvent: {e:?} " );
},
RaydiumCpmmInitializeEvent => | e : RaydiumCpmmInitializeEvent | {
println! ( "RaydiumCpmmInitializeEvent: {e:?} " );
},
RaydiumCpmmWithdrawEvent => | e : RaydiumCpmmWithdrawEvent | {
println! ( "RaydiumCpmmWithdrawEvent: {e:?} " );
},
2025-08-16 14:48:51 +08:00
// -------------------------- raydium_clmm -----------------------
2025-07-19 23:46:42 +08:00
RaydiumClmmSwapEvent => | e : RaydiumClmmSwapEvent | {
2025-08-11 01:04:16 +08:00
println! ( "RaydiumClmmSwapEvent: {e:?} " );
2025-07-19 23:46:42 +08:00
},
RaydiumClmmSwapV2Event => | e : RaydiumClmmSwapV2Event | {
2025-08-11 01:04:16 +08:00
println! ( "RaydiumClmmSwapV2Event: {e:?} " );
2025-08-11 22:02:09 +08:00
},
RaydiumClmmClosePositionEvent => | e : RaydiumClmmClosePositionEvent | {
println! ( "RaydiumClmmClosePositionEvent: {e:?} " );
},
RaydiumClmmDecreaseLiquidityV2Event => | e : RaydiumClmmDecreaseLiquidityV2Event | {
println! ( "RaydiumClmmDecreaseLiquidityV2Event: {e:?} " );
},
RaydiumClmmCreatePoolEvent => | e : RaydiumClmmCreatePoolEvent | {
println! ( "RaydiumClmmCreatePoolEvent: {e:?} " );
},
RaydiumClmmIncreaseLiquidityV2Event => | e : RaydiumClmmIncreaseLiquidityV2Event | {
println! ( "RaydiumClmmIncreaseLiquidityV2Event: {e:?} " );
},
RaydiumClmmOpenPositionWithToken22NftEvent => | e : RaydiumClmmOpenPositionWithToken22NftEvent | {
println! ( "RaydiumClmmOpenPositionWithToken22NftEvent: {e:?} " );
},
RaydiumClmmOpenPositionV2Event => | e : RaydiumClmmOpenPositionV2Event | {
println! ( "RaydiumClmmOpenPositionV2Event: {e:?} " );
},
2025-08-16 14:48:51 +08:00
// -------------------------- raydium_amm_v4 -----------------------
2025-08-11 22:02:09 +08:00
RaydiumAmmV4SwapEvent => | e : RaydiumAmmV4SwapEvent | {
println! ( "RaydiumAmmV4SwapEvent: {e:?} " );
},
RaydiumAmmV4DepositEvent => | e : RaydiumAmmV4DepositEvent | {
println! ( "RaydiumAmmV4DepositEvent: {e:?} " );
},
RaydiumAmmV4Initialize2Event => | e : RaydiumAmmV4Initialize2Event | {
println! ( "RaydiumAmmV4Initialize2Event: {e:?} " );
},
RaydiumAmmV4WithdrawEvent => | e : RaydiumAmmV4WithdrawEvent | {
println! ( "RaydiumAmmV4WithdrawEvent: {e:?} " );
},
RaydiumAmmV4WithdrawPnlEvent => | e : RaydiumAmmV4WithdrawPnlEvent | {
println! ( "RaydiumAmmV4WithdrawPnlEvent: {e:?} " );
},
2025-08-13 23:30:59 +08:00
// -------------------------- account -----------------------
BonkPoolStateAccountEvent => | e : BonkPoolStateAccountEvent | {
println! ( "BonkPoolStateAccountEvent: {e:?} " );
},
BonkGlobalConfigAccountEvent => | e : BonkGlobalConfigAccountEvent | {
println! ( "BonkGlobalConfigAccountEvent: {e:?} " );
},
BonkPlatformConfigAccountEvent => | e : BonkPlatformConfigAccountEvent | {
println! ( "BonkPlatformConfigAccountEvent: {e:?} " );
},
PumpSwapGlobalConfigAccountEvent => | e : PumpSwapGlobalConfigAccountEvent | {
println! ( "PumpSwapGlobalConfigAccountEvent: {e:?} " );
},
PumpSwapPoolAccountEvent => | e : PumpSwapPoolAccountEvent | {
println! ( "PumpSwapPoolAccountEvent: {e:?} " );
},
PumpFunBondingCurveAccountEvent => | e : PumpFunBondingCurveAccountEvent | {
println! ( "PumpFunBondingCurveAccountEvent: {e:?} " );
},
PumpFunGlobalAccountEvent => | e : PumpFunGlobalAccountEvent | {
println! ( "PumpFunGlobalAccountEvent: {e:?} " );
},
RaydiumAmmV4AmmInfoAccountEvent => | e : RaydiumAmmV4AmmInfoAccountEvent | {
println! ( "RaydiumAmmV4AmmInfoAccountEvent: {e:?} " );
},
RaydiumClmmAmmConfigAccountEvent => | e : RaydiumClmmAmmConfigAccountEvent | {
println! ( "RaydiumClmmAmmConfigAccountEvent: {e:?} " );
},
RaydiumClmmPoolStateAccountEvent => | e : RaydiumClmmPoolStateAccountEvent | {
println! ( "RaydiumClmmPoolStateAccountEvent: {e:?} " );
},
RaydiumClmmTickArrayStateAccountEvent => | e : RaydiumClmmTickArrayStateAccountEvent | {
println! ( "RaydiumClmmTickArrayStateAccountEvent: {e:?} " );
},
RaydiumCpmmAmmConfigAccountEvent => | e : RaydiumCpmmAmmConfigAccountEvent | {
println! ( "RaydiumCpmmAmmConfigAccountEvent: {e:?} " );
},
RaydiumCpmmPoolStateAccountEvent => | e : RaydiumCpmmPoolStateAccountEvent | {
println! ( "RaydiumCpmmPoolStateAccountEvent: {e:?} " );
},
2025-07-19 23:46:42 +08:00
});
2025-05-19 14:19:21 +08:00
}
2025-05-31 14:45:20 +08:00
}
2025-05-19 14:19:21 +08:00
```
2025-08-16 14:48:51 +08:00
### Event Filtering
2025-08-18 01:08:12 +08:00
The library supports flexible event filtering to reduce processing overhead and improve performance:
#### Basic Filtering
2025-08-16 14:48:51 +08:00
```rust
use solana_streamer_sdk ::streaming ::event_parser ::common ::{ filter ::EventTypeFilter , EventType };
// No filtering - receive all events
let event_type_filter = None ;
// Filter specific event types - only receive PumpSwap buy/sell events
let event_type_filter = Some ( EventTypeFilter {
include : vec ! [ EventType ::PumpSwapBuy , EventType ::PumpSwapSell ]
});
```
2025-08-18 01:08:12 +08:00
#### Performance Impact
Event filtering can provide significant performance improvements:
- **60-80% reduction** in unnecessary event processing
- **Lower memory usage** by filtering out irrelevant events
- **Reduced network bandwidth** in distributed setups
- **Better focus** on events that matter to your application
#### Filtering Examples by Use Case
**Trading Bot (Focus on Trade Events)**
```rust
let event_type_filter = Some ( EventTypeFilter {
include : vec ! [
EventType ::PumpSwapBuy ,
EventType ::PumpSwapSell ,
EventType ::PumpFunTrade ,
EventType ::RaydiumCpmmSwap ,
EventType ::RaydiumClmmSwap ,
EventType ::RaydiumAmmV4Swap ,
......
]
});
```
**Pool Monitoring (Focus on Liquidity Events)**
```rust
let event_type_filter = Some ( EventTypeFilter {
include : vec ! [
EventType ::PumpSwapCreatePool ,
EventType ::PumpSwapDeposit ,
EventType ::PumpSwapWithdraw ,
EventType ::RaydiumCpmmInitialize ,
EventType ::RaydiumCpmmDeposit ,
EventType ::RaydiumCpmmWithdraw ,
EventType ::RaydiumClmmCreatePool ,
......
]
});
```
2025-08-25 17:09:14 -07:00
## Dynamic Subscription Management
Update subscription filters at runtime without reconnecting to the stream.
```rust
// Update filters on existing subscription
grpc . update_subscription (
TransactionFilter {
account_include : vec ! [ "new_program_id" . to_string ()],
account_exclude : vec ! [],
account_required : vec ! [],
},
AccountFilter {
account : vec ! [],
owner : vec ! [],
},
). await ? ;
```
- **No Reconnection**: Filter changes apply immediately without closing the stream
- **Atomic Updates**: Both transaction and account filters updated together
- **Single Subscription**: One active subscription per client instance
- **Compatible**: Works with both immediate and advanced subscription methods
Note: Multiple subscription attempts on the same client return an error.
2025-07-19 23:46:42 +08:00
## Supported Protocols
2025-05-19 14:19:21 +08:00
2025-07-19 23:46:42 +08:00
- **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
2025-08-11 22:02:09 +08:00
- **Raydium AMM V4**: Raydium's Automated Market Maker V4 protocol
2025-07-19 23:46:42 +08:00
## 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
2025-08-11 22:02:09 +08:00
│ │ │ ├── raydium_amm_v4/ # Raydium AMM V4 event parsing
2025-07-19 23:46:42 +08:00
│ │ │ ├── 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
```
2025-05-31 14:45:20 +08:00
## License
2025-05-19 14:19:21 +08:00
2025-07-19 23:46:42 +08:00
MIT License
2025-05-28 12:47:19 +08:00
2025-07-19 23:46:42 +08:00
## Contact
- Project Repository: https://github.com/0xfnzero/solana-streamer
- Telegram Group: https://t.me/fnzero_group
2025-08-04 21:30:55 +08:00
## Performance Considerations
1. **Connection Management** : Properly handle connection lifecycle and reconnection
2. **Event Filtering** : Use protocol filtering to reduce unnecessary event processing
3. **Memory Management** : Implement appropriate cleanup for long-running streams
4. **Error Handling** : Robust error handling for network issues and service interruptions
5. **Batch Processing Optimization** : Use batch processing to reduce callback overhead and improve throughput
6. **Performance Monitoring** : Enable performance monitoring to identify bottlenecks and optimization opportunities
2025-08-21 15:47:31 +08:00
7. **Graceful Shutdown** : Use the stop() method for clean shutdown and implement signal handlers for proper resource cleanup
2025-08-04 21:30:55 +08:00
2025-07-19 23:46:42 +08:00
## Important Notes
1. **Network Stability** : Ensure stable network connection for continuous event streaming
2. **Rate Limiting** : Be aware of rate limits on public gRPC endpoints
3. **Error Recovery** : Implement proper error handling and reconnection logic
5. **Compliance** : Ensure compliance with relevant laws and regulations
## Language Versions
- [English ](README.md )
- [中文 ](README_CN.md )