solana_central/utilities/
process_get_program_accounts_pool.rs

1use crate::CentralContext;
2use crate::constants::{METEORA_CONSTANTS, POOLS_ACCOUNT_SIZES, PUMP_CONSTANTS, RAYDIUM_CONSTANTS};
3use crate::types::meteora_amm_pool::MeteoraAmmPool;
4use crate::types::meteora_dammv2_pool::MeteoraDammV2Pool;
5use crate::types::pool::PoolTrait;
6use crate::types::pumpswap_pool::PumpswapPool;
7use crate::types::raydium_ammv4_pool::RaydiumAmmV4Pool;
8use crate::types::raydium_cpmm_pool::RaydiumCpmmPool;
9use solana_sdk::account::Account;
10use solana_sdk::pubkey::Pubkey;
11use std::sync::{Arc, RwLock};
12
13/// Process raw account data from getProgramAccounts into pool instances. Identifies pools by their
14/// program owner and account size, then parses them into the appropriate pool type (Meteora,
15/// Raydium, Pumpswap, etc.). Designed to be called from multiple threads with different slice
16/// ranges.
17pub fn process_get_program_accounts_pool(
18  raw_accounts: Arc<Vec<(Pubkey, Account)>>,
19  central_context: Arc<CentralContext>,
20  start: usize,
21  end: usize,
22) -> Vec<Arc<RwLock<dyn PoolTrait>>> {
23  let raw_accounts = &raw_accounts.as_ref()[start..end];
24  let mut results: Vec<Arc<RwLock<dyn PoolTrait>>> = Vec::new();
25  for (pubkey, account) in raw_accounts {
26    if account.owner == PUMP_CONSTANTS.pump_swap_program
27      && account.data.len() == POOLS_ACCOUNT_SIZES.pump_swap
28    {
29      results.push(Arc::from(RwLock::from(PumpswapPool::from_account_info(
30        pubkey.clone(),
31        &account.data,
32      ))));
33    } else if account.owner == METEORA_CONSTANTS.amm_program
34      && account.data.len() == POOLS_ACCOUNT_SIZES.meteora_amm
35    {
36      results.push(Arc::from(RwLock::from(MeteoraAmmPool::from_account_info(
37        pubkey.clone(),
38        &account.data,
39        central_context.clone(),
40      ))));
41    } else if account.owner == METEORA_CONSTANTS.dammv2_program
42      && account.data.len() == POOLS_ACCOUNT_SIZES.meteora_dammv2
43    {
44      results.push(Arc::from(RwLock::from(
45        MeteoraDammV2Pool::from_account_info(pubkey.clone(), &account.data),
46      )));
47    } else if account.owner == RAYDIUM_CONSTANTS.amm_program
48      && account.data.len() == POOLS_ACCOUNT_SIZES.raydium_ammv4
49    {
50      results.push(Arc::from(RwLock::from(
51        RaydiumAmmV4Pool::from_account_info(pubkey.clone(), &account.data),
52      )));
53    } else if account.owner == RAYDIUM_CONSTANTS.cpmm_program
54      && account.data.len() == POOLS_ACCOUNT_SIZES.raydium_cpmm
55    {
56      results.push(Arc::from(RwLock::from(RaydiumCpmmPool::from_account_info(
57        pubkey.clone(),
58        &account.data,
59      ))));
60    }
61  }
62  results
63}