Merge commit '02ab5f5314cfcfe1b267289f3a9070db67add10a'

This commit is contained in:
ysq
2025-06-18 23:23:37 +08:00
5 changed files with 24 additions and 17 deletions
+10
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 {
@@ -463,6 +470,7 @@ impl PumpFun {
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
if trade_platform == PUMPFUN { if trade_platform == PUMPFUN {
pumpfun::sell::sell_by_percent_with_tip( pumpfun::sell::sell_by_percent_with_tip(
self.rpc.clone(),
self.fee_clients.clone(), self.fee_clients.clone(),
self.payer.clone(), self.payer.clone(),
mint, mint,
@@ -506,6 +514,7 @@ impl PumpFun {
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
if trade_platform == PUMPFUN { if trade_platform == PUMPFUN {
pumpfun::sell::sell_by_amount_with_tip( pumpfun::sell::sell_by_amount_with_tip(
self.rpc.clone(),
self.fee_clients.clone(), self.fee_clients.clone(),
self.payer.clone(), self.payer.clone(),
mint, mint,
@@ -547,6 +556,7 @@ impl PumpFun {
recent_blockhash: Hash, recent_blockhash: Hash,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
pumpfun::sell::sell_with_tip( pumpfun::sell::sell_with_tip(
self.rpc.clone(),
self.fee_clients.clone(), self.fee_clients.clone(),
self.payer.clone(), self.payer.clone(),
mint, mint,
+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 {
+6 -1
View File
@@ -98,6 +98,7 @@ pub async fn sell_by_amount(
} }
pub async fn sell_by_percent_with_tip( pub async fn sell_by_percent_with_tip(
rpc: Arc<SolanaRpcClient>,
fee_clients: Vec<Arc<FeeClient>>, fee_clients: Vec<Arc<FeeClient>>,
payer: Arc<Keypair>, payer: Arc<Keypair>,
mint: Pubkey, mint: Pubkey,
@@ -113,6 +114,7 @@ pub async fn sell_by_percent_with_tip(
} }
let amount = amount_token * percent / 100; let amount = amount_token * percent / 100;
sell_with_tip( sell_with_tip(
rpc,
fee_clients, fee_clients,
payer, payer,
mint, mint,
@@ -126,6 +128,7 @@ pub async fn sell_by_percent_with_tip(
} }
pub async fn sell_by_amount_with_tip( pub async fn sell_by_amount_with_tip(
rpc: Arc<SolanaRpcClient>,
fee_clients: Vec<Arc<FeeClient>>, fee_clients: Vec<Arc<FeeClient>>,
payer: Arc<Keypair>, payer: Arc<Keypair>,
mint: Pubkey, mint: Pubkey,
@@ -139,6 +142,7 @@ pub async fn sell_by_amount_with_tip(
return Err(anyhow!("Amount must be greater than 0")); return Err(anyhow!("Amount must be greater than 0"));
} }
sell_with_tip( sell_with_tip(
rpc,
fee_clients, fee_clients,
payer, payer,
mint, mint,
@@ -153,6 +157,7 @@ pub async fn sell_by_amount_with_tip(
/// Sell tokens using Jito /// Sell tokens using Jito
pub async fn sell_with_tip( pub async fn sell_with_tip(
rpc: Arc<SolanaRpcClient>,
fee_clients: Vec<Arc<FeeClient>>, fee_clients: Vec<Arc<FeeClient>>,
payer: Arc<Keypair>, payer: Arc<Keypair>,
mint: Pubkey, mint: Pubkey,
@@ -167,7 +172,7 @@ pub async fn sell_with_tip(
let protocol_params = Box::new(PumpFunSellParams {}); let protocol_params = Box::new(PumpFunSellParams {});
// 创建卖出参数 // 创建卖出参数
let sell_params = SellParams { let sell_params = SellParams {
rpc: None, rpc: Some(rpc.clone()),
payer: payer.clone(), payer: payer.clone(),
mint, mint,
creator, creator,
+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)
} }