refactor(gas-fee): Refactor Gas Fee Strategy API
- Rename add_* methods to set_* for clarity - Simplify normal strategy API (remove TradeType param) - Expose set/del methods for flexible strategy management - Update docs and examples to match new API BREAKING CHANGE: Method names changed for Gas Fee Strategy
This commit is contained in:
@@ -30,12 +30,12 @@ GasFeeStrategy::set_global_fee_strategy(
|
||||
|
||||
```rust
|
||||
// Configure normal strategy for SwqosType::Jito during Buy
|
||||
GasFeeStrategy::add_normal_fee_strategy(
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
TradeType::Buy,
|
||||
xxxxx, // cu_limit
|
||||
xxxx, // cu_price
|
||||
xxxxx // tip
|
||||
xxxxx, // buy_tip
|
||||
xxxxx, // sell_tip
|
||||
);
|
||||
```
|
||||
|
||||
@@ -43,7 +43,7 @@ GasFeeStrategy::add_normal_fee_strategy(
|
||||
|
||||
```rust
|
||||
// Configure high-low fee strategy for SwqosType::Jito during Buy
|
||||
GasFeeStrategy::add_high_low_fee_strategy(
|
||||
GasFeeStrategy::set_high_low_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
TradeType::Buy,
|
||||
xxxxx, // cu_limit
|
||||
@@ -58,7 +58,7 @@ GasFeeStrategy::add_high_low_fee_strategy(
|
||||
|
||||
```rust
|
||||
// Remove a specific strategy
|
||||
GasFeeStrategy::remove_strategy(SwqosType::Jito, TradeType::Buy);
|
||||
GasFeeStrategy::del(SwqosType::Jito, TradeType::Buy);
|
||||
// View all strategies
|
||||
GasFeeStrategy::print_all_strategies();
|
||||
// Clear all strategies
|
||||
|
||||
@@ -30,12 +30,12 @@ GasFeeStrategy::set_global_fee_strategy(
|
||||
|
||||
```rust
|
||||
// 为 SwqosType::Jito 在 Buy 时配置 normal 策略
|
||||
GasFeeStrategy::add_normal_fee_strategy(
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
TradeType::Buy,
|
||||
xxxxx, // cu_limit
|
||||
xxxx, // cu_price
|
||||
xxxxx // tip
|
||||
xxxxx, // buy_tip
|
||||
xxxxx // sell_tip
|
||||
);
|
||||
```
|
||||
|
||||
@@ -43,7 +43,7 @@ GasFeeStrategy::add_normal_fee_strategy(
|
||||
|
||||
```rust
|
||||
// 为 SwqosType::Jito 在 Buy 时配置高低费率策略
|
||||
GasFeeStrategy::add_high_low_fee_strategy(
|
||||
GasFeeStrategy::set_high_low_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
TradeType::Buy,
|
||||
xxxxx, // cu_limit
|
||||
@@ -58,7 +58,7 @@ GasFeeStrategy::add_high_low_fee_strategy(
|
||||
|
||||
```rust
|
||||
// 移除某个策略
|
||||
GasFeeStrategy::remove_strategy(SwqosType::Jito, TradeType::Buy);
|
||||
GasFeeStrategy::del(SwqosType::Jito, TradeType::Buy);
|
||||
// 查看所有策略
|
||||
GasFeeStrategy::print_all_strategies();
|
||||
// 清空所有策略
|
||||
|
||||
@@ -20,19 +20,19 @@ async fn main() {
|
||||
println!("\n3. Clear all strategies");
|
||||
GasFeeStrategy::clear();
|
||||
|
||||
// Add normal fee strategy for SwqosType::Default on Buy
|
||||
println!("\n4. Add normal fee strategy for SwqosType::Default on Buy");
|
||||
GasFeeStrategy::add_normal_fee_strategy(
|
||||
// Add normal fee strategy for SwqosType::Default
|
||||
println!("\n4. Add normal fee strategy for SwqosType::Default");
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
SwqosType::Default,
|
||||
TradeType::Buy,
|
||||
150000, // cu_limit
|
||||
500000, // cu_price
|
||||
0.0, // tip
|
||||
0.0, // buy_tip
|
||||
0.0, // sell_tip
|
||||
);
|
||||
|
||||
// Add high-low fee strategy for SwqosType::Jito on Buy
|
||||
println!("\n5. Add high-low fee strategy for SwqosType::Jito on Buy");
|
||||
GasFeeStrategy::add_high_low_fee_strategy(
|
||||
GasFeeStrategy::set_high_low_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
TradeType::Buy,
|
||||
150000, // cu_limit
|
||||
@@ -47,13 +47,13 @@ async fn main() {
|
||||
GasFeeStrategy::print_all_strategies();
|
||||
|
||||
// Add normal fee strategy for SwqosType::Jito on Buy (will override previous high-low strategy)
|
||||
println!("\n7. Add normal fee strategy for SwqosType::Jito on Buy (will override previous high-low strategy)");
|
||||
GasFeeStrategy::add_normal_fee_strategy(
|
||||
println!("\n7. Add normal fee strategy for SwqosType::Jito (will override previous high-low strategy)");
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
TradeType::Buy,
|
||||
150000, // cu_limit
|
||||
500000, // cu_price
|
||||
0.0001, // tip
|
||||
0.0001, // buy_tip
|
||||
0.0001, // sell_tip
|
||||
);
|
||||
|
||||
// Print all strategies
|
||||
@@ -62,7 +62,7 @@ async fn main() {
|
||||
|
||||
// Remove strategy for SwqosType::Jito on Buy
|
||||
println!("\n9. Remove strategy for SwqosType::Jito on Buy");
|
||||
GasFeeStrategy::remove_strategy(SwqosType::Jito, TradeType::Buy);
|
||||
GasFeeStrategy::del(SwqosType::Jito, TradeType::Buy);
|
||||
|
||||
// Print all strategies
|
||||
println!("\n10. Print all current strategies");
|
||||
|
||||
+101
-18
@@ -37,15 +37,37 @@ impl GasFeeStrategy {
|
||||
if swqos_type.eq(&SwqosType::Default) {
|
||||
continue;
|
||||
}
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Buy, cu_limit, cu_price, buy_tip);
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Sell, cu_limit, cu_price, sell_tip);
|
||||
GasFeeStrategy::set(
|
||||
swqos_type,
|
||||
TradeType::Buy,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
buy_tip,
|
||||
);
|
||||
GasFeeStrategy::set(
|
||||
swqos_type,
|
||||
TradeType::Sell,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
sell_tip,
|
||||
);
|
||||
}
|
||||
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
GasFeeStrategy::set(
|
||||
SwqosType::Default,
|
||||
TradeType::Buy,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
0.0,
|
||||
);
|
||||
GasFeeStrategy::set(
|
||||
SwqosType::Default,
|
||||
TradeType::Sell,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
0.0,
|
||||
);
|
||||
}
|
||||
@@ -63,11 +85,25 @@ impl GasFeeStrategy {
|
||||
) {
|
||||
for swqos_type in swqos_types {
|
||||
GasFeeStrategy::del(*swqos_type, trade_type);
|
||||
GasFeeStrategy::set(*swqos_type, trade_type, cu_limit, high_cu_price, low_tip);
|
||||
GasFeeStrategy::set(*swqos_type, trade_type, cu_limit, low_cu_price, high_tip);
|
||||
GasFeeStrategy::set(
|
||||
*swqos_type,
|
||||
trade_type,
|
||||
GasFeeStrategyType::LowTipHighCuPrice,
|
||||
cu_limit,
|
||||
high_cu_price,
|
||||
low_tip,
|
||||
);
|
||||
GasFeeStrategy::set(
|
||||
*swqos_type,
|
||||
trade_type,
|
||||
GasFeeStrategyType::HighTipLowCuPrice,
|
||||
cu_limit,
|
||||
low_cu_price,
|
||||
high_tip,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 为单个服务类型添加高低费率策略,会移除(SwqosType,TradeType)的默认策略。
|
||||
/// Add high-low fee strategy for a single service type, Will remove the default strategy of (SwqosType,TradeType)
|
||||
pub fn set_high_low_fee_strategy(
|
||||
@@ -83,22 +119,52 @@ impl GasFeeStrategy {
|
||||
return;
|
||||
}
|
||||
GasFeeStrategy::del(swqos_type, trade_type);
|
||||
GasFeeStrategy::set(swqos_type, trade_type, cu_limit, high_cu_price, low_tip);
|
||||
GasFeeStrategy::set(swqos_type, trade_type, cu_limit, low_cu_price, high_tip);
|
||||
GasFeeStrategy::set(
|
||||
swqos_type,
|
||||
trade_type,
|
||||
GasFeeStrategyType::LowTipHighCuPrice,
|
||||
cu_limit,
|
||||
high_cu_price,
|
||||
low_tip,
|
||||
);
|
||||
GasFeeStrategy::set(
|
||||
swqos_type,
|
||||
trade_type,
|
||||
GasFeeStrategyType::HighTipLowCuPrice,
|
||||
cu_limit,
|
||||
low_cu_price,
|
||||
high_tip,
|
||||
);
|
||||
}
|
||||
|
||||
/// 为多个服务类型添加标准费率策略,会移除(SwqosType,TradeType)的高低价策略。
|
||||
/// Add normal fee strategies for multiple service types, Will remove the high-low strategies of (SwqosType,TradeType)
|
||||
pub fn set_normal_fee_strategies(
|
||||
swqos_types: &[SwqosType],
|
||||
trade_type: TradeType,
|
||||
cu_limit: u32,
|
||||
cu_price: u64,
|
||||
tip: f64,
|
||||
buy_tip: f64,
|
||||
sell_tip: f64,
|
||||
) {
|
||||
for swqos_type in swqos_types {
|
||||
GasFeeStrategy::del(*swqos_type, trade_type);
|
||||
GasFeeStrategy::set(*swqos_type, trade_type, cu_limit, cu_price, tip);
|
||||
GasFeeStrategy::del(*swqos_type, TradeType::Buy);
|
||||
GasFeeStrategy::del(*swqos_type, TradeType::Sell);
|
||||
GasFeeStrategy::set(
|
||||
*swqos_type,
|
||||
TradeType::Buy,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
buy_tip,
|
||||
);
|
||||
GasFeeStrategy::set(
|
||||
*swqos_type,
|
||||
TradeType::Sell,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
sell_tip,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,13 +175,30 @@ impl GasFeeStrategy {
|
||||
buy_tip: f64,
|
||||
sell_tip: f64,
|
||||
) {
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Buy, cu_limit, cu_price, buy_tip);
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Sell, cu_limit, cu_price, sell_tip);
|
||||
GasFeeStrategy::del(swqos_type, TradeType::Buy);
|
||||
GasFeeStrategy::del(swqos_type, TradeType::Sell);
|
||||
GasFeeStrategy::set(
|
||||
swqos_type,
|
||||
TradeType::Buy,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
buy_tip,
|
||||
);
|
||||
GasFeeStrategy::set(
|
||||
swqos_type,
|
||||
TradeType::Sell,
|
||||
GasFeeStrategyType::Normal,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
sell_tip,
|
||||
);
|
||||
}
|
||||
|
||||
fn set(
|
||||
pub fn set(
|
||||
swqos_type: SwqosType,
|
||||
trade_type: TradeType,
|
||||
strategy_type: GasFeeStrategyType,
|
||||
cu_limit: u32,
|
||||
cu_price: u64,
|
||||
tip: f64,
|
||||
@@ -124,7 +207,7 @@ impl GasFeeStrategy {
|
||||
STRATEGIES.rcu(|current_map| {
|
||||
let mut new_map = (**current_map).clone();
|
||||
new_map.insert(
|
||||
(swqos_type, trade_type, GasFeeStrategyType::Normal),
|
||||
(swqos_type, trade_type, strategy_type),
|
||||
GasFeeStrategyValue { cu_limit, cu_price, tip },
|
||||
);
|
||||
Arc::new(new_map)
|
||||
@@ -133,7 +216,7 @@ impl GasFeeStrategy {
|
||||
|
||||
/// 移除指定(SwqosType,TradeType)的策略。
|
||||
/// Remove strategy for specified (SwqosType,TradeType)
|
||||
fn del(swqos_type: SwqosType, trade_type: TradeType) {
|
||||
pub fn del(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));
|
||||
|
||||
Reference in New Issue
Block a user