Use sol-parser-sdk 0.4.17

This commit is contained in:
0xfnzero
2026-05-25 19:18:54 +08:00
parent eb1324d402
commit 0875ec1a9d
5 changed files with 101 additions and 27 deletions
@@ -1,5 +1,8 @@
use crate::streaming::event_parser::DexEvent;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{pubkey, pubkey::Pubkey};
const PUMPFUN_SOLSCAN_SOL_QUOTE_MINT: Pubkey =
pubkey!("So11111111111111111111111111111111111111111");
#[inline]
fn fill_pubkey(to: &mut Pubkey, from: Pubkey) {
@@ -8,6 +11,25 @@ fn fill_pubkey(to: &mut Pubkey, from: Pubkey) {
}
}
#[inline]
fn normalize_pumpfun_quote_mint(quote_mint: Pubkey) -> Pubkey {
if quote_mint == Pubkey::default() {
PUMPFUN_SOLSCAN_SOL_QUOTE_MINT
} else {
quote_mint
}
}
#[inline]
fn fill_pumpfun_quote_mint(to: &mut Pubkey, from: Pubkey) {
let from = normalize_pumpfun_quote_mint(from);
if (*to == Pubkey::default() || *to == PUMPFUN_SOLSCAN_SOL_QUOTE_MINT)
&& from != Pubkey::default()
{
*to = from;
}
}
#[inline]
fn fill_u64(to: &mut u64, from: u64) {
if *to == 0 && from != 0 {
@@ -66,7 +88,7 @@ pub fn merge(instruction_event: &mut DexEvent, cpi_log_event: DexEvent) {
if e.shareholders.is_empty() && !cpie.shareholders.is_empty() {
e.shareholders = cpie.shareholders;
}
fill_pubkey(&mut e.quote_mint, cpie.quote_mint);
fill_pumpfun_quote_mint(&mut e.quote_mint, cpie.quote_mint);
fill_u64(&mut e.quote_amount, cpie.quote_amount);
fill_u64(&mut e.virtual_quote_reserves, cpie.virtual_quote_reserves);
fill_u64(&mut e.real_quote_reserves, cpie.real_quote_reserves);
@@ -155,7 +177,7 @@ pub fn merge(instruction_event: &mut DexEvent, cpi_log_event: DexEvent) {
if cpie.token_program != solana_sdk::pubkey::Pubkey::default() {
e.token_program = cpie.token_program;
}
fill_pubkey(&mut e.quote_mint, cpie.quote_mint);
fill_pumpfun_quote_mint(&mut e.quote_mint, cpie.quote_mint);
fill_u64(&mut e.virtual_quote_reserves, cpie.virtual_quote_reserves);
e.is_mayhem_mode |= cpie.is_mayhem_mode;
e.is_cashback_enabled |= cpie.is_cashback_enabled;
@@ -177,7 +199,7 @@ pub fn merge(instruction_event: &mut DexEvent, cpi_log_event: DexEvent) {
fill_u64(&mut e.real_token_reserves, cpie.real_token_reserves);
fill_u64(&mut e.token_total_supply, cpie.token_total_supply);
fill_pubkey(&mut e.token_program, cpie.token_program);
fill_pubkey(&mut e.quote_mint, cpie.quote_mint);
fill_pumpfun_quote_mint(&mut e.quote_mint, cpie.quote_mint);
fill_u64(&mut e.virtual_quote_reserves, cpie.virtual_quote_reserves);
e.is_mayhem_mode |= cpie.is_mayhem_mode;
e.is_cashback_enabled |= cpie.is_cashback_enabled;
@@ -216,7 +238,7 @@ pub fn merge(instruction_event: &mut DexEvent, cpi_log_event: DexEvent) {
if cpie.token_program != solana_sdk::pubkey::Pubkey::default() {
e.token_program = cpie.token_program;
}
fill_pubkey(&mut e.quote_mint, cpie.quote_mint);
fill_pumpfun_quote_mint(&mut e.quote_mint, cpie.quote_mint);
fill_u64(&mut e.virtual_quote_reserves, cpie.virtual_quote_reserves);
e.is_mayhem_mode |= cpie.is_mayhem_mode;
e.is_cashback_enabled |= cpie.is_cashback_enabled;
@@ -883,4 +905,22 @@ mod tests {
_ => panic!("expected PumpFunTradeEvent"),
}
}
#[test]
fn pumpfun_merge_replaces_sol_quote_sentinel_with_real_quote_mint() {
let quote_mint = Pubkey::new_unique();
let mut instruction_event = DexEvent::PumpFunTradeEvent(PumpFunTradeEvent {
quote_mint: PUMPFUN_SOLSCAN_SOL_QUOTE_MINT,
..Default::default()
});
let cpi_log_event =
DexEvent::PumpFunTradeEvent(PumpFunTradeEvent { quote_mint, ..Default::default() });
merge(&mut instruction_event, cpi_log_event);
match instruction_event {
DexEvent::PumpFunTradeEvent(t) => assert_eq!(t.quote_mint, quote_mint),
_ => panic!("expected PumpFunTradeEvent"),
}
}
}