|
1 | 1 | import {
|
| 2 | + VerificationArgs, |
2 | 3 | createUnverifyCollectionInstruction,
|
| 4 | + createUnverifyInstruction, |
3 | 5 | createUnverifySizedCollectionItemInstruction,
|
4 | 6 | } from '@metaplex-foundation/mpl-token-metadata';
|
5 |
| -import { PublicKey } from '@solana/web3.js'; |
| 7 | +import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from '@solana/web3.js'; |
6 | 8 | import { SendAndConfirmTransactionResponse } from '../../rpcModule';
|
7 | 9 | import { Metaplex } from '@/Metaplex';
|
8 | 10 | import {
|
@@ -74,12 +76,28 @@ export type UnverifyNftCollectionInput = {
|
74 | 76 |
|
75 | 77 | /**
|
76 | 78 | * Whether or not the provided `collectionAuthority` is a delegated
|
77 |
| - * collection authority, i.e. it was approved by the update authority |
78 |
| - * using `metaplex.nfts().approveCollectionAuthority()`. |
| 79 | + * collection authority, i.e. it was approved by the update authority. |
| 80 | + * |
| 81 | + * - `false` means the collection authority is the update authority of the collection. |
| 82 | + * - `legacyDelegate` means the collection authority is a delegate that was approved |
| 83 | + * using the legacy `metaplex.nfts().approveCollectionAuthority()` operation. |
| 84 | + * - `metadataDelegate` means the collection authority is a delegate that was approved |
| 85 | + * using the new `metaplex.nfts().delegate()` operation. |
| 86 | + * - `true` is equivalent to `legacyDelegate` for backwards compatibility. |
79 | 87 | *
|
80 | 88 | * @defaultValue `false`
|
81 | 89 | */
|
82 |
| - isDelegated?: boolean; |
| 90 | + isDelegated?: boolean | 'legacyDelegate' | 'metadataDelegate'; |
| 91 | + |
| 92 | + /** |
| 93 | + * The update authority of the Collection NFT. |
| 94 | + * |
| 95 | + * This is used to compute the metadata delegate record when |
| 96 | + * `isDelegated` is equal to `"metadataDelegate"`. |
| 97 | + * |
| 98 | + * @defaultValue `metaplex.identity().publicKey` |
| 99 | + */ |
| 100 | + collectionUpdateAuthority?: PublicKey; |
83 | 101 | };
|
84 | 102 |
|
85 | 103 | /**
|
@@ -151,55 +169,92 @@ export const unverifyNftCollectionBuilder = (
|
151 | 169 | isSizedCollection = true,
|
152 | 170 | isDelegated = false,
|
153 | 171 | collectionAuthority = metaplex.identity(),
|
| 172 | + collectionUpdateAuthority = metaplex.identity().publicKey, |
154 | 173 | } = params;
|
155 | 174 |
|
156 | 175 | // Programs.
|
| 176 | + const systemProgram = metaplex.programs().getSystem(programs); |
157 | 177 | const tokenMetadataProgram = metaplex.programs().getTokenMetadata(programs);
|
158 | 178 |
|
159 |
| - const accounts = { |
160 |
| - metadata: metaplex.nfts().pdas().metadata({ |
161 |
| - mint: mintAddress, |
162 |
| - programs, |
163 |
| - }), |
164 |
| - collectionAuthority: collectionAuthority.publicKey, |
165 |
| - payer: payer.publicKey, |
166 |
| - collectionMint: collectionMintAddress, |
167 |
| - collection: metaplex.nfts().pdas().metadata({ |
168 |
| - mint: collectionMintAddress, |
169 |
| - programs, |
170 |
| - }), |
171 |
| - collectionMasterEditionAccount: metaplex.nfts().pdas().masterEdition({ |
172 |
| - mint: collectionMintAddress, |
173 |
| - programs, |
174 |
| - }), |
175 |
| - collectionAuthorityRecord: isDelegated |
176 |
| - ? metaplex.nfts().pdas().collectionAuthorityRecord({ |
| 179 | + // Accounts. |
| 180 | + const metadata = metaplex.nfts().pdas().metadata({ |
| 181 | + mint: mintAddress, |
| 182 | + programs, |
| 183 | + }); |
| 184 | + const collectionMetadata = metaplex.nfts().pdas().metadata({ |
| 185 | + mint: collectionMintAddress, |
| 186 | + programs, |
| 187 | + }); |
| 188 | + const collectionEdition = metaplex.nfts().pdas().masterEdition({ |
| 189 | + mint: collectionMintAddress, |
| 190 | + programs, |
| 191 | + }); |
| 192 | + |
| 193 | + if (isDelegated === 'legacyDelegate' || isDelegated === true) { |
| 194 | + const accounts = { |
| 195 | + metadata, |
| 196 | + collectionAuthority: collectionAuthority.publicKey, |
| 197 | + payer: payer.publicKey, |
| 198 | + collectionMint: collectionMintAddress, |
| 199 | + collection: collectionMetadata, |
| 200 | + collectionMasterEditionAccount: collectionEdition, |
| 201 | + collectionAuthorityRecord: metaplex |
| 202 | + .nfts() |
| 203 | + .pdas() |
| 204 | + .collectionAuthorityRecord({ |
177 | 205 | mint: collectionMintAddress,
|
178 | 206 | collectionAuthority: collectionAuthority.publicKey,
|
179 | 207 | programs,
|
180 |
| - }) |
181 |
| - : undefined, |
182 |
| - }; |
| 208 | + }), |
| 209 | + }; |
183 | 210 |
|
184 |
| - const instruction = isSizedCollection |
185 |
| - ? createUnverifySizedCollectionItemInstruction( |
186 |
| - accounts, |
187 |
| - tokenMetadataProgram.address |
188 |
| - ) |
189 |
| - : createUnverifyCollectionInstruction( |
190 |
| - accounts, |
191 |
| - tokenMetadataProgram.address |
192 |
| - ); |
| 211 | + const instruction = isSizedCollection |
| 212 | + ? createUnverifySizedCollectionItemInstruction( |
| 213 | + accounts, |
| 214 | + tokenMetadataProgram.address |
| 215 | + ) |
| 216 | + : createUnverifyCollectionInstruction( |
| 217 | + accounts, |
| 218 | + tokenMetadataProgram.address |
| 219 | + ); |
193 | 220 |
|
194 |
| - return ( |
195 |
| - TransactionBuilder.make() |
| 221 | + return TransactionBuilder.make() |
196 | 222 | .setFeePayer(payer)
|
197 |
| - |
198 |
| - // Unverify the collection. |
199 | 223 | .add({
|
200 | 224 | instruction,
|
201 | 225 | signers: [payer, collectionAuthority],
|
202 | 226 | key: params.instructionKey ?? 'unverifyCollection',
|
203 |
| - }) |
204 |
| - ); |
| 227 | + }); |
| 228 | + } |
| 229 | + |
| 230 | + const delegateRecord = |
| 231 | + isDelegated === 'metadataDelegate' |
| 232 | + ? metaplex.nfts().pdas().metadataDelegateRecord({ |
| 233 | + mint: collectionMintAddress, |
| 234 | + type: 'CollectionV1', |
| 235 | + updateAuthority: collectionUpdateAuthority, |
| 236 | + delegate: collectionAuthority.publicKey, |
| 237 | + programs, |
| 238 | + }) |
| 239 | + : undefined; |
| 240 | + |
| 241 | + return TransactionBuilder.make() |
| 242 | + .setFeePayer(payer) |
| 243 | + .add({ |
| 244 | + instruction: createUnverifyInstruction( |
| 245 | + { |
| 246 | + authority: collectionAuthority.publicKey, |
| 247 | + delegateRecord, |
| 248 | + metadata, |
| 249 | + collectionMint: collectionMintAddress, |
| 250 | + collectionMetadata, |
| 251 | + systemProgram: systemProgram.address, |
| 252 | + sysvarInstructions: SYSVAR_INSTRUCTIONS_PUBKEY, |
| 253 | + }, |
| 254 | + { verificationArgs: VerificationArgs.CollectionV1 }, |
| 255 | + tokenMetadataProgram.address |
| 256 | + ), |
| 257 | + signers: [collectionAuthority], |
| 258 | + key: params.instructionKey ?? 'unverifyCollection', |
| 259 | + }); |
205 | 260 | };
|
0 commit comments