refactor: enhance associated token account handling with custom token program support
- Rename create_associated_token_account_fast to create_associated_token_account_idempotent_fast - Upgrade get_associated_token_address_fast to support custom token_program_id parameter - Update ATA cache mechanism to include token_program_id - Adopt new ATA functions in Bonk and PumpFun instruction builders - Improve token program compatibility and cache efficiency
This commit is contained in:
+14
-10
@@ -40,14 +40,18 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
let pool_state = get_pool_pda(¶ms.mint, &crate::constants::WSOL_TOKEN_ACCOUNT).unwrap();
|
||||
|
||||
// Create user token accounts
|
||||
let user_base_token_account = spl_associated_token_account::get_associated_token_address(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
);
|
||||
let user_quote_token_account = spl_associated_token_account::get_associated_token_address(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
);
|
||||
let user_base_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&protocol_params.mint_token_program,
|
||||
);
|
||||
let user_quote_token_account =
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
&crate::constants::WSOL_TOKEN_ACCOUNT,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
);
|
||||
|
||||
// Get pool token accounts
|
||||
let base_vault_account = get_vault_pda(&pool_state, ¶ms.mint).unwrap();
|
||||
@@ -109,7 +113,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
// Create buy instruction
|
||||
let accounts = vec![
|
||||
solana_sdk::instruction::AccountMeta::new(params.payer.pubkey(), true), // Payer (signer)
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
accounts::GLOBAL_CONFIG_META, // Global Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(
|
||||
protocol_params.platform_config,
|
||||
@@ -243,7 +247,7 @@ impl InstructionBuilder for BonkInstructionBuilder {
|
||||
// Create sell instruction
|
||||
let accounts = vec![
|
||||
solana_sdk::instruction::AccountMeta::new(params.payer.pubkey(), true), // Payer (signer)
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
accounts::AUTHORITY_META, // Authority (readonly)
|
||||
accounts::GLOBAL_CONFIG_META, // Global Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(
|
||||
protocol_params.platform_config,
|
||||
|
||||
+27
-18
@@ -57,7 +57,7 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
let mut instructions = Vec::with_capacity(2);
|
||||
|
||||
// Create associated token account
|
||||
instructions.push(crate::common::fast_fn::create_associated_token_account_fast(
|
||||
instructions.push(crate::common::fast_fn::create_associated_token_account_idempotent_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
@@ -75,13 +75,16 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
} else {
|
||||
bonding_curve.account
|
||||
};
|
||||
let associated_bonding_curve = if protocol_params.associated_bonding_curve
|
||||
== Pubkey::default()
|
||||
{
|
||||
crate::common::fast_fn::get_associated_token_address_fast(&bonding_curve, ¶ms.mint)
|
||||
} else {
|
||||
protocol_params.associated_bonding_curve
|
||||
};
|
||||
let associated_bonding_curve =
|
||||
if protocol_params.associated_bonding_curve == Pubkey::default() {
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&bonding_curve,
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
)
|
||||
} else {
|
||||
protocol_params.associated_bonding_curve
|
||||
};
|
||||
|
||||
let accounts: [AccountMeta; 16] = [
|
||||
global_constants::GLOBAL_ACCOUNT_META,
|
||||
@@ -90,9 +93,10 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
AccountMeta::new(bonding_curve, false),
|
||||
AccountMeta::new(associated_bonding_curve, false),
|
||||
AccountMeta::new(
|
||||
crate::common::fast_fn::get_associated_token_address_fast(
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
),
|
||||
false,
|
||||
),
|
||||
@@ -139,9 +143,10 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
} else {
|
||||
return Err(anyhow!("Amount token is required"));
|
||||
};
|
||||
let ata = crate::common::fast_fn::get_associated_token_address_fast(
|
||||
let ata = crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
);
|
||||
let creator_vault_pda = protocol_params.creator_vault;
|
||||
let creator = get_creator(&creator_vault_pda);
|
||||
@@ -168,13 +173,16 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
} else {
|
||||
bonding_curve.account
|
||||
};
|
||||
let associated_bonding_curve = if protocol_params.associated_bonding_curve
|
||||
== Pubkey::default()
|
||||
{
|
||||
crate::common::fast_fn::get_associated_token_address_fast(&bonding_curve, ¶ms.mint)
|
||||
} else {
|
||||
protocol_params.associated_bonding_curve
|
||||
};
|
||||
let associated_bonding_curve =
|
||||
if protocol_params.associated_bonding_curve == Pubkey::default() {
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
&bonding_curve,
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
)
|
||||
} else {
|
||||
protocol_params.associated_bonding_curve
|
||||
};
|
||||
|
||||
let accounts: [AccountMeta; 14] = [
|
||||
global_constants::GLOBAL_ACCOUNT_META,
|
||||
@@ -183,9 +191,10 @@ impl InstructionBuilder for PumpFunInstructionBuilder {
|
||||
AccountMeta::new(bonding_curve, false),
|
||||
AccountMeta::new(associated_bonding_curve, false),
|
||||
AccountMeta::new(
|
||||
crate::common::fast_fn::get_associated_token_address_fast(
|
||||
crate::common::fast_fn::get_associated_token_address_with_program_id_fast(
|
||||
¶ms.payer.pubkey(),
|
||||
¶ms.mint,
|
||||
&crate::constants::TOKEN_PROGRAM,
|
||||
),
|
||||
false,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user