sablier_network_program/instructions/
pool_update.rs1use {
2 crate::state::*,
3 anchor_lang::{
4 prelude::*,
5 system_program::{transfer, Transfer},
6 },
7 sablier_utils::account::AccountInfoExt,
8 std::mem::size_of,
9};
10
11#[derive(Accounts)]
12#[instruction(settings: PoolSettings)]
13pub struct PoolUpdate<'info> {
14 pub admin: Signer<'info>,
15
16 #[account(
17 address = Config::pubkey(),
18 has_one = admin
19 )]
20 pub config: AccountLoader<'info, Config>,
21
22 #[account(mut)]
23 pub payer: Signer<'info>,
24
25 #[account(mut, address = pool.pubkey())]
26 pub pool: Account<'info, Pool>,
27
28 pub system_program: Program<'info, System>,
29}
30
31pub fn handler(ctx: Context<PoolUpdate>, settings: PoolSettings) -> Result<()> {
32 let payer = &ctx.accounts.payer;
34 let pool = &mut ctx.accounts.pool;
35 let system_program = &ctx.accounts.system_program;
36
37 pool.update(&settings)?;
39
40 let data_len = 8 + size_of::<Pool>() + settings.size.checked_mul(size_of::<Pubkey>()).unwrap();
42 pool.realloc(data_len, false)?;
43
44 let minimum_rent = Rent::get()?.minimum_balance(data_len);
46 if minimum_rent > pool.get_lamports() {
47 transfer(
48 CpiContext::new(
49 system_program.to_account_info(),
50 Transfer {
51 from: payer.to_account_info(),
52 to: pool.to_account_info(),
53 },
54 ),
55 minimum_rent - pool.get_lamports(),
56 )?;
57 }
58
59 Ok(())
60}