mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-20 12:28:08 +00:00
examples: update for SDK-backed streamer API
This commit is contained in:
+29
-11
@@ -1,11 +1,17 @@
|
||||
use solana_streamer_sdk::streaming::{
|
||||
event_parser::{
|
||||
common::{filter::EventTypeFilter, EventType},
|
||||
protocols::{
|
||||
bonk::parser::BONK_PROGRAM_ID, meteora_damm_v2::parser::METEORA_DAMM_V2_PROGRAM_ID,
|
||||
pumpfun::parser::PUMPFUN_PROGRAM_ID, pumpswap::parser::PUMPSWAP_PROGRAM_ID,
|
||||
bonk::parser::BONK_PROGRAM_ID,
|
||||
meteora_damm_v2::parser::METEORA_DAMM_V2_PROGRAM_ID,
|
||||
pumpfun::parser::PUMPFUN_PROGRAM_ID,
|
||||
pumpswap::parser::PUMPSWAP_PROGRAM_ID,
|
||||
raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
raydium_clmm::parser::RAYDIUM_CLMM_PROGRAM_ID,
|
||||
raydium_cpmm::parser::RAYDIUM_CPMM_PROGRAM_ID,
|
||||
sol_parser_forward::{
|
||||
METEORA_DLMM_PROGRAM_ID, METEORA_POOLS_PROGRAM_ID, ORCA_WHIRLPOOL_PROGRAM_ID,
|
||||
},
|
||||
},
|
||||
DexEvent, Protocol,
|
||||
},
|
||||
@@ -24,10 +30,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Subscribing to Yellowstone gRPC events...");
|
||||
|
||||
// Create low-latency configuration
|
||||
// Create low-latency configuration.
|
||||
let mut config: ClientConfig = ClientConfig::default();
|
||||
// Enable performance monitoring, has performance overhead, disabled by default
|
||||
config.enable_metrics = true;
|
||||
// Metrics add overhead; enable explicitly with STREAMER_ENABLE_METRICS=1.
|
||||
config.enable_metrics = std::env::var("STREAMER_ENABLE_METRICS").as_deref() == Ok("1");
|
||||
let grpc = YellowstoneGrpc::new_with_config(
|
||||
"https://solana-yellowstone-grpc.publicnode.com:443".to_string(),
|
||||
None,
|
||||
@@ -47,6 +53,9 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Protocol::RaydiumClmm,
|
||||
Protocol::RaydiumAmmV4,
|
||||
Protocol::MeteoraDammV2,
|
||||
Protocol::OrcaWhirlpool,
|
||||
Protocol::MeteoraPools,
|
||||
Protocol::MeteoraDlmm,
|
||||
];
|
||||
|
||||
println!("Protocols to monitor: {:?}", protocols);
|
||||
@@ -60,6 +69,9 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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
|
||||
METEORA_DAMM_V2_PROGRAM_ID.to_string(), // Listen to meteora_damm_v2 program ID
|
||||
ORCA_WHIRLPOOL_PROGRAM_ID.to_string(), // Listen to orca_whirlpool program ID
|
||||
METEORA_POOLS_PROGRAM_ID.to_string(), // Listen to meteora_pools program ID
|
||||
METEORA_DLMM_PROGRAM_ID.to_string(), // Listen to meteora_dlmm program ID
|
||||
];
|
||||
let account_exclude = vec![];
|
||||
let account_required = vec![];
|
||||
@@ -75,11 +87,17 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let account_filter =
|
||||
AccountFilter { account: vec![], owner: account_include.clone(), filters: vec![] };
|
||||
|
||||
// Event filtering
|
||||
// No event filtering, includes all events
|
||||
let event_type_filter = None;
|
||||
// Only include PumpSwapBuy events and PumpSwapSell events
|
||||
// let event_type_filter = Some(EventTypeFilter { include: vec![EventType::PumpFunTrade] });
|
||||
// Event filtering. Set STREAMER_TRADES_ONLY=1 to keep only selected trade events.
|
||||
let event_type_filter = if std::env::var("STREAMER_TRADES_ONLY").as_deref() == Ok("1") {
|
||||
Some(EventTypeFilter::include_only(vec![
|
||||
EventType::PumpFunBuy,
|
||||
EventType::PumpFunSell,
|
||||
EventType::PumpSwapBuy,
|
||||
EventType::PumpSwapSell,
|
||||
]))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
println!("Starting to listen for events, press Ctrl+C to stop...");
|
||||
println!("Monitoring programs: {:?}", account_include);
|
||||
@@ -97,7 +115,7 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
)
|
||||
.await?;
|
||||
|
||||
// 支持 stop 方法,测试代码 - 异步1000秒之后停止
|
||||
// Demo safety stop: stop automatically after 1000 seconds.
|
||||
let grpc_clone = grpc.clone();
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1000)).await;
|
||||
|
||||
Reference in New Issue
Block a user