Skip to main content

light_registry/account_compression_cpi/
register_program.rs

1use account_compression::{
2    program::AccountCompression, utils::constants::CPI_AUTHORITY_PDA_SEED, GroupAuthority,
3};
4use anchor_lang::prelude::*;
5
6use crate::protocol_config::state::ProtocolConfigPda;
7
8#[derive(Accounts)]
9pub struct RegisterProgram<'info> {
10    /// CHECK: only the protocol authority can register new programs.
11    #[account(mut)]
12    pub authority: Signer<'info>,
13    #[account(mut, has_one = authority)]
14    pub protocol_config_pda: Account<'info, ProtocolConfigPda>,
15    /// CHECK: (seed constraints) used to invoke account compression program via cpi.
16    #[account(mut, seeds = [CPI_AUTHORITY_PDA_SEED], bump)]
17    pub cpi_authority: AccountInfo<'info>,
18    /// CHECK: (account compression program).
19    #[account(mut ,constraint = group_pda.authority == cpi_authority.key())]
20    pub group_pda: Account<'info, GroupAuthority>,
21    pub account_compression_program: Program<'info, AccountCompression>,
22    pub system_program: Program<'info, System>,
23    /// CHECK: (account compression program).
24    #[account(mut)]
25    pub registered_program_pda: AccountInfo<'info>,
26    /// CHECK: (account compression program). TODO: check that a signer is the upgrade authority.
27    /// - is signer so that only the program deployer can register a program.
28    pub program_to_be_registered: Signer<'info>,
29}
30
31#[derive(Accounts)]
32pub struct DeregisterProgram<'info> {
33    /// CHECK: only the protocol authority can register new programs.
34    #[account(mut)]
35    pub authority: Signer<'info>,
36    #[account(mut, has_one = authority)]
37    pub protocol_config_pda: Account<'info, ProtocolConfigPda>,
38    /// CHECK: (seed constraints) used to invoke account compression program via cpi.
39    #[account(mut, seeds = [CPI_AUTHORITY_PDA_SEED], bump)]
40    pub cpi_authority: AccountInfo<'info>,
41    /// CHECK: (account compression program).
42    #[account(mut ,constraint = group_pda.authority == cpi_authority.key())]
43    pub group_pda: Account<'info, GroupAuthority>,
44    pub account_compression_program: Program<'info, AccountCompression>,
45    /// CHECK: (account compression program).
46    #[account(mut)]
47    pub registered_program_pda: AccountInfo<'info>,
48}