light_registry/account_compression_cpi/
rollover_batched_state_tree.rs1use account_compression::{program::AccountCompression, utils::constants::CPI_AUTHORITY_PDA_SEED};
2use anchor_lang::prelude::*;
3use light_merkle_tree_metadata::utils::if_equals_zero_u64;
4
5use crate::{protocol_config::state::ProtocolConfigPda, ForesterEpochPda};
6
7#[derive(Accounts)]
8pub struct RolloverBatchedStateMerkleTree<'info> {
9 #[account(mut)]
11 pub registered_forester_pda: Option<Account<'info, ForesterEpochPda>>,
12 #[account(mut)]
13 pub authority: Signer<'info>,
14 #[account(mut)]
16 pub new_state_merkle_tree: AccountInfo<'info>,
17 #[account(mut)]
19 pub old_state_merkle_tree: AccountInfo<'info>,
20 #[account(mut)]
22 pub new_output_queue: AccountInfo<'info>,
23 #[account(mut)]
25 pub old_output_queue: AccountInfo<'info>,
26 #[account(mut)]
28 pub cpi_context_account: AccountInfo<'info>,
29 pub registered_program_pda: AccountInfo<'info>,
31 #[account(mut, seeds = [CPI_AUTHORITY_PDA_SEED], bump)]
33 pub cpi_authority: AccountInfo<'info>,
34 pub account_compression_program: Program<'info, AccountCompression>,
35 pub protocol_config_pda: Account<'info, ProtocolConfigPda>,
36 pub light_system_program: Program<'info, light_system_program::program::LightSystemProgram>,
37}
38
39pub fn process_rollover_batched_state_merkle_tree(
40 ctx: &Context<RolloverBatchedStateMerkleTree>,
41 bump: u8,
42) -> Result<()> {
43 let bump = &[bump];
44 let seeds = [CPI_AUTHORITY_PDA_SEED, bump];
45 let signer_seeds = &[&seeds[..]];
46 let accounts = account_compression::cpi::accounts::RolloverBatchedStateMerkleTree {
47 fee_payer: ctx.accounts.authority.to_account_info(),
48 authority: ctx.accounts.cpi_authority.to_account_info(),
49 old_state_merkle_tree: ctx.accounts.old_state_merkle_tree.to_account_info(),
50 new_state_merkle_tree: ctx.accounts.new_state_merkle_tree.to_account_info(),
51 old_output_queue: ctx.accounts.old_output_queue.to_account_info(),
52 new_output_queue: ctx.accounts.new_output_queue.to_account_info(),
53 registered_program_pda: Some(ctx.accounts.registered_program_pda.clone()),
54 };
55
56 let cpi_ctx = CpiContext::new_with_signer(
57 ctx.accounts.account_compression_program.to_account_info(),
58 accounts,
59 signer_seeds,
60 );
61 let network_fee = if ctx.accounts.registered_forester_pda.is_some() {
62 if_equals_zero_u64(ctx.accounts.protocol_config_pda.config.network_fee)
63 } else {
64 None
65 };
66
67 account_compression::cpi::rollover_batched_state_merkle_tree(
68 cpi_ctx,
69 ctx.accounts.protocol_config_pda.config.cpi_context_size,
70 network_fee,
71 )
72}