mpl_token_metadata/instruction/
edition.rs1use borsh::{BorshDeserialize, BorshSerialize};
2#[cfg(feature = "serde-feature")]
3use serde::{Deserialize, Serialize};
4use solana_program::{
5 instruction::{AccountMeta, Instruction},
6 pubkey::Pubkey,
7};
8
9use crate::{
10 instruction::MetadataInstruction,
11 state::{EDITION, EDITION_MARKER_BIT_SIZE, PREFIX},
12};
13
14#[allow(clippy::too_many_arguments)]
16pub fn convert_master_edition_v1_to_v2(
17 program_id: Pubkey,
18 master_edition: Pubkey,
19 one_time_auth: Pubkey,
20 printing_mint: Pubkey,
21) -> Instruction {
22 Instruction {
23 program_id,
24 accounts: vec![
25 AccountMeta::new(master_edition, false),
26 AccountMeta::new(one_time_auth, false),
27 AccountMeta::new(printing_mint, false),
28 ],
29 data: MetadataInstruction::ConvertMasterEditionV1ToV2
30 .try_to_vec()
31 .unwrap(),
32 }
33}
34
35#[repr(C)]
36#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
37#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
38pub struct CreateMasterEditionArgs {
39 pub max_supply: Option<u64>,
41}
42
43#[allow(clippy::too_many_arguments)]
45pub fn create_master_edition_v3(
46 program_id: Pubkey,
47 edition: Pubkey,
48 mint: Pubkey,
49 update_authority: Pubkey,
50 mint_authority: Pubkey,
51 metadata: Pubkey,
52 payer: Pubkey,
53 max_supply: Option<u64>,
54) -> Instruction {
55 let accounts = vec![
56 AccountMeta::new(edition, false),
57 AccountMeta::new(mint, false),
58 AccountMeta::new_readonly(update_authority, true),
59 AccountMeta::new_readonly(mint_authority, true),
60 AccountMeta::new(payer, true),
61 AccountMeta::new(metadata, false),
62 AccountMeta::new_readonly(spl_token::ID, false),
63 AccountMeta::new_readonly(solana_program::system_program::ID, false),
64 ];
65
66 Instruction {
67 program_id,
68 accounts,
69 data: MetadataInstruction::CreateMasterEditionV3(CreateMasterEditionArgs { max_supply })
70 .try_to_vec()
71 .unwrap(),
72 }
73}
74
75#[repr(C)]
76#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
77#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
78pub struct MintNewEditionFromMasterEditionViaTokenArgs {
79 pub edition: u64,
80}
81
82#[allow(clippy::too_many_arguments)]
84pub fn mint_new_edition_from_master_edition_via_token(
85 program_id: Pubkey,
86 new_metadata: Pubkey,
87 new_edition: Pubkey,
88 master_edition: Pubkey,
89 new_mint: Pubkey,
90 new_mint_authority: Pubkey,
91 payer: Pubkey,
92 token_account_owner: Pubkey,
93 token_account: Pubkey,
94 new_metadata_update_authority: Pubkey,
95 metadata: Pubkey,
96 metadata_mint: Pubkey,
97 edition: u64,
98) -> Instruction {
99 let edition_number = edition.checked_div(EDITION_MARKER_BIT_SIZE).unwrap();
100 let as_string = edition_number.to_string();
101 let (edition_mark_pda, _) = Pubkey::find_program_address(
102 &[
103 PREFIX.as_bytes(),
104 program_id.as_ref(),
105 metadata_mint.as_ref(),
106 EDITION.as_bytes(),
107 as_string.as_bytes(),
108 ],
109 &program_id,
110 );
111
112 let accounts = vec![
113 AccountMeta::new(new_metadata, false),
114 AccountMeta::new(new_edition, false),
115 AccountMeta::new(master_edition, false),
116 AccountMeta::new(new_mint, false),
117 AccountMeta::new(edition_mark_pda, false),
118 AccountMeta::new_readonly(new_mint_authority, true),
119 AccountMeta::new(payer, true),
120 AccountMeta::new_readonly(token_account_owner, true),
121 AccountMeta::new_readonly(token_account, false),
122 AccountMeta::new_readonly(new_metadata_update_authority, false),
123 AccountMeta::new_readonly(metadata, false),
124 AccountMeta::new_readonly(spl_token::ID, false),
125 AccountMeta::new_readonly(solana_program::system_program::ID, false),
126 ];
127
128 Instruction {
129 program_id,
130 accounts,
131 data: MetadataInstruction::MintNewEditionFromMasterEditionViaToken(
132 MintNewEditionFromMasterEditionViaTokenArgs { edition },
133 )
134 .try_to_vec()
135 .unwrap(),
136 }
137}