refactor: Update GasFeeStrategy to instance-based API and update docs

This commit is contained in:
ysq
2025-10-07 23:12:37 +08:00
parent e13c891cc9
commit 85154f6c01
28 changed files with 269 additions and 120 deletions
+5 -8
View File
@@ -7,8 +7,8 @@ use solana_sdk::message::AddressLookupTableAccount;
use solana_sdk::{
instruction::Instruction, pubkey::Pubkey, signature::Keypair, signature::Signature,
};
use std::{str::FromStr, sync::Arc, time::Instant};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::{str::FromStr, sync::Arc, time::Instant};
use crate::{
common::nonce_cache::DurableNonceInfo,
@@ -48,7 +48,7 @@ impl ResultCollector {
let _ = self.results.push(result);
if is_success {
self.success_flag.store(true, Ordering::Release); // Release 确保 push 可见
self.success_flag.store(true, Ordering::Release); // Release 确保 push 可见
}
self.completed_count.fetch_add(1, Ordering::Release);
@@ -106,6 +106,7 @@ pub async fn execute_parallel(
is_buy: bool,
wait_transaction_confirmed: bool,
with_tip: bool,
gas_fee_strategy: GasFeeStrategy,
) -> Result<(bool, Signature)> {
let _exec_start = Instant::now();
@@ -133,7 +134,7 @@ pub async fn execute_parallel(
with_tip || matches!(swqos_client.get_swqos_type(), SwqosType::Default)
})
.flat_map(|(i, swqos_client)| {
let gas_fee_strategy_configs = GasFeeStrategy::get_strategies(if is_buy {
let gas_fee_strategy_configs = gas_fee_strategy.get_strategies(if is_buy {
TradeType::Buy
} else {
TradeType::Sell
@@ -229,11 +230,7 @@ pub async fn execute_parallel(
// Transaction sent
if let Some(signature) = transaction.signatures.first() {
collector.submit(TaskResult {
success,
signature: *signature,
_error: None,
});
collector.submit(TaskResult { success, signature: *signature, _error: None });
}
});
}
+1
View File
@@ -96,6 +96,7 @@ impl TradeExecutor for GenericTradeExecutor {
is_buy,
params.wait_transaction_confirmed,
if is_buy { true } else { params.with_tip },
params.gas_fee_strategy,
)
.await;
let send_elapsed = send_start.elapsed();
+2 -1
View File
@@ -2,7 +2,7 @@ use super::traits::ProtocolParams;
use crate::common::bonding_curve::BondingCurveAccount;
use crate::common::nonce_cache::DurableNonceInfo;
use crate::common::spl_associated_token_account::get_associated_token_address_with_program_id;
use crate::common::SolanaRpcClient;
use crate::common::{GasFeeStrategy, SolanaRpcClient};
use crate::constants::TOKEN_PROGRAM;
use crate::swqos::{SwqosClient, TradeType};
use crate::trading::common::get_multi_token_balances;
@@ -39,6 +39,7 @@ pub struct SwapParams {
pub create_output_mint_ata: bool,
pub close_output_mint_ata: bool,
pub fixed_output_amount: Option<u64>,
pub gas_fee_strategy: GasFeeStrategy,
}
impl std::fmt::Debug for SwapParams {