This commit is contained in:
ysq
2025-09-17 11:14:15 +08:00
parent da28f40889
commit fad343ffbf
43 changed files with 1732 additions and 2017 deletions
+55 -47
View File
@@ -4,9 +4,7 @@ use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::protocols::pump
use sol_trade_sdk::solana_streamer_sdk::streaming::event_parser::{Protocol, UnifiedEvent};
use sol_trade_sdk::solana_streamer_sdk::{match_event, streaming::ShredStreamGrpc};
use sol_trade_sdk::{
common::AnyResult,
constants::trade::trade::{DEFAULT_CU_LIMIT, DEFAULT_CU_PRICE},
swqos::settings::SwqosSettings,
common::{AnyResult, PriorityFee, TradeConfig},
swqos::SwqosConfig,
trading::{core::params::PumpFunParams, factory::DexType},
SolanaTrade,
@@ -67,20 +65,28 @@ fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
/// Create SolanaTrade client
/// Initializes a new SolanaTrade client with configuration
async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
println!("🚀 Initializing SolanaTrade client...");
println!("Creating SolanaTrade client...");
let payer = Keypair::from_base58_string("use_your_payer_keypair_here");
let rpc_url = "https://api.mainnet-beta.solana.com".to_string();
let commitment = CommitmentConfig::confirmed();
let swqos_settings: Vec<SwqosSettings> = vec![SwqosSettings::new(
SwqosConfig::Default(rpc_url.clone()),
DEFAULT_CU_LIMIT,
DEFAULT_CU_PRICE,
0.0,
0.0,
)];
let solana_trade = SolanaTrade::new(Arc::new(payer), rpc_url, commitment, swqos_settings).await;
println!("✅ SolanaTrade client initialized successfully!");
Ok(solana_trade)
let swqos_configs = vec![SwqosConfig::Default(rpc_url.clone())];
let mut priority_fee = PriorityFee::default();
// Set RPC unit limit based on your requirements
priority_fee.rpc_unit_limit = 100000;
let trade_config = TradeConfig {
rpc_url,
commitment: CommitmentConfig::confirmed(),
priority_fee: priority_fee,
swqos_configs,
};
let solana_trade_client = SolanaTrade::new(Arc::new(payer), trade_config).await;
println!("SolanaTrade client created successfully!");
Ok(solana_trade_client)
}
/// Execute PumpFun sniper trading strategy based on received token creation event
@@ -96,22 +102,23 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
// Buy tokens
println!("Buying tokens from PumpFun...");
let buy_sol_amount = 100_000;
let buy_params = sol_trade_sdk::TradeBuyParams {
dex_type: DexType::PumpFun,
mint: mint_pubkey,
sol_amount: buy_sol_amount,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
extension_params: Box::new(PumpFunParams::from_dev_trade(&trade_info, None)),
custom_cu_limit: None,
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: true,
create_mint_ata: true,
open_seed_optimize: false,
};
client.buy(buy_params).await?;
client
.buy(
DexType::PumpFun,
mint_pubkey,
buy_sol_amount,
slippage_basis_points,
recent_blockhash,
None,
Box::new(PumpFunParams::from_dev_trade(&trade_info, None)),
None,
true,
true,
true,
true,
false,
)
.await?;
// Sell tokens
println!("Selling tokens from PumpFun...");
@@ -124,22 +131,23 @@ async fn pumpfun_sniper_trade_with_shreds(trade_info: PumpFunTradeEvent) -> AnyR
let amount_token = balance.amount.parse::<u64>().unwrap();
println!("Selling {} tokens", amount_token);
let sell_params = sol_trade_sdk::TradeSellParams {
dex_type: DexType::PumpFun,
mint: mint_pubkey,
token_amount: amount_token,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
with_tip: false,
extension_params: Box::new(PumpFunParams::immediate_sell(trade_info.creator_vault, true)),
custom_cu_limit: None,
lookup_table_key: None,
wait_transaction_confirmed: true,
create_wsol_ata: true,
close_wsol_ata: true,
open_seed_optimize: false,
};
client.sell(sell_params).await?;
client
.sell(
DexType::PumpFun,
mint_pubkey,
amount_token,
slippage_basis_points,
recent_blockhash,
None,
false,
Box::new(PumpFunParams::immediate_sell(trade_info.creator_vault, true)),
None,
true,
true,
true,
false,
)
.await?;
// PumpFunParams can also be set as PumpFunParams::immediate_sell(creator_vault, close_token_account_when_sell)
// creator_vault can be obtained from the trade event