sol_parser_sdk/core/
common_filler.rs1use 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) = program_invokes
14 .get(&crate::grpc::program_ids::PUMPSWAP_FEES_PROGRAM)
15 .and_then(|v| v.last())
16 {
17 if let Some(data) = get_instruction_data(meta, transaction, invoke) {
18 *is_pump_pool = read_bool(data, 9).unwrap_or_default();
19 }
20 }
21}
22
23#[inline]
24pub fn fill_data(
25 event: &mut DexEvent,
26 meta: &TransactionStatusMeta,
27 transaction: &Option<Transaction>,
28 program_invokes: &HashMap<Pubkey, Vec<(i32, i32)>>,
29) {
30 match event {
31 DexEvent::PumpSwapBuy(ref mut e) => {
32 set_pumpswap_is_pump_pool_from_fees_ix(meta, transaction, program_invokes, &mut e.is_pump_pool);
33 }
34 DexEvent::PumpSwapSell(ref mut e) => {
35 set_pumpswap_is_pump_pool_from_fees_ix(meta, transaction, program_invokes, &mut e.is_pump_pool);
36 }
37 _ => {}
38 }
39}
40
41pub fn get_instruction_data<'a>(
42 meta: &'a TransactionStatusMeta,
43 transaction: &'a Option<Transaction>,
44 index: &(i32, i32), ) -> Option<&'a [u8]> {
46 let data = if index.1 >= 0 {
47 meta.inner_instructions
48 .iter()
49 .find(|i| i.index == index.0 as u32)?
50 .instructions
51 .get(index.1 as usize)?
52 .data
53 .as_slice()
54 } else {
55 transaction.as_ref()?.message.as_ref()?.instructions.get(index.0 as usize)?.data.as_slice()
56 };
57 return Some(data);
58}