refactor: split seed optimization config into wsol_use_seed and mint_use_seed

- Split use_seed_optimize parameter into two independent configs:
  * wsol_use_seed: controls seed optimization for WSOL ATA operations (default: false)
  * mint_use_seed: controls seed optimization for other mint ATA operations (default: true)

- Refactor TradeConfig to accept all parameters in new() constructor
- Remove deprecated builder methods (with_seed_config, with_wsol_ata_config)

- Add wsol_use_seed and mint_use_seed fields to SwapParams
- Remove open_seed_optimize field from SwapParams

- Update all instruction builders to use correct seed parameter:
  * Use params.wsol_use_seed for WSOL token operations
  * Use params.mint_use_seed for other token operations
  * Fix token type detection in bonk.rs, raydium_cpmm.rs, and raydium_amm_v4.rs
    to properly select wsol_use_seed when dealing with WSOL tokens

- Update wsol_manager functions to accept is_use_seed parameter:
  * handle_wsol()
  * close_wsol()
  * create_wsol_ata()
  * wrap_sol_only()
  * wrap_wsol_to_sol()

- Add wrap_wsol_to_sol() function with smart temporary account selection:
  * If source is seed-created, use normal ATA for temp account
  * If source is normal ATA, use seed ATA for temp account
  * Prevents address conflicts while optimizing performance

This provides fine-grained control over seed optimization strategies,
allowing different configurations for WSOL and other tokens.
This commit is contained in:
Wood
2025-11-21 13:05:39 +08:00
parent c0e026a88a
commit eb8de36f50
11 changed files with 196 additions and 135 deletions
+20 -8
View File
@@ -8,7 +8,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🔄 WSOL Wrapper Example");
println!("This example demonstrates:");
println!("1. Wrapping SOL to WSOL");
println!("2. Partial unwrapping WSOL back to SOL using seed account");
println!("2. Partial unwrapping WSOL back to SOL using temporary account");
println!("3. Closing WSOL account and unwrapping remaining balance");
// Initialize SolanaTrade client
@@ -18,8 +18,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("\n📦 Example 1: Wrapping SOL to WSOL");
let wrap_amount = 1_000_000; // 0.001 SOL in lamports
println!("Wrapping {} lamports (0.001 SOL) to WSOL...", wrap_amount);
let is_use_seed = false; // 设置是否使用seed优化
match solana_trade.wrap_sol_to_wsol(wrap_amount).await {
match solana_trade.wrap_sol_to_wsol(wrap_amount, is_use_seed).await {
Ok(signature) => {
println!("✅ Successfully wrapped SOL to WSOL!");
println!("Transaction signature: {}", signature);
@@ -36,13 +37,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
// Example 2: Unwrap half of the WSOL back to SOL using seed account
println!("\n🔄 Example 2: Unwrapping half of WSOL back to SOL using seed account");
println!("\n🔄 Example 2: Unwrapping half of WSOL back to SOL using temporary account");
let unwrap_amount = wrap_amount / 2; // Half of the wrapped amount
println!("Unwrapping {} lamports (0.0005 SOL) back to SOL using seed account...", unwrap_amount);
println!("Unwrapping {} lamports (0.0005 SOL) back to SOL using temporary account...", unwrap_amount);
match solana_trade.wrap_wsol_to_sol(unwrap_amount).await {
// 假设我们的WSOL ATA是使用seed创建的(根据实际情况设置)
// 如果是seed创建的,设置为true;如果是普通ATA,设置为false
let source_is_seed = is_use_seed; // 与is_use_seed保持一致
match solana_trade.wrap_wsol_to_sol(unwrap_amount, source_is_seed).await {
Ok(signature) => {
println!("✅ Successfully unwrapped half of WSOL back to SOL using seed account!");
println!("✅ Successfully unwrapped half of WSOL back to SOL using temporary account!");
println!("Transaction signature: {}", signature);
println!("Explorer: https://solscan.io/tx/{}", signature);
}
@@ -59,7 +64,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("\n🔒 Example 3: Closing WSOL account and unwrapping remaining balance");
println!("Closing WSOL account and unwrapping all remaining balance to SOL...");
match solana_trade.close_wsol().await {
match solana_trade.close_wsol(is_use_seed).await {
Ok(signature) => {
println!("✅ Successfully closed WSOL account and unwrapped remaining balance!");
println!("Transaction signature: {}", signature);
@@ -81,7 +86,14 @@ async fn create_solana_trade_client() -> Result<SolanaTrade, Box<dyn std::error:
let rpc_url = "https://api.mainnet-beta.solana.com".to_string();
let commitment = CommitmentConfig::confirmed();
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
let trade_config = TradeConfig::new(
rpc_url,
swqos_configs,
commitment,
true, // create_wsol_ata_on_startup
false, // wsol_use_seed
true, // mint_use_seed
);
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
println!("✅ SolanaTrade client initialized successfully!");
Ok(solana_trade)