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:
ysq
2025-10-10 18:19:44 +08:00
parent 77caa39f0c
commit 312a675a40
43 changed files with 1013 additions and 1839 deletions
@@ -1,4 +1,3 @@
use crate::impl_unified_event;
use crate::streaming::event_parser::common::EventMetadata;
use crate::streaming::event_parser::protocols::bonk::types::{
CurveParams, MintParams, PoolStatus, TradeDirection, VestingParams,
@@ -82,26 +81,26 @@ pub fn bonk_trade_event_log_decode(data: &[u8]) -> Option<BonkTradeEvent> {
}
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
impl_unified_event!(
BonkTradeEvent,
pool_state,
total_base_sell,
virtual_base,
virtual_quote,
real_base_before,
real_quote_before,
real_base_after,
real_quote_after,
amount_in,
amount_out,
protocol_fee,
platform_fee,
creator_fee,
share_fee,
trade_direction,
pool_status,
exact_in
);
// impl_unified_event!(
// BonkTradeEvent,
// pool_state,
// total_base_sell,
// virtual_base,
// virtual_quote,
// real_base_before,
// real_quote_before,
// real_base_after,
// real_quote_after,
// amount_in,
// amount_out,
// protocol_fee,
// platform_fee,
// creator_fee,
// share_fee,
// trade_direction,
// pool_status,
// exact_in
// );
/// Create pool event
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
@@ -141,16 +140,16 @@ pub fn bonk_pool_create_event_log_decode(data: &[u8]) -> Option<BonkPoolCreateEv
}
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
impl_unified_event!(
BonkPoolCreateEvent,
pool_state,
creator,
config,
base_mint_param,
curve_param,
vesting_param,
amm_fee_on
);
// impl_unified_event!(
// BonkPoolCreateEvent,
// pool_state,
// creator,
// config,
// base_mint_param,
// curve_param,
// vesting_param,
// amm_fee_on
// );
/// Create pool event
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
@@ -227,12 +226,12 @@ pub struct BonkMigrateToAmmEvent {
}
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
impl_unified_event!(
BonkMigrateToAmmEvent,
base_lot_size,
quote_lot_size,
market_vault_signer_nonce
);
// impl_unified_event!(
// BonkMigrateToAmmEvent,
// base_lot_size,
// quote_lot_size,
// market_vault_signer_nonce
// );
// Migrate to CP Swap event
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
@@ -270,9 +269,6 @@ pub struct BonkMigrateToCpswapEvent {
pub remaining_accounts: Vec<Pubkey>,
}
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
impl_unified_event!(BonkMigrateToCpswapEvent,);
/// 池状态
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct BonkPoolStateAccountEvent {
@@ -284,7 +280,6 @@ pub struct BonkPoolStateAccountEvent {
pub rent_epoch: u64,
pub pool_state: PoolState,
}
impl_unified_event!(BonkPoolStateAccountEvent,);
/// 全局配置
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
@@ -297,7 +292,6 @@ pub struct BonkGlobalConfigAccountEvent {
pub rent_epoch: u64,
pub global_config: GlobalConfig,
}
impl_unified_event!(BonkGlobalConfigAccountEvent,);
/// 平台配置
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
@@ -310,7 +304,6 @@ pub struct BonkPlatformConfigAccountEvent {
pub rent_epoch: u64,
pub platform_config: PlatformConfig,
}
impl_unified_event!(BonkPlatformConfigAccountEvent,);
/// Event discriminator constants
pub mod discriminators {