Skip to content

Commit 091fb97

Browse files
wip
1 parent 8f9e743 commit 091fb97

File tree

7 files changed

+189
-94
lines changed

7 files changed

+189
-94
lines changed

program-tests/sdk-token-test/src/pda_ctoken/mint.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ pub fn process_mint_action<'c, 'info>(
8282
account_infos.push(ctx.accounts.payer.to_account_info());
8383
account_infos.push(ctx.accounts.token_account.to_account_info());
8484
msg!("mint_action_instruction {:?}", mint_action_instruction);
85-
msg!(
86-
"account infos pubkeys {:?}",
87-
account_infos
88-
.iter()
89-
.map(|info| info.key)
90-
.collect::<Vec<_>>()
91-
);
85+
// msg!(
86+
// "account infos pubkeys {:?}",
87+
// account_infos
88+
// .iter()
89+
// .map(|info| info.key)
90+
// .collect::<Vec<_>>()
91+
// );
9292
// Invoke the mint action instruction directly
9393
invoke(&mint_action_instruction, &account_infos)?;
9494

programs/system/src/processor/create_address_cpi_data.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use light_compressed_account::{
55
},
66
Pubkey,
77
};
8-
use pinocchio::{account_info::AccountInfo, program_error::ProgramError};
8+
use pinocchio::{account_info::AccountInfo, msg, program_error::ProgramError};
99

