feat: optimize PumpSwap instruction builder performance and caching

- Add PumpSwapUserVolume PDA cache key support
- Refactor PumpSwap instruction builder to simplify code logic
- Optimize memory allocation with pre-allocated Vec capacity
- Integrate fast_fn caching mechanism to replace redundant PDA calculations
- Standardize account metadata construction and data serialization
- Simplify wSOL handling logic by reusing common functions
- Optimize import statements and remove unused dependencies
- Add pool token account parameters to PumpSwapParams structure
This commit is contained in:
ysq
2025-09-08 21:54:05 +08:00
parent ea6c3e9989
commit c8241d12d2
4 changed files with 124 additions and 199 deletions
+14 -9
View File
@@ -1,7 +1,4 @@
use crate::{
common::SolanaRpcClient,
constants::{self, TOKEN_PROGRAM},
};
use crate::{common::SolanaRpcClient, constants::TOKEN_PROGRAM};
use anyhow::anyhow;
use solana_account_decoder::UiAccountEncoding;
use solana_sdk::pubkey::Pubkey;
@@ -60,6 +57,9 @@ pub mod accounts {
pub const FEE_CONFIG: Pubkey = pubkey!("5PHirr8joyTMp9JMm6nW7hNDVyEYdkzDqazxPD7RaTjx"); // get_fee_config_pda().unwrap();
pub const DEFAULT_COIN_CREATOR_VAULT_AUTHORITY: Pubkey =
pubkey!("8N3GDaZ2iwN65oxVatKTLPNooAVUJTbfiVJ1ahyqwjSk");
// META
pub const GLOBAL_ACCOUNT_META: solana_sdk::instruction::AccountMeta =
@@ -149,7 +149,7 @@ pub(crate) fn coin_creator_vault_ata(coin_creator: Pubkey, quote_mint: Pubkey) -
pub(crate) fn fee_recipient_ata(fee_recipient: Pubkey, quote_mint: Pubkey) -> Pubkey {
let associated_token_fee_recipient =
spl_associated_token_account::get_associated_token_address_with_program_id(
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
&fee_recipient,
&quote_mint,
&TOKEN_PROGRAM,
@@ -158,10 +158,15 @@ pub(crate) fn fee_recipient_ata(fee_recipient: Pubkey, quote_mint: Pubkey) -> Pu
}
pub fn get_user_volume_accumulator_pda(user: &Pubkey) -> Option<Pubkey> {
let seeds: &[&[u8]; 2] = &[&seeds::USER_VOLUME_ACCUMULATOR_SEED, user.as_ref()];
let program_id: &Pubkey = &&accounts::AMM_PROGRAM;
let pda: Option<(Pubkey, u8)> = Pubkey::try_find_program_address(seeds, program_id);
pda.map(|pubkey| pubkey.0)
crate::common::fast_fn::get_cached_pda(
crate::common::fast_fn::PdaCacheKey::PumpSwapUserVolume(*user),
|| {
let seeds: &[&[u8]; 2] = &[&seeds::USER_VOLUME_ACCUMULATOR_SEED, user.as_ref()];
let program_id: &Pubkey = &&accounts::AMM_PROGRAM;
let pda: Option<(Pubkey, u8)> = Pubkey::try_find_program_address(seeds, program_id);
pda.map(|pubkey| pubkey.0)
},
)
}
pub fn get_global_volume_accumulator_pda() -> Option<Pubkey> {