mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-23 22:08:05 +00:00
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:
@@ -1,5 +1,7 @@
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::{
|
||||
impl_unified_event, streaming::event_parser::protocols::raydium_amm_v4::types::AmmInfo,
|
||||
};
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@@ -151,6 +153,19 @@ pub struct RaydiumAmmV4WithdrawPnlEvent {
|
||||
}
|
||||
impl_unified_event!(RaydiumAmmV4WithdrawPnlEvent,);
|
||||
|
||||
/// 池信息
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4AmmInfoAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub amm_info: AmmInfo,
|
||||
}
|
||||
impl_unified_event!(RaydiumAmmV4AmmInfoAccountEvent,);
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 指令鉴别器
|
||||
@@ -160,4 +175,7 @@ pub mod discriminators {
|
||||
pub const INITIALIZE2: &[u8] = &[01];
|
||||
pub const WITHDRAW: &[u8] = &[04];
|
||||
pub const WITHDRAW_PNL: &[u8] = &[07];
|
||||
|
||||
/// 池信息鉴别器
|
||||
pub const AMM_INFO: &[u8] = &[6];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod events;
|
||||
pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
pub use parser::RaydiumAmmV4EventParser;
|
||||
|
||||
@@ -38,8 +38,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP_BASE_IN,
|
||||
event_type: EventType::RaydiumAmmV4SwapBaseIn,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_base_input_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_base_input_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -47,8 +47,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP_BASE_OUT,
|
||||
event_type: EventType::RaydiumAmmV4SwapBaseOut,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_base_output_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_base_output_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -56,8 +56,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::DEPOSIT,
|
||||
event_type: EventType::RaydiumAmmV4Deposit,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_deposit_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_deposit_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -65,8 +65,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::INITIALIZE2,
|
||||
event_type: EventType::RaydiumAmmV4Initialize2,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_initialize2_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_initialize2_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -74,8 +74,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::WITHDRAW,
|
||||
event_type: EventType::RaydiumAmmV4Withdraw,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_withdraw_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_withdraw_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -83,8 +83,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::WITHDRAW_PNL,
|
||||
event_type: EventType::RaydiumAmmV4WithdrawPnl,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_withdraw_pnl_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_withdraw_pnl_instruction),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -93,10 +93,6 @@ impl RaydiumAmmV4EventParser {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
fn empty_parse(_data: &[u8], _metadata: EventMetadata) -> Option<Box<dyn UnifiedEvent>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// 解析提现指令事件
|
||||
fn parse_withdraw_pnl_instruction(
|
||||
_data: &[u8],
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata, protocols::raydium_amm_v4::RaydiumAmmV4AmmInfoAccountEvent,
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct Fees {
|
||||
pub min_separate_numerator: u64,
|
||||
pub min_separate_denominator: u64,
|
||||
pub trade_fee_numerator: u64,
|
||||
pub trade_fee_denominator: u64,
|
||||
pub pnl_numerator: u64,
|
||||
pub pnl_denominator: u64,
|
||||
pub swap_fee_numerator: u64,
|
||||
pub swap_fee_denominator: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct OutPutData {
|
||||
pub need_take_pnl_coin: u64,
|
||||
pub need_take_pnl_pc: u64,
|
||||
pub total_pnl_pc: u64,
|
||||
pub total_pnl_coin: u64,
|
||||
pub pool_open_time: u64,
|
||||
pub punish_pc_amount: u64,
|
||||
pub punish_coin_amount: u64,
|
||||
pub orderbook_to_init_time: u64,
|
||||
pub swap_coin_in_amount: u128,
|
||||
pub swap_pc_out_amount: u128,
|
||||
pub swap_take_pc_fee: u64,
|
||||
pub swap_pc_in_amount: u128,
|
||||
pub swap_coin_out_amount: u128,
|
||||
pub swap_take_coin_fee: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct AmmInfo {
|
||||
pub status: u64,
|
||||
pub nonce: u64,
|
||||
pub order_num: u64,
|
||||
pub depth: u64,
|
||||
pub coin_decimals: u64,
|
||||
pub pc_decimals: u64,
|
||||
pub state: u64,
|
||||
pub reset_flag: u64,
|
||||
pub min_size: u64,
|
||||
pub vol_max_cut_ratio: u64,
|
||||
pub amount_wave: u64,
|
||||
pub coin_lot_size: u64,
|
||||
pub pc_lot_size: u64,
|
||||
pub min_price_multiplier: u64,
|
||||
pub max_price_multiplier: u64,
|
||||
pub sys_decimal_value: u64,
|
||||
pub fees: Fees,
|
||||
pub out_put: OutPutData,
|
||||
pub token_coin: Pubkey,
|
||||
pub token_pc: Pubkey,
|
||||
pub coin_mint: Pubkey,
|
||||
pub pc_mint: Pubkey,
|
||||
pub lp_mint: Pubkey,
|
||||
pub open_orders: Pubkey,
|
||||
pub market: Pubkey,
|
||||
pub serum_dex: Pubkey,
|
||||
pub target_orders: Pubkey,
|
||||
pub withdraw_queue: Pubkey,
|
||||
pub token_temp_lp: Pubkey,
|
||||
pub amm_owner: Pubkey,
|
||||
pub lp_amount: u64,
|
||||
pub client_order_id: u64,
|
||||
pub padding: [u64; 2],
|
||||
}
|
||||
|
||||
pub const AMM_INFO_SIZE: usize = 752;
|
||||
|
||||
pub fn amm_info_decode(data: &[u8]) -> Option<AmmInfo> {
|
||||
borsh::from_slice::<AmmInfo>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn amm_info_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if account.data.len() < AMM_INFO_SIZE {
|
||||
return None;
|
||||
}
|
||||
if let Some(amm_info) = amm_info_decode(&account.data[..AMM_INFO_SIZE]) {
|
||||
Some(Box::new(RaydiumAmmV4AmmInfoAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
amm_info: amm_info,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user