nifty_bridge/generated/instructions/
create.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! [https://github.com/metaplex-foundation/kinobi]
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12pub struct Create {
13    /// Asset account of the mint (pda of `['nifty::bridge::asset', mint pubkey]`)
14    pub asset: solana_program::pubkey::Pubkey,
15    /// Bridge account for the asset (pda of `['nifty::bridge::vault', mint pubkey]`)
16    pub vault: solana_program::pubkey::Pubkey,
17    /// Mint account of the token
18    pub mint: solana_program::pubkey::Pubkey,
19    /// Metadata account of the collection
20    pub metadata: solana_program::pubkey::Pubkey,
21    /// Update authority of the metadata
22    pub update_authority: (solana_program::pubkey::Pubkey, bool),
23    /// Asset account of the collection (pda of `['nifty::bridge::asset', collection mint pubkey]`)
24    pub collection: Option<solana_program::pubkey::Pubkey>,
25    /// The account paying for the storage fees
26    pub payer: solana_program::pubkey::Pubkey,
27    /// System program
28    pub system_program: solana_program::pubkey::Pubkey,
29    /// Nifty Asset program
30    pub nifty_asset_program: solana_program::pubkey::Pubkey,
31}
32
33impl Create {
34    pub fn instruction(&self) -> solana_program::instruction::Instruction {
35        self.instruction_with_remaining_accounts(&[])
36    }
37    #[allow(clippy::vec_init_then_push)]
38    pub fn instruction_with_remaining_accounts(
39        &self,
40        remaining_accounts: &[solana_program::instruction::AccountMeta],
41    ) -> solana_program::instruction::Instruction {
42        let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
43        accounts.push(solana_program::instruction::AccountMeta::new(
44            self.asset, false,
45        ));
46        accounts.push(solana_program::instruction::AccountMeta::new(
47            self.vault, false,
48        ));
49        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
50            self.mint, false,
51        ));
52        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
53            self.metadata,
54            false,
55        ));
56        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
57            self.update_authority.0,
58            self.update_authority.1,
59        ));
60        if let Some(collection) = self.collection {
61            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
62                collection, false,
63            ));
64        } else {
65            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
66                crate::BRIDGE_ID,
67                false,
68            ));
69        }
70        accounts.push(solana_program::instruction::AccountMeta::new(
71            self.payer, true,
72        ));
73        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
74            self.system_program,
75            false,
76        ));
77        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
78            self.nifty_asset_program,
79            false,
80        ));
81        accounts.extend_from_slice(remaining_accounts);
82        let data = CreateInstructionData::new().try_to_vec().unwrap();
83
84        solana_program::instruction::Instruction {
85            program_id: crate::BRIDGE_ID,
86            accounts,
87            data,
88        }
89    }
90}
91
92#[derive(BorshDeserialize, BorshSerialize)]
93struct CreateInstructionData {
94    discriminator: u8,
95}
96
97impl CreateInstructionData {
98    fn new() -> Self {
99        Self { discriminator: 1 }
100    }
101}
102
103/// Instruction builder for `Create`.
104///
105/// ### Accounts:
106///
107///   0. `[writable]` asset
108///   1. `[writable]` vault
109///   2. `[]` mint
110///   3. `[]` metadata
111///   4. `[signer]` update_authority
112///   5. `[optional]` collection
113///   6. `[writable, signer]` payer
114///   7. `[optional]` system_program (default to `11111111111111111111111111111111`)
115///   8. `[optional]` nifty_asset_program (default to `AssetGtQBTSgm5s91d1RAQod5JmaZiJDxqsgtqrZud73`)
116#[derive(Default)]
117pub struct CreateBuilder {
118    asset: Option<solana_program::pubkey::Pubkey>,
119    vault: Option<solana_program::pubkey::Pubkey>,
120    mint: Option<solana_program::pubkey::Pubkey>,
121    metadata: Option<solana_program::pubkey::Pubkey>,
122    update_authority: Option<(solana_program::pubkey::Pubkey, bool)>,
123    collection: Option<solana_program::pubkey::Pubkey>,
124    payer: Option<solana_program::pubkey::Pubkey>,
125    system_program: Option<solana_program::pubkey::Pubkey>,
126    nifty_asset_program: Option<solana_program::pubkey::Pubkey>,
127    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
128}
129
130impl CreateBuilder {
131    pub fn new() -> Self {
132        Self::default()
133    }
134    /// Asset account of the mint (pda of `['nifty::bridge::asset', mint pubkey]`)
135    #[inline(always)]
136    pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
137        self.asset = Some(asset);
138        self
139    }
140    /// Bridge account for the asset (pda of `['nifty::bridge::vault', mint pubkey]`)
141    #[inline(always)]
142    pub fn vault(&mut self, vault: solana_program::pubkey::Pubkey) -> &mut Self {
143        self.vault = Some(vault);
144        self
145    }
146    /// Mint account of the token
147    #[inline(always)]
148    pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
149        self.mint = Some(mint);
150        self
151    }
152    /// Metadata account of the collection
153    #[inline(always)]
154    pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
155        self.metadata = Some(metadata);
156        self
157    }
158    /// Update authority of the metadata
159    #[inline(always)]
160    pub fn update_authority(
161        &mut self,
162        update_authority: solana_program::pubkey::Pubkey,
163        as_signer: bool,
164    ) -> &mut Self {
165        self.update_authority = Some((update_authority, as_signer));
166        self
167    }
168    /// `[optional account]`
169    /// Asset account of the collection (pda of `['nifty::bridge::asset', collection mint pubkey]`)
170    #[inline(always)]
171    pub fn collection(&mut self, collection: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
172        self.collection = collection;
173        self
174    }
175    /// The account paying for the storage fees
176    #[inline(always)]
177    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
178        self.payer = Some(payer);
179        self
180    }
181    /// `[optional account, default to '11111111111111111111111111111111']`
182    /// System program
183    #[inline(always)]
184    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
185        self.system_program = Some(system_program);
186        self
187    }
188    /// `[optional account, default to 'AssetGtQBTSgm5s91d1RAQod5JmaZiJDxqsgtqrZud73']`
189    /// Nifty Asset program
190    #[inline(always)]
191    pub fn nifty_asset_program(
192        &mut self,
193        nifty_asset_program: solana_program::pubkey::Pubkey,
194    ) -> &mut Self {
195        self.nifty_asset_program = Some(nifty_asset_program);
196        self
197    }
198    /// Add an aditional account to the instruction.
199    #[inline(always)]
200    pub fn add_remaining_account(
201        &mut self,
202        account: solana_program::instruction::AccountMeta,
203    ) -> &mut Self {
204        self.__remaining_accounts.push(account);
205        self
206    }
207    /// Add additional accounts to the instruction.
208    #[inline(always)]
209    pub fn add_remaining_accounts(
210        &mut self,
211        accounts: &[solana_program::instruction::AccountMeta],
212    ) -> &mut Self {
213        self.__remaining_accounts.extend_from_slice(accounts);
214        self
215    }
216    #[allow(clippy::clone_on_copy)]
217    pub fn instruction(&self) -> solana_program::instruction::Instruction {
218        let accounts = Create {
219            asset: self.asset.expect("asset is not set"),
220            vault: self.vault.expect("vault is not set"),
221            mint: self.mint.expect("mint is not set"),
222            metadata: self.metadata.expect("metadata is not set"),
223            update_authority: self.update_authority.expect("update_authority is not set"),
224            collection: self.collection,
225            payer: self.payer.expect("payer is not set"),
226            system_program: self
227                .system_program
228                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
229            nifty_asset_program: self.nifty_asset_program.unwrap_or(solana_program::pubkey!(
230                "AssetGtQBTSgm5s91d1RAQod5JmaZiJDxqsgtqrZud73"
231            )),
232        };
233
234        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
235    }
236}
237
238/// `create` CPI accounts.
239pub struct CreateCpiAccounts<'a, 'b> {
240    /// Asset account of the mint (pda of `['nifty::bridge::asset', mint pubkey]`)
241    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
242    /// Bridge account for the asset (pda of `['nifty::bridge::vault', mint pubkey]`)
243    pub vault: &'b solana_program::account_info::AccountInfo<'a>,
244    /// Mint account of the token
245    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
246    /// Metadata account of the collection
247    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
248    /// Update authority of the metadata
249    pub update_authority: (&'b solana_program::account_info::AccountInfo<'a>, bool),
250    /// Asset account of the collection (pda of `['nifty::bridge::asset', collection mint pubkey]`)
251    pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
252    /// The account paying for the storage fees
253    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
254    /// System program
255    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
256    /// Nifty Asset program
257    pub nifty_asset_program: &'b solana_program::account_info::AccountInfo<'a>,
258}
259
260/// `create` CPI instruction.
261pub struct CreateCpi<'a, 'b> {
262    /// The program to invoke.
263    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
264    /// Asset account of the mint (pda of `['nifty::bridge::asset', mint pubkey]`)
265    pub asset: &'b solana_program::account_info::AccountInfo<'a>,
266    /// Bridge account for the asset (pda of `['nifty::bridge::vault', mint pubkey]`)
267    pub vault: &'b solana_program::account_info::AccountInfo<'a>,
268    /// Mint account of the token
269    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
270    /// Metadata account of the collection
271    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
272    /// Update authority of the metadata
273    pub update_authority: (&'b solana_program::account_info::AccountInfo<'a>, bool),
274    /// Asset account of the collection (pda of `['nifty::bridge::asset', collection mint pubkey]`)
275    pub collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
276    /// The account paying for the storage fees
277    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
278    /// System program
279    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
280    /// Nifty Asset program
281    pub nifty_asset_program: &'b solana_program::account_info::AccountInfo<'a>,
282}
283
284impl<'a, 'b> CreateCpi<'a, 'b> {
285    pub fn new(
286        program: &'b solana_program::account_info::AccountInfo<'a>,
287        accounts: CreateCpiAccounts<'a, 'b>,
288    ) -> Self {
289        Self {
290            __program: program,
291            asset: accounts.asset,
292            vault: accounts.vault,
293            mint: accounts.mint,
294            metadata: accounts.metadata,
295            update_authority: accounts.update_authority,
296            collection: accounts.collection,
297            payer: accounts.payer,
298            system_program: accounts.system_program,
299            nifty_asset_program: accounts.nifty_asset_program,
300        }
301    }
302    #[inline(always)]
303    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
304        self.invoke_signed_with_remaining_accounts(&[], &[])
305    }
306    #[inline(always)]
307    pub fn invoke_with_remaining_accounts(
308        &self,
309        remaining_accounts: &[(
310            &'b solana_program::account_info::AccountInfo<'a>,
311            bool,
312            bool,
313        )],
314    ) -> solana_program::entrypoint::ProgramResult {
315        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
316    }
317    #[inline(always)]
318    pub fn invoke_signed(
319        &self,
320        signers_seeds: &[&[&[u8]]],
321    ) -> solana_program::entrypoint::ProgramResult {
322        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
323    }
324    #[allow(clippy::clone_on_copy)]
325    #[allow(clippy::vec_init_then_push)]
326    pub fn invoke_signed_with_remaining_accounts(
327        &self,
328        signers_seeds: &[&[&[u8]]],
329        remaining_accounts: &[(
330            &'b solana_program::account_info::AccountInfo<'a>,
331            bool,
332            bool,
333        )],
334    ) -> solana_program::entrypoint::ProgramResult {
335        let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
336        accounts.push(solana_program::instruction::AccountMeta::new(
337            *self.asset.key,
338            false,
339        ));
340        accounts.push(solana_program::instruction::AccountMeta::new(
341            *self.vault.key,
342            false,
343        ));
344        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
345            *self.mint.key,
346            false,
347        ));
348        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
349            *self.metadata.key,
350            false,
351        ));
352        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
353            *self.update_authority.0.key,
354            self.update_authority.1,
355        ));
356        if let Some(collection) = self.collection {
357            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
358                *collection.key,
359                false,
360            ));
361        } else {
362            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
363                crate::BRIDGE_ID,
364                false,
365            ));
366        }
367        accounts.push(solana_program::instruction::AccountMeta::new(
368            *self.payer.key,
369            true,
370        ));
371        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
372            *self.system_program.key,
373            false,
374        ));
375        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
376            *self.nifty_asset_program.key,
377            false,
378        ));
379        remaining_accounts.iter().for_each(|remaining_account| {
380            accounts.push(solana_program::instruction::AccountMeta {
381                pubkey: *remaining_account.0.key,
382                is_signer: remaining_account.1,
383                is_writable: remaining_account.2,
384            })
385        });
386        let data = CreateInstructionData::new().try_to_vec().unwrap();
387
388        let instruction = solana_program::instruction::Instruction {
389            program_id: crate::BRIDGE_ID,
390            accounts,
391            data,
392        };
393        let mut account_infos = Vec::with_capacity(9 + 1 + remaining_accounts.len());
394        account_infos.push(self.__program.clone());
395        account_infos.push(self.asset.clone());
396        account_infos.push(self.vault.clone());
397        account_infos.push(self.mint.clone());
398        account_infos.push(self.metadata.clone());
399        account_infos.push(self.update_authority.0.clone());
400        if let Some(collection) = self.collection {
401            account_infos.push(collection.clone());
402        }
403        account_infos.push(self.payer.clone());
404        account_infos.push(self.system_program.clone());
405        account_infos.push(self.nifty_asset_program.clone());
406        remaining_accounts
407            .iter()
408            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
409
410        if signers_seeds.is_empty() {
411            solana_program::program::invoke(&instruction, &account_infos)
412        } else {
413            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
414        }
415    }
416}
417
418/// Instruction builder for `Create` via CPI.
419///
420/// ### Accounts:
421///
422///   0. `[writable]` asset
423///   1. `[writable]` vault
424///   2. `[]` mint
425///   3. `[]` metadata
426///   4. `[signer]` update_authority
427///   5. `[optional]` collection
428///   6. `[writable, signer]` payer
429///   7. `[]` system_program
430///   8. `[]` nifty_asset_program
431pub struct CreateCpiBuilder<'a, 'b> {
432    instruction: Box<CreateCpiBuilderInstruction<'a, 'b>>,
433}
434
435impl<'a, 'b> CreateCpiBuilder<'a, 'b> {
436    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
437        let instruction = Box::new(CreateCpiBuilderInstruction {
438            __program: program,
439            asset: None,
440            vault: None,
441            mint: None,
442            metadata: None,
443            update_authority: None,
444            collection: None,
445            payer: None,
446            system_program: None,
447            nifty_asset_program: None,
448            __remaining_accounts: Vec::new(),
449        });
450        Self { instruction }
451    }
452    /// Asset account of the mint (pda of `['nifty::bridge::asset', mint pubkey]`)
453    #[inline(always)]
454    pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
455        self.instruction.asset = Some(asset);
456        self
457    }
458    /// Bridge account for the asset (pda of `['nifty::bridge::vault', mint pubkey]`)
459    #[inline(always)]
460    pub fn vault(&mut self, vault: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
461        self.instruction.vault = Some(vault);
462        self
463    }
464    /// Mint account of the token
465    #[inline(always)]
466    pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
467        self.instruction.mint = Some(mint);
468        self
469    }
470    /// Metadata account of the collection
471    #[inline(always)]
472    pub fn metadata(
473        &mut self,
474        metadata: &'b solana_program::account_info::AccountInfo<'a>,
475    ) -> &mut Self {
476        self.instruction.metadata = Some(metadata);
477        self
478    }
479    /// Update authority of the metadata
480    #[inline(always)]
481    pub fn update_authority(
482        &mut self,
483        update_authority: &'b solana_program::account_info::AccountInfo<'a>,
484        as_signer: bool,
485    ) -> &mut Self {
486        self.instruction.update_authority = Some((update_authority, as_signer));
487        self
488    }
489    /// `[optional account]`
490    /// Asset account of the collection (pda of `['nifty::bridge::asset', collection mint pubkey]`)
491    #[inline(always)]
492    pub fn collection(
493        &mut self,
494        collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
495    ) -> &mut Self {
496        self.instruction.collection = collection;
497        self
498    }
499    /// The account paying for the storage fees
500    #[inline(always)]
501    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
502        self.instruction.payer = Some(payer);
503        self
504    }
505    /// System program
506    #[inline(always)]
507    pub fn system_program(
508        &mut self,
509        system_program: &'b solana_program::account_info::AccountInfo<'a>,
510    ) -> &mut Self {
511        self.instruction.system_program = Some(system_program);
512        self
513    }
514    /// Nifty Asset program
515    #[inline(always)]
516    pub fn nifty_asset_program(
517        &mut self,
518        nifty_asset_program: &'b solana_program::account_info::AccountInfo<'a>,
519    ) -> &mut Self {
520        self.instruction.nifty_asset_program = Some(nifty_asset_program);
521        self
522    }
523    /// Add an additional account to the instruction.
524    #[inline(always)]
525    pub fn add_remaining_account(
526        &mut self,
527        account: &'b solana_program::account_info::AccountInfo<'a>,
528        is_writable: bool,
529        is_signer: bool,
530    ) -> &mut Self {
531        self.instruction
532            .__remaining_accounts
533            .push((account, is_writable, is_signer));
534        self
535    }
536    /// Add additional accounts to the instruction.
537    ///
538    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
539    /// and a `bool` indicating whether the account is a signer or not.
540    #[inline(always)]
541    pub fn add_remaining_accounts(
542        &mut self,
543        accounts: &[(
544            &'b solana_program::account_info::AccountInfo<'a>,
545            bool,
546            bool,
547        )],
548    ) -> &mut Self {
549        self.instruction
550            .__remaining_accounts
551            .extend_from_slice(accounts);
552        self
553    }
554    #[inline(always)]
555    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
556        self.invoke_signed(&[])
557    }
558    #[allow(clippy::clone_on_copy)]
559    #[allow(clippy::vec_init_then_push)]
560    pub fn invoke_signed(
561        &self,
562        signers_seeds: &[&[&[u8]]],
563    ) -> solana_program::entrypoint::ProgramResult {
564        let instruction = CreateCpi {
565            __program: self.instruction.__program,
566
567            asset: self.instruction.asset.expect("asset is not set"),
568
569            vault: self.instruction.vault.expect("vault is not set"),
570
571            mint: self.instruction.mint.expect("mint is not set"),
572
573            metadata: self.instruction.metadata.expect("metadata is not set"),
574
575            update_authority: self
576                .instruction
577                .update_authority
578                .expect("update_authority is not set"),
579
580            collection: self.instruction.collection,
581
582            payer: self.instruction.payer.expect("payer is not set"),
583
584            system_program: self
585                .instruction
586                .system_program
587                .expect("system_program is not set"),
588
589            nifty_asset_program: self
590                .instruction
591                .nifty_asset_program
592                .expect("nifty_asset_program is not set"),
593        };
594        instruction.invoke_signed_with_remaining_accounts(
595            signers_seeds,
596            &self.instruction.__remaining_accounts,
597        )
598    }
599}
600
601struct CreateCpiBuilderInstruction<'a, 'b> {
602    __program: &'b solana_program::account_info::AccountInfo<'a>,
603    asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
604    vault: Option<&'b solana_program::account_info::AccountInfo<'a>>,
605    mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
606    metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
607    update_authority: Option<(&'b solana_program::account_info::AccountInfo<'a>, bool)>,
608    collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
609    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
610    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
611    nifty_asset_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
612    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
613    __remaining_accounts: Vec<(
614        &'b solana_program::account_info::AccountInfo<'a>,
615        bool,
616        bool,
617    )>,
618}