use aligned_sized::aligned_sized;
use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, Token, TokenAccount};
use crate::{
utils::constants::{POOL_CONFIG_SEED, POOL_SEED, POOL_TYPE_SEED, TOKEN_AUTHORITY_SEED},
MerkleTreeAuthority,
};
#[account]
#[aligned_sized(anchor)]
pub struct RegisteredAssetPool {
pub asset_pool_pubkey: Pubkey,
pub pool_type: [u8; 32],
pub index: u64,
}
#[account]
#[aligned_sized(anchor)]
pub struct RegisteredPoolType {
pub pool_type: [u8; 32],
}
#[derive(Accounts)]
#[instruction(pool_type: [u8;32])]
pub struct RegisterPoolType<'info> {
#[account(
init,
payer = authority,
seeds = [&pool_type, POOL_TYPE_SEED],
bump,
space = RegisteredPoolType::LEN,
)]
pub registered_pool_type_pda: Account<'info, RegisteredPoolType>,
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
}
#[derive(Accounts)]
pub struct RegisterSplPool<'info> {
#[account(
init,
payer = authority,
seeds = [&mint.key().to_bytes(), ®istered_pool_type_pda.pool_type, POOL_CONFIG_SEED],
bump,
space = RegisteredAssetPool::LEN,
)]
pub registered_asset_pool_pda: Account<'info, RegisteredAssetPool>,
#[account(init,
seeds = [
&mint.key().to_bytes(), ®istered_pool_type_pda.pool_type,
POOL_SEED
],
bump,
payer = authority,
token::mint = mint,
token::authority = token_authority
)]
pub merkle_tree_pda_token: Account<'info, TokenAccount>,
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
#[account(mut)]
pub mint: Account<'info, Mint>,
#[account(mut, seeds=[TOKEN_AUTHORITY_SEED], bump)]
pub token_authority: AccountInfo<'info>,
pub token_program: Program<'info, Token>,
#[account(
seeds = [®istered_pool_type_pda.pool_type[..], POOL_TYPE_SEED],
bump,
)]
pub registered_pool_type_pda: Account<'info, RegisteredPoolType>,
#[account(mut)]
pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
}
#[derive(Accounts)]
pub struct RegisterSolPool<'info> {
#[account(
init,
payer = authority,
seeds = [&[0u8;32], ®istered_pool_type_pda.pool_type, POOL_CONFIG_SEED],
bump,
space = RegisteredAssetPool::LEN,
)]
pub registered_asset_pool_pda: Account<'info, RegisteredAssetPool>,
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
#[account(
seeds = [®istered_pool_type_pda.pool_type[..], POOL_TYPE_SEED],
bump,
)]
pub registered_pool_type_pda: Account<'info, RegisteredPoolType>,
#[account(mut)]
pub merkle_tree_authority_pda: Account<'info, MerkleTreeAuthority>,
}