Skip to main content

sol_parser_sdk/grpc/
program_ids.rs

1use crate::grpc::types::Protocol;
2use once_cell::sync::Lazy;
3use solana_sdk::pubkey;
4use solana_sdk::pubkey::Pubkey;
5use std::collections::HashMap;
6
7// Program IDs for supported DEX protocols (string format)
8pub const PUMPFUN_PROGRAM_ID: &str = "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P";
9pub const PUMPSWAP_PROGRAM_ID: &str = "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA";
10pub const PUMPSWAP_FEES_PROGRAM_ID: &str = "pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ";
11pub const RAYDIUM_LAUNCHLAB_PROGRAM_ID: &str = "LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj";
12pub const RAYDIUM_CPMM_PROGRAM_ID: &str = "CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C";
13pub const RAYDIUM_CLMM_PROGRAM_ID: &str = "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK";
14pub const RAYDIUM_AMM_V4_PROGRAM_ID: &str = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8";
15pub const ORCA_WHIRLPOOL_PROGRAM_ID: &str = "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc";
16pub const METEORA_POOLS_PROGRAM_ID: &str = "Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB";
17pub const METEORA_DAMM_V2_PROGRAM_ID: &str = "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
18pub const METEORA_DLMM_PROGRAM_ID: &str = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo";
19pub const METEORA_DBC_PROGRAM_ID: &str = "dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN";
20
21// Program IDs (Pubkey format for matching)
22pub const PUMPFUN_PROGRAM: Pubkey = pubkey!("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P");
23pub const PUMPSWAP_PROGRAM: Pubkey = pubkey!("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA");
24pub const PUMPSWAP_FEES_PROGRAM: Pubkey = pubkey!("pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ");
25pub const RAYDIUM_LAUNCHLAB_PROGRAM: Pubkey =
26    pubkey!("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj");
27pub const RAYDIUM_CPMM_PROGRAM: Pubkey = pubkey!("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C");
28pub const RAYDIUM_CLMM_PROGRAM: Pubkey = pubkey!("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK");
29pub const RAYDIUM_AMM_V4_PROGRAM: Pubkey = pubkey!("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8");
30pub const ORCA_WHIRLPOOL_PROGRAM: Pubkey = pubkey!("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc");
31pub const METEORA_POOLS_PROGRAM: Pubkey = pubkey!("Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB");
32pub const METEORA_DAMM_V2_PROGRAM: Pubkey = pubkey!("cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG");
33pub const METEORA_DLMM_PROGRAM: Pubkey = pubkey!("LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo");
34pub const METEORA_DBC_PROGRAM: Pubkey = pubkey!("dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN");
35
36/// Avoid base58 decoding for program ids emitted by the DEXes this crate parses.
37#[inline(always)]
38pub(crate) fn known_program_id(program_id: &str) -> Option<Pubkey> {
39    match program_id {
40        PUMPFUN_PROGRAM_ID => Some(PUMPFUN_PROGRAM),
41        PUMPSWAP_PROGRAM_ID => Some(PUMPSWAP_PROGRAM),
42        PUMPSWAP_FEES_PROGRAM_ID => Some(PUMPSWAP_FEES_PROGRAM),
43        RAYDIUM_LAUNCHLAB_PROGRAM_ID => Some(RAYDIUM_LAUNCHLAB_PROGRAM),
44        RAYDIUM_CPMM_PROGRAM_ID => Some(RAYDIUM_CPMM_PROGRAM),
45        RAYDIUM_CLMM_PROGRAM_ID => Some(RAYDIUM_CLMM_PROGRAM),
46        RAYDIUM_AMM_V4_PROGRAM_ID => Some(RAYDIUM_AMM_V4_PROGRAM),
47        ORCA_WHIRLPOOL_PROGRAM_ID => Some(ORCA_WHIRLPOOL_PROGRAM),
48        METEORA_POOLS_PROGRAM_ID => Some(METEORA_POOLS_PROGRAM),
49        METEORA_DAMM_V2_PROGRAM_ID => Some(METEORA_DAMM_V2_PROGRAM),
50        METEORA_DLMM_PROGRAM_ID => Some(METEORA_DLMM_PROGRAM),
51        METEORA_DBC_PROGRAM_ID => Some(METEORA_DBC_PROGRAM),
52        _ => None,
53    }
54}
55
56/// Programs whose instruction positions are queried later by account/data fillers.
57#[inline(always)]
58pub(crate) fn needs_invoke_context(program_id: &Pubkey) -> bool {
59    matches!(
60        *program_id,
61        PUMPFUN_PROGRAM
62            | PUMPSWAP_PROGRAM
63            | PUMPSWAP_FEES_PROGRAM
64            | RAYDIUM_LAUNCHLAB_PROGRAM
65            | RAYDIUM_CPMM_PROGRAM
66            | RAYDIUM_CLMM_PROGRAM
67            | RAYDIUM_AMM_V4_PROGRAM
68            | ORCA_WHIRLPOOL_PROGRAM
69            | METEORA_POOLS_PROGRAM
70            | METEORA_DAMM_V2_PROGRAM
71            | METEORA_DLMM_PROGRAM
72    )
73}
74
75pub static PROTOCOL_PROGRAM_IDS: Lazy<HashMap<Protocol, Vec<&'static str>>> = Lazy::new(|| {
76    let mut map = HashMap::new();
77    map.insert(Protocol::PumpFun, vec![PUMPFUN_PROGRAM_ID]);
78    map.insert(Protocol::PumpSwap, vec![PUMPSWAP_PROGRAM_ID]);
79    map.insert(Protocol::PumpFees, vec![PUMPSWAP_FEES_PROGRAM_ID]);
80    map.insert(Protocol::RaydiumLaunchlab, vec![RAYDIUM_LAUNCHLAB_PROGRAM_ID]);
81    map.insert(Protocol::RaydiumCpmm, vec![RAYDIUM_CPMM_PROGRAM_ID]);
82    map.insert(Protocol::RaydiumClmm, vec![RAYDIUM_CLMM_PROGRAM_ID]);
83    map.insert(Protocol::RaydiumAmmV4, vec![RAYDIUM_AMM_V4_PROGRAM_ID]);
84    map.insert(Protocol::OrcaWhirlpool, vec![ORCA_WHIRLPOOL_PROGRAM_ID]);
85    map.insert(Protocol::MeteoraPools, vec![METEORA_POOLS_PROGRAM_ID]);
86    map.insert(Protocol::MeteoraDammV2, vec![METEORA_DAMM_V2_PROGRAM_ID]);
87    map.insert(Protocol::MeteoraDlmm, vec![METEORA_DLMM_PROGRAM_ID]);
88    map.insert(Protocol::MeteoraDbc, vec![METEORA_DBC_PROGRAM_ID]);
89    map
90});
91
92pub fn get_program_ids_for_protocols(protocols: &[Protocol]) -> Vec<String> {
93    let mut program_ids = Vec::new();
94    for protocol in protocols {
95        if let Some(ids) = PROTOCOL_PROGRAM_IDS.get(protocol) {
96            for id in ids {
97                program_ids.push(id.to_string());
98            }
99        }
100    }
101    program_ids.sort();
102    program_ids.dedup();
103    program_ids
104}
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109    use crate::instr;
110
111    #[test]
112    fn grpc_program_ids_match_instruction_program_ids() {
113        assert_eq!(PUMPFUN_PROGRAM, instr::program_ids::PUMPFUN_PROGRAM_ID);
114        assert_eq!(PUMPSWAP_PROGRAM, instr::program_ids::PUMPSWAP_PROGRAM_ID);
115        assert_eq!(PUMPSWAP_FEES_PROGRAM, instr::program_ids::PUMP_FEES_PROGRAM_ID);
116        assert_eq!(RAYDIUM_LAUNCHLAB_PROGRAM, instr::program_ids::RAYDIUM_LAUNCHLAB_PROGRAM_ID);
117        assert_eq!(RAYDIUM_CPMM_PROGRAM, instr::program_ids::RAYDIUM_CPMM_PROGRAM_ID);
118        assert_eq!(RAYDIUM_CLMM_PROGRAM, instr::program_ids::RAYDIUM_CLMM_PROGRAM_ID);
119        assert_eq!(RAYDIUM_AMM_V4_PROGRAM, instr::program_ids::RAYDIUM_AMM_V4_PROGRAM_ID);
120        assert_eq!(ORCA_WHIRLPOOL_PROGRAM, instr::program_ids::ORCA_WHIRLPOOL_PROGRAM_ID);
121        assert_eq!(METEORA_POOLS_PROGRAM, instr::program_ids::METEORA_POOLS_PROGRAM_ID);
122        assert_eq!(METEORA_DAMM_V2_PROGRAM, instr::program_ids::METEORA_DAMM_V2_PROGRAM_ID);
123        assert_eq!(METEORA_DLMM_PROGRAM, instr::program_ids::METEORA_DLMM_PROGRAM_ID);
124        assert_eq!(METEORA_DBC_PROGRAM, instr::program_ids::METEORA_DBC_PROGRAM_ID);
125    }
126
127    #[test]
128    fn protocol_filter_maps_all_supported_protocols() {
129        let protocols = [
130            Protocol::PumpFun,
131            Protocol::PumpSwap,
132            Protocol::PumpFees,
133            Protocol::RaydiumLaunchlab,
134            Protocol::RaydiumCpmm,
135            Protocol::RaydiumClmm,
136            Protocol::RaydiumAmmV4,
137            Protocol::OrcaWhirlpool,
138            Protocol::MeteoraPools,
139            Protocol::MeteoraDammV2,
140            Protocol::MeteoraDlmm,
141            Protocol::MeteoraDbc,
142        ];
143        for protocol in protocols {
144            assert!(
145                PROTOCOL_PROGRAM_IDS.contains_key(&protocol),
146                "missing program id mapping for {protocol:?}"
147            );
148        }
149    }
150
151    #[test]
152    fn invoke_context_only_tracks_programs_used_by_fillers() {
153        for program_id in [
154            PUMPFUN_PROGRAM,
155            PUMPSWAP_PROGRAM,
156            PUMPSWAP_FEES_PROGRAM,
157            RAYDIUM_LAUNCHLAB_PROGRAM,
158            RAYDIUM_CPMM_PROGRAM,
159            RAYDIUM_CLMM_PROGRAM,
160            RAYDIUM_AMM_V4_PROGRAM,
161            ORCA_WHIRLPOOL_PROGRAM,
162            METEORA_POOLS_PROGRAM,
163            METEORA_DAMM_V2_PROGRAM,
164            METEORA_DLMM_PROGRAM,
165        ] {
166            assert!(needs_invoke_context(&program_id));
167        }
168        assert!(!needs_invoke_context(&Pubkey::new_unique()));
169    }
170
171    #[test]
172    fn known_log_program_ids_map_without_decoding() {
173        for (encoded, expected) in [
174            (PUMPFUN_PROGRAM_ID, PUMPFUN_PROGRAM),
175            (PUMPSWAP_PROGRAM_ID, PUMPSWAP_PROGRAM),
176            (PUMPSWAP_FEES_PROGRAM_ID, PUMPSWAP_FEES_PROGRAM),
177            (RAYDIUM_LAUNCHLAB_PROGRAM_ID, RAYDIUM_LAUNCHLAB_PROGRAM),
178            (RAYDIUM_CPMM_PROGRAM_ID, RAYDIUM_CPMM_PROGRAM),
179            (RAYDIUM_CLMM_PROGRAM_ID, RAYDIUM_CLMM_PROGRAM),
180            (RAYDIUM_AMM_V4_PROGRAM_ID, RAYDIUM_AMM_V4_PROGRAM),
181            (ORCA_WHIRLPOOL_PROGRAM_ID, ORCA_WHIRLPOOL_PROGRAM),
182            (METEORA_POOLS_PROGRAM_ID, METEORA_POOLS_PROGRAM),
183            (METEORA_DAMM_V2_PROGRAM_ID, METEORA_DAMM_V2_PROGRAM),
184            (METEORA_DLMM_PROGRAM_ID, METEORA_DLMM_PROGRAM),
185            (METEORA_DBC_PROGRAM_ID, METEORA_DBC_PROGRAM),
186        ] {
187            assert_eq!(known_program_id(encoded), Some(expected));
188        }
189        assert_eq!(known_program_id("11111111111111111111111111111111"), None);
190    }
191}