Skip to content

Commit 4446aad

Browse files
add clear
1 parent 9619235 commit 4446aad

File tree

16 files changed

+125
-140
lines changed

16 files changed

+125
-140
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,61 @@ pub struct CompressedMintWithContext {
4040
pub mint: CompressedMintInstructionData,
4141
}
4242

43+
impl CompressedMintWithContext {
44+
pub fn new(
45+
compressed_address: [u8; 32],
46+
root_index: u16,
47+
decimals: u8,
48+
mint_authority: Option<Pubkey>,
49+
freeze_authority: Option<Pubkey>,
50+
spl_mint: Pubkey,
51+
) -> Self {
52+
Self {
53+
leaf_index: 0,
54+
prove_by_index: false,
55+
root_index,
56+
address: compressed_address,
57+
mint: CompressedMintInstructionData {
58+
version: 0,
59+
spl_mint,
60+
supply: 0, // TODO: dynamic?
61+
decimals,
62+
is_decompressed: false,
63+
mint_authority,
64+
freeze_authority,
65+
extensions: None,
66+
},
67+
}
68+
}
69+
70+
pub fn new_with_extensions(
71+
compressed_address: [u8; 32],
72+
root_index: u16,
73+
decimals: u8,
74+
mint_authority: Option<Pubkey>,
75+
freeze_authority: Option<Pubkey>,
76+
spl_mint: Pubkey,
77+
extensions: Option<Vec<ExtensionInstructionData>>,
78+
) -> Self {
79+
Self {
80+
leaf_index: 0,
81+
prove_by_index: false,
82+
root_index,
83+
address: compressed_address,
84+
mint: CompressedMintInstructionData {
85+
version: 0,
86+
spl_mint,
87+
supply: 0,
88+
decimals,
89+
is_decompressed: false,
90+
mint_authority,
91+
freeze_authority,
92+
extensions,
93+
},
94+
}
95+
}
96+
}
97+
4398
#[repr(C)]
4499
#[derive(Debug, PartialEq, Eq, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
45100
pub struct CompressedMintInstructionData {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,22 @@ impl CompressedCpiContextTrait for ZCpiContext<'_> {
130130
self.set_context() as u8
131131
}
132132
}
133+
134+
impl CpiContext {
135+
/// Specific helper for creating a cmint as last use of cpi context.
136+
pub fn last_cpi_create_mint(
137+
address_tree_index: usize,
138+
output_state_queue_index: usize,
139+
mint_account_index: usize,
140+
) -> Self {
141+
Self {
142+
set_context: false,
143+
first_set_context: false,
144+
in_tree_index: address_tree_index as u8,
145+
in_queue_index: 0, // unused
146+
out_queue_index: output_state_queue_index as u8,
147+
token_out_queue_index: output_state_queue_index as u8,
148+
assigned_account_index: mint_account_index as u8,
149+
}
150+
}
151+
}

program-libs/ctoken-types/src/state/mint.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use light_compressed_account::{hash_to_bn254_field_size_be, Pubkey};
22
use light_hasher::{errors::HasherError, Hasher, Poseidon, Sha256};
33
use light_zero_copy::{traits::ZeroCopyAt, ZeroCopy, ZeroCopyMut};
4-
use solana_msg::msg;
54
use zerocopy::IntoBytes;
65

76
use crate::{
@@ -243,7 +242,6 @@ impl ZCompressedMintMut<'_> {
243242
&hashed_freeze_authority_option,
244243
self.version,
245244
)?;
246-
msg!("mint_hash {:?}", mint_hash);
247245

248246
// Compute extension hash chain if extensions exist
249247
if let Some(extensions) = self.extensions.as_ref() {
@@ -265,7 +263,6 @@ impl ZCompressedMintMut<'_> {
265263
}
266264
_ => return Err(CTokenError::UnsupportedExtension),
267265
};
268-
msg!("ZCompressedMintMut extension hash: {:?} ", extension_hash);
269266

270267
if self.version == 0 {
271268
extension_hashchain = Poseidon::hashv(&[
@@ -278,14 +275,9 @@ impl ZCompressedMintMut<'_> {
278275
extension_hash.as_slice(),
279276
])?;
280277
} else {
281-
msg!("invalid version ");
282278
return Err(CTokenError::InvalidTokenDataVersion);
283279
}
284280
}
285-
msg!(
286-
"ZCompressedMintMut extension_hashchain: {:?} ",
287-
extension_hashchain
288-
);
289281

