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    for protocol in [Protocol::LaunchLab, Protocol::StonkFun, Protocol::RaydiumLaunchlab] {
81        map.insert(protocol, vec![RAYDIUM_LAUNCHLAB_PROGRAM_ID]);
82    }
83    map.insert(Protocol::RaydiumCpmm, vec![RAYDIUM_CPMM_PROGRAM_ID]);
84    map.insert(Protocol::RaydiumClmm, vec![RAYDIUM_CLMM_PROGRAM_ID]);
85    map.insert(Protocol::RaydiumAmmV4, vec![RAYDIUM_AMM_V4_PROGRAM_ID]);
86    map.insert(Protocol::OrcaWhirlpool, vec![ORCA_WHIRLPOOL_PROGRAM_ID]);
87    map.insert(Protocol::MeteoraPools, vec![METEORA_POOLS_PROGRAM_ID]);
88    map.insert(Protocol::MeteoraDammV2, vec![METEORA_DAMM_V2_PROGRAM_ID]);
89    map.insert(Protocol::MeteoraDlmm, vec![METEORA_DLMM_PROGRAM_ID]);
90    map.insert(Protocol::MeteoraDbc, vec![METEORA_DBC_PROGRAM_ID]);
91    map
92});
93
94pub fn get_program_ids_for_protocols(protocols: &[Protocol]) -> Vec<String> {
95    let mut program_ids = Vec::new();
96    for protocol in protocols {
97        if let Some(ids) = PROTOCOL_PROGRAM_IDS.get(protocol) {
98            for id in ids {
99                program_ids.push(id.to_string());
100            }
101        }
102    }
103    program_ids.sort();
104    program_ids.dedup();
105    program_ids
106}
107
108#[cfg(test)]
109mod tests {
110    use super::*;
111    use crate::instr;
112
113    #[test]
114    fn grpc_program_ids_match_instruction_program_ids() {
115        assert_eq!(PUMPFUN_PROGRAM, instr::program_ids::PUMPFUN_PROGRAM_ID);
116        assert_eq!(PUMPSWAP_PROGRAM, instr::program_ids::PUMPSWAP_PROGRAM_ID);
117        assert_eq!(PUMPSWAP_FEES_PROGRAM, instr::program_ids::PUMP_FEES_PROGRAM_ID);
118        assert_eq!(RAYDIUM_LAUNCHLAB_PROGRAM, instr::program_ids::RAYDIUM_LAUNCHLAB_PROGRAM_ID);
119        assert_eq!(RAYDIUM_CPMM_PROGRAM, instr::program_ids::RAYDIUM_CPMM_PROGRAM_ID);
120        assert_eq!(RAYDIUM_CLMM_PROGRAM, instr::program_ids::RAYDIUM_CLMM_PROGRAM_ID);
121        assert_eq!(RAYDIUM_AMM_V4_PROGRAM, instr::program_ids::RAYDIUM_AMM_V4_PROGRAM_ID);
122        assert_eq!(ORCA_WHIRLPOOL_PROGRAM, instr::program_ids::ORCA_WHIRLPOOL_PROGRAM_ID);
123        assert_eq!(METEORA_POOLS_PROGRAM, instr::program_ids::METEORA_POOLS_PROGRAM_ID);
124        assert_eq!(METEORA_DAMM_V2_PROGRAM, instr::program_ids::METEORA_DAMM_V2_PROGRAM_ID);
125        assert_eq!(METEORA_DLMM_PROGRAM, instr::program_ids::METEORA_DLMM_PROGRAM_ID);
126        assert_eq!(METEORA_DBC_PROGRAM, instr::program_ids::METEORA_DBC_PROGRAM_ID);
127    }
128
129    #[test]
130    fn protocol_filter_maps_all_supported_protocols() {
131        let protocols = [
132            Protocol::PumpFun,
133            Protocol::PumpSwap,
134            Protocol::PumpFees,
135            Protocol::RaydiumLaunchlab,
136            Protocol::RaydiumCpmm,
137            Protocol::RaydiumClmm,
138            Protocol::RaydiumAmmV4,
139            Protocol::OrcaWhirlpool,
140            Protocol::MeteoraPools,
141            Protocol::MeteoraDammV2,
142            Protocol::MeteoraDlmm,
143            Protocol::MeteoraDbc,
144        ];
145        for protocol in protocols {
146            assert!(
147                PROTOCOL_PROGRAM_IDS.contains_key(&protocol),
148                "missing program id mapping for {protocol:?}"
149            );
150        }
151    }
152
153    #[test]
154    fn invoke_context_only_tracks_programs_used_by_fillers() {
155        for program_id in [
156            PUMPFUN_PROGRAM,
157            PUMPSWAP_PROGRAM,
158            PUMPSWAP_FEES_PROGRAM,
159            RAYDIUM_LAUNCHLAB_PROGRAM,
160            RAYDIUM_CPMM_PROGRAM,
161            RAYDIUM_CLMM_PROGRAM,
162            RAYDIUM_AMM_V4_PROGRAM,
163            ORCA_WHIRLPOOL_PROGRAM,
164            METEORA_POOLS_PROGRAM,
165            METEORA_DAMM_V2_PROGRAM,
166            METEORA_DLMM_PROGRAM,
167        ] {
168            assert!(needs_invoke_context(&program_id));
169        }
170        assert!(!needs_invoke_context(&Pubkey::new_unique()));
171    }
172
173    #[test]
174    fn known_log_program_ids_map_without_decoding() {
175        for (encoded, expected) in [
176            (PUMPFUN_PROGRAM_ID, PUMPFUN_PROGRAM),
177            (PUMPSWAP_PROGRAM_ID, PUMPSWAP_PROGRAM),
178            (PUMPSWAP_FEES_PROGRAM_ID, PUMPSWAP_FEES_PROGRAM),
179            (RAYDIUM_LAUNCHLAB_PROGRAM_ID, RAYDIUM_LAUNCHLAB_PROGRAM),
180            (RAYDIUM_CPMM_PROGRAM_ID, RAYDIUM_CPMM_PROGRAM),
181            (RAYDIUM_CLMM_PROGRAM_ID, RAYDIUM_CLMM_PROGRAM),
182            (RAYDIUM_AMM_V4_PROGRAM_ID, RAYDIUM_AMM_V4_PROGRAM),
183            (ORCA_WHIRLPOOL_PROGRAM_ID, ORCA_WHIRLPOOL_PROGRAM),
184            (METEORA_POOLS_PROGRAM_ID, METEORA_POOLS_PROGRAM),
185            (METEORA_DAMM_V2_PROGRAM_ID, METEORA_DAMM_V2_PROGRAM),
186            (METEORA_DLMM_PROGRAM_ID, METEORA_DLMM_PROGRAM),
187            (METEORA_DBC_PROGRAM_ID, METEORA_DBC_PROGRAM),
188        ] {
189            assert_eq!(known_program_id(encoded), Some(expected));
190        }
191        assert_eq!(known_program_id("11111111111111111111111111111111"), None);
192    }
193}