The buy and sell methods have added the priority_fee parameter, which can control the priority fee for each transaction

This commit is contained in:
wei
2025-09-02 09:43:53 +08:00
parent 7aa676781c
commit 6f953ffa0d
13 changed files with 107 additions and 9 deletions
+42 -4
View File
@@ -65,16 +65,16 @@ impl SolanaTrade {
let mut priority_fee = trade_config.priority_fee.clone();
let commitment = trade_config.commitment.clone();
if priority_fee.buy_tip_fees.len() < swqos_configs.len() {
// 补齐数组,只补齐缺少的
// Fill the array, only fill the missing elements
let mut buy_tip_fees = priority_fee.buy_tip_fees.clone();
let default_fee = priority_fee.buy_tip_fee;
// 计算需要补充的元素数量
// Calculate the number of elements that need to be added
let missing_count = swqos_configs.len() - buy_tip_fees.len();
// 添加缺少的元素,使用默认值
// Add missing elements using default values
for _ in 0..missing_count {
buy_tip_fees.push(default_fee);
}
// 更新 priority_fee 中的 buy_tip_fees
// Update buy_tip_fees in priority_fee
priority_fee.buy_tip_fees = buy_tip_fees;
trade_config.priority_fee = priority_fee.clone();
}
@@ -159,6 +159,7 @@ impl SolanaTrade {
extension_params: Box<dyn ProtocolParams>,
lookup_table_key: Option<Pubkey>,
wait_transaction_confirmed: bool,
priority_fee: Option<PriorityFee>,
) -> Result<(), anyhow::Error> {
let executor = TradeFactory::create_executor(dex_type.clone());
let protocol_params = extension_params;
@@ -178,6 +179,23 @@ impl SolanaTrade {
wait_transaction_confirmed: wait_transaction_confirmed,
protocol_params: protocol_params.clone(),
};
if priority_fee.is_some() {
let mut custom_priority_fee = priority_fee.unwrap();
// Fill the array, only fill the missing elements
if custom_priority_fee.buy_tip_fees.len() < self.swqos_clients.len() {
let mut buy_tip_fees = custom_priority_fee.buy_tip_fees.clone();
let default_fee = custom_priority_fee.buy_tip_fee;
// Calculate the number of elements that need to be added
let missing_count = self.swqos_clients.len() - buy_tip_fees.len();
// Add missing elements using default values
for _ in 0..missing_count {
buy_tip_fees.push(default_fee);
}
// Update buy_tip_fees in custom_priority_fee
custom_priority_fee.buy_tip_fees = buy_tip_fees;
}
buy_params.priority_fee = custom_priority_fee;
}
if custom_buy_tip_fee.is_some() {
buy_params.priority_fee.buy_tip_fee = custom_buy_tip_fee.unwrap();
buy_params.priority_fee.buy_tip_fees = buy_params
@@ -250,6 +268,7 @@ impl SolanaTrade {
extension_params: Box<dyn ProtocolParams>,
lookup_table_key: Option<Pubkey>,
wait_transaction_confirmed: bool,
priority_fee: Option<PriorityFee>,
) -> Result<(), anyhow::Error> {
let executor = TradeFactory::create_executor(dex_type.clone());
let protocol_params = extension_params;
@@ -268,6 +287,23 @@ impl SolanaTrade {
wait_transaction_confirmed: wait_transaction_confirmed,
protocol_params: protocol_params.clone(),
};
if priority_fee.is_some() {
let mut custom_priority_fee = priority_fee.unwrap();
// Fill the array, only fill the missing elements
if custom_priority_fee.buy_tip_fees.len() < self.swqos_clients.len() {
let mut buy_tip_fees = custom_priority_fee.buy_tip_fees.clone();
let default_fee = custom_priority_fee.buy_tip_fee;
// Calculate the number of elements that need to be added
let missing_count = self.swqos_clients.len() - buy_tip_fees.len();
// Add missing elements using default values
for _ in 0..missing_count {
buy_tip_fees.push(default_fee);
}
// Update buy_tip_fees in custom_priority_fee
custom_priority_fee.buy_tip_fees = buy_tip_fees;
}
sell_params.priority_fee = custom_priority_fee;
}
if custom_buy_tip_fee.is_some() {
sell_params.priority_fee.buy_tip_fee = custom_buy_tip_fee.unwrap();
sell_params.priority_fee.buy_tip_fees = sell_params
@@ -351,6 +387,7 @@ impl SolanaTrade {
extension_params: Box<dyn ProtocolParams>,
lookup_table_key: Option<Pubkey>,
wait_transaction_confirmed: bool,
priority_fee: Option<PriorityFee>,
) -> Result<(), anyhow::Error> {
if percent == 0 || percent > 100 {
return Err(anyhow::anyhow!("Percentage must be between 1 and 100"));
@@ -367,6 +404,7 @@ impl SolanaTrade {
extension_params,
lookup_table_key,
wait_transaction_confirmed,
priority_fee,
)
.await
}
+17
View File
@@ -120,6 +120,7 @@ async fn test_middleware() -> AnyResult<()> {
Box::new(PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?),
None,
true,
None,
)
.await?;
Ok(())
@@ -147,6 +148,7 @@ async fn test_pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> Any
Box::new(PumpFunParams::from_trade(&trade_info, None)),
None,
true,
None,
)
.await?;
@@ -165,6 +167,7 @@ async fn test_pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> Any
Box::new(PumpFunParams::from_trade(&trade_info, None)),
None,
true,
None,
)
.await?;
@@ -197,6 +200,7 @@ async fn test_pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) ->
Box::new(PumpFunParams::from_trade(&trade_info, None)),
None,
true,
None,
)
.await?;
@@ -215,6 +219,7 @@ async fn test_pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) ->
Box::new(PumpFunParams::from_trade(&trade_info, None)),
None,
true,
None,
)
.await?;
@@ -245,6 +250,7 @@ async fn test_pumpswap() -> AnyResult<()> {
Box::new(PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?),
None,
true,
None,
)
.await?;
@@ -264,6 +270,7 @@ async fn test_pumpswap() -> AnyResult<()> {
Box::new(PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?),
None,
true,
None,
)
.await?;
@@ -292,6 +299,7 @@ async fn test_bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult
Box::new(BonkParams::from_trade(trade_info.clone())),
None,
true,
None,
)
.await?;
@@ -310,6 +318,7 @@ async fn test_bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult
Box::new(BonkParams::from_trade(trade_info)),
None,
true,
None,
)
.await?;
@@ -342,6 +351,7 @@ async fn test_bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyRe
Box::new(BonkParams::from_dev_trade(trade_info.clone())),
None,
true,
None,
)
.await?;
@@ -360,6 +370,7 @@ async fn test_bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyRe
Box::new(BonkParams::from_dev_trade(trade_info)),
None,
true,
None,
)
.await?;
@@ -389,6 +400,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
Box::new(BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?),
None,
true,
None,
)
.await?;
@@ -408,6 +420,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
Box::new(BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?),
None,
true,
None,
)
.await?;
@@ -439,6 +452,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
),
None,
true,
None,
)
.await?;
@@ -460,6 +474,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
),
None,
true,
None,
)
.await?;
@@ -489,6 +504,7 @@ async fn test_raydium_amm_v4() -> Result<(), Box<dyn std::error::Error>> {
Box::new(RaydiumAmmV4Params::from_amm_address_by_rpc(&client.rpc, amm_address).await?),
None,
true,
None,
)
.await?;
@@ -508,6 +524,7 @@ async fn test_raydium_amm_v4() -> Result<(), Box<dyn std::error::Error>> {
Box::new(RaydiumAmmV4Params::from_amm_address_by_rpc(&client.rpc, amm_address).await?),
None,
true,
None,
)
.await?;