sablier_network_program/instructions/
initialize.rs1use {
2 crate::{constants::*, state::*},
3 anchor_lang::prelude::*,
4 anchor_spl::token::Mint,
5};
6
7#[derive(Accounts)]
8pub struct Initialize<'info> {
9 #[account(mut)]
10 pub admin: Signer<'info>,
11
12 #[account(
13 init,
14 seeds = [SEED_CONFIG],
15 bump,
16 payer = admin,
17 space = 8 + Config::INIT_SPACE,
18 )]
19 pub config: AccountLoader<'info, Config>,
20
21 pub mint: Account<'info, Mint>,
22
23 #[account(
24 init,
25 seeds = [SEED_REGISTRY],
26 bump,
27 payer = admin,
28 space = 8 + Registry::INIT_SPACE,
29 )]
30 pub registry: Account<'info, Registry>,
31
32 #[account(
33 init,
34 seeds = [
35 SEED_SNAPSHOT,
36 0_u64.to_be_bytes().as_ref(),
37 ],
38 bump,
39 payer = admin,
40 space = 8 + Snapshot::INIT_SPACE,
41 )]
42 pub snapshot: Account<'info, Snapshot>,
43
44 pub system_program: Program<'info, System>,
45}
46
47pub fn handler(ctx: Context<Initialize>) -> Result<()> {
48 let admin = &ctx.accounts.admin;
50 let config = &mut ctx.accounts.config;
51 let mint = &ctx.accounts.mint;
52 let registry = &mut ctx.accounts.registry;
53 let snapshot = &mut ctx.accounts.snapshot;
54
55 config.init(admin.key(), mint.key())?;
57 registry.init(ctx.bumps.registry)?;
58 snapshot.init(0)?;
59
60 Ok(())
61}