@@ -33,8 +33,10 @@ pub const LIGHT_CPI_SIGNER: CpiSigner =
33
33
pub mod anchor_compressible {
34
34
35
35
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 ,
37
38
} ;
39
+ use light_sdk_types:: cpi_context_write:: CpiContextWriteAccounts ;
38
40
39
41
use super :: * ;
40
42
@@ -180,7 +182,7 @@ pub mod anchor_compressible {
180
182
"program: remaining_accounts len: {:?}" ,
181
183
ctx. remaining_accounts. len( )
182
184
) ;
183
- msg ! ( "program: remaining_accounts: {:?}" , ctx. remaining_accounts) ;
185
+ // msg!("program: remaining_accounts: {:?}", ctx.remaining_accounts);
184
186
// Validate we have matching number of PDAs, compressed accounts, and bumps
185
187
if solana_accounts. len ( ) != compressed_accounts. len ( )
186
188
|| solana_accounts. len ( ) != bumps. len ( )
@@ -399,91 +401,27 @@ pub mod anchor_compressible {
399
401
game_session. end_time = None ;
400
402
game_session. score = 0 ;
401
403
402
- let cpi_config = CpiAccountsConfig :: new_with_cpi_context ( LIGHT_CPI_SIGNER ) ;
403
-
404
- msg ! ( "program: remaining_accounts: {:?}" , ctx. remaining_accounts) ;
405
404
// Create CPI accounts from remaining accounts
406
405
let cpi_accounts = CpiAccountsSmall :: new_with_config (
407
406
ctx. accounts . user . as_ref ( ) ,
408
407
ctx. remaining_accounts ,
409
- cpi_config ,
408
+ CpiAccountsConfig :: new_with_cpi_context ( LIGHT_CPI_SIGNER ) ,
410
409
) ;
410
+ let cpi_context_pubkey = cpi_accounts. cpi_context ( ) . unwrap ( ) . key ( ) ;
411
+ let cpi_context_account = cpi_accounts. cpi_context ( ) . unwrap ( ) ;
411
412
412
413
msg ! (
413
414
"program: cpi_accounts.cpi_context(): {:?}" ,
414
415
cpi_accounts. cpi_context( )
415
416
) ;
416
417
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
-
480
418
// Prepare new address params. One per pda account.
481
419
let user_new_address_params = compression_params
482
420
. 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 ) ) ;
484
422
let game_new_address_params = compression_params
485
423
. 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 ) ) ;
487
425
488
426
let mut all_compressed_infos = Vec :: new ( ) ;
489
427
@@ -521,28 +459,99 @@ pub mod anchor_compressible {
521
459
) ?;
522
460
all_compressed_infos. extend ( game_compressed_infos) ;
523
461
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
- // );
530
462
let cpi_inputs = CpiInputs {
531
- proof : compression_params. proof ,
463
+ proof : ValidityProof ( None ) , // compression_params.proof,
532
464
account_infos : Some ( all_compressed_infos) ,
533
465
new_assigned_addresses : Some ( vec ! [ user_new_address_params, game_new_address_params] ) ,
534
466
cpi_context : Some ( CompressedCpiContext {
535
467
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
538
470
} ) ,
539
471
..Default :: default ( )
540
472
} ;
541
473
msg ! ( "invoke .pda" ) ;
542
474
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!" ) ;
546
555
547
556
Ok ( ( ) )
548
557
}
0 commit comments