Skip to main content

mpl_bubblegum/generated/instructions/
set_collection_v2.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 crate::generated::types::MetadataArgsV2;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12/// Accounts.
13pub struct SetCollectionV2 {
14    pub tree_config: solana_program::pubkey::Pubkey,
15
16    pub payer: solana_program::pubkey::Pubkey,
17    /// If item is not in a collection, then authority must be tree owner/delegate.  If item is
18    /// getting removed from a collection, then this must be an authority for the existing
19    /// collection.  Defaults to `payer`
20    pub authority: Option<solana_program::pubkey::Pubkey>,
21    /// If item is getting added to a new collection, then this must be the authority
22    /// for the new collection.  Defaults to `authority`
23    pub new_collection_authority: Option<solana_program::pubkey::Pubkey>,
24
25    pub leaf_owner: solana_program::pubkey::Pubkey,
26    /// Defaults to `leaf_owner`
27    pub leaf_delegate: Option<solana_program::pubkey::Pubkey>,
28
29    pub merkle_tree: solana_program::pubkey::Pubkey,
30
31    pub core_collection: Option<solana_program::pubkey::Pubkey>,
32
33    pub new_core_collection: Option<solana_program::pubkey::Pubkey>,
34
35    pub mpl_core_cpi_signer: solana_program::pubkey::Pubkey,
36
37    pub log_wrapper: solana_program::pubkey::Pubkey,
38
39    pub compression_program: solana_program::pubkey::Pubkey,
40
41    pub mpl_core_program: solana_program::pubkey::Pubkey,
42
43    pub system_program: solana_program::pubkey::Pubkey,
44}
45
46impl SetCollectionV2 {
47    pub fn instruction(
48        &self,
49        args: SetCollectionV2InstructionArgs,
50    ) -> solana_program::instruction::Instruction {
51        self.instruction_with_remaining_accounts(args, &[])
52    }
53    #[allow(clippy::vec_init_then_push)]
54    pub fn instruction_with_remaining_accounts(
55        &self,
56        args: SetCollectionV2InstructionArgs,
57        remaining_accounts: &[solana_program::instruction::AccountMeta],
58    ) -> solana_program::instruction::Instruction {
59        let mut accounts = Vec::with_capacity(14 + remaining_accounts.len());
60        accounts.push(solana_program::instruction::AccountMeta::new(
61            self.tree_config,
62            false,
63        ));
64        accounts.push(solana_program::instruction::AccountMeta::new(
65            self.payer, true,
66        ));
67        if let Some(authority) = self.authority {
68            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
69                authority, true,
70            ));
71        } else {
72            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
73                crate::MPL_BUBBLEGUM_ID,
74                false,
75            ));
76        }
77        if let Some(new_collection_authority) = self.new_collection_authority {
78            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
79                new_collection_authority,
80                true,
81            ));
82        } else {
83            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
84                crate::MPL_BUBBLEGUM_ID,
85                false,
86            ));
87        }
88        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
89            self.leaf_owner,
90            false,
91        ));
92        if let Some(leaf_delegate) = self.leaf_delegate {
93            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
94                leaf_delegate,
95                false,
96            ));
97        } else {
98            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
99                crate::MPL_BUBBLEGUM_ID,
100                false,
101            ));
102        }
103        accounts.push(solana_program::instruction::AccountMeta::new(
104            self.merkle_tree,
105            false,
106        ));
107        if let Some(core_collection) = self.core_collection {
108            accounts.push(solana_program::instruction::AccountMeta::new(
109                core_collection,
110                false,
111            ));
112        } else {
113            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
114                crate::MPL_BUBBLEGUM_ID,
115                false,
116            ));
117        }
118        if let Some(new_core_collection) = self.new_core_collection {
119            accounts.push(solana_program::instruction::AccountMeta::new(
120                new_core_collection,
121                false,
122            ));
123        } else {
124            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
125                crate::MPL_BUBBLEGUM_ID,
126                false,
127            ));
128        }
129        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
130            self.mpl_core_cpi_signer,
131            false,
132        ));
133        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
134            self.log_wrapper,
135            false,
136        ));
137        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
138            self.compression_program,
139            false,
140        ));
141        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
142            self.mpl_core_program,
143            false,
144        ));
145        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
146            self.system_program,
147            false,
148        ));
149        accounts.extend_from_slice(remaining_accounts);
150        let mut data = SetCollectionV2InstructionData::new().try_to_vec().unwrap();
151        let mut args = args.try_to_vec().unwrap();
152        data.append(&mut args);
153
154        solana_program::instruction::Instruction {
155            program_id: crate::MPL_BUBBLEGUM_ID,
156            accounts,
157            data,
158        }
159    }
160}
161
162#[derive(BorshDeserialize, BorshSerialize)]
163struct SetCollectionV2InstructionData {
164    discriminator: [u8; 8],
165}
166
167impl SetCollectionV2InstructionData {
168    fn new() -> Self {
169        Self {
170            discriminator: [229, 35, 61, 91, 15, 14, 99, 160],
171        }
172    }
173}
174
175#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
176#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
177pub struct SetCollectionV2InstructionArgs {
178    pub root: [u8; 32],
179    pub asset_data_hash: Option<[u8; 32]>,
180    pub flags: Option<u8>,
181    pub nonce: u64,
182    pub index: u32,
183    pub metadata: MetadataArgsV2,
184}
185
186/// Instruction builder.
187#[derive(Default)]
188pub struct SetCollectionV2Builder {
189    tree_config: Option<solana_program::pubkey::Pubkey>,
190    payer: Option<solana_program::pubkey::Pubkey>,
191    authority: Option<solana_program::pubkey::Pubkey>,
192    new_collection_authority: Option<solana_program::pubkey::Pubkey>,
193    leaf_owner: Option<solana_program::pubkey::Pubkey>,
194    leaf_delegate: Option<solana_program::pubkey::Pubkey>,
195    merkle_tree: Option<solana_program::pubkey::Pubkey>,
196    core_collection: Option<solana_program::pubkey::Pubkey>,
197    new_core_collection: Option<solana_program::pubkey::Pubkey>,
198    mpl_core_cpi_signer: Option<solana_program::pubkey::Pubkey>,
199    log_wrapper: Option<solana_program::pubkey::Pubkey>,
200    compression_program: Option<solana_program::pubkey::Pubkey>,
201    mpl_core_program: Option<solana_program::pubkey::Pubkey>,
202    system_program: Option<solana_program::pubkey::Pubkey>,
203    root: Option<[u8; 32]>,
204    asset_data_hash: Option<[u8; 32]>,
205    flags: Option<u8>,
206    nonce: Option<u64>,
207    index: Option<u32>,
208    metadata: Option<MetadataArgsV2>,
209    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
210}
211
212impl SetCollectionV2Builder {
213    pub fn new() -> Self {
214        Self::default()
215    }
216    #[inline(always)]
217    pub fn tree_config(&mut self, tree_config: solana_program::pubkey::Pubkey) -> &mut Self {
218        self.tree_config = Some(tree_config);
219        self
220    }
221    #[inline(always)]
222    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
223        self.payer = Some(payer);
224        self
225    }
226    /// `[optional account]`
227    /// If item is not in a collection, then authority must be tree owner/delegate.  If item is
228    /// getting removed from a collection, then this must be an authority for the existing
229    /// collection.  Defaults to `payer`
230    #[inline(always)]
231    pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
232        self.authority = authority;
233        self
234    }
235    /// `[optional account]`
236    /// If item is getting added to a new collection, then this must be the authority
237    /// for the new collection.  Defaults to `authority`
238    #[inline(always)]
239    pub fn new_collection_authority(
240        &mut self,
241        new_collection_authority: Option<solana_program::pubkey::Pubkey>,
242    ) -> &mut Self {
243        self.new_collection_authority = new_collection_authority;
244        self
245    }
246    #[inline(always)]
247    pub fn leaf_owner(&mut self, leaf_owner: solana_program::pubkey::Pubkey) -> &mut Self {
248        self.leaf_owner = Some(leaf_owner);
249        self
250    }
251    /// `[optional account]`
252    /// Defaults to `leaf_owner`
253    #[inline(always)]
254    pub fn leaf_delegate(
255        &mut self,
256        leaf_delegate: Option<solana_program::pubkey::Pubkey>,
257    ) -> &mut Self {
258        self.leaf_delegate = leaf_delegate;
259        self
260    }
261    #[inline(always)]
262    pub fn merkle_tree(&mut self, merkle_tree: solana_program::pubkey::Pubkey) -> &mut Self {
263        self.merkle_tree = Some(merkle_tree);
264        self
265    }
266    /// `[optional account]`
267    #[inline(always)]
268    pub fn core_collection(
269        &mut self,
270        core_collection: Option<solana_program::pubkey::Pubkey>,
271    ) -> &mut Self {
272        self.core_collection = core_collection;
273        self
274    }
275    /// `[optional account]`
276    #[inline(always)]
277    pub fn new_core_collection(
278        &mut self,
279        new_core_collection: Option<solana_program::pubkey::Pubkey>,
280    ) -> &mut Self {
281        self.new_core_collection = new_core_collection;
282        self
283    }
284    /// `[optional account, default to 'CbNY3JiXdXNE9tPNEk1aRZVEkWdj2v7kfJLNQwZZgpXk']`
285    #[inline(always)]
286    pub fn mpl_core_cpi_signer(
287        &mut self,
288        mpl_core_cpi_signer: solana_program::pubkey::Pubkey,
289    ) -> &mut Self {
290        self.mpl_core_cpi_signer = Some(mpl_core_cpi_signer);
291        self
292    }
293    /// `[optional account, default to 'mnoopTCrg4p8ry25e4bcWA9XZjbNjMTfgYVGGEdRsf3']`
294    #[inline(always)]
295    pub fn log_wrapper(&mut self, log_wrapper: solana_program::pubkey::Pubkey) -> &mut Self {
296        self.log_wrapper = Some(log_wrapper);
297        self
298    }
299    /// `[optional account, default to 'mcmt6YrQEMKw8Mw43FmpRLmf7BqRnFMKmAcbxE3xkAW']`
300    #[inline(always)]
301    pub fn compression_program(
302        &mut self,
303        compression_program: solana_program::pubkey::Pubkey,
304    ) -> &mut Self {
305        self.compression_program = Some(compression_program);
306        self
307    }
308    /// `[optional account, default to 'CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d']`
309    #[inline(always)]
310    pub fn mpl_core_program(
311        &mut self,
312        mpl_core_program: solana_program::pubkey::Pubkey,
313    ) -> &mut Self {
314        self.mpl_core_program = Some(mpl_core_program);
315        self
316    }
317    /// `[optional account, default to '11111111111111111111111111111111']`
318    #[inline(always)]
319    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
320        self.system_program = Some(system_program);
321        self
322    }
323    #[inline(always)]
324    pub fn root(&mut self, root: [u8; 32]) -> &mut Self {
325        self.root = Some(root);
326        self
327    }
328    /// `[optional argument]`
329    #[inline(always)]
330    pub fn asset_data_hash(&mut self, asset_data_hash: [u8; 32]) -> &mut Self {
331        self.asset_data_hash = Some(asset_data_hash);
332        self
333    }
334    /// `[optional argument]`
335    #[inline(always)]
336    pub fn flags(&mut self, flags: u8) -> &mut Self {
337        self.flags = Some(flags);
338        self
339    }
340    #[inline(always)]
341    pub fn nonce(&mut self, nonce: u64) -> &mut Self {
342        self.nonce = Some(nonce);
343        self
344    }
345    #[inline(always)]
346    pub fn index(&mut self, index: u32) -> &mut Self {
347        self.index = Some(index);
348        self
349    }
350    #[inline(always)]
351    pub fn metadata(&mut self, metadata: MetadataArgsV2) -> &mut Self {
352        self.metadata = Some(metadata);
353        self
354    }
355    /// Add an aditional account to the instruction.
356    #[inline(always)]
357    pub fn add_remaining_account(
358        &mut self,
359        account: solana_program::instruction::AccountMeta,
360    ) -> &mut Self {
361        self.__remaining_accounts.push(account);
362        self
363    }
364    /// Add additional accounts to the instruction.
365    #[inline(always)]
366    pub fn add_remaining_accounts(
367        &mut self,
368        accounts: &[solana_program::instruction::AccountMeta],
369    ) -> &mut Self {
370        self.__remaining_accounts.extend_from_slice(accounts);
371        self
372    }
373    #[allow(clippy::clone_on_copy)]
374    pub fn instruction(&self) -> solana_program::instruction::Instruction {
375        let accounts = SetCollectionV2 {
376            tree_config: self.tree_config.expect("tree_config is not set"),
377            payer: self.payer.expect("payer is not set"),
378            authority: self.authority,
379            new_collection_authority: self.new_collection_authority,
380            leaf_owner: self.leaf_owner.expect("leaf_owner is not set"),
381            leaf_delegate: self.leaf_delegate,
382            merkle_tree: self.merkle_tree.expect("merkle_tree is not set"),
383            core_collection: self.core_collection,
384            new_core_collection: self.new_core_collection,
385            mpl_core_cpi_signer: self.mpl_core_cpi_signer.unwrap_or(solana_program::pubkey!(
386                "CbNY3JiXdXNE9tPNEk1aRZVEkWdj2v7kfJLNQwZZgpXk"
387            )),
388            log_wrapper: self.log_wrapper.unwrap_or(solana_program::pubkey!(
389                "mnoopTCrg4p8ry25e4bcWA9XZjbNjMTfgYVGGEdRsf3"
390            )),
391            compression_program: self.compression_program.unwrap_or(solana_program::pubkey!(
392                "mcmt6YrQEMKw8Mw43FmpRLmf7BqRnFMKmAcbxE3xkAW"
393            )),
394            mpl_core_program: self.mpl_core_program.unwrap_or(solana_program::pubkey!(
395                "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d"
396            )),
397            system_program: self
398                .system_program
399                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
400        };
401        let args = SetCollectionV2InstructionArgs {
402            root: self.root.clone().expect("root is not set"),
403            asset_data_hash: self.asset_data_hash.clone(),
404            flags: self.flags.clone(),
405            nonce: self.nonce.clone().expect("nonce is not set"),
406            index: self.index.clone().expect("index is not set"),
407            metadata: self.metadata.clone().expect("metadata is not set"),
408        };
409
410        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
411    }
412}
413
414/// `set_collection_v2` CPI accounts.
415pub struct SetCollectionV2CpiAccounts<'a, 'b> {
416    pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
417
418    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
419    /// If item is not in a collection, then authority must be tree owner/delegate.  If item is
420    /// getting removed from a collection, then this must be an authority for the existing
421    /// collection.  Defaults to `payer`
422    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
423    /// If item is getting added to a new collection, then this must be the authority
424    /// for the new collection.  Defaults to `authority`
425    pub new_collection_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
426
427    pub leaf_owner: &'b solana_program::account_info::AccountInfo<'a>,
428    /// Defaults to `leaf_owner`
429    pub leaf_delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
430
431    pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
432
433    pub core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
434
435    pub new_core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
436
437    pub mpl_core_cpi_signer: &'b solana_program::account_info::AccountInfo<'a>,
438
439    pub log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
440
441    pub compression_program: &'b solana_program::account_info::AccountInfo<'a>,
442
443    pub mpl_core_program: &'b solana_program::account_info::AccountInfo<'a>,
444
445    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
446}
447
448/// `set_collection_v2` CPI instruction.
449pub struct SetCollectionV2Cpi<'a, 'b> {
450    /// The program to invoke.
451    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
452
453    pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
454
455    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
456    /// If item is not in a collection, then authority must be tree owner/delegate.  If item is
457    /// getting removed from a collection, then this must be an authority for the existing
458    /// collection.  Defaults to `payer`
459    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
460    /// If item is getting added to a new collection, then this must be the authority
461    /// for the new collection.  Defaults to `authority`
462    pub new_collection_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
463
464    pub leaf_owner: &'b solana_program::account_info::AccountInfo<'a>,
465    /// Defaults to `leaf_owner`
466    pub leaf_delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
467
468    pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
469
470    pub core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
471
472    pub new_core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
473
474    pub mpl_core_cpi_signer: &'b solana_program::account_info::AccountInfo<'a>,
475
476    pub log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
477
478    pub compression_program: &'b solana_program::account_info::AccountInfo<'a>,
479
480    pub mpl_core_program: &'b solana_program::account_info::AccountInfo<'a>,
481
482    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
483    /// The arguments for the instruction.
484    pub __args: SetCollectionV2InstructionArgs,
485}
486
487impl<'a, 'b> SetCollectionV2Cpi<'a, 'b> {
488    pub fn new(
489        program: &'b solana_program::account_info::AccountInfo<'a>,
490        accounts: SetCollectionV2CpiAccounts<'a, 'b>,
491        args: SetCollectionV2InstructionArgs,
492    ) -> Self {
493        Self {
494            __program: program,
495            tree_config: accounts.tree_config,
496            payer: accounts.payer,
497            authority: accounts.authority,
498            new_collection_authority: accounts.new_collection_authority,
499            leaf_owner: accounts.leaf_owner,
500            leaf_delegate: accounts.leaf_delegate,
501            merkle_tree: accounts.merkle_tree,
502            core_collection: accounts.core_collection,
503            new_core_collection: accounts.new_core_collection,
504            mpl_core_cpi_signer: accounts.mpl_core_cpi_signer,
505            log_wrapper: accounts.log_wrapper,
506            compression_program: accounts.compression_program,
507            mpl_core_program: accounts.mpl_core_program,
508            system_program: accounts.system_program,
509            __args: args,
510        }
511    }
512    #[inline(always)]
513    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
514        self.invoke_signed_with_remaining_accounts(&[], &[])
515    }
516    #[inline(always)]
517    pub fn invoke_with_remaining_accounts(
518        &self,
519        remaining_accounts: &[(
520            &'b solana_program::account_info::AccountInfo<'a>,
521            bool,
522            bool,
523        )],
524    ) -> solana_program::entrypoint::ProgramResult {
525        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
526    }
527    #[inline(always)]
528    pub fn invoke_signed(
529        &self,
530        signers_seeds: &[&[&[u8]]],
531    ) -> solana_program::entrypoint::ProgramResult {
532        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
533    }
534    #[allow(clippy::clone_on_copy)]
535    #[allow(clippy::vec_init_then_push)]
536    pub fn invoke_signed_with_remaining_accounts(
537        &self,
538        signers_seeds: &[&[&[u8]]],
539        remaining_accounts: &[(
540            &'b solana_program::account_info::AccountInfo<'a>,
541            bool,
542            bool,
543        )],
544    ) -> solana_program::entrypoint::ProgramResult {
545        let mut accounts = Vec::with_capacity(14 + remaining_accounts.len());
546        accounts.push(solana_program::instruction::AccountMeta::new(
547            *self.tree_config.key,
548            false,
549        ));
550        accounts.push(solana_program::instruction::AccountMeta::new(
551            *self.payer.key,
552            true,
553        ));
554        if let Some(authority) = self.authority {
555            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
556                *authority.key,
557                true,
558            ));
559        } else {
560            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
561                crate::MPL_BUBBLEGUM_ID,
562                false,
563            ));
564        }
565        if let Some(new_collection_authority) = self.new_collection_authority {
566            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
567                *new_collection_authority.key,
568                true,
569            ));
570        } else {
571            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
572                crate::MPL_BUBBLEGUM_ID,
573                false,
574            ));
575        }
576        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
577            *self.leaf_owner.key,
578            false,
579        ));
580        if let Some(leaf_delegate) = self.leaf_delegate {
581            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
582                *leaf_delegate.key,
583                false,
584            ));
585        } else {
586            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
587                crate::MPL_BUBBLEGUM_ID,
588                false,
589            ));
590        }
591        accounts.push(solana_program::instruction::AccountMeta::new(
592            *self.merkle_tree.key,
593            false,
594        ));
595        if let Some(core_collection) = self.core_collection {
596            accounts.push(solana_program::instruction::AccountMeta::new(
597                *core_collection.key,
598                false,
599            ));
600        } else {
601            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
602                crate::MPL_BUBBLEGUM_ID,
603                false,
604            ));
605        }
606        if let Some(new_core_collection) = self.new_core_collection {
607            accounts.push(solana_program::instruction::AccountMeta::new(
608                *new_core_collection.key,
609                false,
610            ));
611        } else {
612            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
613                crate::MPL_BUBBLEGUM_ID,
614                false,
615            ));
616        }
617        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
618            *self.mpl_core_cpi_signer.key,
619            false,
620        ));
621        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
622            *self.log_wrapper.key,
623            false,
624        ));
625        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
626            *self.compression_program.key,
627            false,
628        ));
629        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
630            *self.mpl_core_program.key,
631            false,
632        ));
633        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
634            *self.system_program.key,
635            false,
636        ));
637        remaining_accounts.iter().for_each(|remaining_account| {
638            accounts.push(solana_program::instruction::AccountMeta {
639                pubkey: *remaining_account.0.key,
640                is_signer: remaining_account.1,
641                is_writable: remaining_account.2,
642            })
643        });
644        let mut data = SetCollectionV2InstructionData::new().try_to_vec().unwrap();
645        let mut args = self.__args.try_to_vec().unwrap();
646        data.append(&mut args);
647
648        let instruction = solana_program::instruction::Instruction {
649            program_id: crate::MPL_BUBBLEGUM_ID,
650            accounts,
651            data,
652        };
653        let mut account_infos = Vec::with_capacity(14 + 1 + remaining_accounts.len());
654        account_infos.push(self.__program.clone());
655        account_infos.push(self.tree_config.clone());
656        account_infos.push(self.payer.clone());
657        if let Some(authority) = self.authority {
658            account_infos.push(authority.clone());
659        }
660        if let Some(new_collection_authority) = self.new_collection_authority {
661            account_infos.push(new_collection_authority.clone());
662        }
663        account_infos.push(self.leaf_owner.clone());
664        if let Some(leaf_delegate) = self.leaf_delegate {
665            account_infos.push(leaf_delegate.clone());
666        }
667        account_infos.push(self.merkle_tree.clone());
668        if let Some(core_collection) = self.core_collection {
669            account_infos.push(core_collection.clone());
670        }
671        if let Some(new_core_collection) = self.new_core_collection {
672            account_infos.push(new_core_collection.clone());
673        }
674        account_infos.push(self.mpl_core_cpi_signer.clone());
675        account_infos.push(self.log_wrapper.clone());
676        account_infos.push(self.compression_program.clone());
677        account_infos.push(self.mpl_core_program.clone());
678        account_infos.push(self.system_program.clone());
679        remaining_accounts
680            .iter()
681            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
682
683        if signers_seeds.is_empty() {
684            solana_program::program::invoke(&instruction, &account_infos)
685        } else {
686            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
687        }
688    }
689}
690
691/// `set_collection_v2` CPI instruction builder.
692pub struct SetCollectionV2CpiBuilder<'a, 'b> {
693    instruction: Box<SetCollectionV2CpiBuilderInstruction<'a, 'b>>,
694}
695
696impl<'a, 'b> SetCollectionV2CpiBuilder<'a, 'b> {
697    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
698        let instruction = Box::new(SetCollectionV2CpiBuilderInstruction {
699            __program: program,
700            tree_config: None,
701            payer: None,
702            authority: None,
703            new_collection_authority: None,
704            leaf_owner: None,
705            leaf_delegate: None,
706            merkle_tree: None,
707            core_collection: None,
708            new_core_collection: None,
709            mpl_core_cpi_signer: None,
710            log_wrapper: None,
711            compression_program: None,
712            mpl_core_program: None,
713            system_program: None,
714            root: None,
715            asset_data_hash: None,
716            flags: None,
717            nonce: None,
718            index: None,
719            metadata: None,
720            __remaining_accounts: Vec::new(),
721        });
722        Self { instruction }
723    }
724    #[inline(always)]
725    pub fn tree_config(
726        &mut self,
727        tree_config: &'b solana_program::account_info::AccountInfo<'a>,
728    ) -> &mut Self {
729        self.instruction.tree_config = Some(tree_config);
730        self
731    }
732    #[inline(always)]
733    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
734        self.instruction.payer = Some(payer);
735        self
736    }
737    /// `[optional account]`
738    /// If item is not in a collection, then authority must be tree owner/delegate.  If item is
739    /// getting removed from a collection, then this must be an authority for the existing
740    /// collection.  Defaults to `payer`
741    #[inline(always)]
742    pub fn authority(
743        &mut self,
744        authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
745    ) -> &mut Self {
746        self.instruction.authority = authority;
747        self
748    }
749    /// `[optional account]`
750    /// If item is getting added to a new collection, then this must be the authority
751    /// for the new collection.  Defaults to `authority`
752    #[inline(always)]
753    pub fn new_collection_authority(
754        &mut self,
755        new_collection_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
756    ) -> &mut Self {
757        self.instruction.new_collection_authority = new_collection_authority;
758        self
759    }
760    #[inline(always)]
761    pub fn leaf_owner(
762        &mut self,
763        leaf_owner: &'b solana_program::account_info::AccountInfo<'a>,
764    ) -> &mut Self {
765        self.instruction.leaf_owner = Some(leaf_owner);
766        self
767    }
768    /// `[optional account]`
769    /// Defaults to `leaf_owner`
770    #[inline(always)]
771    pub fn leaf_delegate(
772        &mut self,
773        leaf_delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
774    ) -> &mut Self {
775        self.instruction.leaf_delegate = leaf_delegate;
776        self
777    }
778    #[inline(always)]
779    pub fn merkle_tree(
780        &mut self,
781        merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
782    ) -> &mut Self {
783        self.instruction.merkle_tree = Some(merkle_tree);
784        self
785    }
786    /// `[optional account]`
787    #[inline(always)]
788    pub fn core_collection(
789        &mut self,
790        core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
791    ) -> &mut Self {
792        self.instruction.core_collection = core_collection;
793        self
794    }
795    /// `[optional account]`
796    #[inline(always)]
797    pub fn new_core_collection(
798        &mut self,
799        new_core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
800    ) -> &mut Self {
801        self.instruction.new_core_collection = new_core_collection;
802        self
803    }
804    #[inline(always)]
805    pub fn mpl_core_cpi_signer(
806        &mut self,
807        mpl_core_cpi_signer: &'b solana_program::account_info::AccountInfo<'a>,
808    ) -> &mut Self {
809        self.instruction.mpl_core_cpi_signer = Some(mpl_core_cpi_signer);
810        self
811    }
812    #[inline(always)]
813    pub fn log_wrapper(
814        &mut self,
815        log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
816    ) -> &mut Self {
817        self.instruction.log_wrapper = Some(log_wrapper);
818        self
819    }
820    #[inline(always)]
821    pub fn compression_program(
822        &mut self,
823        compression_program: &'b solana_program::account_info::AccountInfo<'a>,
824    ) -> &mut Self {
825        self.instruction.compression_program = Some(compression_program);
826        self
827    }
828    #[inline(always)]
829    pub fn mpl_core_program(
830        &mut self,
831        mpl_core_program: &'b solana_program::account_info::AccountInfo<'a>,
832    ) -> &mut Self {
833        self.instruction.mpl_core_program = Some(mpl_core_program);
834        self
835    }
836    #[inline(always)]
837    pub fn system_program(
838        &mut self,
839        system_program: &'b solana_program::account_info::AccountInfo<'a>,
840    ) -> &mut Self {
841        self.instruction.system_program = Some(system_program);
842        self
843    }
844    #[inline(always)]
845    pub fn root(&mut self, root: [u8; 32]) -> &mut Self {
846        self.instruction.root = Some(root);
847        self
848    }
849    /// `[optional argument]`
850    #[inline(always)]
851    pub fn asset_data_hash(&mut self, asset_data_hash: [u8; 32]) -> &mut Self {
852        self.instruction.asset_data_hash = Some(asset_data_hash);
853        self
854    }
855    /// `[optional argument]`
856    #[inline(always)]
857    pub fn flags(&mut self, flags: u8) -> &mut Self {
858        self.instruction.flags = Some(flags);
859        self
860    }
861    #[inline(always)]
862    pub fn nonce(&mut self, nonce: u64) -> &mut Self {
863        self.instruction.nonce = Some(nonce);
864        self
865    }
866    #[inline(always)]
867    pub fn index(&mut self, index: u32) -> &mut Self {
868        self.instruction.index = Some(index);
869        self
870    }
871    #[inline(always)]
872    pub fn metadata(&mut self, metadata: MetadataArgsV2) -> &mut Self {
873        self.instruction.metadata = Some(metadata);
874        self
875    }
876    /// Add an additional account to the instruction.
877    #[inline(always)]
878    pub fn add_remaining_account(
879        &mut self,
880        account: &'b solana_program::account_info::AccountInfo<'a>,
881        is_writable: bool,
882        is_signer: bool,
883    ) -> &mut Self {
884        self.instruction
885            .__remaining_accounts
886            .push((account, is_writable, is_signer));
887        self
888    }
889    /// Add additional accounts to the instruction.
890    ///
891    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
892    /// and a `bool` indicating whether the account is a signer or not.
893    #[inline(always)]
894    pub fn add_remaining_accounts(
895        &mut self,
896        accounts: &[(
897            &'b solana_program::account_info::AccountInfo<'a>,
898            bool,
899            bool,
900        )],
901    ) -> &mut Self {
902        self.instruction
903            .__remaining_accounts
904            .extend_from_slice(accounts);
905        self
906    }
907    #[inline(always)]
908    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
909        self.invoke_signed(&[])
910    }
911    #[allow(clippy::clone_on_copy)]
912    #[allow(clippy::vec_init_then_push)]
913    pub fn invoke_signed(
914        &self,
915        signers_seeds: &[&[&[u8]]],
916    ) -> solana_program::entrypoint::ProgramResult {
917        let args = SetCollectionV2InstructionArgs {
918            root: self.instruction.root.clone().expect("root is not set"),
919            asset_data_hash: self.instruction.asset_data_hash.clone(),
920            flags: self.instruction.flags.clone(),
921            nonce: self.instruction.nonce.clone().expect("nonce is not set"),
922            index: self.instruction.index.clone().expect("index is not set"),
923            metadata: self
924                .instruction
925                .metadata
926                .clone()
927                .expect("metadata is not set"),
928        };
929        let instruction = SetCollectionV2Cpi {
930            __program: self.instruction.__program,
931
932            tree_config: self
933                .instruction
934                .tree_config
935                .expect("tree_config is not set"),
936
937            payer: self.instruction.payer.expect("payer is not set"),
938
939            authority: self.instruction.authority,
940
941            new_collection_authority: self.instruction.new_collection_authority,
942
943            leaf_owner: self.instruction.leaf_owner.expect("leaf_owner is not set"),
944
945            leaf_delegate: self.instruction.leaf_delegate,
946
947            merkle_tree: self
948                .instruction
949                .merkle_tree
950                .expect("merkle_tree is not set"),
951
952            core_collection: self.instruction.core_collection,
953
954            new_core_collection: self.instruction.new_core_collection,
955
956            mpl_core_cpi_signer: self
957                .instruction
958                .mpl_core_cpi_signer
959                .expect("mpl_core_cpi_signer is not set"),
960
961            log_wrapper: self
962                .instruction
963                .log_wrapper
964                .expect("log_wrapper is not set"),
965
966            compression_program: self
967                .instruction
968                .compression_program
969                .expect("compression_program is not set"),
970
971            mpl_core_program: self
972                .instruction
973                .mpl_core_program
974                .expect("mpl_core_program is not set"),
975
976            system_program: self
977                .instruction
978                .system_program
979                .expect("system_program is not set"),
980            __args: args,
981        };
982        instruction.invoke_signed_with_remaining_accounts(
983            signers_seeds,
984            &self.instruction.__remaining_accounts,
985        )
986    }
987}
988
989struct SetCollectionV2CpiBuilderInstruction<'a, 'b> {
990    __program: &'b solana_program::account_info::AccountInfo<'a>,
991    tree_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
992    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
993    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
994    new_collection_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
995    leaf_owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
996    leaf_delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
997    merkle_tree: Option<&'b solana_program::account_info::AccountInfo<'a>>,
998    core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
999    new_core_collection: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1000    mpl_core_cpi_signer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1001    log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1002    compression_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1003    mpl_core_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1004    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
1005    root: Option<[u8; 32]>,
1006    asset_data_hash: Option<[u8; 32]>,
1007    flags: Option<u8>,
1008    nonce: Option<u64>,
1009    index: Option<u32>,
1010    metadata: Option<MetadataArgsV2>,
1011    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
1012    __remaining_accounts: Vec<(
1013        &'b solana_program::account_info::AccountInfo<'a>,
1014        bool,
1015        bool,
1016    )>,
1017}