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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user