From 9e4f71dbb24aa2fd80d1a6d60c750a764e31ccbc Mon Sep 17 00:00:00 2001 From: ysq Date: Sun, 9 Nov 2025 23:30:48 +0800 Subject: [PATCH] feat: support Pump.fun V2 (Mayhem Mode) and update protocol structures for Nov 11 breaking changes --- Cargo.toml | 2 +- README.md | 4 +- README_CN.md | 4 +- src/streaming/event_parser/common/types.rs | 2 + .../event_parser/core/merger_event.rs | 16 ++++ src/streaming/event_parser/core/traits.rs | 3 + .../event_parser/protocols/pumpfun/events.rs | 38 +++++++++ .../event_parser/protocols/pumpfun/parser.rs | 84 +++++++++++++++++-- .../event_parser/protocols/pumpfun/types.rs | 9 +- .../event_parser/protocols/pumpswap/types.rs | 8 +- 10 files changed, 154 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f32d9a0..8a6f018 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "solana-streamer-sdk" -version = "1.1.0" +version = "1.1.1" edition = "2021" authors = ["William ", "sgxiang ", "wei <1415121722@qq.com>"] repository = "https://github.com/0xfnzero/solana-streamer" diff --git a/README.md b/README.md index ebd876f..1597e25 100755 --- a/README.md +++ b/README.md @@ -109,14 +109,14 @@ Add the dependency to your `Cargo.toml`: ```toml # Add to your Cargo.toml -solana-streamer-sdk = { path = "./solana-streamer", version = "1.1.0" } +solana-streamer-sdk = { path = "./solana-streamer", version = "1.1.1" } ``` ### Use crates.io ```toml # Add to your Cargo.toml -solana-streamer-sdk = "1.1.0" +solana-streamer-sdk = "1.1.1" ``` ## 🔄 Migration Guide diff --git a/README_CN.md b/README_CN.md index 1c544c4..9285e5b 100644 --- a/README_CN.md +++ b/README_CN.md @@ -108,14 +108,14 @@ git clone https://github.com/0xfnzero/solana-streamer ```toml # 添加到您的 Cargo.toml -solana-streamer-sdk = { path = "./solana-streamer", version = "1.1.0" } +solana-streamer-sdk = { path = "./solana-streamer", version = "1.1.1" } ``` ### 使用 crates.io ```toml # 添加到您的 Cargo.toml -solana-streamer-sdk = "1.1.0" +solana-streamer-sdk = "1.1.1" ``` ## 🔄 迁移指南 diff --git a/src/streaming/event_parser/common/types.rs b/src/streaming/event_parser/common/types.rs index 904da19..c07004c 100755 --- a/src/streaming/event_parser/common/types.rs +++ b/src/streaming/event_parser/common/types.rs @@ -69,6 +69,7 @@ pub enum EventType { // PumpFun events PumpFunCreateToken, + PumpFunCreateV2Token, PumpFunBuy, PumpFunSell, PumpFunMigrate, @@ -162,6 +163,7 @@ impl fmt::Display for EventType { EventType::PumpSwapDeposit => write!(f, "PumpSwapDeposit"), EventType::PumpSwapWithdraw => write!(f, "PumpSwapWithdraw"), EventType::PumpFunCreateToken => write!(f, "PumpFunCreateToken"), + EventType::PumpFunCreateV2Token => write!(f, "PumpFunCreateV2Token"), EventType::PumpFunBuy => write!(f, "PumpFunBuy"), EventType::PumpFunSell => write!(f, "PumpFunSell"), EventType::PumpFunMigrate => write!(f, "PumpFunMigrate"), diff --git a/src/streaming/event_parser/core/merger_event.rs b/src/streaming/event_parser/core/merger_event.rs index 2497d87..2893b0d 100644 --- a/src/streaming/event_parser/core/merger_event.rs +++ b/src/streaming/event_parser/core/merger_event.rs @@ -38,6 +38,22 @@ pub fn merge(instruction_event: &mut DexEvent, cpi_log_event: DexEvent) { } _ => {} }, + DexEvent::PumpFunCreateV2TokenEvent(e) => match cpi_log_event { + DexEvent::PumpFunCreateV2TokenEvent(cpie) => { + e.mint = cpie.mint; + e.bonding_curve = cpie.bonding_curve; + e.user = cpie.user; + e.creator = cpie.creator; + e.timestamp = cpie.timestamp; + e.virtual_token_reserves = cpie.virtual_token_reserves; + e.virtual_sol_reserves = cpie.virtual_sol_reserves; + e.real_token_reserves = cpie.real_token_reserves; + e.token_total_supply = cpie.token_total_supply; + e.token_program = cpie.token_program; + e.is_mayhem_mode = cpie.is_mayhem_mode; + } + _ => {} + }, DexEvent::PumpFunMigrateEvent(e) => match cpi_log_event { DexEvent::PumpFunMigrateEvent(cpie) => { e.user = cpie.user; diff --git a/src/streaming/event_parser/core/traits.rs b/src/streaming/event_parser/core/traits.rs index a2f6f00..833c182 100755 --- a/src/streaming/event_parser/core/traits.rs +++ b/src/streaming/event_parser/core/traits.rs @@ -26,6 +26,7 @@ pub enum DexEvent { // PumpFun events PumpFunCreateTokenEvent(PumpFunCreateTokenEvent), + PumpFunCreateV2TokenEvent(PumpFunCreateV2TokenEvent), PumpFunTradeEvent(PumpFunTradeEvent), PumpFunMigrateEvent(PumpFunMigrateEvent), PumpFunBondingCurveAccountEvent(PumpFunBondingCurveAccountEvent), @@ -87,6 +88,7 @@ impl DexEvent { DexEvent::BonkGlobalConfigAccountEvent(e) => &e.metadata, DexEvent::BonkPlatformConfigAccountEvent(e) => &e.metadata, DexEvent::PumpFunCreateTokenEvent(e) => &e.metadata, + DexEvent::PumpFunCreateV2TokenEvent(e) => &e.metadata, DexEvent::PumpFunTradeEvent(e) => &e.metadata, DexEvent::PumpFunMigrateEvent(e) => &e.metadata, DexEvent::PumpFunBondingCurveAccountEvent(e) => &e.metadata, @@ -138,6 +140,7 @@ impl DexEvent { DexEvent::BonkGlobalConfigAccountEvent(e) => &mut e.metadata, DexEvent::BonkPlatformConfigAccountEvent(e) => &mut e.metadata, DexEvent::PumpFunCreateTokenEvent(e) => &mut e.metadata, + DexEvent::PumpFunCreateV2TokenEvent(e) => &mut e.metadata, DexEvent::PumpFunTradeEvent(e) => &mut e.metadata, DexEvent::PumpFunMigrateEvent(e) => &mut e.metadata, DexEvent::PumpFunBondingCurveAccountEvent(e) => &mut e.metadata, diff --git a/src/streaming/event_parser/protocols/pumpfun/events.rs b/src/streaming/event_parser/protocols/pumpfun/events.rs index 1e176ce..6a09870 100755 --- a/src/streaming/event_parser/protocols/pumpfun/events.rs +++ b/src/streaming/event_parser/protocols/pumpfun/events.rs @@ -36,6 +36,39 @@ pub fn pumpfun_create_token_event_log_decode(data: &[u8]) -> Option(&data[..PUMPFUN_CREATE_TOKEN_EVENT_LOG_SIZE]).ok() } +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)] +pub struct PumpFunCreateV2TokenEvent { + #[borsh(skip)] + pub metadata: EventMetadata, + pub name: String, + pub symbol: String, + pub uri: String, + pub mint: Pubkey, + pub bonding_curve: Pubkey, + pub user: Pubkey, + pub creator: Pubkey, + pub timestamp: i64, + pub virtual_token_reserves: u64, + pub virtual_sol_reserves: u64, + pub real_token_reserves: u64, + pub token_total_supply: u64, + pub token_program: Pubkey, + pub is_mayhem_mode: bool, + #[borsh(skip)] + pub mint_authority: Pubkey, + #[borsh(skip)] + pub associated_bonding_curve: Pubkey, +} + +pub const PUMPFUN_CREATE_V2_TOKEN_EVENT_LOG_SIZE: usize = 257 + 32 + 1; + +pub fn pumpfun_create_v2_token_event_log_decode(data: &[u8]) -> Option { + if data.len() < PUMPFUN_CREATE_V2_TOKEN_EVENT_LOG_SIZE { + return None; + } + borsh::from_slice::(&data[..PUMPFUN_CREATE_V2_TOKEN_EVENT_LOG_SIZE]).ok() +} + #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)] pub struct PumpFunTradeEvent { #[borsh(skip)] @@ -101,6 +134,10 @@ pub struct PumpFunTradeEvent { pub global_volume_accumulator: Pubkey, #[borsh(skip)] pub user_volume_accumulator: Pubkey, + #[borsh(skip)] + pub fee_config: Pubkey, + #[borsh(skip)] + pub fee_program: Pubkey, } pub const PUMPFUN_TRADE_EVENT_LOG_SIZE: usize = 250; @@ -218,6 +255,7 @@ pub mod discriminators { // 指令鉴别器 pub const CREATE_TOKEN_IX: &[u8] = &[24, 30, 200, 40, 5, 28, 7, 119]; + pub const CREATE_V2_TOKEN_IX: &[u8] = &[214, 144, 76, 236, 95, 139, 49, 180]; pub const BUY_IX: &[u8] = &[102, 6, 61, 18, 1, 218, 235, 234]; pub const SELL_IX: &[u8] = &[51, 230, 133, 164, 1, 127, 131, 173]; pub const MIGRATE_IX: &[u8] = &[155, 234, 231, 146, 236, 158, 162, 30]; diff --git a/src/streaming/event_parser/protocols/pumpfun/parser.rs b/src/streaming/event_parser/protocols/pumpfun/parser.rs index d1bad33..2f23729 100755 --- a/src/streaming/event_parser/protocols/pumpfun/parser.rs +++ b/src/streaming/event_parser/protocols/pumpfun/parser.rs @@ -1,9 +1,9 @@ use crate::streaming::event_parser::{ common::{EventMetadata, EventType}, protocols::pumpfun::{ - discriminators, pumpfun_create_token_event_log_decode, pumpfun_migrate_event_log_decode, - pumpfun_trade_event_log_decode, PumpFunCreateTokenEvent, PumpFunMigrateEvent, - PumpFunTradeEvent, + discriminators, pumpfun_create_token_event_log_decode, pumpfun_create_v2_token_event_log_decode, + pumpfun_migrate_event_log_decode, pumpfun_trade_event_log_decode, PumpFunCreateTokenEvent, + PumpFunCreateV2TokenEvent, PumpFunMigrateEvent, PumpFunTradeEvent, }, DexEvent, }; @@ -26,6 +26,9 @@ pub fn parse_pumpfun_instruction_data( discriminators::CREATE_TOKEN_IX => { parse_create_token_instruction(data, accounts, metadata) } + discriminators::CREATE_V2_TOKEN_IX => { + parse_create_v2_token_instruction(data, accounts, metadata) + } discriminators::BUY_IX => { parse_buy_instruction(data, accounts, metadata) } @@ -179,6 +182,69 @@ fn parse_create_token_instruction( })) } +/// 解析创建 V2 代币指令事件 (SPL-22 Token, Mayhem Mode) +fn parse_create_v2_token_instruction( + data: &[u8], + accounts: &[Pubkey], + mut metadata: EventMetadata, +) -> Option { + metadata.event_type = EventType::PumpFunCreateV2Token; + + if data.len() < 16 || accounts.len() < 11 { + return None; + } + let mut offset = 0; + if offset + 4 > data.len() { + return None; + } + let name_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize; + offset += 4; + if offset + name_len > data.len() { + return None; + } + let name = String::from_utf8_lossy(&data[offset..offset + name_len]); + offset += name_len; + if offset + 4 > data.len() { + return None; + } + let symbol_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize; + offset += 4; + if offset + symbol_len > data.len() { + return None; + } + let symbol = String::from_utf8_lossy(&data[offset..offset + symbol_len]); + offset += symbol_len; + if offset + 4 > data.len() { + return None; + } + let uri_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize; + offset += 4; + if offset + uri_len > data.len() { + return None; + } + let uri = String::from_utf8_lossy(&data[offset..offset + uri_len]); + offset += uri_len; + let creator = if offset + 32 <= data.len() { + Pubkey::new_from_array(data[offset..offset + 32].try_into().ok()?) + } else { + Pubkey::default() + }; + + Some(DexEvent::PumpFunCreateV2TokenEvent(PumpFunCreateV2TokenEvent { + metadata, + name: name.to_string(), + symbol: symbol.to_string(), + uri: uri.to_string(), + creator, + mint: accounts[0], + mint_authority: accounts[1], + bonding_curve: accounts[2], + associated_bonding_curve: accounts[3], + user: accounts[7], + ..Default::default() + })) +} + // 解析买入指令事件 fn parse_buy_instruction( data: &[u8], @@ -187,7 +253,7 @@ fn parse_buy_instruction( ) -> Option { metadata.event_type = EventType::PumpFunBuy; - if data.len() < 16 || accounts.len() < 13 { + if data.len() < 16 || accounts.len() < 16 { return None; } let amount = u64::from_le_bytes(data[0..8].try_into().unwrap()); @@ -208,6 +274,8 @@ fn parse_buy_instruction( program: accounts[11], global_volume_accumulator: accounts[12], user_volume_accumulator: accounts[13], + fee_config: accounts[14], + fee_program: accounts[15], max_sol_cost, amount, is_buy: true, @@ -223,7 +291,7 @@ fn parse_sell_instruction( ) -> Option { metadata.event_type = EventType::PumpFunSell; - if data.len() < 16 || accounts.len() < 11 { + if data.len() < 16 || accounts.len() < 14 { return None; } let amount = u64::from_le_bytes(data[0..8].try_into().unwrap()); @@ -242,8 +310,10 @@ fn parse_sell_instruction( token_program: accounts[9], event_authority: accounts[10], program: accounts[11], - global_volume_accumulator: *accounts.get(12).unwrap_or(&Pubkey::default()), - user_volume_accumulator: *accounts.get(13).unwrap_or(&Pubkey::default()), + global_volume_accumulator: Pubkey::default(), + user_volume_accumulator: Pubkey::default(), + fee_config: accounts[12], + fee_program: accounts[13], min_sol_output, amount, is_buy: false, diff --git a/src/streaming/event_parser/protocols/pumpfun/types.rs b/src/streaming/event_parser/protocols/pumpfun/types.rs index 0805fb4..e30436b 100644 --- a/src/streaming/event_parser/protocols/pumpfun/types.rs +++ b/src/streaming/event_parser/protocols/pumpfun/types.rs @@ -20,9 +20,10 @@ pub struct BondingCurve { pub token_total_supply: u64, pub complete: bool, pub creator: Pubkey, + pub is_mayhem_mode: bool, } -pub const BONDING_CURVE_SIZE: usize = 8 * 5 + 1 + 32; +pub const BONDING_CURVE_SIZE: usize = 8 * 5 + 1 + 32 + 1; pub fn bonding_curve_decode(data: &[u8]) -> Option { if data.len() < BONDING_CURVE_SIZE { @@ -72,9 +73,13 @@ pub struct Global { pub fee_recipients: [Pubkey; 7], pub set_creator_authority: Pubkey, pub admin_set_creator_authority: Pubkey, + pub create_v2_enabled: bool, + pub whitelist_pda: Pubkey, + pub reserved_fee_recipient: Pubkey, + pub mayhem_mode_enabled: bool, } -pub const GLOBAL_SIZE: usize = 1 + 32 * 2 + 8 * 5 + 32 + 1 + 8 * 2 + 32 * 7 + 32 * 2; +pub const GLOBAL_SIZE: usize = 1 + 32 * 2 + 8 * 5 + 32 + 1 + 8 * 2 + 32 * 7 + 32 * 2 + 1 + 32 * 2 + 1; pub fn global_decode(data: &[u8]) -> Option { if data.len() < GLOBAL_SIZE { diff --git a/src/streaming/event_parser/protocols/pumpswap/types.rs b/src/streaming/event_parser/protocols/pumpswap/types.rs index afa99bc..d50aa43 100644 --- a/src/streaming/event_parser/protocols/pumpswap/types.rs +++ b/src/streaming/event_parser/protocols/pumpswap/types.rs @@ -20,9 +20,12 @@ pub struct GlobalConfig { pub protocol_fee_recipients: [Pubkey; 8], pub coin_creator_fee_basis_points: u64, pub admin_set_coin_creator_authority: Pubkey, + pub whitelist_pda: Pubkey, + pub reserved_fee_recipient: Pubkey, + pub mayhem_mode_enabled: bool, } -pub const GLOBAL_CONFIG_SIZE: usize = 32 + 8 + 8 + 1 + 32 * 8 + 8 + 32; +pub const GLOBAL_CONFIG_SIZE: usize = 32 + 8 + 8 + 1 + 32 * 8 + 8 + 32 + 32 + 32 + 1; pub fn global_config_decode(data: &[u8]) -> Option { if data.len() < GLOBAL_CONFIG_SIZE { @@ -67,9 +70,10 @@ pub struct Pool { pub pool_quote_token_account: Pubkey, pub lp_supply: u64, pub coin_creator: Pubkey, + pub is_mayhem_mode: bool, } -pub const POOL_SIZE: usize = 1 + 2 + 32 * 6 + 8 + 32; +pub const POOL_SIZE: usize = 1 + 2 + 32 * 6 + 8 + 32 + 1; pub fn pool_decode(data: &[u8]) -> Option { if data.len() < POOL_SIZE {