feat: refactor seed optimization to global configuration in v3.2.0

- Remove open_seed_optimize parameter from TradeBuyParams and TradeSellParams structs
- Add global use_seed_optimize configuration in TradeConfig with default value true
- Add create_wsol_ata_on_startup configuration in TradeConfig with default value true
- Implement automatic WSOL ATA creation and verification on SDK initialization
- Add with_wsol_ata_config() builder method to TradeConfig for custom WSOL settings
- Update all examples to remove open_seed_optimize parameter usage
- Update documentation (README, TRADING_PARAMETERS) to reflect new configuration approach
- Upgrade package version from 3.1.7 to 3.2.0

Breaking Changes:
- open_seed_optimize parameter removed from trade parameters (now global setting)
- Seed optimization is now enabled by default for all operations
This commit is contained in:
ysq
2025-11-07 16:57:28 +08:00
parent 9824576164
commit c5a55b1c14
23 changed files with 173 additions and 74 deletions
+12 -4
View File
@@ -34,7 +34,6 @@ The `TradeBuyParams` struct contains all parameters required for executing buy o
| `create_input_token_ata` | `bool` | ✅ | Whether to create input token Associated Token Account |
| `close_input_token_ata` | `bool` | ✅ | Whether to close input token ATA after transaction |
| `create_mint_ata` | `bool` | ✅ | Whether to create token mint ATA |
| `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 |
@@ -66,7 +65,6 @@ The `TradeSellParams` struct contains all parameters required for executing sell
| `wait_transaction_confirmed` | `bool` | ✅ | Whether to wait for transaction confirmation |
| `create_output_token_ata` | `bool` | ✅ | Whether to create output token Associated Token Account |
| `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) |
@@ -105,7 +103,6 @@ These parameters control automatic account creation and management:
These parameters enable advanced optimizations:
- **address_lookup_table_account**: Use address lookup tables for reduced transaction size
- **open_seed_optimize**: Use seed-based account creation for lower CU consumption
### 🔄 Token Type Parameters
@@ -123,7 +120,18 @@ When you need to use durable nonce, you need to fill in this parameter:
### 🌱 Seed Optimization
When `open_seed_optimize: true`:
Seed optimization is now configured globally in `TradeConfig` when creating the `SolanaTrade` instance:
```rust
// Enable seed optimization globally (default: true)
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment)
.with_wsol_ata_config(
true, // create_wsol_ata_on_startup: Check and create WSOL ATA on startup (default: true)
true // use_seed_optimize: Enable seed optimization for all ATA operations (default: true)
);
```
When seed optimization is enabled:
- ⚠️ **Warning**: Tokens purchased with seed optimization must be sold through this SDK
- ⚠️ **Warning**: Official platform selling methods may fail
- 📝 **Note**: Use `get_associated_token_address_with_program_id_fast_use_seed` to get ATA addresses
+12 -4
View File
@@ -34,7 +34,6 @@
| `create_input_token_ata` | `bool` | ✅ | 是否创建输入代币关联代币账户 |
| `close_input_token_ata` | `bool` | ✅ | 交易后是否关闭输入代币 ATA |
| `create_mint_ata` | `bool` | ✅ | 是否创建代币 mint ATA |
| `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 策略实例,用于控制交易费用和优先级 |
@@ -66,7 +65,6 @@
| `wait_transaction_confirmed` | `bool` | ✅ | 是否等待交易确认 |
| `create_output_token_ata` | `bool` | ✅ | 是否创建输出代币关联代币账户 |
| `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 必需) |
@@ -105,7 +103,6 @@
这些参数启用高级优化:
- **address_lookup_table_account**: 使用地址查找表减少交易大小
- **open_seed_optimize**: 使用基于 seed 的账户创建以降低 CU 消耗
### 🔄 代币类型参数
@@ -123,7 +120,18 @@
### 🌱 Seed 优化
`open_seed_optimize: true`
Seed 优化现在在创建 `SolanaTrade` 实例时通过 `TradeConfig` 全局配置
```rust
// 全局启用 seed 优化(默认: true
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment)
.with_wsol_ata_config(
true, // create_wsol_ata_on_startup: 启动时检查并创建 WSOL ATA(默认: true
true // use_seed_optimize: 为所有 ATA 操作启用 seed 优化(默认: true
);
```
当 seed 优化启用时:
- ⚠️ **警告**: 使用 seed 优化购买的代币必须通过此 SDK 出售
- ⚠️ **警告**: 官方平台的出售方法可能会失败
- 📝 **注意**: 使用 `get_associated_token_address_with_program_id_fast_use_seed` 获取 ATA 地址