Merge commit '7fb4fd35d18bb0ec9c87d893958d4ac0c506b39e'

This commit is contained in:
ysq
2025-11-18 10:08:37 +08:00
7 changed files with 167 additions and 17 deletions
+10 -6
View File
@@ -200,11 +200,13 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
data[16..24].copy_from_slice(&token_amount.to_le_bytes());
}
instructions.push(Instruction {
let buy_instruction = Instruction {
program_id: accounts::AMM_PROGRAM,
accounts,
accounts: accounts.clone(),
data: data.to_vec(),
});
};
instructions.push(buy_instruction);
if close_wsol_ata {
// Close wSOL ATA account, reclaim rent
instructions.extend(crate::trading::common::close_wsol(&params.payer.pubkey()));
@@ -375,11 +377,13 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
data[16..24].copy_from_slice(&token_amount.to_le_bytes());
}
instructions.push(Instruction {
let sell_instruction = Instruction {
program_id: accounts::AMM_PROGRAM,
accounts,
accounts: accounts.clone(),
data: data.to_vec(),
});
};
instructions.push(sell_instruction);
if close_wsol_ata {
instructions.extend(crate::trading::common::close_wsol(&params.payer.pubkey()));
+14
View File
@@ -230,10 +230,17 @@ pub async fn find_by_base_mint(
if accounts.is_empty() {
return Err(anyhow!("No pool found for mint {}", base_mint));
}
let accounts_count = accounts.len(); // 🔧 保存长度,因为 into_iter() 会消耗 accounts
let mut pools: Vec<_> = accounts
.into_iter()
.filter_map(|(addr, acc)| pool_decode(&acc.data).map(|pool| (addr, pool)))
.collect();
// 🔧 修复:检查过滤后的 pools 是否为空(accounts 可能不为空但解码全部失败)
if pools.is_empty() {
return Err(anyhow!("No valid pool decoded for mint {} (found {} accounts but all decode failed)", base_mint, accounts_count));
}
pools.sort_by(|a, b| b.1.lp_supply.cmp(&a.1.lp_supply));
let (address, pool) = pools[0].clone();
Ok((address, pool))
@@ -266,10 +273,17 @@ pub async fn find_by_quote_mint(
if accounts.is_empty() {
return Err(anyhow!("No pool found for mint {}", quote_mint));
}
let accounts_count = accounts.len(); // 🔧 保存长度,因为 into_iter() 会消耗 accounts
let mut pools: Vec<_> = accounts
.into_iter()
.filter_map(|(addr, acc)| pool_decode(&acc.data).map(|pool| (addr, pool)))
.collect();
// 🔧 修复:检查过滤后的 pools 是否为空(accounts 可能不为空但解码全部失败)
if pools.is_empty() {
return Err(anyhow!("No valid pool decoded for quote_mint {} (found {} accounts but all decode failed)", quote_mint, accounts_count));
}
pools.sort_by(|a, b| b.1.lp_supply.cmp(&a.1.lp_supply));
let (address, pool) = pools[0].clone();
Ok((address, pool))