mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-17 10:58:06 +00:00
refactor: restructure event handling from trait objects to enum pattern
- Convert UnifiedEvent from trait object (Box<dyn UnifiedEvent>) to concrete enum type - Remove match_event! macro in favor of native match expressions - Simplify event metadata access: event.event_type() -> event.metadata().event_type - Unify event callback signatures: Fn(Box<dyn UnifiedEvent>) -> Fn(UnifiedEvent) - Update all example code to use the new enum-based event system - Optimize type system to reduce runtime overhead and improve type safety Affected scope: - Core event parser and processor - All protocol event definitions (PumpFun, PumpSwap, Bonk, Raydium series, etc.) - gRPC and Shred streaming modules - All example code
This commit is contained in:
@@ -31,10 +31,10 @@ async fn main() -> Result<()> {
|
||||
let counter = event_counter.clone();
|
||||
|
||||
let callback =
|
||||
move |event: Box<dyn solana_streamer_sdk::streaming::event_parser::UnifiedEvent>| {
|
||||
move |event: solana_streamer_sdk::streaming::event_parser::UnifiedEvent| {
|
||||
let count = counter.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
let protocol = match event.event_type() {
|
||||
let protocol = match event.metadata().event_type {
|
||||
EventType::PumpFunBuy | EventType::PumpFunSell => "PumpFun",
|
||||
EventType::RaydiumCpmmSwapBaseInput | EventType::RaydiumCpmmSwapBaseOutput => {
|
||||
"RaydiumCpmm"
|
||||
@@ -42,7 +42,7 @@ async fn main() -> Result<()> {
|
||||
_ => "Unknown",
|
||||
};
|
||||
|
||||
println!("Event #{}: {:11} - {:.8}...", count + 1, protocol, event.signature());
|
||||
println!("Event #{}: {:11} - {:.8}...", count + 1, protocol, event.metadata().signature);
|
||||
};
|
||||
|
||||
println!("\n=== Phase 1: PumpFun only ===");
|
||||
@@ -254,7 +254,7 @@ async fn main() -> Result<()> {
|
||||
let shutdown_event_counter = Arc::new(AtomicU64::new(0));
|
||||
let shutdown_counter = shutdown_event_counter.clone();
|
||||
let shutdown_callback =
|
||||
move |_event: Box<dyn solana_streamer_sdk::streaming::event_parser::UnifiedEvent>| {
|
||||
move |_event: solana_streamer_sdk::streaming::event_parser::UnifiedEvent| {
|
||||
shutdown_counter.fetch_add(1, Ordering::Relaxed);
|
||||
};
|
||||
|
||||
@@ -327,7 +327,7 @@ async fn main() -> Result<()> {
|
||||
println!("\n=== Subscription enforcement ===");
|
||||
|
||||
let test_callback =
|
||||
|_event: Box<dyn solana_streamer_sdk::streaming::event_parser::UnifiedEvent>| {};
|
||||
|_event: solana_streamer_sdk::streaming::event_parser::UnifiedEvent| {};
|
||||
|
||||
match client
|
||||
.subscribe_events_immediate(
|
||||
@@ -358,7 +358,7 @@ async fn main() -> Result<()> {
|
||||
let client2_counter = Arc::new(AtomicU64::new(0));
|
||||
let counter2 = client2_counter.clone();
|
||||
let client2_callback =
|
||||
move |_event: Box<dyn solana_streamer_sdk::streaming::event_parser::UnifiedEvent>| {
|
||||
move |_event: solana_streamer_sdk::streaming::event_parser::UnifiedEvent| {
|
||||
counter2.fetch_add(1, Ordering::Relaxed);
|
||||
};
|
||||
|
||||
@@ -390,7 +390,7 @@ async fn main() -> Result<()> {
|
||||
println!("\n=== Advanced subscription enforcement ===");
|
||||
|
||||
let test_callback_advanced =
|
||||
|_event: Box<dyn solana_streamer_sdk::streaming::event_parser::UnifiedEvent>| {};
|
||||
|_event: solana_streamer_sdk::streaming::event_parser::UnifiedEvent| {};
|
||||
|
||||
let client3 =
|
||||
Arc::new(YellowstoneGrpc::new(GRPC_ENDPOINT.to_string(), API_KEY.map(|s| s.to_string()))?);
|
||||
@@ -447,7 +447,7 @@ async fn main() -> Result<()> {
|
||||
let client4_counter = Arc::new(AtomicU64::new(0));
|
||||
let counter4 = client4_counter.clone();
|
||||
let client4_callback =
|
||||
move |_event: Box<dyn solana_streamer_sdk::streaming::event_parser::UnifiedEvent>| {
|
||||
move |_event: solana_streamer_sdk::streaming::event_parser::UnifiedEvent| {
|
||||
counter4.fetch_add(1, Ordering::Relaxed);
|
||||
};
|
||||
|
||||
|
||||
+28
-203
@@ -1,52 +1,17 @@
|
||||
use solana_streamer_sdk::{
|
||||
match_event,
|
||||
streaming::{
|
||||
event_parser::{
|
||||
common::EventType,
|
||||
core::account_event_parser::{NonceAccountEvent, TokenAccountEvent, TokenInfoEvent},
|
||||
protocols::{
|
||||
bonk::{
|
||||
parser::BONK_PROGRAM_ID, BonkGlobalConfigAccountEvent, BonkMigrateToAmmEvent,
|
||||
BonkMigrateToCpswapEvent, BonkPlatformConfigAccountEvent, BonkPoolCreateEvent,
|
||||
BonkPoolStateAccountEvent, BonkTradeEvent,
|
||||
},
|
||||
pumpfun::{
|
||||
parser::PUMPFUN_PROGRAM_ID, PumpFunBondingCurveAccountEvent,
|
||||
PumpFunCreateTokenEvent, PumpFunGlobalAccountEvent, PumpFunMigrateEvent,
|
||||
PumpFunTradeEvent,
|
||||
},
|
||||
pumpswap::{
|
||||
parser::PUMPSWAP_PROGRAM_ID, PumpSwapBuyEvent, PumpSwapCreatePoolEvent,
|
||||
PumpSwapDepositEvent, PumpSwapGlobalConfigAccountEvent,
|
||||
PumpSwapPoolAccountEvent, PumpSwapSellEvent, PumpSwapWithdrawEvent,
|
||||
},
|
||||
raydium_amm_v4::{
|
||||
parser::RAYDIUM_AMM_V4_PROGRAM_ID, RaydiumAmmV4AmmInfoAccountEvent,
|
||||
RaydiumAmmV4DepositEvent, RaydiumAmmV4Initialize2Event, RaydiumAmmV4SwapEvent,
|
||||
RaydiumAmmV4WithdrawEvent, RaydiumAmmV4WithdrawPnlEvent,
|
||||
},
|
||||
raydium_clmm::{
|
||||
parser::RAYDIUM_CLMM_PROGRAM_ID, RaydiumClmmAmmConfigAccountEvent,
|
||||
RaydiumClmmClosePositionEvent, RaydiumClmmCreatePoolEvent,
|
||||
RaydiumClmmDecreaseLiquidityV2Event, RaydiumClmmIncreaseLiquidityV2Event,
|
||||
RaydiumClmmOpenPositionV2Event, RaydiumClmmOpenPositionWithToken22NftEvent,
|
||||
RaydiumClmmPoolStateAccountEvent, RaydiumClmmSwapEvent, RaydiumClmmSwapV2Event,
|
||||
RaydiumClmmTickArrayStateAccountEvent,
|
||||
},
|
||||
raydium_cpmm::{
|
||||
parser::RAYDIUM_CPMM_PROGRAM_ID, RaydiumCpmmAmmConfigAccountEvent,
|
||||
RaydiumCpmmDepositEvent, RaydiumCpmmInitializeEvent,
|
||||
RaydiumCpmmPoolStateAccountEvent, RaydiumCpmmSwapEvent,
|
||||
RaydiumCpmmWithdrawEvent,
|
||||
},
|
||||
BlockMetaEvent,
|
||||
},
|
||||
Protocol, UnifiedEvent,
|
||||
use solana_streamer_sdk::streaming::{
|
||||
event_parser::{
|
||||
protocols::{
|
||||
bonk::parser::BONK_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,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
Protocol, UnifiedEvent,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -60,7 +25,7 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Subscribing to Yellowstone gRPC events...");
|
||||
|
||||
// Create low-latency configuration
|
||||
let mut config: ClientConfig = ClientConfig::low_latency();
|
||||
let mut config: ClientConfig = ClientConfig::default();
|
||||
// Enable performance monitoring, has performance overhead, disabled by default
|
||||
config.enable_metrics = true;
|
||||
let grpc = YellowstoneGrpc::new_with_config(
|
||||
@@ -105,7 +70,8 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
};
|
||||
|
||||
// Listen to account data belonging to owner programs -> account event monitoring
|
||||
let account_filter = AccountFilter { account: vec![], owner: account_include.clone(), filters: vec![] };
|
||||
let account_filter =
|
||||
AccountFilter { account: vec![], owner: account_include.clone(), filters: vec![] };
|
||||
|
||||
// Event filtering
|
||||
// No event filtering, includes all events
|
||||
@@ -142,162 +108,21 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
fn create_event_callback() -> impl Fn(UnifiedEvent) {
|
||||
|event: UnifiedEvent| {
|
||||
println!(
|
||||
"🎉 Event received! Type: {:?}, transaction_index: {:?}",
|
||||
event.event_type(),
|
||||
event.transaction_index()
|
||||
event.metadata().event_type,
|
||||
event.metadata().transaction_index
|
||||
);
|
||||
match_event!(event, {
|
||||
// -------------------------- block meta -----------------------
|
||||
BlockMetaEvent => |e: BlockMetaEvent| {
|
||||
println!("BlockMetaEvent: {:?}", e.metadata.handle_us);
|
||||
},
|
||||
// -------------------------- bonk -----------------------
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
// 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);
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {e:?}");
|
||||
},
|
||||
BonkMigrateToAmmEvent => |e: BonkMigrateToAmmEvent| {
|
||||
println!("BonkMigrateToAmmEvent: {e:?}");
|
||||
},
|
||||
BonkMigrateToCpswapEvent => |e: BonkMigrateToCpswapEvent| {
|
||||
println!("BonkMigrateToCpswapEvent: {e:?}");
|
||||
},
|
||||
// -------------------------- pumpfun -----------------------
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {e:?}");
|
||||
},
|
||||
PumpFunMigrateEvent => |e: PumpFunMigrateEvent| {
|
||||
println!("PumpFunMigrateEvent: {e:?}");
|
||||
},
|
||||
PumpFunCreateTokenEvent => |e: PumpFunCreateTokenEvent| {
|
||||
println!("PumpFunCreateTokenEvent: {e:?}");
|
||||
},
|
||||
// -------------------------- pumpswap -----------------------
|
||||
PumpSwapBuyEvent => |e: PumpSwapBuyEvent| {
|
||||
println!("Buy event: {e:?}");
|
||||
},
|
||||
PumpSwapSellEvent => |e: PumpSwapSellEvent| {
|
||||
println!("Sell event: {e:?}");
|
||||
},
|
||||
PumpSwapCreatePoolEvent => |e: PumpSwapCreatePoolEvent| {
|
||||
println!("CreatePool event: {e:?}");
|
||||
},
|
||||
PumpSwapDepositEvent => |e: PumpSwapDepositEvent| {
|
||||
println!("Deposit event: {e:?}");
|
||||
},
|
||||
PumpSwapWithdrawEvent => |e: PumpSwapWithdrawEvent| {
|
||||
println!("Withdraw event: {e:?}");
|
||||
},
|
||||
// -------------------------- raydium_cpmm -----------------------
|
||||
RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| {
|
||||
println!("RaydiumCpmmSwapEvent: {e:?}");
|
||||
},
|
||||
RaydiumCpmmDepositEvent => |e: RaydiumCpmmDepositEvent| {
|
||||
println!("RaydiumCpmmDepositEvent: {e:?}");
|
||||
},
|
||||
RaydiumCpmmInitializeEvent => |e: RaydiumCpmmInitializeEvent| {
|
||||
println!("RaydiumCpmmInitializeEvent: {e:?}");
|
||||
},
|
||||
RaydiumCpmmWithdrawEvent => |e: RaydiumCpmmWithdrawEvent| {
|
||||
println!("RaydiumCpmmWithdrawEvent: {e:?}");
|
||||
},
|
||||
// -------------------------- raydium_clmm -----------------------
|
||||
RaydiumClmmSwapEvent => |e: RaydiumClmmSwapEvent| {
|
||||
println!("RaydiumClmmSwapEvent: {e:?}");
|
||||
},
|
||||
RaydiumClmmSwapV2Event => |e: RaydiumClmmSwapV2Event| {
|
||||
println!("RaydiumClmmSwapV2Event: {e:?}");
|
||||
},
|
||||
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:?}");
|
||||
},
|
||||
// -------------------------- raydium_amm_v4 -----------------------
|
||||
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:?}");
|
||||
},
|
||||
// -------------------------- 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:?}");
|
||||
},
|
||||
TokenAccountEvent => |e: TokenAccountEvent| {
|
||||
println!("TokenAccountEvent: {e:?}");
|
||||
},
|
||||
NonceAccountEvent => |e: NonceAccountEvent| {
|
||||
println!("NonceAccountEvent: {e:?}");
|
||||
},
|
||||
TokenInfoEvent => |e: TokenInfoEvent| {
|
||||
println!("TokenInfoEvent: {e:?}");
|
||||
},
|
||||
});
|
||||
match event {
|
||||
UnifiedEvent::BlockMetaEvent(e) => {
|
||||
println!("{:?}", e);
|
||||
}
|
||||
// .... other events
|
||||
_ => {
|
||||
println!("{:?}", event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_streamer_sdk::{
|
||||
match_event,
|
||||
streaming::{
|
||||
event_parser::{
|
||||
common::{filter::EventTypeFilter, EventType},
|
||||
core::account_event_parser::TokenAccountEvent,
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
use solana_streamer_sdk::streaming::{
|
||||
event_parser::{
|
||||
common::{filter::EventTypeFilter, EventType},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
};
|
||||
use yellowstone_grpc_proto::geyser::{
|
||||
subscribe_request_filter_accounts_filter::Filter,
|
||||
@@ -30,7 +26,7 @@ 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
|
||||
let mut config: ClientConfig = ClientConfig::low_latency();
|
||||
let mut config: ClientConfig = ClientConfig::default();
|
||||
// Enable performance monitoring, has performance overhead, disabled by default
|
||||
config.enable_metrics = true;
|
||||
let grpc = YellowstoneGrpc::new_with_config(
|
||||
@@ -106,12 +102,11 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
TokenAccountEvent => |e: TokenAccountEvent| {
|
||||
println!("TokenAccount: {:?} amount: {:?}", e.pubkey, e.amount);
|
||||
},
|
||||
});
|
||||
fn create_event_callback() -> impl Fn(UnifiedEvent) {
|
||||
|event: UnifiedEvent| match event {
|
||||
UnifiedEvent::TokenAccountEvent(e) => {
|
||||
println!("TokenAccount: {:?} amount: {:?}", e.pubkey, e.amount);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ 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
|
||||
let mut config: ClientConfig = ClientConfig::low_latency();
|
||||
let mut config: ClientConfig = ClientConfig::default();
|
||||
// Enable performance monitoring, has performance overhead, disabled by default
|
||||
config.enable_metrics = true;
|
||||
let grpc = YellowstoneGrpc::new_with_config(
|
||||
@@ -75,8 +75,8 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
fn create_event_callback() -> impl Fn(UnifiedEvent) {
|
||||
|event: UnifiedEvent| {
|
||||
println!("🎉 Event received! {:?}", event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ async fn get_single_transaction_details(signature_str: &str) -> Result<()> {
|
||||
.parse_encoded_confirmed_transaction_with_status_meta(
|
||||
signature,
|
||||
transaction,
|
||||
Arc::new(move |event: &Box<dyn UnifiedEvent>| {
|
||||
Arc::new(move |event: &UnifiedEvent| {
|
||||
println!("{:?}\n", event);
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_streamer_sdk::{
|
||||
match_event,
|
||||
streaming::{
|
||||
event_parser::{
|
||||
common::{filter::EventTypeFilter, EventType},
|
||||
core::account_event_parser::TokenAccountEvent,
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
use solana_streamer_sdk::streaming::{
|
||||
event_parser::{
|
||||
common::{filter::EventTypeFilter, EventType},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
};
|
||||
use yellowstone_grpc_proto::geyser::{
|
||||
subscribe_request_filter_accounts_filter::Filter,
|
||||
@@ -108,12 +104,11 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
TokenAccountEvent => |e: TokenAccountEvent| {
|
||||
println!("TokenAccount: {:?} amount: {:?}", e.pubkey, e.amount);
|
||||
},
|
||||
});
|
||||
fn create_event_callback() -> impl Fn(UnifiedEvent) {
|
||||
|event: UnifiedEvent| match event {
|
||||
UnifiedEvent::TokenAccountEvent(e) => {
|
||||
println!("TokenAccount: {:?} amount: {:?}", e.pubkey, e.amount);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-196
@@ -1,51 +1,7 @@
|
||||
use solana_streamer_sdk::{
|
||||
match_event,
|
||||
streaming::{
|
||||
event_parser::{
|
||||
common::EventType,
|
||||
core::account_event_parser::TokenAccountEvent,
|
||||
protocols::{
|
||||
bonk::{
|
||||
BonkGlobalConfigAccountEvent, BonkMigrateToAmmEvent,
|
||||
BonkMigrateToCpswapEvent, BonkPlatformConfigAccountEvent, BonkPoolCreateEvent,
|
||||
BonkPoolStateAccountEvent, BonkTradeEvent,
|
||||
},
|
||||
pumpfun::{
|
||||
PumpFunBondingCurveAccountEvent,
|
||||
PumpFunCreateTokenEvent, PumpFunGlobalAccountEvent, PumpFunMigrateEvent,
|
||||
PumpFunTradeEvent,
|
||||
},
|
||||
pumpswap::{
|
||||
PumpSwapBuyEvent, PumpSwapCreatePoolEvent,
|
||||
PumpSwapDepositEvent, PumpSwapGlobalConfigAccountEvent,
|
||||
PumpSwapPoolAccountEvent, PumpSwapSellEvent, PumpSwapWithdrawEvent,
|
||||
},
|
||||
raydium_amm_v4::{
|
||||
RaydiumAmmV4AmmInfoAccountEvent,
|
||||
RaydiumAmmV4DepositEvent, RaydiumAmmV4Initialize2Event, RaydiumAmmV4SwapEvent,
|
||||
RaydiumAmmV4WithdrawEvent, RaydiumAmmV4WithdrawPnlEvent,
|
||||
},
|
||||
raydium_clmm::{
|
||||
RaydiumClmmAmmConfigAccountEvent,
|
||||
RaydiumClmmClosePositionEvent, RaydiumClmmCreatePoolEvent,
|
||||
RaydiumClmmDecreaseLiquidityV2Event, RaydiumClmmIncreaseLiquidityV2Event,
|
||||
RaydiumClmmOpenPositionV2Event, RaydiumClmmOpenPositionWithToken22NftEvent,
|
||||
RaydiumClmmPoolStateAccountEvent, RaydiumClmmSwapEvent, RaydiumClmmSwapV2Event,
|
||||
RaydiumClmmTickArrayStateAccountEvent,
|
||||
},
|
||||
raydium_cpmm::{
|
||||
RaydiumCpmmAmmConfigAccountEvent,
|
||||
RaydiumCpmmDepositEvent, RaydiumCpmmInitializeEvent,
|
||||
RaydiumCpmmPoolStateAccountEvent, RaydiumCpmmSwapEvent,
|
||||
RaydiumCpmmWithdrawEvent,
|
||||
},
|
||||
BlockMetaEvent,
|
||||
},
|
||||
Protocol, UnifiedEvent,
|
||||
},
|
||||
shred::StreamClientConfig,
|
||||
ShredStreamGrpc,
|
||||
},
|
||||
use solana_streamer_sdk::streaming::{
|
||||
event_parser::{Protocol, UnifiedEvent},
|
||||
shred::StreamClientConfig,
|
||||
ShredStreamGrpc,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -98,156 +54,18 @@ async fn test_shreds() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
fn create_event_callback() -> impl Fn(UnifiedEvent) {
|
||||
|event: UnifiedEvent| {
|
||||
println!(
|
||||
"🎉 Event received! Type: {:?}, transaction_index: {:?}",
|
||||
event.event_type(),
|
||||
event.transaction_index()
|
||||
event.metadata().event_type,
|
||||
event.metadata().transaction_index
|
||||
);
|
||||
match_event!(event, {
|
||||
// -------------------------- block meta -----------------------
|
||||
BlockMetaEvent => |e: BlockMetaEvent| {
|
||||
match event {
|
||||
UnifiedEvent::BlockMetaEvent(e) => {
|
||||
println!("BlockMetaEvent: {:?}", e.metadata.handle_us);
|
||||
},
|
||||
// -------------------------- bonk -----------------------
|
||||
BonkPoolCreateEvent => |e: BonkPoolCreateEvent| {
|
||||
// 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);
|
||||
println!("BonkPoolCreateEvent: {:?}", e.base_mint_param.symbol);
|
||||
},
|
||||
BonkTradeEvent => |e: BonkTradeEvent| {
|
||||
println!("BonkTradeEvent: {e:?}");
|
||||
},
|
||||
BonkMigrateToAmmEvent => |e: BonkMigrateToAmmEvent| {
|
||||
println!("BonkMigrateToAmmEvent: {e:?}");
|
||||
},
|
||||
BonkMigrateToCpswapEvent => |e: BonkMigrateToCpswapEvent| {
|
||||
println!("BonkMigrateToCpswapEvent: {e:?}");
|
||||
},
|
||||
// -------------------------- pumpfun -----------------------
|
||||
PumpFunTradeEvent => |e: PumpFunTradeEvent| {
|
||||
println!("PumpFunTradeEvent: {e:?}");
|
||||
},
|
||||
PumpFunMigrateEvent => |e: PumpFunMigrateEvent| {
|
||||
println!("PumpFunMigrateEvent: {e:?}");
|
||||
},
|
||||
PumpFunCreateTokenEvent => |e: PumpFunCreateTokenEvent| {
|
||||
println!("PumpFunCreateTokenEvent: {e:?}");
|
||||
},
|
||||
// -------------------------- pumpswap -----------------------
|
||||
PumpSwapBuyEvent => |e: PumpSwapBuyEvent| {
|
||||
println!("Buy event: {e:?}");
|
||||
},
|
||||
PumpSwapSellEvent => |e: PumpSwapSellEvent| {
|
||||
println!("Sell event: {e:?}");
|
||||
},
|
||||
PumpSwapCreatePoolEvent => |e: PumpSwapCreatePoolEvent| {
|
||||
println!("CreatePool event: {e:?}");
|
||||
},
|
||||
PumpSwapDepositEvent => |e: PumpSwapDepositEvent| {
|
||||
println!("Deposit event: {e:?}");
|
||||
},
|
||||
PumpSwapWithdrawEvent => |e: PumpSwapWithdrawEvent| {
|
||||
println!("Withdraw event: {e:?}");
|
||||
},
|
||||
// -------------------------- raydium_cpmm -----------------------
|
||||
RaydiumCpmmSwapEvent => |e: RaydiumCpmmSwapEvent| {
|
||||
println!("RaydiumCpmmSwapEvent: {e:?}");
|
||||
},
|
||||
RaydiumCpmmDepositEvent => |e: RaydiumCpmmDepositEvent| {
|
||||
println!("RaydiumCpmmDepositEvent: {e:?}");
|
||||
},
|
||||
RaydiumCpmmInitializeEvent => |e: RaydiumCpmmInitializeEvent| {
|
||||
println!("RaydiumCpmmInitializeEvent: {e:?}");
|
||||
},
|
||||
RaydiumCpmmWithdrawEvent => |e: RaydiumCpmmWithdrawEvent| {
|
||||
println!("RaydiumCpmmWithdrawEvent: {e:?}");
|
||||
},
|
||||
// -------------------------- raydium_clmm -----------------------
|
||||
RaydiumClmmSwapEvent => |e: RaydiumClmmSwapEvent| {
|
||||
println!("RaydiumClmmSwapEvent: {e:?}");
|
||||
},
|
||||
RaydiumClmmSwapV2Event => |e: RaydiumClmmSwapV2Event| {
|
||||
println!("RaydiumClmmSwapV2Event: {e:?}");
|
||||
},
|
||||
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:?}");
|
||||
},
|
||||
// -------------------------- raydium_amm_v4 -----------------------
|
||||
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:?}");
|
||||
},
|
||||
// -------------------------- 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:?}");
|
||||
},
|
||||
TokenAccountEvent => |e: TokenAccountEvent| {
|
||||
println!("TokenAccountEvent: {e:?}");
|
||||
},
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
fn create_event_callback() -> impl Fn(UnifiedEvent) {
|
||||
|event: UnifiedEvent| {
|
||||
println!("🎉 Event received! {:?}", event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
use solana_streamer_sdk::{
|
||||
match_event,
|
||||
streaming::{
|
||||
event_parser::{
|
||||
common::{filter::EventTypeFilter, EventType},
|
||||
core::account_event_parser::TokenInfoEvent,
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
use solana_streamer_sdk::streaming::{
|
||||
event_parser::{
|
||||
common::{filter::EventTypeFilter, EventType},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::ClientConfig,
|
||||
yellowstone_grpc::{AccountFilter, TransactionFilter},
|
||||
YellowstoneGrpc,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -80,12 +76,11 @@ async fn test_grpc() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
|event: Box<dyn UnifiedEvent>| {
|
||||
match_event!(event, {
|
||||
TokenInfoEvent => |e: TokenInfoEvent| {
|
||||
println!("TokenInfoEvent: {:?}", e.decimals);
|
||||
},
|
||||
});
|
||||
fn create_event_callback() -> impl Fn(UnifiedEvent) {
|
||||
|event: UnifiedEvent| match event {
|
||||
UnifiedEvent::TokenInfoEvent(e) => {
|
||||
println!("TokenInfoEvent: {:?}", e.decimals);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user