feat: add gas fee strategy system with examples

- Add GasFeeStrategy module supporting normal and high-low fee strategies
- Initialize gas fee strategies in all examples
- Update documentation and README with gas fee strategy configuration
- Improve nonce cache documentation emphasizing latest nonce usage
- Adjust default gas fee configuration parameters
- Remove duplicate imports and unused constant references
This commit is contained in:
ysq
2025-09-19 15:46:51 +08:00
parent e8abb65e2e
commit a53038855e
27 changed files with 342 additions and 83 deletions
+65
View File
@@ -0,0 +1,65 @@
# 📊 Gas Fee Strategy Guide
This document introduces the Gas Fee strategy configuration and usage methods in Sol Trade SDK.
## Basic Usage
### 1. Overview
This module supports users to configure strategies for SwqosType under different TradeType (buy/sell).
- Normal strategy: One SwqosType sends one transaction, specifying cu_limit, cu_price, and tip.
- High-low fee strategy: One SwqosType sends two transactions simultaneously, one with low tip and high priority fee, another with high tip and low priority fee.
Each (SwqosType, TradeType) combination can only configure one strategy. Subsequent strategy configurations will override previous ones.
### 2. Using Built-in Strategies
```rust
use sol_trade_sdk::common::gas_fee_strategy::GasFeeStrategy;
// Use built-in strategies (includes normal strategies for various SwqosTypes)
GasFeeStrategy::init_builtin_fee_strategies();
```
### 3. Configuring Single Strategy
```rust
// Configure normal strategy for SwqosType::Jito during Buy
GasFeeStrategy::add_normal_fee_strategy(
SwqosType::Jito,
TradeType::Buy,
xxxxx, // cu_limit
xxxx, // cu_price
xxxxx // tip
);
```
### 4. Configuring High-Low Fee Strategy
```rust
// Configure high-low fee strategy for SwqosType::Jito during Buy
GasFeeStrategy::add_high_low_fee_strategy(
SwqosType::Jito,
TradeType::Buy,
xxxxx, // cu_limit
xxxxx, // low cu_price
xxxxx, // high cu_price
xxxxx, // low tip
xxxxx // high tip
);
```
### 5. Viewing and Cleanup
```rust
// Remove a specific strategy
GasFeeStrategy::remove_strategy(SwqosType::Jito, TradeType::Buy);
// View all strategies
GasFeeStrategy::print_all_strategies();
// Clear all strategies
GasFeeStrategy::clear();
```
## 🔗 Related Documents
- [Example: Gas Fee Strategy](../examples/gas_fee_strategy/)
+65
View File
@@ -0,0 +1,65 @@
# 📊 Gas Fee 策略指南
本文档介绍 Sol Trade SDK 中的 Gas Fee 策略配置和使用方法。
## 基础使用
### 1. 说明
该模块支持用户配置 SwqosType 在不同 TradeType(buy/sell) 下的策略。
- normal 策略: 一个 SwqosType 发送一笔交易,指定 cu_limit、cu_price 和小费。
- 高低费率策略: 一个 SwqosType 同时发送两笔交易,一笔低小费高优先费,一笔高小费低优先费。
每个 (SwqosType, TradeType) 的组合仅可配置一个策略。后续配置的策略会覆盖之前的策略。
### 2. 使用内置策略
```rust
use sol_trade_sdk::common::gas_fee_strategy::GasFeeStrategy;
// 使用内置策略(内置了各个 SwqosType 的 normal 策略)
GasFeeStrategy::init_builtin_fee_strategies();
```
### 3. 配置单个策略
```rust
// 为 SwqosType::Jito 在 Buy 时配置 normal 策略
GasFeeStrategy::add_normal_fee_strategy(
SwqosType::Jito,
TradeType::Buy,
xxxxx, // cu_limit
xxxx, // cu_price
xxxxx // tip
);
```
### 4. 配置高低费率策略
```rust
// 为 SwqosType::Jito 在 Buy 时配置高低费率策略
GasFeeStrategy::add_high_low_fee_strategy(
SwqosType::Jito,
TradeType::Buy,
xxxxx, // cu_limit
xxxxx, // low cu_price
xxxxx, // high cu_price
xxxxx, // low tip
xxxxx // high tip
);
```
### 5. 查看和清理
```rust
// 移除某个策略
GasFeeStrategy::remove_strategy(SwqosType::Jito, TradeType::Buy);
// 查看所有策略
GasFeeStrategy::print_all_strategies();
// 清空所有策略
GasFeeStrategy::clear();
```
## 🔗 相关文档
- [示例:Gas Fee 策略](../examples/gas_fee_strategy/)
+1 -1
View File
@@ -57,7 +57,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: Some(100),
recent_blockhash: current_nonce, // Use nonce as blockhash
recent_blockhash: current_nonce, // Use nonce as blockhash. Please use the latest nonce value for each transaction.
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: None,
wait_transaction_confirmed: true,
+1 -1
View File
@@ -57,7 +57,7 @@ let buy_params = sol_trade_sdk::TradeBuyParams {
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: Some(100),
recent_blockhash: current_nonce, // 使用 nonce 作为 blockhash
recent_blockhash: current_nonce, // 使用 nonce 作为 blockhash。请在每次交易时,都使用最新的 nonce 值。
extension_params: Box::new(PumpFunParams::from_trade(&trade_info, None)),
lookup_table_key: None,
wait_transaction_confirmed: true,