290282
if self.version == 0 {
291283
Ok(Poseidon::hashv(&[
@@ -296,7 +288,6 @@ impl ZCompressedMintMut<'_> {
296288
let mut hash =
297289
Sha256::hashv(&[mint_hash.as_slice(), extension_hashchain.as_slice()])?;
298290
hash[0] = 0;
299-
msg!("data hash {:?}", hash);
300291
Ok(hash)
301292
} else {
302293
Err(CTokenError::InvalidTokenDataVersion)
@@ -326,24 +317,23 @@ impl ZCompressedMintMut<'_> {
326317
self.supply = ix_data.supply;
327318
self.decimals = ix_data.decimals;
328319
self.is_decompressed = if is_decompressed { 1 } else { 0 };
329-
msg!("set1");
320+
330321
if let Some(self_mint_authority) = self.mint_authority.as_deref_mut() {
331322
*self_mint_authority = *ix_data
332323
.mint_authority
333324
.ok_or(CTokenError::InstructionDataExpectedMintAuthority)?;
334325
}
335-
msg!("set2");
326+
336327
if self.mint_authority.is_some() && ix_data.mint_authority.is_none() {
337328
return Err(CTokenError::ZeroCopyExpectedMintAuthority);
338329
}
339-
msg!("set3");
340330

341331
if let Some(self_freeze_authority) = self.freeze_authority.as_deref_mut() {
342332
*self_freeze_authority = *ix_data
343333
.freeze_authority
344334
.ok_or(CTokenError::InstructionDataExpectedFreezeAuthority)?;
345335
}
346-
msg!("set4");
336+
347337
if self.freeze_authority.is_some() && ix_data.freeze_authority.is_none() {
348338
return Err(CTokenError::ZeroCopyExpectedFreezeAuthority);
349339
}

programs/compressed-token/program/src/mint_action/mint_output.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use light_ctoken_types::{
77
state::{CompressedMint, CompressedMintConfig},
88
};
99
use light_zero_copy::ZeroCopyNew;
10-
use pinocchio::msg;
1110

1211
use crate::{
1312
constants::COMPRESSED_MINT_DISCRIMINATOR,
@@ -28,7 +27,6 @@ pub fn process_output_compressed_account<'a>(
2827
hash_cache: &mut HashCache,
2928
queue_indices: &QueueIndices,
3029
) -> Result<(), ProgramError> {
31-
msg!("process_output_compressed_account: ENTRY");
3230
let (mint_account, token_accounts): (
3331
&mut ZOutputCompressedAccountWithPackedContextMut<'_>,
3432
&mut [ZOutputCompressedAccountWithPackedContextMut<'_>],
@@ -39,7 +37,6 @@ pub fn process_output_compressed_account<'a>(
3937
(&mut mint_account[0], token_accounts)
4038
};
4139

42-
msg!("About to call mint_account.set");
4340
mint_account.set(
4441
crate::LIGHT_CPI_SIGNER.program_id.into(),
4542
0,
@@ -48,24 +45,16 @@ pub fn process_output_compressed_account<'a>(
4845
COMPRESSED_MINT_DISCRIMINATOR,
4946
[0u8; 32],
5047
)?;
51-
msg!("mint_account.set completed");
5248

53-
msg!("About to get compressed_account_data");
5449
let compressed_account_data = mint_account
5550
.compressed_account
5651
.data
5752
.as_mut()
5853
.ok_or(ErrorCode::MintActionOutputSerializationFailed)?;
59-
msg!(
60-
"compressed_account_data obtained, data len: {}",
61-
compressed_account_data.data.len()
62-
);
6354

64-
msg!("About to create CompressedMint::new_zero_copy with mint_size_config");
6555
let (mut compressed_mint, _) =
6656
CompressedMint::new_zero_copy(compressed_account_data.data, mint_size_config)
6757
.map_err(|_| ErrorCode::MintActionOutputSerializationFailed)?;
68-
msg!("CompressedMint::new_zero_copy completed successfully");
6958
{
7059
compressed_mint.set(
7160
&parsed_instruction_data.mint,
@@ -86,10 +75,6 @@ pub fn process_output_compressed_account<'a>(
8675
)?;
8776
}
8877
}
89-
msg!(
90-
"About to call process_actions with {} actions",
91-
parsed_instruction_data.actions.len()
92-
);
9378
process_actions(
9479
parsed_instruction_data,
9580
validated_accounts,

programs/compressed-token/program/src/mint_action/processor.rs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use light_ctoken_types::{
1818
use light_sdk::instruction::PackedMerkleContext;
1919
use light_zero_copy::{traits::ZeroCopyAt, ZeroCopyNew};
2020
use pinocchio::account_info::AccountInfo;
21-
use spl_pod::solana_msg::msg;
2221
use spl_token::solana_program::log::sol_log_compute_units;
2322

2423
use crate::{
@@ -197,40 +196,23 @@ pub fn process_actions<'a>(
197196
) -> Result<(), ProgramError> {
198197
// Centralized authority validation - extract and validate authorities at the start
199198
let signer_key = *validated_accounts.authority.key();
200-
msg!(
201-
"parsed_instruction_data.mint.mint_authority {:?}",
202-
parsed_instruction_data
203-
.mint
204-
.mint_authority
205-
.as_ref()
206-
.map(|x| solana_pubkey::Pubkey::new_from_array((**x).into()))
207-
);
208-
msg!(
209-
"signer_key {:?}",
210-
solana_pubkey::Pubkey::new_from_array(signer_key)
211-
);
199+
212200
// Validate mint authority
213201
let mut _validated_mint_authority = None;
214202
if let Some(current_mint_auth) = parsed_instruction_data.mint.mint_authority.as_ref() {
215203
if current_mint_auth.to_bytes() == signer_key {
216204
_validated_mint_authority = Some(**current_mint_auth);
217-
msg!("Mint authority validated: signer matches current mint authority");
218205
} else {
219-
msg!("Mint authority validation failed: signer does not match current mint authority");
206+
// TODO: no error?
220207
}
221208
}
222209

223210
// Start metadata authority with same value as mint authority
224211
let mut validated_metadata_authority = Some(light_compressed_account::Pubkey::from(signer_key));
225-
msg!(
226-
"validated_metadata_authority {:?}",
227-
validated_metadata_authority
228-
);
212+
229213
for (index, action) in parsed_instruction_data.actions.iter().enumerate() {
230-
msg!("Action {}", index);
231214
match action {
232215
ZAction::MintTo(action) => {
233-
msg!("Processing MintTo action");
234216
let new_supply = process_mint_to_action(
235217
action,
236218
compressed_mint,
@@ -249,7 +231,6 @@ pub fn process_actions<'a>(
249231
compressed_mint.supply = new_supply.into();
250232
}
251233
ZAction::UpdateMintAuthority(update_action) => {
252-
msg!("Processing UpdateMintAuthority action");
253234
validate_and_update_authority(
254235
&mut compressed_mint.mint_authority,
255236
parsed_instruction_data
@@ -263,7 +244,6 @@ pub fn process_actions<'a>(
263244
)?;
264245
}
265246
ZAction::UpdateFreezeAuthority(update_action) => {
266-
msg!("Processing UpdateFreezeAuthority action");
267247
validate_and_update_authority(
268248
&mut compressed_mint.freeze_authority,
269249
parsed_instruction_data
@@ -277,15 +257,13 @@ pub fn process_actions<'a>(
277257
)?;
278258
}
279259
ZAction::CreateSplMint(create_spl_action) => {
280-
msg!("Processing CreateSplMint action");
281260
process_create_spl_mint_action(
282261
create_spl_action,
283262
validated_accounts,
284263
&parsed_instruction_data.mint,
285264
)?;
286265
}
287266
ZAction::MintToDecompressed(mint_to_decompressed_action) => {
288-
msg!("Processing MintToDecompressed action");
289267
let new_supply = process_mint_to_decompressed_action(
290268
mint_to_decompressed_action,
291269
u64::from(compressed_mint.supply),
@@ -301,25 +279,15 @@ pub fn process_actions<'a>(
301279
.map(|a| **a),
302280
)?;
303281
compressed_mint.supply = new_supply.into();
304-
msg!("done Processing MintToDecompressed action");
305282
}
306283
ZAction::UpdateMetadataField(update_metadata_action) => {
307-
msg!("Processing UpdateMetadataField action - START");
308-
msg!(
309-
"UpdateMetadataField: extension_index={}, field_type={}, value_len={}",
310-
update_metadata_action.extension_index,
311-
update_metadata_action.field_type,
312-
update_metadata_action.value.len()
313-
);
314284
process_update_metadata_field_action(
315285
update_metadata_action,
316286
compressed_mint,
317287
&validated_metadata_authority,
318288
)?;
319-
msg!("Processing UpdateMetadataField action - COMPLETE");
320289
}
321290
ZAction::UpdateMetadataAuthority(update_metadata_authority_action) => {
322-
msg!("Processing UpdateMetadataAuthority action");
323291
let old_authority = parsed_instruction_data
324292
.mint
325293
.extensions
@@ -341,7 +309,6 @@ pub fn process_actions<'a>(
341309
)?;
342310
}
343311
ZAction::RemoveMetadataKey(remove_metadata_key_action) => {
344-
msg!("Processing RemoveMetadataKey action");
345312
process_remove_metadata_key_action(
346313
remove_metadata_key_action,
347314
compressed_mint,

programs/compressed-token/program/src/mint_action/update_metadata.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,13 @@ pub fn process_update_metadata_authority_action(
237237
msg!("No extensions found - cannot update metadata authority");
238238
ErrorCode::MintActionMissingMetadataExtension
239239
})?;
240-
msg!("here");
241240

242241
let extension_index = action.extension_index as usize;
243242
if extension_index >= extensions.len() {
244243
msg!("Extension index {} out of bounds", extension_index);
245244
return Err(ErrorCode::MintActionInvalidExtensionIndex.into());
246245
}
247-
msg!("here1");
246+
248247
// Get the metadata extension and update the authority
249248
match &mut extensions.as_mut_slice()[extension_index] {
250249
ZExtensionStructMut::TokenMetadata(ref mut metadata) => {
@@ -253,10 +252,8 @@ pub fn process_update_metadata_authority_action(
253252
} else {
254253
Some(action.new_authority)
255254
};
256-
msg!("here2");
257255

258256
if metadata.update_authority.is_none() {
259-
msg!("here3");
260257
let instruction_data_mint_authority = instruction_data_mint_authority
261258
.ok_or(ErrorCode::MintActionInvalidMintAuthority)?;
262259
msg!(

programs/compressed-token/program/src/shared/cpi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ pub fn execute_cpi_invoke(
106106
.iter()
107107
.map(|x| solana_pubkey::Pubkey::new_from_array(*x.pubkey))
108108
.collect::<Vec<_>>();
109-
msg!("_cpi_accounts {:?}", _cpi_accounts);
110109
let instruction = Instruction {
111110
program_id: &LIGHT_SYSTEM_PROGRAM_ID,
112111
accounts: account_metas.as_slice(),

programs/system/src/cpi_context/process_cpi_context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ pub fn process_cpi_context<'a, 'info, T: InstructionData<'a>>(
6969
)?;
7070
}
7171
if cpi_context.set_context || cpi_context.first_set_context {
72-
msg!("setting cpi context");
7372
set_cpi_context(fee_payer, cpi_context_account_info, instruction_data)?;
74-
msg!("cpi context set");
73+
7574
return Ok(None);
7675
} else {
7776
if cpi_context_account.is_empty() {
7877
return Err(SystemProgramError::CpiContextEmpty.into());
7978
}
80-
msg!("checking fee payer");
8179
if (*cpi_context_account.fee_payer).to_bytes() != fee_payer {
8280
msg!("fee payer mismatch");
8381
msg!(format!(" {:?} != {:?}", fee_payer, cpi_context_account.fee_payer).as_str());
@@ -192,7 +190,6 @@ pub fn copy_cpi_context_outputs(
192190
.to_le_bytes()
193191
.as_slice(),
194192
);
195-
msg!("here");
196193
for (output_account, output_data) in cpi_context
197194
.out_accounts
198195
.iter()

0 commit comments

Comments
 (0)