refactor: Update GasFeeStrategy to instance-based API and update docs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use sol_trade_sdk::common::address_lookup::fetch_address_lookup_table_account;
|
||||
use sol_trade_sdk::common::TradeConfig;
|
||||
use sol_trade_sdk::common::{gas_fee_strategy, GasFeeStrategy, TradeConfig};
|
||||
use sol_trade_sdk::{
|
||||
common::AnyResult,
|
||||
swqos::SwqosConfig,
|
||||
@@ -106,8 +106,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -126,6 +124,9 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
let address_lookup_table_account =
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpFun...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -156,6 +157,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::{
|
||||
Arc,
|
||||
};
|
||||
|
||||
use sol_trade_sdk::common::spl_associated_token_account::get_associated_token_address;
|
||||
use sol_trade_sdk::common::{spl_associated_token_account::get_associated_token_address, GasFeeStrategy};
|
||||
use sol_trade_sdk::common::TradeConfig;
|
||||
use sol_trade_sdk::{
|
||||
common::AnyResult,
|
||||
@@ -110,8 +110,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -126,6 +124,9 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
||||
let slippage_basis_points = Some(100);
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from Bonk...");
|
||||
let input_token_type =
|
||||
@@ -164,6 +165,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -207,6 +209,7 @@ async fn bonk_copy_trade_with_grpc(trade_info: BonkTradeEvent) -> AnyResult<()>
|
||||
create_output_token_ata: false,
|
||||
close_output_token_ata: false,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
|
||||
@@ -80,8 +80,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -96,6 +94,9 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
||||
let slippage_basis_points = Some(300);
|
||||
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);
|
||||
|
||||
let token_type = if trade_info.quote_token_mint == sol_trade_sdk::constants::USD1_TOKEN_ACCOUNT
|
||||
{
|
||||
sol_trade_sdk::TradeTokenType::USD1
|
||||
@@ -134,6 +135,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -170,6 +172,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
||||
with_tip: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
|
||||
@@ -614,6 +614,9 @@ async fn handle_buy_pumpfun(
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
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);
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::PumpFun,
|
||||
input_token_type: TradeTokenType::SOL,
|
||||
@@ -630,6 +633,7 @@ async fn handle_buy_pumpfun(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.buy(buy_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -664,6 +668,9 @@ async fn handle_buy_pumpswap(
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
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);
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
@@ -680,6 +687,7 @@ async fn handle_buy_pumpswap(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.buy(buy_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -713,6 +721,9 @@ async fn handle_buy_bonk(
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
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);
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::Bonk,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
@@ -729,6 +740,7 @@ async fn handle_buy_bonk(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.buy(buy_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -766,6 +778,9 @@ async fn handle_buy_raydium_v4(
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
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);
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::RaydiumAmmV4,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
@@ -782,6 +797,7 @@ async fn handle_buy_raydium_v4(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.buy(buy_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -819,6 +835,9 @@ async fn handle_buy_raydium_cpmm(
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
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);
|
||||
|
||||
let buy_params = TradeBuyParams {
|
||||
dex_type: DexType::RaydiumCpmm,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
@@ -835,6 +854,7 @@ async fn handle_buy_raydium_cpmm(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.buy(buy_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -982,6 +1002,9 @@ async fn handle_sell_pumpfun(
|
||||
let param = PumpFunParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?;
|
||||
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);
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::PumpFun,
|
||||
output_token_type: TradeTokenType::SOL,
|
||||
@@ -998,6 +1021,7 @@ async fn handle_sell_pumpfun(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
|
||||
match client.sell(sell_params).await {
|
||||
@@ -1035,6 +1059,9 @@ async fn handle_sell_pumpswap(
|
||||
let param = PumpSwapParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?;
|
||||
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);
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
@@ -1051,6 +1078,7 @@ async fn handle_sell_pumpswap(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.sell(sell_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -1087,6 +1115,9 @@ async fn handle_sell_bonk(
|
||||
let param = BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey, false).await?;
|
||||
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);
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::Bonk,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
@@ -1103,6 +1134,7 @@ async fn handle_sell_bonk(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.sell(sell_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -1142,6 +1174,9 @@ async fn handle_sell_raydium_v4(
|
||||
let param = RaydiumAmmV4Params::from_amm_address_by_rpc(&client.rpc, amm_pubkey).await?;
|
||||
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);
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::RaydiumAmmV4,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
@@ -1158,6 +1193,7 @@ async fn handle_sell_raydium_v4(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.sell(sell_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -1197,6 +1233,9 @@ async fn handle_sell_raydium_cpmm(
|
||||
let param = RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &pool_pubkey).await?;
|
||||
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);
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
dex_type: DexType::RaydiumCpmm,
|
||||
output_token_type: TradeTokenType::WSOL,
|
||||
@@ -1213,6 +1252,7 @@ async fn handle_sell_raydium_cpmm(
|
||||
open_seed_optimize: use_seed,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
match client.sell(sell_params).await {
|
||||
Ok((_, signature)) => {
|
||||
@@ -1325,8 +1365,6 @@ async fn initialize_real_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(payer, trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
|
||||
@@ -8,21 +8,23 @@ async fn main() {
|
||||
println!("🚀 Gas Fee Strategy Demo");
|
||||
println!("========================");
|
||||
|
||||
let gas_fee_strategy = GasFeeStrategy::new();
|
||||
|
||||
// Set global strategy
|
||||
println!("1. Set global strategy");
|
||||
GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
|
||||
// Print all strategies
|
||||
println!("\n2. Print all strategies");
|
||||
GasFeeStrategy::print_all_strategies();
|
||||
gas_fee_strategy.print_all_strategies();
|
||||
|
||||
// Clear all strategies
|
||||
println!("\n3. Clear all strategies");
|
||||
GasFeeStrategy::clear();
|
||||
gas_fee_strategy.clear();
|
||||
|
||||
// Add normal fee strategy for SwqosType::Default
|
||||
println!("\n4. Add normal fee strategy for SwqosType::Default");
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
gas_fee_strategy.set_normal_fee_strategy(
|
||||
SwqosType::Default,
|
||||
150000, // cu_limit
|
||||
500000, // cu_price
|
||||
@@ -32,7 +34,7 @@ async fn main() {
|
||||
|
||||
// Add high-low fee strategy for SwqosType::Jito on Buy
|
||||
println!("\n5. Add high-low fee strategy for SwqosType::Jito on Buy");
|
||||
GasFeeStrategy::set_high_low_fee_strategy(
|
||||
gas_fee_strategy.set_high_low_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
TradeType::Buy,
|
||||
150000, // cu_limit
|
||||
@@ -44,11 +46,11 @@ async fn main() {
|
||||
|
||||
// Print all strategies
|
||||
println!("\n6. Print all current strategies");
|
||||
GasFeeStrategy::print_all_strategies();
|
||||
gas_fee_strategy.print_all_strategies();
|
||||
|
||||
// Add normal fee strategy for SwqosType::Jito on Buy (will override previous high-low strategy)
|
||||
println!("\n7. Add normal fee strategy for SwqosType::Jito (will override previous high-low strategy)");
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
gas_fee_strategy.set_normal_fee_strategy(
|
||||
SwqosType::Jito,
|
||||
150000, // cu_limit
|
||||
500000, // cu_price
|
||||
@@ -58,15 +60,15 @@ async fn main() {
|
||||
|
||||
// Print all strategies
|
||||
println!("\n8. Print all current strategies");
|
||||
GasFeeStrategy::print_all_strategies();
|
||||
gas_fee_strategy.print_all_strategies();
|
||||
|
||||
// Remove strategy for SwqosType::Jito on Buy
|
||||
println!("\n9. Remove strategy for SwqosType::Jito on Buy");
|
||||
GasFeeStrategy::del_all(SwqosType::Jito, TradeType::Buy);
|
||||
gas_fee_strategy.del_all(SwqosType::Jito, TradeType::Buy);
|
||||
|
||||
// Print all strategies
|
||||
println!("\n10. Print all current strategies");
|
||||
GasFeeStrategy::print_all_strategies();
|
||||
gas_fee_strategy.print_all_strategies();
|
||||
|
||||
println!("\n✅ Gas Fee Strategy Demo completed!");
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let pool = Pubkey::from_str("35EFyWd9cH8pdHxVgXHF68L1oZxSWd1FfJASSNTUtoTC").unwrap();
|
||||
let mint_pubkey = Pubkey::from_str("FhTRoy63ZiLcjLEVCMCTLc5Cu5ozrzouNg6cDp1ASZMC").unwrap();
|
||||
|
||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from Metaora Damm V2...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -43,6 +46,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: Some(1),
|
||||
gas_fee_strategy: gas_fee_strategy.clone()
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -74,6 +78,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: Some(1),
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
@@ -91,8 +96,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
|
||||
@@ -64,8 +64,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -82,6 +80,9 @@ async fn test_middleware() -> AnyResult<()> {
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
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);
|
||||
|
||||
let buy_params = sol_trade_sdk::TradeBuyParams {
|
||||
dex_type: DexType::PumpSwap,
|
||||
input_token_type: TradeTokenType::WSOL,
|
||||
@@ -100,6 +101,7 @@ async fn test_middleware() -> AnyResult<()> {
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
println!("tip: This transaction will not succeed because we're using a test account. You can modify the code to initialize the payer with your own private key");
|
||||
|
||||
@@ -106,8 +106,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -126,6 +124,9 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
let nonce_account_str = Pubkey::from_str("use_your_nonce_account_here")?;
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpFun...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -156,6 +157,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: durable_nonce,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
|
||||
@@ -106,8 +106,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -122,6 +120,9 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
let slippage_basis_points = Some(100);
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpFun...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -152,6 +153,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -193,6 +195,7 @@ async fn pumpfun_copy_trade_with_grpc(trade_info: PumpFunTradeEvent) -> AnyResul
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
|
||||
@@ -74,8 +74,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -90,6 +88,9 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
|
||||
let slippage_basis_points = Some(300);
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpFun...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -118,6 +119,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -148,6 +150,7 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let pool = Pubkey::from_str("539m4mVWt6iduB6W8rDGPMarzNCMesuqY5eUTiiYHAgR").unwrap();
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpSwap...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -43,6 +46,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -73,6 +77,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
@@ -90,8 +95,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
|
||||
@@ -124,8 +124,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -183,6 +181,9 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
||||
let slippage_basis_points = Some(500);
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpSwap...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -202,6 +203,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -234,6 +236,7 @@ async fn pumpswap_trade_with_grpc(mint_pubkey: Pubkey, params: PumpSwapParams) -
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
|
||||
@@ -107,8 +107,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -139,6 +137,10 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
coin_reserve,
|
||||
pc_reserve,
|
||||
);
|
||||
|
||||
let gas_fee_strategy = sol_trade_sdk::common::GasFeeStrategy::new();
|
||||
gas_fee_strategy.set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from Raydium_amm_v4...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -158,6 +160,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -189,6 +192,7 @@ async fn raydium_amm_v4_copy_trade_with_grpc(trade_info: RaydiumAmmV4SwapEvent)
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use sol_trade_sdk::common::spl_associated_token_account::get_associated_token_address;
|
||||
use sol_trade_sdk::common::TradeConfig;
|
||||
use sol_trade_sdk::common::{gas_fee_strategy, TradeConfig};
|
||||
use sol_trade_sdk::constants::WSOL_TOKEN_ACCOUNT;
|
||||
use sol_trade_sdk::trading::core::params::RaydiumCpmmParams;
|
||||
use sol_trade_sdk::trading::factory::DexType;
|
||||
@@ -107,8 +107,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
@@ -128,6 +126,9 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
let slippage_basis_points = Some(100);
|
||||
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);
|
||||
|
||||
let buy_params =
|
||||
RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &trade_info.pool_state).await?;
|
||||
// Buy tokens
|
||||
@@ -149,6 +150,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -182,6 +184,7 @@ async fn raydium_cpmm_copy_trade_with_grpc(trade_info: RaydiumCpmmSwapEvent) ->
|
||||
open_seed_optimize: false,
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let pool = Pubkey::from_str("9qKxzRejsV6Bp2zkefXWCbGvg61c3hHei7ShXJ4FythA").unwrap();
|
||||
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);
|
||||
|
||||
// Buy tokens
|
||||
println!("Buying tokens from PumpSwap...");
|
||||
let buy_sol_amount = 100_000;
|
||||
@@ -42,6 +45,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy.clone(),
|
||||
};
|
||||
client.buy(buy_params).await?;
|
||||
|
||||
@@ -80,6 +84,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
open_seed_optimize: true, // ❗️❗️❗️❗️ open seed optimize
|
||||
durable_nonce: None,
|
||||
fixed_output_token_amount: None,
|
||||
gas_fee_strategy: gas_fee_strategy,
|
||||
};
|
||||
client.sell(sell_params).await?;
|
||||
|
||||
@@ -97,8 +102,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
|
||||
@@ -36,8 +36,6 @@ async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade_client = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("SolanaTrade client created successfully!");
|
||||
Ok(solana_trade_client)
|
||||
}
|
||||
|
||||
@@ -59,8 +59,6 @@ async fn create_solana_trade_client() -> Result<SolanaTrade, Box<dyn std::error:
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
let solana_trade = SolanaTrade::new(Arc::new(payer), trade_config).await;
|
||||
// set global strategy
|
||||
sol_trade_sdk::common::GasFeeStrategy::set_global_fee_strategy(150000, 500000, 0.001, 0.001);
|
||||
println!("✅ SolanaTrade client initialized successfully!");
|
||||
Ok(solana_trade)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user