refactor: optimize trading execution architecture and add wSOL management
- Simplify TradeExecutor interface by integrating middleware and swqos clients into params - Refactor parallel execution module with dedicated buy/sell execute functions - Add SOL wrapping/unwrapping functionality for wSOL management - Remove redundant parameter passing in sell operations - Delete example main.rs file - Optimize transaction building with integrated parameter structures BREAKING CHANGE: TradeExecutor interface simplified, middleware and swqos_clients now passed through params
This commit is contained in:
@@ -103,12 +103,14 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
.extend(crate::trading::common::handle_wsol(¶ms.payer.pubkey(), amount_in));
|
||||
}
|
||||
|
||||
instructions.push(crate::common::fast_fn::create_associated_token_account_idempotent_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&mint_token_program,
|
||||
));
|
||||
instructions.extend(
|
||||
crate::common::fast_fn::create_associated_token_account_idempotent_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&mint_token_program,
|
||||
),
|
||||
);
|
||||
|
||||
// Create buy instruction
|
||||
let accounts: [AccountMeta; 13] = [
|
||||
@@ -140,7 +142,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.push(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
Ok(instructions)
|
||||
@@ -221,12 +223,14 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
// ========================================
|
||||
let mut instructions = Vec::with_capacity(3);
|
||||
|
||||
instructions.push(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,
|
||||
));
|
||||
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,
|
||||
),
|
||||
);
|
||||
|
||||
// Create sell instruction
|
||||
let accounts: [AccountMeta; 13] = [
|
||||
@@ -258,7 +262,7 @@ impl InstructionBuilder for RaydiumCpmmInstructionBuilder {
|
||||
|
||||
if protocol_params.auto_handle_wsol {
|
||||
// Close wSOL ATA account, reclaim rent
|
||||
instructions.push(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
instructions.extend(crate::trading::common::close_wsol(¶ms.payer.pubkey()));
|
||||
}
|
||||
|
||||
Ok(instructions)
|
||||
|
||||
Reference in New Issue
Block a user