1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct Bridge {
13 pub asset: solana_program::pubkey::Pubkey,
15 pub vault: solana_program::pubkey::Pubkey,
17 pub owner: solana_program::pubkey::Pubkey,
19 pub token: solana_program::pubkey::Pubkey,
21 pub mint: solana_program::pubkey::Pubkey,
23 pub metadata: solana_program::pubkey::Pubkey,
25 pub master_edition: solana_program::pubkey::Pubkey,
27 pub token_record: Option<solana_program::pubkey::Pubkey>,
29 pub vault_token: solana_program::pubkey::Pubkey,
31 pub vault_token_record: Option<solana_program::pubkey::Pubkey>,
33 pub payer: solana_program::pubkey::Pubkey,
35 pub nifty_asset_program: solana_program::pubkey::Pubkey,
37 pub token_metadata_program: solana_program::pubkey::Pubkey,
39 pub system_program: solana_program::pubkey::Pubkey,
41 pub sysvar_instructions: solana_program::pubkey::Pubkey,
43 pub spl_token_program: solana_program::pubkey::Pubkey,
45 pub spl_ata_program: solana_program::pubkey::Pubkey,
47 pub authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
49 pub authorization_rules: Option<solana_program::pubkey::Pubkey>,
51}
52
53impl Bridge {
54 pub fn instruction(&self) -> solana_program::instruction::Instruction {
55 self.instruction_with_remaining_accounts(&[])
56 }
57 #[allow(clippy::vec_init_then_push)]
58 pub fn instruction_with_remaining_accounts(
59 &self,
60 remaining_accounts: &[solana_program::instruction::AccountMeta],
61 ) -> solana_program::instruction::Instruction {
62 let mut accounts = Vec::with_capacity(19 + remaining_accounts.len());
63 accounts.push(solana_program::instruction::AccountMeta::new(
64 self.asset, false,
65 ));
66 accounts.push(solana_program::instruction::AccountMeta::new(
67 self.vault, false,
68 ));
69 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
70 self.owner, true,
71 ));
72 accounts.push(solana_program::instruction::AccountMeta::new(
73 self.token, false,
74 ));
75 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
76 self.mint, false,
77 ));
78 accounts.push(solana_program::instruction::AccountMeta::new(
79 self.metadata,
80 false,
81 ));
82 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
83 self.master_edition,
84 false,
85 ));
86 if let Some(token_record) = self.token_record {
87 accounts.push(solana_program::instruction::AccountMeta::new(
88 token_record,
89 false,
90 ));
91 } else {
92 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
93 crate::BRIDGE_ID,
94 false,
95 ));
96 }
97 accounts.push(solana_program::instruction::AccountMeta::new(
98 self.vault_token,
99 false,
100 ));
101 if let Some(vault_token_record) = self.vault_token_record {
102 accounts.push(solana_program::instruction::AccountMeta::new(
103 vault_token_record,
104 false,
105 ));
106 } else {
107 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
108 crate::BRIDGE_ID,
109 false,
110 ));
111 }
112 accounts.push(solana_program::instruction::AccountMeta::new(
113 self.payer, true,
114 ));
115 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
116 self.nifty_asset_program,
117 false,
118 ));
119 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
120 self.token_metadata_program,
121 false,
122 ));
123 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
124 self.system_program,
125 false,
126 ));
127 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
128 self.sysvar_instructions,
129 false,
130 ));
131 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
132 self.spl_token_program,
133 false,
134 ));
135 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
136 self.spl_ata_program,
137 false,
138 ));
139 if let Some(authorization_rules_program) = self.authorization_rules_program {
140 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
141 authorization_rules_program,
142 false,
143 ));
144 } else {
145 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
146 crate::BRIDGE_ID,
147 false,
148 ));
149 }
150 if let Some(authorization_rules) = self.authorization_rules {
151 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
152 authorization_rules,
153 false,
154 ));
155 } else {
156 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
157 crate::BRIDGE_ID,
158 false,
159 ));
160 }
161 accounts.extend_from_slice(remaining_accounts);
162 let data = BridgeInstructionData::new().try_to_vec().unwrap();
163
164 solana_program::instruction::Instruction {
165 program_id: crate::BRIDGE_ID,
166 accounts,
167 data,
168 }
169 }
170}
171
172#[derive(BorshDeserialize, BorshSerialize)]
173struct BridgeInstructionData {
174 discriminator: u8,
175}
176
177impl BridgeInstructionData {
178 fn new() -> Self {
179 Self { discriminator: 0 }
180 }
181}
182
183#[derive(Default)]
207pub struct BridgeBuilder {
208 asset: Option<solana_program::pubkey::Pubkey>,
209 vault: Option<solana_program::pubkey::Pubkey>,
210 owner: Option<solana_program::pubkey::Pubkey>,
211 token: Option<solana_program::pubkey::Pubkey>,
212 mint: Option<solana_program::pubkey::Pubkey>,
213 metadata: Option<solana_program::pubkey::Pubkey>,
214 master_edition: Option<solana_program::pubkey::Pubkey>,
215 token_record: Option<solana_program::pubkey::Pubkey>,
216 vault_token: Option<solana_program::pubkey::Pubkey>,
217 vault_token_record: Option<solana_program::pubkey::Pubkey>,
218 payer: Option<solana_program::pubkey::Pubkey>,
219 nifty_asset_program: Option<solana_program::pubkey::Pubkey>,
220 token_metadata_program: Option<solana_program::pubkey::Pubkey>,
221 system_program: Option<solana_program::pubkey::Pubkey>,
222 sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
223 spl_token_program: Option<solana_program::pubkey::Pubkey>,
224 spl_ata_program: Option<solana_program::pubkey::Pubkey>,
225 authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
226 authorization_rules: Option<solana_program::pubkey::Pubkey>,
227 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
228}
229
230impl BridgeBuilder {
231 pub fn new() -> Self {
232 Self::default()
233 }
234 #[inline(always)]
236 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
237 self.asset = Some(asset);
238 self
239 }
240 #[inline(always)]
242 pub fn vault(&mut self, vault: solana_program::pubkey::Pubkey) -> &mut Self {
243 self.vault = Some(vault);
244 self
245 }
246 #[inline(always)]
248 pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
249 self.owner = Some(owner);
250 self
251 }
252 #[inline(always)]
254 pub fn token(&mut self, token: solana_program::pubkey::Pubkey) -> &mut Self {
255 self.token = Some(token);
256 self
257 }
258 #[inline(always)]
260 pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
261 self.mint = Some(mint);
262 self
263 }
264 #[inline(always)]
266 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
267 self.metadata = Some(metadata);
268 self
269 }
270 #[inline(always)]
272 pub fn master_edition(&mut self, master_edition: solana_program::pubkey::Pubkey) -> &mut Self {
273 self.master_edition = Some(master_edition);
274 self
275 }
276 #[inline(always)]
279 pub fn token_record(
280 &mut self,
281 token_record: Option<solana_program::pubkey::Pubkey>,
282 ) -> &mut Self {
283 self.token_record = token_record;
284 self
285 }
286 #[inline(always)]
288 pub fn vault_token(&mut self, vault_token: solana_program::pubkey::Pubkey) -> &mut Self {
289 self.vault_token = Some(vault_token);
290 self
291 }
292 #[inline(always)]
295 pub fn vault_token_record(
296 &mut self,
297 vault_token_record: Option<solana_program::pubkey::Pubkey>,
298 ) -> &mut Self {
299 self.vault_token_record = vault_token_record;
300 self
301 }
302 #[inline(always)]
304 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
305 self.payer = Some(payer);
306 self
307 }
308 #[inline(always)]
311 pub fn nifty_asset_program(
312 &mut self,
313 nifty_asset_program: solana_program::pubkey::Pubkey,
314 ) -> &mut Self {
315 self.nifty_asset_program = Some(nifty_asset_program);
316 self
317 }
318 #[inline(always)]
321 pub fn token_metadata_program(
322 &mut self,
323 token_metadata_program: solana_program::pubkey::Pubkey,
324 ) -> &mut Self {
325 self.token_metadata_program = Some(token_metadata_program);
326 self
327 }
328 #[inline(always)]
331 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
332 self.system_program = Some(system_program);
333 self
334 }
335 #[inline(always)]
338 pub fn sysvar_instructions(
339 &mut self,
340 sysvar_instructions: solana_program::pubkey::Pubkey,
341 ) -> &mut Self {
342 self.sysvar_instructions = Some(sysvar_instructions);
343 self
344 }
345 #[inline(always)]
348 pub fn spl_token_program(
349 &mut self,
350 spl_token_program: solana_program::pubkey::Pubkey,
351 ) -> &mut Self {
352 self.spl_token_program = Some(spl_token_program);
353 self
354 }
355 #[inline(always)]
358 pub fn spl_ata_program(
359 &mut self,
360 spl_ata_program: solana_program::pubkey::Pubkey,
361 ) -> &mut Self {
362 self.spl_ata_program = Some(spl_ata_program);
363 self
364 }
365 #[inline(always)]
368 pub fn authorization_rules_program(
369 &mut self,
370 authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
371 ) -> &mut Self {
372 self.authorization_rules_program = authorization_rules_program;
373 self
374 }
375 #[inline(always)]
378 pub fn authorization_rules(
379 &mut self,
380 authorization_rules: Option<solana_program::pubkey::Pubkey>,
381 ) -> &mut Self {
382 self.authorization_rules = authorization_rules;
383 self
384 }
385 #[inline(always)]
387 pub fn add_remaining_account(
388 &mut self,
389 account: solana_program::instruction::AccountMeta,
390 ) -> &mut Self {
391 self.__remaining_accounts.push(account);
392 self
393 }
394 #[inline(always)]
396 pub fn add_remaining_accounts(
397 &mut self,
398 accounts: &[solana_program::instruction::AccountMeta],
399 ) -> &mut Self {
400 self.__remaining_accounts.extend_from_slice(accounts);
401 self
402 }
403 #[allow(clippy::clone_on_copy)]
404 pub fn instruction(&self) -> solana_program::instruction::Instruction {
405 let accounts =
406 Bridge {
407 asset: self.asset.expect("asset is not set"),
408 vault: self.vault.expect("vault is not set"),
409 owner: self.owner.expect("owner is not set"),
410 token: self.token.expect("token is not set"),
411 mint: self.mint.expect("mint is not set"),
412 metadata: self.metadata.expect("metadata is not set"),
413 master_edition: self.master_edition.expect("master_edition is not set"),
414 token_record: self.token_record,
415 vault_token: self.vault_token.expect("vault_token is not set"),
416 vault_token_record: self.vault_token_record,
417 payer: self.payer.expect("payer is not set"),
418 nifty_asset_program: self.nifty_asset_program.unwrap_or(solana_program::pubkey!(
419 "AssetGtQBTSgm5s91d1RAQod5JmaZiJDxqsgtqrZud73"
420 )),
421 token_metadata_program: self.token_metadata_program.unwrap_or(
422 solana_program::pubkey!("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),
423 ),
424 system_program: self
425 .system_program
426 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
427 sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
428 "Sysvar1nstructions1111111111111111111111111"
429 )),
430 spl_token_program: self.spl_token_program.unwrap_or(solana_program::pubkey!(
431 "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
432 )),
433 spl_ata_program: self.spl_ata_program.unwrap_or(solana_program::pubkey!(
434 "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
435 )),
436 authorization_rules_program: self.authorization_rules_program,
437 authorization_rules: self.authorization_rules,
438 };
439
440 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
441 }
442}
443
444pub struct BridgeCpiAccounts<'a, 'b> {
446 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
448 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
450 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
452 pub token: &'b solana_program::account_info::AccountInfo<'a>,
454 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
456 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
458 pub master_edition: &'b solana_program::account_info::AccountInfo<'a>,
460 pub token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
462 pub vault_token: &'b solana_program::account_info::AccountInfo<'a>,
464 pub vault_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
466 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
468 pub nifty_asset_program: &'b solana_program::account_info::AccountInfo<'a>,
470 pub token_metadata_program: &'b solana_program::account_info::AccountInfo<'a>,
472 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
474 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
476 pub spl_token_program: &'b solana_program::account_info::AccountInfo<'a>,
478 pub spl_ata_program: &'b solana_program::account_info::AccountInfo<'a>,
480 pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
482 pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
484}
485
486pub struct BridgeCpi<'a, 'b> {
488 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
490 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
492 pub vault: &'b solana_program::account_info::AccountInfo<'a>,
494 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
496 pub token: &'b solana_program::account_info::AccountInfo<'a>,
498 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
500 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
502 pub master_edition: &'b solana_program::account_info::AccountInfo<'a>,
504 pub token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
506 pub vault_token: &'b solana_program::account_info::AccountInfo<'a>,
508 pub vault_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
510 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
512 pub nifty_asset_program: &'b solana_program::account_info::AccountInfo<'a>,
514 pub token_metadata_program: &'b solana_program::account_info::AccountInfo<'a>,
516 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
518 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
520 pub spl_token_program: &'b solana_program::account_info::AccountInfo<'a>,
522 pub spl_ata_program: &'b solana_program::account_info::AccountInfo<'a>,
524 pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
526 pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
528}
529
530impl<'a, 'b> BridgeCpi<'a, 'b> {
531 pub fn new(
532 program: &'b solana_program::account_info::AccountInfo<'a>,
533 accounts: BridgeCpiAccounts<'a, 'b>,
534 ) -> Self {
535 Self {
536 __program: program,
537 asset: accounts.asset,
538 vault: accounts.vault,
539 owner: accounts.owner,
540 token: accounts.token,
541 mint: accounts.mint,
542 metadata: accounts.metadata,
543 master_edition: accounts.master_edition,
544 token_record: accounts.token_record,
545 vault_token: accounts.vault_token,
546 vault_token_record: accounts.vault_token_record,
547 payer: accounts.payer,
548 nifty_asset_program: accounts.nifty_asset_program,
549 token_metadata_program: accounts.token_metadata_program,
550 system_program: accounts.system_program,
551 sysvar_instructions: accounts.sysvar_instructions,
552 spl_token_program: accounts.spl_token_program,
553 spl_ata_program: accounts.spl_ata_program,
554 authorization_rules_program: accounts.authorization_rules_program,
555 authorization_rules: accounts.authorization_rules,
556 }
557 }
558 #[inline(always)]
559 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
560 self.invoke_signed_with_remaining_accounts(&[], &[])
561 }
562 #[inline(always)]
563 pub fn invoke_with_remaining_accounts(
564 &self,
565 remaining_accounts: &[(
566 &'b solana_program::account_info::AccountInfo<'a>,
567 bool,
568 bool,
569 )],
570 ) -> solana_program::entrypoint::ProgramResult {
571 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
572 }
573 #[inline(always)]
574 pub fn invoke_signed(
575 &self,
576 signers_seeds: &[&[&[u8]]],
577 ) -> solana_program::entrypoint::ProgramResult {
578 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
579 }
580 #[allow(clippy::clone_on_copy)]
581 #[allow(clippy::vec_init_then_push)]
582 pub fn invoke_signed_with_remaining_accounts(
583 &self,
584 signers_seeds: &[&[&[u8]]],
585 remaining_accounts: &[(
586 &'b solana_program::account_info::AccountInfo<'a>,
587 bool,
588 bool,
589 )],
590 ) -> solana_program::entrypoint::ProgramResult {
591 let mut accounts = Vec::with_capacity(19 + remaining_accounts.len());
592 accounts.push(solana_program::instruction::AccountMeta::new(
593 *self.asset.key,
594 false,
595 ));
596 accounts.push(solana_program::instruction::AccountMeta::new(
597 *self.vault.key,
598 false,
599 ));
600 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
601 *self.owner.key,
602 true,
603 ));
604 accounts.push(solana_program::instruction::AccountMeta::new(
605 *self.token.key,
606 false,
607 ));
608 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
609 *self.mint.key,
610 false,
611 ));
612 accounts.push(solana_program::instruction::AccountMeta::new(
613 *self.metadata.key,
614 false,
615 ));
616 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
617 *self.master_edition.key,
618 false,
619 ));
620 if let Some(token_record) = self.token_record {
621 accounts.push(solana_program::instruction::AccountMeta::new(
622 *token_record.key,
623 false,
624 ));
625 } else {
626 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
627 crate::BRIDGE_ID,
628 false,
629 ));
630 }
631 accounts.push(solana_program::instruction::AccountMeta::new(
632 *self.vault_token.key,
633 false,
634 ));
635 if let Some(vault_token_record) = self.vault_token_record {
636 accounts.push(solana_program::instruction::AccountMeta::new(
637 *vault_token_record.key,
638 false,
639 ));
640 } else {
641 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
642 crate::BRIDGE_ID,
643 false,
644 ));
645 }
646 accounts.push(solana_program::instruction::AccountMeta::new(
647 *self.payer.key,
648 true,
649 ));
650 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
651 *self.nifty_asset_program.key,
652 false,
653 ));
654 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
655 *self.token_metadata_program.key,
656 false,
657 ));
658 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
659 *self.system_program.key,
660 false,
661 ));
662 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
663 *self.sysvar_instructions.key,
664 false,
665 ));
666 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
667 *self.spl_token_program.key,
668 false,
669 ));
670 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
671 *self.spl_ata_program.key,
672 false,
673 ));
674 if let Some(authorization_rules_program) = self.authorization_rules_program {
675 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
676 *authorization_rules_program.key,
677 false,
678 ));
679 } else {
680 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
681 crate::BRIDGE_ID,
682 false,
683 ));
684 }
685 if let Some(authorization_rules) = self.authorization_rules {
686 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
687 *authorization_rules.key,
688 false,
689 ));
690 } else {
691 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
692 crate::BRIDGE_ID,
693 false,
694 ));
695 }
696 remaining_accounts.iter().for_each(|remaining_account| {
697 accounts.push(solana_program::instruction::AccountMeta {
698 pubkey: *remaining_account.0.key,
699 is_signer: remaining_account.1,
700 is_writable: remaining_account.2,
701 })
702 });
703 let data = BridgeInstructionData::new().try_to_vec().unwrap();
704
705 let instruction = solana_program::instruction::Instruction {
706 program_id: crate::BRIDGE_ID,
707 accounts,
708 data,
709 };
710 let mut account_infos = Vec::with_capacity(19 + 1 + remaining_accounts.len());
711 account_infos.push(self.__program.clone());
712 account_infos.push(self.asset.clone());
713 account_infos.push(self.vault.clone());
714 account_infos.push(self.owner.clone());
715 account_infos.push(self.token.clone());
716 account_infos.push(self.mint.clone());
717 account_infos.push(self.metadata.clone());
718 account_infos.push(self.master_edition.clone());
719 if let Some(token_record) = self.token_record {
720 account_infos.push(token_record.clone());
721 }
722 account_infos.push(self.vault_token.clone());
723 if let Some(vault_token_record) = self.vault_token_record {
724 account_infos.push(vault_token_record.clone());
725 }
726 account_infos.push(self.payer.clone());
727 account_infos.push(self.nifty_asset_program.clone());
728 account_infos.push(self.token_metadata_program.clone());
729 account_infos.push(self.system_program.clone());
730 account_infos.push(self.sysvar_instructions.clone());
731 account_infos.push(self.spl_token_program.clone());
732 account_infos.push(self.spl_ata_program.clone());
733 if let Some(authorization_rules_program) = self.authorization_rules_program {
734 account_infos.push(authorization_rules_program.clone());
735 }
736 if let Some(authorization_rules) = self.authorization_rules {
737 account_infos.push(authorization_rules.clone());
738 }
739 remaining_accounts
740 .iter()
741 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
742
743 if signers_seeds.is_empty() {
744 solana_program::program::invoke(&instruction, &account_infos)
745 } else {
746 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
747 }
748 }
749}
750
751pub struct BridgeCpiBuilder<'a, 'b> {
775 instruction: Box<BridgeCpiBuilderInstruction<'a, 'b>>,
776}
777
778impl<'a, 'b> BridgeCpiBuilder<'a, 'b> {
779 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
780 let instruction = Box::new(BridgeCpiBuilderInstruction {
781 __program: program,
782 asset: None,
783 vault: None,
784 owner: None,
785 token: None,
786 mint: None,
787 metadata: None,
788 master_edition: None,
789 token_record: None,
790 vault_token: None,
791 vault_token_record: None,
792 payer: None,
793 nifty_asset_program: None,
794 token_metadata_program: None,
795 system_program: None,
796 sysvar_instructions: None,
797 spl_token_program: None,
798 spl_ata_program: None,
799 authorization_rules_program: None,
800 authorization_rules: None,
801 __remaining_accounts: Vec::new(),
802 });
803 Self { instruction }
804 }
805 #[inline(always)]
807 pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
808 self.instruction.asset = Some(asset);
809 self
810 }
811 #[inline(always)]
813 pub fn vault(&mut self, vault: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
814 self.instruction.vault = Some(vault);
815 self
816 }
817 #[inline(always)]
819 pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
820 self.instruction.owner = Some(owner);
821 self
822 }
823 #[inline(always)]
825 pub fn token(&mut self, token: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
826 self.instruction.token = Some(token);
827 self
828 }
829 #[inline(always)]
831 pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
832 self.instruction.mint = Some(mint);
833 self
834 }
835 #[inline(always)]
837 pub fn metadata(
838 &mut self,
839 metadata: &'b solana_program::account_info::AccountInfo<'a>,
840 ) -> &mut Self {
841 self.instruction.metadata = Some(metadata);
842 self
843 }
844 #[inline(always)]
846 pub fn master_edition(
847 &mut self,
848 master_edition: &'b solana_program::account_info::AccountInfo<'a>,
849 ) -> &mut Self {
850 self.instruction.master_edition = Some(master_edition);
851 self
852 }
853 #[inline(always)]
856 pub fn token_record(
857 &mut self,
858 token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
859 ) -> &mut Self {
860 self.instruction.token_record = token_record;
861 self
862 }
863 #[inline(always)]
865 pub fn vault_token(
866 &mut self,
867 vault_token: &'b solana_program::account_info::AccountInfo<'a>,
868 ) -> &mut Self {
869 self.instruction.vault_token = Some(vault_token);
870 self
871 }
872 #[inline(always)]
875 pub fn vault_token_record(
876 &mut self,
877 vault_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
878 ) -> &mut Self {
879 self.instruction.vault_token_record = vault_token_record;
880 self
881 }
882 #[inline(always)]
884 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
885 self.instruction.payer = Some(payer);
886 self
887 }
888 #[inline(always)]
890 pub fn nifty_asset_program(
891 &mut self,
892 nifty_asset_program: &'b solana_program::account_info::AccountInfo<'a>,
893 ) -> &mut Self {
894 self.instruction.nifty_asset_program = Some(nifty_asset_program);
895 self
896 }
897 #[inline(always)]
899 pub fn token_metadata_program(
900 &mut self,
901 token_metadata_program: &'b solana_program::account_info::AccountInfo<'a>,
902 ) -> &mut Self {
903 self.instruction.token_metadata_program = Some(token_metadata_program);
904 self
905 }
906 #[inline(always)]
908 pub fn system_program(
909 &mut self,
910 system_program: &'b solana_program::account_info::AccountInfo<'a>,
911 ) -> &mut Self {
912 self.instruction.system_program = Some(system_program);
913 self
914 }
915 #[inline(always)]
917 pub fn sysvar_instructions(
918 &mut self,
919 sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
920 ) -> &mut Self {
921 self.instruction.sysvar_instructions = Some(sysvar_instructions);
922 self
923 }
924 #[inline(always)]
926 pub fn spl_token_program(
927 &mut self,
928 spl_token_program: &'b solana_program::account_info::AccountInfo<'a>,
929 ) -> &mut Self {
930 self.instruction.spl_token_program = Some(spl_token_program);
931 self
932 }
933 #[inline(always)]
935 pub fn spl_ata_program(
936 &mut self,
937 spl_ata_program: &'b solana_program::account_info::AccountInfo<'a>,
938 ) -> &mut Self {
939 self.instruction.spl_ata_program = Some(spl_ata_program);
940 self
941 }
942 #[inline(always)]
945 pub fn authorization_rules_program(
946 &mut self,
947 authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
948 ) -> &mut Self {
949 self.instruction.authorization_rules_program = authorization_rules_program;
950 self
951 }
952 #[inline(always)]
955 pub fn authorization_rules(
956 &mut self,
957 authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
958 ) -> &mut Self {
959 self.instruction.authorization_rules = authorization_rules;
960 self
961 }
962 #[inline(always)]
964 pub fn add_remaining_account(
965 &mut self,
966 account: &'b solana_program::account_info::AccountInfo<'a>,
967 is_writable: bool,
968 is_signer: bool,
969 ) -> &mut Self {
970 self.instruction
971 .__remaining_accounts
972 .push((account, is_writable, is_signer));
973 self
974 }
975 #[inline(always)]
980 pub fn add_remaining_accounts(
981 &mut self,
982 accounts: &[(
983 &'b solana_program::account_info::AccountInfo<'a>,
984 bool,
985 bool,
986 )],
987 ) -> &mut Self {
988 self.instruction
989 .__remaining_accounts
990 .extend_from_slice(accounts);
991 self
992 }
993 #[inline(always)]
994 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
995 self.invoke_signed(&[])
996 }
997 #[allow(clippy::clone_on_copy)]
998 #[allow(clippy::vec_init_then_push)]
999 pub fn invoke_signed(
1000 &self,
1001 signers_seeds: &[&[&[u8]]],
1002 ) -> solana_program::entrypoint::ProgramResult {
1003 let instruction = BridgeCpi {
1004 __program: self.instruction.__program,
1005
1006 asset: self.instruction.asset.expect("asset is not set"),
1007
1008 vault: self.instruction.vault.expect("vault is not set"),
1009
1010 owner: self.instruction.owner.expect("owner is not set"),
1011
1012 token: self.instruction.token.expect("token is not set"),
1013
1014 mint: self.instruction.mint.expect("mint is not set"),
1015
1016 metadata: self.instruction.metadata.expect("metadata is not set"),
1017
1018 master_edition: self
1019 .instruction
1020 .master_edition
1021 .expect("master_edition is not set"),
1022
1023 token_record: self.instruction.token_record,
1024
1025 vault_token: self
1026 .instruction
1027 .vault_token
1028 .expect("vault_token is not set"),
1029
1030 vault_token_record: self.instruction.vault_token_record,
1031
1032 payer: self.instruction.payer.expect("payer is not set"),
1033
1034 nifty_asset_program: self
1035 .instruction
1036 .nifty_asset_program
1037 .expect("nifty_asset_program is not set"),
1038
1039 token_metadata_program: self
1040 .instruction
1041 .token_metadata_program
1042 .expect("token_metadata_program is not set"),
1043
1044 system_program: self
1045 .instruction
1046 .system_program
1047 .expect("system_program is not set"),
1048
1049 sysvar_instructions: self
1050 .instruction
1051 .sysvar_instructions
1052 .expect("sysvar_instructions is not set"),
1053
1054 spl_token_program: self
1055 .instruction
1056 .spl_token_program
1057 .expect("spl_token_program is not set"),
1058
1059 spl_ata_program: self
1060 .instruction
1061 .spl_ata_program
1062 .expect("spl_ata_program is not set"),
1063
1064 authorization_rules_program: self.instruction.authorization_rules_program,
1065
1066 authorization_rules: self.instruction.authorization_rules,
1067 };
1068 instruction.invoke_signed_with_remaining_accounts(
1069 signers_seeds,
1070 &self.instruction.__remaining_accounts,
1071 )
1072 }
1073}
1074
1075struct BridgeCpiBuilderInstruction<'a, 'b> {
1076 __program: &'b solana_program::account_info::AccountInfo<'a>,
1077 asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1078 vault: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1079 owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1080 token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1081 mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1082 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1083 master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1084 token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1085 vault_token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1086 vault_token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1087 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1088 nifty_asset_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1089 token_metadata_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1090 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1091 sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1092 spl_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1093 spl_ata_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1094 authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1095 authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1096 __remaining_accounts: Vec<(
1098 &'b solana_program::account_info::AccountInfo<'a>,
1099 bool,
1100 bool,
1101 )>,
1102}