1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const TRIGGER_EPOCH_DRAW_DISCRIMINATOR: [u8; 8] = [93, 12, 139, 55, 235, 88, 37, 117];
12
13#[derive(Debug)]
15pub struct TriggerEpochDraw {
16
17
18 pub authority: solana_address::Address,
19
20
21 pub satrush_config: solana_address::Address,
22
23
24 pub epoch_vault: solana_address::Address,
25
26
27 pub epoch_vault_iteration: solana_address::Address,
28
29
30 pub next_epoch_vault_iteration: solana_address::Address,
31 pub slot_hashes: solana_address::Address,
36
37
38 pub system_program: solana_address::Address,
39 }
40
41impl TriggerEpochDraw {
42 pub fn instruction(&self) -> solana_instruction::Instruction {
43 self.instruction_with_remaining_accounts(&[])
44 }
45 #[allow(clippy::arithmetic_side_effects)]
46 #[allow(clippy::vec_init_then_push)]
47 pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
48 let mut accounts = Vec::with_capacity(7+ remaining_accounts.len());
49 accounts.push(solana_instruction::AccountMeta::new(
50 self.authority,
51 true
52 ));
53 accounts.push(solana_instruction::AccountMeta::new_readonly(
54 self.satrush_config,
55 false
56 ));
57 accounts.push(solana_instruction::AccountMeta::new(
58 self.epoch_vault,
59 false
60 ));
61 accounts.push(solana_instruction::AccountMeta::new(
62 self.epoch_vault_iteration,
63 false
64 ));
65 accounts.push(solana_instruction::AccountMeta::new(
66 self.next_epoch_vault_iteration,
67 false
68 ));
69 accounts.push(solana_instruction::AccountMeta::new_readonly(
70 self.slot_hashes,
71 false
72 ));
73 accounts.push(solana_instruction::AccountMeta::new_readonly(
74 self.system_program,
75 false
76 ));
77 accounts.extend_from_slice(remaining_accounts);
78 let data = TriggerEpochDrawInstructionData::new().try_to_vec().unwrap();
79
80 solana_instruction::Instruction {
81 program_id: crate::SATRUSH_ID,
82 accounts,
83 data,
84 }
85 }
86}
87
88#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
89 pub struct TriggerEpochDrawInstructionData {
90 discriminator: [u8; 8],
91 }
92
93impl TriggerEpochDrawInstructionData {
94 pub fn new() -> Self {
95 Self {
96 discriminator: [93, 12, 139, 55, 235, 88, 37, 117],
97 }
98 }
99
100 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
101 borsh::to_vec(self)
102 }
103 }
104
105impl Default for TriggerEpochDrawInstructionData {
106 fn default() -> Self {
107 Self::new()
108 }
109}
110
111
112
113#[derive(Clone, Debug, Default)]
125pub struct TriggerEpochDrawBuilder {
126 authority: Option<solana_address::Address>,
127 satrush_config: Option<solana_address::Address>,
128 epoch_vault: Option<solana_address::Address>,
129 epoch_vault_iteration: Option<solana_address::Address>,
130 next_epoch_vault_iteration: Option<solana_address::Address>,
131 slot_hashes: Option<solana_address::Address>,
132 system_program: Option<solana_address::Address>,
133 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
134}
135
136impl TriggerEpochDrawBuilder {
137 pub fn new() -> Self {
138 Self::default()
139 }
140 #[inline(always)]
141 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
142 self.authority = Some(authority);
143 self
144 }
145 #[inline(always)]
146 pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
147 self.satrush_config = Some(satrush_config);
148 self
149 }
150 #[inline(always)]
151 pub fn epoch_vault(&mut self, epoch_vault: solana_address::Address) -> &mut Self {
152 self.epoch_vault = Some(epoch_vault);
153 self
154 }
155 #[inline(always)]
156 pub fn epoch_vault_iteration(&mut self, epoch_vault_iteration: solana_address::Address) -> &mut Self {
157 self.epoch_vault_iteration = Some(epoch_vault_iteration);
158 self
159 }
160 #[inline(always)]
161 pub fn next_epoch_vault_iteration(&mut self, next_epoch_vault_iteration: solana_address::Address) -> &mut Self {
162 self.next_epoch_vault_iteration = Some(next_epoch_vault_iteration);
163 self
164 }
165 #[inline(always)]
168 pub fn slot_hashes(&mut self, slot_hashes: solana_address::Address) -> &mut Self {
169 self.slot_hashes = Some(slot_hashes);
170 self
171 }
172 #[inline(always)]
174 pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
175 self.system_program = Some(system_program);
176 self
177 }
178 #[inline(always)]
180 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
181 self.__remaining_accounts.push(account);
182 self
183 }
184 #[inline(always)]
186 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
187 self.__remaining_accounts.extend_from_slice(accounts);
188 self
189 }
190 #[allow(clippy::clone_on_copy)]
191 pub fn instruction(&self) -> solana_instruction::Instruction {
192 let accounts = TriggerEpochDraw {
193 authority: self.authority.expect("authority is not set"),
194 satrush_config: self.satrush_config.expect("satrush_config is not set"),
195 epoch_vault: self.epoch_vault.expect("epoch_vault is not set"),
196 epoch_vault_iteration: self.epoch_vault_iteration.expect("epoch_vault_iteration is not set"),
197 next_epoch_vault_iteration: self.next_epoch_vault_iteration.expect("next_epoch_vault_iteration is not set"),
198 slot_hashes: self.slot_hashes.unwrap_or(solana_address::address!("SysvarS1otHashes111111111111111111111111111")),
199 system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
200 };
201
202 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
203 }
204}
205
206 pub struct TriggerEpochDrawCpiAccounts<'a, 'b> {
208
209
210 pub authority: &'b solana_account_info::AccountInfo<'a>,
211
212
213 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
214
215
216 pub epoch_vault: &'b solana_account_info::AccountInfo<'a>,
217
218
219 pub epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>,
220
221
222 pub next_epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>,
223 pub slot_hashes: &'b solana_account_info::AccountInfo<'a>,
228
229
230 pub system_program: &'b solana_account_info::AccountInfo<'a>,
231 }
232
233pub struct TriggerEpochDrawCpi<'a, 'b> {
235 pub __program: &'b solana_account_info::AccountInfo<'a>,
237
238
239 pub authority: &'b solana_account_info::AccountInfo<'a>,
240
241
242 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
243
244
245 pub epoch_vault: &'b solana_account_info::AccountInfo<'a>,
246
247
248 pub epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>,
249
250
251 pub next_epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>,
252 pub slot_hashes: &'b solana_account_info::AccountInfo<'a>,
257
258
259 pub system_program: &'b solana_account_info::AccountInfo<'a>,
260 }
261
262impl<'a, 'b> TriggerEpochDrawCpi<'a, 'b> {
263 pub fn new(
264 program: &'b solana_account_info::AccountInfo<'a>,
265 accounts: TriggerEpochDrawCpiAccounts<'a, 'b>,
266 ) -> Self {
267 Self {
268 __program: program,
269 authority: accounts.authority,
270 satrush_config: accounts.satrush_config,
271 epoch_vault: accounts.epoch_vault,
272 epoch_vault_iteration: accounts.epoch_vault_iteration,
273 next_epoch_vault_iteration: accounts.next_epoch_vault_iteration,
274 slot_hashes: accounts.slot_hashes,
275 system_program: accounts.system_program,
276 }
277 }
278 #[inline(always)]
279 pub fn invoke(&self) -> solana_program_error::ProgramResult {
280 self.invoke_signed_with_remaining_accounts(&[], &[])
281 }
282 #[inline(always)]
283 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
284 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
285 }
286 #[inline(always)]
287 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
288 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
289 }
290 #[allow(clippy::arithmetic_side_effects)]
291 #[allow(clippy::clone_on_copy)]
292 #[allow(clippy::vec_init_then_push)]
293 pub fn invoke_signed_with_remaining_accounts(
294 &self,
295 signers_seeds: &[&[&[u8]]],
296 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
297 ) -> solana_program_error::ProgramResult {
298 let mut accounts = Vec::with_capacity(7+ remaining_accounts.len());
299 accounts.push(solana_instruction::AccountMeta::new(
300 *self.authority.key,
301 true
302 ));
303 accounts.push(solana_instruction::AccountMeta::new_readonly(
304 *self.satrush_config.key,
305 false
306 ));
307 accounts.push(solana_instruction::AccountMeta::new(
308 *self.epoch_vault.key,
309 false
310 ));
311 accounts.push(solana_instruction::AccountMeta::new(
312 *self.epoch_vault_iteration.key,
313 false
314 ));
315 accounts.push(solana_instruction::AccountMeta::new(
316 *self.next_epoch_vault_iteration.key,
317 false
318 ));
319 accounts.push(solana_instruction::AccountMeta::new_readonly(
320 *self.slot_hashes.key,
321 false
322 ));
323 accounts.push(solana_instruction::AccountMeta::new_readonly(
324 *self.system_program.key,
325 false
326 ));
327 remaining_accounts.iter().for_each(|remaining_account| {
328 accounts.push(solana_instruction::AccountMeta {
329 pubkey: *remaining_account.0.key,
330 is_signer: remaining_account.1,
331 is_writable: remaining_account.2,
332 })
333 });
334 let data = TriggerEpochDrawInstructionData::new().try_to_vec().unwrap();
335
336 let instruction = solana_instruction::Instruction {
337 program_id: crate::SATRUSH_ID,
338 accounts,
339 data,
340 };
341 let mut account_infos = Vec::with_capacity(8 + remaining_accounts.len());
342 account_infos.push(self.__program.clone());
343 account_infos.push(self.authority.clone());
344 account_infos.push(self.satrush_config.clone());
345 account_infos.push(self.epoch_vault.clone());
346 account_infos.push(self.epoch_vault_iteration.clone());
347 account_infos.push(self.next_epoch_vault_iteration.clone());
348 account_infos.push(self.slot_hashes.clone());
349 account_infos.push(self.system_program.clone());
350 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
351
352 if signers_seeds.is_empty() {
353 solana_cpi::invoke(&instruction, &account_infos)
354 } else {
355 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
356 }
357 }
358}
359
360#[derive(Clone, Debug)]
372pub struct TriggerEpochDrawCpiBuilder<'a, 'b> {
373 instruction: Box<TriggerEpochDrawCpiBuilderInstruction<'a, 'b>>,
374}
375
376impl<'a, 'b> TriggerEpochDrawCpiBuilder<'a, 'b> {
377 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
378 let instruction = Box::new(TriggerEpochDrawCpiBuilderInstruction {
379 __program: program,
380 authority: None,
381 satrush_config: None,
382 epoch_vault: None,
383 epoch_vault_iteration: None,
384 next_epoch_vault_iteration: None,
385 slot_hashes: None,
386 system_program: None,
387 __remaining_accounts: Vec::new(),
388 });
389 Self { instruction }
390 }
391 #[inline(always)]
392 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
393 self.instruction.authority = Some(authority);
394 self
395 }
396 #[inline(always)]
397 pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
398 self.instruction.satrush_config = Some(satrush_config);
399 self
400 }
401 #[inline(always)]
402 pub fn epoch_vault(&mut self, epoch_vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
403 self.instruction.epoch_vault = Some(epoch_vault);
404 self
405 }
406 #[inline(always)]
407 pub fn epoch_vault_iteration(&mut self, epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
408 self.instruction.epoch_vault_iteration = Some(epoch_vault_iteration);
409 self
410 }
411 #[inline(always)]
412 pub fn next_epoch_vault_iteration(&mut self, next_epoch_vault_iteration: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
413 self.instruction.next_epoch_vault_iteration = Some(next_epoch_vault_iteration);
414 self
415 }
416 #[inline(always)]
418 pub fn slot_hashes(&mut self, slot_hashes: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
419 self.instruction.slot_hashes = Some(slot_hashes);
420 self
421 }
422 #[inline(always)]
423 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
424 self.instruction.system_program = Some(system_program);
425 self
426 }
427 #[inline(always)]
429 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
430 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
431 self
432 }
433 #[inline(always)]
438 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
439 self.instruction.__remaining_accounts.extend_from_slice(accounts);
440 self
441 }
442 #[inline(always)]
443 pub fn invoke(&self) -> solana_program_error::ProgramResult {
444 self.invoke_signed(&[])
445 }
446 #[allow(clippy::clone_on_copy)]
447 #[allow(clippy::vec_init_then_push)]
448 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
449 let instruction = TriggerEpochDrawCpi {
450 __program: self.instruction.__program,
451
452 authority: self.instruction.authority.expect("authority is not set"),
453
454 satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
455
456 epoch_vault: self.instruction.epoch_vault.expect("epoch_vault is not set"),
457
458 epoch_vault_iteration: self.instruction.epoch_vault_iteration.expect("epoch_vault_iteration is not set"),
459
460 next_epoch_vault_iteration: self.instruction.next_epoch_vault_iteration.expect("next_epoch_vault_iteration is not set"),
461
462 slot_hashes: self.instruction.slot_hashes.expect("slot_hashes is not set"),
463
464 system_program: self.instruction.system_program.expect("system_program is not set"),
465 };
466 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
467 }
468}
469
470#[derive(Clone, Debug)]
471struct TriggerEpochDrawCpiBuilderInstruction<'a, 'b> {
472 __program: &'b solana_account_info::AccountInfo<'a>,
473 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
474 satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
475 epoch_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
476 epoch_vault_iteration: Option<&'b solana_account_info::AccountInfo<'a>>,
477 next_epoch_vault_iteration: Option<&'b solana_account_info::AccountInfo<'a>>,
478 slot_hashes: Option<&'b solana_account_info::AccountInfo<'a>>,
479 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
480 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
482}
483