Skip to main content

pump_rust_client/sdk/
pump_legacy.rs

1use anchor_lang::{InstructionData, ToAccountMetas};
2use solana_program::{
3    instruction::{AccountMeta, Instruction},
4    pubkey::Pubkey,
5    system_program, sysvar,
6};
7
8use crate::{constants, pda, pump::client, pump::types::OptionBool};
9
10use super::PumpSdk;
11
12#[allow(deprecated)]
13impl PumpSdk {
14    /// Legacy create (SPL Token + Metaplex); prefer [`Self::create_v2_instruction`].
15    #[deprecated(note = "Use create_v2_instruction instead")]
16    pub fn create_instruction(
17        &self,
18        mint: Pubkey,
19        user: Pubkey,
20        name: impl Into<String>,
21        symbol: impl Into<String>,
22        uri: impl Into<String>,
23        creator: Pubkey,
24    ) -> Instruction {
25        let token_program = constants::SPL_TOKEN_PROGRAM_ID;
26        let bonding_curve = pda::pump::bonding_curve(&mint).0;
27        let accounts = client::accounts::Create {
28            mint,
29            mint_authority: pda::pump::mint_authority().0,
30            bonding_curve,
31            associated_bonding_curve: pda::associated_token(&bonding_curve, &token_program, &mint)
32                .0,
33            global: pda::pump::global().0,
34            mpl_token_metadata: constants::MPL_TOKEN_METADATA_PROGRAM_ID,
35            metadata: pda::pump::metadata(&mint).0,
36            user,
37            system_program: system_program::ID,
38            token_program,
39            associated_token_program: constants::SPL_ATA_PROGRAM_ID,
40            rent: sysvar::rent::ID,
41            event_authority: pda::pump::event_authority().0,
42            program: crate::pump::ID,
43        };
44        let args = client::args::Create {
45            name: name.into(),
46            symbol: symbol.into(),
47            uri: uri.into(),
48            creator,
49        };
50        Instruction {
51            program_id: crate::pump::ID,
52            accounts: accounts.to_account_metas(None),
53            data: args.data(),
54        }
55    }
56
57    /// Legacy bonding-curve buy; prefer [`Self::buy_v2_instruction`]. Appends `bonding_curve_v2`, `buyback_fee_recipient`.
58    #[deprecated(note = "Use buy_v2_instruction instead")]
59    pub fn buy_instruction(
60        &self,
61        mint: Pubkey,
62        user: Pubkey,
63        creator: Pubkey,
64        fee_recipient: Pubkey,
65        buyback_fee_recipient: Pubkey,
66        amount: u64,
67        max_sol_cost: u64,
68        token_program: Pubkey,
69    ) -> Instruction {
70        let bonding_curve = pda::pump::bonding_curve(&mint).0;
71        let accounts = client::accounts::Buy {
72            global: pda::pump::global().0,
73            fee_recipient,
74            mint,
75            bonding_curve,
76            associated_bonding_curve: pda::associated_token(&bonding_curve, &token_program, &mint)
77                .0,
78            associated_user: pda::associated_token(&user, &token_program, &mint).0,
79            user,
80            system_program: system_program::ID,
81            token_program,
82            creator_vault: pda::pump::creator_vault(&creator).0,
83            event_authority: pda::pump::event_authority().0,
84            program: crate::pump::ID,
85            global_volume_accumulator: pda::pump::global_volume_accumulator().0,
86            user_volume_accumulator: pda::pump::user_volume_accumulator(&user).0,
87            fee_config: pda::pump::fee_config().0,
88            fee_program: constants::FEE_PROGRAM_ID,
89        };
90        let args = client::args::Buy {
91            amount,
92            max_sol_cost,
93            track_volume: OptionBool(true),
94        };
95        let mut metas = accounts.to_account_metas(None);
96        metas.push(AccountMeta::new_readonly(
97            pda::pump::bonding_curve_v2(&mint).0,
98            false,
99        ));
100        metas.push(AccountMeta::new(buyback_fee_recipient, false));
101        Instruction {
102            program_id: crate::pump::ID,
103            accounts: metas,
104            data: args.data(),
105        }
106    }
107
108    /// Legacy sell; prefer [`Self::sell_v2_instruction`]. Appends UVA, `bonding_curve_v2`.
109    #[deprecated(note = "Use sell_v2_instruction instead")]
110    pub fn sell_instruction(
111        &self,
112        mint: Pubkey,
113        user: Pubkey,
114        creator: Pubkey,
115        fee_recipient: Pubkey,
116        buyback_fee_recipient: Pubkey,
117        amount: u64,
118        min_sol_output: u64,
119        token_program: Pubkey,
120        is_cashback_coin: bool,
121    ) -> Instruction {
122        let bonding_curve = pda::pump::bonding_curve(&mint).0;
123        let accounts = client::accounts::Sell {
124            global: pda::pump::global().0,
125            fee_recipient,
126            mint,
127            bonding_curve,
128            associated_bonding_curve: pda::associated_token(&bonding_curve, &token_program, &mint)
129                .0,
130            associated_user: pda::associated_token(&user, &token_program, &mint).0,
131            user,
132            system_program: system_program::ID,
133            creator_vault: pda::pump::creator_vault(&creator).0,
134            token_program,
135            event_authority: pda::pump::event_authority().0,
136            program: crate::pump::ID,
137            fee_config: pda::pump::fee_config().0,
138            fee_program: constants::FEE_PROGRAM_ID,
139        };
140        let args = client::args::Sell {
141            amount,
142            min_sol_output,
143        };
144        let mut metas = accounts.to_account_metas(None);
145        if is_cashback_coin {
146            metas.push(AccountMeta::new(
147                pda::pump::user_volume_accumulator(&user).0,
148                false,
149            ));
150        }
151        metas.push(AccountMeta::new_readonly(
152            pda::pump::bonding_curve_v2(&mint).0,
153            false,
154        ));
155        metas.push(AccountMeta::new(buyback_fee_recipient, false));
156        Instruction {
157            program_id: crate::pump::ID,
158            accounts: metas,
159            data: args.data(),
160        }
161    }
162}