Skip to main content

sol_parser_sdk/shredstream/
mod.rs

1//! ShredStream 模块 - Jito ShredStream 超低延迟交易订阅
2//!
3//! 提供从 Jito ShredStream 直接订阅 Solana Entry 数据的能力,
4//! 相比 gRPC 订阅具有更低的延迟(约 50-100ms 优势)。
5//!
6//! 实现拆分:`client` 负责网络与队列;`pump_ix` 为 **DEX 外层**指令热路径:
7//! Pump.fun 使用专用解析,其它已支持池子协议复用 `instr::parse_instruction_unified`;
8//!
9//! ## 使用示例
10//! ```rust,no_run
11//! use sol_parser_sdk::shredstream::{ShredStreamClient, ShredStreamConfig};
12//!
13//! #[tokio::main]
14//! async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
15//!     let client = ShredStreamClient::new("http://localhost:10800").await?;
16//!
17//!     // 订阅并获取事件队列
18//!     let queue = client.subscribe().await?;
19//!
20//!     // 消费事件
21//!     loop {
22//!         if let Some(event) = queue.pop() {
23//!             println!("Received: {:?}", event);
24//!         } else {
25//!             std::hint::spin_loop();
26//!         }
27//!     }
28//! }
29//! ```
30//!
31//! ## 事件过滤
32//! ShredStream proxy 本身推送完整 entry 流,不能像 Yellowstone gRPC 一样把交易账户过滤条件下发给服务端。
33//! SDK 仍支持本地热路径事件过滤:使用 [`ShredStreamClient::subscribe_with_filter`] 或
34//! [`ShredStreamClient::subscribe_with_filter_callback`],只解析/回调指定的 SDK 事件类型。
35//!
36//! ```rust,no_run
37//! use sol_parser_sdk::grpc::{EventType, EventTypeFilter};
38//! use sol_parser_sdk::shredstream::ShredStreamClient;
39//!
40//! #[tokio::main]
41//! async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
42//!     let client = ShredStreamClient::new("http://localhost:10800").await?;
43//!     let filter = EventTypeFilter::include_only(vec![EventType::PumpFunTrade]);
44//!     let queue = client.subscribe_with_filter(Some(filter)).await?;
45//!
46//!     loop {
47//!         if let Some(event) = queue.pop() {
48//!             println!("Received: {:?}", event);
49//!         } else {
50//!             tokio::task::yield_now().await;
51//!         }
52//!     }
53//! }
54//! ```
55//!
56//! ## 限制说明
57//! ShredStream 相比 gRPC 订阅有以下限制:
58//! - 仅 `static_account_keys()`:V0 交易若带 **地址查找表(ALT)**,ALT-loaded 指令账户会以 `Pubkey::default()` 占位;若程序 ID 也来自 ALT,会按指令 discriminator 做 best-effort 解析。
59//! - 不解析 **inner instructions**:只覆盖外层指令可解析的事件;若事件只存在于 CPI/Program log,需使用 gRPC/RPC 路径。
60//! - 无 block_time,恒为 0
61//! - tx_index 在单个 ShredStream payload 内递增,不保证等同于完整 slot 全局交易索引
62
63pub mod client;
64pub mod config;
65pub mod proto;
66pub(crate) mod pump_ix;
67
68pub use client::ShredStreamClient;
69pub use config::ShredStreamConfig;
70pub use pump_ix::{parse_transaction_dex_events, parse_transaction_dex_events_with_filter};