diff --git a/src/lib.rs b/src/lib.rs index 8416f5b..2e79b9d 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,3 @@ -pub mod streaming; +pub mod common; pub mod protos; -pub mod common; \ No newline at end of file +pub mod streaming; diff --git a/src/streaming/common/event_processor.rs b/src/streaming/common/event_processor.rs index a2364fe..e7ffe13 100644 --- a/src/streaming/common/event_processor.rs +++ b/src/streaming/common/event_processor.rs @@ -115,21 +115,20 @@ impl EventProcessor { transaction_pretty.block_time, transaction_pretty.program_received_time_us, bot_wallet, + transaction_pretty.transaction_index, ) .await .unwrap_or_else(|_e| vec![]); - let mut max_time_consuming_us = 0; + let mut all_time_consuming_us = 0; let event_count = all_events.len(); // 为所有事件设置交易索引 for mut event in all_events { - event.set_transaction_index(transaction_pretty.transaction_index); event.set_program_handle_time_consuming_us( chrono::Utc::now().timestamp_micros() - event.program_received_time_us(), ); - max_time_consuming_us = - max_time_consuming_us.max(event.program_handle_time_consuming_us()); + all_time_consuming_us += event.program_handle_time_consuming_us(); self.invoke_callback(event); } @@ -137,7 +136,7 @@ impl EventProcessor { self.update_metrics( MetricsEventType::Transaction, event_count as u64, - max_time_consuming_us as f64, + all_time_consuming_us as f64, Some(signature), ); } @@ -199,6 +198,7 @@ impl EventProcessor { None, program_received_time_us, bot_wallet, + None, ) .await .unwrap_or_else(|_e| vec![]); diff --git a/src/streaming/event_parser/common/mod.rs b/src/streaming/event_parser/common/mod.rs index 85c2d90..c74b304 100755 --- a/src/streaming/event_parser/common/mod.rs +++ b/src/streaming/event_parser/common/mod.rs @@ -76,10 +76,6 @@ macro_rules! impl_unified_event { fn transaction_index(&self) -> Option { self.metadata.transaction_index } - - fn set_transaction_index(&mut self, transaction_index: Option) { - self.metadata.set_transaction_index(transaction_index); - } } }; } diff --git a/src/streaming/event_parser/common/types.rs b/src/streaming/event_parser/common/types.rs index 2bc74ba..60c1e1a 100755 --- a/src/streaming/event_parser/common/types.rs +++ b/src/streaming/event_parser/common/types.rs @@ -323,12 +323,12 @@ impl EventMetadata { instruction_outer_index: i64, instruction_inner_index: Option, program_received_time_us: i64, + transaction_index: Option, ) -> Self { Self { id, signature, slot, - transaction_index: None, // 默认为None,后续设置 block_time, block_time_ms, program_received_time_us, @@ -339,6 +339,7 @@ impl EventMetadata { swap_data: None, instruction_outer_index, instruction_inner_index, + transaction_index, } } @@ -350,11 +351,6 @@ impl EventMetadata { self.swap_data = Some(swap_data); } - /// 设置交易索引 - pub fn set_transaction_index(&mut self, transaction_index: Option) { - self.transaction_index = transaction_index; - } - /// Recycle EventMetadata to object pool pub fn recycle(self) { EVENT_METADATA_POOL.release(self); diff --git a/src/streaming/event_parser/common/utils.rs b/src/streaming/event_parser/common/utils.rs index 80458d4..56ec1a5 100755 --- a/src/streaming/event_parser/common/utils.rs +++ b/src/streaming/event_parser/common/utils.rs @@ -13,15 +13,6 @@ pub fn extract_discriminator(length: usize, data: &[u8]) -> Option<(&[u8], &[u8] Some((&data[..length], &data[length..])) } -/// 检查鉴别器是否匹配 - 优化版本 -pub fn discriminator_matches(data: &str, expected: &str) -> bool { - if data.len() < expected.len() { - return false; - } - // 使用字节比较而不是字符串比较,更高效 - data.as_bytes().starts_with(expected.as_bytes()) -} - /// 从日志中提取程序数据 pub fn extract_program_data(log: &str) -> Option<&str> { const PROGRAM_DATA_PREFIX: &str = "Program data: "; diff --git a/src/streaming/event_parser/core/macros.rs b/src/streaming/event_parser/core/macros.rs new file mode 100644 index 0000000..9ef239e --- /dev/null +++ b/src/streaming/event_parser/core/macros.rs @@ -0,0 +1,97 @@ +/// Macro to generate boilerplate EventParser implementation for protocol parsers +/// +/// This macro eliminates the repetitive code where each parser simply delegates +/// all EventParser trait methods to its inner GenericEventParser. +/// +/// Usage: +/// ```rust +/// impl_event_parser_delegate!(MyEventParser); +/// ``` +/// +/// This will generate the complete EventParser implementation that delegates +/// all methods to `self.inner`. +#[macro_export] +macro_rules! impl_event_parser_delegate { + ($parser_type:ty) => { + #[async_trait::async_trait] + impl $crate::streaming::event_parser::core::traits::EventParser for $parser_type { + fn inner_instruction_configs( + &self, + ) -> std::collections::HashMap< + Vec, + Vec<$crate::streaming::event_parser::core::traits::GenericEventParseConfig>, + > { + self.inner.inner_instruction_configs() + } + + fn instruction_configs( + &self, + ) -> std::collections::HashMap< + Vec, + Vec<$crate::streaming::event_parser::core::traits::GenericEventParseConfig>, + > { + self.inner.instruction_configs() + } + + fn parse_events_from_inner_instruction( + &self, + inner_instruction: &solana_sdk::instruction::CompiledInstruction, + signature: solana_sdk::signature::Signature, + slot: u64, + block_time: Option, + program_received_time_us: i64, + outer_index: i64, + inner_index: Option, + bot_wallet: Option, + transaction_index: Option, + ) -> Vec> { + self.inner.parse_events_from_inner_instruction( + inner_instruction, + signature, + slot, + block_time, + program_received_time_us, + outer_index, + inner_index, + bot_wallet, + transaction_index, + ) + } + + fn parse_events_from_instruction( + &self, + instruction: &solana_sdk::instruction::CompiledInstruction, + accounts: &[solana_sdk::pubkey::Pubkey], + signature: solana_sdk::signature::Signature, + slot: u64, + block_time: Option, + program_received_time_us: i64, + outer_index: i64, + inner_index: Option, + bot_wallet: Option, + transaction_index: Option, + ) -> Vec> { + self.inner.parse_events_from_instruction( + instruction, + accounts, + signature, + slot, + block_time, + program_received_time_us, + outer_index, + inner_index, + bot_wallet, + transaction_index, + ) + } + + fn should_handle(&self, program_id: &solana_sdk::pubkey::Pubkey) -> bool { + self.inner.should_handle(program_id) + } + + fn supported_program_ids(&self) -> Vec { + self.inner.supported_program_ids() + } + } + }; +} diff --git a/src/streaming/event_parser/core/mod.rs b/src/streaming/event_parser/core/mod.rs index 27d61db..cbe0602 100755 --- a/src/streaming/event_parser/core/mod.rs +++ b/src/streaming/event_parser/core/mod.rs @@ -1,4 +1,5 @@ pub mod common_event_parser; pub mod traits; pub mod account_event_parser; +pub mod macros; pub use traits::{EventParser, UnifiedEvent}; diff --git a/src/streaming/event_parser/core/traits.rs b/src/streaming/event_parser/core/traits.rs index f9c7f4c..b37da1a 100755 --- a/src/streaming/event_parser/core/traits.rs +++ b/src/streaming/event_parser/core/traits.rs @@ -68,16 +68,13 @@ pub trait UnifiedEvent: Debug + Send + Sync { /// Get transaction index in slot fn transaction_index(&self) -> Option; - - /// Set transaction index in slot - fn set_transaction_index(&mut self, transaction_index: Option); } /// 事件解析器trait - 定义了事件解析的核心方法 #[async_trait::async_trait] pub trait EventParser: Send + Sync { /// 获取内联指令解析配置 - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec>; + fn inner_instruction_configs(&self) -> HashMap, Vec>; /// 获取指令解析配置 fn instruction_configs(&self) -> HashMap, Vec>; /// 从内联指令中解析事件数据 @@ -91,6 +88,8 @@ pub trait EventParser: Send + Sync { program_received_time_us: i64, outer_index: i64, inner_index: Option, + bot_wallet: Option, + transaction_index: Option, ) -> Vec>; /// 从指令中解析事件数据 @@ -105,6 +104,8 @@ pub trait EventParser: Send + Sync { program_received_time_us: i64, outer_index: i64, inner_index: Option, + bot_wallet: Option, + transaction_index: Option, ) -> Vec>; /// 从VersionedTransaction中解析指令事件的通用方法 @@ -118,6 +119,8 @@ pub trait EventParser: Send + Sync { program_received_time_us: i64, accounts: &[Pubkey], inner_instructions: &[InnerInstructions], + bot_wallet: Option, + transaction_index: Option, ) -> Result>> { // 预分配容量,避免动态扩容 let mut instruction_events = Vec::with_capacity(16); @@ -149,6 +152,8 @@ pub trait EventParser: Send + Sync { program_received_time_us, index as i64, None, + bot_wallet, + Some(index as u64), ) .await { @@ -188,6 +193,7 @@ pub trait EventParser: Send + Sync { block_time: Option, program_received_time_us: i64, bot_wallet: Option, + transaction_index: Option, ) -> Result>> { let accounts: Vec = versioned_tx.message.static_account_keys().to_vec(); let events = self @@ -199,6 +205,8 @@ pub trait EventParser: Send + Sync { program_received_time_us, &accounts, &[], + bot_wallet, + transaction_index, ) .await .unwrap_or_else(|_e| vec![]); @@ -213,6 +221,7 @@ pub trait EventParser: Send + Sync { block_time: Option, program_received_time_us: i64, bot_wallet: Option, + transaction_index: Option, ) -> Result>> { let versioned_tx = tx.get_transaction(); let meta = tx.get_status_meta(); @@ -254,6 +263,8 @@ pub trait EventParser: Send + Sync { program_received_time_us, &accounts_for_task1, &inner_instructions_for_task1, + bot_wallet, + transaction_index, ) .await .unwrap_or_else(|_e| vec![]) @@ -305,6 +316,8 @@ pub trait EventParser: Send + Sync { *program_received_time_us, *outer_index, *inner_index, + bot_wallet, + transaction_index, ) .await { @@ -348,6 +361,8 @@ pub trait EventParser: Send + Sync { *program_received_time_us, *outer_index, *inner_index, + bot_wallet, + transaction_index, ) .await { @@ -496,6 +511,8 @@ pub trait EventParser: Send + Sync { program_received_time_us: i64, outer_index: i64, inner_index: Option, + bot_wallet: Option, + transaction_index: Option, ) -> Result>> { let slot = slot.unwrap_or(0); let events = self.parse_events_from_inner_instruction( @@ -506,6 +523,8 @@ pub trait EventParser: Send + Sync { program_received_time_us, outer_index, inner_index, + bot_wallet, + transaction_index, ); Ok(events) } @@ -521,6 +540,8 @@ pub trait EventParser: Send + Sync { program_received_time_us: i64, outer_index: i64, inner_index: Option, + bot_wallet: Option, + transaction_index: Option, ) -> Result>> { let slot = slot.unwrap_or(0); let events = self.parse_events_from_instruction( @@ -532,6 +553,8 @@ pub trait EventParser: Send + Sync { program_received_time_us, outer_index, inner_index, + bot_wallet, + transaction_index, ); Ok(events) } @@ -555,7 +578,7 @@ impl Clone for Box { pub struct GenericEventParseConfig { pub program_id: Pubkey, pub protocol_type: ProtocolType, - pub inner_instruction_discriminator: &'static str, + pub inner_instruction_discriminator: &'static [u8], pub instruction_discriminator: &'static [u8], pub event_type: EventType, pub inner_instruction_parser: Option, @@ -573,7 +596,7 @@ pub type InstructionEventParser = /// 通用事件解析器基类 pub struct GenericEventParser { pub program_ids: Vec, - pub inner_instruction_configs: HashMap<&'static str, Vec>, + pub inner_instruction_configs: HashMap, Vec>, pub instruction_configs: HashMap, Vec>, } @@ -585,10 +608,12 @@ impl GenericEventParser { let mut instruction_configs = HashMap::with_capacity(configs.len()); for config in configs { - inner_instruction_configs - .entry(config.inner_instruction_discriminator) - .or_insert_with(Vec::new) - .push(config.clone()); + if config.inner_instruction_discriminator.len() > 0 { + inner_instruction_configs + .entry(config.inner_instruction_discriminator.to_vec()) + .or_insert_with(Vec::new) + .push(config.clone()); + } instruction_configs .entry(config.instruction_discriminator.to_vec()) .or_insert_with(Vec::new) @@ -610,6 +635,7 @@ impl GenericEventParser { program_received_time_us: i64, outer_index: i64, inner_index: Option, + transaction_index: Option, ) -> Option> { if let Some(parser) = config.inner_instruction_parser { let timestamp = block_time.unwrap_or(Timestamp { seconds: 0, nanos: 0 }); @@ -626,6 +652,7 @@ impl GenericEventParser { outer_index, inner_index, program_received_time_us, + transaction_index, ); parser(data, metadata) } else { @@ -646,6 +673,7 @@ impl GenericEventParser { program_received_time_us: i64, outer_index: i64, inner_index: Option, + transaction_index: Option, ) -> Option> { if let Some(parser) = config.instruction_parser { let timestamp = block_time.unwrap_or(Timestamp { seconds: 0, nanos: 0 }); @@ -662,6 +690,7 @@ impl GenericEventParser { outer_index, inner_index, program_received_time_us, + transaction_index, ); parser(data, account_pubkeys, metadata) } else { @@ -672,7 +701,7 @@ impl GenericEventParser { #[async_trait::async_trait] impl EventParser for GenericEventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { + fn inner_instruction_configs(&self) -> HashMap, Vec> { // 返回引用而非克隆,减少内存分配 self.inner_instruction_configs.clone() } @@ -691,17 +720,16 @@ impl EventParser for GenericEventParser { program_received_time_us: i64, outer_index: i64, inner_index: Option, + bot_wallet: Option, + transaction_index: Option, ) -> Vec> { - let inner_instruction_data_decoded = inner_instruction.data.clone(); - if inner_instruction_data_decoded.len() < 16 { + if inner_instruction.data.len() < 16 { return Vec::new(); } - let inner_instruction_data_decoded_str = - format!("0x{}", hex::encode(&inner_instruction_data_decoded)); - let data = &inner_instruction_data_decoded[16..]; + let data = &inner_instruction.data[16..]; let mut events = Vec::new(); for (disc, configs) in &self.inner_instruction_configs { - if discriminator_matches(&inner_instruction_data_decoded_str, disc) { + if data == disc { for config in configs { if let Some(event) = self.parse_inner_instruction_event( config, @@ -712,6 +740,7 @@ impl EventParser for GenericEventParser { program_received_time_us, outer_index, inner_index, + transaction_index, ) { events.push(event); } @@ -733,6 +762,8 @@ impl EventParser for GenericEventParser { program_received_time_us: i64, outer_index: i64, inner_index: Option, + bot_wallet: Option, + transaction_index: Option, ) -> Vec> { let program_id = accounts[instruction.program_id_index as usize]; if !self.should_handle(&program_id) { @@ -767,6 +798,7 @@ impl EventParser for GenericEventParser { program_received_time_us, outer_index, inner_index, + transaction_index, ) { events.push(event); } diff --git a/src/streaming/event_parser/protocols/block/block_meta_event.rs b/src/streaming/event_parser/protocols/block/block_meta_event.rs index 2f99ba1..d204eef 100644 --- a/src/streaming/event_parser/protocols/block/block_meta_event.rs +++ b/src/streaming/event_parser/protocols/block/block_meta_event.rs @@ -31,6 +31,7 @@ impl BlockMetaEvent { 0, None, program_received_time_us, + None, ); Self { metadata, slot, block_hash } } diff --git a/src/streaming/event_parser/protocols/bonk/events.rs b/src/streaming/event_parser/protocols/bonk/events.rs index e2a2d50..cb450ae 100755 --- a/src/streaming/event_parser/protocols/bonk/events.rs +++ b/src/streaming/event_parser/protocols/bonk/events.rs @@ -314,8 +314,12 @@ impl_unified_event!(BonkPlatformConfigAccountEvent,); /// Event discriminator constants pub mod discriminators { // Event discriminators - pub const TRADE_EVENT: &str = "0xe445a52e51cb9a1dbddb7fd34ee661ee"; - pub const POOL_CREATE_EVENT: &str = "0xe445a52e51cb9a1d97d7e20976a173ae"; + // pub const TRADE_EVENT: &str = "0xe445a52e51cb9a1dbddb7fd34ee661ee"; + pub const TRADE_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 189, 219, 127, 211, 78, 230, 97, 238]; + // pub const POOL_CREATE_EVENT: &str = "0xe445a52e51cb9a1d97d7e20976a173ae"; + pub const POOL_CREATE_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 151, 215, 226, 9, 118, 161, 115, 174]; // Instruction discriminators pub const BUY_EXACT_IN: &[u8] = &[250, 234, 13, 123, 213, 156, 19, 236]; diff --git a/src/streaming/event_parser/protocols/bonk/parser.rs b/src/streaming/event_parser/protocols/bonk/parser.rs index bc28e85..0c08216 100755 --- a/src/streaming/event_parser/protocols/bonk/parser.rs +++ b/src/streaming/event_parser/protocols/bonk/parser.rs @@ -1,16 +1,16 @@ -use std::collections::HashMap; +use solana_sdk::pubkey::Pubkey; -use prost_types::Timestamp; -use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature}; - -use crate::streaming::event_parser::{ - common::{utils::*, EventMetadata, EventType, ProtocolType}, - core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent}, - protocols::bonk::{ - bonk_pool_create_event_log_decode, bonk_trade_event_log_decode, discriminators, AmmFeeOn, - BonkMigrateToAmmEvent, BonkMigrateToCpswapEvent, BonkPoolCreateEvent, BonkTradeEvent, - ConstantCurve, CurveParams, FixedCurve, LinearCurve, MintParams, TradeDirection, - VestingParams, +use crate::{ + impl_event_parser_delegate, + streaming::event_parser::{ + common::{utils::*, EventMetadata, EventType, ProtocolType}, + core::traits::{GenericEventParseConfig, GenericEventParser, UnifiedEvent}, + protocols::bonk::{ + bonk_pool_create_event_log_decode, bonk_trade_event_log_decode, discriminators, + AmmFeeOn, BonkMigrateToAmmEvent, BonkMigrateToCpswapEvent, BonkPoolCreateEvent, + BonkTradeEvent, ConstantCurve, CurveParams, FixedCurve, LinearCurve, MintParams, + TradeDirection, VestingParams, + }, }, }; @@ -90,7 +90,7 @@ impl BonkEventParser { GenericEventParseConfig { program_id: BONK_PROGRAM_ID, protocol_type: ProtocolType::Bonk, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::MIGRATE_TO_AMM, event_type: EventType::BonkMigrateToAmm, inner_instruction_parser: None, @@ -99,7 +99,7 @@ impl BonkEventParser { GenericEventParseConfig { program_id: BONK_PROGRAM_ID, protocol_type: ProtocolType::Bonk, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::MIGRATE_TO_CP_SWAP, event_type: EventType::BonkMigrateToCpswap, inner_instruction_parser: None, @@ -603,63 +603,4 @@ impl BonkEventParser { } } -#[async_trait::async_trait] -impl EventParser for BonkEventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { - self.inner.inner_instruction_configs() - } - fn instruction_configs(&self) -> HashMap, Vec> { - self.inner.instruction_configs() - } - fn parse_events_from_inner_instruction( - &self, - inner_instruction: &CompiledInstruction, - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_inner_instruction( - inner_instruction, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn parse_events_from_instruction( - &self, - instruction: &CompiledInstruction, - accounts: &[Pubkey], - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_instruction( - instruction, - accounts, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn should_handle(&self, program_id: &Pubkey) -> bool { - self.inner.should_handle(program_id) - } - - fn supported_program_ids(&self) -> Vec { - self.inner.supported_program_ids() - } -} +impl_event_parser_delegate!(BonkEventParser); diff --git a/src/streaming/event_parser/protocols/mutil/parser.rs b/src/streaming/event_parser/protocols/mutil/parser.rs index b04da73..c8b58a0 100755 --- a/src/streaming/event_parser/protocols/mutil/parser.rs +++ b/src/streaming/event_parser/protocols/mutil/parser.rs @@ -1,13 +1,10 @@ -use std::collections::HashMap; - -use prost_types::Timestamp; -use solana_sdk::signature::Signature; -use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey}; - -use crate::streaming::event_parser::common::filter::EventTypeFilter; -use crate::streaming::event_parser::{ - core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent}, - EventParserFactory, Protocol, +use crate::{ + impl_event_parser_delegate, + streaming::event_parser::{ + common::filter::EventTypeFilter, + core::traits::{GenericEventParseConfig, GenericEventParser}, + EventParserFactory, Protocol, + }, }; pub struct MutilEventParser { @@ -64,63 +61,4 @@ impl MutilEventParser { } } -#[async_trait::async_trait] -impl EventParser for MutilEventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { - self.inner.inner_instruction_configs() - } - fn instruction_configs(&self) -> HashMap, Vec> { - self.inner.instruction_configs() - } - fn parse_events_from_inner_instruction( - &self, - inner_instruction: &CompiledInstruction, - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_inner_instruction( - inner_instruction, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn parse_events_from_instruction( - &self, - instruction: &CompiledInstruction, - accounts: &[Pubkey], - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_instruction( - instruction, - accounts, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn should_handle(&self, program_id: &Pubkey) -> bool { - self.inner.should_handle(program_id) - } - - fn supported_program_ids(&self) -> Vec { - self.inner.supported_program_ids() - } -} +impl_event_parser_delegate!(MutilEventParser); diff --git a/src/streaming/event_parser/protocols/pumpfun/events.rs b/src/streaming/event_parser/protocols/pumpfun/events.rs index 89b02d7..5e06a84 100755 --- a/src/streaming/event_parser/protocols/pumpfun/events.rs +++ b/src/streaming/event_parser/protocols/pumpfun/events.rs @@ -255,9 +255,15 @@ impl_unified_event!(PumpFunGlobalAccountEvent,); /// 事件鉴别器常量 pub mod discriminators { // 事件鉴别器 - pub const CREATE_TOKEN_EVENT: &str = "0xe445a52e51cb9a1d1b72a94ddeeb6376"; - pub const TRADE_EVENT: &str = "0xe445a52e51cb9a1dbddb7fd34ee661ee"; - pub const COMPLETE_PUMP_AMM_MIGRATION_EVENT: &str = "0xe445a52e51cb9a1dbde95db95c94ea94"; + // pub const CREATE_TOKEN_EVENT: &str = "0xe445a52e51cb9a1d1b72a94ddeeb6376"; + pub const CREATE_TOKEN_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 27, 114, 169, 77, 222, 235, 99, 118]; + // pub const TRADE_EVENT: &str = "0xe445a52e51cb9a1dbddb7fd34ee661ee"; + pub const TRADE_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 189, 219, 127, 211, 78, 230, 97, 238]; + // pub const COMPLETE_PUMP_AMM_MIGRATION_EVENT: &str = "0xe445a52e51cb9a1dbde95db95c94ea94"; + pub const COMPLETE_PUMP_AMM_MIGRATION_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 189, 233, 93, 185, 92, 148, 234, 148]; // 指令鉴别器 pub const CREATE_TOKEN_IX: &[u8] = &[24, 30, 200, 40, 5, 28, 7, 119]; diff --git a/src/streaming/event_parser/protocols/pumpfun/parser.rs b/src/streaming/event_parser/protocols/pumpfun/parser.rs index 2e97979..5596f38 100755 --- a/src/streaming/event_parser/protocols/pumpfun/parser.rs +++ b/src/streaming/event_parser/protocols/pumpfun/parser.rs @@ -1,15 +1,15 @@ -use std::collections::HashMap; +use solana_sdk::pubkey::Pubkey; -use prost_types::Timestamp; -use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature}; - -use crate::streaming::event_parser::{ - common::{EventMetadata, EventType, ProtocolType}, - core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent}, - protocols::pumpfun::{ - discriminators, pumpfun_create_token_event_log_decode, pumpfun_migrate_event_log_decode, - pumpfun_trade_event_log_decode, PumpFunCreateTokenEvent, PumpFunMigrateEvent, - PumpFunTradeEvent, +use crate::{ + impl_event_parser_delegate, + streaming::event_parser::{ + common::{EventMetadata, EventType, ProtocolType}, + core::traits::{GenericEventParseConfig, GenericEventParser, UnifiedEvent}, + protocols::pumpfun::{ + discriminators, pumpfun_create_token_event_log_decode, + pumpfun_migrate_event_log_decode, pumpfun_trade_event_log_decode, + PumpFunCreateTokenEvent, PumpFunMigrateEvent, PumpFunTradeEvent, + }, }, }; @@ -284,63 +284,4 @@ impl PumpFunEventParser { } } -#[async_trait::async_trait] -impl EventParser for PumpFunEventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { - self.inner.inner_instruction_configs() - } - fn instruction_configs(&self) -> HashMap, Vec> { - self.inner.instruction_configs() - } - fn parse_events_from_inner_instruction( - &self, - inner_instruction: &CompiledInstruction, - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_inner_instruction( - inner_instruction, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn parse_events_from_instruction( - &self, - instruction: &CompiledInstruction, - accounts: &[Pubkey], - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_instruction( - instruction, - accounts, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn should_handle(&self, program_id: &Pubkey) -> bool { - self.inner.should_handle(program_id) - } - - fn supported_program_ids(&self) -> Vec { - self.inner.supported_program_ids() - } -} +impl_event_parser_delegate!(PumpFunEventParser); diff --git a/src/streaming/event_parser/protocols/pumpswap/events.rs b/src/streaming/event_parser/protocols/pumpswap/events.rs index 5b27449..63a85b7 100755 --- a/src/streaming/event_parser/protocols/pumpswap/events.rs +++ b/src/streaming/event_parser/protocols/pumpswap/events.rs @@ -392,11 +392,21 @@ impl_unified_event!(PumpSwapPoolAccountEvent,); /// 事件鉴别器常量 pub mod discriminators { // 事件鉴别器 - pub const BUY_EVENT: &str = "0xe445a52e51cb9a1d67f4521f2cf57777"; - pub const SELL_EVENT: &str = "0xe445a52e51cb9a1d3e2f370aa503dc2a"; - pub const CREATE_POOL_EVENT: &str = "0xe445a52e51cb9a1db1310cd2a076a774"; - pub const DEPOSIT_EVENT: &str = "0xe445a52e51cb9a1d78f83d531f8e6b90"; - pub const WITHDRAW_EVENT: &str = "0xe445a52e51cb9a1d1609851aa02c47c0"; + // pub const BUY_EVENT: &str = "0xe445a52e51cb9a1d67f4521f2cf57777"; + pub const BUY_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 103, 244, 82, 31, 44, 245, 119, 119]; + // pub const SELL_EVENT: &str = "0xe445a52e51cb9a1d3e2f370aa503dc2a"; + pub const SELL_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 62, 47, 55, 10, 165, 3, 220, 42]; + // pub const CREATE_POOL_EVENT: &str = "0xe445a52e51cb9a1db1310cd2a076a774"; + pub const CREATE_POOL_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 177, 49, 12, 210, 160, 118, 167, 116]; + // pub const DEPOSIT_EVENT: &str = "0xe445a52e51cb9a1d78f83d531f8e6b90"; + pub const DEPOSIT_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 120, 248, 61, 83, 31, 142, 107, 144]; + // pub const WITHDRAW_EVENT: &str = "0xe445a52e51cb9a1d1609851aa02c47c0"; + pub const WITHDRAW_EVENT: &[u8] = + &[228, 69, 165, 46, 81, 203, 154, 29, 22, 9, 133, 26, 160, 44, 71, 192]; // 指令鉴别器 pub const BUY_IX: &[u8] = &[102, 6, 61, 18, 1, 218, 235, 234]; diff --git a/src/streaming/event_parser/protocols/pumpswap/parser.rs b/src/streaming/event_parser/protocols/pumpswap/parser.rs index a688c41..dc22336 100755 --- a/src/streaming/event_parser/protocols/pumpswap/parser.rs +++ b/src/streaming/event_parser/protocols/pumpswap/parser.rs @@ -1,16 +1,16 @@ -use std::collections::HashMap; +use solana_sdk::pubkey::Pubkey; -use prost_types::Timestamp; -use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature}; - -use crate::streaming::event_parser::{ - common::{read_u64_le, EventMetadata, EventType, ProtocolType}, - core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent}, - protocols::pumpswap::{ - discriminators, pump_swap_buy_event_log_decode, pump_swap_create_pool_event_log_decode, - pump_swap_deposit_event_log_decode, pump_swap_sell_event_log_decode, - pump_swap_withdraw_event_log_decode, PumpSwapBuyEvent, PumpSwapCreatePoolEvent, - PumpSwapDepositEvent, PumpSwapSellEvent, PumpSwapWithdrawEvent, +use crate::{ + impl_event_parser_delegate, + streaming::event_parser::{ + common::{read_u64_le, EventMetadata, EventType, ProtocolType}, + core::traits::{GenericEventParseConfig, GenericEventParser, UnifiedEvent}, + protocols::pumpswap::{ + discriminators, pump_swap_buy_event_log_decode, pump_swap_create_pool_event_log_decode, + pump_swap_deposit_event_log_decode, pump_swap_sell_event_log_decode, + pump_swap_withdraw_event_log_decode, PumpSwapBuyEvent, PumpSwapCreatePoolEvent, + PumpSwapDepositEvent, PumpSwapSellEvent, PumpSwapWithdrawEvent, + }, }, }; @@ -374,63 +374,4 @@ impl PumpSwapEventParser { } } -#[async_trait::async_trait] -impl EventParser for PumpSwapEventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { - self.inner.inner_instruction_configs() - } - fn instruction_configs(&self) -> HashMap, Vec> { - self.inner.instruction_configs() - } - fn parse_events_from_inner_instruction( - &self, - inner_instruction: &CompiledInstruction, - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_inner_instruction( - inner_instruction, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn parse_events_from_instruction( - &self, - instruction: &CompiledInstruction, - accounts: &[Pubkey], - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_instruction( - instruction, - accounts, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn should_handle(&self, program_id: &Pubkey) -> bool { - self.inner.should_handle(program_id) - } - - fn supported_program_ids(&self) -> Vec { - self.inner.supported_program_ids() - } -} +impl_event_parser_delegate!(PumpSwapEventParser); diff --git a/src/streaming/event_parser/protocols/raydium_amm_v4/parser.rs b/src/streaming/event_parser/protocols/raydium_amm_v4/parser.rs index 288e523..6b8a7ba 100755 --- a/src/streaming/event_parser/protocols/raydium_amm_v4/parser.rs +++ b/src/streaming/event_parser/protocols/raydium_amm_v4/parser.rs @@ -1,14 +1,14 @@ -use std::collections::HashMap; +use solana_sdk::pubkey::Pubkey; -use prost_types::Timestamp; -use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature}; - -use crate::streaming::event_parser::{ - common::{read_u64_le, EventMetadata, EventType, ProtocolType}, - core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent}, - protocols::raydium_amm_v4::{ - discriminators, RaydiumAmmV4DepositEvent, RaydiumAmmV4Initialize2Event, - RaydiumAmmV4SwapEvent, RaydiumAmmV4WithdrawEvent, RaydiumAmmV4WithdrawPnlEvent, +use crate::{ + impl_event_parser_delegate, + streaming::event_parser::{ + common::{read_u64_le, EventMetadata, EventType, ProtocolType}, + core::traits::{GenericEventParseConfig, GenericEventParser, UnifiedEvent}, + protocols::raydium_amm_v4::{ + discriminators, RaydiumAmmV4DepositEvent, RaydiumAmmV4Initialize2Event, + RaydiumAmmV4SwapEvent, RaydiumAmmV4WithdrawEvent, RaydiumAmmV4WithdrawPnlEvent, + }, }, }; @@ -34,7 +34,7 @@ impl RaydiumAmmV4EventParser { GenericEventParseConfig { program_id: RAYDIUM_AMM_V4_PROGRAM_ID, protocol_type: ProtocolType::RaydiumAmmV4, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::SWAP_BASE_IN, event_type: EventType::RaydiumAmmV4SwapBaseIn, inner_instruction_parser: None, @@ -43,7 +43,7 @@ impl RaydiumAmmV4EventParser { GenericEventParseConfig { program_id: RAYDIUM_AMM_V4_PROGRAM_ID, protocol_type: ProtocolType::RaydiumAmmV4, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::SWAP_BASE_OUT, event_type: EventType::RaydiumAmmV4SwapBaseOut, inner_instruction_parser: None, @@ -52,7 +52,7 @@ impl RaydiumAmmV4EventParser { GenericEventParseConfig { program_id: RAYDIUM_AMM_V4_PROGRAM_ID, protocol_type: ProtocolType::RaydiumAmmV4, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::DEPOSIT, event_type: EventType::RaydiumAmmV4Deposit, inner_instruction_parser: None, @@ -61,7 +61,7 @@ impl RaydiumAmmV4EventParser { GenericEventParseConfig { program_id: RAYDIUM_AMM_V4_PROGRAM_ID, protocol_type: ProtocolType::RaydiumAmmV4, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::INITIALIZE2, event_type: EventType::RaydiumAmmV4Initialize2, inner_instruction_parser: None, @@ -70,7 +70,7 @@ impl RaydiumAmmV4EventParser { GenericEventParseConfig { program_id: RAYDIUM_AMM_V4_PROGRAM_ID, protocol_type: ProtocolType::RaydiumAmmV4, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::WITHDRAW, event_type: EventType::RaydiumAmmV4Withdraw, inner_instruction_parser: None, @@ -79,7 +79,7 @@ impl RaydiumAmmV4EventParser { GenericEventParseConfig { program_id: RAYDIUM_AMM_V4_PROGRAM_ID, protocol_type: ProtocolType::RaydiumAmmV4, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::WITHDRAW_PNL, event_type: EventType::RaydiumAmmV4WithdrawPnl, inner_instruction_parser: None, @@ -376,63 +376,4 @@ impl RaydiumAmmV4EventParser { } } -#[async_trait::async_trait] -impl EventParser for RaydiumAmmV4EventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { - self.inner.inner_instruction_configs() - } - fn instruction_configs(&self) -> HashMap, Vec> { - self.inner.instruction_configs() - } - fn parse_events_from_inner_instruction( - &self, - inner_instruction: &CompiledInstruction, - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_inner_instruction( - inner_instruction, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn parse_events_from_instruction( - &self, - instruction: &CompiledInstruction, - accounts: &[Pubkey], - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_instruction( - instruction, - accounts, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn should_handle(&self, program_id: &Pubkey) -> bool { - self.inner.should_handle(program_id) - } - - fn supported_program_ids(&self) -> Vec { - self.inner.supported_program_ids() - } -} +impl_event_parser_delegate!(RaydiumAmmV4EventParser); diff --git a/src/streaming/event_parser/protocols/raydium_clmm/parser.rs b/src/streaming/event_parser/protocols/raydium_clmm/parser.rs index 16fab61..7f56274 100755 --- a/src/streaming/event_parser/protocols/raydium_clmm/parser.rs +++ b/src/streaming/event_parser/protocols/raydium_clmm/parser.rs @@ -1,19 +1,19 @@ -use std::collections::HashMap; +use solana_sdk::pubkey::Pubkey; -use prost_types::Timestamp; -use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature}; - -use crate::streaming::event_parser::{ - common::{ - read_i32_le, read_option_bool, read_u128_le, read_u64_le, read_u8_le, EventMetadata, - EventType, ProtocolType, - }, - core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent}, - protocols::raydium_clmm::{ - discriminators, RaydiumClmmClosePositionEvent, RaydiumClmmCreatePoolEvent, - RaydiumClmmDecreaseLiquidityV2Event, RaydiumClmmIncreaseLiquidityV2Event, - RaydiumClmmOpenPositionV2Event, RaydiumClmmOpenPositionWithToken22NftEvent, - RaydiumClmmSwapEvent, RaydiumClmmSwapV2Event, +use crate::{ + impl_event_parser_delegate, + streaming::event_parser::{ + common::{ + read_i32_le, read_option_bool, read_u128_le, read_u64_le, read_u8_le, EventMetadata, + EventType, ProtocolType, + }, + core::traits::{GenericEventParseConfig, GenericEventParser, UnifiedEvent}, + protocols::raydium_clmm::{ + discriminators, RaydiumClmmClosePositionEvent, RaydiumClmmCreatePoolEvent, + RaydiumClmmDecreaseLiquidityV2Event, RaydiumClmmIncreaseLiquidityV2Event, + RaydiumClmmOpenPositionV2Event, RaydiumClmmOpenPositionWithToken22NftEvent, + RaydiumClmmSwapEvent, RaydiumClmmSwapV2Event, + }, }, }; @@ -39,7 +39,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::SWAP, event_type: EventType::RaydiumClmmSwap, inner_instruction_parser: None, @@ -48,7 +48,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::SWAP_V2, event_type: EventType::RaydiumClmmSwapV2, inner_instruction_parser: None, @@ -57,7 +57,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::CLOSE_POSITION, event_type: EventType::RaydiumClmmClosePosition, inner_instruction_parser: None, @@ -66,7 +66,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::DECREASE_LIQUIDITY_V2, event_type: EventType::RaydiumClmmDecreaseLiquidityV2, inner_instruction_parser: None, @@ -75,7 +75,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::CREATE_POOL, event_type: EventType::RaydiumClmmCreatePool, inner_instruction_parser: None, @@ -84,7 +84,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::INCREASE_LIQUIDITY_V2, event_type: EventType::RaydiumClmmIncreaseLiquidityV2, inner_instruction_parser: None, @@ -93,7 +93,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::OPEN_POSITION_WITH_TOKEN_22_NFT, event_type: EventType::RaydiumClmmOpenPositionWithToken22Nft, inner_instruction_parser: None, @@ -102,7 +102,7 @@ impl RaydiumClmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CLMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumClmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::OPEN_POSITION_V2, event_type: EventType::RaydiumClmmOpenPositionV2, inner_instruction_parser: None, @@ -417,63 +417,4 @@ impl RaydiumClmmEventParser { } } -#[async_trait::async_trait] -impl EventParser for RaydiumClmmEventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { - self.inner.inner_instruction_configs() - } - fn instruction_configs(&self) -> HashMap, Vec> { - self.inner.instruction_configs() - } - fn parse_events_from_inner_instruction( - &self, - inner_instruction: &CompiledInstruction, - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_inner_instruction( - inner_instruction, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn parse_events_from_instruction( - &self, - instruction: &CompiledInstruction, - accounts: &[Pubkey], - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_instruction( - instruction, - accounts, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn should_handle(&self, program_id: &Pubkey) -> bool { - self.inner.should_handle(program_id) - } - - fn supported_program_ids(&self) -> Vec { - self.inner.supported_program_ids() - } -} +impl_event_parser_delegate!(RaydiumClmmEventParser); diff --git a/src/streaming/event_parser/protocols/raydium_cpmm/parser.rs b/src/streaming/event_parser/protocols/raydium_cpmm/parser.rs index 288bf60..f7d2e2e 100755 --- a/src/streaming/event_parser/protocols/raydium_cpmm/parser.rs +++ b/src/streaming/event_parser/protocols/raydium_cpmm/parser.rs @@ -1,14 +1,14 @@ -use std::collections::HashMap; +use solana_sdk::pubkey::Pubkey; -use prost_types::Timestamp; -use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, signature::Signature}; - -use crate::streaming::event_parser::{ - common::{read_u64_le, EventMetadata, EventType, ProtocolType}, - core::traits::{EventParser, GenericEventParseConfig, GenericEventParser, UnifiedEvent}, - protocols::raydium_cpmm::{ - discriminators, RaydiumCpmmDepositEvent, RaydiumCpmmInitializeEvent, RaydiumCpmmSwapEvent, - RaydiumCpmmWithdrawEvent, +use crate::{ + impl_event_parser_delegate, + streaming::event_parser::{ + common::{read_u64_le, EventMetadata, EventType, ProtocolType}, + core::traits::{GenericEventParseConfig, GenericEventParser, UnifiedEvent}, + protocols::raydium_cpmm::{ + discriminators, RaydiumCpmmDepositEvent, RaydiumCpmmInitializeEvent, + RaydiumCpmmSwapEvent, RaydiumCpmmWithdrawEvent, + }, }, }; @@ -34,7 +34,7 @@ impl RaydiumCpmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CPMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumCpmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::SWAP_BASE_IN, event_type: EventType::RaydiumCpmmSwapBaseInput, inner_instruction_parser: None, @@ -43,7 +43,7 @@ impl RaydiumCpmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CPMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumCpmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::SWAP_BASE_OUT, event_type: EventType::RaydiumCpmmSwapBaseOutput, inner_instruction_parser: None, @@ -52,7 +52,7 @@ impl RaydiumCpmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CPMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumCpmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::DEPOSIT, event_type: EventType::RaydiumCpmmDeposit, inner_instruction_parser: None, @@ -61,7 +61,7 @@ impl RaydiumCpmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CPMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumCpmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::INITIALIZE, event_type: EventType::RaydiumCpmmInitialize, inner_instruction_parser: None, @@ -70,7 +70,7 @@ impl RaydiumCpmmEventParser { GenericEventParseConfig { program_id: RAYDIUM_CPMM_PROGRAM_ID, protocol_type: ProtocolType::RaydiumCpmm, - inner_instruction_discriminator: "", + inner_instruction_discriminator: &[], instruction_discriminator: discriminators::WITHDRAW, event_type: EventType::RaydiumCpmmWithdraw, inner_instruction_parser: None, @@ -267,63 +267,4 @@ impl RaydiumCpmmEventParser { } } -#[async_trait::async_trait] -impl EventParser for RaydiumCpmmEventParser { - fn inner_instruction_configs(&self) -> HashMap<&'static str, Vec> { - self.inner.inner_instruction_configs() - } - fn instruction_configs(&self) -> HashMap, Vec> { - self.inner.instruction_configs() - } - fn parse_events_from_inner_instruction( - &self, - inner_instruction: &CompiledInstruction, - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_inner_instruction( - inner_instruction, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn parse_events_from_instruction( - &self, - instruction: &CompiledInstruction, - accounts: &[Pubkey], - signature: Signature, - slot: u64, - block_time: Option, - program_received_time_us: i64, - outer_index: i64, - inner_index: Option, - ) -> Vec> { - self.inner.parse_events_from_instruction( - instruction, - accounts, - signature, - slot, - block_time, - program_received_time_us, - outer_index, - inner_index, - ) - } - - fn should_handle(&self, program_id: &Pubkey) -> bool { - self.inner.should_handle(program_id) - } - - fn supported_program_ids(&self) -> Vec { - self.inner.supported_program_ids() - } -} +impl_event_parser_delegate!(RaydiumCpmmEventParser);