light_registry/account_compression_cpi/
rollover_batched_address_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 RolloverBatchedAddressMerkleTree<'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_address_merkle_tree: AccountInfo<'info>,
17 #[account(mut)]
19 pub old_address_merkle_tree: AccountInfo<'info>,
20 pub registered_program_pda: AccountInfo<'info>,
22 #[account(mut, seeds = [CPI_AUTHORITY_PDA_SEED], bump)]
24 pub cpi_authority: AccountInfo<'info>,
25 pub account_compression_program: Program<'info, AccountCompression>,
26 pub protocol_config_pda: Account<'info, ProtocolConfigPda>,
27}
28
29pub fn process_rollover_batched_address_merkle_tree(
30 ctx: &Context<RolloverBatchedAddressMerkleTree>,
31 bump: u8,
32) -> Result<()> {
33 let bump = &[bump];
34 let seeds = [CPI_AUTHORITY_PDA_SEED, bump];
35 let signer_seeds = &[&seeds[..]];
36 let accounts = account_compression::cpi::accounts::RolloverBatchedAddressMerkleTree {
37 fee_payer: ctx.accounts.authority.to_account_info(),
38 authority: ctx.accounts.cpi_authority.to_account_info(),
39 old_address_merkle_tree: ctx.accounts.old_address_merkle_tree.to_account_info(),
40 new_address_merkle_tree: ctx.accounts.new_address_merkle_tree.to_account_info(),
41 registered_program_pda: Some(ctx.accounts.registered_program_pda.clone()),
42 };
43
44 let cpi_ctx = CpiContext::new_with_signer(
45 ctx.accounts.account_compression_program.to_account_info(),
46 accounts,
47 signer_seeds,
48 );
49
50 account_compression::cpi::rollover_batched_address_merkle_tree(
51 cpi_ctx,
52 if_equals_zero_u64(ctx.accounts.protocol_config_pda.config.network_fee),
53 )
54}