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()));
|
||||
}
|
||||
|
||||
+30
-19
@@ -150,9 +150,8 @@ pub struct PumpSwapParams {
|
||||
pub base_token_program: Pubkey,
|
||||
/// Quote token program ID
|
||||
pub quote_token_program: Pubkey,
|
||||
/// Automatically handle WSOL wrapping
|
||||
/// When true, automatically handles wrapping and unwrapping operations between SOL and WSOL
|
||||
pub auto_handle_wsol: bool,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl PumpSwapParams {
|
||||
@@ -169,7 +168,8 @@ impl PumpSwapParams {
|
||||
coin_creator_vault_authority: event.coin_creator_vault_authority,
|
||||
base_token_program: event.base_token_program,
|
||||
quote_token_program: event.quote_token_program,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,8 @@ impl PumpSwapParams {
|
||||
coin_creator_vault_authority: event.coin_creator_vault_authority,
|
||||
base_token_program: event.base_token_program,
|
||||
quote_token_program: event.quote_token_program,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,7 +239,8 @@ impl PumpSwapParams {
|
||||
} else {
|
||||
crate::constants::TOKEN_PROGRAM_2022
|
||||
},
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -270,7 +272,8 @@ pub struct BonkParams {
|
||||
pub platform_config: Pubkey,
|
||||
pub platform_associated_account: Pubkey,
|
||||
pub creator_associated_account: Pubkey,
|
||||
pub auto_handle_wsol: bool,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl BonkParams {
|
||||
@@ -281,7 +284,8 @@ impl BonkParams {
|
||||
creator_associated_account: Pubkey,
|
||||
) -> Self {
|
||||
Self {
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
mint_token_program,
|
||||
platform_config,
|
||||
platform_associated_account,
|
||||
@@ -302,7 +306,8 @@ impl BonkParams {
|
||||
platform_config: trade_info.platform_config,
|
||||
platform_associated_account: trade_info.platform_associated_account,
|
||||
creator_associated_account: trade_info.creator_associated_account,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,7 +363,8 @@ impl BonkParams {
|
||||
platform_config: trade_info.platform_config,
|
||||
platform_associated_account: trade_info.platform_associated_account,
|
||||
creator_associated_account: trade_info.creator_associated_account,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +400,8 @@ impl BonkParams {
|
||||
platform_config: pool_data.platform_config,
|
||||
platform_associated_account,
|
||||
creator_associated_account,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -433,8 +440,8 @@ pub struct RaydiumCpmmParams {
|
||||
pub quote_token_program: Pubkey,
|
||||
/// Observation state account
|
||||
pub observation_state: Pubkey,
|
||||
/// Whether to automatically handle wSOL wrapping and unwrapping
|
||||
pub auto_handle_wsol: bool,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl RaydiumCpmmParams {
|
||||
@@ -454,7 +461,8 @@ impl RaydiumCpmmParams {
|
||||
base_token_program: trade_info.input_token_program,
|
||||
quote_token_program: trade_info.output_token_program,
|
||||
observation_state: trade_info.observation_state,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,7 +491,8 @@ impl RaydiumCpmmParams {
|
||||
base_token_program: pool.token0_program,
|
||||
quote_token_program: pool.token1_program,
|
||||
observation_state: pool.observation_key,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -516,8 +525,8 @@ pub struct RaydiumAmmV4Params {
|
||||
pub coin_reserve: u64,
|
||||
/// Current pc reserve amount in the pool
|
||||
pub pc_reserve: u64,
|
||||
/// Whether to automatically handle wSOL wrapping and unwrapping
|
||||
pub auto_handle_wsol: bool,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl RaydiumAmmV4Params {
|
||||
@@ -535,7 +544,8 @@ impl RaydiumAmmV4Params {
|
||||
token_pc: amm_info.token_pc,
|
||||
coin_reserve,
|
||||
pc_reserve,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
pub async fn from_amm_address_by_rpc(
|
||||
@@ -553,7 +563,8 @@ impl RaydiumAmmV4Params {
|
||||
token_pc: amm_info.token_pc,
|
||||
coin_reserve,
|
||||
pc_reserve,
|
||||
auto_handle_wsol: true,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user