1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use {
crate::objects::*,
anchor_lang::prelude::*,
clockwork_utils::{anchor_sighash, AccountMetaData, CrankResponse, InstructionData},
};
#[derive(Accounts)]
pub struct RegistryEpochKickoff<'info> {
#[account(address = Config::pubkey())]
pub config: Account<'info, Config>,
#[account(address = config.epoch_queue)]
pub queue: Signer<'info>,
#[account(
mut,
seeds = [SEED_REGISTRY],
bump,
)]
pub registry: Account<'info, Registry>,
#[account(
address = snapshot.pubkey(),
constraint = snapshot.id.eq(®istry.current_epoch)
)]
pub snapshot: Account<'info, Snapshot>,
}
pub fn handler(ctx: Context<RegistryEpochKickoff>) -> Result<CrankResponse> {
let config = &ctx.accounts.config;
let queue = &ctx.accounts.queue;
let registry = &mut ctx.accounts.registry;
let snapshot = &ctx.accounts.snapshot;
registry.locked = true;
let kickoff_instruction = Some(InstructionData {
program_id: crate::ID,
accounts: vec![
AccountMetaData::new_readonly(config.key(), false),
AccountMetaData::new_readonly(queue.key(), true),
AccountMetaData::new(registry.key(), false),
AccountMetaData::new_readonly(
Snapshot::pubkey(snapshot.id.checked_add(1).unwrap()),
false,
),
],
data: anchor_sighash("registry_epoch_kickoff").to_vec(),
});
let next_instruction = if snapshot.total_frames.gt(&0) {
Some(InstructionData {
program_id: crate::ID,
accounts: vec![
AccountMetaData::new_readonly(config.key(), false),
AccountMetaData::new(Fee::pubkey(Worker::pubkey(0)), false),
AccountMetaData::new_readonly(queue.key(), true),
AccountMetaData::new_readonly(registry.key(), false),
AccountMetaData::new_readonly(snapshot.key(), false),
AccountMetaData::new_readonly(SnapshotFrame::pubkey(snapshot.key(), 0), false),
AccountMetaData::new(Worker::pubkey(0), false),
],
data: anchor_sighash("worker_fees_distribute").to_vec(),
})
} else if registry.total_workers.gt(&0) {
Some(InstructionData {
program_id: crate::ID,
accounts: vec![
AccountMetaData::new_readonly(config.key(), false),
AccountMetaData::new_readonly(queue.key(), true),
AccountMetaData::new_readonly(registry.key(), false),
AccountMetaData::new_readonly(Worker::pubkey(0), false),
],
data: anchor_sighash("worker_delegations_stake").to_vec(),
})
} else {
Some(InstructionData {
program_id: crate::ID,
accounts: vec![
AccountMetaData::new_readonly(config.key(), false),
AccountMetaData::new_readonly(queue.key(), true),
AccountMetaData::new(registry.key(), false),
],
data: anchor_sighash("registry_epoch_cutover").to_vec(),
})
};
Ok(CrankResponse {
kickoff_instruction,
next_instruction,
})
}