mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-15 01:48:05 +00:00
Use sol-parser-sdk 0.4.17
This commit is contained in:
@@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,23 @@ use crate::streaming::event_parser::protocols::pumpswap::events::{
|
||||
};
|
||||
use crate::streaming::event_parser::DexEvent;
|
||||
use prost_types::Timestamp;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::{pubkey, pubkey::Pubkey};
|
||||
|
||||
use super::adapt::adapt_pm;
|
||||
use super::program_ids::{pump_program, pumpswap_program};
|
||||
|
||||
const PUMPFUN_SOLSCAN_SOL_QUOTE_MINT: Pubkey =
|
||||
pubkey!("So11111111111111111111111111111111111111111");
|
||||
|
||||
#[inline]
|
||||
fn normalize_pumpfun_quote_mint(quote_mint: Pubkey) -> Pubkey {
|
||||
if quote_mint == Pubkey::default() {
|
||||
PUMPFUN_SOLSCAN_SOL_QUOTE_MINT
|
||||
} else {
|
||||
quote_mint
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn pumpfun_create_token_from_parser(
|
||||
c: sol_parser_sdk::core::events::PumpFunCreateTokenEvent,
|
||||
meta: EventMetadata,
|
||||
@@ -47,7 +59,7 @@ pub(crate) fn pumpfun_create_token_from_parser(
|
||||
token_program: c.token_program,
|
||||
is_mayhem_mode: c.is_mayhem_mode,
|
||||
is_cashback_enabled: c.is_cashback_enabled,
|
||||
quote_mint: c.quote_mint,
|
||||
quote_mint: normalize_pumpfun_quote_mint(c.quote_mint),
|
||||
virtual_quote_reserves: c.virtual_quote_reserves,
|
||||
..Default::default()
|
||||
}
|
||||
@@ -74,7 +86,7 @@ pub(crate) fn pumpfun_create_v2_from_parser(
|
||||
token_program: c.token_program,
|
||||
is_mayhem_mode: c.is_mayhem_mode,
|
||||
is_cashback_enabled: c.is_cashback_enabled,
|
||||
quote_mint: c.quote_mint,
|
||||
quote_mint: normalize_pumpfun_quote_mint(c.quote_mint),
|
||||
virtual_quote_reserves: c.virtual_quote_reserves,
|
||||
mint_authority: c.mint_authority,
|
||||
associated_bonding_curve: c.associated_bonding_curve,
|
||||
@@ -365,7 +377,7 @@ pub(crate) fn pumpfun_bonding_curve_account_from_parser(
|
||||
creator: e.bonding_curve.creator,
|
||||
is_mayhem_mode: e.bonding_curve.is_mayhem_mode,
|
||||
is_cashback_coin: e.bonding_curve.is_cashback_coin,
|
||||
quote_mint: e.bonding_curve.quote_mint,
|
||||
quote_mint: normalize_pumpfun_quote_mint(e.bonding_curve.quote_mint),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -735,7 +747,7 @@ pub(crate) fn pumpfun_trade_from_parser_with_event_type(
|
||||
buyback_fee_basis_points: t.buyback_fee_basis_points,
|
||||
buyback_fee: t.buyback_fee,
|
||||
shareholders: t.shareholders.into_iter().map(pump_fees_shareholder_from_parser).collect(),
|
||||
quote_mint: t.quote_mint,
|
||||
quote_mint: normalize_pumpfun_quote_mint(t.quote_mint),
|
||||
quote_amount: t.quote_amount,
|
||||
virtual_quote_reserves: t.virtual_quote_reserves,
|
||||
real_quote_reserves: t.real_quote_reserves,
|
||||
@@ -840,3 +852,25 @@ pub(crate) fn pumpswap_trade_from_parser(
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn pumpfun_default_quote_mint_uses_solscan_sol_sentinel() {
|
||||
let ev = pumpfun_trade_from_parser_with_event_type(
|
||||
sol_parser_sdk::core::events::PumpFunTradeEvent { is_buy: true, ..Default::default() },
|
||||
None,
|
||||
0,
|
||||
EventType::PumpFunBuy,
|
||||
);
|
||||
|
||||
match ev {
|
||||
DexEvent::PumpFunTradeEvent(t) => {
|
||||
assert_eq!(t.quote_mint.to_string(), "So11111111111111111111111111111111111111111");
|
||||
}
|
||||
_ => panic!("expected PumpFunTradeEvent"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user