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:
@@ -1,6 +1,7 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use solana_sdk::{instruction::Instruction, signer::Signer};
|
||||
use spl_associated_token_account::instruction::create_associated_token_account_idempotent;
|
||||
use spl_token::instruction::close_account;
|
||||
|
||||
use crate::{
|
||||
constants::bonk::{
|
||||
@@ -241,14 +242,6 @@ impl BonkInstructionBuilder {
|
||||
),
|
||||
);
|
||||
|
||||
// 创建用户的代币账户
|
||||
instructions.push(create_associated_token_account_idempotent(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&accounts::TOKEN_PROGRAM,
|
||||
));
|
||||
|
||||
// 创建卖出指令
|
||||
let accounts = vec![
|
||||
solana_sdk::instruction::AccountMeta::new(params.payer.pubkey(), true), // Payer (signer)
|
||||
@@ -281,6 +274,8 @@ impl BonkInstructionBuilder {
|
||||
data,
|
||||
});
|
||||
|
||||
instructions.push(close_account(&accounts::TOKEN_PROGRAM, &user_quote_token_account, ¶ms.payer.pubkey(), ¶ms.payer.pubkey(), &[¶ms.payer.pubkey()]).unwrap());
|
||||
|
||||
Ok(instructions)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user