use anchor_lang::prelude::*;
use crate::{
config,
errors::ErrorCode,
event_merkle_tree::EventMerkleTree,
transaction_merkle_tree::state::TransactionMerkleTree,
utils::constants::{
EVENT_MERKLE_TREE_SEED, MERKLE_TREE_AUTHORITY_SEED, TRANSACTION_MERKLE_TREE_SEED,
},
};
#[account]
pub struct MerkleTreeAuthority {
pub pubkey: Pubkey,
pub transaction_merkle_tree_index: u64,
pub event_merkle_tree_index: u64,
pub registered_asset_index: u64,
pub enable_permissionless_spl_tokens: bool,
pub enable_permissionless_merkle_tree_registration: bool,
}
#[derive(Accounts)]
pub struct InitializeMerkleTreeAuthority<'info> {
#[account(
init,
payer = authority,
seeds = [MERKLE_TREE_AUTHORITY_SEED],
bump,
space = 8 + 32 + 8 + 8 + 8 + 8
)]
pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
#[account(
init,
seeds = [
TRANSACTION_MERKLE_TREE_SEED,
0u64.to_le_bytes().as_ref(),
],
bump,
payer = authority,
space = 8880
)]
pub transaction_merkle_tree: AccountLoader<'info, TransactionMerkleTree>,
#[account(
init,
seeds = [
EVENT_MERKLE_TREE_SEED,
0u64.to_le_bytes().as_ref(),
],
bump,
payer=authority,
space = 1280,
)]
pub event_merkle_tree: AccountLoader<'info, EventMerkleTree>,
#[account(mut, address=anchor_lang::prelude::Pubkey::try_from(config::INITIAL_MERKLE_TREE_AUTHORITY).map_err(|_| ErrorCode::PubkeyTryFromFailed)? @ErrorCode::InvalidAuthority)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
}
#[derive(Accounts)]
pub struct UpdateMerkleTreeAuthority<'info> {
#[account(mut, seeds = [MERKLE_TREE_AUTHORITY_SEED], bump)]
pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
#[account(address=merkle_tree_authority_pda.pubkey @ErrorCode::InvalidAuthority)]
pub authority: Signer<'info>,
pub new_authority: UncheckedAccount<'info>,
}
#[derive(Accounts)]
pub struct UpdateMerkleTreeAuthorityConfig<'info> {
#[account(mut, seeds = [MERKLE_TREE_AUTHORITY_SEED], bump)]
pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
#[account( address=merkle_tree_authority_pda.pubkey @ErrorCode::InvalidAuthority)]
pub authority: Signer<'info>,
}
#[derive(Accounts)]
pub struct UpdateLockDuration<'info> {
#[account(mut, seeds = [MERKLE_TREE_AUTHORITY_SEED], bump)]
pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
#[account( address=merkle_tree_authority_pda.pubkey @ErrorCode::InvalidAuthority)]
pub authority: Signer<'info>,
#[account(mut)]
pub transaction_merkle_tree: AccountLoader<'info, TransactionMerkleTree>,
}