sablier_network_program/jobs/process_unstakes/
job.rs1use anchor_lang::{prelude::*, solana_program::instruction::Instruction, InstructionData};
2use sablier_utils::thread::ThreadResponse;
3
4use crate::state::*;
5
6#[derive(Accounts)]
7pub struct ProcessUnstakesJob<'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(address = config.load()?.epoch_thread)]
18 pub thread: Signer<'info>,
19}
20
21pub fn handler(ctx: Context<ProcessUnstakesJob>) -> Result<ThreadResponse> {
22 let config = &ctx.accounts.config;
24 let registry = &ctx.accounts.registry;
25 let thread = &ctx.accounts.thread;
26
27 Ok(ThreadResponse {
29 dynamic_instruction: if registry.total_unstakes > 0 {
30 Some(
31 Instruction {
32 program_id: crate::ID,
33 accounts: crate::accounts::UnstakePreprocess {
34 config: config.key(),
35 registry: registry.key(),
36 thread: thread.key(),
37 unstake: Unstake::pubkey(0),
38 }
39 .to_account_metas(Some(true)),
40 data: crate::instruction::UnstakePreprocess {}.data(),
41 }
42 .into(),
43 )
44 } else {
45 None
46 },
47 close_to: None,
48 trigger: None,
49 })
50}