refactor: unify trading parameters and add USD1 token pool support
- Merge BuyParams and SellParams into unified SwapParams structure - Add USD1 token pool support with related constants and configurations - Refactor trade executor by combining buy_with_tip and sell_with_tip into swap method - Update all protocol instruction builders to support new parameter structure - Standardize ATA creation/closing parameter naming conventions - Update example code to use new API interfaces - Optimize trading logic with automatic direction detection based on input token type
This commit is contained in:
@@ -137,6 +137,7 @@ async fn bonk_sniper_trade_with_shreds(trade_info: BonkTradeEvent) -> AnyResult<
|
||||
trade_info.platform_config,
|
||||
trade_info.platform_associated_account,
|
||||
trade_info.creator_associated_account,
|
||||
trade_info.global_config,
|
||||
)),
|
||||
lookup_table_key: None,
|
||||
wait_transaction_confirmed: true,
|
||||
|
||||
@@ -694,7 +694,7 @@ async fn handle_buy_bonk(
|
||||
println!(" Slippage: {}%", slippage.unwrap());
|
||||
}
|
||||
let mint_pubkey = Pubkey::from_str(mint)?;
|
||||
let param = BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?;
|
||||
let param = BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey, false).await?;
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
let sol_lamports = sol_str_to_lamports(sol_amount.to_string().as_str()).unwrap();
|
||||
|
||||
@@ -1059,7 +1059,7 @@ async fn handle_sell_bonk(
|
||||
}
|
||||
let client = initialize_real_client().await?;
|
||||
let mint_pubkey = Pubkey::from_str(mint)?;
|
||||
let param = BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?;
|
||||
let param = BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey, false).await?;
|
||||
let recent_blockhash = client.rpc.get_latest_blockhash().await?;
|
||||
|
||||
let sell_params = TradeSellParams {
|
||||
|
||||
@@ -111,17 +111,8 @@ fn create_event_callback() -> impl Fn(Box<dyn UnifiedEvent>) {
|
||||
/// Initializes a new SolanaTrade client with configuration
|
||||
async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
println!("🚀 Initializing SolanaTrade client...");
|
||||
|
||||
let payer = Keypair::from_bytes(
|
||||
&std::fs::read_to_string("/Users/ysq/.config/solana/sdk_test.json")
|
||||
.unwrap()
|
||||
.trim_matches(|c| c == '[' || c == ']')
|
||||
.split(',')
|
||||
.map(|s| s.trim().parse::<u8>().unwrap())
|
||||
.collect::<Vec<u8>>(),
|
||||
)
|
||||
.unwrap();
|
||||
let rpc_url = "https://ultra-bold-sunset.solana-mainnet.quiknode.pro/1210ea22139565495810678ac0aa33243fea8406/".to_string();
|
||||
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_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
let trade_config = TradeConfig::new(rpc_url, swqos_configs, commitment);
|
||||
|
||||
Reference in New Issue
Block a user