/
nftGate.ts
91 lines (84 loc) · 2.39 KB
/
nftGate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { nftGateBeet } from '@metaplex-foundation/mpl-candy-guard';
import { GuardMintSettingsMissingError } from '../errors';
import { CandyGuardManifest } from './core';
import { createSerializerFromBeet, PublicKey } from '@/types';
/**
* The nftGate guard restricts minting to holders
* of a specified NFT collection.
*
* This means the mint address of an NFT from this
* collection must be passed when minting.
*
* This object defines the settings that should be
* provided when creating and/or updating a Candy
* Machine if you wish to enable this guard.
*
* @see {@link NftGateGuardMintSettings} for more
* information on the mint settings of this guard.
*/
export type NftGateGuardSettings = {
/** The mint address of the required NFT Collection. */
requiredCollection: PublicKey;
};
/**
* The settings for the nftGate guard that could
* be provided when minting from the Candy Machine.
*
* @see {@link NftGateGuardSettings} for more
* information on the nftGate guard itself.
*/
export type NftGateGuardMintSettings = {
/**
* The mint address of an NFT from the required
* collection that belongs to the payer.
*/
mint: PublicKey;
/**
* The token account linking the NFT with its owner.
*
* @defaultValue
* Defaults to the associated token address using the
* mint address of the NFT and the payer's address.
*/
tokenAccount?: PublicKey;
};
/** @internal */
export const nftGateGuardManifest: CandyGuardManifest<
NftGateGuardSettings,
NftGateGuardMintSettings
> = {
name: 'nftGate',
settingsBytes: 32,
settingsSerializer: createSerializerFromBeet(nftGateBeet),
mintSettingsParser: ({ metaplex, mintSettings, payer, programs }) => {
if (!mintSettings) {
throw new GuardMintSettingsMissingError('nftGate');
}
const tokenAccount =
mintSettings.tokenAccount ??
metaplex.tokens().pdas().associatedTokenAccount({
mint: mintSettings.mint,
owner: payer.publicKey,
programs,
});
const tokenMetadata = metaplex.nfts().pdas().metadata({
mint: mintSettings.mint,
programs,
});
return {
arguments: Buffer.from([]),
remainingAccounts: [
{
isSigner: false,
address: tokenAccount,
isWritable: false,
},
{
isSigner: false,
address: tokenMetadata,
isWritable: false,
},
],
};
},
};