Skip to main content

sol_parser_sdk/core/
common_filler.rs

1use crate::{core::events::*, instr::read_bool};
2use solana_sdk::pubkey::Pubkey;
3use std::collections::HashMap;
4use yellowstone_grpc_proto::prelude::{Transaction, TransactionStatusMeta};
5
6#[inline]
7fn set_pumpswap_is_pump_pool_from_fees_ix(
8    meta: &TransactionStatusMeta,
9    transaction: &Option<Transaction>,
10    program_invokes: &HashMap<Pubkey, Vec<(i32, i32)>>,
11    is_pump_pool: &mut bool,
12) {
13    if let Some(invoke) =
14        program_invokes.get(&crate::grpc::program_ids::PUMPSWAP_FEES_PROGRAM).and_then(|v| v.last())
15    {
16        if let Some(data) = get_instruction_data(meta, transaction, invoke) {
17            *is_pump_pool = read_bool(data, 9).unwrap_or_default();
18        }
19    }
20}
21
22#[inline]
23pub fn fill_data(
24    event: &mut DexEvent,
25    meta: &TransactionStatusMeta,
26    transaction: &Option<Transaction>,
27    program_invokes: &HashMap<Pubkey, Vec<(i32, i32)>>,
28) {
29    match event {
30        DexEvent::PumpSwapBuy(ref mut e) => {
31            set_pumpswap_is_pump_pool_from_fees_ix(
32                meta,
33                transaction,
34                program_invokes,
35                &mut e.is_pump_pool,
36            );
37        }
38        DexEvent::PumpSwapSell(ref mut e) => {
39            set_pumpswap_is_pump_pool_from_fees_ix(
40                meta,
41                transaction,
42                program_invokes,
43                &mut e.is_pump_pool,
44            );
45        }
46        _ => {}
47    }
48}
49
50pub fn get_instruction_data<'a>(
51    meta: &'a TransactionStatusMeta,
52    transaction: &'a Option<Transaction>,
53    index: &(i32, i32), // (outer_index, inner_index)
54) -> Option<&'a [u8]> {
55    let data = if index.1 >= 0 {
56        meta.inner_instructions
57            .iter()
58            .find(|i| i.index == index.0 as u32)?
59            .instructions
60            .get(index.1 as usize)?
61            .data
62            .as_slice()
63    } else {
64        transaction.as_ref()?.message.as_ref()?.instructions.get(index.0 as usize)?.data.as_slice()
65    };
66    return Some(data);
67}