This commit is contained in:
wei
2025-06-14 20:16:50 +08:00
parent af2afcbb60
commit 1b2d79d5fe
+18 -10
View File
@@ -7,7 +7,7 @@ use spl_associated_token_account::get_associated_token_address;
use spl_token::instruction::close_account;
use tokio::task::JoinHandle;
use std::{str::FromStr, sync::Arc, time::Instant};
use crate::PumpFun;
use crate::{common::{address_lookup_cache::get_address_lookup_table_account, PriorityFee, SolanaRpcClient}, constants::pumpfun::{global_constants::FEE_RECIPIENT}, instruction, swqos::{FeeClient, TradeType, ClientType}};
use super::common::get_creator_vault_pda;
@@ -270,7 +270,10 @@ pub async fn build_sell_instructions(
let creator_vault_pda = get_creator_vault_pda(&creator).unwrap();
let ata = get_associated_token_address(&payer.pubkey(), &mint);
let instructions = vec![
// Get token balance using get_payer_token_balance
let balance_u64 = PumpFun::get_instance().get_payer_token_balance(&mint).await?;
let mut instructions = vec![
instruction::sell(
payer.as_ref(),
&mint,
@@ -281,15 +284,20 @@ pub async fn build_sell_instructions(
_min_sol_output: 1,
},
),
close_account(
&spl_token::ID,
&ata,
&payer.pubkey(),
&payer.pubkey(),
&[&payer.pubkey()],
)?
];
// Only add close account instruction if amount is less than balance
if amount_token >= balance_u64 {
instructions.push(
close_account(
&spl_token::ID,
&ata,
&payer.pubkey(),
&payer.pubkey(),
&[&payer.pubkey()],
)?
);
}
Ok(instructions)
}