feat: add close_mint_token_ata support for sell transactions
This commit is contained in:
@@ -316,6 +316,15 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
if params.close_output_mint_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.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,
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&[¶ms.payer.pubkey()],
|
||||
)?);
|
||||
}
|
||||
|
||||
Ok(instructions)
|
||||
}
|
||||
|
||||
@@ -220,6 +220,19 @@ impl InstructionBuilder for MeteoraDammV2InstructionBuilder {
|
||||
if params.close_output_mint_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.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,
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&[¶ms.payer.pubkey()],
|
||||
)?);
|
||||
}
|
||||
|
||||
Ok(instructions)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -356,6 +356,23 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
if close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.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 {
|
||||
"e_token_program
|
||||
},
|
||||
if quote_is_wsol_or_usdc {
|
||||
&user_base_token_account
|
||||
} else {
|
||||
&user_quote_token_account
|
||||
},
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&[¶ms.payer.pubkey()],
|
||||
)?);
|
||||
}
|
||||
Ok(instructions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +236,15 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
if params.close_output_mint_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
if params.close_input_mint_ata {
|
||||
instructions.push(crate::common::spl_token::close_account(
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
&user_source_token_account,
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&[¶ms.payer.pubkey()],
|
||||
)?);
|
||||
}
|
||||
|
||||
Ok(instructions)
|
||||
}
|
||||
|
||||
@@ -293,6 +293,15 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
if params.close_input_mint_ata {
|
||||
instructions.push(crate::common::spl_token::close_account(
|
||||
&mint_token_program,
|
||||
&input_token_account,
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&[¶ms.payer.pubkey()],
|
||||
)?);
|
||||
}
|
||||
|
||||
Ok(instructions)
|
||||
}
|
||||
|
||||
+3
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user