feat: bonding_curve is transmitted from the outside

This commit is contained in:
wei
2025-06-18 17:39:20 +08:00
parent fa941174c2
commit 2303a4c1e6
4 changed files with 15 additions and 16 deletions
+7
View File
@@ -28,6 +28,7 @@ use ipfs::TokenMetadataIPFS;
use constants::trade_type::{COPY_BUY, SNIPER_BUY}; use constants::trade_type::{COPY_BUY, SNIPER_BUY};
use constants::trade_platform::{PUMPFUN, PUMPFUN_SWAP, RAYDIUM}; use constants::trade_platform::{PUMPFUN, PUMPFUN_SWAP, RAYDIUM};
use accounts::BondingCurveAccount;
pub struct PumpFun { pub struct PumpFun {
pub payer: Arc<Keypair>, pub payer: Arc<Keypair>,
@@ -218,6 +219,7 @@ impl PumpFun {
self.priority_fee.clone(), self.priority_fee.clone(),
self.cluster.clone().lookup_table_key, self.cluster.clone().lookup_table_key,
recent_blockhash, recent_blockhash,
None,
SNIPER_BUY.to_string(), SNIPER_BUY.to_string(),
).await ).await
} }
@@ -231,6 +233,7 @@ impl PumpFun {
buy_sol_cost: u64, buy_sol_cost: u64,
slippage_basis_points: Option<u64>, slippage_basis_points: Option<u64>,
recent_blockhash: Hash, recent_blockhash: Hash,
bonding_curve: Option<Arc<BondingCurveAccount>>,
trade_platform: String, trade_platform: String,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
if trade_platform == PUMPFUN { if trade_platform == PUMPFUN {
@@ -246,6 +249,7 @@ impl PumpFun {
self.priority_fee.clone(), self.priority_fee.clone(),
self.cluster.clone().lookup_table_key, self.cluster.clone().lookup_table_key,
recent_blockhash, recent_blockhash,
bonding_curve,
COPY_BUY.to_string(), COPY_BUY.to_string(),
).await ).await
} else if trade_platform == PUMPFUN_SWAP { } else if trade_platform == PUMPFUN_SWAP {
@@ -293,6 +297,7 @@ impl PumpFun {
self.priority_fee.clone(), self.priority_fee.clone(),
self.cluster.clone().lookup_table_key, self.cluster.clone().lookup_table_key,
recent_blockhash, recent_blockhash,
None,
SNIPER_BUY.to_string(), SNIPER_BUY.to_string(),
).await ).await
} }
@@ -306,6 +311,7 @@ impl PumpFun {
buy_sol_cost: u64, buy_sol_cost: u64,
slippage_basis_points: Option<u64>, slippage_basis_points: Option<u64>,
recent_blockhash: Hash, recent_blockhash: Hash,
bonding_curve: Option<Arc<BondingCurveAccount>>,
trade_platform: String, trade_platform: String,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
if trade_platform == PUMPFUN { if trade_platform == PUMPFUN {
@@ -321,6 +327,7 @@ impl PumpFun {
self.priority_fee.clone(), self.priority_fee.clone(),
self.cluster.clone().lookup_table_key, self.cluster.clone().lookup_table_key,
recent_blockhash, recent_blockhash,
bonding_curve,
COPY_BUY.to_string(), COPY_BUY.to_string(),
).await ).await
} else if trade_platform == PUMPFUN_SWAP { } else if trade_platform == PUMPFUN_SWAP {
+5
View File
@@ -6,6 +6,7 @@ use crate::{
swqos::FeeClient, swqos::FeeClient,
trading::{core::params::PumpFunParams, factory::Protocol, BuyParams, TradeFactory}, trading::{core::params::PumpFunParams, factory::Protocol, BuyParams, TradeFactory},
}; };
use crate::accounts::BondingCurveAccount;
const MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT: u32 = 250000; const MAX_LOADED_ACCOUNTS_DATA_SIZE_LIMIT: u32 = 250000;
pub async fn buy( pub async fn buy(
@@ -20,6 +21,7 @@ pub async fn buy(
priority_fee: PriorityFee, priority_fee: PriorityFee,
lookup_table_key: Option<Pubkey>, lookup_table_key: Option<Pubkey>,
recent_blockhash: Hash, recent_blockhash: Hash,
bonding_curve: Option<Arc<BondingCurveAccount>>,
trade_type: String, trade_type: String,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
// 创建执行器 // 创建执行器
@@ -29,6 +31,7 @@ pub async fn buy(
dev_buy_token: dev_buy_token, dev_buy_token: dev_buy_token,
dev_sol_cost: dev_sol_cost, dev_sol_cost: dev_sol_cost,
trade_type: trade_type, trade_type: trade_type,
bonding_curve: bonding_curve,
}); });
// 创建买入参数 // 创建买入参数
let buy_params = BuyParams { let buy_params = BuyParams {
@@ -61,6 +64,7 @@ pub async fn buy_with_tip(
priority_fee: PriorityFee, priority_fee: PriorityFee,
lookup_table_key: Option<Pubkey>, lookup_table_key: Option<Pubkey>,
recent_blockhash: Hash, recent_blockhash: Hash,
bonding_curve: Option<Arc<BondingCurveAccount>>,
trade_type: String, trade_type: String,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
// 创建执行器 // 创建执行器
@@ -70,6 +74,7 @@ pub async fn buy_with_tip(
dev_buy_token: dev_buy_token, dev_buy_token: dev_buy_token,
dev_sol_cost: dev_sol_cost, dev_sol_cost: dev_sol_cost,
trade_type: trade_type, trade_type: trade_type,
bonding_curve: bonding_curve,
}); });
// 创建买入参数 // 创建买入参数
let buy_params = BuyParams { let buy_params = BuyParams {
+2
View File
@@ -5,6 +5,7 @@ use std::sync::Arc;
use super::traits::ProtocolParams; use super::traits::ProtocolParams;
use crate::common::{PriorityFee, SolanaRpcClient}; use crate::common::{PriorityFee, SolanaRpcClient};
use crate::swqos::FeeClient; use crate::swqos::FeeClient;
use crate::accounts::BondingCurveAccount;
/// 通用买入参数 /// 通用买入参数
#[derive(Clone)] #[derive(Clone)]
@@ -76,6 +77,7 @@ pub struct PumpFunParams {
pub dev_buy_token: u64, pub dev_buy_token: u64,
pub dev_sol_cost: u64, pub dev_sol_cost: u64,
pub trade_type: String, pub trade_type: String,
pub bonding_curve: Option<Arc<BondingCurveAccount>>,
} }
impl ProtocolParams for PumpFunParams { impl ProtocolParams for PumpFunParams {
+1 -16
View File
@@ -51,20 +51,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
) )
.await? .await?
} else { } else {
let (bonding_curve, _) = protocol_params.bonding_curve.clone().unwrap()
get_bonding_curve_account_v2(&PumpFun::get_instance().get_rpc(), &params.mint)
.await?;
Arc::new(BondingCurveAccount {
discriminator: bonding_curve.discriminator,
account: get_bonding_curve_pda(&params.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,
})
}; };
let max_sol_cost = calculate_with_slippage_buy( 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) Ok(instructions)
} }