From 2303a4c1e6416cde4b2572f36c293a89e877e151 Mon Sep 17 00:00:00 2001 From: wei <1415121722@qq.com> Date: Wed, 18 Jun 2025 17:39:20 +0800 Subject: [PATCH] feat: bonding_curve is transmitted from the outside --- src/lib.rs | 7 +++++++ src/pumpfun/buy.rs | 5 +++++ src/trading/core/params.rs | 2 ++ src/trading/protocols/pumpfun.rs | 17 +---------------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index aef5816..1fcc1c2 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,7 @@ use ipfs::TokenMetadataIPFS; use constants::trade_type::{COPY_BUY, SNIPER_BUY}; use constants::trade_platform::{PUMPFUN, PUMPFUN_SWAP, RAYDIUM}; +use accounts::BondingCurveAccount; pub struct PumpFun { pub payer: Arc, @@ -218,6 +219,7 @@ impl PumpFun { self.priority_fee.clone(), self.cluster.clone().lookup_table_key, recent_blockhash, + None, SNIPER_BUY.to_string(), ).await } @@ -231,6 +233,7 @@ impl PumpFun { buy_sol_cost: u64, slippage_basis_points: Option, recent_blockhash: Hash, + bonding_curve: Option>, trade_platform: String, ) -> Result<(), anyhow::Error> { if trade_platform == PUMPFUN { @@ -246,6 +249,7 @@ impl PumpFun { self.priority_fee.clone(), self.cluster.clone().lookup_table_key, recent_blockhash, + bonding_curve, COPY_BUY.to_string(), ).await } else if trade_platform == PUMPFUN_SWAP { @@ -293,6 +297,7 @@ impl PumpFun { self.priority_fee.clone(), self.cluster.clone().lookup_table_key, recent_blockhash, + None, SNIPER_BUY.to_string(), ).await } @@ -306,6 +311,7 @@ impl PumpFun { buy_sol_cost: u64, slippage_basis_points: Option, recent_blockhash: Hash, + bonding_curve: Option>, trade_platform: String, ) -> Result<(), anyhow::Error> { if trade_platform == PUMPFUN { @@ -321,6 +327,7 @@ impl PumpFun { self.priority_fee.clone(), self.cluster.clone().lookup_table_key, recent_blockhash, + bonding_curve, COPY_BUY.to_string(), ).await } else if trade_platform == PUMPFUN_SWAP { diff --git a/src/pumpfun/buy.rs b/src/pumpfun/buy.rs index 106cdf1..e854877 100755 --- a/src/pumpfun/buy.rs +++ b/src/pumpfun/buy.rs @@ -6,6 +6,7 @@ use crate::{ swqos::FeeClient, trading::{core::params::PumpFunParams, factory::Protocol, BuyParams, TradeFactory}, }; +use crate::accounts::BondingCurveAccount; const MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT: u32 = 250000; pub async fn buy( @@ -20,6 +21,7 @@ pub async fn buy( priority_fee: PriorityFee, lookup_table_key: Option, recent_blockhash: Hash, + bonding_curve: Option>, trade_type: String, ) -> Result<(), anyhow::Error> { // 创建执行器 @@ -29,6 +31,7 @@ pub async fn buy( dev_buy_token: dev_buy_token, dev_sol_cost: dev_sol_cost, trade_type: trade_type, + bonding_curve: bonding_curve, }); // 创建买入参数 let buy_params = BuyParams { @@ -61,6 +64,7 @@ pub async fn buy_with_tip( priority_fee: PriorityFee, lookup_table_key: Option, recent_blockhash: Hash, + bonding_curve: Option>, trade_type: String, ) -> Result<(), anyhow::Error> { // 创建执行器 @@ -70,6 +74,7 @@ pub async fn buy_with_tip( dev_buy_token: dev_buy_token, dev_sol_cost: dev_sol_cost, trade_type: trade_type, + bonding_curve: bonding_curve, }); // 创建买入参数 let buy_params = BuyParams { diff --git a/src/trading/core/params.rs b/src/trading/core/params.rs index 0985e2a..f742c89 100644 --- a/src/trading/core/params.rs +++ b/src/trading/core/params.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use super::traits::ProtocolParams; use crate::common::{PriorityFee, SolanaRpcClient}; use crate::swqos::FeeClient; +use crate::accounts::BondingCurveAccount; /// 通用买入参数 #[derive(Clone)] @@ -76,6 +77,7 @@ pub struct PumpFunParams { pub dev_buy_token: u64, pub dev_sol_cost: u64, pub trade_type: String, + pub bonding_curve: Option>, } impl ProtocolParams for PumpFunParams { diff --git a/src/trading/protocols/pumpfun.rs b/src/trading/protocols/pumpfun.rs index 27320f2..6bbe831 100644 --- a/src/trading/protocols/pumpfun.rs +++ b/src/trading/protocols/pumpfun.rs @@ -51,20 +51,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder { ) .await? } else { - let (bonding_curve, _) = - get_bonding_curve_account_v2(&PumpFun::get_instance().get_rpc(), ¶ms.mint) - .await?; - Arc::new(BondingCurveAccount { - discriminator: bonding_curve.discriminator, - account: get_bonding_curve_pda(¶ms.mint).unwrap(), - virtual_token_reserves: bonding_curve.virtual_token_reserves, - virtual_sol_reserves: bonding_curve.virtual_sol_reserves, - real_token_reserves: bonding_curve.real_token_reserves, - real_sol_reserves: bonding_curve.real_sol_reserves, - token_total_supply: bonding_curve.token_total_supply, - complete: bonding_curve.complete, - creator: params.creator, - }) + protocol_params.bonding_curve.clone().unwrap() }; let max_sol_cost = calculate_with_slippage_buy( @@ -108,8 +95,6 @@ impl InstructionBuilder for PumpFunInstructionBuilder { }, )); - println!("max_sol_cost: {:?}", max_sol_cost); - Ok(instructions) }