feat: Add account event parser and protocol type definitions

- Add account event parser (account_event_parser.rs) for account-level event handling
- Introduce type definitions for pumpfun, pumpswap, raydium_amm_v4, raydium_clmm, raydium_cpmm protocols
- Enhance event processor to support account event processing alongside transactions
- Improve subscription system with separate transaction and account filters
- Optimize parser configuration using Option types for cleaner code structure
- Update examples and documentation to reflect new capabilities

Changes include:
- 6 new types.rs files for protocol-specific data structures
- Updated event processor for account, transaction, and block meta events
- Refactored subscription manager with account filtering support
- Enhanced metrics and batch processing logic
This commit is contained in:
ysq
2025-08-13 23:30:59 +08:00
parent c753c8418d
commit aee8921ad5
40 changed files with 1845 additions and 349 deletions
@@ -2,8 +2,9 @@ use borsh::BorshDeserialize;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use crate::streaming::event_parser::common::EventMetadata;
use crate::impl_unified_event;
use crate::streaming::event_parser::common::EventMetadata;
use crate::streaming::event_parser::protocols::pumpswap::types::{GlobalConfig, Pool};
/// 买入事件
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
@@ -309,6 +310,32 @@ impl_unified_event!(
user_pool_token_account
);
/// 全局配置
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
pub struct PumpSwapGlobalConfigAccountEvent {
pub metadata: EventMetadata,
pub pubkey: String,
pub executable: bool,
pub lamports: u64,
pub owner: String,
pub rent_epoch: u64,
pub global_config: GlobalConfig,
}
impl_unified_event!(PumpSwapGlobalConfigAccountEvent,);
/// 池
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
pub struct PumpSwapPoolAccountEvent {
pub metadata: EventMetadata,
pub pubkey: String,
pub executable: bool,
pub lamports: u64,
pub owner: String,
pub rent_epoch: u64,
pub pool: Pool,
}
impl_unified_event!(PumpSwapPoolAccountEvent,);
/// 事件鉴别器常量
pub mod discriminators {
// 事件鉴别器
@@ -324,4 +351,8 @@ pub mod discriminators {
pub const CREATE_POOL_IX: &[u8] = &[233, 146, 209, 142, 207, 104, 64, 188];
pub const DEPOSIT_IX: &[u8] = &[242, 35, 198, 137, 82, 225, 242, 182];
pub const WITHDRAW_IX: &[u8] = &[183, 18, 70, 156, 148, 109, 161, 34];
// 账户鉴别器
pub const GLOBAL_CONFIG_ACCOUNT: &[u8] = &[149, 8, 156, 202, 160, 252, 176, 217];
pub const POOL_ACCOUNT: &[u8] = &[241, 154, 109, 4, 17, 177, 109, 188];
}
@@ -1,5 +1,6 @@
pub mod events;
pub mod parser;
pub mod types;
pub use events::*;
pub use parser::PumpSwapEventParser;
pub use parser::PumpSwapEventParser;
@@ -38,8 +38,8 @@ impl PumpSwapEventParser {
inner_instruction_discriminator: discriminators::BUY_EVENT,
instruction_discriminator: discriminators::BUY_IX,
event_type: EventType::PumpSwapBuy,
inner_instruction_parser: Self::parse_buy_inner_instruction,
instruction_parser: Self::parse_buy_instruction,
inner_instruction_parser: Some(Self::parse_buy_inner_instruction),
instruction_parser: Some(Self::parse_buy_instruction),
},
GenericEventParseConfig {
program_id: PUMPSWAP_PROGRAM_ID,
@@ -47,8 +47,8 @@ impl PumpSwapEventParser {
inner_instruction_discriminator: discriminators::SELL_EVENT,
instruction_discriminator: discriminators::SELL_IX,
event_type: EventType::PumpSwapSell,
inner_instruction_parser: Self::parse_sell_inner_instruction,
instruction_parser: Self::parse_sell_instruction,
inner_instruction_parser: Some(Self::parse_sell_inner_instruction),
instruction_parser: Some(Self::parse_sell_instruction),
},
GenericEventParseConfig {
program_id: PUMPSWAP_PROGRAM_ID,
@@ -56,8 +56,8 @@ impl PumpSwapEventParser {
inner_instruction_discriminator: discriminators::CREATE_POOL_EVENT,
instruction_discriminator: discriminators::CREATE_POOL_IX,
event_type: EventType::PumpSwapCreatePool,
inner_instruction_parser: Self::parse_create_pool_inner_instruction,
instruction_parser: Self::parse_create_pool_instruction,
inner_instruction_parser: Some(Self::parse_create_pool_inner_instruction),
instruction_parser: Some(Self::parse_create_pool_instruction),
},
GenericEventParseConfig {
program_id: PUMPSWAP_PROGRAM_ID,
@@ -65,8 +65,8 @@ impl PumpSwapEventParser {
inner_instruction_discriminator: discriminators::DEPOSIT_EVENT,
instruction_discriminator: discriminators::DEPOSIT_IX,
event_type: EventType::PumpSwapDeposit,
inner_instruction_parser: Self::parse_deposit_inner_instruction,
instruction_parser: Self::parse_deposit_instruction,
inner_instruction_parser: Some(Self::parse_deposit_inner_instruction),
instruction_parser: Some(Self::parse_deposit_instruction),
},
GenericEventParseConfig {
program_id: PUMPSWAP_PROGRAM_ID,
@@ -74,8 +74,8 @@ impl PumpSwapEventParser {
inner_instruction_discriminator: discriminators::WITHDRAW_EVENT,
instruction_discriminator: discriminators::WITHDRAW_IX,
event_type: EventType::PumpSwapWithdraw,
inner_instruction_parser: Self::parse_withdraw_inner_instruction,
instruction_parser: Self::parse_withdraw_instruction,
inner_instruction_parser: Some(Self::parse_withdraw_inner_instruction),
instruction_parser: Some(Self::parse_withdraw_instruction),
},
];
@@ -0,0 +1,95 @@
use borsh::BorshDeserialize;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use crate::streaming::{
event_parser::{
common::EventMetadata,
protocols::pumpswap::{
parser::PUMPSWAP_PROGRAM_ID, PumpSwapGlobalConfigAccountEvent, PumpSwapPoolAccountEvent,
},
UnifiedEvent,
},
grpc::AccountPretty,
};
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
pub struct GlobalConfig {
pub admin: Pubkey,
pub lp_fee_basis_points: u64,
pub protocol_fee_basis_points: u64,
pub disable_flags: u8,
pub protocol_fee_recipients: [Pubkey; 8],
pub coin_creator_fee_basis_points: u64,
pub admin_set_coin_creator_authority: Pubkey,
}
pub const GLOBAL_CONFIG_SIZE: usize = 32 + 8 + 8 + 1 + 32 * 8 + 8 + 32;
pub fn global_config_decode(data: &[u8]) -> Option<GlobalConfig> {
if data.len() < GLOBAL_CONFIG_SIZE {
return None;
}
borsh::from_slice::<GlobalConfig>(&data).ok()
}
pub fn global_config_parser(
account: &AccountPretty,
metadata: EventMetadata,
) -> Option<Box<dyn UnifiedEvent>> {
if let Some(config) = global_config_decode(&account.data[8..GLOBAL_CONFIG_SIZE + 8]) {
Some(Box::new(PumpSwapGlobalConfigAccountEvent {
metadata,
pubkey: account.pubkey.to_string(),
executable: account.executable,
lamports: account.lamports,
owner: account.owner.to_string(),
rent_epoch: account.rent_epoch,
global_config: config,
}))
} else {
None
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
pub struct Pool {
pub pool_bump: u8,
pub index: u16,
pub creator: Pubkey,
pub base_mint: Pubkey,
pub quote_mint: Pubkey,
pub lp_mint: Pubkey,
pub pool_base_token_account: Pubkey,
pub pool_quote_token_account: Pubkey,
pub lp_supply: u64,
pub coin_creator: Pubkey,
}
pub const POOL_SIZE: usize = 1 + 2 + 32 * 6 + 8 + 32;
pub fn pool_decode(data: &[u8]) -> Option<Pool> {
if data.len() < POOL_SIZE {
return None;
}
borsh::from_slice::<Pool>(&data).ok()
}
pub fn pool_parser(
account: &AccountPretty,
metadata: EventMetadata,
) -> Option<Box<dyn UnifiedEvent>> {
if let Some(pool) = pool_decode(&account.data[8..POOL_SIZE + 8]) {
Some(Box::new(PumpSwapPoolAccountEvent {
metadata,
pubkey: account.pubkey.to_string(),
executable: account.executable,
lamports: account.lamports,
owner: account.owner.to_string(),
rent_epoch: account.rent_epoch,
pool: pool,
}))
} else {
None
}
}