clockwork_pool_program/instructions/
pool_create.rs1use {
2 crate::objects::*,
3 anchor_lang::{prelude::*, solana_program::system_program},
4 std::mem::size_of,
5};
6
7#[derive(Accounts)]
8#[instruction(name: String, size: usize)]
9pub struct PoolCreate<'info> {
10 #[account(
11 address = Config::pubkey(),
12 has_one = pool_authority
13 )]
14 pub config: Account<'info, Config>,
15
16 #[account(mut)]
17 pub payer: Signer<'info>,
18
19 #[account(
20 init,
21 seeds = [
22 SEED_POOL,
23 name.as_bytes(),
24 ],
25 bump,
26 payer = payer,
27 space = 8 + size_of::<Pool>() + (size_of::<Pubkey>() * size) + name.as_bytes().len(),
28 )]
29 pub pool: Account<'info, Pool>,
30
31 #[account()]
32 pub pool_authority: Signer<'info>,
33
34 #[account(address = system_program::ID)]
35 pub system_program: Program<'info, System>,
36}
37
38pub fn handler(ctx: Context<PoolCreate>, name: String, size: usize) -> Result<()> {
39 let pool = &mut ctx.accounts.pool;
41
42 pool.init(name, size)?;
44
45 Ok(())
46}