perf: optimize constants and memory allocation for trading instruction performance
This commit is contained in:
@@ -25,22 +25,26 @@ pub mod accounts {
|
||||
pub const SHARE_FEE_RATE: u128 = 0; // 0%
|
||||
|
||||
// META
|
||||
pub const AUTHORITY_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(AUTHORITY, false)
|
||||
});
|
||||
pub const GLOBAL_CONFIG_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(GLOBAL_CONFIG, false)
|
||||
});
|
||||
pub const EVENT_AUTHORITY_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(EVENT_AUTHORITY, false)
|
||||
});
|
||||
pub const BONK_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(BONK, false)
|
||||
});
|
||||
pub const AUTHORITY_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: AUTHORITY,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
pub const GLOBAL_CONFIG_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: GLOBAL_CONFIG,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
pub const EVENT_AUTHORITY_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: EVENT_AUTHORITY,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
pub const BONK_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta { pubkey: BONK, is_signer: false, is_writable: false };
|
||||
}
|
||||
|
||||
pub const BUY_EXECT_IN_DISCRIMINATOR: [u8; 8] = [250, 234, 13, 123, 213, 156, 19, 236];
|
||||
|
||||
@@ -51,7 +51,7 @@ pub mod global_constants {
|
||||
|
||||
pub const POOL_MIGRATION_FEE: u64 = 15_000_001;
|
||||
|
||||
pub const CREATOR_FEE: u64 = 5;
|
||||
pub const CREATOR_FEE: u64 = 30;
|
||||
|
||||
pub const SCALE: u64 = 1_000_000; // 10^6 for token decimals
|
||||
|
||||
@@ -61,19 +61,21 @@ pub mod global_constants {
|
||||
|
||||
/// Public key for the fee recipient
|
||||
pub const FEE_RECIPIENT: Pubkey = pubkey!("62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV");
|
||||
/// Static AccountMeta for fee recipient (initialized once)
|
||||
pub static FEE_RECIPIENT_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new(FEE_RECIPIENT, false)
|
||||
});
|
||||
pub const FEE_RECIPIENT_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: FEE_RECIPIENT,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
};
|
||||
|
||||
/// Public key for the global PDA
|
||||
pub const GLOBAL_ACCOUNT: Pubkey = pubkey!("4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf");
|
||||
/// Static AccountMeta for global account (initialized once)
|
||||
pub static GLOBAL_ACCOUNT_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(GLOBAL_ACCOUNT, false)
|
||||
});
|
||||
pub const GLOBAL_ACCOUNT_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: GLOBAL_ACCOUNT,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
/// Public key for the authority
|
||||
pub const AUTHORITY: Pubkey = pubkey!("FFWtrEQ4B4PKQoVuHYzZq8FabGkVatYzDpEVHsK5rrhF");
|
||||
@@ -95,10 +97,6 @@ pub mod global_constants {
|
||||
pub mod accounts {
|
||||
use solana_sdk::{pubkey, pubkey::Pubkey};
|
||||
|
||||
use crate::instruction::utils::pumpfun::{
|
||||
get_fee_config_pda, get_global_volume_accumulator_pda,
|
||||
};
|
||||
|
||||
/// Public key for the Pump.fun program
|
||||
pub const PUMPFUN: Pubkey = pubkey!("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P");
|
||||
|
||||
@@ -112,43 +110,50 @@ pub mod accounts {
|
||||
pub const ASSOCIATED_TOKEN_PROGRAM: Pubkey =
|
||||
pubkey!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
||||
|
||||
/// Rent Sysvar ID
|
||||
pub const RENT: Pubkey = pubkey!("SysvarRent111111111111111111111111111111111");
|
||||
|
||||
pub const AMM_PROGRAM: Pubkey = pubkey!("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8");
|
||||
|
||||
pub const FEE_PROGRAM: Pubkey = pubkey!("pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ");
|
||||
|
||||
pub const GLOBAL_VOLUME_ACCUMULATOR: Pubkey =
|
||||
pubkey!("Hq2wp8uJ9jCPsYgNHex8RtqdvMPfVGoYwjvF1ATiwn2Y"); // get_global_volume_accumulator_pda().unwrap();
|
||||
|
||||
pub const FEE_CONFIG: Pubkey = pubkey!("8Wf5TiAheLUqBrKXeYg2JtAFFMWtKdG2BSFgqUcPVwTt"); // get_fee_config_pda().unwrap();
|
||||
|
||||
// META
|
||||
pub const PUMPFUN_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: PUMPFUN,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const PUMPFUN_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(PUMPFUN, false)
|
||||
});
|
||||
pub const EVENT_AUTHORITY_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: EVENT_AUTHORITY,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const EVENT_AUTHORITY_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(EVENT_AUTHORITY, false)
|
||||
});
|
||||
pub const FEE_PROGRAM_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: FEE_PROGRAM,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const FEE_PROGRAM_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(FEE_PROGRAM, false)
|
||||
});
|
||||
pub const GLOBAL_VOLUME_ACCUMULATOR_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: GLOBAL_VOLUME_ACCUMULATOR,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
};
|
||||
|
||||
pub const GLOBAL_VOLUME_ACCUMULATOR_META: once_cell::sync::Lazy<
|
||||
solana_sdk::instruction::AccountMeta,
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new(
|
||||
get_global_volume_accumulator_pda().unwrap(),
|
||||
false,
|
||||
)
|
||||
});
|
||||
|
||||
pub const FEE_CONFIG_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(get_fee_config_pda().unwrap(), false)
|
||||
});
|
||||
pub const FEE_CONFIG_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: FEE_CONFIG,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
}
|
||||
|
||||
pub struct Symbol;
|
||||
@@ -185,6 +190,22 @@ pub fn get_bonding_curve_pda(mint: &Pubkey) -> Option<Pubkey> {
|
||||
pda.map(|pubkey| pubkey.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_creator(creator_vault_pda: &Pubkey) -> Pubkey {
|
||||
if creator_vault_pda.eq(&Pubkey::default()) {
|
||||
Pubkey::default()
|
||||
} else {
|
||||
// Fast check against cached default creator vault
|
||||
static DEFAULT_CREATOR_VAULT: std::sync::LazyLock<Option<Pubkey>> =
|
||||
std::sync::LazyLock::new(|| get_creator_vault_pda(&Pubkey::default()));
|
||||
if creator_vault_pda.eq(&DEFAULT_CREATOR_VAULT.unwrap()) {
|
||||
Pubkey::default()
|
||||
} else {
|
||||
*creator_vault_pda
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_creator_vault_pda(creator: &Pubkey) -> Option<Pubkey> {
|
||||
let seeds: &[&[u8]; 2] = &[seeds::CREATOR_VAULT_SEED, creator.as_ref()];
|
||||
|
||||
@@ -51,9 +51,6 @@ pub mod accounts {
|
||||
pub const PROTOCOL_FEE_RECIPIENT: Pubkey =
|
||||
pubkey!("62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV");
|
||||
|
||||
/// Rent Sysvar ID
|
||||
pub const RENT: Pubkey = pubkey!("SysvarRent111111111111111111111111111111111");
|
||||
|
||||
pub const AMM_PROGRAM: Pubkey = pubkey!("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA");
|
||||
|
||||
pub const LP_FEE_BASIS_POINTS: u64 = 20;
|
||||
@@ -62,52 +59,68 @@ pub mod accounts {
|
||||
|
||||
pub const FEE_PROGRAM: Pubkey = pubkey!("pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ");
|
||||
|
||||
pub const GLOBAL_VOLUME_ACCUMULATOR: Pubkey =
|
||||
pubkey!("C2aFPdENg4A2HQsmrd5rTw5TaYBX5Ku887cWjbFKtZpw"); // get_global_volume_accumulator_pda().unwrap();
|
||||
|
||||
pub const FEE_CONFIG: Pubkey = pubkey!("5PHirr8joyTMp9JMm6nW7hNDVyEYdkzDqazxPD7RaTjx"); // get_fee_config_pda().unwrap();
|
||||
|
||||
// META
|
||||
|
||||
pub const GLOBAL_ACCOUNT_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(GLOBAL_ACCOUNT, false)
|
||||
});
|
||||
pub const GLOBAL_ACCOUNT_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: GLOBAL_ACCOUNT,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const FEE_RECIPIENT_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(FEE_RECIPIENT, false)
|
||||
});
|
||||
pub const FEE_RECIPIENT_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: FEE_RECIPIENT,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const ASSOCIATED_TOKEN_PROGRAM_META: once_cell::sync::Lazy<
|
||||
solana_sdk::instruction::AccountMeta,
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(ASSOCIATED_TOKEN_PROGRAM, false)
|
||||
});
|
||||
pub const ASSOCIATED_TOKEN_PROGRAM_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: ASSOCIATED_TOKEN_PROGRAM,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const EVENT_AUTHORITY_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(EVENT_AUTHORITY, false)
|
||||
});
|
||||
pub const EVENT_AUTHORITY_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: EVENT_AUTHORITY,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const AMM_PROGRAM_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(AMM_PROGRAM, false)
|
||||
});
|
||||
pub const AMM_PROGRAM_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: AMM_PROGRAM,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const GLOBAL_VOLUME_ACCUMULATOR_META: once_cell::sync::Lazy<
|
||||
solana_sdk::instruction::AccountMeta,
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new(
|
||||
get_global_volume_accumulator_pda().unwrap(),
|
||||
false,
|
||||
)
|
||||
});
|
||||
pub const GLOBAL_VOLUME_ACCUMULATOR_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: GLOBAL_VOLUME_ACCUMULATOR,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
};
|
||||
|
||||
pub const FEE_CONFIG_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(get_fee_config_pda().unwrap(), false)
|
||||
});
|
||||
pub const FEE_CONFIG_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: FEE_CONFIG,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const FEE_PROGRAM_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(FEE_PROGRAM, false)
|
||||
});
|
||||
pub const FEE_PROGRAM_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: FEE_PROGRAM,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
}
|
||||
|
||||
pub const BUY_DISCRIMINATOR: [u8; 8] = [102, 6, 61, 18, 1, 218, 235, 234];
|
||||
|
||||
@@ -24,10 +24,12 @@ pub mod accounts {
|
||||
|
||||
// META
|
||||
|
||||
pub const AUTHORITY_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(AUTHORITY, false)
|
||||
});
|
||||
pub const AUTHORITY_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: AUTHORITY,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
}
|
||||
|
||||
pub const SWAP_BASE_IN_DISCRIMINATOR: &[u8] = &[9];
|
||||
|
||||
@@ -24,15 +24,19 @@ pub mod accounts {
|
||||
pub const PROTOCOL_FEE_RATE: u64 = 120000;
|
||||
pub const FUND_FEE_RATE: u64 = 40000;
|
||||
// META
|
||||
pub const AUTHORITY_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(AUTHORITY, false)
|
||||
});
|
||||
pub const AUTHORITY_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: AUTHORITY,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
|
||||
pub const AMM_CONFIG_META: once_cell::sync::Lazy<solana_sdk::instruction::AccountMeta> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(AMM_CONFIG, false)
|
||||
});
|
||||
pub const AMM_CONFIG_META: solana_sdk::instruction::AccountMeta =
|
||||
solana_sdk::instruction::AccountMeta {
|
||||
pubkey: AMM_CONFIG,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
};
|
||||
}
|
||||
|
||||
pub const SWAP_BASE_IN_DISCRIMINATOR: &[u8] = &[143, 190, 90, 218, 196, 30, 51, 222];
|
||||
|
||||
Reference in New Issue
Block a user