feat: add close_mint_token_ata support for sell transactions

This commit is contained in:
ysq
2025-10-26 23:55:28 +08:00
parent 2bf43fc99f
commit 11383a0492
10 changed files with 66 additions and 7 deletions
+9
View File
@@ -316,6 +316,15 @@ impl InstructionBuilder for BonkInstructionBuilder {
if params.close_output_mint_ata {
instructions.extend(crate::trading::common::close_wsol(&params.payer.pubkey()));
}
if params.close_input_mint_ata {
instructions.push(crate::common::spl_token::close_account(
&protocol_params.mint_token_program,
&user_base_token_account,
&params.payer.pubkey(),
&params.payer.pubkey(),
&[&params.payer.pubkey()],
)?);
}
Ok(instructions)
}
+13
View File
@@ -220,6 +220,19 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
if params.close_output_mint_ata {
instructions.extend(crate::trading::common::close_wsol(&params.payer.pubkey()));
}
if params.close_input_mint_ata {
instructions.push(crate::common::spl_token::close_account(
if is_a_in {
&protocol_params.token_a_program
} else {
&protocol_params.token_b_program
},
&input_token_account,
&params.payer.pubkey(),
&params.payer.pubkey(),
&[&params.payer.pubkey()],
)?);
}
Ok(instructions)
}
+1 -1
View File
@@ -241,7 +241,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
));
// Optional: Close token account
if protocol_params.close_token_account_when_sell.unwrap_or(false) {
if protocol_params.close_token_account_when_sell.unwrap_or(false) || params.close_input_mint_ata {
instructions.push(close_account(
&crate::constants::TOKEN_PROGRAM,
&user_token_account,
+17
View File
@@ -356,6 +356,23 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
if close_wsol_ata {
instructions.extend(crate::trading::common::close_wsol(&params.payer.pubkey()));
}
if params.close_input_mint_ata {
instructions.push(crate::common::spl_token::close_account(
if quote_is_wsol_or_usdc {
&base_token_program
} else {
&quote_token_program
},
if quote_is_wsol_or_usdc {
&user_base_token_account
} else {
&user_quote_token_account
},
&params.payer.pubkey(),
&params.payer.pubkey(),
&[&params.payer.pubkey()],
)?);
}
Ok(instructions)
}
}
+9
View File
@@ -236,6 +236,15 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
if params.close_output_mint_ata {
instructions.extend(crate::trading::common::close_wsol(&params.payer.pubkey()));
}
if params.close_input_mint_ata {
instructions.push(crate::common::spl_token::close_account(
&crate::constants::TOKEN_PROGRAM,
&user_source_token_account,
&params.payer.pubkey(),
&params.payer.pubkey(),
&[&params.payer.pubkey()],
)?);
}
Ok(instructions)
}
+9
View File
@@ -293,6 +293,15 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
// Close wSOL ATA account, reclaim rent
instructions.extend(crate::trading::common::close_wsol(&params.payer.pubkey()));
}
if params.close_input_mint_ata {
instructions.push(crate::common::spl_token::close_account(
&mint_token_program,
&input_token_account,
&params.payer.pubkey(),
&params.payer.pubkey(),
&[&params.payer.pubkey()],
)?);
}
Ok(instructions)
}
+3 -1
View File
@@ -148,6 +148,8 @@ pub struct TradeSellParams {
pub create_output_token_ata: bool,
/// Whether to close output token associated token account after trade
pub close_output_token_ata: bool,
/// Whether to close mint token associated token account after trade
pub close_mint_token_ata: bool,
/// Whether to enable seed-based optimization for account creation
pub open_seed_optimize: bool,
/// Durable nonce information
@@ -409,7 +411,7 @@ impl SolanaTrade {
durable_nonce: params.durable_nonce,
data_size_limit: 0,
create_input_mint_ata: false,
close_input_mint_ata: false,
close_input_mint_ata: params.close_mint_token_ata,
create_output_mint_ata: params.create_output_token_ata,
close_output_mint_ata: params.close_output_token_ata,
fixed_output_amount: params.fixed_output_token_amount,