sablier_network_program/jobs/delete_snapshot/
process_snapshot.rs1use anchor_lang::{prelude::*, solana_program::instruction::Instruction, InstructionData};
2use sablier_utils::thread::ThreadResponse;
3
4use crate::{constants::*, state::*};
5
6#[derive(Accounts)]
7pub struct DeleteSnapshotProcessSnapshot<'info> {
8 #[account(address = Config::pubkey())]
9 pub config: AccountLoader<'info, Config>,
10
11 #[account(
12 address = Registry::pubkey(),
13 constraint = !registry.locked
14 )]
15 pub registry: Account<'info, Registry>,
16
17 #[account(
18 mut,
19 seeds = [
20 SEED_SNAPSHOT,
21 snapshot.id.to_be_bytes().as_ref(),
22 ],
23 bump,
24 constraint = snapshot.id < registry.current_epoch
25 )]
26 pub snapshot: Account<'info, Snapshot>,
27
28 #[account(
29 mut,
30 address = config.load()?.epoch_thread
31 )]
32 pub thread: Signer<'info>,
33}
34
35pub fn handler(ctx: Context<DeleteSnapshotProcessSnapshot>) -> Result<ThreadResponse> {
36 let config = &ctx.accounts.config;
38 let registry = &ctx.accounts.registry;
39 let snapshot = &mut ctx.accounts.snapshot;
40 let thread = &mut ctx.accounts.thread;
41
42 if snapshot.total_frames == 0 {
44 let snapshot_lamports = snapshot.get_lamports();
45 snapshot.sub_lamports(snapshot_lamports)?;
46 thread.add_lamports(snapshot_lamports)?;
47 }
48
49 let dynamic_instruction = if snapshot.total_frames > 0 {
51 Some(
53 Instruction {
54 program_id: crate::ID,
55 accounts: crate::accounts::DeleteSnapshotProcessFrame {
56 config: config.key(),
57 registry: registry.key(),
58 snapshot: snapshot.key(),
59 snapshot_frame: SnapshotFrame::pubkey(snapshot.key(), 0),
60 thread: thread.key(),
61 }
62 .to_account_metas(Some(true)),
63 data: crate::instruction::DeleteSnapshotProcessFrame {}.data(),
64 }
65 .into(),
66 )
67 } else {
68 None
70 };
71
72 Ok(ThreadResponse {
73 dynamic_instruction,
74 close_to: None,
75 trigger: None,
76 })
77}