Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use light_compressed_account::Pubkey;
use light_zero_copy::ZeroCopy;

use crate::{
Expand All @@ -9,10 +8,6 @@ use crate::{
#[repr(C)]
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
pub struct CreateAssociatedTokenAccountInstructionData {
/// The owner of the associated token account
pub owner: Pubkey,
/// The mint for the associated token account
pub mint: Pubkey,
pub bump: u8,
/// Optional compressible configuration for the token account
pub compressible_config: Option<CompressibleExtensionInstructionData>,
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion program-libs/ctoken-types/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod create_associated_token_account;
pub mod create_associated_token_account2;
pub mod transfer2;

pub mod create_ctoken_account;
Expand Down
17 changes: 13 additions & 4 deletions program-tests/compressed-token-test/tests/ctoken/create_ata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ async fn test_create_ata_failing() {
};

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

// Account order: mint, payer, ata, system_program, config, rent_sponsor
let ix = Instruction {
program_id: light_compressed_token::ID,
accounts: vec![
solana_sdk::instruction::AccountMeta::new_readonly(
context.owner_keypair.pubkey(),
false,
),
solana_sdk::instruction::AccountMeta::new_readonly(context.mint_pubkey, false),
solana_sdk::instruction::AccountMeta::new(payer_pubkey, true),
solana_sdk::instruction::AccountMeta::new(ata_pubkey, false),
solana_sdk::instruction::AccountMeta::new_readonly(
Expand Down Expand Up @@ -392,9 +396,8 @@ async fn test_create_ata_failing() {
correct_bump + 1
};

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

// Account order: owner, mint, payer, ata, system_program, config, rent_sponsor
let ix = Instruction {
program_id: light_compressed_token::ID,
accounts: vec![
solana_sdk::instruction::AccountMeta::new_readonly(
context.owner_keypair.pubkey(),
false,
),
solana_sdk::instruction::AccountMeta::new_readonly(context.mint_pubkey, false),
solana_sdk::instruction::AccountMeta::new(payer_pubkey, true),
solana_sdk::instruction::AccountMeta::new(ata_pubkey, false),
solana_sdk::instruction::AccountMeta::new_readonly(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{
};

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

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

/// Process create associated token account with compile-time idempotent mode
/// Convert create_associated_token_account instruction format to create_ata format by extracting
/// owner and mint from accounts and calling the inner function directly
///
/// Note:
/// - we don't validate the mint because it would be very expensive with compressed mints
/// - it is possible to create an associated token account for non existing mints
/// - accounts with non existing mints can never have a balance
///
/// Account order:
/// 0. owner (non-mut, non-signer)
/// 1. mint (non-mut, non-signer)
/// 2. fee_payer (signer, mut)
/// 3. associated_token_account (mut)
/// 4. system_program
/// 5. optional accounts (config, rent_payer, etc.)
#[inline(always)]
#[profile]
pub(crate) fn process_create_associated_token_account_with_mode<const IDEMPOTENT: bool>(
fn process_create_associated_token_account_with_mode<const IDEMPOTENT: bool>(
account_infos: &[AccountInfo],
mut instruction_data: &[u8],
) -> Result<(), ProgramError> {
if account_infos.len() < 2 {
return Err(ProgramError::NotEnoughAccountKeys);
}

let instruction_inputs =
CreateAssociatedTokenAccountInstructionData::deserialize(&mut instruction_data)
.map_err(ProgramError::from)?;

let (owner_and_mint, remaining_accounts) = account_infos.split_at(2);
let owner = &owner_and_mint[0];
let mint = &owner_and_mint[1];

process_create_associated_token_account_inner::<IDEMPOTENT>(
account_infos,
&instruction_inputs.owner.to_bytes(),
&instruction_inputs.mint.to_bytes(),
remaining_accounts,
owner.key(),
mint.key(),
instruction_inputs.bump,
instruction_inputs.compressible_config,
)
Expand Down

This file was deleted.

18 changes: 0 additions & 18 deletions programs/compressed-token/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub mod claim;
pub mod close_token_account;
pub mod convert_account_infos;
pub mod create_associated_token_account;
pub mod create_associated_token_account2;
pub mod create_token_account;
pub mod ctoken_transfer;
pub mod extensions;
Expand All @@ -25,9 +24,6 @@ use close_token_account::processor::process_close_token_account;
use create_associated_token_account::{
process_create_associated_token_account, process_create_associated_token_account_idempotent,
};
use create_associated_token_account2::{
process_create_associated_token_account2, process_create_associated_token_account2_idempotent,
};
use create_token_account::process_create_token_account;
use ctoken_transfer::process_ctoken_transfer;
use withdraw_funding_pool::process_withdraw_funding_pool;
Expand Down Expand Up @@ -75,10 +71,6 @@ pub enum InstructionType {
Claim = 104,
/// Withdraw funds from pool PDA
WithdrawFundingPool = 105,
/// Create associated token account with owner and mint as accounts (non-idempotent)
CreateAssociatedTokenAccount2 = 106,
/// Create associated token account with owner and mint as accounts (idempotent)
CreateAssociatedTokenAccount2Idempotent = 107,
Other,
}

Expand All @@ -95,8 +87,6 @@ impl From<u8> for InstructionType {
103 => InstructionType::MintAction,
104 => InstructionType::Claim,
105 => InstructionType::WithdrawFundingPool,
106 => InstructionType::CreateAssociatedTokenAccount2,
107 => InstructionType::CreateAssociatedTokenAccount2Idempotent,
_ => InstructionType::Other, // anchor instructions
}
}
Expand Down Expand Up @@ -156,14 +146,6 @@ pub fn process_instruction(
msg!("WithdrawFundingPool");
process_withdraw_funding_pool(accounts, &instruction_data[1..])?;
}
InstructionType::CreateAssociatedTokenAccount2 => {
msg!("CreateAssociatedTokenAccount2");
process_create_associated_token_account2(accounts, &instruction_data[1..])?;
}
InstructionType::CreateAssociatedTokenAccount2Idempotent => {
msg!("CreateAssociatedTokenAccount2Idempotent");
process_create_associated_token_account2_idempotent(accounts, &instruction_data[1..])?;
}
// anchor instructions have no discriminator conflicts with InstructionType
// TODO: add test for discriminator conflict
_ => {
Expand Down
Loading