Testing pump buy

This commit is contained in:
2026-08-06 05:22:30 +02:00
parent b42c59e01b
commit f20bdd490a
3 changed files with 221 additions and 472 deletions
+65 -28
View File
@@ -1,40 +1,77 @@
use pump_rust_client::{
AccountWrapper, PumpSdk, pump::pump::accounts::BondingCurve, state::Global,
use solana_sdk::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};
use std::str::FromStr;
use crate::executor::Executor;
pub mod system_program {
use solana_sdk::declare_id;
pub const PROGRAM_ID: &str = "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P";
pub struct PumpFun {
pub private_key: String,
pub sdk: PumpSdk,
pub global: Global,
declare_id!("11111111111111111111111111111111");
}
impl Executor for PumpFun {
async fn buy(&self, token: solana_sdk::pubkey::Pubkey, amount: u64) -> anyhow::Result<()> {
log::info!("Buying {token}");
/// Derives the bonding curve and associated bonding curve tokens for a given mint.
pub fn derive_bonding_curve_pdas(mint: &Pubkey, program_id: &Pubkey) -> (Pubkey, Pubkey) {
let (bonding_curve, _) =
Pubkey::find_program_address(&[b"bonding-curve", mint.as_ref()], program_id);
// let bonding_curve: AccountWrapper<BondingCurve> = _;
let (associated_bonding_curve, _) = Pubkey::find_program_address(
&[
bonding_curve.as_ref(),
spl_token::ID.as_ref(),
mint.as_ref(),
],
&spl_associated_token_account::ID,
);
// self.sdk.buy_v2_instructions(
// &self.global,
// &bonding_curve,
// token,
// quote_token_program,
// user,
// amount,
// max_quote_tokens,
// );
(bonding_curve, associated_bonding_curve)
}
Ok(())
}
/// Constructs a raw pump.fun buy instruction
pub fn create_pump_buy_instruction(
payer: Pubkey,
mint: Pubkey,
ata_token_account: Pubkey, // User's associated token account for this mint
token_amount: u64, // Amount of tokens to purchase
max_sol_cost: u64, // Max lamports to spend (Slippage protection)
) -> Instruction {
let program_id = Pubkey::from_str("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5AMX787Nz").unwrap();
async fn sell(&self, token: solana_sdk::pubkey::Pubkey, amount: u64) -> anyhow::Result<()> {
log::info!("Selling {token}");
// Constant global state accounts used by pump.fun
let global_account = Pubkey::from_str("4wTV1YmiEkRvAtN4S7mJP2bXax2p18e4LK8LCHWwEQ2F").unwrap();
let fee_recipient = Pubkey::from_str("CebN5WG3QfR6EPEDZgbu6wN6sfg92v7S759DcGTR8b61").unwrap();
Ok(())
// Derive the PDAs for the bonding curves
let (bonding_curve, associated_bonding_curve) = derive_bonding_curve_pdas(&mint, &program_id);
// 1. Build the data payload (Discriminator + Args)
// Anchor discriminator for 'buy': [102, 139, 25, 211, 85, 210, 149, 228]
let mut instruction_data = vec![102, 139, 25, 211, 85, 210, 149, 228];
instruction_data.extend_from_slice(&token_amount.to_le_bytes());
instruction_data.extend_from_slice(&max_sol_cost.to_le_bytes());
// 2. Map required accounts in correct order
let accounts = vec![
AccountMeta::new_readonly(global_account, false),
AccountMeta::new(fee_recipient, false),
AccountMeta::new_readonly(mint, false),
AccountMeta::new(bonding_curve, false),
AccountMeta::new(associated_bonding_curve, false),
AccountMeta::new(ata_token_account, false),
AccountMeta::new(payer, true), // Signer
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(solana_program::sysvar::rent::ID, false),
AccountMeta::new_readonly(
Pubkey::from_str("Ce6TQqeHC9p8KBAayQr27Pyy6wJaCdE7wXw8msu3vA8Q").unwrap(),
false,
), // Event Authority
AccountMeta::new_readonly(program_id, false),
];
Instruction {
program_id,
accounts,
data: instruction_data,
}
}