Skip to content

Commit

Permalink
Merge pull request #15 from metaplex-foundation/feat/vanity_address
Browse files Browse the repository at this point in the history
Add a guard to verify the mint of the new asset matches a vanity pattern
  • Loading branch information
blockiosaurus authored Aug 12, 2024
2 parents e179c4f + 878f4de commit bcd4c4d
Show file tree
Hide file tree
Showing 18 changed files with 499 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ CARGO_TERM_COLOR=always
NODE_VERSION=16.x
PROGRAMS=["candy-machine-core", "candy-guard"]
RUST_VERSION=1.75.0
SOLANA_VERSION=1.17.20
SOLANA_VERSION=1.18.21
ANCHOR_VERSION=0.27.0
COMMIT_USER_NAME="github-actions[bot]"
COMMIT_USER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
DEPLOY_SOLANA_VERSION=1.18.14
DEPLOY_SOLANA_VERSION=1.18.21
5 changes: 5 additions & 0 deletions clients/js/src/defaultGuards/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import {
TokenGateArgs,
TokenPayment,
TokenPaymentArgs,
VanityMint,
VanityMintArgs,
} from '../generated';
import {
GuardSet,
Expand Down Expand Up @@ -131,6 +133,7 @@ export type DefaultGuardSetArgs = GuardSetArgs & {
assetBurnMulti: OptionOrNullable<AssetBurnMultiArgs>;
assetPaymentMulti: OptionOrNullable<AssetPaymentMultiArgs>;
assetGate: OptionOrNullable<AssetGateArgs>;
vanityMint: OptionOrNullable<VanityMintArgs>;
};

/**
Expand Down Expand Up @@ -167,6 +170,7 @@ export type DefaultGuardSet = GuardSet & {
assetBurnMulti: Option<AssetBurnMulti>;
assetPaymentMulti: Option<AssetPaymentMulti>;
assetGate: Option<AssetGate>;
vanityMint: Option<VanityMint>;
};

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

/** @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 @@ -29,3 +29,4 @@ export * from './assetMintLimit';
export * from './assetBurnMulti';
export * from './assetPaymentMulti';
export * from './assetGate';
export * from './vanityMint';
34 changes: 34 additions & 0 deletions clients/js/src/defaultGuards/vanityMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
fixSerializer,
mapSerializer,
} from '@metaplex-foundation/umi/serializers';
import { ExceededRegexLengthError } from '../errors';
import {
getVanityMintSerializer,
VanityMint,
VanityMintArgs,
} from '../generated';
import { GuardManifest, noopParser } from '../guards';

/**
* The vanityMint guard verifies that the new asset
* address matches the provided regex.
*/
export const vanityMintGuardManifest: GuardManifest<
VanityMintArgs,
VanityMint
> = {
name: 'vanityMint',
serializer: () =>
mapSerializer(
fixSerializer(getVanityMintSerializer(), 4 + 100),
(value) => {
if (value.regex.length > 100) {
throw new ExceededRegexLengthError();
}
return value;
}
),
mintParser: noopParser,
routeParser: noopParser,
};
11 changes: 11 additions & 0 deletions clients/js/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,14 @@ export class MaximumOfFiveAdditionalProgramsError extends CandyMachineError {
super(message);
}
}

export class ExceededRegexLengthError extends CandyMachineError {
readonly name: string = 'ExceededRegexLengthError';

constructor() {
const message =
`The maximum length of a regex that can be used is 100 characters. ` +
'Please reduce the length of the regex to <= 100.';
super(message);
}
}
43 changes: 43 additions & 0 deletions clients/js/src/generated/errors/mplCoreCandyGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,49 @@ export class CgInvalidAccountVersionError extends ProgramError {
codeToErrorMap.set(0x17a3, CgInvalidAccountVersionError);
nameToErrorMap.set('InvalidAccountVersion', CgInvalidAccountVersionError);

/** ExceededRegexLength: Exceeded the maximum length of a regex that can be used */
export class CgExceededRegexLengthError extends ProgramError {
readonly name: string = 'ExceededRegexLength';

readonly code: number = 0x17a4; // 6052

constructor(program: Program, cause?: Error) {
super(
'Exceeded the maximum length of a regex that can be used',
program,
cause
);
}
}
codeToErrorMap.set(0x17a4, CgExceededRegexLengthError);
nameToErrorMap.set('ExceededRegexLength', CgExceededRegexLengthError);

/** InvalidVanityAddress: Invalid vanity address */
export class CgInvalidVanityAddressError extends ProgramError {
readonly name: string = 'InvalidVanityAddress';

readonly code: number = 0x17a5; // 6053

constructor(program: Program, cause?: Error) {
super('Invalid vanity address', program, cause);
}
}
codeToErrorMap.set(0x17a5, CgInvalidVanityAddressError);
nameToErrorMap.set('InvalidVanityAddress', CgInvalidVanityAddressError);

/** InvalidRegex: Invalid regex */
export class CgInvalidRegexError extends ProgramError {
readonly name: string = 'InvalidRegex';

readonly code: number = 0x17a6; // 6054

constructor(program: Program, cause?: Error) {
super('Invalid regex', program, cause);
}
}
codeToErrorMap.set(0x17a6, CgInvalidRegexError);
nameToErrorMap.set('InvalidRegex', CgInvalidRegexError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
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 @@ -40,6 +40,7 @@ export enum GuardType {
AssetBurnMulti,
AssetPaymentMulti,
AssetGate,
VanityMint,
}

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 @@ -42,3 +42,4 @@ export * from './token2022Payment';
export * from './tokenBurn';
export * from './tokenGate';
export * from './tokenPayment';
export * from './vanityMint';
27 changes: 27 additions & 0 deletions clients/js/src/generated/types/vanityMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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 {
Serializer,
string,
struct,
} from '@metaplex-foundation/umi/serializers';

/** Guard that sets a specific start date for the mint. */
export type VanityMint = { regex: string };

export type VanityMintArgs = VanityMint;

export function getVanityMintSerializer(): Serializer<
VanityMintArgs,
VanityMint
> {
return struct<VanityMint>([['regex', string()]], {
description: 'VanityMint',
}) as Serializer<VanityMintArgs, VanityMint>;
}
4 changes: 3 additions & 1 deletion clients/js/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
assetBurnMultiGuardManifest,
assetPaymentMultiGuardManifest,
assetGateGuardManifest,
vanityMintGuardManifest,
} from './defaultGuards';
import {
createMplCoreCandyGuardProgram,
Expand Down Expand Up @@ -95,7 +96,8 @@ export const mplCandyMachine = (): UmiPlugin => ({
assetMintLimitGuardManifest,
assetBurnMultiGuardManifest,
assetPaymentMultiGuardManifest,
assetGateGuardManifest
assetGateGuardManifest,
vanityMintGuardManifest
);
},
});
Expand Down
Loading

0 comments on commit bcd4c4d

Please sign in to comment.