refactor: Update GasFeeStrategy to instance-based API and update docs

This commit is contained in:
ysq
2025-10-07 23:12:37 +08:00
parent e13c891cc9
commit 85154f6c01
28 changed files with 269 additions and 120 deletions
+32 -13
View File
@@ -13,12 +13,20 @@ This module supports users to configure strategies for SwqosType under different
Each (SwqosType, TradeType) combination can only configure one strategy. Subsequent strategy configurations will override previous ones.
### 2. Set Global Strategy (can also be configured individually)
### 2. Create GasFeeStrategy Instance
```rust
use sol_trade_sdk::common::GasFeeStrategy;
// Create a new GasFeeStrategy instance
let gas_fee_strategy = GasFeeStrategy::new();
```
### 3. Set Global Strategy (can also be configured individually)
```rust
use sol_trade_sdk::common::{gas_fee_strategy::GasFeeStrategy};
// Set global strategy (normal strategy)
GasFeeStrategy::set_global_fee_strategy(
gas_fee_strategy.set_global_fee_strategy(
150000, // cu_limit
500000, // cu_price
0.001, // buy tip
@@ -26,24 +34,24 @@ GasFeeStrategy::set_global_fee_strategy(
);
```
### 3. Configuring Single Strategy
### 4. Configuring Single Strategy
```rust
// Configure normal strategy for SwqosType::Jito during Buy
GasFeeStrategy::set_normal_fee_strategy(
// Configure normal strategy for SwqosType::Jito
gas_fee_strategy.set_normal_fee_strategy(
SwqosType::Jito,
xxxxx, // cu_limit
xxxx, // cu_price
xxxxx, // buy_tip
xxxxx, // sell_tip
xxxxx // sell_tip
);
```
### 4. Configuring High-Low Fee Strategy
### 5. Configuring High-Low Fee Strategy
```rust
// Configure high-low fee strategy for SwqosType::Jito during Buy
GasFeeStrategy::set_high_low_fee_strategy(
gas_fee_strategy.set_high_low_fee_strategy(
SwqosType::Jito,
TradeType::Buy,
xxxxx, // cu_limit
@@ -54,15 +62,26 @@ GasFeeStrategy::set_high_low_fee_strategy(
);
```
### 5. Viewing and Cleanup
### 6. Using in Trading Parameters
```rust
use sol_trade_sdk::TradeBuyParams;
let buy_params = TradeBuyParams {
// ... other parameters
gas_fee_strategy: gas_fee_strategy.clone(),
};
```
### 7. Viewing and Cleanup
```rust
// Remove a specific strategy
GasFeeStrategy::del(SwqosType::Jito, TradeType::Buy);
gas_fee_strategy.del_all(SwqosType::Jito, TradeType::Buy);
// View all strategies
GasFeeStrategy::print_all_strategies();
gas_fee_strategy.print_all_strategies();
// Clear all strategies
GasFeeStrategy::clear();
gas_fee_strategy.clear();
```
## 🔗 Related Documents
+31 -12
View File
@@ -13,12 +13,20 @@
每个 (SwqosType, TradeType) 的组合仅可配置一个策略。后续配置的策略会覆盖之前的策略。
### 2. 设置全局策略(也可以不设置,单独去配置单个策略)
### 2. 创建 GasFeeStrategy 实例
```rust
use sol_trade_sdk::common::GasFeeStrategy;
// 创建一个新的 GasFeeStrategy 实例
let gas_fee_strategy = GasFeeStrategy::new();
```
### 3. 设置全局策略(也可以不设置,单独去配置单个策略)
```rust
use sol_trade_sdk::common::{gas_fee_strategy::GasFeeStrategy};
// 设置全局策略(normal 策略)
GasFeeStrategy::set_global_fee_strategy(
gas_fee_strategy.set_global_fee_strategy(
150000, // cu_limit
500000, // cu_price
0.001, // buy tip
@@ -26,11 +34,11 @@ GasFeeStrategy::set_global_fee_strategy(
);
```
### 3. 配置单个策略
### 4. 配置单个策略
```rust
// 为 SwqosType::Jito 在 Buy 时配置 normal 策略
GasFeeStrategy::set_normal_fee_strategy(
// 为 SwqosType::Jito 配置 normal 策略
gas_fee_strategy.set_normal_fee_strategy(
SwqosType::Jito,
xxxxx, // cu_limit
xxxx, // cu_price
@@ -39,11 +47,11 @@ GasFeeStrategy::set_normal_fee_strategy(
);
```
### 4. 配置高低费率策略
### 5. 配置高低费率策略
```rust
// 为 SwqosType::Jito 在 Buy 时配置高低费率策略
GasFeeStrategy::set_high_low_fee_strategy(
gas_fee_strategy.set_high_low_fee_strategy(
SwqosType::Jito,
TradeType::Buy,
xxxxx, // cu_limit
@@ -54,15 +62,26 @@ GasFeeStrategy::set_high_low_fee_strategy(
);
```
### 5. 查看和清理
### 6. 在交易参数中使用
```rust
use sol_trade_sdk::TradeBuyParams;
let buy_params = TradeBuyParams {
// ... 其他参数
gas_fee_strategy: gas_fee_strategy.clone(),
};
```
### 7. 查看和清理
```rust
// 移除某个策略
GasFeeStrategy::del(SwqosType::Jito, TradeType::Buy);
gas_fee_strategy.del_all(SwqosType::Jito, TradeType::Buy);
// 查看所有策略
GasFeeStrategy::print_all_strategies();
gas_fee_strategy.print_all_strategies();
// 清空所有策略
GasFeeStrategy::clear();
gas_fee_strategy.clear();
```
## 🔗 相关文档
+2
View File
@@ -37,6 +37,7 @@ The `TradeBuyParams` struct contains all parameters required for executing buy o
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
| `fixed_output_token_amount` | `Option<u64>` | ❌ | Optional fixed output token amount. If set, this value will be directly assigned to the output amount instead of being calculated (required for Meteora DAMM V2) |
| `gas_fee_strategy` | `GasFeeStrategy` | ✅ | Gas fee strategy instance for controlling transaction fees and priorities |
## TradeSellParams
@@ -66,6 +67,7 @@ The `TradeSellParams` struct contains all parameters required for executing sell
| `close_output_token_ata` | `bool` | ✅ | Whether to close output token ATA after transaction |
| `open_seed_optimize` | `bool` | ✅ | Whether to use seed optimization for reduced CU consumption |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | Durable nonce information containing nonce account and current nonce value |
| `gas_fee_strategy` | `GasFeeStrategy` | ✅ | Gas fee strategy instance for controlling transaction fees and priorities |
| `fixed_output_token_amount` | `Option<u64>` | ❌ | Optional fixed output token amount. If set, this value will be directly assigned to the output amount instead of being calculated (required for Meteora DAMM V2) |
+2
View File
@@ -37,6 +37,7 @@
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
| `fixed_output_token_amount` | `Option<u64>` | ❌ | 可选的固定输出代币数量。如果设置,此值将直接分配给输出数量而不是通过计算得出(Meteora DAMM V2 必需) |
| `gas_fee_strategy` | `GasFeeStrategy` | ✅ | Gas fee 策略实例,用于控制交易费用和优先级 |
## TradeSellParams
@@ -66,6 +67,7 @@
| `close_output_token_ata` | `bool` | ✅ | 交易后是否关闭输出代币 ATA |
| `open_seed_optimize` | `bool` | ✅ | 是否使用 seed 优化以减少 CU 消耗 |
| `durable_nonce` | `Option<DurableNonceInfo>` | ❌ | 持久 nonce 信息,包含 nonce 账户和当前 nonce 值 |
| `gas_fee_strategy` | `GasFeeStrategy` | ✅ | Gas fee 策略实例,用于控制交易费用和优先级 |
| `fixed_output_token_amount` | `Option<u64>` | ❌ | 可选的固定输出代币数量。如果设置,此值将直接分配给输出数量而不是通过计算得出(Meteora DAMM V2 必需) |