Skip to main content

pump_rust_client/
pda.rs

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