sablier_network_program/jobs/distribute_fees/
job.rs

1use anchor_lang::{prelude::*, solana_program::instruction::Instruction, InstructionData};
2use sablier_utils::thread::ThreadResponse;
3
4use crate::{constants::*, state::*};
5
6#[derive(Accounts)]
7pub struct DistributeFeesJob<'info> {
8    #[account(address = Config::pubkey())]
9    pub config: AccountLoader<'info, Config>,
10
11    #[account(
12        mut,
13        seeds = [SEED_REGISTRY],
14        bump,
15    )]
16    pub registry: Account<'info, Registry>,
17
18    #[account(address = config.load()?.epoch_thread)]
19    pub thread: Signer<'info>,
20}
21
22pub fn handler(ctx: Context<DistributeFeesJob>) -> Result<ThreadResponse> {
23    // Get accounts.
24    let config = &ctx.accounts.config;
25    let registry = &mut ctx.accounts.registry;
26    let thread = &ctx.accounts.thread;
27
28    // Lock the registry.
29    registry.locked = true;
30
31    // Process the snapshot.
32    Ok(ThreadResponse {
33        dynamic_instruction: Some(
34            Instruction {
35                program_id: crate::ID,
36                accounts: crate::accounts::DistributeFeesProcessSnapshot {
37                    config: config.key(),
38                    registry: registry.key(),
39                    snapshot: Snapshot::pubkey(registry.current_epoch),
40                    thread: thread.key(),
41                }
42                .to_account_metas(Some(true)),
43                data: crate::instruction::DistributeFeesProcessSnapshot {}.data(),
44            }
45            .into(),
46        ),
47        close_to: None,
48        trigger: None,
49    })
50}