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) { 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),