refactor: optimize AccountMeta creation with lazy static constants

- Consolidate protocol constants to unified module
- Pre-build AccountMeta objects using once_cell::Lazy
- Reduce instruction building overhead across all DEX protocols
- Improve code maintainability and performance
This commit is contained in:
ysq
2025-09-07 21:36:57 +08:00
parent 51253c7aaf
commit 544e65318d
17 changed files with 323 additions and 185 deletions
+7 -7
View File
@@ -189,13 +189,13 @@ impl PumpSwapParams {
spl_associated_token_account::get_associated_token_address_with_program_id(
&pool_address,
&pool_data.base_mint,
&crate::instruction::utils::pumpswap::accounts::TOKEN_PROGRAM,
&crate::constants::TOKEN_PROGRAM,
);
let quote_token_program_ata =
spl_associated_token_account::get_associated_token_address_with_program_id(
&pool_address,
&pool_data.quote_mint,
&crate::instruction::utils::pumpswap::accounts::TOKEN_PROGRAM,
&crate::constants::TOKEN_PROGRAM,
);
Ok(Self {
@@ -207,14 +207,14 @@ impl PumpSwapParams {
coin_creator_vault_ata: coin_creator_vault_ata,
coin_creator_vault_authority: coin_creator_vault_authority,
base_token_program: if pool_data.pool_base_token_account == base_token_program_ata {
crate::instruction::utils::pumpswap::accounts::TOKEN_PROGRAM
crate::constants::TOKEN_PROGRAM
} else {
spl_token_2022::ID
crate::constants::TOKEN_PROGRAM_2022
},
quote_token_program: if pool_data.pool_quote_token_account == quote_token_program_ata {
crate::instruction::utils::pumpswap::accounts::TOKEN_PROGRAM
crate::constants::TOKEN_PROGRAM
} else {
spl_token_2022::ID
crate::constants::TOKEN_PROGRAM_2022
},
auto_handle_wsol: true,
})
@@ -337,7 +337,7 @@ impl BonkParams {
) -> Result<Self, anyhow::Error> {
let pool_address = crate::instruction::utils::bonk::get_pool_pda(
mint,
&crate::instruction::utils::bonk::accounts::WSOL_TOKEN_ACCOUNT,
&crate::constants::WSOL_TOKEN_ACCOUNT,
)
.unwrap();
let pool_data =