diff --git a/src/lib.rs b/src/lib.rs index aef5816..c5d48c8 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 { @@ -463,6 +470,7 @@ impl PumpFun { ) -> Result<(), anyhow::Error> { if trade_platform == PUMPFUN { pumpfun::sell::sell_by_percent_with_tip( + self.rpc.clone(), self.fee_clients.clone(), self.payer.clone(), mint, @@ -506,6 +514,7 @@ impl PumpFun { ) -> Result<(), anyhow::Error> { if trade_platform == PUMPFUN { pumpfun::sell::sell_by_amount_with_tip( + self.rpc.clone(), self.fee_clients.clone(), self.payer.clone(), mint, @@ -547,6 +556,7 @@ impl PumpFun { recent_blockhash: Hash, ) -> Result<(), anyhow::Error> { pumpfun::sell::sell_with_tip( + self.rpc.clone(), self.fee_clients.clone(), self.payer.clone(), mint, 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/pumpfun/sell.rs b/src/pumpfun/sell.rs index 6836db3..546e4e8 100755 --- a/src/pumpfun/sell.rs +++ b/src/pumpfun/sell.rs @@ -98,6 +98,7 @@ pub async fn sell_by_amount( } pub async fn sell_by_percent_with_tip( + rpc: Arc, fee_clients: Vec>, payer: Arc, mint: Pubkey, @@ -113,6 +114,7 @@ pub async fn sell_by_percent_with_tip( } let amount = amount_token * percent / 100; sell_with_tip( + rpc, fee_clients, payer, mint, @@ -126,6 +128,7 @@ pub async fn sell_by_percent_with_tip( } pub async fn sell_by_amount_with_tip( + rpc: Arc, fee_clients: Vec>, payer: Arc, mint: Pubkey, @@ -139,6 +142,7 @@ pub async fn sell_by_amount_with_tip( return Err(anyhow!("Amount must be greater than 0")); } sell_with_tip( + rpc, fee_clients, payer, mint, @@ -153,6 +157,7 @@ pub async fn sell_by_amount_with_tip( /// Sell tokens using Jito pub async fn sell_with_tip( + rpc: Arc, fee_clients: Vec>, payer: Arc, mint: Pubkey, @@ -167,7 +172,7 @@ pub async fn sell_with_tip( let protocol_params = Box::new(PumpFunSellParams {}); // 创建卖出参数 let sell_params = SellParams { - rpc: None, + rpc: Some(rpc.clone()), payer: payer.clone(), mint, creator, 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 cce81ba..7ae899b 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) }