sablier_network_program/jobs/distribute_fees/
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)]
25pub struct DistributeFeesProcessSnapshot<'info> {
26 #[account(address = Config::pubkey())]
27 pub config: AccountLoader<'info, Config>,
28
29 #[account(seeds = [SEED_REGISTRY], bump)]
30 pub registry: Account<'info, Registry>,
31
32 #[account(
33 address = snapshot.pubkey(),
34 constraint = snapshot.id == registry.current_epoch
35 )]
36 pub snapshot: Account<'info, Snapshot>,
37
38 #[account(address = config.load()?.epoch_thread)]
39 pub thread: Signer<'info>,
40}
41
42pub fn handler(ctx: Context<DistributeFeesProcessSnapshot>) -> Result<ThreadResponse> {
43 let config = &ctx.accounts.config;
44 let registry = &mut ctx.accounts.registry;
45 let snapshot = &ctx.accounts.snapshot;
46 let thread = &ctx.accounts.thread;
47
48 Ok(ThreadResponse {
49 dynamic_instruction: if snapshot.total_frames > 0 {
50 Some(
51 Instruction {
52 program_id: crate::ID,
53 accounts: crate::accounts::DistributeFeesProcessFrame {
54 config: config.key(),
55 fee: Fee::pubkey(Worker::pubkey(0)),
56 registry: registry.key(),
57 snapshot: snapshot.key(),
58 snapshot_frame: SnapshotFrame::pubkey(snapshot.key(), 0),
59 thread: thread.key(),
60 worker: Worker::pubkey(0),
61 }
62 .to_account_metas(Some(true)),
63 data: crate::instruction::DistributeFeesProcessFrame {}.data(),
64 }
65 .into(),
66 )
67 } else {
68 None
69 },
70 close_to: None,
71 trigger: None,
72 })
73}