1use borsh::BorshSerialize;
9use borsh::BorshDeserialize;
10
11pub const CREATE_BOARD_DISCRIMINATOR: [u8; 8] = [81, 129, 130, 38, 99, 204, 224, 177];
12
13#[derive(Debug)]
15pub struct CreateBoard {
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 initial_round: solana_address::Address,
31
32
33 pub usd_mint: solana_address::Address,
34
35
36 pub btc_mint: solana_address::Address,
37 pub board_usd_ata: solana_address::Address,
42 pub board_btc_ata: solana_address::Address,
47
48
49 pub token_program: solana_address::Address,
50
51
52 pub associated_token_program: solana_address::Address,
53
54
55 pub system_program: solana_address::Address,
56 }
57
58impl CreateBoard {
59 pub fn instruction(&self) -> solana_instruction::Instruction {
60 self.instruction_with_remaining_accounts(&[])
61 }
62 #[allow(clippy::arithmetic_side_effects)]
63 #[allow(clippy::vec_init_then_push)]
64 pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
65 let mut accounts = Vec::with_capacity(11+ remaining_accounts.len());
66 accounts.push(solana_instruction::AccountMeta::new(
67 self.authority,
68 true
69 ));
70 accounts.push(solana_instruction::AccountMeta::new_readonly(
71 self.satrush_config,
72 false
73 ));
74 accounts.push(solana_instruction::AccountMeta::new(
75 self.board,
76 false
77 ));
78 accounts.push(solana_instruction::AccountMeta::new(
79 self.initial_round,
80 false
81 ));
82 accounts.push(solana_instruction::AccountMeta::new_readonly(
83 self.usd_mint,
84 false
85 ));
86 accounts.push(solana_instruction::AccountMeta::new_readonly(
87 self.btc_mint,
88 false
89 ));
90 accounts.push(solana_instruction::AccountMeta::new(
91 self.board_usd_ata,
92 false
93 ));
94 accounts.push(solana_instruction::AccountMeta::new(
95 self.board_btc_ata,
96 false
97 ));
98 accounts.push(solana_instruction::AccountMeta::new_readonly(
99 self.token_program,
100 false
101 ));
102 accounts.push(solana_instruction::AccountMeta::new_readonly(
103 self.associated_token_program,
104 false
105 ));
106 accounts.push(solana_instruction::AccountMeta::new_readonly(
107 self.system_program,
108 false
109 ));
110 accounts.extend_from_slice(remaining_accounts);
111 let data = CreateBoardInstructionData::new().try_to_vec().unwrap();
112
113 solana_instruction::Instruction {
114 program_id: crate::SATRUSH_ID,
115 accounts,
116 data,
117 }
118 }
119}
120
121#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
122 pub struct CreateBoardInstructionData {
123 discriminator: [u8; 8],
124 }
125
126impl CreateBoardInstructionData {
127 pub fn new() -> Self {
128 Self {
129 discriminator: [81, 129, 130, 38, 99, 204, 224, 177],
130 }
131 }
132
133 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
134 borsh::to_vec(self)
135 }
136 }
137
138impl Default for CreateBoardInstructionData {
139 fn default() -> Self {
140 Self::new()
141 }
142}
143
144
145
146#[derive(Clone, Debug, Default)]
162pub struct CreateBoardBuilder {
163 authority: Option<solana_address::Address>,
164 satrush_config: Option<solana_address::Address>,
165 board: Option<solana_address::Address>,
166 initial_round: Option<solana_address::Address>,
167 usd_mint: Option<solana_address::Address>,
168 btc_mint: Option<solana_address::Address>,
169 board_usd_ata: Option<solana_address::Address>,
170 board_btc_ata: Option<solana_address::Address>,
171 token_program: Option<solana_address::Address>,
172 associated_token_program: Option<solana_address::Address>,
173 system_program: Option<solana_address::Address>,
174 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
175}
176
177impl CreateBoardBuilder {
178 pub fn new() -> Self {
179 Self::default()
180 }
181 #[inline(always)]
182 pub fn authority(&mut self, authority: solana_address::Address) -> &mut Self {
183 self.authority = Some(authority);
184 self
185 }
186 #[inline(always)]
187 pub fn satrush_config(&mut self, satrush_config: solana_address::Address) -> &mut Self {
188 self.satrush_config = Some(satrush_config);
189 self
190 }
191 #[inline(always)]
192 pub fn board(&mut self, board: solana_address::Address) -> &mut Self {
193 self.board = Some(board);
194 self
195 }
196 #[inline(always)]
199 pub fn initial_round(&mut self, initial_round: solana_address::Address) -> &mut Self {
200 self.initial_round = Some(initial_round);
201 self
202 }
203 #[inline(always)]
204 pub fn usd_mint(&mut self, usd_mint: solana_address::Address) -> &mut Self {
205 self.usd_mint = Some(usd_mint);
206 self
207 }
208 #[inline(always)]
209 pub fn btc_mint(&mut self, btc_mint: solana_address::Address) -> &mut Self {
210 self.btc_mint = Some(btc_mint);
211 self
212 }
213 #[inline(always)]
215 pub fn board_usd_ata(&mut self, board_usd_ata: solana_address::Address) -> &mut Self {
216 self.board_usd_ata = Some(board_usd_ata);
217 self
218 }
219 #[inline(always)]
221 pub fn board_btc_ata(&mut self, board_btc_ata: solana_address::Address) -> &mut Self {
222 self.board_btc_ata = Some(board_btc_ata);
223 self
224 }
225 #[inline(always)]
227 pub fn token_program(&mut self, token_program: solana_address::Address) -> &mut Self {
228 self.token_program = Some(token_program);
229 self
230 }
231 #[inline(always)]
233 pub fn associated_token_program(&mut self, associated_token_program: solana_address::Address) -> &mut Self {
234 self.associated_token_program = Some(associated_token_program);
235 self
236 }
237 #[inline(always)]
239 pub fn system_program(&mut self, system_program: solana_address::Address) -> &mut Self {
240 self.system_program = Some(system_program);
241 self
242 }
243 #[inline(always)]
245 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
246 self.__remaining_accounts.push(account);
247 self
248 }
249 #[inline(always)]
251 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
252 self.__remaining_accounts.extend_from_slice(accounts);
253 self
254 }
255 #[allow(clippy::clone_on_copy)]
256 pub fn instruction(&self) -> solana_instruction::Instruction {
257 let accounts = CreateBoard {
258 authority: self.authority.expect("authority is not set"),
259 satrush_config: self.satrush_config.expect("satrush_config is not set"),
260 board: self.board.expect("board is not set"),
261 initial_round: self.initial_round.expect("initial_round is not set"),
262 usd_mint: self.usd_mint.expect("usd_mint is not set"),
263 btc_mint: self.btc_mint.expect("btc_mint is not set"),
264 board_usd_ata: self.board_usd_ata.expect("board_usd_ata is not set"),
265 board_btc_ata: self.board_btc_ata.expect("board_btc_ata is not set"),
266 token_program: self.token_program.unwrap_or(solana_address::address!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
267 associated_token_program: self.associated_token_program.unwrap_or(solana_address::address!("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL")),
268 system_program: self.system_program.unwrap_or(solana_address::address!("11111111111111111111111111111111")),
269 };
270
271 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
272 }
273}
274
275 pub struct CreateBoardCpiAccounts<'a, 'b> {
277
278
279 pub authority: &'b solana_account_info::AccountInfo<'a>,
280
281
282 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
283
284
285 pub board: &'b solana_account_info::AccountInfo<'a>,
286 pub initial_round: &'b solana_account_info::AccountInfo<'a>,
292
293
294 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
295
296
297 pub btc_mint: &'b solana_account_info::AccountInfo<'a>,
298 pub board_usd_ata: &'b solana_account_info::AccountInfo<'a>,
303 pub board_btc_ata: &'b solana_account_info::AccountInfo<'a>,
308
309
310 pub token_program: &'b solana_account_info::AccountInfo<'a>,
311
312
313 pub associated_token_program: &'b solana_account_info::AccountInfo<'a>,
314
315
316 pub system_program: &'b solana_account_info::AccountInfo<'a>,
317 }
318
319pub struct CreateBoardCpi<'a, 'b> {
321 pub __program: &'b solana_account_info::AccountInfo<'a>,
323
324
325 pub authority: &'b solana_account_info::AccountInfo<'a>,
326
327
328 pub satrush_config: &'b solana_account_info::AccountInfo<'a>,
329
330
331 pub board: &'b solana_account_info::AccountInfo<'a>,
332 pub initial_round: &'b solana_account_info::AccountInfo<'a>,
338
339
340 pub usd_mint: &'b solana_account_info::AccountInfo<'a>,
341
342
343 pub btc_mint: &'b solana_account_info::AccountInfo<'a>,
344 pub board_usd_ata: &'b solana_account_info::AccountInfo<'a>,
349 pub board_btc_ata: &'b solana_account_info::AccountInfo<'a>,
354
355
356 pub token_program: &'b solana_account_info::AccountInfo<'a>,
357
358
359 pub associated_token_program: &'b solana_account_info::AccountInfo<'a>,
360
361
362 pub system_program: &'b solana_account_info::AccountInfo<'a>,
363 }
364
365impl<'a, 'b> CreateBoardCpi<'a, 'b> {
366 pub fn new(
367 program: &'b solana_account_info::AccountInfo<'a>,
368 accounts: CreateBoardCpiAccounts<'a, 'b>,
369 ) -> Self {
370 Self {
371 __program: program,
372 authority: accounts.authority,
373 satrush_config: accounts.satrush_config,
374 board: accounts.board,
375 initial_round: accounts.initial_round,
376 usd_mint: accounts.usd_mint,
377 btc_mint: accounts.btc_mint,
378 board_usd_ata: accounts.board_usd_ata,
379 board_btc_ata: accounts.board_btc_ata,
380 token_program: accounts.token_program,
381 associated_token_program: accounts.associated_token_program,
382 system_program: accounts.system_program,
383 }
384 }
385 #[inline(always)]
386 pub fn invoke(&self) -> solana_program_error::ProgramResult {
387 self.invoke_signed_with_remaining_accounts(&[], &[])
388 }
389 #[inline(always)]
390 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
391 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
392 }
393 #[inline(always)]
394 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
395 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
396 }
397 #[allow(clippy::arithmetic_side_effects)]
398 #[allow(clippy::clone_on_copy)]
399 #[allow(clippy::vec_init_then_push)]
400 pub fn invoke_signed_with_remaining_accounts(
401 &self,
402 signers_seeds: &[&[&[u8]]],
403 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
404 ) -> solana_program_error::ProgramResult {
405 let mut accounts = Vec::with_capacity(11+ remaining_accounts.len());
406 accounts.push(solana_instruction::AccountMeta::new(
407 *self.authority.key,
408 true
409 ));
410 accounts.push(solana_instruction::AccountMeta::new_readonly(
411 *self.satrush_config.key,
412 false
413 ));
414 accounts.push(solana_instruction::AccountMeta::new(
415 *self.board.key,
416 false
417 ));
418 accounts.push(solana_instruction::AccountMeta::new(
419 *self.initial_round.key,
420 false
421 ));
422 accounts.push(solana_instruction::AccountMeta::new_readonly(
423 *self.usd_mint.key,
424 false
425 ));
426 accounts.push(solana_instruction::AccountMeta::new_readonly(
427 *self.btc_mint.key,
428 false
429 ));
430 accounts.push(solana_instruction::AccountMeta::new(
431 *self.board_usd_ata.key,
432 false
433 ));
434 accounts.push(solana_instruction::AccountMeta::new(
435 *self.board_btc_ata.key,
436 false
437 ));
438 accounts.push(solana_instruction::AccountMeta::new_readonly(
439 *self.token_program.key,
440 false
441 ));
442 accounts.push(solana_instruction::AccountMeta::new_readonly(
443 *self.associated_token_program.key,
444 false
445 ));
446 accounts.push(solana_instruction::AccountMeta::new_readonly(
447 *self.system_program.key,
448 false
449 ));
450 remaining_accounts.iter().for_each(|remaining_account| {
451 accounts.push(solana_instruction::AccountMeta {
452 pubkey: *remaining_account.0.key,
453 is_signer: remaining_account.1,
454 is_writable: remaining_account.2,
455 })
456 });
457 let data = CreateBoardInstructionData::new().try_to_vec().unwrap();
458
459 let instruction = solana_instruction::Instruction {
460 program_id: crate::SATRUSH_ID,
461 accounts,
462 data,
463 };
464 let mut account_infos = Vec::with_capacity(12 + remaining_accounts.len());
465 account_infos.push(self.__program.clone());
466 account_infos.push(self.authority.clone());
467 account_infos.push(self.satrush_config.clone());
468 account_infos.push(self.board.clone());
469 account_infos.push(self.initial_round.clone());
470 account_infos.push(self.usd_mint.clone());
471 account_infos.push(self.btc_mint.clone());
472 account_infos.push(self.board_usd_ata.clone());
473 account_infos.push(self.board_btc_ata.clone());
474 account_infos.push(self.token_program.clone());
475 account_infos.push(self.associated_token_program.clone());
476 account_infos.push(self.system_program.clone());
477 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
478
479 if signers_seeds.is_empty() {
480 solana_cpi::invoke(&instruction, &account_infos)
481 } else {
482 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
483 }
484 }
485}
486
487#[derive(Clone, Debug)]
503pub struct CreateBoardCpiBuilder<'a, 'b> {
504 instruction: Box<CreateBoardCpiBuilderInstruction<'a, 'b>>,
505}
506
507impl<'a, 'b> CreateBoardCpiBuilder<'a, 'b> {
508 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
509 let instruction = Box::new(CreateBoardCpiBuilderInstruction {
510 __program: program,
511 authority: None,
512 satrush_config: None,
513 board: None,
514 initial_round: None,
515 usd_mint: None,
516 btc_mint: None,
517 board_usd_ata: None,
518 board_btc_ata: None,
519 token_program: None,
520 associated_token_program: None,
521 system_program: None,
522 __remaining_accounts: Vec::new(),
523 });
524 Self { instruction }
525 }
526 #[inline(always)]
527 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
528 self.instruction.authority = Some(authority);
529 self
530 }
531 #[inline(always)]
532 pub fn satrush_config(&mut self, satrush_config: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
533 self.instruction.satrush_config = Some(satrush_config);
534 self
535 }
536 #[inline(always)]
537 pub fn board(&mut self, board: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
538 self.instruction.board = Some(board);
539 self
540 }
541 #[inline(always)]
544 pub fn initial_round(&mut self, initial_round: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
545 self.instruction.initial_round = Some(initial_round);
546 self
547 }
548 #[inline(always)]
549 pub fn usd_mint(&mut self, usd_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
550 self.instruction.usd_mint = Some(usd_mint);
551 self
552 }
553 #[inline(always)]
554 pub fn btc_mint(&mut self, btc_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
555 self.instruction.btc_mint = Some(btc_mint);
556 self
557 }
558 #[inline(always)]
560 pub fn board_usd_ata(&mut self, board_usd_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
561 self.instruction.board_usd_ata = Some(board_usd_ata);
562 self
563 }
564 #[inline(always)]
566 pub fn board_btc_ata(&mut self, board_btc_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
567 self.instruction.board_btc_ata = Some(board_btc_ata);
568 self
569 }
570 #[inline(always)]
571 pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
572 self.instruction.token_program = Some(token_program);
573 self
574 }
575 #[inline(always)]
576 pub fn associated_token_program(&mut self, associated_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
577 self.instruction.associated_token_program = Some(associated_token_program);
578 self
579 }
580 #[inline(always)]
581 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
582 self.instruction.system_program = Some(system_program);
583 self
584 }
585 #[inline(always)]
587 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
588 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
589 self
590 }
591 #[inline(always)]
596 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
597 self.instruction.__remaining_accounts.extend_from_slice(accounts);
598 self
599 }
600 #[inline(always)]
601 pub fn invoke(&self) -> solana_program_error::ProgramResult {
602 self.invoke_signed(&[])
603 }
604 #[allow(clippy::clone_on_copy)]
605 #[allow(clippy::vec_init_then_push)]
606 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
607 let instruction = CreateBoardCpi {
608 __program: self.instruction.__program,
609
610 authority: self.instruction.authority.expect("authority is not set"),
611
612 satrush_config: self.instruction.satrush_config.expect("satrush_config is not set"),
613
614 board: self.instruction.board.expect("board is not set"),
615
616 initial_round: self.instruction.initial_round.expect("initial_round is not set"),
617
618 usd_mint: self.instruction.usd_mint.expect("usd_mint is not set"),
619
620 btc_mint: self.instruction.btc_mint.expect("btc_mint is not set"),
621
622 board_usd_ata: self.instruction.board_usd_ata.expect("board_usd_ata is not set"),
623
624 board_btc_ata: self.instruction.board_btc_ata.expect("board_btc_ata is not set"),
625
626 token_program: self.instruction.token_program.expect("token_program is not set"),
627
628 associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"),
629
630 system_program: self.instruction.system_program.expect("system_program is not set"),
631 };
632 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
633 }
634}
635
636#[derive(Clone, Debug)]
637struct CreateBoardCpiBuilderInstruction<'a, 'b> {
638 __program: &'b solana_account_info::AccountInfo<'a>,
639 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
640 satrush_config: Option<&'b solana_account_info::AccountInfo<'a>>,
641 board: Option<&'b solana_account_info::AccountInfo<'a>>,
642 initial_round: Option<&'b solana_account_info::AccountInfo<'a>>,
643 usd_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
644 btc_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
645 board_usd_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
646 board_btc_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
647 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
648 associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
649 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
650 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
652}
653