Skip to main content

pump_rust_client/
pda.rs

1//! PDA derivations for `pump` and `pump_amm`. Each returns `(Pubkey, bump)`.
2
3use solana_program::pubkey::Pubkey;
4
5use crate::constants;
6
7/// SPL associated token account PDA.
8pub fn associated_token(owner: &Pubkey, token_program: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) {
9    Pubkey::find_program_address(
10        &[owner.as_ref(), token_program.as_ref(), mint.as_ref()],
11        &constants::SPL_ATA_PROGRAM_ID,
12    )
13}
14
15pub mod pump {
16    use super::*;
17    use crate::constants::pump::*;
18
19    pub fn global() -> (Pubkey, u8) {
20        Pubkey::find_program_address(&[GLOBAL_SEED], &PROGRAM_ID)
21    }
22
23    pub fn bonding_curve(mint: &Pubkey) -> (Pubkey, u8) {
24        Pubkey::find_program_address(&[BONDING_CURVE_SEED, mint.as_ref()], &PROGRAM_ID)
25    }
26
27    /// Remaining account on `buy` / `sell`.
28    pub fn bonding_curve_v2(mint: &Pubkey) -> (Pubkey, u8) {
29        Pubkey::find_program_address(&[BONDING_CURVE_V2_SEED, mint.as_ref()], &PROGRAM_ID)
30    }
31
32    pub fn creator_vault(creator: &Pubkey) -> (Pubkey, u8) {
33        Pubkey::find_program_address(&[CREATOR_VAULT_SEED, creator.as_ref()], &PROGRAM_ID)
34    }
35
36    pub fn event_authority() -> (Pubkey, u8) {
37        Pubkey::find_program_address(&[EVENT_AUTHORITY_SEED], &PROGRAM_ID)
38    }
39
40    pub fn mint_authority() -> (Pubkey, u8) {
41        Pubkey::find_program_address(&[MINT_AUTHORITY_SEED], &PROGRAM_ID)
42    }
43
44    pub fn pool_authority(mint: &Pubkey) -> (Pubkey, u8) {
45        Pubkey::find_program_address(&[POOL_AUTHORITY_SEED, mint.as_ref()], &PROGRAM_ID)
46    }
47
48    pub fn global_volume_accumulator() -> (Pubkey, u8) {
49        Pubkey::find_program_address(&[GLOBAL_VOLUME_ACCUMULATOR_SEED], &PROGRAM_ID)
50    }
51
52    pub fn user_volume_accumulator(user: &Pubkey) -> (Pubkey, u8) {
53        Pubkey::find_program_address(&[USER_VOLUME_ACCUMULATOR_SEED, user.as_ref()], &PROGRAM_ID)
54    }
55
56    pub fn fee_config() -> (Pubkey, u8) {
57        Pubkey::find_program_address(
58            &[FEE_CONFIG_SEED, FEE_CONFIG_PROGRAM_SEED_KEY.as_ref()],
59            &constants::FEE_PROGRAM_ID,
60        )
61    }
62
63    pub fn metadata(mint: &Pubkey) -> (Pubkey, u8) {
64        Pubkey::find_program_address(
65            &[
66                METADATA_SEED,
67                constants::MPL_TOKEN_METADATA_PROGRAM_ID.as_ref(),
68                mint.as_ref(),
69            ],
70            &constants::MPL_TOKEN_METADATA_PROGRAM_ID,
71        )
72    }
73
74    /// Per-mint fee-sharing config (`pump_fees`); may be uninitialized.
75    pub fn sharing_config(mint: &Pubkey) -> (Pubkey, u8) {
76        Pubkey::find_program_address(
77            &[SHARING_CONFIG_SEED, mint.as_ref()],
78            &constants::FEE_PROGRAM_ID,
79        )
80    }
81}
82
83pub mod mayhem {
84    //! Mayhem program PDAs referenced by `create_v2`.
85    use super::*;
86
87    pub const PROGRAM_ID: Pubkey = constants::MAYHEM_PROGRAM_ID;
88
89    pub const GLOBAL_PARAMS_SEED: &[u8] = b"global-params";
90    pub const SOL_VAULT_SEED: &[u8] = b"sol-vault";
91    pub const MAYHEM_STATE_SEED: &[u8] = b"mayhem-state";
92
93    pub fn global_params() -> (Pubkey, u8) {
94        Pubkey::find_program_address(&[GLOBAL_PARAMS_SEED], &PROGRAM_ID)
95    }
96
97    pub fn sol_vault() -> (Pubkey, u8) {
98        Pubkey::find_program_address(&[SOL_VAULT_SEED], &PROGRAM_ID)
99    }
100
101    pub fn mayhem_state(mint: &Pubkey) -> (Pubkey, u8) {
102        Pubkey::find_program_address(&[MAYHEM_STATE_SEED, mint.as_ref()], &PROGRAM_ID)
103    }
104
105    /// Token-2022 ATA for (`sol_vault`, mint).
106    pub fn mayhem_token_vault(mint: &Pubkey) -> (Pubkey, u8) {
107        let (sol_vault_pda, _) = sol_vault();
108        super::associated_token(&sol_vault_pda, &constants::SPL_TOKEN_2022_PROGRAM_ID, mint)
109    }
110}
111
112pub mod pump_amm {
113    use super::*;
114    use crate::constants::pump_amm::*;
115
116    pub fn global_config() -> (Pubkey, u8) {
117        Pubkey::find_program_address(&[GLOBAL_CONFIG_SEED], &PROGRAM_ID)
118    }
119
120    pub fn pool(
121        index: u16,
122        creator: &Pubkey,
123        base_mint: &Pubkey,
124        quote_mint: &Pubkey,
125    ) -> (Pubkey, u8) {
126        Pubkey::find_program_address(
127            &[
128                POOL_SEED,
129                &index.to_le_bytes(),
130                creator.as_ref(),
131                base_mint.as_ref(),
132                quote_mint.as_ref(),
133            ],
134            &PROGRAM_ID,
135        )
136    }
137
138    pub fn lp_mint(pool: &Pubkey) -> (Pubkey, u8) {
139        Pubkey::find_program_address(&[POOL_LP_MINT_SEED, pool.as_ref()], &PROGRAM_ID)
140    }
141
142    pub fn coin_creator_vault_authority(coin_creator: &Pubkey) -> (Pubkey, u8) {
143        Pubkey::find_program_address(&[CREATOR_VAULT_SEED, coin_creator.as_ref()], &PROGRAM_ID)
144    }
145
146    pub fn event_authority() -> (Pubkey, u8) {
147        Pubkey::find_program_address(&[EVENT_AUTHORITY_SEED], &PROGRAM_ID)
148    }
149
150    pub fn global_volume_accumulator() -> (Pubkey, u8) {
151        Pubkey::find_program_address(&[GLOBAL_VOLUME_ACCUMULATOR_SEED], &PROGRAM_ID)
152    }
153
154    pub fn user_volume_accumulator(user: &Pubkey) -> (Pubkey, u8) {
155        Pubkey::find_program_address(&[USER_VOLUME_ACCUMULATOR_SEED, user.as_ref()], &PROGRAM_ID)
156    }
157
158    pub fn pool_v2(base_mint: &Pubkey) -> (Pubkey, u8) {
159        Pubkey::find_program_address(&[POOL_V2_SEED, base_mint.as_ref()], &PROGRAM_ID)
160    }
161
162    pub fn fee_config() -> (Pubkey, u8) {
163        Pubkey::find_program_address(
164            &[FEE_CONFIG_SEED, FEE_CONFIG_PROGRAM_SEED_KEY.as_ref()],
165            &constants::FEE_PROGRAM_ID,
166        )
167    }
168}
169
170pub mod pump_agent_payments {
171    use super::*;
172    use crate::constants::pump_agent_payments::*;
173
174    pub fn global_config() -> (Pubkey, u8) {
175        Pubkey::find_program_address(&[GLOBAL_CONFIG_SEED], &PROGRAM_ID)
176    }
177
178    pub fn token_agent_payments(mint: &Pubkey) -> (Pubkey, u8) {
179        Pubkey::find_program_address(&[TOKEN_AGENT_PAYMENTS_SEED, mint.as_ref()], &PROGRAM_ID)
180    }
181
182    pub fn event_authority() -> (Pubkey, u8) {
183        Pubkey::find_program_address(&[EVENT_AUTHORITY_SEED], &PROGRAM_ID)
184    }
185}