light_registry/account_compression_cpi/
rollover_state_tree.rs1use account_compression::{
2 program::AccountCompression, utils::constants::CPI_AUTHORITY_PDA_SEED,
3 AddressMerkleTreeAccount, StateMerkleTreeAccount,
4};
5use anchor_lang::prelude::*;
6use light_system_program::program::LightSystemProgram;
7
8use crate::{epoch::register_epoch::ForesterEpochPda, protocol_config::state::ProtocolConfigPda};
9
10#[derive(Accounts)]
11pub struct RolloverStateMerkleTreeAndQueue<'info> {
12 #[account(mut)]
14 pub registered_forester_pda: Option<Account<'info, ForesterEpochPda>>,
15 #[account(mut)]
17 pub authority: Signer<'info>,
18 pub cpi_authority: AccountInfo<'info>,
20 pub registered_program_pda: AccountInfo<'info>,
22 pub account_compression_program: Program<'info, AccountCompression>,
23 #[account(mut)]
25 pub new_merkle_tree: AccountInfo<'info>,
26 #[account(mut)]
28 pub new_queue: AccountInfo<'info>,
29 #[account(mut)]
31 pub old_merkle_tree: AccountLoader<'info, StateMerkleTreeAccount>,
32 #[account(mut)]
34 pub old_queue: AccountInfo<'info>,
35 pub cpi_context_account: AccountInfo<'info>,
37 pub light_system_program: Program<'info, LightSystemProgram>,
38 pub protocol_config_pda: Account<'info, ProtocolConfigPda>,
39}
40
41#[derive(Accounts)]
42pub struct RolloverAddressMerkleTreeAndQueue<'info> {
43 #[account(mut)]
45 pub registered_forester_pda: Option<Account<'info, ForesterEpochPda>>,
46 #[account(mut)]
48 pub authority: Signer<'info>,
49 pub cpi_authority: AccountInfo<'info>,
51 pub registered_program_pda: AccountInfo<'info>,
53 pub account_compression_program: Program<'info, AccountCompression>,
54 #[account(mut)]
56 pub new_merkle_tree: AccountInfo<'info>,
57 #[account(mut)]
59 pub new_queue: AccountInfo<'info>,
60 #[account(mut)]
62 pub old_merkle_tree: AccountLoader<'info, AddressMerkleTreeAccount>,
63 #[account(mut)]
65 pub old_queue: AccountInfo<'info>,
66}
67
68pub fn process_rollover_address_merkle_tree_and_queue(
69 ctx: &Context<RolloverAddressMerkleTreeAndQueue>,
70 bump: u8,
71) -> Result<()> {
72 let bump = &[bump];
73
74 let seeds = [CPI_AUTHORITY_PDA_SEED, bump];
75 let signer_seeds = &[&seeds[..]];
76
77 let accounts = account_compression::cpi::accounts::RolloverAddressMerkleTreeAndQueue {
78 fee_payer: ctx.accounts.authority.to_account_info(),
79 authority: ctx.accounts.cpi_authority.to_account_info(),
80 registered_program_pda: Some(ctx.accounts.registered_program_pda.to_account_info()),
81 new_address_merkle_tree: ctx.accounts.new_merkle_tree.to_account_info(),
82 new_queue: ctx.accounts.new_queue.to_account_info(),
83 old_address_merkle_tree: ctx.accounts.old_merkle_tree.to_account_info(),
84 old_queue: ctx.accounts.old_queue.to_account_info(),
85 };
86 let cpi_ctx = CpiContext::new_with_signer(
87 ctx.accounts.account_compression_program.to_account_info(),
88 accounts,
89 signer_seeds,
90 );
91
92 account_compression::cpi::rollover_address_merkle_tree_and_queue(cpi_ctx)
93}
94pub fn process_rollover_state_merkle_tree_and_queue(
95 ctx: &Context<RolloverStateMerkleTreeAndQueue>,
96 bump: u8,
97) -> Result<()> {
98 let bump = &[bump];
99
100 let seeds = [CPI_AUTHORITY_PDA_SEED, bump];
101 let signer_seeds = &[&seeds[..]];
102
103 let accounts = account_compression::cpi::accounts::RolloverStateMerkleTreeAndNullifierQueue {
104 fee_payer: ctx.accounts.authority.to_account_info(),
105 authority: ctx.accounts.cpi_authority.to_account_info(),
106 registered_program_pda: Some(ctx.accounts.registered_program_pda.to_account_info()),
107 new_state_merkle_tree: ctx.accounts.new_merkle_tree.to_account_info(),
108 new_nullifier_queue: ctx.accounts.new_queue.to_account_info(),
109 old_state_merkle_tree: ctx.accounts.old_merkle_tree.to_account_info(),
110 old_nullifier_queue: ctx.accounts.old_queue.to_account_info(),
111 };
112 let cpi_ctx = CpiContext::new_with_signer(
113 ctx.accounts.account_compression_program.to_account_info(),
114 accounts,
115 signer_seeds,
116 );
117
118 account_compression::cpi::rollover_state_merkle_tree_and_nullifier_queue(cpi_ctx)
119}