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
+36 -35
View File
@@ -1,8 +1,6 @@
use anyhow::Result;
use sol_trade_sdk::{
common::AnyResult,
constants::trade::trade::{DEFAULT_CU_LIMIT, DEFAULT_CU_PRICE},
swqos::settings::SwqosSettings,
common::{AnyResult, PriorityFee, TradeConfig},
swqos::{SwqosConfig, SwqosRegion},
trading::{
core::params::PumpSwapParams, factory::DexType, middleware::builtin::LoggingMiddleware,
@@ -61,20 +59,25 @@ impl InstructionMiddleware for CustomMiddleware {
/// Create SolanaTrade client
/// Initializes a new SolanaTrade client with configuration
async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
println!("🚀 Initializing SolanaTrade client...");
let payer = Keypair::from_base58_string("use_your_payer_keypair_here");
println!("Creating SolanaTrade client...");
// In real transactions, use your own private key to initialize the payer
let payer = Keypair::new();
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 trade_config = TradeConfig {
rpc_url,
commitment: CommitmentConfig::confirmed(),
priority_fee: PriorityFee::default(),
swqos_configs,
};
let solana_trade_client = SolanaTrade::new(Arc::new(payer), trade_config).await;
println!("SolanaTrade client created successfully!");
Ok(solana_trade_client)
}
async fn test_middleware() -> AnyResult<()> {
@@ -88,25 +91,23 @@ async fn test_middleware() -> AnyResult<()> {
let slippage_basis_points = Some(100);
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
let pool_address = Pubkey::from_str("539m4mVWt6iduB6W8rDGPMarzNCMesuqY5eUTiiYHAgR")?;
let buy_params = sol_trade_sdk::TradeBuyParams {
dex_type: DexType::PumpSwap,
mint: mint_pubkey,
sol_amount: buy_sol_cost,
slippage_basis_points: slippage_basis_points,
recent_blockhash: recent_blockhash,
extension_params: Box::new(
PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?,
),
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::PumpSwap,
mint_pubkey,
buy_sol_cost,
slippage_basis_points,
recent_blockhash,
None,
Box::new(PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?),
None,
true,
true,
true,
true,
false,
)
.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");
Ok(())
}