1010
use crate::{
1111
accounts::remaining_account_checks::AcpAccount, context::SystemContext,
@@ -24,6 +24,40 @@ pub fn derive_new_addresses<'info, 'a, 'b: 'a, const ADDRESS_ASSIGNMENT: bool>(
2424
let invoking_program_id_clone = context.invoking_program_id;
2525

2626
for (i, new_address_params) in new_address_params.enumerate() {
27+
let tree_index = new_address_params.address_merkle_tree_account_index() as usize;
28+
29+
let account_type = match &accounts[tree_index] {
30+
AcpAccount::Authority(_) => "Authority",
31+
AcpAccount::RegisteredProgramPda(_) => "RegisteredProgramPda",
32+
AcpAccount::SystemProgram(_) => "SystemProgram",
33+
AcpAccount::OutputQueue(_) => "OutputQueue",
34+
AcpAccount::BatchedStateTree(_) => "BatchedStateTree",
35+
AcpAccount::BatchedAddressTree(_) => "BatchedAddressTree",
36+
AcpAccount::StateTree(_) => "StateTree",
37+
AcpAccount::AddressTree(_) => "AddressTree",
38+
AcpAccount::AddressQueue(_, _) => "AddressQueue",
39+
AcpAccount::V1Queue(_) => "V1Queue",
40+
AcpAccount::Unknown() => "Unknown",
41+
};
42+
msg!(&format!("accounts[{}] type: {}", tree_index, account_type));
43+
let pubkey = match &accounts[tree_index] {
44+
AcpAccount::AddressTree((pubkey, _)) => pubkey,
45+
AcpAccount::BatchedAddressTree(tree) => tree.pubkey(),
46+
_ => {
47+
msg!(&format!(
48+
"Account at index {:?} is not an address tree",
49+
tree_index
50+
));
51+
52+
return Err(
53+
SystemProgramError::AddressMerkleTreeAccountDiscriminatorMismatch.into(),
54+
);
55+
}
56+
};
57+
msg!(&format!(
58+
"new_address_params: address_merkle_tree_account_index = {}, pubkey = {:?}",
59+
tree_index, pubkey
60+
));
2761
let (address, rollover_fee) =
2862
match &accounts[new_address_params.address_merkle_tree_account_index() as usize] {
2963
AcpAccount::AddressTree((pubkey, _)) => {

programs/system/src/processor/process.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ pub fn process<
102102

103103
let cpi_outputs_data_len =
104104
inputs.get_cpi_context_outputs_end_offset() - inputs.get_cpi_context_outputs_start_offset();
105+
msg!(&format!("cpi_outputs_data_len {:?}", cpi_outputs_data_len));
106+
msg!(&format!(
107+
"cpi_context_inputs_len {:?}",
108+
cpi_context_inputs_len
109+
));
110+
msg!(&format!("num_new_addresses {:?}", num_new_addresses));
111+
msg!(&format!("num_input_accounts {:?}", num_input_accounts));
112+
msg!(&format!(
113+
"num_output_compressed_accounts {:?}",
114+
num_output_compressed_accounts
115+
));
105116
// 1. Allocate cpi data and initialize context
106117
let (mut context, mut cpi_ix_bytes) = create_cpi_data_and_context(
107118
ctx,

programs/system/src/processor/verify_proof.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ fn read_root<const IS_READ_ONLY: bool, const IS_STATE: bool>(
115115
roots: &mut Vec<[u8; 32]>,
116116
) -> Result<u8, SystemProgramError> {
117117
let height;
118+
119+
let account_type = match &merkle_tree_account {
120+
AcpAccount::Authority(_) => "Authority",
121+
AcpAccount::RegisteredProgramPda(_) => "RegisteredProgramPda",
122+
AcpAccount::SystemProgram(_) => "SystemProgram",
123+
AcpAccount::OutputQueue(_) => "OutputQueue",
124+
AcpAccount::BatchedStateTree(_) => "BatchedStateTree",
125+
AcpAccount::BatchedAddressTree(_) => "BatchedAddressTree",
126+
AcpAccount::StateTree(_) => "StateTree",
127+
AcpAccount::AddressTree(_) => "AddressTree",
128+
AcpAccount::AddressQueue(_, _) => "AddressQueue",
129+
AcpAccount::V1Queue(_) => "V1Queue",
130+
AcpAccount::Unknown() => "Unknown",
131+
};
132+
msg!(&format!("merkle_tree_account type: {}", account_type));
133+
let pubkey = match &merkle_tree_account {
134+
AcpAccount::AddressTree((pubkey, _)) => pubkey,
135+
AcpAccount::BatchedAddressTree(tree) => tree.pubkey(),
136+
_ => {
137+
msg!("fu");
138+
return Err(SystemProgramError::AddressMerkleTreeAccountDiscriminatorMismatch.into());
139+
}
140+
};
141+
142+
msg!(&format!("root_index:{:?} pubkey: {:?}", root_index, pubkey));
143+
118144
match merkle_tree_account {
119145
AcpAccount::AddressTree((_, merkle_tree)) => {
120146
if IS_READ_ONLY {
@@ -146,6 +172,7 @@ fn read_root<const IS_READ_ONLY: bool, const IS_STATE: bool>(
146172
return if IS_STATE {
147173
Err(SystemProgramError::StateMerkleTreeAccountDiscriminatorMismatch)
148174
} else {
175+
msg!("is_state: false");
149176
Err(SystemProgramError::AddressMerkleTreeAccountDiscriminatorMismatch)
150177
}
151178
}

sdk-libs/program-test/src/indexer/test_indexer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,8 @@ impl TestIndexer {
19181918
queues.push(bundle.accounts.nullifier_queue);
19191919
cpi_contextes.push(bundle.accounts.cpi_context);
19201920
tree_types.push(bundle.tree_type);
1921+
println!("merkle_tree {:?}", merkle_tree);
1922+
println!("account {:?}", account);
19211923
let leaf_index = merkle_tree.get_leaf_index(account).unwrap();
19221924
let proof = merkle_tree.get_proof_of_leaf(leaf_index, true).unwrap();
19231925

sdk-tests/anchor-compressible/src/lib.rs

Lines changed: 92 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ pub const LIGHT_CPI_SIGNER: CpiSigner =
3333
pub mod anchor_compressible {
3434

3535
use light_compressed_token_sdk::instructions::{
36-
mint_action::MintActionCpiWriteAccounts, mint_action_cpi_write, MintActionInputsCpiWrite,
36+
create_mint_action_cpi, mint_action::MintActionCpiWriteAccounts, mint_action_cpi_write,
37+
MintActionInputs, MintActionInputsCpiWrite,
3738
};
39+
use light_sdk_types::cpi_context_write::CpiContextWriteAccounts;
3840

3941
use super::*;
4042

@@ -180,7 +182,7 @@ pub mod anchor_compressible {
180182
"program: remaining_accounts len: {:?}",
181183
ctx.remaining_accounts.len()
182184
);
183-
msg!("program: remaining_accounts: {:?}", ctx.remaining_accounts);
185+
// msg!("program: remaining_accounts: {:?}", ctx.remaining_accounts);
184186
// Validate we have matching number of PDAs, compressed accounts, and bumps
185187
if solana_accounts.len() != compressed_accounts.len()
186188
|| solana_accounts.len() != bumps.len()
@@ -399,91 +401,27 @@ pub mod anchor_compressible {
399401
game_session.end_time = None;
400402
game_session.score = 0;
401403

402-
let cpi_config = CpiAccountsConfig::new_with_cpi_context(LIGHT_CPI_SIGNER);
403-
404-
msg!("program: remaining_accounts: {:?}", ctx.remaining_accounts);
405404
// Create CPI accounts from remaining accounts
406405
let cpi_accounts = CpiAccountsSmall::new_with_config(
407406
ctx.accounts.user.as_ref(),
408407
ctx.remaining_accounts,
409-
cpi_config,
408+
CpiAccountsConfig::new_with_cpi_context(LIGHT_CPI_SIGNER),
410409
);
410+
let cpi_context_pubkey = cpi_accounts.cpi_context().unwrap().key();
411+
let cpi_context_account = cpi_accounts.cpi_context().unwrap();
411412

412413
msg!(
413414
"program: cpi_accounts.cpi_context(): {:?}",
414415
cpi_accounts.cpi_context()
415416
);
416417

417-
let actions = vec![
418-
// MintActionType::MintTo {
419-
// recipients: input.token_recipients.clone(),
420-
// lamports: input.lamports,
421-
// token_account_version: input.compressed_mint_with_context.mint.version,
422-
// },
423-
// MintActionType::UpdateMintAuthority {
424-
// new_authority: input.final_mint_authority,
425-
// },
426-
// MintActionType::MintToDecompressed {
427-
// account: ctx.accounts.token_account.key(),
428-
// amount: input
429-
// .token_recipients
430-
// .first()
431-
// .map(|r| r.amount)
432-
// .unwrap_or(1000),
433-
// compressible_config: None,
434-
// },
435-
];
436-
437-
let mint_action_inputs = MintActionInputsCpiWrite {
438-
compressed_mint_inputs: compression_params.mint_with_context.clone().into(),
439-
mint_seed: Some(ctx.accounts.mint_signer.key()),
440-
mint_bump: Some(compression_params.mint_bump),
441-
create_mint: true,
442-
authority: ctx.accounts.mint_authority.key(),
443-
payer: ctx.accounts.user.key(),
444-
actions,
445-
input_queue: None, // Not needed for create_mint: true
446-
cpi_context: light_ctoken_types::instructions::mint_actions::CpiContext {
447-
set_context: false,
448-
first_set_context: true,
449-
in_tree_index: 0,
450-
in_queue_index: 1,
451-
out_queue_index: 1,
452-
token_out_queue_index: 1,
453-
assigned_account_index: 0,
454-
},
455-
cpi_context_pubkey: *cpi_accounts.cpi_context().unwrap().key,
456-
};
457-
458-
let mint_action_instruction = mint_action_cpi_write(mint_action_inputs).unwrap();
459-
let mint_action_account_infos = MintActionCpiWriteAccounts {
460-
light_system_program: cpi_accounts.system_program().unwrap(),
461-
mint_signer: Some(ctx.accounts.mint_signer.as_ref()),
462-
authority: ctx.accounts.mint_authority.as_ref(),
463-
fee_payer: ctx.accounts.user.as_ref(),
464-
cpi_authority_pda: ctx.accounts.compress_token_program_cpi_authority.as_ref(),
465-
cpi_context: cpi_accounts.cpi_context().unwrap(),
466-
cpi_signer: crate::LIGHT_CPI_SIGNER,
467-
recipient_token_accounts: vec![], // why needed.
468-
};
469-
470-
msg!("invoke token start!");
471-
msg!("mint_action_account_infos: {:?}", mint_action_account_infos);
472-
473-
invoke(
474-
&mint_action_instruction,
475-
&mint_action_account_infos.to_account_infos(),
476-
)?;
477-
478-
msg!("invoke token done!");
479-
480418
// Prepare new address params. One per pda account.
481419
let user_new_address_params = compression_params
482420
.user_address_tree_info
483-
.into_new_address_params_assigned_packed(user_record.key().to_bytes(), true, Some(1));
421+
.into_new_address_params_assigned_packed(user_record.key().to_bytes(), true, Some(0));
484422
let game_new_address_params = compression_params
485423
.game_address_tree_info
486-
.into_new_address_params_assigned_packed(game_session.key().to_bytes(), true, Some(2));
424+
.into_new_address_params_assigned_packed(game_session.key().to_bytes(), true, Some(1));
487425

488426
let mut all_compressed_infos = Vec::new();
489427

@@ -521,28 +459,99 @@ pub mod anchor_compressible {
521459
)?;
522460
all_compressed_infos.extend(game_compressed_infos);
523461

524-
// Create CPI inputs with all compressed accounts and new addresses
525-
// let cpi_inputs = CpiInputs::new_with_address(
526-
// compression_params.proof,
527-
// all_compressed_infos,
528-
// vec![user_new_address_params, game_new_address_params],
529-
// );
530462
let cpi_inputs = CpiInputs {
531-
proof: compression_params.proof,
463+
proof: ValidityProof(None), //compression_params.proof,
532464
account_infos: Some(all_compressed_infos),
533465
new_assigned_addresses: Some(vec![user_new_address_params, game_new_address_params]),
534466
cpi_context: Some(CompressedCpiContext {
535467
set_context: false,
536-
first_set_context: false,
537-
cpi_context_account_index: 0,
468+
first_set_context: true,
469+
cpi_context_account_index: 0, // Unused
538470
}),
539471
..Default::default()
540472
};
541473
msg!("invoke .pda");
542474

543-
// Invoke light system program to create all compressed accounts in one
544-
// CPI. Call at the end of your init instruction.
545-
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
475+
let cpi_context_accounts = CpiContextWriteAccounts {
476+
fee_payer: cpi_accounts.fee_payer(),
477+
authority: cpi_accounts.authority().unwrap(),
478+
cpi_context: cpi_context_account,
479+
cpi_signer: LIGHT_CPI_SIGNER,
480+
};
481+
cpi_inputs.invoke_light_system_program_cpi_context(cpi_context_accounts)?;
482+
483+
let actions = vec![];
484+
485+
// TODO: pass.
486+
msg!("TREE ACCOUNTS {:?}", cpi_accounts.tree_accounts().unwrap());
487+
let output_queue = *cpi_accounts.tree_accounts().unwrap()[0].key; // Same tree as PDA
488+
let address_tree_pubkey = *cpi_accounts.tree_accounts().unwrap()[1].key; // Same tree as PDA
489+
490+
msg!("output_queue {:?}", output_queue);
491+
msg!("address_tree_pubkey {:?}", address_tree_pubkey);
492+
msg!("mint_authority {:?}", ctx.accounts.mint_authority.key);
493+
msg!("mint_authority {:?}", ctx.accounts.mint_authority.is_signer);
494+
msg!("mint_signer {:?}", ctx.accounts.mint_signer.key);
495+
msg!("mint_signer {:?}", ctx.accounts.mint_signer.is_signer);
496+
let mint_action_inputs = MintActionInputs {
497+
compressed_mint_inputs: compression_params.mint_with_context.clone().into(),
498+
mint_seed: ctx.accounts.mint_signer.key(),
499+
mint_bump: Some(compression_params.mint_bump),
500+
create_mint: true,
501+
authority: ctx.accounts.mint_authority.key(),
502+
payer: ctx.accounts.user.key(),
503+
proof: compression_params.proof.into(),
504+
actions,
505+
input_queue: None, // Not needed for create_mint: true
506+
output_queue,
507+
tokens_out_queue: Some(output_queue), // For MintTo actions
508+
address_tree_pubkey,
509+
};
510+
511+
let mint_action_instruction = create_mint_action_cpi(
512+
mint_action_inputs,
513+
Some(light_ctoken_types::instructions::mint_actions::CpiContext {
514+
set_context: false,
515+
first_set_context: false,
516+
in_tree_index: 1, // address tree
517+
in_queue_index: 0,
518+
out_queue_index: 0,
519+
token_out_queue_index: 0,
520+
assigned_account_index: 2,
521+
}),
522+
Some(cpi_context_pubkey),
523+
)
524+
.unwrap();
525+
526+
msg!("invoke token start!");
527+
// Get all account infos needed for the mint action
528+
let mut account_infos = cpi_accounts.to_account_infos();
529+
account_infos.push(
530+
ctx.accounts
531+
.compress_token_program_cpi_authority
532+
.to_account_info(),
533+
);
534+
account_infos.push(ctx.accounts.compressed_token_program.to_account_info());
535+
account_infos.push(ctx.accounts.mint_authority.to_account_info());
536+
account_infos.push(ctx.accounts.mint_signer.to_account_info());
537+
account_infos.push(ctx.accounts.user.to_account_info());
538+
// account_infos.push(ctx.accounts.token_account.to_account_info());
539+
msg!(
540+
"mint_action_instruction {:?}",
541+
mint_action_instruction.accounts
542+
);
543+
// msg!("account_infos {:?}", account_infos);
544+
msg!(
545+
"account infos pubkeys {:?}",
546+
account_infos
547+
.iter()
548+
.map(|info| info.key)
549+
.collect::<Vec<_>>()
550+
);
551+
// Invoke the mint action instruction directly
552+
invoke(&mint_action_instruction, &account_infos)?;
553+
554+
msg!("invoke token done!");
546555

547556
Ok(())
548557
}

0 commit comments

Comments
 (0)