diff --git a/Cargo.toml b/Cargo.toml index 1bed9cb..dd618d4 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sol-trade-sdk" -version = "3.3.0" +version = "3.3.1" edition = "2021" authors = [ "William ", diff --git a/README.md b/README.md index 096d499..805274f 100644 --- a/README.md +++ b/README.md @@ -87,14 +87,14 @@ Add the dependency to your `Cargo.toml`: ```toml # Add to your Cargo.toml -sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.0" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.1" } ``` ### Use crates.io ```toml # Add to your Cargo.toml -sol-trade-sdk = "3.3.0" +sol-trade-sdk = "3.3.1" ``` ## 🛠️ Usage Examples @@ -146,7 +146,7 @@ For detailed information about Gas Fee Strategy, see the [Gas Fee Strategy Refer // Create GasFeeStrategy instance let gas_fee_strategy = GasFeeStrategy::new(); // Set global strategy -gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); +gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); ``` #### 3. Build Trading Parameters diff --git a/README_CN.md b/README_CN.md index 5606898..35561ef 100755 --- a/README_CN.md +++ b/README_CN.md @@ -87,14 +87,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk ```toml # 添加到您的 Cargo.toml -sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.0" } +sol-trade-sdk = { path = "./sol-trade-sdk", version = "3.3.1" } ``` ### 使用 crates.io ```toml # 添加到您的 Cargo.toml -sol-trade-sdk = "3.3.0" +sol-trade-sdk = "3.3.1" ``` ## 🛠️ 使用示例 @@ -146,7 +146,7 @@ let client = SolanaTrade::new(Arc::new(payer), trade_config).await; // 创建 GasFeeStrategy 实例 let gas_fee_strategy = GasFeeStrategy::new(); // 设置全局策略 -gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); +gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); ``` #### 3. 构建交易参数 diff --git a/examples/address_lookup/src/main.rs b/examples/address_lookup/src/main.rs index 5af43b1..b169058 100644 --- a/examples/address_lookup/src/main.rs +++ b/examples/address_lookup/src/main.rs @@ -125,7 +125,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul fetch_address_lookup_table_account(&client.rpc, &lookup_table_key).await.ok(); let gas_fee_strategy = GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from PumpFun..."); diff --git a/examples/bonk_copy_trading/src/main.rs b/examples/bonk_copy_trading/src/main.rs index 7bc38c0..9c58a01 100644 --- a/examples/bonk_copy_trading/src/main.rs +++ b/examples/bonk_copy_trading/src/main.rs @@ -125,7 +125,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()> let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from Bonk..."); diff --git a/examples/bonk_sniper_trading/src/main.rs b/examples/bonk_sniper_trading/src/main.rs index 5ac165d..c964e39 100644 --- a/examples/bonk_sniper_trading/src/main.rs +++ b/examples/bonk_sniper_trading/src/main.rs @@ -95,7 +95,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult< let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let token_type = if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT { diff --git a/examples/cli_trading/src/main.rs b/examples/cli_trading/src/main.rs index 531a268..09b0c75 100644 --- a/examples/cli_trading/src/main.rs +++ b/examples/cli_trading/src/main.rs @@ -615,7 +615,7 @@ async fn handle_buy_pumpfun( let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let buy_params = TradeBuyParams { dex_type: DexType::PumpFun, @@ -636,7 +636,7 @@ async fn handle_buy_pumpfun( simulate: false, }; match client.buy(buy_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully bought tokens from PumpFun!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -669,7 +669,7 @@ async fn handle_buy_pumpswap( let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let buy_params = TradeBuyParams { dex_type: DexType::PumpSwap, @@ -690,7 +690,7 @@ async fn handle_buy_pumpswap( simulate: false, }; match client.buy(buy_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully bought tokens from PumpSwap!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -722,7 +722,7 @@ async fn handle_buy_bonk( let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let buy_params = TradeBuyParams { dex_type: DexType::Bonk, @@ -743,7 +743,7 @@ async fn handle_buy_bonk( simulate: false, }; match client.buy(buy_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully bought tokens from Bonk!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -779,7 +779,7 @@ async fn handle_buy_raydium_v4( let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let buy_params = TradeBuyParams { dex_type: DexType::RaydiumAmmV4, @@ -800,7 +800,7 @@ async fn handle_buy_raydium_v4( simulate: false, }; match client.buy(buy_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully bought tokens from Raydium V4!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -836,7 +836,7 @@ async fn handle_buy_raydium_cpmm( let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let buy_params = TradeBuyParams { dex_type: DexType::RaydiumCpmm, @@ -857,7 +857,7 @@ async fn handle_buy_raydium_cpmm( simulate: false, }; match client.buy(buy_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully bought tokens from Raydium CPMM!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -1003,7 +1003,7 @@ async fn handle_sell_pumpfun( let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let sell_params = TradeSellParams { dex_type: DexType::PumpFun, @@ -1026,7 +1026,7 @@ async fn handle_sell_pumpfun( }; match client.sell(sell_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully sold tokens from PumpFun!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -1061,7 +1061,7 @@ async fn handle_sell_pumpswap( let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let sell_params = TradeSellParams { dex_type: DexType::PumpSwap, @@ -1083,7 +1083,7 @@ async fn handle_sell_pumpswap( simulate: false, }; match client.sell(sell_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully sold tokens from PumpSwap!"); println!(" ✅ Transaction Signature: {}", signature); } @@ -1118,7 +1118,7 @@ async fn handle_sell_bonk( let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let sell_params = TradeSellParams { dex_type: DexType::Bonk, @@ -1140,7 +1140,7 @@ async fn handle_sell_bonk( simulate: false, }; match client.sell(sell_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully sold tokens from Bonk!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -1178,7 +1178,7 @@ async fn handle_sell_raydium_v4( let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let sell_params = TradeSellParams { dex_type: DexType::RaydiumAmmV4, @@ -1200,7 +1200,7 @@ async fn handle_sell_raydium_v4( simulate: false, }; match client.sell(sell_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully sold tokens from Raydium V4!"); println!(" ✅ Transaction Signature: {:?}", signature); } @@ -1238,7 +1238,7 @@ async fn handle_sell_raydium_cpmm( let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let sell_params = TradeSellParams { dex_type: DexType::RaydiumCpmm, @@ -1260,7 +1260,7 @@ async fn handle_sell_raydium_cpmm( simulate: false, }; match client.sell(sell_params).await { - Ok((_, signature)) => { + Ok((_, signature, _)) => { println!(" ✅ Successfully sold tokens from Raydium CPMM!"); println!(" ✅ Transaction Signature: {:?}", signature); } diff --git a/examples/gas_fee_strategy/src/main.rs b/examples/gas_fee_strategy/src/main.rs index f085d03..7543afb 100644 --- a/examples/gas_fee_strategy/src/main.rs +++ b/examples/gas_fee_strategy/src/main.rs @@ -12,7 +12,7 @@ async fn main() { // Set global strategy println!("1. Set global strategy"); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Print all strategies println!("\n2. Print all strategies"); diff --git a/examples/meteora_damm_v2_direct_trading/src/main.rs b/examples/meteora_damm_v2_direct_trading/src/main.rs index cae7e46..d074960 100644 --- a/examples/meteora_damm_v2_direct_trading/src/main.rs +++ b/examples/meteora_damm_v2_direct_trading/src/main.rs @@ -23,7 +23,7 @@ async fn main() -> Result<(), Box> { let mint_pubkey = Pubkey::from_str("PRVT6TB7uss3FrUd2D9xs2zqDBsa3GbMJMwCQsgmeta").unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from Metaora Damm V2..."); diff --git a/examples/middleware_system/src/main.rs b/examples/middleware_system/src/main.rs index a57d782..53aedb4 100644 --- a/examples/middleware_system/src/main.rs +++ b/examples/middleware_system/src/main.rs @@ -81,7 +81,7 @@ async fn test_middleware() -> AnyResult<()> { let pool_address = Pubkey::from_str("539m4mVWt6iduB6W8rDGPMarzNCMesuqY5eUTiiYHAgR")?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let buy_params = sol_trade_sdk::TradeBuyParams { dex_type: DexType::PumpSwap, diff --git a/examples/nonce_cache/src/main.rs b/examples/nonce_cache/src/main.rs index 836d176..081f8f2 100644 --- a/examples/nonce_cache/src/main.rs +++ b/examples/nonce_cache/src/main.rs @@ -125,7 +125,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul let durable_nonce = fetch_nonce_info(&client.rpc, nonce_account_str).await; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from PumpFun..."); diff --git a/examples/pumpfun_copy_trading/src/main.rs b/examples/pumpfun_copy_trading/src/main.rs index 520d668..18f6df1 100644 --- a/examples/pumpfun_copy_trading/src/main.rs +++ b/examples/pumpfun_copy_trading/src/main.rs @@ -121,7 +121,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from PumpFun..."); diff --git a/examples/pumpfun_sniper_trading/src/main.rs b/examples/pumpfun_sniper_trading/src/main.rs index a3960e7..8018ce6 100644 --- a/examples/pumpfun_sniper_trading/src/main.rs +++ b/examples/pumpfun_sniper_trading/src/main.rs @@ -89,7 +89,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from PumpFun..."); diff --git a/examples/pumpswap_direct_trading/src/main.rs b/examples/pumpswap_direct_trading/src/main.rs index fac1297..5710190 100644 --- a/examples/pumpswap_direct_trading/src/main.rs +++ b/examples/pumpswap_direct_trading/src/main.rs @@ -23,7 +23,7 @@ async fn main() -> Result<(), Box> { let mint_pubkey = Pubkey::from_str("pumpCmXqMfrsAkQ5r49WcJnRayYRqmXz6ae8H7H9Dfn").unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from PumpSwap..."); diff --git a/examples/pumpswap_trading/src/main.rs b/examples/pumpswap_trading/src/main.rs index d80c9cf..ae09a9c 100644 --- a/examples/pumpswap_trading/src/main.rs +++ b/examples/pumpswap_trading/src/main.rs @@ -195,7 +195,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) - let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let is_sol = params.base_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT || params.quote_mint == sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT; diff --git a/examples/raydium_amm_v4_trading/src/main.rs b/examples/raydium_amm_v4_trading/src/main.rs index b70c6fa..cbf5c82 100644 --- a/examples/raydium_amm_v4_trading/src/main.rs +++ b/examples/raydium_amm_v4_trading/src/main.rs @@ -140,7 +140,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent) ); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from Raydium_amm_v4..."); diff --git a/examples/raydium_cpmm_trading/src/main.rs b/examples/raydium_cpmm_trading/src/main.rs index 4d95373..7f374a8 100644 --- a/examples/raydium_cpmm_trading/src/main.rs +++ b/examples/raydium_cpmm_trading/src/main.rs @@ -130,7 +130,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) -> let recent_blockhash = client.rpc.get_latest_blockhash().await?; let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); let buy_params = RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &trade_info.pool_state).await?; diff --git a/examples/seed_trading/src/main.rs b/examples/seed_trading/src/main.rs index 59c9b9c..ad6d0fa 100644 --- a/examples/seed_trading/src/main.rs +++ b/examples/seed_trading/src/main.rs @@ -22,7 +22,7 @@ async fn main() -> Result<(), Box> { let mint_pubkey = Pubkey::from_str("2zMMhcVQEXDtdE6vsFS7S7D5oUodfJHE8vd1gnBouauv").unwrap(); let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new(); - gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001, 256 * 1024, 0); + gas_fee_strategy.set_global_fee_strategy(150000,150000, 500000,500000, 0.001, 0.001, 256 * 1024, 0); // Buy tokens println!("Buying tokens from PumpSwap..."); diff --git a/src/common/fast_fn.rs b/src/common/fast_fn.rs index f293ea0..23f7cf2 100644 --- a/src/common/fast_fn.rs +++ b/src/common/fast_fn.rs @@ -5,7 +5,10 @@ use solana_sdk::{ pubkey::Pubkey, }; -use crate::common::{spl_associated_token_account::get_associated_token_address_with_program_id, spl_token::close_account}; +use crate::common::{ + spl_associated_token_account::get_associated_token_address_with_program_id, + spl_token::close_account, +}; use crate::perf::compiler_optimization::CompileTimeOptimizedEventProcessor; /// 🚀 编译时优化的哈希处理器 @@ -56,10 +59,7 @@ where }; // Lock-free cache lookup with entry API - INSTRUCTION_CACHE - .entry(cache_key) - .or_insert_with(compute_fn) - .clone() + INSTRUCTION_CACHE.entry(cache_key).or_insert_with(compute_fn).clone() } // --------------------- Associated Token Account --------------------- @@ -104,7 +104,8 @@ pub fn _create_associated_token_account_idempotent_fast( if use_seed && !mint.eq(&crate::constants::WSOL_TOKEN_ACCOUNT) && !mint.eq(&crate::constants::SOL_TOKEN_ACCOUNT) - && token_program.eq(&crate::constants::TOKEN_PROGRAM) + && (token_program.eq(&crate::constants::TOKEN_PROGRAM) + || token_program.eq(&crate::constants::TOKEN_PROGRAM_2022)) { // Use cache to get instruction get_cached_instructions(cache_key, || { @@ -239,7 +240,8 @@ fn _get_associated_token_address_with_program_id_fast( let ata = if use_seed && !token_mint_address.eq(&crate::constants::WSOL_TOKEN_ACCOUNT) && !token_mint_address.eq(&crate::constants::SOL_TOKEN_ACCOUNT) - && token_program_id.eq(&crate::constants::TOKEN_PROGRAM) + && (token_program_id.eq(&crate::constants::TOKEN_PROGRAM) + || token_program_id.eq(&crate::constants::TOKEN_PROGRAM_2022)) { super::seed::get_associated_token_address_with_program_id_use_seed( wallet_address, diff --git a/src/instruction/utils/pumpfun.rs b/src/instruction/utils/pumpfun.rs index 838f568..ff445b6 100644 --- a/src/instruction/utils/pumpfun.rs +++ b/src/instruction/utils/pumpfun.rs @@ -61,7 +61,7 @@ pub mod global_constants { pubkey!("GesfTA3X2arioaHp8bbKdjG9vJtskViWACZoYvxp4twS"); pub const MAYHEM_FEE_RECIPIENT_META: solana_sdk::instruction::AccountMeta = solana_sdk::instruction::AccountMeta { - pubkey: FEE_RECIPIENT, + pubkey: MAYHEM_FEE_RECIPIENT, is_signer: false, is_writable: true, }; diff --git a/src/lib.rs b/src/lib.rs index f95b490..be4903a 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -345,7 +345,7 @@ impl SolanaTrade { /// - Network or RPC errors occur /// - Insufficient SOL balance for the purchase /// - Required accounts cannot be created or accessed - pub async fn buy(&self, params: TradeBuyParams) -> Result<(bool, Signature), anyhow::Error> { + pub async fn buy(&self, params: TradeBuyParams) -> Result<(bool, Signature, Option), anyhow::Error> { if params.slippage_basis_points.is_none() { println!( "slippage_basis_points is none, use default slippage basis points: {}", @@ -445,7 +445,7 @@ impl SolanaTrade { /// - Insufficient token balance for the sale /// - Token account doesn't exist or is not properly initialized /// - Required accounts cannot be created or accessed - pub async fn sell(&self, params: TradeSellParams) -> Result<(bool, Signature), anyhow::Error> { + pub async fn sell(&self, params: TradeSellParams) -> Result<(bool, Signature, Option), anyhow::Error> { if params.slippage_basis_points.is_none() { println!( "slippage_basis_points is none, use default slippage basis points: {}", @@ -557,7 +557,7 @@ impl SolanaTrade { mut params: TradeSellParams, amount_token: u64, percent: u64, - ) -> Result<(bool, Signature), anyhow::Error> { + ) -> Result<(bool, Signature, Option), anyhow::Error> { if percent == 0 || percent > 100 { return Err(anyhow::anyhow!("Percentage must be between 1 and 100")); } diff --git a/src/trading/core/async_executor.rs b/src/trading/core/async_executor.rs index 26b1100..115b225 100644 --- a/src/trading/core/async_executor.rs +++ b/src/trading/core/async_executor.rs @@ -21,7 +21,7 @@ use crate::{ struct TaskResult { success: bool, signature: Signature, - _error: Option, + error: Option, } struct ResultCollector { @@ -54,7 +54,7 @@ impl ResultCollector { self.completed_count.fetch_add(1, Ordering::Release); } - async fn wait_for_success(&self) -> Option<(bool, Signature)> { + async fn wait_for_success(&self) -> Option<(bool, Signature, Option)> { let start = Instant::now(); let timeout = std::time::Duration::from_secs(30); @@ -63,7 +63,7 @@ impl ResultCollector { if self.success_flag.load(Ordering::Acquire) { while let Some(result) = self.results.pop() { if result.success { - return Some((true, result.signature)); + return Some((true, result.signature, None)); } } } @@ -71,7 +71,7 @@ impl ResultCollector { let completed = self.completed_count.load(Ordering::Acquire); if completed >= self.total_tasks { while let Some(result) = self.results.pop() { - return Some((result.success, result.signature)); + return Some((result.success, result.signature, result.error)); } return None; } @@ -83,9 +83,9 @@ impl ResultCollector { } } - fn get_first(&self) -> Option<(bool, Signature)> { + fn get_first(&self) -> Option<(bool, Signature, Option,)> { if let Some(result) = self.results.pop() { - Some((result.success, result.signature)) + Some((result.success, result.signature, result.error)) } else { None } @@ -107,7 +107,7 @@ pub async fn execute_parallel( wait_transaction_confirmed: bool, with_tip: bool, gas_fee_strategy: GasFeeStrategy, -) -> Result<(bool, Signature)> { +) -> Result<(bool, Signature, Option)> { let _exec_start = Instant::now(); if swqos_clients.is_empty() { @@ -208,7 +208,7 @@ pub async fn execute_parallel( collector.submit(TaskResult { success: false, signature: Signature::default(), - _error: Some(e), + error: Some(e), }); return; } @@ -217,6 +217,7 @@ pub async fn execute_parallel( // Transaction built let _send_start = Instant::now(); + let mut err = None; let success = match swqos_client .send_transaction( if is_buy { TradeType::Buy } else { TradeType::Sell }, @@ -225,7 +226,8 @@ pub async fn execute_parallel( .await { Ok(()) => true, - Err(_e) => { + Err(e) => { + err = Some(e); // Send transaction failed false } @@ -234,7 +236,7 @@ pub async fn execute_parallel( // Transaction sent if let Some(signature) = transaction.signatures.first() { - collector.submit(TaskResult { success, signature: *signature, _error: None }); + collector.submit(TaskResult { success, signature: *signature, error: err }); } }); } diff --git a/src/trading/core/executor.rs b/src/trading/core/executor.rs index e9c625e..1166d0b 100755 --- a/src/trading/core/executor.rs +++ b/src/trading/core/executor.rs @@ -44,7 +44,7 @@ impl GenericTradeExecutor { #[async_trait::async_trait] impl TradeExecutor for GenericTradeExecutor { - async fn swap(&self, params: SwapParams) -> Result<(bool, Signature)> { + async fn swap(&self, params: SwapParams) -> Result<(bool, Signature, Option)> { let total_start = Instant::now(); // 判断买卖方向 @@ -201,7 +201,7 @@ async fn simulate_transaction( is_buy: bool, with_tip: bool, gas_fee_strategy: GasFeeStrategy, -) -> Result<(bool, Signature)> { +) -> Result<(bool, Signature, Option)> { use crate::trading::common::build_transaction; use solana_client::rpc_config::RpcSimulateTransactionConfig; use solana_commitment_config::CommitmentLevel; @@ -288,7 +288,7 @@ async fn simulate_transaction( } println!("=========================================\n"); - return Ok((false, signature)); + return Ok((false, signature, Some(anyhow::anyhow!("{:?}", err)))); } // Simulation succeeded @@ -308,5 +308,5 @@ async fn simulate_transaction( println!("============================================\n"); - Ok((true, signature)) + Ok((true, signature, None)) } diff --git a/src/trading/core/traits.rs b/src/trading/core/traits.rs index ef6e51c..bf91a29 100755 --- a/src/trading/core/traits.rs +++ b/src/trading/core/traits.rs @@ -5,7 +5,7 @@ use solana_sdk::{instruction::Instruction, signature::Signature}; /// 交易执行器trait - 定义了所有交易协议都需要实现的核心方法 #[async_trait::async_trait] pub trait TradeExecutor: Send + Sync { - async fn swap(&self, params: SwapParams) -> Result<(bool, Signature)>; + async fn swap(&self, params: SwapParams) -> Result<(bool, Signature, Option)>; /// 获取协议名称 fn protocol_name(&self) -> &'static str; }