refactor: split auto_handle_wsol into create/close_wsol_ata params
- Replace auto_handle_wsol with create_wsol_ata and close_wsol_ata - Enable fine-grained control over wSOL account lifecycle - Update all trading protocols and documentation - Add open_seed_optimize support in fast functions This provides better flexibility for batch operations and advanced trading.
This commit is contained in:
+16
-9
@@ -61,16 +61,18 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
);
|
||||
|
||||
let user_base_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&protocol_params.mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
let user_quote_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
let base_vault_account = if protocol_params.base_vault == Pubkey::default() {
|
||||
@@ -89,17 +91,18 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(6);
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.create_wsol_ata {
|
||||
instructions
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&protocol_params.mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -132,7 +135,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(accounts::BONK, &data, accounts.to_vec()));
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
@@ -187,16 +190,18 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
);
|
||||
|
||||
let user_base_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&protocol_params.mint_token_program,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
let user_quote_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast_use_seed(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
params.open_seed_optimize,
|
||||
);
|
||||
|
||||
let base_vault_account = if protocol_params.base_vault == Pubkey::default() {
|
||||
@@ -215,7 +220,9 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
instructions.extend(crate::trading::common::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
if protocol_params.create_wsol_ata {
|
||||
instructions.extend(crate::trading::common::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
let mut data = [0u8; 32];
|
||||
data[..8].copy_from_slice(&SELL_EXECT_IN_DISCRIMINATOR);
|
||||
@@ -246,7 +253,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(accounts::BONK, &data, accounts.to_vec()));
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,8 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
let pool_quote_token_reserves = protocol_params.pool_quote_token_reserves;
|
||||
let params_coin_creator_vault_ata = protocol_params.coin_creator_vault_ata;
|
||||
let params_coin_creator_vault_authority = protocol_params.coin_creator_vault_authority;
|
||||
let auto_handle_wsol = protocol_params.auto_handle_wsol;
|
||||
let create_wsol_ata = protocol_params.create_wsol_ata;
|
||||
let close_wsol_ata = protocol_params.close_wsol_ata;
|
||||
let base_token_program = protocol_params.base_token_program;
|
||||
let quote_token_program = protocol_params.quote_token_program;
|
||||
let pool_base_token_account = protocol_params.pool_base_token_account;
|
||||
@@ -118,7 +119,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(6);
|
||||
|
||||
if auto_handle_wsol {
|
||||
if create_wsol_ata {
|
||||
instructions
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), sol_amount));
|
||||
}
|
||||
@@ -187,7 +188,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
accounts,
|
||||
data: data.to_vec(),
|
||||
});
|
||||
if auto_handle_wsol {
|
||||
if close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
@@ -213,7 +214,8 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
let pool_quote_token_account = protocol_params.pool_quote_token_account;
|
||||
let params_coin_creator_vault_ata = protocol_params.coin_creator_vault_ata;
|
||||
let params_coin_creator_vault_authority = protocol_params.coin_creator_vault_authority;
|
||||
let auto_handle_wsol = protocol_params.auto_handle_wsol;
|
||||
let create_wsol_ata = protocol_params.create_wsol_ata;
|
||||
let close_wsol_ata = protocol_params.close_wsol_ata;
|
||||
let base_token_program = protocol_params.base_token_program;
|
||||
let quote_token_program = protocol_params.quote_token_program;
|
||||
|
||||
@@ -286,7 +288,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
if auto_handle_wsol {
|
||||
if create_wsol_ata {
|
||||
instructions.extend(wsol_manager::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
@@ -346,7 +348,7 @@ impl InstructionBuilder for PumpSwapInstructionBuilder {
|
||||
data: data.to_vec(),
|
||||
});
|
||||
|
||||
if auto_handle_wsol {
|
||||
if close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
Ok(instructions)
|
||||
|
||||
@@ -63,7 +63,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(6);
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.create_wsol_ata {
|
||||
instructions
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
@@ -109,7 +109,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
@@ -162,14 +162,9 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
),
|
||||
);
|
||||
if protocol_params.create_wsol_ata {
|
||||
instructions.extend(crate::trading::common::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
// Create buy instruction
|
||||
let accounts: [AccountMeta; 17] = [
|
||||
@@ -203,7 +198,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(6);
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.create_wsol_ata {
|
||||
instructions
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
@@ -140,7 +140,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
@@ -223,14 +223,9 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
),
|
||||
);
|
||||
if protocol_params.create_wsol_ata {
|
||||
instructions.extend(crate::trading::common::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
// Create sell instruction
|
||||
let accounts: [AccountMeta; 13] = [
|
||||
@@ -260,7 +255,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
if protocol_params.close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user