cronos_pool/instructions/
initialize.rs

1use {
2    crate::state::*,
3    anchor_lang::{prelude::*, solana_program::system_program},
4    std::mem::size_of,
5};
6
7#[derive(Accounts)]
8#[account(rotator: Pubkey)]
9pub struct Initialize<'info> {
10    #[account(mut)]
11    pub admin: Signer<'info>,
12
13    #[account(
14        init,
15        seeds = [SEED_CONFIG],
16        bump,
17        payer = admin,
18        space = 8 + size_of::<Config>(),
19    )]
20    pub config: Account<'info, Config>,
21
22    #[account(
23        init,
24        seeds = [SEED_POOL],
25        bump,
26        payer = admin,
27        space = 8 + size_of::<Pool>() + (size_of::<Pubkey>() * 10),
28    )]
29    pub pool: Account<'info, Pool>,
30
31    #[account(address = system_program::ID)]
32    pub system_program: Program<'info, System>,
33}
34
35pub fn handler(ctx: Context<Initialize>, rotator: Pubkey) -> Result<()> {
36    let admin = &ctx.accounts.admin;
37    let config = &mut ctx.accounts.config;
38    let pool = &mut ctx.accounts.pool;
39
40    config.new(admin.key(), rotator)?;
41    pool.new()?;
42
43    Ok(())
44}