Skip to content

Commit c9a3753

Browse files
committed
refactor: remove create ata2
1 parent f90dbdd commit c9a3753

12 files changed

Lines changed: 105 additions & 399 deletions

File tree

program-libs/ctoken-types/src/instructions/create_associated_token_account.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use light_compressed_account::Pubkey;
21
use light_zero_copy::ZeroCopy;
32

43
use crate::{
@@ -9,10 +8,7 @@ use crate::{
98
#[repr(C)]
109
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
1110
pub struct CreateAssociatedTokenAccountInstructionData {
12-
/// The owner of the associated token account
13-
pub owner: Pubkey,
14-
/// The mint for the associated token account
15-
pub mint: Pubkey,
11+
/// Mint is passed as account input (first account)
1612
pub bump: u8,
1713
/// Optional compressible configuration for the token account
1814
pub compressible_config: Option<CompressibleExtensionInstructionData>,

program-libs/ctoken-types/src/instructions/create_associated_token_account2.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

program-libs/ctoken-types/src/instructions/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub mod create_associated_token_account;
2-
pub mod create_associated_token_account2;
32
pub mod transfer2;
43

54
pub mod create_ctoken_account;

program-tests/compressed-token-test/tests/ctoken/create_ata.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ async fn test_create_ata_failing() {
326326
};
327327

328328
let instruction_data = CreateAssociatedTokenAccountInstructionData {
329-
owner: context.owner_keypair.pubkey().into(),
330-
mint: context.mint_pubkey.into(),
331329
bump,
332330
compressible_config: Some(CompressibleExtensionInstructionData {
333331
compression_only: 0,
@@ -342,9 +340,15 @@ async fn test_create_ata_failing() {
342340
let mut data = vec![100]; // CreateAssociatedTokenAccount discriminator
343341
instruction_data.serialize(&mut data).unwrap();
344342

343+
// Account order: mint, payer, ata, system_program, config, rent_sponsor
345344
let ix = Instruction {
346345
program_id: light_compressed_token::ID,
347346
accounts: vec![
347+
solana_sdk::instruction::AccountMeta::new_readonly(
348+
context.owner_keypair.pubkey(),
349+
false,
350+
),
351+
solana_sdk::instruction::AccountMeta::new_readonly(context.mint_pubkey, false),
348352
solana_sdk::instruction::AccountMeta::new(payer_pubkey, true),
349353
solana_sdk::instruction::AccountMeta::new(ata_pubkey, false),
350354
solana_sdk::instruction::AccountMeta::new_readonly(
@@ -392,9 +396,8 @@ async fn test_create_ata_failing() {
392396
correct_bump + 1
393397
};
394398

399+
// Owner and mint are now passed as accounts, not in instruction data
395400
let instruction_data = CreateAssociatedTokenAccountInstructionData {
396-
owner: context.owner_keypair.pubkey().into(),
397-
mint: context.mint_pubkey.into(),
398401
bump: wrong_bump, // Wrong bump!
399402
compressible_config: Some(CompressibleExtensionInstructionData {
400403
compression_only: 0,
@@ -409,9 +412,15 @@ async fn test_create_ata_failing() {
409412
let mut data = vec![100]; // CreateAssociatedTokenAccount discriminator
410413
instruction_data.serialize(&mut data).unwrap();
411414

415+
// Account order: owner, mint, payer, ata, system_program, config, rent_sponsor
412416
let ix = Instruction {
413417
program_id: light_compressed_token::ID,
414418
accounts: vec![
419+
solana_sdk::instruction::AccountMeta::new_readonly(
420+
context.owner_keypair.pubkey(),
421+
false,
422+
),
423+
solana_sdk::instruction::AccountMeta::new_readonly(context.mint_pubkey, false),
415424
solana_sdk::instruction::AccountMeta::new(payer_pubkey, true),
416425
solana_sdk::instruction::AccountMeta::new(ata_pubkey, false),
417426
solana_sdk::instruction::AccountMeta::new_readonly(

programs/compressed-token/program/src/create_associated_token_account.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{
2020
};
2121

2222
/// Process the create associated token account instruction (non-idempotent)
23+
/// Owner and mint are passed as accounts instead of instruction data
2324
#[inline(always)]
2425
pub fn process_create_associated_token_account(
2526
account_infos: &[AccountInfo],
@@ -28,7 +29,8 @@ pub fn process_create_associated_token_account(
2829
process_create_associated_token_account_with_mode::<false>(account_infos, instruction_data)
2930
}
3031

31-
/// Process the create associated token account instruction (non-idempotent)
32+
/// Process the create associated token account instruction (idempotent)
33+
/// Owner and mint are passed as accounts instead of instruction data
3234
#[inline(always)]
3335
pub fn process_create_associated_token_account_idempotent(
3436
account_infos: &[AccountInfo],
@@ -37,26 +39,42 @@ pub fn process_create_associated_token_account_idempotent(
3739
process_create_associated_token_account_with_mode::<true>(account_infos, instruction_data)
3840
}
3941

40-
/// Process create associated token account with compile-time idempotent mode
42+
/// Convert create_associated_token_account instruction format to create_ata format by extracting
43+
/// owner and mint from accounts and calling the inner function directly
4144
///
4245
/// Note:
4346
/// - we don't validate the mint because it would be very expensive with compressed mints
4447
/// - it is possible to create an associated token account for non existing mints
4548
/// - accounts with non existing mints can never have a balance
49+
///
50+
/// Account order:
51+
/// 0. owner (non-mut, non-signer)
52+
/// 1. mint (non-mut, non-signer)
53+
/// 2. fee_payer (signer, mut)
54+
/// 3. associated_token_account (mut)
55+
/// 4. system_program
56+
/// 5. optional accounts (config, rent_payer, etc.)
4657
#[inline(always)]
47-
#[profile]
48-
pub(crate) fn process_create_associated_token_account_with_mode<const IDEMPOTENT: bool>(
58+
fn process_create_associated_token_account_with_mode<const IDEMPOTENT: bool>(
4959
account_infos: &[AccountInfo],
5060
mut instruction_data: &[u8],
5161
) -> Result<(), ProgramError> {
62+
if account_infos.len() < 2 {
63+
return Err(ProgramError::NotEnoughAccountKeys);
64+
}
65+
5266
let instruction_inputs =
5367
CreateAssociatedTokenAccountInstructionData::deserialize(&mut instruction_data)
5468
.map_err(ProgramError::from)?;
5569

70+
let (owner_and_mint, remaining_accounts) = account_infos.split_at(2);
71+
let owner = &owner_and_mint[0];
72+
let mint = &owner_and_mint[1];
73+
5674
process_create_associated_token_account_inner::<IDEMPOTENT>(
57-
account_infos,
58-
&instruction_inputs.owner.to_bytes(),
59-
&instruction_inputs.mint.to_bytes(),
75+
remaining_accounts,
76+
owner.key(),
77+
mint.key(),
6078
instruction_inputs.bump,
6179
instruction_inputs.compressible_config,
6280
)

programs/compressed-token/program/src/create_associated_token_account2.rs

Lines changed: 0 additions & 62 deletions
This file was deleted.

programs/compressed-token/program/src/lib.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub mod claim;
99
pub mod close_token_account;
1010
pub mod convert_account_infos;
1111
pub mod create_associated_token_account;
12-
pub mod create_associated_token_account2;
1312
pub mod create_token_account;
1413
pub mod ctoken_transfer;
1514
pub mod extensions;
@@ -25,9 +24,6 @@ use close_token_account::processor::process_close_token_account;
2524
use create_associated_token_account::{
2625
process_create_associated_token_account, process_create_associated_token_account_idempotent,
2726
};
28-
use create_associated_token_account2::{
29-
process_create_associated_token_account2, process_create_associated_token_account2_idempotent,
30-
};
3127
use create_token_account::process_create_token_account;
3228
use ctoken_transfer::process_ctoken_transfer;
3329
use withdraw_funding_pool::process_withdraw_funding_pool;
@@ -75,10 +71,6 @@ pub enum InstructionType {
7571
Claim = 104,
7672
/// Withdraw funds from pool PDA
7773
WithdrawFundingPool = 105,
78-
/// Create associated token account with owner and mint as accounts (non-idempotent)
79-
CreateAssociatedTokenAccount2 = 106,
80-
/// Create associated token account with owner and mint as accounts (idempotent)
81-
CreateAssociatedTokenAccount2Idempotent = 107,
8274
Other,
8375
}
8476

@@ -95,8 +87,6 @@ impl From<u8> for InstructionType {
9587
103 => InstructionType::MintAction,
9688
104 => InstructionType::Claim,
9789
105 => InstructionType::WithdrawFundingPool,
98-
106 => InstructionType::CreateAssociatedTokenAccount2,
99-
107 => InstructionType::CreateAssociatedTokenAccount2Idempotent,
10090
_ => InstructionType::Other, // anchor instructions
10191
}
10292
}
@@ -156,14 +146,6 @@ pub fn process_instruction(
156146
msg!("WithdrawFundingPool");
157147
process_withdraw_funding_pool(accounts, &instruction_data[1..])?;
158148
}
159-
InstructionType::CreateAssociatedTokenAccount2 => {
160-
msg!("CreateAssociatedTokenAccount2");
161-
process_create_associated_token_account2(accounts, &instruction_data[1..])?;
162-
}
163-
InstructionType::CreateAssociatedTokenAccount2Idempotent => {
164-
msg!("CreateAssociatedTokenAccount2Idempotent");
165-
process_create_associated_token_account2_idempotent(accounts, &instruction_data[1..])?;
166-
}
167149
// anchor instructions have no discriminator conflicts with InstructionType
168150
// TODO: add test for discriminator conflict
169151
_ => {

0 commit comments

Comments
 (0)