Skip to content

Commit

Permalink
Merge pull request #14 from metaplex-foundation/feat/asset-gate
Browse files Browse the repository at this point in the history
Add asset gate guard
  • Loading branch information
blockiosaurus authored Aug 8, 2024
2 parents d35f2bc + 124a9eb commit e179c4f
Show file tree
Hide file tree
Showing 12 changed files with 467 additions and 1 deletion.
32 changes: 32 additions & 0 deletions clients/js/src/defaultGuards/assetGate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PublicKey } from '@metaplex-foundation/umi';
import { getAssetGateSerializer, AssetGate, AssetGateArgs } from '../generated';
import { GuardManifest, noopParser } from '../guards';

/**
* The assetGate 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.
*/
export const assetGateGuardManifest: GuardManifest<
AssetGateArgs,
AssetGate,
AssetGateMintArgs
> = {
name: 'assetGate',
serializer: getAssetGateSerializer,
mintParser: (context, mintContext, args) => ({
data: new Uint8Array(),
remainingAccounts: [{ publicKey: args.asset, isWritable: false }],
}),
routeParser: noopParser,
};

export type AssetGateMintArgs = {
/**
* The address of an Asset from the required
* collection that belongs to the payer.
*/
asset: PublicKey;
};
7 changes: 7 additions & 0 deletions clients/js/src/defaultGuards/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
AssetBurnArgs,
AssetBurnMulti,
AssetBurnMultiArgs,
AssetGate,
AssetGateArgs,
AssetMintLimit,
AssetMintLimitArgs,
AssetPayment,
Expand Down Expand Up @@ -93,6 +95,7 @@ import { AssetBurnMintArgs } from './assetBurn';
import { AssetMintLimitMintArgs } from './assetMintLimit';
import { AssetBurnMultiMintArgs } from './assetBurnMulti';
import { AssetPaymentMultiMintArgs } from './assetPaymentMulti';
import { AssetGateMintArgs } from './assetGate';

/**
* The arguments for all default Candy Machine guards.
Expand Down Expand Up @@ -127,6 +130,7 @@ export type DefaultGuardSetArgs = GuardSetArgs & {
assetMintLimit: OptionOrNullable<AssetMintLimitArgs>;
assetBurnMulti: OptionOrNullable<AssetBurnMultiArgs>;
assetPaymentMulti: OptionOrNullable<AssetPaymentMultiArgs>;
assetGate: OptionOrNullable<AssetGateArgs>;
};

/**
Expand Down Expand Up @@ -162,6 +166,7 @@ export type DefaultGuardSet = GuardSet & {
assetMintLimit: Option<AssetMintLimit>;
assetBurnMulti: Option<AssetBurnMulti>;
assetPaymentMulti: Option<AssetPaymentMulti>;
assetGate: Option<AssetGate>;
};

/**
Expand Down Expand Up @@ -197,6 +202,7 @@ export type DefaultGuardSetMintArgs = GuardSetMintArgs & {
assetMintLimit: OptionOrNullable<AssetMintLimitMintArgs>;
assetBurnMulti: OptionOrNullable<AssetBurnMultiMintArgs>;
assetPaymentMulti: OptionOrNullable<AssetPaymentMultiMintArgs>;
assetGate: OptionOrNullable<AssetGateMintArgs>;
};

/**
Expand Down Expand Up @@ -257,6 +263,7 @@ export const defaultCandyGuardNames: string[] = [
'assetMintLimit',
'assetBurnMulti',
'assetPaymentMulti',
'assetGate',
];

/** @internal */
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/defaultGuards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export * from './assetBurn';
export * from './assetMintLimit';
export * from './assetBurnMulti';
export * from './assetPaymentMulti';
export * from './assetGate';
32 changes: 32 additions & 0 deletions clients/js/src/generated/types/assetGate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/metaplex-foundation/kinobi
*/

import { PublicKey } from '@metaplex-foundation/umi';
import {
Serializer,
publicKey as publicKeySerializer,
struct,
} from '@metaplex-foundation/umi/serializers';

/**
* Guard that restricts the transaction to holders of a specified collection.
*
* List of accounts required:
*
* 0. `[]` Account of the Asset.
*/

export type AssetGate = { requiredCollection: PublicKey };

export type AssetGateArgs = AssetGate;

export function getAssetGateSerializer(): Serializer<AssetGateArgs, AssetGate> {
return struct<AssetGate>([['requiredCollection', publicKeySerializer()]], {
description: 'AssetGate',
}) as Serializer<AssetGateArgs, AssetGate>;
}
1 change: 1 addition & 0 deletions clients/js/src/generated/types/guardType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum GuardType {
AssetMintLimit,
AssetBurnMulti,
AssetPaymentMulti,
AssetGate,
}

export type GuardTypeArgs = GuardType;
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './allocation';
export * from './allowList';
export * from './assetBurn';
export * from './assetBurnMulti';
export * from './assetGate';
export * from './assetMintLimit';
export * from './assetPayment';
export * from './assetPaymentMulti';
Expand Down
4 changes: 3 additions & 1 deletion clients/js/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
assetMintLimitGuardManifest,
assetBurnMultiGuardManifest,
assetPaymentMultiGuardManifest,
assetGateGuardManifest,
} from './defaultGuards';
import {
createMplCoreCandyGuardProgram,
Expand Down Expand Up @@ -93,7 +94,8 @@ export const mplCandyMachine = (): UmiPlugin => ({
assetBurnGuardManifest,
assetMintLimitGuardManifest,
assetBurnMultiGuardManifest,
assetPaymentMultiGuardManifest
assetPaymentMultiGuardManifest,
assetGateGuardManifest
);
},
});
Expand Down
Loading

0 comments on commit e179c4f

Please sign in to comment.