From 26311e9796ad20a20d0da4c671a3264d7638a790 Mon Sep 17 00:00:00 2001 From: Wood Date: Fri, 28 Nov 2025 06:40:05 +0800 Subject: [PATCH 1/2] feat: return native Solana InstructionError code in TradeError - Simplify error code handling by directly returning Solana's native InstructionError codes - Custom errors return their embedded code directly - Standard InstructionError variants map to fixed codes (1-10, 999) - Remove nested match pattern for better code readability - Error format: buy_failed|sig={signature}|code={error_code}|msg={message} Benefits: - More accurate error identification using native Solana error codes - Simpler and cleaner code structure - Easier to maintain and extend - Consistent with Solana ecosystem standards --- src/swqos/common.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/swqos/common.rs b/src/swqos/common.rs index 443d855..80f3451 100755 --- a/src/swqos/common.rs +++ b/src/swqos/common.rs @@ -133,18 +133,32 @@ pub async fn poll_transaction_confirmation( let ui_err = meta.err.unwrap(); let tx_err: TransactionError = serde_json::from_value(serde_json::to_value(&ui_err)?)?; - let mut code = 500; + + // 直接使用Solana原生的InstructionError中的错误码 + let mut code = 0u32; let mut index = None; match &tx_err { TransactionError::InstructionError(i, i_error) => { - match i_error { - solana_sdk::instruction::InstructionError::Custom(c) => code = *c, - _ => {} - } + // 直接匹配所有InstructionError类型,Custom也是其中之一 + code = match i_error { + solana_sdk::instruction::InstructionError::Custom(c) => *c, + solana_sdk::instruction::InstructionError::GenericError => 1, + solana_sdk::instruction::InstructionError::InvalidArgument => 2, + solana_sdk::instruction::InstructionError::InvalidInstructionData => 3, + solana_sdk::instruction::InstructionError::InvalidAccountData => 4, + solana_sdk::instruction::InstructionError::AccountDataTooSmall => 5, + solana_sdk::instruction::InstructionError::InsufficientFunds => 6, + solana_sdk::instruction::InstructionError::IncorrectProgramId => 7, + solana_sdk::instruction::InstructionError::MissingRequiredSignature => 8, + solana_sdk::instruction::InstructionError::AccountAlreadyInitialized => 9, + solana_sdk::instruction::InstructionError::UninitializedAccount => 10, + _ => 999, // 其他未知错误 + }; index = Some(*i); } _ => {} } + return Err(anyhow::Error::new(TradeError { code: code, message: format!("{} {:?}", tx_err, error_msg), From de8c55e599fa58e35e3f3dc68437f8ae4712d4ba Mon Sep 17 00:00:00 2001 From: Wood Date: Mon, 1 Dec 2025 00:11:38 +0800 Subject: [PATCH 2/2] feat: add dynamic compute unit price update methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加动态优先费更新方法 ## 新增方法 - update_buy_cu_price(): 动态更新买入优先费 - update_sell_cu_price(): 动态更新卖出优先费 ## 功能 - 保持其他策略参数不变,仅更新 cu_price - 使用 RCU 模式确保线程安全 - 支持所有 SwqosType 和 GasFeeStrategyType ## 应用场景 - 根据交易金额动态调整优先费 - 实时优化 gas 费用策略 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/common/gas_fee_strategy.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/common/gas_fee_strategy.rs b/src/common/gas_fee_strategy.rs index 6f2457a..6feca49 100644 --- a/src/common/gas_fee_strategy.rs +++ b/src/common/gas_fee_strategy.rs @@ -345,6 +345,34 @@ impl GasFeeStrategy { }); } + /// 动态更新买入优先费(保持其他参数不变) + /// Dynamically update buy compute unit price (keep other parameters unchanged) + pub fn update_buy_cu_price(&self, buy_cu_price: u64) { + self.strategies.rcu(|current_map| { + let mut new_map = (**current_map).clone(); + for ((swqos_type, trade_type, strategy_type), value) in new_map.iter_mut() { + if *trade_type == TradeType::Buy { + value.cu_price = buy_cu_price; + } + } + Arc::new(new_map) + }); + } + + /// 动态更新卖出优先费(保持其他参数不变) + /// Dynamically update sell compute unit price (keep other parameters unchanged) + pub fn update_sell_cu_price(&self, sell_cu_price: u64) { + self.strategies.rcu(|current_map| { + let mut new_map = (**current_map).clone(); + for ((swqos_type, trade_type, strategy_type), value) in new_map.iter_mut() { + if *trade_type == TradeType::Sell { + value.cu_price = sell_cu_price; + } + } + Arc::new(new_map) + }); + } + /// 打印所有策略。 /// Print all strategies pub fn print_all_strategies(&self) {