feat: add flexible nonce parameter support

- Add nonce_account and current_nonce to trade parameters
- Remove hardcoded NonceCache dependency from nonce_manager
- Update examples and documentation for new nonce usage
- Fix nonce documentation errors and improve clarity
This commit is contained in:
ysq
2025-09-19 18:02:11 +08:00
parent a53038855e
commit 4907aafead
26 changed files with 214 additions and 71 deletions
+14 -1
View File
@@ -8,7 +8,7 @@ use tokio::sync::mpsc;
use tokio::task::JoinHandle;
use crate::{
common::GasFeeStrategy,
common::{GasFeeStrategy, SolanaRpcClient},
swqos::{SwqosClient, SwqosType, TradeType},
trading::{common::build_transaction, BuyParams, MiddlewareManager, SellParams},
};
@@ -21,9 +21,12 @@ pub async fn buy_parallel_execute(
parallel_execute(
params.swqos_clients,
params.payer,
params.rpc,
instructions,
params.lookup_table_key,
params.recent_blockhash,
params.nonce_account,
params.current_nonce,
params.data_size_limit,
params.middleware_manager,
protocol_name,
@@ -42,9 +45,12 @@ pub async fn sell_parallel_execute(
parallel_execute(
params.swqos_clients,
params.payer,
params.rpc,
instructions,
params.lookup_table_key,
params.recent_blockhash,
params.nonce_account,
params.current_nonce,
0,
params.middleware_manager,
protocol_name,
@@ -59,9 +65,12 @@ pub async fn sell_parallel_execute(
async fn parallel_execute(
swqos_clients: Vec<Arc<SwqosClient>>,
payer: Arc<Keypair>,
rpc: Option<Arc<SolanaRpcClient>>,
instructions: Vec<Instruction>,
lookup_table_key: Option<Pubkey>,
recent_blockhash: Hash,
nonce_account: Option<Pubkey>,
current_nonce: Option<Hash>,
data_size_limit: u32,
middleware_manager: Option<Arc<MiddlewareManager>>,
protocol_name: &'static str,
@@ -123,6 +132,7 @@ async fn parallel_execute(
let unit_price = gas_fee_strategy_config.2.cu_price;
let swqos_type = swqos_type.clone();
let tip_account = tip_account.clone();
let rpc = rpc.clone();
let handle = tokio::spawn(async move {
core_affinity::set_for_current(core_id);
@@ -133,6 +143,7 @@ async fn parallel_execute(
let transaction = build_transaction(
payer,
rpc,
unit_limit,
unit_price,
instructions.as_ref().clone(),
@@ -145,6 +156,8 @@ async fn parallel_execute(
swqos_type != SwqosType::Default,
&tip_account,
tip_amount,
nonce_account,
current_nonce,
)
.await?;
+4
View File
@@ -35,6 +35,8 @@ pub struct BuyParams {
pub create_wsol_ata: bool,
pub close_wsol_ata: bool,
pub create_mint_ata: bool,
pub nonce_account: Option<Pubkey>,
pub current_nonce: Option<Hash>,
}
/// Sell parameters
@@ -55,6 +57,8 @@ pub struct SellParams {
pub middleware_manager: Option<Arc<MiddlewareManager>>,
pub create_wsol_ata: bool,
pub close_wsol_ata: bool,
pub nonce_account: Option<Pubkey>,
pub current_nonce: Option<Hash>,
}
impl std::fmt::Debug for BuyParams {