2025-10-10 18:19:44 +08:00
|
|
|
use solana_streamer_sdk::streaming::{
|
2026-05-15 07:46:29 +08:00
|
|
|
event_parser::common::{filter::EventTypeFilter, EventType},
|
2026-05-15 05:09:29 +08:00
|
|
|
event_parser::{DexEvent, Protocol},
|
2025-10-10 18:19:44 +08:00
|
|
|
shred::StreamClientConfig,
|
|
|
|
|
ShredStreamGrpc,
|
2025-07-19 23:46:42 +08:00
|
|
|
};
|
2025-01-03 00:38:45 +08:00
|
|
|
|
2025-01-02 19:44:38 +08:00
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2025-09-09 18:21:26 +08:00
|
|
|
println!("Starting ShredStream Streamer...");
|
2025-08-31 22:18:18 +08:00
|
|
|
test_shreds().await?;
|
2025-07-19 23:46:42 +08:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
2025-08-03 05:37:04 +08:00
|
|
|
println!("Subscribing to ShredStream events...");
|
|
|
|
|
|
2026-05-15 07:46:29 +08:00
|
|
|
// Create low-latency configuration.
|
|
|
|
|
// Metrics add overhead; enable explicitly with STREAMER_ENABLE_METRICS=1.
|
2026-06-01 20:20:01 +08:00
|
|
|
let config = StreamClientConfig {
|
|
|
|
|
enable_metrics: std::env::var("STREAMER_ENABLE_METRICS").as_deref() == Ok("1"),
|
|
|
|
|
..Default::default()
|
|
|
|
|
};
|
2025-08-03 21:59:08 +08:00
|
|
|
let shred_stream =
|
2025-08-29 14:59:16 +08:00
|
|
|
ShredStreamGrpc::new_with_config("http://127.0.0.1:10800".to_string(), config).await?;
|
2025-05-31 14:45:20 +08:00
|
|
|
|
2025-07-19 23:46:42 +08:00
|
|
|
let callback = create_event_callback();
|
2026-05-15 07:46:29 +08:00
|
|
|
let protocols = vec![Protocol::PumpFun];
|
2025-07-19 23:46:42 +08:00
|
|
|
|
2026-05-15 07:46:29 +08:00
|
|
|
// ShredStream uses the sol-parser-sdk ShredStream hot path. Keep filters narrow for
|
|
|
|
|
// latency-sensitive bots; use None to receive every event the SDK ShredStream path emits.
|
|
|
|
|
let event_type_filter = Some(EventTypeFilter::include_only(vec![
|
|
|
|
|
EventType::PumpFunBuy,
|
|
|
|
|
EventType::PumpFunSell,
|
|
|
|
|
EventType::PumpFunCreateToken,
|
|
|
|
|
EventType::PumpFunCreateV2Token,
|
|
|
|
|
]));
|
2025-08-18 01:08:12 +08:00
|
|
|
|
2025-08-03 05:37:04 +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-07-19 23:46:42 +08:00
|
|
|
|
2026-05-15 07:46:29 +08:00
|
|
|
// Demo safety stop: stop automatically after 1000 seconds.
|
2025-08-21 15:47:31 +08:00
|
|
|
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(())
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 22:00:15 +08:00
|
|
|
fn create_event_callback() -> impl Fn(DexEvent) {
|
|
|
|
|
|event: DexEvent| {
|
2025-08-31 22:18:18 +08:00
|
|
|
println!(
|
2026-03-07 12:35:57 +08:00
|
|
|
"🎉 Event received! Type: {:?}, tx_index: {:?}",
|
2025-10-10 18:19:44 +08:00
|
|
|
event.metadata().event_type,
|
2026-03-07 12:35:57 +08:00
|
|
|
event.metadata().tx_index
|
2025-08-31 22:18:18 +08:00
|
|
|
);
|
2026-06-01 20:20:01 +08:00
|
|
|
if let DexEvent::BlockMetaEvent(e) = event {
|
|
|
|
|
println!("BlockMetaEvent: {:?}", e.metadata.handle_us);
|
2025-10-10 18:19:44 +08:00
|
|
|
}
|
2025-07-19 23:46:42 +08:00
|
|
|
}
|
2025-10-10 18:19:44 +08:00
|
|
|
}
|