light_merkle_tree_program/config_accounts/
merkle_tree_authority.rs

1use aligned_sized::aligned_sized;
2use anchor_lang::prelude::*;
3
4use crate::{
5    config,
6    errors::ErrorCode,
7    event_merkle_tree::EventMerkleTree,
8    transaction_merkle_tree::state::TransactionMerkleTree,
9    utils::constants::{
10        EVENT_MERKLE_TREE_SEED, MERKLE_TREE_AUTHORITY_SEED, TRANSACTION_MERKLE_TREE_SEED,
11    },
12};
13
14/// Configures the authority of the merkle tree which can:
15/// - register new verifiers
16/// - register new asset pools
17/// - register new asset pool types
18/// - set permissions for new asset pool creation
19/// - keeps current highest index for assets and merkle trees to enable lookups of these
20#[account]
21#[aligned_sized(anchor)]
22pub struct MerkleTreeAuthority {
23    pub pubkey: Pubkey,
24    pub transaction_merkle_tree_index: u64,
25    pub event_merkle_tree_index: u64,
26    pub registered_asset_index: u64,
27    pub enable_permissionless_spl_tokens: bool,
28    pub enable_permissionless_merkle_tree_registration: bool,
29}
30
31#[derive(Accounts)]
32pub struct InitializeMerkleTreeAuthority<'info> {
33    #[account(
34        init,
35        payer = authority,
36        seeds = [MERKLE_TREE_AUTHORITY_SEED],
37        bump,
38        space = MerkleTreeAuthority::LEN,
39    )]
40    pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
41    #[account(
42        init,
43        seeds = [
44            TRANSACTION_MERKLE_TREE_SEED,
45            0u64.to_le_bytes().as_ref(),
46        ],
47        bump,
48        payer = authority,
49        space = TransactionMerkleTree::LEN,
50    )]
51    pub transaction_merkle_tree: AccountLoader<'info, TransactionMerkleTree>,
52    #[account(
53        init,
54        seeds = [
55            EVENT_MERKLE_TREE_SEED,
56            0u64.to_le_bytes().as_ref(),
57        ],
58        bump,
59        payer=authority,
60        space = EventMerkleTree::LEN,
61    )]
62    pub event_merkle_tree: AccountLoader<'info, EventMerkleTree>,
63    /// CHECK:` Signer is merkle tree init authority.
64    #[account(mut, address=anchor_lang::prelude::Pubkey::try_from(config::INITIAL_MERKLE_TREE_AUTHORITY).map_err(|_| ErrorCode::PubkeyTryFromFailed)? @ErrorCode::InvalidAuthority)]
65    pub authority: Signer<'info>,
66    pub system_program: Program<'info, System>,
67    pub rent: Sysvar<'info, Rent>,
68}
69
70#[derive(Accounts)]
71pub struct UpdateMerkleTreeAuthority<'info> {
72    #[account(mut, seeds = [MERKLE_TREE_AUTHORITY_SEED], bump)]
73    pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
74    /// CHECK:` Signer is merkle tree authority.
75    #[account(address=merkle_tree_authority_pda.pubkey @ErrorCode::InvalidAuthority)]
76    pub authority: Signer<'info>,
77    /// CHECK:` New authority no need to be checked
78    pub new_authority: UncheckedAccount<'info>,
79}
80
81#[derive(Accounts)]
82pub struct UpdateMerkleTreeAuthorityConfig<'info> {
83    #[account(mut, seeds = [MERKLE_TREE_AUTHORITY_SEED], bump)]
84    pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
85    /// CHECK:` Signer is merkle tree authority.
86    #[account( address=merkle_tree_authority_pda.pubkey @ErrorCode::InvalidAuthority)]
87    pub authority: Signer<'info>,
88}
89
90#[derive(Accounts)]
91pub struct UpdateLockDuration<'info> {
92    #[account(mut, seeds = [MERKLE_TREE_AUTHORITY_SEED], bump)]
93    pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
94    /// CHECK:` Signer is merkle tree authority.
95    #[account( address=merkle_tree_authority_pda.pubkey @ErrorCode::InvalidAuthority)]
96    pub authority: Signer<'info>,
97    #[account(mut)]
98    pub transaction_merkle_tree: AccountLoader<'info, TransactionMerkleTree>,
99}