sablier_network_program/instructions/
pool_create.rs1use {
2 crate::{constants::*, errors::*, state::*},
3 anchor_lang::prelude::*,
4 std::mem::size_of,
5};
6
7#[derive(Accounts)]
8pub struct PoolCreate<'info> {
9 #[account(address = config.load()?.admin)]
10 pub admin: Signer<'info>,
11
12 #[account(
13 address = Config::pubkey(),
14 has_one = admin
15 )]
16 pub config: AccountLoader<'info, Config>,
17
18 #[account(mut)]
19 pub payer: Signer<'info>,
20
21 #[account(
22 init,
23 seeds = [
24 SEED_POOL,
25 registry.total_pools.to_be_bytes().as_ref(),
26 ],
27 bump,
28 payer = payer,
29 space = 8 + size_of::<Pool>() + size_of::<Pubkey>(),
30 )]
31 pub pool: Account<'info, Pool>,
32
33 #[account(
34 mut,
35 seeds = [SEED_REGISTRY],
36 bump,
37 constraint = !registry.locked @ SablierError::RegistryLocked
38 )]
39 pub registry: Box<Account<'info, Registry>>,
40
41 pub system_program: Program<'info, System>,
42}
43
44pub fn handler(ctx: Context<PoolCreate>) -> Result<()> {
45 let pool = &mut ctx.accounts.pool;
47 let registry = &mut ctx.accounts.registry;
48
49 pool.init(registry.total_pools)?;
51
52 registry.total_pools += 1;
54
55 Ok(())
56}