2025-09-14 01:13:11 +08:00
|
|
|
use crate::streaming::event_parser::{
|
2025-11-03 23:58:19 +08:00
|
|
|
common::{EventMetadata, EventType},
|
2025-09-14 01:13:11 +08:00
|
|
|
protocols::pumpfun::{
|
2025-11-09 23:59:56 +08:00
|
|
|
discriminators, pumpfun_create_v2_token_event_log_decode, pumpfun_migrate_event_log_decode,
|
|
|
|
|
pumpfun_trade_event_log_decode, PumpFunCreateTokenEvent, PumpFunCreateV2TokenEvent,
|
|
|
|
|
PumpFunMigrateEvent, PumpFunTradeEvent,
|
2025-08-11 22:02:09 +08:00
|
|
|
},
|
2025-10-12 22:00:15 +08:00
|
|
|
DexEvent,
|
2025-07-19 23:46:42 +08:00
|
|
|
};
|
2025-09-14 01:13:11 +08:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
2025-07-19 23:46:42 +08:00
|
|
|
|
|
|
|
|
/// PumpFun程序ID
|
|
|
|
|
pub const PUMPFUN_PROGRAM_ID: Pubkey =
|
|
|
|
|
solana_sdk::pubkey!("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P");
|
|
|
|
|
|
2025-11-03 23:58:19 +08:00
|
|
|
/// 解析 PumpFun instruction data
|
|
|
|
|
///
|
|
|
|
|
/// 根据判别器路由到具体的 instruction 解析函数
|
|
|
|
|
pub fn parse_pumpfun_instruction_data(
|
|
|
|
|
discriminator: &[u8],
|
|
|
|
|
data: &[u8],
|
|
|
|
|
accounts: &[Pubkey],
|
|
|
|
|
metadata: EventMetadata,
|
|
|
|
|
) -> Option<DexEvent> {
|
|
|
|
|
match discriminator {
|
2025-11-09 23:59:56 +08:00
|
|
|
discriminators::CREATE_TOKEN_IX => parse_create_token_instruction(data, accounts, metadata),
|
2025-11-09 23:30:48 +08:00
|
|
|
discriminators::CREATE_V2_TOKEN_IX => {
|
|
|
|
|
parse_create_v2_token_instruction(data, accounts, metadata)
|
|
|
|
|
}
|
2026-01-23 16:47:55 +08:00
|
|
|
discriminators::BUY_IX => parse_buy_instruction(data, accounts, metadata),
|
|
|
|
|
discriminators::BUY_EXACT_SOL_IN_IX => parse_buy_exact_sol_in_instruction(data, accounts, metadata),
|
2025-11-09 23:59:56 +08:00
|
|
|
discriminators::SELL_IX => parse_sell_instruction(data, accounts, metadata),
|
|
|
|
|
discriminators::MIGRATE_IX => parse_migrate_instruction(data, accounts, metadata),
|
2025-11-03 23:58:19 +08:00
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 解析 PumpFun inner instruction data
|
|
|
|
|
///
|
|
|
|
|
/// 根据判别器路由到具体的 inner instruction 解析函数
|
|
|
|
|
pub fn parse_pumpfun_inner_instruction_data(
|
|
|
|
|
discriminator: &[u8],
|
|
|
|
|
data: &[u8],
|
|
|
|
|
metadata: EventMetadata,
|
|
|
|
|
) -> Option<DexEvent> {
|
|
|
|
|
match discriminator {
|
2025-11-09 23:59:56 +08:00
|
|
|
discriminators::CREATE_TOKEN_EVENT => parse_create_token_inner_instruction(data, metadata),
|
|
|
|
|
discriminators::TRADE_EVENT => parse_trade_inner_instruction(data, metadata),
|
2025-11-03 23:58:19 +08:00
|
|
|
discriminators::COMPLETE_PUMP_AMM_MIGRATION_EVENT => {
|
|
|
|
|
parse_migrate_inner_instruction(data, metadata)
|
|
|
|
|
}
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 解析 PumpFun 账户数据
|
|
|
|
|
///
|
|
|
|
|
/// 根据判别器路由到具体的账户解析函数
|
|
|
|
|
pub fn parse_pumpfun_account_data(
|
|
|
|
|
discriminator: &[u8],
|
|
|
|
|
account: &crate::streaming::grpc::AccountPretty,
|
|
|
|
|
metadata: crate::streaming::event_parser::common::EventMetadata,
|
|
|
|
|
) -> Option<crate::streaming::event_parser::DexEvent> {
|
|
|
|
|
match discriminator {
|
|
|
|
|
discriminators::BONDING_CURVE_ACCOUNT => {
|
2025-11-09 23:59:56 +08:00
|
|
|
crate::streaming::event_parser::protocols::pumpfun::types::bonding_curve_parser(
|
|
|
|
|
account, metadata,
|
|
|
|
|
)
|
2025-11-03 23:58:19 +08:00
|
|
|
}
|
|
|
|
|
discriminators::GLOBAL_ACCOUNT => {
|
2025-11-09 23:59:56 +08:00
|
|
|
crate::streaming::event_parser::protocols::pumpfun::types::global_parser(
|
|
|
|
|
account, metadata,
|
|
|
|
|
)
|
2025-11-03 23:58:19 +08:00
|
|
|
}
|
|
|
|
|
_ => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-14 01:13:11 +08:00
|
|
|
/// 解析迁移事件
|
2025-11-03 23:58:19 +08:00
|
|
|
fn parse_migrate_inner_instruction(data: &[u8], mut metadata: EventMetadata) -> Option<DexEvent> {
|
|
|
|
|
metadata.event_type = EventType::PumpFunMigrate;
|
2025-09-14 01:13:11 +08:00
|
|
|
if let Some(event) = pumpfun_migrate_event_log_decode(data) {
|
2025-10-12 22:00:15 +08:00
|
|
|
Some(DexEvent::PumpFunMigrateEvent(PumpFunMigrateEvent { metadata, ..event }))
|
2025-09-14 01:13:11 +08:00
|
|
|
} else {
|
|
|
|
|
None
|
2025-08-03 05:37:04 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-14 01:13:11 +08:00
|
|
|
/// 解析创建代币日志事件
|
|
|
|
|
fn parse_create_token_inner_instruction(
|
|
|
|
|
data: &[u8],
|
2025-11-03 23:58:19 +08:00
|
|
|
mut metadata: EventMetadata,
|
2025-10-12 22:00:15 +08:00
|
|
|
) -> Option<DexEvent> {
|
2025-11-03 23:58:19 +08:00
|
|
|
metadata.event_type = EventType::PumpFunCreateToken;
|
2025-11-09 23:59:56 +08:00
|
|
|
if let Some(event) = pumpfun_create_v2_token_event_log_decode(data) {
|
|
|
|
|
Some(DexEvent::PumpFunCreateV2TokenEvent(PumpFunCreateV2TokenEvent { metadata, ..event }))
|
2025-09-14 01:13:11 +08:00
|
|
|
} else {
|
|
|
|
|
None
|
2025-08-11 22:02:09 +08:00
|
|
|
}
|
2025-07-19 23:46:42 +08:00
|
|
|
}
|
|
|
|
|
|
2025-11-03 23:58:19 +08:00
|
|
|
/// 解析交易事件 (inner instruction 不设置 event_type,因为不知道是 Buy 还是 Sell)
|
2025-10-12 22:00:15 +08:00
|
|
|
fn parse_trade_inner_instruction(data: &[u8], metadata: EventMetadata) -> Option<DexEvent> {
|
2025-11-03 23:58:19 +08:00
|
|
|
// 注意:inner instruction 的 trade event 不设置 event_type
|
|
|
|
|
// 因为它会被合并到 instruction event 中,而 instruction event 已经设置了正确的 event_type
|
2025-09-14 01:13:11 +08:00
|
|
|
if let Some(event) = pumpfun_trade_event_log_decode(data) {
|
2025-10-12 22:00:15 +08:00
|
|
|
Some(DexEvent::PumpFunTradeEvent(PumpFunTradeEvent { metadata, ..event }))
|
2025-09-14 01:13:11 +08:00
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 解析创建代币指令事件
|
2026-03-07 11:45:40 +08:00
|
|
|
/// 账户: 0: mint, 1: mint_authority, 2: bonding_curve, 3: associated_bonding_curve, 4: global,
|
|
|
|
|
/// 5: mpl_token_metadata, 6: metadata_account, 7: user, 8: system_program, 9: token_program,
|
|
|
|
|
/// 10: associated_token_program, 11: rent, 12: event_authority, 13: program.
|
2025-09-14 01:13:11 +08:00
|
|
|
fn parse_create_token_instruction(
|
|
|
|
|
data: &[u8],
|
|
|
|
|
accounts: &[Pubkey],
|
2025-11-03 23:58:19 +08:00
|
|
|
mut metadata: EventMetadata,
|
2025-10-12 22:00:15 +08:00
|
|
|
) -> Option<DexEvent> {
|
2025-11-03 23:58:19 +08:00
|
|
|
metadata.event_type = EventType::PumpFunCreateToken;
|
|
|
|
|
|
2025-09-14 01:13:11 +08:00
|
|
|
if data.len() < 16 || accounts.len() < 11 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let mut offset = 0;
|
2025-09-14 23:26:21 +08:00
|
|
|
if offset + 4 > data.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2025-09-14 01:13:11 +08:00
|
|
|
let name_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize;
|
|
|
|
|
offset += 4;
|
2025-09-14 23:26:21 +08:00
|
|
|
if offset + name_len > data.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2025-09-14 01:13:11 +08:00
|
|
|
let name = String::from_utf8_lossy(&data[offset..offset + name_len]);
|
|
|
|
|
offset += name_len;
|
2025-09-14 23:26:21 +08:00
|
|
|
if offset + 4 > data.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2025-09-14 01:13:11 +08:00
|
|
|
let symbol_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize;
|
|
|
|
|
offset += 4;
|
2025-09-14 23:26:21 +08:00
|
|
|
if offset + symbol_len > data.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2025-09-14 01:13:11 +08:00
|
|
|
let symbol = String::from_utf8_lossy(&data[offset..offset + symbol_len]);
|
|
|
|
|
offset += symbol_len;
|
2025-09-14 23:26:21 +08:00
|
|
|
if offset + 4 > data.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2025-09-14 01:13:11 +08:00
|
|
|
let uri_len = u32::from_le_bytes(data[offset..offset + 4].try_into().unwrap()) as usize;
|
|
|
|
|
offset += 4;
|
2025-09-14 23:26:21 +08:00
|
|
|
if offset + uri_len > data.len() {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2025-09-14 01:13:11 +08:00
|
|
|
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()
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-12 22:00:15 +08:00
|
|
|
Some(DexEvent::PumpFunCreateTokenEvent(PumpFunCreateTokenEvent {
|
2025-09-14 01:13:11 +08:00
|
|
|
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],
|
2026-02-21 09:51:02 +00:00
|
|
|
global: accounts[4],
|
|
|
|
|
mpl_token_metadata: accounts[5],
|
|
|
|
|
metadata_account: accounts[6],
|
2025-09-14 01:13:11 +08:00
|
|
|
user: accounts[7],
|
2026-02-21 09:51:02 +00:00
|
|
|
system_program: accounts[8],
|
|
|
|
|
token_program: accounts[9],
|
|
|
|
|
associated_token_program: accounts[10],
|
|
|
|
|
rent: accounts[11],
|
|
|
|
|
event_authority: accounts[12],
|
|
|
|
|
program: accounts[13],
|
2025-09-14 01:13:11 +08:00
|
|
|
..Default::default()
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-09 23:30:48 +08:00
|
|
|
/// 解析创建 V2 代币指令事件 (SPL-22 Token, Mayhem Mode)
|
2026-03-07 11:45:40 +08:00
|
|
|
/// 账户: 0: mint, 1: mint_authority, 2: bonding_curve, 3: associated_bonding_curve, 4: global,
|
|
|
|
|
/// 5: user, 6: system_program, 7: token_program, 8: associated_token_program, 9: mayhem_program_id,
|
|
|
|
|
/// 10: global_params, 11: sol_vault, 12: mayhem_state, 13: mayhem_token_vault, 14: event_authority, 15: program.
|
2025-11-09 23:30:48 +08:00
|
|
|
fn parse_create_v2_token_instruction(
|
|
|
|
|
data: &[u8],
|
|
|
|
|
accounts: &[Pubkey],
|
|
|
|
|
mut metadata: EventMetadata,
|
|
|
|
|
) -> Option<DexEvent> {
|
|
|
|
|
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],
|
2026-02-21 09:51:02 +00:00
|
|
|
global: accounts[4],
|
|
|
|
|
user: accounts[5],
|
|
|
|
|
system_program: accounts[6],
|
|
|
|
|
token_program: accounts[7],
|
|
|
|
|
associated_token_program: accounts[8],
|
|
|
|
|
mayhem_program_id: accounts[9],
|
|
|
|
|
global_params: accounts[10],
|
|
|
|
|
sol_vault: accounts[11],
|
|
|
|
|
mayhem_state: accounts[12],
|
|
|
|
|
mayhem_token_vault: accounts[13],
|
|
|
|
|
event_authority: accounts[14],
|
|
|
|
|
program: accounts[15],
|
2025-11-09 23:30:48 +08:00
|
|
|
..Default::default()
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-07 11:45:40 +08:00
|
|
|
/// 解析买入指令事件
|
|
|
|
|
/// Buy 指令共 16 个固定账户(与 idl/pumpfun.json 一致):
|
|
|
|
|
/// 0: global, 1: fee_recipient, 2: mint, 3: bonding_curve, 4: associated_bonding_curve,
|
|
|
|
|
/// 5: associated_user, 6: user, 7: system_program, 8: token_program, 9: creator_vault,
|
|
|
|
|
/// 10: event_authority, 11: program, 12: global_volume_accumulator, 13: user_volume_accumulator,
|
|
|
|
|
/// 14: fee_config, 15: fee_program.
|
2025-09-14 01:13:11 +08:00
|
|
|
fn parse_buy_instruction(
|
|
|
|
|
data: &[u8],
|
|
|
|
|
accounts: &[Pubkey],
|
2025-11-03 23:58:19 +08:00
|
|
|
mut metadata: EventMetadata,
|
2025-10-12 22:00:15 +08:00
|
|
|
) -> Option<DexEvent> {
|
2025-11-03 23:58:19 +08:00
|
|
|
metadata.event_type = EventType::PumpFunBuy;
|
|
|
|
|
|
2025-11-09 23:30:48 +08:00
|
|
|
if data.len() < 16 || accounts.len() < 16 {
|
2025-09-14 01:13:11 +08:00
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let amount = u64::from_le_bytes(data[0..8].try_into().unwrap());
|
|
|
|
|
let max_sol_cost = u64::from_le_bytes(data[8..16].try_into().unwrap());
|
2025-10-12 22:00:15 +08:00
|
|
|
Some(DexEvent::PumpFunTradeEvent(PumpFunTradeEvent {
|
2025-09-14 01:13:11 +08:00
|
|
|
metadata,
|
|
|
|
|
global: accounts[0],
|
|
|
|
|
fee_recipient: accounts[1],
|
|
|
|
|
mint: accounts[2],
|
|
|
|
|
bonding_curve: accounts[3],
|
|
|
|
|
associated_bonding_curve: accounts[4],
|
|
|
|
|
associated_user: accounts[5],
|
|
|
|
|
user: accounts[6],
|
|
|
|
|
system_program: accounts[7],
|
|
|
|
|
token_program: accounts[8],
|
|
|
|
|
creator_vault: accounts[9],
|
|
|
|
|
event_authority: accounts[10],
|
|
|
|
|
program: accounts[11],
|
|
|
|
|
global_volume_accumulator: accounts[12],
|
|
|
|
|
user_volume_accumulator: accounts[13],
|
2025-11-09 23:30:48 +08:00
|
|
|
fee_config: accounts[14],
|
|
|
|
|
fee_program: accounts[15],
|
2025-09-14 01:13:11 +08:00
|
|
|
max_sol_cost,
|
|
|
|
|
amount,
|
|
|
|
|
is_buy: true,
|
|
|
|
|
..Default::default()
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 16:47:55 +08:00
|
|
|
/// 解析 buy_exact_sol_in 指令事件
|
2026-03-07 11:45:40 +08:00
|
|
|
/// 账户布局与 buy 相同,共 16 个固定账户: 0: global, 1: fee_recipient, 2: mint, 3: bonding_curve,
|
|
|
|
|
/// 4: associated_bonding_curve, 5: associated_user, 6: user, 7: system_program, 8: token_program,
|
|
|
|
|
/// 9: creator_vault, 10: event_authority, 11: program, 12: global_volume_accumulator,
|
|
|
|
|
/// 13: user_volume_accumulator, 14: fee_config, 15: fee_program.
|
|
|
|
|
/// 参数顺序与 buy 不同: spendable_sol_in (SOL), min_tokens_out (token).
|
2026-01-23 16:47:55 +08:00
|
|
|
fn parse_buy_exact_sol_in_instruction(
|
|
|
|
|
data: &[u8], accounts: &[Pubkey],
|
|
|
|
|
mut metadata: EventMetadata,
|
|
|
|
|
) -> Option<DexEvent> {
|
|
|
|
|
metadata.event_type = EventType::PumpFunBuy;
|
|
|
|
|
|
|
|
|
|
if data.len() < 16 || accounts.len() < 16 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 注意:buy_exact_sol_in 的参数顺序是先 SOL 再 token
|
|
|
|
|
let spendable_sol_in = u64::from_le_bytes(data[0..8].try_into().unwrap());
|
|
|
|
|
let min_tokens_out = u64::from_le_bytes(data[8..16].try_into().unwrap());
|
|
|
|
|
|
|
|
|
|
Some(DexEvent::PumpFunTradeEvent(PumpFunTradeEvent {
|
|
|
|
|
metadata,
|
|
|
|
|
global: accounts[0],
|
|
|
|
|
fee_recipient: accounts[1],
|
|
|
|
|
mint: accounts[2],
|
|
|
|
|
bonding_curve: accounts[3],
|
|
|
|
|
associated_bonding_curve: accounts[4],
|
|
|
|
|
associated_user: accounts[5],
|
|
|
|
|
user: accounts[6],
|
|
|
|
|
system_program: accounts[7],
|
|
|
|
|
token_program: accounts[8],
|
|
|
|
|
creator_vault: accounts[9],
|
|
|
|
|
event_authority: accounts[10],
|
|
|
|
|
program: accounts[11],
|
|
|
|
|
global_volume_accumulator: accounts[12],
|
|
|
|
|
user_volume_accumulator: accounts[13],
|
|
|
|
|
fee_config: accounts[14],
|
|
|
|
|
fee_program: accounts[15],
|
|
|
|
|
max_sol_cost: spendable_sol_in, // Map spendable_sol_in to max_sol_cost
|
|
|
|
|
amount: min_tokens_out, // Map min_tokens_out to amount
|
|
|
|
|
is_buy: true,
|
|
|
|
|
..Default::default()
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-07 11:45:40 +08:00
|
|
|
/// 解析卖出指令事件
|
|
|
|
|
/// Sell 指令共 14 个固定账户(与 idl/pumpfun.json 一致):
|
|
|
|
|
/// 0: global, 1: fee_recipient, 2: mint, 3: bonding_curve, 4: associated_bonding_curve,
|
|
|
|
|
/// 5: associated_user, 6: user, 7: system_program, 8: creator_vault, 9: token_program,
|
|
|
|
|
/// 10: event_authority, 11: program, 12: fee_config, 13: fee_program.
|
|
|
|
|
/// remaining_accounts 可能含 user_volume_accumulator(返现)等。
|
2025-09-14 01:13:11 +08:00
|
|
|
fn parse_sell_instruction(
|
|
|
|
|
data: &[u8],
|
|
|
|
|
accounts: &[Pubkey],
|
2025-11-03 23:58:19 +08:00
|
|
|
mut metadata: EventMetadata,
|
2025-10-12 22:00:15 +08:00
|
|
|
) -> Option<DexEvent> {
|
2025-11-03 23:58:19 +08:00
|
|
|
metadata.event_type = EventType::PumpFunSell;
|
|
|
|
|
|
2025-11-09 23:30:48 +08:00
|
|
|
if data.len() < 16 || accounts.len() < 14 {
|
2025-09-14 01:13:11 +08:00
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
let amount = u64::from_le_bytes(data[0..8].try_into().unwrap());
|
|
|
|
|
let min_sol_output = u64::from_le_bytes(data[8..16].try_into().unwrap());
|
2025-10-12 22:00:15 +08:00
|
|
|
Some(DexEvent::PumpFunTradeEvent(PumpFunTradeEvent {
|
2025-09-14 01:13:11 +08:00
|
|
|
metadata,
|
|
|
|
|
global: accounts[0],
|
|
|
|
|
fee_recipient: accounts[1],
|
|
|
|
|
mint: accounts[2],
|
|
|
|
|
bonding_curve: accounts[3],
|
|
|
|
|
associated_bonding_curve: accounts[4],
|
|
|
|
|
associated_user: accounts[5],
|
|
|
|
|
user: accounts[6],
|
|
|
|
|
system_program: accounts[7],
|
|
|
|
|
creator_vault: accounts[8],
|
|
|
|
|
token_program: accounts[9],
|
|
|
|
|
event_authority: accounts[10],
|
|
|
|
|
program: accounts[11],
|
2025-11-09 23:30:48 +08:00
|
|
|
global_volume_accumulator: Pubkey::default(),
|
|
|
|
|
user_volume_accumulator: Pubkey::default(),
|
|
|
|
|
fee_config: accounts[12],
|
|
|
|
|
fee_program: accounts[13],
|
2025-09-14 01:13:11 +08:00
|
|
|
min_sol_output,
|
|
|
|
|
amount,
|
|
|
|
|
is_buy: false,
|
|
|
|
|
..Default::default()
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 解析迁移指令事件
|
2026-03-07 11:45:40 +08:00
|
|
|
/// 共 24 个固定账户: 0: global, 1: withdraw_authority, 2: mint, 3: bonding_curve, 4: associated_bonding_curve,
|
|
|
|
|
/// 5: user, 6: system_program, 7: token_program, 8: pump_amm, 9: pool, 10: pool_authority,
|
|
|
|
|
/// 11: pool_authority_mint_account, 12: pool_authority_wsol_account, 13: amm_global_config, 14: wsol_mint,
|
|
|
|
|
/// 15: lp_mint, 16: user_pool_token_account, 17: pool_base_token_account, 18: pool_quote_token_account,
|
|
|
|
|
/// 19: token_2022_program, 20: associated_token_program, 21: pump_amm_event_authority, 22: event_authority, 23: program.
|
2025-09-14 01:13:11 +08:00
|
|
|
fn parse_migrate_instruction(
|
|
|
|
|
_data: &[u8],
|
|
|
|
|
accounts: &[Pubkey],
|
2025-11-03 23:58:19 +08:00
|
|
|
mut metadata: EventMetadata,
|
2025-10-12 22:00:15 +08:00
|
|
|
) -> Option<DexEvent> {
|
2025-11-03 23:58:19 +08:00
|
|
|
metadata.event_type = EventType::PumpFunMigrate;
|
|
|
|
|
|
2025-09-14 01:13:11 +08:00
|
|
|
if accounts.len() < 24 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
2025-10-12 22:00:15 +08:00
|
|
|
Some(DexEvent::PumpFunMigrateEvent(PumpFunMigrateEvent {
|
2025-09-14 01:13:11 +08:00
|
|
|
metadata,
|
|
|
|
|
global: accounts[0],
|
|
|
|
|
withdraw_authority: accounts[1],
|
|
|
|
|
mint: accounts[2],
|
|
|
|
|
bonding_curve: accounts[3],
|
|
|
|
|
associated_bonding_curve: accounts[4],
|
|
|
|
|
user: accounts[5],
|
|
|
|
|
system_program: accounts[6],
|
|
|
|
|
token_program: accounts[7],
|
|
|
|
|
pump_amm: accounts[8],
|
|
|
|
|
pool: accounts[9],
|
|
|
|
|
pool_authority: accounts[10],
|
|
|
|
|
pool_authority_mint_account: accounts[11],
|
|
|
|
|
pool_authority_wsol_account: accounts[12],
|
|
|
|
|
amm_global_config: accounts[13],
|
|
|
|
|
wsol_mint: accounts[14],
|
|
|
|
|
lp_mint: accounts[15],
|
|
|
|
|
user_pool_token_account: accounts[16],
|
|
|
|
|
pool_base_token_account: accounts[17],
|
|
|
|
|
pool_quote_token_account: accounts[18],
|
|
|
|
|
token_2022_program: accounts[19],
|
|
|
|
|
associated_token_program: accounts[20],
|
|
|
|
|
pump_amm_event_authority: accounts[21],
|
|
|
|
|
event_authority: accounts[22],
|
|
|
|
|
program: accounts[23],
|
|
|
|
|
..Default::default()
|
|
|
|
|
}))
|
|
|
|
|
}
|