1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const ROTATE_ROUND_DISCRIMINATOR: [u8; 8] = [3, 245, 202, 88, 161, 29, 51, 141];
12
13#[derive(Debug)]
15pub struct RotateRound {
16
17
18 pub authority: solana_address::Address,
19
20
21 pub satrush_config: solana_address::Address,
22
23
24 pub board: solana_address::Address,
25 pub current_round: solana_address::Address,
30 pub next_round: solana_address::Address,
37 pub slot_hashes: solana_address::Address,
42
43
44 pub system_program: solana_address::Address,
45
46
47 pub event_authority: solana_address::Address,
48
49
50 pub program: solana_address::Address,
51 }
52
53impl RotateRound {
54 pub fn instruction(&self) -> solana_instruction::Instruction {
55 self.instruction_with_remaining_accounts(&[])
56 }
57 #[allow(clippy::arithmetic_side_effects)]
58 #[allow(clippy::vec_init_then_push)]
59 pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
60 let mut accounts = Vec::with_capacity(9+ remaining_accounts.len());
61 accounts.push(solana_instruction::AccountMeta::new(
62 self.authority,
63 true
64 ));
65 accounts.push(solana_instruction::AccountMeta::new_readonly(
66 self.satrush_config,
67 false
68 ));
69 accounts.push(solana_instruction::AccountMeta::new(
70 self.board,
71 false
72 ));
73 accounts.push(solana_instruction::AccountMeta::new(
74 self.current_round,
75 false
76 ));
77 accounts.push(solana_instruction::AccountMeta::new(
78 self.next_round,
79 false
80 ));
81 accounts.push(solana_instruction::AccountMeta::new_readonly(
82 self.slot_hashes,
83 false
84 ));
85 accounts.push(solana_instruction::AccountMeta::new_readonly(
86 self.system_program,
87 false
88 ));
89 accounts.push(solana_instruction::AccountMeta::new_readonly(
90 self.event_authority,
91 false
92 ));
93 accounts.push(solana_instruction::AccountMeta::new_readonly(
94 self.program,
95 false
96 ));
97 accounts.extend_from_slice(remaining_accounts);
98 let data = RotateRoundInstructionData::new().try_to_vec().unwrap();
99
100 solana_instruction::Instruction {
101 program_id: crate::SATRUSH_ID,
102 accounts,
103 data,
104 }
105 }
106}
107
108#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
109 pub struct RotateRoundInstructionData {
110 discriminator: [u8; 8],
111 }
112
113impl RotateRoundInstructionData {
114 pub fn new() -> Self {
115 Self {
116 discriminator: [3, 245, 202, 88, 161, 29, 51, 141],
117 }
118 }
119
120 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
121 borsh::to_vec(self)
122 }
123 }
124
125impl Default for RotateRoundInstructionData {
126 fn default() -> Self {
127 Self::new()
128 }
129}
130
131
132
133#[derive(Clone, Debug, Default)]
147pub struct RotateRoundBuilder {
148 authority: Option<solana_address::Address>,
149 satrush_config: Option<solana_address::Address>,
150 board: Option<solana_address::Address>,
151 current_round: Option<solana_address::Address>,
152 next_round: Option<solana_address::Address>,
153 slot_hashes: Option<solana_address::Address>,
154 system_program: Option<solana_address::Address>,
155 event_authority: Option<solana_address::Address>,
156 program: Option<solana_address::Address>,
157 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
158}
159
160impl RotateRoundBuilder {
161 pub fn new() -> Self {
162 Self::default()
163 }
164 #[inline(always)]
165 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
166 self.authority = Some(authority);
167 self
168 }
169 #[inline(always)]
170 pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
171 self.satrush_config = Some(satrush_config);
172 self
173 }
174 #[inline(always)]
175 pub fn board(&mut self, board: solana_address::Address) -> &mut Self {
176 self.board = Some(board);
177 self
178 }
179 #[inline(always)]
181 pub fn current_round(&mut self, current_round: solana_address::Address) -> &mut Self {
182 self.current_round = Some(current_round);
183 self
184 }
185 #[inline(always)]
189 pub fn next_round(&mut self, next_round: solana_address::Address) -> &mut Self {
190 self.next_round = Some(next_round);
191 self
192 }
193 #[inline(always)]
196 pub fn slot_hashes(&mut self, slot_hashes: solana_address::Address) -> &mut Self {
197 self.slot_hashes = Some(slot_hashes);
198 self
199 }
200 #[inline(always)]
202 pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
203 self.system_program = Some(system_program);
204 self
205 }
206 #[inline(always)]
207 pub fn event_authority(&mut self, event_authority: solana_address::Address) -> &mut Self {
208 self.event_authority = Some(event_authority);
209 self
210 }
211 #[inline(always)]
212 pub fn program(&mut self, program: solana_address::Address) -> &mut Self {
213 self.program = Some(program);
214 self
215 }
216 #[inline(always)]
218 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
219 self.__remaining_accounts.push(account);
220 self
221 }
222 #[inline(always)]
224 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
225 self.__remaining_accounts.extend_from_slice(accounts);
226 self
227 }
228 #[allow(clippy::clone_on_copy)]
229 pub fn instruction(&self) -> solana_instruction::Instruction {
230 let accounts = RotateRound {
231 authority: self.authority.expect("authority is not set"),
232 satrush_config: self.satrush_config.expect("satrush_config is not set"),
233 board: self.board.expect("board is not set"),
234 current_round: self.current_round.expect("current_round is not set"),
235 next_round: self.next_round.expect("next_round is not set"),
236 slot_hashes: self.slot_hashes.unwrap_or(solana_address::address!("SysvarS1otHashes111111111111111111111111111")),
237 system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
238 event_authority: self.event_authority.expect("event_authority is not set"),
239 program: self.program.expect("program is not set"),
240 };
241
242 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
243 }
244}
245
246 pub struct RotateRoundCpiAccounts<'a, 'b> {
248
249
250 pub authority: &'b solana_account_info::AccountInfo<'a>,
251
252
253 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
254
255
256 pub board: &'b solana_account_info::AccountInfo<'a>,
257 pub current_round: &'b solana_account_info::AccountInfo<'a>,
262 pub next_round: &'b solana_account_info::AccountInfo<'a>,
269 pub slot_hashes: &'b solana_account_info::AccountInfo<'a>,
274
275
276 pub system_program: &'b solana_account_info::AccountInfo<'a>,
277
278
279 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
280
281
282 pub program: &'b solana_account_info::AccountInfo<'a>,
283 }
284
285pub struct RotateRoundCpi<'a, 'b> {
287 pub __program: &'b solana_account_info::AccountInfo<'a>,
289
290
291 pub authority: &'b solana_account_info::AccountInfo<'a>,
292
293
294 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
295
296
297 pub board: &'b solana_account_info::AccountInfo<'a>,
298 pub current_round: &'b solana_account_info::AccountInfo<'a>,
303 pub next_round: &'b solana_account_info::AccountInfo<'a>,
310 pub slot_hashes: &'b solana_account_info::AccountInfo<'a>,
315
316
317 pub system_program: &'b solana_account_info::AccountInfo<'a>,
318
319
320 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
321
322
323 pub program: &'b solana_account_info::AccountInfo<'a>,
324 }
325
326impl<'a, 'b> RotateRoundCpi<'a, 'b> {
327 pub fn new(
328 program: &'b solana_account_info::AccountInfo<'a>,
329 accounts: RotateRoundCpiAccounts<'a, 'b>,
330 ) -> Self {
331 Self {
332 __program: program,
333 authority: accounts.authority,
334 satrush_config: accounts.satrush_config,
335 board: accounts.board,
336 current_round: accounts.current_round,
337 next_round: accounts.next_round,
338 slot_hashes: accounts.slot_hashes,
339 system_program: accounts.system_program,
340 event_authority: accounts.event_authority,
341 program: accounts.program,
342 }
343 }
344 #[inline(always)]
345 pub fn invoke(&self) -> solana_program_error::ProgramResult {
346 self.invoke_signed_with_remaining_accounts(&[], &[])
347 }
348 #[inline(always)]
349 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
350 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
351 }
352 #[inline(always)]
353 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
354 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
355 }
356 #[allow(clippy::arithmetic_side_effects)]
357 #[allow(clippy::clone_on_copy)]
358 #[allow(clippy::vec_init_then_push)]
359 pub fn invoke_signed_with_remaining_accounts(
360 &self,
361 signers_seeds: &[&[&[u8]]],
362 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
363 ) -> solana_program_error::ProgramResult {
364 let mut accounts = Vec::with_capacity(9+ remaining_accounts.len());
365 accounts.push(solana_instruction::AccountMeta::new(
366 *self.authority.key,
367 true
368 ));
369 accounts.push(solana_instruction::AccountMeta::new_readonly(
370 *self.satrush_config.key,
371 false
372 ));
373 accounts.push(solana_instruction::AccountMeta::new(
374 *self.board.key,
375 false
376 ));
377 accounts.push(solana_instruction::AccountMeta::new(
378 *self.current_round.key,
379 false
380 ));
381 accounts.push(solana_instruction::AccountMeta::new(
382 *self.next_round.key,
383 false
384 ));
385 accounts.push(solana_instruction::AccountMeta::new_readonly(
386 *self.slot_hashes.key,
387 false
388 ));
389 accounts.push(solana_instruction::AccountMeta::new_readonly(
390 *self.system_program.key,
391 false
392 ));
393 accounts.push(solana_instruction::AccountMeta::new_readonly(
394 *self.event_authority.key,
395 false
396 ));
397 accounts.push(solana_instruction::AccountMeta::new_readonly(
398 *self.program.key,
399 false
400 ));
401 remaining_accounts.iter().for_each(|remaining_account| {
402 accounts.push(solana_instruction::AccountMeta {
403 pubkey: *remaining_account.0.key,
404 is_signer: remaining_account.1,
405 is_writable: remaining_account.2,
406 })
407 });
408 let data = RotateRoundInstructionData::new().try_to_vec().unwrap();
409
410 let instruction = solana_instruction::Instruction {
411 program_id: crate::SATRUSH_ID,
412 accounts,
413 data,
414 };
415 let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len());
416 account_infos.push(self.__program.clone());
417 account_infos.push(self.authority.clone());
418 account_infos.push(self.satrush_config.clone());
419 account_infos.push(self.board.clone());
420 account_infos.push(self.current_round.clone());
421 account_infos.push(self.next_round.clone());
422 account_infos.push(self.slot_hashes.clone());
423 account_infos.push(self.system_program.clone());
424 account_infos.push(self.event_authority.clone());
425 account_infos.push(self.program.clone());
426 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
427
428 if signers_seeds.is_empty() {
429 solana_cpi::invoke(&instruction, &account_infos)
430 } else {
431 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
432 }
433 }
434}
435
436#[derive(Clone, Debug)]
450pub struct RotateRoundCpiBuilder<'a, 'b> {
451 instruction: Box<RotateRoundCpiBuilderInstruction<'a, 'b>>,
452}
453
454impl<'a, 'b> RotateRoundCpiBuilder<'a, 'b> {
455 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
456 let instruction = Box::new(RotateRoundCpiBuilderInstruction {
457 __program: program,
458 authority: None,
459 satrush_config: None,
460 board: None,
461 current_round: None,
462 next_round: None,
463 slot_hashes: None,
464 system_program: None,
465 event_authority: None,
466 program: None,
467 __remaining_accounts: Vec::new(),
468 });
469 Self { instruction }
470 }
471 #[inline(always)]
472 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
473 self.instruction.authority = Some(authority);
474 self
475 }
476 #[inline(always)]
477 pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
478 self.instruction.satrush_config = Some(satrush_config);
479 self
480 }
481 #[inline(always)]
482 pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
483 self.instruction.board = Some(board);
484 self
485 }
486 #[inline(always)]
488 pub fn current_round(&mut self, current_round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
489 self.instruction.current_round = Some(current_round);
490 self
491 }
492 #[inline(always)]
496 pub fn next_round(&mut self, next_round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
497 self.instruction.next_round = Some(next_round);
498 self
499 }
500 #[inline(always)]
502 pub fn slot_hashes(&mut self, slot_hashes: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
503 self.instruction.slot_hashes = Some(slot_hashes);
504 self
505 }
506 #[inline(always)]
507 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
508 self.instruction.system_program = Some(system_program);
509 self
510 }
511 #[inline(always)]
512 pub fn event_authority(&mut self, event_authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
513 self.instruction.event_authority = Some(event_authority);
514 self
515 }
516 #[inline(always)]
517 pub fn program(&mut self, program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
518 self.instruction.program = Some(program);
519 self
520 }
521 #[inline(always)]
523 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
524 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
525 self
526 }
527 #[inline(always)]
532 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
533 self.instruction.__remaining_accounts.extend_from_slice(accounts);
534 self
535 }
536 #[inline(always)]
537 pub fn invoke(&self) -> solana_program_error::ProgramResult {
538 self.invoke_signed(&[])
539 }
540 #[allow(clippy::clone_on_copy)]
541 #[allow(clippy::vec_init_then_push)]
542 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
543 let instruction = RotateRoundCpi {
544 __program: self.instruction.__program,
545
546 authority: self.instruction.authority.expect("authority is not set"),
547
548 satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
549
550 board: self.instruction.board.expect("board is not set"),
551
552 current_round: self.instruction.current_round.expect("current_round is not set"),
553
554 next_round: self.instruction.next_round.expect("next_round is not set"),
555
556 slot_hashes: self.instruction.slot_hashes.expect("slot_hashes is not set"),
557
558 system_program: self.instruction.system_program.expect("system_program is not set"),
559
560 event_authority: self.instruction.event_authority.expect("event_authority is not set"),
561
562 program: self.instruction.program.expect("program is not set"),
563 };
564 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
565 }
566}
567
568#[derive(Clone, Debug)]
569struct RotateRoundCpiBuilderInstruction<'a, 'b> {
570 __program: &'b solana_account_info::AccountInfo<'a>,
571 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
572 satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
573 board: Option<&'b solana_account_info::AccountInfo<'a>>,
574 current_round: Option<&'b solana_account_info::AccountInfo<'a>>,
575 next_round: Option<&'b solana_account_info::AccountInfo<'a>>,
576 slot_hashes: Option<&'b solana_account_info::AccountInfo<'a>>,
577 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
578 event_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
579 program: Option<&'b solana_account_info::AccountInfo<'a>>,
580 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
582}
583