sablier_network_program/jobs/process_unstakes/
unstake_preprocess.rs1use anchor_lang::{prelude::*, solana_program::instruction::Instruction, InstructionData};
2use anchor_spl::associated_token::get_associated_token_address;
3use sablier_utils::thread::ThreadResponse;
4
5use crate::state::*;
6
7#[derive(Accounts)]
8pub struct UnstakePreprocess<'info> {
9 #[account(address = Config::pubkey())]
10 pub config: AccountLoader<'info, Config>,
11
12 #[account(
13 address = Registry::pubkey(),
14 constraint = registry.locked
15 )]
16 pub registry: Account<'info, Registry>,
17
18 #[account(address = config.load()?.epoch_thread)]
19 pub thread: Signer<'info>,
20
21 #[account(address = unstake.pubkey())]
22 pub unstake: Account<'info, Unstake>,
23}
24
25pub fn handler(ctx: Context<UnstakePreprocess>) -> Result<ThreadResponse> {
26 let config_key = ctx.accounts.config.key();
28 let config = &ctx.accounts.config.load()?;
29 let registry = &ctx.accounts.registry;
30 let thread = &ctx.accounts.thread;
31 let unstake = &ctx.accounts.unstake;
32
33 Ok(ThreadResponse {
35 dynamic_instruction: Some(
36 Instruction {
37 program_id: crate::ID,
38 accounts: crate::accounts::UnstakeProcess {
39 authority: unstake.authority,
40 authority_tokens: get_associated_token_address(
41 &unstake.authority,
42 &config.mint,
43 ),
44 config: config_key,
45 delegation: unstake.delegation,
46 registry: registry.key(),
47 thread: thread.key(),
48 token_program: anchor_spl::token::ID,
49 unstake: unstake.key(),
50 worker: unstake.worker,
51 worker_tokens: get_associated_token_address(&unstake.worker, &config.mint),
52 }
53 .to_account_metas(Some(true)),
54 data: crate::instruction::UnstakeProcess {}.data(),
55 }
56 .into(),
57 ),
58 ..ThreadResponse::default()
59 })
60}