feat: optimize Bonk trading instructions and add price calculation

- Optimize sell instruction building, remove redundant code and add account closing
- Add token price calculation function supporting different decimal places
- Clean up debug logs and refactor code structure
This commit is contained in:
ysq
2025-07-12 01:14:05 +08:00
parent 9946637c62
commit c4bf62be7d
3 changed files with 53 additions and 14 deletions
+22 -4
View File
@@ -22,10 +22,6 @@ impl SolanaTrade {
payer: &Pubkey,
mint: &Pubkey,
) -> Result<u64, anyhow::Error> {
println!(
"get_token_balance payer: {}, mint: {}, rpc_url: {}",
payer, mint, self.trade_config.rpc_url
);
trading::common::utils::get_token_balance(&self.rpc, payer, mint).await
}
@@ -162,4 +158,26 @@ impl SolanaTrade {
Ok(base_amount)
}
// -------------------------------- Bonk --------------------------------
#[inline]
pub fn get_bonk_token_price(
&self,
virtual_base: u128,
virtual_quote: u128,
real_base: u128,
real_quote: u128,
decimal_base: u64,
decimal_quote: u64,
) -> f64 {
trading::bonk::common::get_token_price(
virtual_base,
virtual_quote,
real_base,
real_quote,
decimal_base,
decimal_quote,
)
}
}