From 07651638b9ba24eb5a41ebddf055bca90dea2462 Mon Sep 17 00:00:00 2001 From: William Date: Tue, 13 May 2025 07:08:01 +0800 Subject: [PATCH] fix --- src/instruction/mod.rs | 2 +- src/pumpfun/buy.rs | 10 +++++----- src/pumpfun/common.rs | 2 +- src/pumpfun/create.rs | 28 +++++++++++++++------------- src/pumpfun/sell.rs | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/instruction/mod.rs b/src/instruction/mod.rs index bc076d0..f6e55d2 100755 --- a/src/instruction/mod.rs +++ b/src/instruction/mod.rs @@ -202,7 +202,7 @@ pub fn sell( AccountMeta::new_readonly(constants::global_constants::GLOBAL_ACCOUNT, false), AccountMeta::new(*fee_recipient, false), AccountMeta::new_readonly(*mint, false), - AccountMeta::new(bonding_curve, false), + AccountMeta::new(*bonding_curve, false), AccountMeta::new(get_associated_token_address(&bonding_curve, mint), false), AccountMeta::new(get_associated_token_address(&payer.pubkey(), mint), false), AccountMeta::new(payer.pubkey(), true), diff --git a/src/pumpfun/buy.rs b/src/pumpfun/buy.rs index 16a93cc..92a6efc 100755 --- a/src/pumpfun/buy.rs +++ b/src/pumpfun/buy.rs @@ -7,11 +7,11 @@ use spl_associated_token_account::instruction::create_associated_token_account; use tokio::task::JoinHandle; use std::{str::FromStr, time::Instant, sync::Arc}; -use crate::{common::{PriorityFee, SolanaRpcClient}, constants::{self, trade::DEFAULT_SLIPPAGE}, instruction, swqos::FeeClient}; +use crate::{common::{PriorityFee, SolanaRpcClient}, constants::{self, global_constants::FEE_RECIPIENT, trade::DEFAULT_SLIPPAGE}, instruction, swqos::FeeClient}; const MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT: u32 = 250000; -use super::common::{calculate_with_slippage_buy, get_bonding_curve_account, get_global_account, get_initial_buy_price}; +use super::common::{calculate_with_slippage_buy, get_bonding_curve_account, get_buy_token_amount, get_creator_vault_pda, get_global_account, get_initial_buy_price}; pub async fn buy( rpc: Arc, @@ -139,10 +139,10 @@ pub async fn build_buy_instructions( rpc: Arc, payer: Arc, mint: Arc, - amount_sol: u64, + buy_sol_cost: u64, slippage_basis_points: Option, ) -> Result, anyhow::Error> { - if amount_sol == 0 { + if buy_sol_cost == 0 { return Err(anyhow!("Amount cannot be zero")); } @@ -165,7 +165,7 @@ pub async fn build_buy_instructions( &mint, &bonding_curve_pda, &creator_vault_pda, - &global_account.fee_recipient, + &FEE_RECIPIENT, instruction::Buy { _amount: buy_token_amount, _max_sol_cost: max_sol_cost, diff --git a/src/pumpfun/common.rs b/src/pumpfun/common.rs index 981252b..6be013b 100755 --- a/src/pumpfun/common.rs +++ b/src/pumpfun/common.rs @@ -177,7 +177,7 @@ pub async fn get_bonding_curve_account( #[inline] pub fn get_buy_token_amount( - bonding_curve_account: &BondingCurveAccount, + bonding_curve_account: &Arc, buy_sol_cost: u64, slippage_basis_points: Option, ) -> anyhow::Result<(u64, u64)> { diff --git a/src/pumpfun/create.rs b/src/pumpfun/create.rs index 49d392a..5e1eb0a 100755 --- a/src/pumpfun/create.rs +++ b/src/pumpfun/create.rs @@ -10,9 +10,7 @@ use spl_associated_token_account::{ }; use crate::{ - common::{PriorityFee, SolanaRpcClient}, constants, instruction, - ipfs::TokenMetadataIPFS, swqos::FeeClient, - pumpfun::buy::build_buy_transaction_with_tip + common::{PriorityFee, SolanaRpcClient}, constants::{self, global_constants::FEE_RECIPIENT}, instruction, ipfs::TokenMetadataIPFS, pumpfun::buy::build_buy_transaction_with_tip, swqos::FeeClient }; use crate::pumpfun::common::{ @@ -20,6 +18,8 @@ use crate::pumpfun::common::{ get_buy_amount_with_slippage, get_global_account }; +use super::common::{get_bonding_curve_account, get_buy_token_amount, get_creator_vault_pda}; + /// Create a new token pub async fn create( rpc: Arc, @@ -181,19 +181,19 @@ pub async fn build_create_and_buy_instructions( payer: Arc, mint: Arc, ipfs: TokenMetadataIPFS, - amount_sol: u64, + buy_sol_cost: u64, slippage_basis_points: Option, priority_fee: PriorityFee, ) -> Result, anyhow::Error> { - if amount_sol == 0 { + if buy_sol_cost == 0 { return Err(anyhow!("Amount cannot be zero")); } - let rpc = rpc.as_ref(); - let global_account = get_global_account(rpc).await?; - let buy_amount = global_account.get_initial_buy_price(amount_sol); - let buy_amount_with_slippage = - get_buy_amount_with_slippage(amount_sol, slippage_basis_points); + let (bonding_curve_account, bonding_curve_pda) = get_bonding_curve_account(&rpc, &mint.pubkey()).await?; + + let creator_vault_pda = get_creator_vault_pda(&bonding_curve_account.creator).unwrap(); + + let (buy_token_amount, max_sol_cost) = get_buy_token_amount(&bonding_curve_account, buy_sol_cost, slippage_basis_points)?; let mut instructions = vec![]; @@ -218,10 +218,12 @@ pub async fn build_create_and_buy_instructions( instructions.push(instruction::buy( payer.as_ref(), &mint.pubkey(), - &global_account.fee_recipient, + &bonding_curve_pda, + &creator_vault_pda, + &FEE_RECIPIENT, instruction::Buy { - _amount: buy_amount, - _max_sol_cost: buy_amount_with_slippage, + _amount: buy_token_amount, + _max_sol_cost: max_sol_cost, }, )); diff --git a/src/pumpfun/sell.rs b/src/pumpfun/sell.rs index 88a966c..02bf8d5 100755 --- a/src/pumpfun/sell.rs +++ b/src/pumpfun/sell.rs @@ -12,7 +12,7 @@ use std::{str::FromStr, time::Instant, sync::Arc}; use crate::{common::{PriorityFee, SolanaRpcClient}, constants::trade::{DEFAULT_COMPUTE_UNIT_PRICE, DEFAULT_SLIPPAGE}, instruction, swqos::FeeClient}; -use super::common::{calculate_with_slippage_sell, get_bonding_curve_account, get_global_account}; +use super::common::{calculate_with_slippage_sell, get_bonding_curve_account, get_creator_vault_pda, get_global_account}; async fn get_token_balance(rpc: &SolanaRpcClient, payer: &Keypair, mint: &Pubkey) -> Result<(u64, Pubkey), anyhow::Error> { let ata = get_associated_token_address(&payer.pubkey(), mint);