feat: add seed optimization and refactor wSOL account control
- Add `open_seed_optimize` parameter for enhanced performance - Move wSOL account flags from protocol params to buy/sell params - Add seed_trading example demonstrating optimization features - Update all examples and upgrade dependencies - Improve wSOL account management flexibility BREAKING CHANGE: Modified buy/sell method signatures and protocol param structs
This commit is contained in:
@@ -91,7 +91,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(6);
|
||||
|
||||
if protocol_params.create_wsol_ata {
|
||||
if params.create_wsol_ata {
|
||||
instructions
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
@@ -135,7 +135,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(accounts::BONK, &data, accounts.to_vec()));
|
||||
|
||||
if protocol_params.close_wsol_ata {
|
||||
if params.close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
if protocol_params.create_wsol_ata {
|
||||
if params.create_wsol_ata {
|
||||
instructions.extend(crate::trading::common::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
|
||||
instructions.push(Instruction::new_with_bytes(accounts::BONK, &data, accounts.to_vec()));
|
||||
|
||||
if protocol_params.close_wsol_ata {
|
||||
if params.close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +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 create_wsol_ata = protocol_params.create_wsol_ata;
|
||||
let close_wsol_ata = protocol_params.close_wsol_ata;
|
||||
let create_wsol_ata = params.create_wsol_ata;
|
||||
let close_wsol_ata = 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;
|
||||
@@ -214,8 +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 create_wsol_ata = protocol_params.create_wsol_ata;
|
||||
let close_wsol_ata = protocol_params.close_wsol_ata;
|
||||
let create_wsol_ata = params.create_wsol_ata;
|
||||
let close_wsol_ata = params.close_wsol_ata;
|
||||
let base_token_program = protocol_params.base_token_program;
|
||||
let quote_token_program = protocol_params.quote_token_program;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(6);
|
||||
|
||||
if protocol_params.create_wsol_ata {
|
||||
if params.create_wsol_ata {
|
||||
instructions
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
@@ -112,7 +112,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.close_wsol_ata {
|
||||
if params.close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
@@ -167,7 +167,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
if protocol_params.create_wsol_ata {
|
||||
if params.create_wsol_ata {
|
||||
instructions.extend(crate::trading::common::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ impl InstructionBuilder for RaydiumAmmV4InstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.close_wsol_ata {
|
||||
if params.close_wsol_ata {
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(6);
|
||||
|
||||
if protocol_params.create_wsol_ata {
|
||||
if params.create_wsol_ata {
|
||||
instructions
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
@@ -143,7 +143,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.close_wsol_ata {
|
||||
if params.close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
@@ -228,7 +228,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
if protocol_params.create_wsol_ata {
|
||||
if params.create_wsol_ata {
|
||||
instructions.extend(crate::trading::common::create_wsol_ata(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
accounts.to_vec(),
|
||||
));
|
||||
|
||||
if protocol_params.close_wsol_ata {
|
||||
if params.close_wsol_ata {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
+18
-3
@@ -133,6 +133,9 @@ impl SolanaTrade {
|
||||
/// * `extension_params` - Optional protocol-specific parameters (uses defaults if None)
|
||||
/// * `lookup_table_key` - Optional address lookup table key for transaction optimization
|
||||
/// * `wait_transaction_confirmed` - Whether to wait for the transaction to be confirmed
|
||||
/// * `create_wsol_ata` - Whether to create wSOL ATA account
|
||||
/// * `close_wsol_ata` - Whether to close wSOL ATA account
|
||||
/// * `open_seed_optimize` - Whether to open seed optimize
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
@@ -156,6 +159,8 @@ impl SolanaTrade {
|
||||
extension_params: Box<dyn ProtocolParams>,
|
||||
lookup_table_key: Option<Pubkey>,
|
||||
wait_transaction_confirmed: bool,
|
||||
create_wsol_ata: bool,
|
||||
close_wsol_ata: bool,
|
||||
open_seed_optimize: bool,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
if slippage_basis_points.is_none() {
|
||||
@@ -180,6 +185,8 @@ impl SolanaTrade {
|
||||
wait_transaction_confirmed: wait_transaction_confirmed,
|
||||
protocol_params: protocol_params.clone(),
|
||||
open_seed_optimize,
|
||||
create_wsol_ata,
|
||||
close_wsol_ata,
|
||||
swqos_clients: self.swqos_clients.clone(),
|
||||
middleware_manager: self.middleware_manager.clone(),
|
||||
};
|
||||
@@ -223,6 +230,9 @@ impl SolanaTrade {
|
||||
/// * `extension_params` - Optional protocol-specific parameters (uses defaults if None)
|
||||
/// * `lookup_table_key` - Optional address lookup table key for transaction optimization
|
||||
/// * `wait_transaction_confirmed` - Whether to wait for the transaction to be confirmed
|
||||
/// * `create_wsol_ata` - Whether to create wSOL ATA account
|
||||
/// * `close_wsol_ata` - Whether to close wSOL ATA account
|
||||
/// * `open_seed_optimize` - Whether to open seed optimize
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
@@ -248,6 +258,8 @@ impl SolanaTrade {
|
||||
extension_params: Box<dyn ProtocolParams>,
|
||||
lookup_table_key: Option<Pubkey>,
|
||||
wait_transaction_confirmed: bool,
|
||||
create_wsol_ata: bool,
|
||||
close_wsol_ata: bool,
|
||||
open_seed_optimize: bool,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
if slippage_basis_points.is_none() {
|
||||
@@ -278,6 +290,8 @@ impl SolanaTrade {
|
||||
self.swqos_clients.clone()
|
||||
},
|
||||
middleware_manager: self.middleware_manager.clone(),
|
||||
create_wsol_ata,
|
||||
close_wsol_ata,
|
||||
};
|
||||
if custom_priority_fee.is_some() {
|
||||
sell_params.priority_fee = Arc::new(custom_priority_fee.unwrap());
|
||||
@@ -302,9 +316,6 @@ impl SolanaTrade {
|
||||
return Err(anyhow::anyhow!("Invalid protocol params for Trade"));
|
||||
}
|
||||
|
||||
let _swqos_clients =
|
||||
if !with_tip { self.rpc_client.clone() } else { self.swqos_clients.clone() };
|
||||
|
||||
// Execute sell based on tip preference
|
||||
executor.sell_with_tip(sell_params).await
|
||||
}
|
||||
@@ -354,6 +365,8 @@ impl SolanaTrade {
|
||||
extension_params: Box<dyn ProtocolParams>,
|
||||
lookup_table_key: Option<Pubkey>,
|
||||
wait_transaction_confirmed: bool,
|
||||
create_wsol_ata: bool,
|
||||
close_wsol_ata: bool,
|
||||
open_seed_optimize: bool,
|
||||
) -> Result<Signature, anyhow::Error> {
|
||||
if percent == 0 || percent > 100 {
|
||||
@@ -371,6 +384,8 @@ impl SolanaTrade {
|
||||
extension_params,
|
||||
lookup_table_key,
|
||||
wait_transaction_confirmed,
|
||||
create_wsol_ata,
|
||||
close_wsol_ata,
|
||||
open_seed_optimize,
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -32,6 +32,8 @@ pub struct BuyParams {
|
||||
pub open_seed_optimize: bool,
|
||||
pub swqos_clients: Vec<Arc<SwqosClient>>,
|
||||
pub middleware_manager: Option<Arc<MiddlewareManager>>,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
/// Sell parameters
|
||||
@@ -51,6 +53,8 @@ pub struct SellParams {
|
||||
pub open_seed_optimize: bool,
|
||||
pub swqos_clients: Vec<Arc<SwqosClient>>,
|
||||
pub middleware_manager: Option<Arc<MiddlewareManager>>,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
/// PumpFun protocol specific parameters
|
||||
@@ -150,8 +154,6 @@ pub struct PumpSwapParams {
|
||||
pub base_token_program: Pubkey,
|
||||
/// Quote token program ID
|
||||
pub quote_token_program: Pubkey,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl PumpSwapParams {
|
||||
@@ -168,8 +170,6 @@ 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,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +186,6 @@ 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,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,8 +237,6 @@ impl PumpSwapParams {
|
||||
} else {
|
||||
crate::constants::TOKEN_PROGRAM_2022
|
||||
},
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -272,8 +268,6 @@ pub struct BonkParams {
|
||||
pub platform_config: Pubkey,
|
||||
pub platform_associated_account: Pubkey,
|
||||
pub creator_associated_account: Pubkey,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl BonkParams {
|
||||
@@ -284,8 +278,6 @@ impl BonkParams {
|
||||
creator_associated_account: Pubkey,
|
||||
) -> Self {
|
||||
Self {
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
mint_token_program,
|
||||
platform_config,
|
||||
platform_associated_account,
|
||||
@@ -306,8 +298,6 @@ impl BonkParams {
|
||||
platform_config: trade_info.platform_config,
|
||||
platform_associated_account: trade_info.platform_associated_account,
|
||||
creator_associated_account: trade_info.creator_associated_account,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,8 +353,6 @@ impl BonkParams {
|
||||
platform_config: trade_info.platform_config,
|
||||
platform_associated_account: trade_info.platform_associated_account,
|
||||
creator_associated_account: trade_info.creator_associated_account,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,8 +388,6 @@ impl BonkParams {
|
||||
platform_config: pool_data.platform_config,
|
||||
platform_associated_account,
|
||||
creator_associated_account,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -442,8 +428,6 @@ pub struct RaydiumCpmmParams {
|
||||
pub quote_token_program: Pubkey,
|
||||
/// Observation state account
|
||||
pub observation_state: Pubkey,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl RaydiumCpmmParams {
|
||||
@@ -464,8 +448,6 @@ impl RaydiumCpmmParams {
|
||||
base_token_program: trade_info.input_token_program,
|
||||
quote_token_program: trade_info.output_token_program,
|
||||
observation_state: trade_info.observation_state,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,8 +477,6 @@ impl RaydiumCpmmParams {
|
||||
base_token_program: pool.token0_program,
|
||||
quote_token_program: pool.token1_program,
|
||||
observation_state: pool.observation_key,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -529,8 +509,6 @@ pub struct RaydiumAmmV4Params {
|
||||
pub coin_reserve: u64,
|
||||
/// Current pc reserve amount in the pool
|
||||
pub pc_reserve: u64,
|
||||
pub create_wsol_ata: bool,
|
||||
pub close_wsol_ata: bool,
|
||||
}
|
||||
|
||||
impl RaydiumAmmV4Params {
|
||||
@@ -548,8 +526,6 @@ impl RaydiumAmmV4Params {
|
||||
token_pc: amm_info.token_pc,
|
||||
coin_reserve,
|
||||
pc_reserve,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
}
|
||||
}
|
||||
pub async fn from_amm_address_by_rpc(
|
||||
@@ -567,8 +543,6 @@ impl RaydiumAmmV4Params {
|
||||
token_pc: amm_info.token_pc,
|
||||
coin_reserve,
|
||||
pc_reserve,
|
||||
create_wsol_ata: true,
|
||||
close_wsol_ata: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user