mpl_token_metadata/instruction/
collection.rs

1use 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::instruction::MetadataInstruction;
10
11///# Approve Collection Authority
12///
13///Approve another account to verify NFTs belonging to a collection, [verify_collection] on the collection NFT
14///
15///### Accounts:
16///   0. `[writable]` Collection Authority Record PDA
17///   1. `[signer]` Update Authority of Collection NFT
18///   2. `[signer]` Payer
19///   3. `[]` A Collection Authority
20///   4. `[]` Collection Metadata account
21///   5. `[]` Mint of Collection Metadata
22///   6. `[]` Token program
23///   7. `[]` System program
24///   8. Optional `[]` Rent info
25#[allow(clippy::too_many_arguments)]
26pub fn approve_collection_authority(
27    program_id: Pubkey,
28    collection_authority_record: Pubkey,
29    new_collection_authority: Pubkey,
30    update_authority: Pubkey,
31    payer: Pubkey,
32    metadata: Pubkey,
33    mint: Pubkey,
34) -> Instruction {
35    Instruction {
36        program_id,
37        accounts: vec![
38            AccountMeta::new(collection_authority_record, false),
39            AccountMeta::new_readonly(new_collection_authority, false),
40            AccountMeta::new(update_authority, true),
41            AccountMeta::new(payer, true),
42            AccountMeta::new_readonly(metadata, false),
43            AccountMeta::new_readonly(mint, false),
44            AccountMeta::new_readonly(solana_program::system_program::ID, false),
45        ],
46        data: MetadataInstruction::ApproveCollectionAuthority
47            .try_to_vec()
48            .unwrap(),
49    }
50}
51
52//# Revoke Collection Authority
53///
54///Revoke account to call [verify_collection] on this NFT
55///
56///### Accounts:
57///
58///   0. `[writable]` Collection Authority Record PDA
59///   1. `[writable]` The Authority that was delegated to
60///   2. `[signer]` The Original Update Authority or Delegated Authority
61///   2. `[]` Metadata account
62///   3. `[]` Mint of Metadata
63#[allow(clippy::too_many_arguments)]
64pub fn revoke_collection_authority(
65    program_id: Pubkey,
66    collection_authority_record: Pubkey,
67    delegate_authority: Pubkey,
68    revoke_authority: Pubkey,
69    metadata: Pubkey,
70    mint: Pubkey,
71) -> Instruction {
72    Instruction {
73        program_id,
74        accounts: vec![
75            AccountMeta::new(collection_authority_record, false),
76            AccountMeta::new_readonly(delegate_authority, false),
77            AccountMeta::new(revoke_authority, true),
78            AccountMeta::new_readonly(metadata, false),
79            AccountMeta::new_readonly(mint, false),
80        ],
81        data: MetadataInstruction::RevokeCollectionAuthority
82            .try_to_vec()
83            .unwrap(),
84    }
85}
86
87//# Set And Verify Collection
88///
89///Allows the same Update Authority (Or Delegated Authority) on an NFT and Collection to
90/// perform update_metadata_accounts_v2 with collection and [verify_collection] on the
91/// NFT/Collection in one instruction.
92///
93/// ### Accounts:
94///
95///   0. `[writable]` Metadata account
96///   1. `[signer]` Collection Update authority
97///   2. `[signer]` payer
98///   3. `[] Update Authority of Collection NFT and NFT
99///   3. `[]` Mint of the Collection
100///   4. `[]` Metadata Account of the Collection
101///   5. `[]` MasterEdition2 Account of the Collection Token
102#[allow(clippy::too_many_arguments)]
103pub fn set_and_verify_collection(
104    program_id: Pubkey,
105    metadata: Pubkey,
106    collection_authority: Pubkey,
107    payer: Pubkey,
108    update_authority: Pubkey,
109    collection_mint: Pubkey,
110    collection: Pubkey,
111    collection_master_edition_account: Pubkey,
112    collection_authority_record: Option<Pubkey>,
113) -> Instruction {
114    let mut accounts = vec![
115        AccountMeta::new(metadata, false),
116        AccountMeta::new(collection_authority, true),
117        AccountMeta::new(payer, true),
118        AccountMeta::new_readonly(update_authority, false),
119        AccountMeta::new_readonly(collection_mint, false),
120        AccountMeta::new_readonly(collection, false),
121        AccountMeta::new_readonly(collection_master_edition_account, false),
122    ];
123
124    if let Some(collection_authority_record) = collection_authority_record {
125        accounts.push(AccountMeta::new_readonly(
126            collection_authority_record,
127            false,
128        ));
129    }
130
131    Instruction {
132        program_id,
133        accounts,
134        data: MetadataInstruction::SetAndVerifyCollection
135            .try_to_vec()
136            .unwrap(),
137    }
138}
139
140//# Set And Verify Collection V2 -- Supports v1.3 Collection Details
141///
142///Allows the same Update Authority (Or Delegated Authority) on an NFT and Collection to perform update_metadata_accounts_v2 with collection and [verify_collection] on the NFT/Collection in one instruction
143///
144/// ### Accounts:
145///
146///   0. `[writable]` Metadata account
147///   1. `[signer]` Collection Update authority
148///   2. `[signer]` payer
149///   3. `[] Update Authority of Collection NFT and NFT
150///   3. `[]` Mint of the Collection
151///   4. `[writable]` Metadata Account of the Collection
152///   5. `[]` MasterEdition2 Account of the Collection Token
153#[allow(clippy::too_many_arguments)]
154pub fn set_and_verify_sized_collection_item(
155    program_id: Pubkey,
156    metadata: Pubkey,
157    collection_authority: Pubkey,
158    payer: Pubkey,
159    update_authority: Pubkey,
160    collection_mint: Pubkey,
161    collection: Pubkey,
162    collection_master_edition_account: Pubkey,
163    collection_authority_record: Option<Pubkey>,
164) -> Instruction {
165    let mut accounts = vec![
166        AccountMeta::new(metadata, false),
167        AccountMeta::new(collection_authority, true),
168        AccountMeta::new(payer, true),
169        AccountMeta::new_readonly(update_authority, false),
170        AccountMeta::new_readonly(collection_mint, false),
171        AccountMeta::new(collection, false),
172        AccountMeta::new_readonly(collection_master_edition_account, false),
173    ];
174
175    if let Some(collection_authority_record) = collection_authority_record {
176        accounts.push(AccountMeta::new_readonly(
177            collection_authority_record,
178            false,
179        ));
180    }
181
182    Instruction {
183        program_id,
184        accounts,
185        data: MetadataInstruction::SetAndVerifySizedCollectionItem
186            .try_to_vec()
187            .unwrap(),
188    }
189}
190
191#[repr(C)]
192#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
193#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
194pub struct SetCollectionSizeArgs {
195    pub size: u64,
196}
197
198pub fn set_collection_size(
199    program_id: Pubkey,
200    metadata_account: Pubkey,
201    update_authority: Pubkey,
202    mint: Pubkey,
203    collection_authority_record: Option<Pubkey>,
204    size: u64,
205) -> Instruction {
206    let mut accounts = vec![
207        AccountMeta::new(metadata_account, false),
208        AccountMeta::new_readonly(update_authority, true),
209        AccountMeta::new_readonly(mint, false),
210    ];
211
212    if let Some(record) = collection_authority_record {
213        accounts.push(AccountMeta::new_readonly(record, false));
214    }
215
216    Instruction {
217        program_id,
218        accounts,
219        data: MetadataInstruction::SetCollectionSize(SetCollectionSizeArgs { size })
220            .try_to_vec()
221            .unwrap(),
222    }
223}
224
225/// # Unverify Collection
226///
227/// If a MetadataAccount Has a Collection allow an Authority of the Collection to unverify an NFT in a Collection
228///
229/// ### Accounts:
230///
231///   0. `[writable]` Metadata account
232///   1. `[signer]` Collection Authority
233///   2. `[signer]` payer
234///   3. `[]` Mint of the Collection
235///   4. `[]` Metadata Account of the Collection
236///   5. `[]` MasterEdition2 Account of the Collection Token
237#[allow(clippy::too_many_arguments)]
238pub fn unverify_collection(
239    program_id: Pubkey,
240    metadata: Pubkey,
241    collection_authority: Pubkey,
242    collection_mint: Pubkey,
243    collection: Pubkey,
244    collection_master_edition_account: Pubkey,
245    collection_authority_record: Option<Pubkey>,
246) -> Instruction {
247    let mut accounts = vec![
248        AccountMeta::new(metadata, false),
249        AccountMeta::new(collection_authority, true),
250        AccountMeta::new_readonly(collection_mint, false),
251        AccountMeta::new_readonly(collection, false),
252        AccountMeta::new_readonly(collection_master_edition_account, false),
253    ];
254
255    if let Some(collection_authority_record) = collection_authority_record {
256        accounts.push(AccountMeta::new_readonly(
257            collection_authority_record,
258            false,
259        ));
260    }
261
262    Instruction {
263        program_id,
264        accounts,
265        data: MetadataInstruction::UnverifyCollection
266            .try_to_vec()
267            .unwrap(),
268    }
269}
270
271/// # Unverify Collection V2 -- Supports v1.3 Collection Details
272///
273/// If a MetadataAccount Has a Collection allow an Authority of the Collection to unverify an NFT in a Collection
274///
275/// ### Accounts:
276///
277///   0. `[writable]` Metadata account
278///   1. `[signer]` Collection Authority
279///   2. `[signer]` payer
280///   3. `[]` Mint of the Collection
281///   4. `[writable]` Metadata Account of the Collection
282///   5. `[]` MasterEdition2 Account of the Collection Token
283#[allow(clippy::too_many_arguments)]
284pub fn unverify_sized_collection_item(
285    program_id: Pubkey,
286    metadata: Pubkey,
287    collection_authority: Pubkey,
288    payer: Pubkey,
289    collection_mint: Pubkey,
290    collection: Pubkey,
291    collection_master_edition_account: Pubkey,
292    collection_authority_record: Option<Pubkey>,
293) -> Instruction {
294    let mut accounts = vec![
295        AccountMeta::new(metadata, false),
296        AccountMeta::new_readonly(collection_authority, true),
297        AccountMeta::new(payer, true),
298        AccountMeta::new_readonly(collection_mint, false),
299        AccountMeta::new(collection, false),
300        AccountMeta::new_readonly(collection_master_edition_account, false),
301    ];
302
303    if let Some(collection_authority_record) = collection_authority_record {
304        accounts.push(AccountMeta::new_readonly(
305            collection_authority_record,
306            false,
307        ));
308    }
309
310    Instruction {
311        program_id,
312        accounts,
313        data: MetadataInstruction::UnverifySizedCollectionItem
314            .try_to_vec()
315            .unwrap(),
316    }
317}
318
319/// # Verify Collection
320///
321/// If a MetadataAccount Has a Collection allow the UpdateAuthority of the Collection to Verify the NFT Belongs in the Collection
322///
323/// ### Accounts:
324///
325///   0. `[writable]` Metadata account
326///   1. `[signer]` Collection Update authority
327///   2. `[signer]` payer
328///   3. `[]` Mint of the Collection
329///   4. `[]` Metadata Account of the Collection
330///   5. `[]` MasterEdition2 Account of the Collection Token
331#[allow(clippy::too_many_arguments)]
332pub fn verify_collection(
333    program_id: Pubkey,
334    metadata: Pubkey,
335    collection_authority: Pubkey,
336    payer: Pubkey,
337    collection_mint: Pubkey,
338    collection: Pubkey,
339    collection_master_edition_account: Pubkey,
340    collection_authority_record: Option<Pubkey>,
341) -> Instruction {
342    let mut accounts = vec![
343        AccountMeta::new(metadata, false),
344        AccountMeta::new(collection_authority, true),
345        AccountMeta::new(payer, true),
346        AccountMeta::new_readonly(collection_mint, false),
347        AccountMeta::new_readonly(collection, false),
348        AccountMeta::new_readonly(collection_master_edition_account, false),
349    ];
350
351    if let Some(collection_authority_record) = collection_authority_record {
352        accounts.push(AccountMeta::new_readonly(
353            collection_authority_record,
354            false,
355        ));
356    }
357
358    Instruction {
359        program_id,
360        accounts,
361        data: MetadataInstruction::VerifyCollection.try_to_vec().unwrap(),
362    }
363}
364
365/// # Verify Collection V2 -- Supports v1.3 Collection Details
366///
367/// If a MetadataAccount Has a Collection allow the UpdateAuthority of the Collection to Verify the NFT Belongs in the Collection
368///
369/// ### Accounts:
370///
371///   0. `[writable]` Metadata account
372///   1. `[signer]` Collection Update authority
373///   2. `[signer]` payer
374///   3. `[]` Mint of the Collection
375///   4. `[writable]` Metadata Account of the Collection
376///   5. `[]` MasterEdition2 Account of the Collection Token
377#[allow(clippy::too_many_arguments)]
378pub fn verify_sized_collection_item(
379    program_id: Pubkey,
380    metadata: Pubkey,
381    collection_authority: Pubkey,
382    payer: Pubkey,
383    collection_mint: Pubkey,
384    collection: Pubkey,
385    collection_master_edition_account: Pubkey,
386    collection_authority_record: Option<Pubkey>,
387) -> Instruction {
388    let mut accounts = vec![
389        AccountMeta::new(metadata, false),
390        AccountMeta::new_readonly(collection_authority, true),
391        AccountMeta::new(payer, true),
392        AccountMeta::new_readonly(collection_mint, false),
393        AccountMeta::new(collection, false),
394        AccountMeta::new_readonly(collection_master_edition_account, false),
395    ];
396
397    if let Some(record) = collection_authority_record {
398        accounts.push(AccountMeta::new_readonly(record, false));
399    }
400
401    Instruction {
402        program_id,
403        accounts,
404        data: MetadataInstruction::VerifySizedCollectionItem
405            .try_to_vec()
406            .unwrap(),
407    }
408}