Skip to content

Commit

Permalink
editions (#1)
Browse files Browse the repository at this point in the history
- cleanup unused CM config items
- allow guards to attach plugins to mints
- edition guard will add edition plugin with the edition number set to edition_starting_number + items_redeemed
- intended usage is with hidden settings to stamp out identical assets with different edition numbers
  • Loading branch information
nhanphan authored Apr 11, 2024
1 parent f638a41 commit 7ac2b83
Show file tree
Hide file tree
Showing 41 changed files with 587 additions and 369 deletions.
6 changes: 3 additions & 3 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"author": "Metaplex Maintainers <[email protected]>",
"license": "Apache-2.0",
"peerDependencies": {
"@metaplex-foundation/umi": ">= 0.8.2 < 1",
"@metaplex-foundation/mpl-core": ">= 0.4.2 < 1"
"@metaplex-foundation/mpl-core": ">= 0.4.5 < 1",
"@metaplex-foundation/umi": ">= 0.8.2 < 1"
},
"dependencies": {
"@metaplex-foundation/mpl-token-metadata": "3.0.0-alpha.27",
Expand All @@ -37,7 +37,7 @@
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@identity.com/solana-gateway-ts": "^0.12.0",
"@metaplex-foundation/mpl-core": "0.4.2",
"@metaplex-foundation/mpl-core": "^0.4.5",
"@metaplex-foundation/mpl-token-auth-rules": "^1.2.0",
"@metaplex-foundation/umi": "^0.8.2",
"@metaplex-foundation/umi-bundle-tests": "^0.8.2",
Expand Down
8 changes: 4 additions & 4 deletions clients/js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions clients/js/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ export const CONFIG_LINE_SIZE = 4 + MAX_NAME_LENGTH + 4 + MAX_URI_LENGTH;

export const CANDY_MACHINE_HIDDEN_SECTION =
8 + // discriminator
8 + // features
1 + // version
32 + // authority
32 + // mint authority
32 + // collection mint
8 + // items redeemed
8 + // items available (config data)
4 +
MAX_SYMBOL_LENGTH + // u32 + max symbol length
2 + // seller fee basis points
8 + // max supply
1 + // is mutable
4 +
MAX_CREATOR_LIMIT * MAX_CREATOR_LEN + // u32 + creators vec
1 + // option (config lines settings)
4 +
MAX_NAME_LENGTH + // u32 + max name length
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/createCandyMachineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const createCandyMachineV2 = async (
input.itemsAvailable,
input.configLineSettings ?? none()
);

const lamports = await context.rpc.getRent(space);
return transactionBuilder()
.add(
Expand Down
6 changes: 6 additions & 0 deletions clients/js/src/defaultGuards/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
AllowListArgs,
BotTax,
BotTaxArgs,
Edition,
EditionArgs,
EndDate,
EndDateArgs,
FreezeSolPayment,
Expand Down Expand Up @@ -104,6 +106,7 @@ export type DefaultGuardSetArgs = GuardSetArgs & {
token2022Payment: OptionOrNullable<Token2022PaymentArgs>;
solFixedFee: OptionOrNullable<SolFixedFeeArgs>;
nftMintLimit: OptionOrNullable<NftMintLimitArgs>;
edition: OptionOrNullable<EditionArgs>;
};

/**
Expand Down Expand Up @@ -133,6 +136,7 @@ export type DefaultGuardSet = GuardSet & {
token2022Payment: Option<Token2022Payment>;
solFixedFee: Option<SolFixedFee>;
nftMintLimit: Option<NftMintLimit>;
edition: Option<Edition>;
};

/**
Expand Down Expand Up @@ -162,6 +166,7 @@ export type DefaultGuardSetMintArgs = GuardSetMintArgs & {
token2022Payment: OptionOrNullable<Token2022PaymentMintArgs>;
solFixedFee: OptionOrNullable<SolFixedFeeMintArgs>;
nftMintLimit: OptionOrNullable<NftMintLimitMintArgs>;
// edition: no mint settings
};

/**
Expand Down Expand Up @@ -216,6 +221,7 @@ export const defaultCandyGuardNames: string[] = [
'token2022Payment',
'solFixedFee',
'nftMintLimit',
'edition',
];

/** @internal */
Expand Down
18 changes: 18 additions & 0 deletions clients/js/src/defaultGuards/edition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getEditionSerializer, Edition, EditionArgs } from '../generated';
import { GuardManifest, noopParser } from '../guards';

/**
* The edition guard is used add the edition plugin to minted assets
*/
export const editionGuardManifest: GuardManifest<
EditionArgs,
Edition,
EditionMintArgs
> = {
name: 'edition',
serializer: getEditionSerializer,
mintParser: noopParser,
routeParser: noopParser,
};

export type EditionMintArgs = Omit<EditionArgs, 'lamports'>;
1 change: 1 addition & 0 deletions clients/js/src/defaultGuards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './tokenBurn';
export * from './tokenGate';
export * from './tokenPayment';
export * from './token2022Payment';
export * from './edition';
12 changes: 5 additions & 7 deletions clients/js/src/generated/accounts/candyMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export function getCandyMachineGpaBuilder(
.registerFields<{
discriminator: Array<number>;
version: AccountVersionArgs;
features: Array<number>;
authority: PublicKey;
mintAuthority: PublicKey;
collectionMint: PublicKey;
Expand All @@ -117,12 +116,11 @@ export function getCandyMachineGpaBuilder(
}>({
discriminator: [0, array(u8(), { size: 8 })],
version: [8, getAccountVersionSerializer()],
features: [9, array(u8(), { size: 6 })],
authority: [15, publicKeySerializer()],
mintAuthority: [47, publicKeySerializer()],
collectionMint: [79, publicKeySerializer()],
itemsRedeemed: [111, u64()],
data: [119, getCandyMachineDataSerializer()],
authority: [9, publicKeySerializer()],
mintAuthority: [41, publicKeySerializer()],
collectionMint: [73, publicKeySerializer()],
itemsRedeemed: [105, u64()],
data: [113, getCandyMachineDataSerializer()],
})
.deserializeUsing<CandyMachine>((account) =>
deserializeCandyMachine(account)
Expand Down
23 changes: 0 additions & 23 deletions clients/js/src/generated/instructions/initializeCandyMachineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
*/

import {
Amount,
Context,
Option,
OptionOrNullable,
Pda,
PublicKey,
Signer,
TransactionBuilder,
mapAmountSerializer,
none,
publicKey,
transactionBuilder,
Expand All @@ -26,9 +24,7 @@ import {
bool,
mapSerializer,
option,
string,
struct,
u16,
u64,
u8,
} from '@metaplex-foundation/umi/serializers';
Expand All @@ -42,12 +38,9 @@ import {
import {
ConfigLineSettings,
ConfigLineSettingsArgs,
Creator,
CreatorArgs,
HiddenSettings,
HiddenSettingsArgs,
getConfigLineSettingsSerializer,
getCreatorSerializer,
getHiddenSettingsSerializer,
} from '../types';

Expand Down Expand Up @@ -107,16 +100,10 @@ export type InitializeCandyMachineV2InstructionData = {
discriminator: Array<number>;
/** Number of assets available */
itemsAvailable: bigint;
/** Symbol for the asset */
symbol: string;
/** Secondary sales royalty basis points (0-10000) */
sellerFeeBasisPoints: Amount<'%', 2>;
/** Max supply of each individual asset (default 0) */
maxEditionSupply: bigint;
/** Indicates if the asset is mutable or not (default yes) */
isMutable: boolean;
/** List of creators */
creators: Array<Creator>;
/** Config line settings */
configLineSettings: Option<ConfigLineSettings>;
/** Hidden setttings */
Expand All @@ -126,16 +113,10 @@ export type InitializeCandyMachineV2InstructionData = {
export type InitializeCandyMachineV2InstructionDataArgs = {
/** Number of assets available */
itemsAvailable: number | bigint;
/** Symbol for the asset */
symbol?: string;
/** Secondary sales royalty basis points (0-10000) */
sellerFeeBasisPoints: Amount<'%', 2>;
/** Max supply of each individual asset (default 0) */
maxEditionSupply?: number | bigint;
/** Indicates if the asset is mutable or not (default yes) */
isMutable?: boolean;
/** List of creators */
creators: Array<CreatorArgs>;
/** Config line settings */
configLineSettings?: OptionOrNullable<ConfigLineSettingsArgs>;
/** Hidden setttings */
Expand All @@ -155,11 +136,8 @@ export function getInitializeCandyMachineV2InstructionDataSerializer(): Serializ
[
['discriminator', array(u8(), { size: 8 })],
['itemsAvailable', u64()],
['symbol', string()],
['sellerFeeBasisPoints', mapAmountSerializer(u16(), '%', 2)],
['maxEditionSupply', u64()],
['isMutable', bool()],
['creators', array(getCreatorSerializer())],
['configLineSettings', option(getConfigLineSettingsSerializer())],
['hiddenSettings', option(getHiddenSettingsSerializer())],
],
Expand All @@ -168,7 +146,6 @@ export function getInitializeCandyMachineV2InstructionDataSerializer(): Serializ
(value) => ({
...value,
discriminator: [67, 153, 175, 39, 218, 16, 38, 32],
symbol: value.symbol ?? '',
maxEditionSupply: value.maxEditionSupply ?? 0,
isMutable: value.isMutable ?? true,
configLineSettings: value.configLineSettings ?? none(),
Expand Down
35 changes: 31 additions & 4 deletions clients/js/src/generated/instructions/mintAssetFromCandyMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import {
PluginAuthorityPair,
PluginAuthorityPairArgs,
getPluginAuthorityPairSerializer,
} from '@metaplex-foundation/mpl-core';
import {
Context,
Pda,
Expand All @@ -24,6 +29,7 @@ import {
} from '@metaplex-foundation/umi/serializers';
import { findCandyMachineAuthorityPda } from '../../hooked';
import {
PickPartial,
ResolvedAccount,
ResolvedAccountsWithIndices,
expectPublicKey,
Expand Down Expand Up @@ -88,9 +94,12 @@ export type MintAssetFromCandyMachineInstructionAccounts = {
// Data.
export type MintAssetFromCandyMachineInstructionData = {
discriminator: Array<number>;
plugins: Array<PluginAuthorityPair>;
};

export type MintAssetFromCandyMachineInstructionDataArgs = {};
export type MintAssetFromCandyMachineInstructionDataArgs = {
plugins: Array<PluginAuthorityPairArgs>;
};

export function getMintAssetFromCandyMachineInstructionDataSerializer(): Serializer<
MintAssetFromCandyMachineInstructionDataArgs,
Expand All @@ -102,7 +111,10 @@ export function getMintAssetFromCandyMachineInstructionDataSerializer(): Seriali
MintAssetFromCandyMachineInstructionData
>(
struct<MintAssetFromCandyMachineInstructionData>(
[['discriminator', array(u8(), { size: 8 })]],
[
['discriminator', array(u8(), { size: 8 })],
['plugins', array(getPluginAuthorityPairSerializer())],
],
{ description: 'MintAssetFromCandyMachineInstructionData' }
),
(value) => ({
Expand All @@ -115,10 +127,17 @@ export function getMintAssetFromCandyMachineInstructionDataSerializer(): Seriali
>;
}

// Args.
export type MintAssetFromCandyMachineInstructionArgs = PickPartial<
MintAssetFromCandyMachineInstructionDataArgs,
'plugins'
>;

// Instruction.
export function mintAssetFromCandyMachine(
context: Pick<Context, 'eddsa' | 'payer' | 'programs'>,
input: MintAssetFromCandyMachineInstructionAccounts
input: MintAssetFromCandyMachineInstructionAccounts &
MintAssetFromCandyMachineInstructionArgs
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -173,6 +192,9 @@ export function mintAssetFromCandyMachine(
},
};

// Arguments.
const resolvedArgs: MintAssetFromCandyMachineInstructionArgs = { ...input };

// Default values.
if (!resolvedAccounts.authorityPda.value) {
resolvedAccounts.authorityPda.value = findCandyMachineAuthorityPda(
Expand Down Expand Up @@ -207,6 +229,9 @@ export function mintAssetFromCandyMachine(
'SysvarS1otHashes111111111111111111111111111'
);
}
if (!resolvedArgs.plugins) {
resolvedArgs.plugins = [];
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
Expand All @@ -222,7 +247,9 @@ export function mintAssetFromCandyMachine(

// Data.
const data =
getMintAssetFromCandyMachineInstructionDataSerializer().serialize({});
getMintAssetFromCandyMachineInstructionDataSerializer().serialize(
resolvedArgs as MintAssetFromCandyMachineInstructionDataArgs
);

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;
Expand Down
5 changes: 0 additions & 5 deletions clients/js/src/generated/types/candyMachineAccountData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export type CandyMachineAccountData = {
discriminator: Array<number>;
/** Version of the account. */
version: AccountVersion;
/** Features flags. */
features: Array<number>;
/** Authority address. */
authority: PublicKey;
/** Authority address allowed to mint from the candy machine. */
Expand All @@ -47,8 +45,6 @@ export type CandyMachineAccountData = {
export type CandyMachineAccountDataArgs = {
/** Version of the account. */
version: AccountVersionArgs;
/** Features flags. */
features: Array<number>;
/** Authority address. */
authority: PublicKey;
/** Authority address allowed to mint from the candy machine. */
Expand All @@ -74,7 +70,6 @@ export function getCandyMachineAccountDataSerializer(): Serializer<
[
['discriminator', array(u8(), { size: 8 })],
['version', getAccountVersionSerializer()],
['features', array(u8(), { size: 6 })],
['authority', publicKeySerializer()],
['mintAuthority', publicKeySerializer()],
['collectionMint', publicKeySerializer()],
Expand Down
Loading

0 comments on commit 7ac2b83

Please sign in to comment.