1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct CreateMasterEditionV3 {
13 pub edition: solana_program::pubkey::Pubkey,
15 pub mint: solana_program::pubkey::Pubkey,
17 pub update_authority: solana_program::pubkey::Pubkey,
19 pub mint_authority: solana_program::pubkey::Pubkey,
21 pub payer: solana_program::pubkey::Pubkey,
23 pub metadata: solana_program::pubkey::Pubkey,
25 pub token_program: solana_program::pubkey::Pubkey,
27 pub system_program: solana_program::pubkey::Pubkey,
29 pub rent: Option<solana_program::pubkey::Pubkey>,
31}
32
33impl CreateMasterEditionV3 {
34 pub fn instruction(
35 &self,
36 args: CreateMasterEditionV3InstructionArgs,
37 ) -> solana_program::instruction::Instruction {
38 self.instruction_with_remaining_accounts(args, &[])
39 }
40 #[allow(clippy::vec_init_then_push)]
41 pub fn instruction_with_remaining_accounts(
42 &self,
43 args: CreateMasterEditionV3InstructionArgs,
44 remaining_accounts: &[solana_program::instruction::AccountMeta],
45 ) -> solana_program::instruction::Instruction {
46 let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
47 accounts.push(solana_program::instruction::AccountMeta::new(
48 self.edition,
49 false,
50 ));
51 accounts.push(solana_program::instruction::AccountMeta::new(
52 self.mint, false,
53 ));
54 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
55 self.update_authority,
56 true,
57 ));
58 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
59 self.mint_authority,
60 true,
61 ));
62 accounts.push(solana_program::instruction::AccountMeta::new(
63 self.payer, true,
64 ));
65 accounts.push(solana_program::instruction::AccountMeta::new(
66 self.metadata,
67 false,
68 ));
69 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
70 self.token_program,
71 false,
72 ));
73 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
74 self.system_program,
75 false,
76 ));
77 if let Some(rent) = self.rent {
78 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
79 rent, false,
80 ));
81 }
82 accounts.extend_from_slice(remaining_accounts);
83 let mut data = CreateMasterEditionV3InstructionData::new()
84 .try_to_vec()
85 .unwrap();
86 let mut args = args.try_to_vec().unwrap();
87 data.append(&mut args);
88
89 solana_program::instruction::Instruction {
90 program_id: crate::MPL_TOKEN_METADATA_ID,
91 accounts,
92 data,
93 }
94 }
95}
96
97#[derive(BorshDeserialize, BorshSerialize)]
98struct CreateMasterEditionV3InstructionData {
99 discriminator: u8,
100}
101
102impl CreateMasterEditionV3InstructionData {
103 fn new() -> Self {
104 Self { discriminator: 17 }
105 }
106}
107
108#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
109#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
110pub struct CreateMasterEditionV3InstructionArgs {
111 pub max_supply: Option<u64>,
112}
113
114#[derive(Default)]
128pub struct CreateMasterEditionV3Builder {
129 edition: Option<solana_program::pubkey::Pubkey>,
130 mint: Option<solana_program::pubkey::Pubkey>,
131 update_authority: Option<solana_program::pubkey::Pubkey>,
132 mint_authority: Option<solana_program::pubkey::Pubkey>,
133 payer: Option<solana_program::pubkey::Pubkey>,
134 metadata: Option<solana_program::pubkey::Pubkey>,
135 token_program: Option<solana_program::pubkey::Pubkey>,
136 system_program: Option<solana_program::pubkey::Pubkey>,
137 rent: Option<solana_program::pubkey::Pubkey>,
138 max_supply: Option<u64>,
139 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
140}
141
142impl CreateMasterEditionV3Builder {
143 pub fn new() -> Self {
144 Self::default()
145 }
146 #[inline(always)]
148 pub fn edition(&mut self, edition: solana_program::pubkey::Pubkey) -> &mut Self {
149 self.edition = Some(edition);
150 self
151 }
152 #[inline(always)]
154 pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
155 self.mint = Some(mint);
156 self
157 }
158 #[inline(always)]
160 pub fn update_authority(
161 &mut self,
162 update_authority: solana_program::pubkey::Pubkey,
163 ) -> &mut Self {
164 self.update_authority = Some(update_authority);
165 self
166 }
167 #[inline(always)]
169 pub fn mint_authority(&mut self, mint_authority: solana_program::pubkey::Pubkey) -> &mut Self {
170 self.mint_authority = Some(mint_authority);
171 self
172 }
173 #[inline(always)]
175 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
176 self.payer = Some(payer);
177 self
178 }
179 #[inline(always)]
181 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
182 self.metadata = Some(metadata);
183 self
184 }
185 #[inline(always)]
188 pub fn token_program(&mut self, token_program: solana_program::pubkey::Pubkey) -> &mut Self {
189 self.token_program = Some(token_program);
190 self
191 }
192 #[inline(always)]
195 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
196 self.system_program = Some(system_program);
197 self
198 }
199 #[inline(always)]
202 pub fn rent(&mut self, rent: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
203 self.rent = rent;
204 self
205 }
206 #[inline(always)]
208 pub fn max_supply(&mut self, max_supply: u64) -> &mut Self {
209 self.max_supply = Some(max_supply);
210 self
211 }
212 #[inline(always)]
214 pub fn add_remaining_account(
215 &mut self,
216 account: solana_program::instruction::AccountMeta,
217 ) -> &mut Self {
218 self.__remaining_accounts.push(account);
219 self
220 }
221 #[inline(always)]
223 pub fn add_remaining_accounts(
224 &mut self,
225 accounts: &[solana_program::instruction::AccountMeta],
226 ) -> &mut Self {
227 self.__remaining_accounts.extend_from_slice(accounts);
228 self
229 }
230 #[allow(clippy::clone_on_copy)]
231 pub fn instruction(&self) -> solana_program::instruction::Instruction {
232 let accounts = CreateMasterEditionV3 {
233 edition: self.edition.expect("edition is not set"),
234 mint: self.mint.expect("mint is not set"),
235 update_authority: self.update_authority.expect("update_authority is not set"),
236 mint_authority: self.mint_authority.expect("mint_authority is not set"),
237 payer: self.payer.expect("payer is not set"),
238 metadata: self.metadata.expect("metadata is not set"),
239 token_program: self.token_program.unwrap_or(solana_program::pubkey!(
240 "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
241 )),
242 system_program: self
243 .system_program
244 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
245 rent: self.rent,
246 };
247 let args = CreateMasterEditionV3InstructionArgs {
248 max_supply: self.max_supply.clone(),
249 };
250
251 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
252 }
253}
254
255pub struct CreateMasterEditionV3CpiAccounts<'a, 'b> {
257 pub edition: &'b solana_program::account_info::AccountInfo<'a>,
259 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
261 pub update_authority: &'b solana_program::account_info::AccountInfo<'a>,
263 pub mint_authority: &'b solana_program::account_info::AccountInfo<'a>,
265 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
267 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
269 pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
271 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
273 pub rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
275}
276
277pub struct CreateMasterEditionV3Cpi<'a, 'b> {
279 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
281 pub edition: &'b solana_program::account_info::AccountInfo<'a>,
283 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
285 pub update_authority: &'b solana_program::account_info::AccountInfo<'a>,
287 pub mint_authority: &'b solana_program::account_info::AccountInfo<'a>,
289 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
291 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
293 pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
295 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
297 pub rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
299 pub __args: CreateMasterEditionV3InstructionArgs,
301}
302
303impl<'a, 'b> CreateMasterEditionV3Cpi<'a, 'b> {
304 pub fn new(
305 program: &'b solana_program::account_info::AccountInfo<'a>,
306 accounts: CreateMasterEditionV3CpiAccounts<'a, 'b>,
307 args: CreateMasterEditionV3InstructionArgs,
308 ) -> Self {
309 Self {
310 __program: program,
311 edition: accounts.edition,
312 mint: accounts.mint,
313 update_authority: accounts.update_authority,
314 mint_authority: accounts.mint_authority,
315 payer: accounts.payer,
316 metadata: accounts.metadata,
317 token_program: accounts.token_program,
318 system_program: accounts.system_program,
319 rent: accounts.rent,
320 __args: args,
321 }
322 }
323 #[inline(always)]
324 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
325 self.invoke_signed_with_remaining_accounts(&[], &[])
326 }
327 #[inline(always)]
328 pub fn invoke_with_remaining_accounts(
329 &self,
330 remaining_accounts: &[(
331 &'b solana_program::account_info::AccountInfo<'a>,
332 bool,
333 bool,
334 )],
335 ) -> solana_program::entrypoint::ProgramResult {
336 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
337 }
338 #[inline(always)]
339 pub fn invoke_signed(
340 &self,
341 signers_seeds: &[&[&[u8]]],
342 ) -> solana_program::entrypoint::ProgramResult {
343 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
344 }
345 #[allow(clippy::clone_on_copy)]
346 #[allow(clippy::vec_init_then_push)]
347 pub fn invoke_signed_with_remaining_accounts(
348 &self,
349 signers_seeds: &[&[&[u8]]],
350 remaining_accounts: &[(
351 &'b solana_program::account_info::AccountInfo<'a>,
352 bool,
353 bool,
354 )],
355 ) -> solana_program::entrypoint::ProgramResult {
356 let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
357 accounts.push(solana_program::instruction::AccountMeta::new(
358 *self.edition.key,
359 false,
360 ));
361 accounts.push(solana_program::instruction::AccountMeta::new(
362 *self.mint.key,
363 false,
364 ));
365 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
366 *self.update_authority.key,
367 true,
368 ));
369 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
370 *self.mint_authority.key,
371 true,
372 ));
373 accounts.push(solana_program::instruction::AccountMeta::new(
374 *self.payer.key,
375 true,
376 ));
377 accounts.push(solana_program::instruction::AccountMeta::new(
378 *self.metadata.key,
379 false,
380 ));
381 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
382 *self.token_program.key,
383 false,
384 ));
385 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
386 *self.system_program.key,
387 false,
388 ));
389 if let Some(rent) = self.rent {
390 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
391 *rent.key, false,
392 ));
393 }
394 remaining_accounts.iter().for_each(|remaining_account| {
395 accounts.push(solana_program::instruction::AccountMeta {
396 pubkey: *remaining_account.0.key,
397 is_signer: remaining_account.1,
398 is_writable: remaining_account.2,
399 })
400 });
401 let mut data = CreateMasterEditionV3InstructionData::new()
402 .try_to_vec()
403 .unwrap();
404 let mut args = self.__args.try_to_vec().unwrap();
405 data.append(&mut args);
406
407 let instruction = solana_program::instruction::Instruction {
408 program_id: crate::MPL_TOKEN_METADATA_ID,
409 accounts,
410 data,
411 };
412 let mut account_infos = Vec::with_capacity(9 + 1 + remaining_accounts.len());
413 account_infos.push(self.__program.clone());
414 account_infos.push(self.edition.clone());
415 account_infos.push(self.mint.clone());
416 account_infos.push(self.update_authority.clone());
417 account_infos.push(self.mint_authority.clone());
418 account_infos.push(self.payer.clone());
419 account_infos.push(self.metadata.clone());
420 account_infos.push(self.token_program.clone());
421 account_infos.push(self.system_program.clone());
422 if let Some(rent) = self.rent {
423 account_infos.push(rent.clone());
424 }
425 remaining_accounts
426 .iter()
427 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
428
429 if signers_seeds.is_empty() {
430 solana_program::program::invoke(&instruction, &account_infos)
431 } else {
432 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
433 }
434 }
435}
436
437pub struct CreateMasterEditionV3CpiBuilder<'a, 'b> {
451 instruction: Box<CreateMasterEditionV3CpiBuilderInstruction<'a, 'b>>,
452}
453
454impl<'a, 'b> CreateMasterEditionV3CpiBuilder<'a, 'b> {
455 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
456 let instruction = Box::new(CreateMasterEditionV3CpiBuilderInstruction {
457 __program: program,
458 edition: None,
459 mint: None,
460 update_authority: None,
461 mint_authority: None,
462 payer: None,
463 metadata: None,
464 token_program: None,
465 system_program: None,
466 rent: None,
467 max_supply: None,
468 __remaining_accounts: Vec::new(),
469 });
470 Self { instruction }
471 }
472 #[inline(always)]
474 pub fn edition(
475 &mut self,
476 edition: &'b solana_program::account_info::AccountInfo<'a>,
477 ) -> &mut Self {
478 self.instruction.edition = Some(edition);
479 self
480 }
481 #[inline(always)]
483 pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
484 self.instruction.mint = Some(mint);
485 self
486 }
487 #[inline(always)]
489 pub fn update_authority(
490 &mut self,
491 update_authority: &'b solana_program::account_info::AccountInfo<'a>,
492 ) -> &mut Self {
493 self.instruction.update_authority = Some(update_authority);
494 self
495 }
496 #[inline(always)]
498 pub fn mint_authority(
499 &mut self,
500 mint_authority: &'b solana_program::account_info::AccountInfo<'a>,
501 ) -> &mut Self {
502 self.instruction.mint_authority = Some(mint_authority);
503 self
504 }
505 #[inline(always)]
507 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
508 self.instruction.payer = Some(payer);
509 self
510 }
511 #[inline(always)]
513 pub fn metadata(
514 &mut self,
515 metadata: &'b solana_program::account_info::AccountInfo<'a>,
516 ) -> &mut Self {
517 self.instruction.metadata = Some(metadata);
518 self
519 }
520 #[inline(always)]
522 pub fn token_program(
523 &mut self,
524 token_program: &'b solana_program::account_info::AccountInfo<'a>,
525 ) -> &mut Self {
526 self.instruction.token_program = Some(token_program);
527 self
528 }
529 #[inline(always)]
531 pub fn system_program(
532 &mut self,
533 system_program: &'b solana_program::account_info::AccountInfo<'a>,
534 ) -> &mut Self {
535 self.instruction.system_program = Some(system_program);
536 self
537 }
538 #[inline(always)]
541 pub fn rent(
542 &mut self,
543 rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
544 ) -> &mut Self {
545 self.instruction.rent = rent;
546 self
547 }
548 #[inline(always)]
550 pub fn max_supply(&mut self, max_supply: u64) -> &mut Self {
551 self.instruction.max_supply = Some(max_supply);
552 self
553 }
554 #[inline(always)]
556 pub fn add_remaining_account(
557 &mut self,
558 account: &'b solana_program::account_info::AccountInfo<'a>,
559 is_writable: bool,
560 is_signer: bool,
561 ) -> &mut Self {
562 self.instruction
563 .__remaining_accounts
564 .push((account, is_writable, is_signer));
565 self
566 }
567 #[inline(always)]
572 pub fn add_remaining_accounts(
573 &mut self,
574 accounts: &[(
575 &'b solana_program::account_info::AccountInfo<'a>,
576 bool,
577 bool,
578 )],
579 ) -> &mut Self {
580 self.instruction
581 .__remaining_accounts
582 .extend_from_slice(accounts);
583 self
584 }
585 #[inline(always)]
586 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
587 self.invoke_signed(&[])
588 }
589 #[allow(clippy::clone_on_copy)]
590 #[allow(clippy::vec_init_then_push)]
591 pub fn invoke_signed(
592 &self,
593 signers_seeds: &[&[&[u8]]],
594 ) -> solana_program::entrypoint::ProgramResult {
595 let args = CreateMasterEditionV3InstructionArgs {
596 max_supply: self.instruction.max_supply.clone(),
597 };
598 let instruction = CreateMasterEditionV3Cpi {
599 __program: self.instruction.__program,
600
601 edition: self.instruction.edition.expect("edition is not set"),
602
603 mint: self.instruction.mint.expect("mint is not set"),
604
605 update_authority: self
606 .instruction
607 .update_authority
608 .expect("update_authority is not set"),
609
610 mint_authority: self
611 .instruction
612 .mint_authority
613 .expect("mint_authority is not set"),
614
615 payer: self.instruction.payer.expect("payer is not set"),
616
617 metadata: self.instruction.metadata.expect("metadata is not set"),
618
619 token_program: self
620 .instruction
621 .token_program
622 .expect("token_program is not set"),
623
624 system_program: self
625 .instruction
626 .system_program
627 .expect("system_program is not set"),
628
629 rent: self.instruction.rent,
630 __args: args,
631 };
632 instruction.invoke_signed_with_remaining_accounts(
633 signers_seeds,
634 &self.instruction.__remaining_accounts,
635 )
636 }
637}
638
639struct CreateMasterEditionV3CpiBuilderInstruction<'a, 'b> {
640 __program: &'b solana_program::account_info::AccountInfo<'a>,
641 edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
642 mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
643 update_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
644 mint_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
645 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
646 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
647 token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
648 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
649 rent: Option<&'b solana_program::account_info::AccountInfo<'a>>,
650 max_supply: Option<u64>,
651 __remaining_accounts: Vec<(
653 &'b solana_program::account_info::AccountInfo<'a>,
654 bool,
655 bool,
656 )>,
657}