From 2c52306a7976d7a1d681bfa33a496bb76298c680 Mon Sep 17 00:00:00 2001 From: ysq Date: Fri, 26 Sep 2025 00:07:39 +0800 Subject: [PATCH] feat: refactor GasFeeStrategy API and bump version to 1.2.2 --- Cargo.toml | 2 +- README.md | 4 ++-- README_CN.md | 4 ++-- examples/gas_fee_strategy/src/main.rs | 2 +- src/common/gas_fee_strategy.rs | 31 ++++++++++++++++++++------- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 71f2d99..affa5ad 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sol-trade-sdk" -version = "1.2.1" +version = "1.2.2" edition = "2021" authors = [ "William ", diff --git a/README.md b/README.md index 4e73b12..afe9f99 100644 --- a/README.md +++ b/README.md @@ -87,14 +87,14 @@ Add the dependency to your `Cargo.toml`: ```toml # Add to your Cargo.toml -sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.2.1" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.2.2" } ``` ### Use crates.io ```toml # Add to your Cargo.toml -sol-trade-sdk = "1.2.1" +sol-trade-sdk = "1.2.2" ``` ## 🛠️ Usage Examples diff --git a/README_CN.md b/README_CN.md index b20680f..6012855 100755 --- a/README_CN.md +++ b/README_CN.md @@ -87,14 +87,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk ```toml # 添加到您的 Cargo.toml -sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.2.1" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "1.2.2" } ``` ### 使用 crates.io ```toml # 添加到您的 Cargo.toml -sol-trade-sdk = "1.2.1" +sol-trade-sdk = "1.2.2" ``` ## 🛠️ 使用示例 diff --git a/examples/gas_fee_strategy/src/main.rs b/examples/gas_fee_strategy/src/main.rs index 0163679..c8c1c95 100644 --- a/examples/gas_fee_strategy/src/main.rs +++ b/examples/gas_fee_strategy/src/main.rs @@ -62,7 +62,7 @@ async fn main() { // Remove strategy for SwqosType::Jito on Buy println!("\n9. Remove strategy for SwqosType::Jito on Buy"); - GasFeeStrategy::del(SwqosType::Jito, TradeType::Buy); + GasFeeStrategy::del_all(SwqosType::Jito, TradeType::Buy); // Print all strategies println!("\n10. Print all current strategies"); diff --git a/src/common/gas_fee_strategy.rs b/src/common/gas_fee_strategy.rs index 3d1d7b4..0407837 100644 --- a/src/common/gas_fee_strategy.rs +++ b/src/common/gas_fee_strategy.rs @@ -84,7 +84,7 @@ impl GasFeeStrategy { high_tip: f64, ) { for swqos_type in swqos_types { - GasFeeStrategy::del(*swqos_type, trade_type); + GasFeeStrategy::del(*swqos_type, trade_type, GasFeeStrategyType::Normal); GasFeeStrategy::set( *swqos_type, trade_type, @@ -118,7 +118,7 @@ impl GasFeeStrategy { if swqos_type.eq(&SwqosType::Default) { return; } - GasFeeStrategy::del(swqos_type, trade_type); + GasFeeStrategy::del(swqos_type, trade_type, GasFeeStrategyType::Normal); GasFeeStrategy::set( swqos_type, trade_type, @@ -147,8 +147,8 @@ impl GasFeeStrategy { sell_tip: f64, ) { for swqos_type in swqos_types { - GasFeeStrategy::del(*swqos_type, TradeType::Buy); - GasFeeStrategy::del(*swqos_type, TradeType::Sell); + GasFeeStrategy::del_all(*swqos_type, TradeType::Buy); + GasFeeStrategy::del_all(*swqos_type, TradeType::Sell); GasFeeStrategy::set( *swqos_type, TradeType::Buy, @@ -175,8 +175,8 @@ impl GasFeeStrategy { buy_tip: f64, sell_tip: f64, ) { - GasFeeStrategy::del(swqos_type, TradeType::Buy); - GasFeeStrategy::del(swqos_type, TradeType::Sell); + GasFeeStrategy::del_all(swqos_type, TradeType::Buy); + GasFeeStrategy::del_all(swqos_type, TradeType::Sell); GasFeeStrategy::set( swqos_type, TradeType::Buy, @@ -203,7 +203,12 @@ impl GasFeeStrategy { cu_price: u64, tip: f64, ) { - GasFeeStrategy::del(swqos_type, trade_type); + if strategy_type == GasFeeStrategyType::Normal { + GasFeeStrategy::del(swqos_type, trade_type, GasFeeStrategyType::HighTipLowCuPrice); + GasFeeStrategy::del(swqos_type, trade_type, GasFeeStrategyType::LowTipHighCuPrice); + } else { + GasFeeStrategy::del(swqos_type, trade_type, GasFeeStrategyType::Normal); + } STRATEGIES.rcu(|current_map| { let mut new_map = (**current_map).clone(); new_map.insert( @@ -216,7 +221,7 @@ impl GasFeeStrategy { /// 移除指定(SwqosType,TradeType)的策略。 /// Remove strategy for specified (SwqosType,TradeType) - pub fn del(swqos_type: SwqosType, trade_type: TradeType) { + pub fn del_all(swqos_type: SwqosType, trade_type: TradeType) { STRATEGIES.rcu(|current_map| { let mut new_map = (**current_map).clone(); new_map.remove(&(swqos_type, trade_type, GasFeeStrategyType::Normal)); @@ -226,6 +231,16 @@ impl GasFeeStrategy { }); } + /// 移除指定(SwqosType,TradeType,GasFeeStrategyType)的策略。 + /// Remove strategy for specified (SwqosType,TradeType,GasFeeStrategyType) + pub fn del(swqos_type: SwqosType, trade_type: TradeType, strategy_type: GasFeeStrategyType) { + STRATEGIES.rcu(|current_map| { + let mut new_map = (**current_map).clone(); + new_map.remove(&(swqos_type, trade_type, strategy_type)); + Arc::new(new_map) + }); + } + /// 获取指定交易类型的所有策略。 /// Get all strategies for specified trade type pub fn get_strategies(