Skip to content

Commit

Permalink
remove unneeded versions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan authored Apr 11, 2024
1 parent 7ac2b83 commit 53d0845
Show file tree
Hide file tree
Showing 57 changed files with 362 additions and 510 deletions.
1 change: 0 additions & 1 deletion clients/js/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const CONFIG_LINE_SIZE = 4 + MAX_NAME_LENGTH + 4 + MAX_URI_LENGTH;

export const CANDY_MACHINE_HIDDEN_SECTION =
8 + // discriminator
1 + // version
32 + // authority
32 + // mint authority
32 + // collection mint
Expand Down
8 changes: 4 additions & 4 deletions clients/js/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import {
createCandyGuard,
CreateCandyGuardInstructionDataArgs,
} from './createCandyGuard';
import { createCandyMachineV2 } from './createCandyMachineV2';
import { createCandyMachine } from './createCandyMachine';
import { DefaultGuardSetArgs } from './defaultGuards';
import { wrap } from './generated';
import { GuardRepository, GuardSetArgs } from './guards';
import { findCandyGuardPda } from './hooked';

export type CreateInput<DA extends GuardSetArgs = DefaultGuardSetArgs> =
Parameters<typeof createCandyMachineV2>[1] &
Parameters<typeof createCandyMachine>[1] &
CreateCandyGuardInstructionDataArgs<DA>;

export const create = async <DA extends GuardSetArgs = DefaultGuardSetArgs>(
context: Parameters<typeof createCandyMachineV2>[0] & {
context: Parameters<typeof createCandyMachine>[0] & {
coreGuards: GuardRepository;
},
input: CreateInput<DA extends undefined ? DefaultGuardSetArgs : DA>
Expand All @@ -27,7 +27,7 @@ export const create = async <DA extends GuardSetArgs = DefaultGuardSetArgs>(
base: input.candyMachine.publicKey,
});
return transactionBuilder()
.add(await createCandyMachineV2(context, rest))
.add(await createCandyMachine(context, rest))
.add(
createCandyGuard(context, {
base: input.candyMachine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import {
transactionBuilder,
TransactionBuilder,
} from '@metaplex-foundation/umi';
import { initializeCandyMachineV2 } from './generated';
import { initializeCandyMachine } from './generated';
import { getCandyMachineSize } from './hooked';

export type CreateCandyMachineV2Input = Omit<
Parameters<typeof initializeCandyMachineV2>[1],
export type CreateCandyMachineInput = Omit<
Parameters<typeof initializeCandyMachine>[1],
'candyMachine'
> & {
candyMachine: Signer;
};

export const createCandyMachineV2 = async (
context: Parameters<typeof initializeCandyMachineV2>[0] &
export const createCandyMachine = async (
context: Parameters<typeof initializeCandyMachine>[0] &
Pick<Context, 'rpc'>,
input: CreateCandyMachineV2Input
input: CreateCandyMachineInput
): Promise<TransactionBuilder> => {
const space = getCandyMachineSize(
input.itemsAvailable,
Expand All @@ -37,7 +37,7 @@ export const createCandyMachineV2 = async (
})
)
.add(
initializeCandyMachineV2(context, {
initializeCandyMachine(context, {
...input,
candyMachine: input.candyMachine.publicKey,
})
Expand Down
19 changes: 6 additions & 13 deletions clients/js/src/generated/accounts/candyMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ import {
CandyMachineAccountData,
getCandyMachineAccountDataSerializer,
} from '../../hooked';
import {
AccountVersionArgs,
CandyMachineDataArgs,
getAccountVersionSerializer,
getCandyMachineDataSerializer,
} from '../types';
import { CandyMachineDataArgs, getCandyMachineDataSerializer } from '../types';

/** Candy machine state and config data. */
export type CandyMachine = Account<CandyMachineAccountData>;
Expand Down Expand Up @@ -107,20 +102,18 @@ export function getCandyMachineGpaBuilder(
return gpaBuilder(context, programId)
.registerFields<{
discriminator: Array<number>;
version: AccountVersionArgs;
authority: PublicKey;
mintAuthority: PublicKey;
collectionMint: PublicKey;
itemsRedeemed: number | bigint;
data: CandyMachineDataArgs;
}>({
discriminator: [0, array(u8(), { size: 8 })],
version: [8, getAccountVersionSerializer()],
authority: [9, publicKeySerializer()],
mintAuthority: [41, publicKeySerializer()],
collectionMint: [73, publicKeySerializer()],
itemsRedeemed: [105, u64()],
data: [113, getCandyMachineDataSerializer()],
authority: [8, publicKeySerializer()],
mintAuthority: [40, publicKeySerializer()],
collectionMint: [72, publicKeySerializer()],
itemsRedeemed: [104, u64()],
data: [112, getCandyMachineDataSerializer()],
})
.deserializeUsing<CandyMachine>((account) =>
deserializeCandyMachine(account)
Expand Down
4 changes: 2 additions & 2 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
export * from './addConfigLines';
export * from './deleteCandyGuard';
export * from './deleteCandyMachine';
export * from './initializeCandyMachineV2';
export * from './initializeCandyMachine';
export * from './mintAssetFromCandyMachine';
export * from './setCandyGuardAuthority';
export * from './setCandyMachineAuthority';
export * from './setCollectionV2';
export * from './setCollection';
export * from './setMintAuthority';
export * from './unwrap';
export * from './updateCandyMachine';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
} from '../types';

// Accounts.
export type InitializeCandyMachineV2InstructionAccounts = {
export type InitializeCandyMachineInstructionAccounts = {
/**
* Candy Machine account. The account space must be allocated to allow accounts larger
* than 10kb.
Expand Down Expand Up @@ -96,7 +96,7 @@ export type InitializeCandyMachineV2InstructionAccounts = {
};

// Data.
export type InitializeCandyMachineV2InstructionData = {
export type InitializeCandyMachineInstructionData = {
discriminator: Array<number>;
/** Number of assets available */
itemsAvailable: bigint;
Expand All @@ -110,7 +110,7 @@ export type InitializeCandyMachineV2InstructionData = {
hiddenSettings: Option<HiddenSettings>;
};

export type InitializeCandyMachineV2InstructionDataArgs = {
export type InitializeCandyMachineInstructionDataArgs = {
/** Number of assets available */
itemsAvailable: number | bigint;
/** Max supply of each individual asset (default 0) */
Expand All @@ -123,16 +123,16 @@ export type InitializeCandyMachineV2InstructionDataArgs = {
hiddenSettings?: OptionOrNullable<HiddenSettingsArgs>;
};

export function getInitializeCandyMachineV2InstructionDataSerializer(): Serializer<
InitializeCandyMachineV2InstructionDataArgs,
InitializeCandyMachineV2InstructionData
export function getInitializeCandyMachineInstructionDataSerializer(): Serializer<
InitializeCandyMachineInstructionDataArgs,
InitializeCandyMachineInstructionData
> {
return mapSerializer<
InitializeCandyMachineV2InstructionDataArgs,
InitializeCandyMachineInstructionDataArgs,
any,
InitializeCandyMachineV2InstructionData
InitializeCandyMachineInstructionData
>(
struct<InitializeCandyMachineV2InstructionData>(
struct<InitializeCandyMachineInstructionData>(
[
['discriminator', array(u8(), { size: 8 })],
['itemsAvailable', u64()],
Expand All @@ -141,31 +141,31 @@ export function getInitializeCandyMachineV2InstructionDataSerializer(): Serializ
['configLineSettings', option(getConfigLineSettingsSerializer())],
['hiddenSettings', option(getHiddenSettingsSerializer())],
],
{ description: 'InitializeCandyMachineV2InstructionData' }
{ description: 'InitializeCandyMachineInstructionData' }
),
(value) => ({
...value,
discriminator: [67, 153, 175, 39, 218, 16, 38, 32],
discriminator: [175, 175, 109, 31, 13, 152, 155, 237],
maxEditionSupply: value.maxEditionSupply ?? 0,
isMutable: value.isMutable ?? true,
configLineSettings: value.configLineSettings ?? none(),
hiddenSettings: value.hiddenSettings ?? none(),
})
) as Serializer<
InitializeCandyMachineV2InstructionDataArgs,
InitializeCandyMachineV2InstructionData
InitializeCandyMachineInstructionDataArgs,
InitializeCandyMachineInstructionData
>;
}

// Args.
export type InitializeCandyMachineV2InstructionArgs =
InitializeCandyMachineV2InstructionDataArgs;
export type InitializeCandyMachineInstructionArgs =
InitializeCandyMachineInstructionDataArgs;

// Instruction.
export function initializeCandyMachineV2(
export function initializeCandyMachine(
context: Pick<Context, 'eddsa' | 'identity' | 'payer' | 'programs'>,
input: InitializeCandyMachineV2InstructionAccounts &
InitializeCandyMachineV2InstructionArgs
input: InitializeCandyMachineInstructionAccounts &
InitializeCandyMachineInstructionArgs
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -211,7 +211,7 @@ export function initializeCandyMachineV2(
};

// Arguments.
const resolvedArgs: InitializeCandyMachineV2InstructionArgs = { ...input };
const resolvedArgs: InitializeCandyMachineInstructionArgs = { ...input };

// Default values.
if (!resolvedAccounts.authorityPda.value) {
Expand Down Expand Up @@ -259,8 +259,8 @@ export function initializeCandyMachineV2(
);

// Data.
const data = getInitializeCandyMachineV2InstructionDataSerializer().serialize(
resolvedArgs as InitializeCandyMachineV2InstructionDataArgs
const data = getInitializeCandyMachineInstructionDataSerializer().serialize(
resolvedArgs as InitializeCandyMachineInstructionDataArgs
);

// Bytes Created On Chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from '../shared';

// Accounts.
export type MintV2InstructionAccounts = {
export type MintV1InstructionAccounts = {
/** Candy Guard account. */
candyGuard?: PublicKey | Pda;
/**
Expand Down Expand Up @@ -104,44 +104,44 @@ export type MintV2InstructionAccounts = {
};

// Data.
export type MintV2InstructionData = {
export type MintV1InstructionData = {
discriminator: Array<number>;
mintArgs: Uint8Array;
group: Option<string>;
};

export type MintV2InstructionDataArgs = {
export type MintV1InstructionDataArgs = {
mintArgs: Uint8Array;
group: OptionOrNullable<string>;
};

export function getMintV2InstructionDataSerializer(): Serializer<
MintV2InstructionDataArgs,
MintV2InstructionData
export function getMintV1InstructionDataSerializer(): Serializer<
MintV1InstructionDataArgs,
MintV1InstructionData
> {
return mapSerializer<MintV2InstructionDataArgs, any, MintV2InstructionData>(
struct<MintV2InstructionData>(
return mapSerializer<MintV1InstructionDataArgs, any, MintV1InstructionData>(
struct<MintV1InstructionData>(
[
['discriminator', array(u8(), { size: 8 })],
['mintArgs', bytes({ size: u32() })],
['group', option(string())],
],
{ description: 'MintV2InstructionData' }
{ description: 'MintV1InstructionData' }
),
(value) => ({
...value,
discriminator: [120, 121, 23, 146, 173, 110, 199, 205],
discriminator: [145, 98, 192, 118, 184, 147, 118, 104],
})
) as Serializer<MintV2InstructionDataArgs, MintV2InstructionData>;
) as Serializer<MintV1InstructionDataArgs, MintV1InstructionData>;
}

// Args.
export type MintV2InstructionArgs = MintV2InstructionDataArgs;
export type MintV1InstructionArgs = MintV1InstructionDataArgs;

// Instruction.
export function mintV2(
export function mintV1(
context: Pick<Context, 'eddsa' | 'identity' | 'payer' | 'programs'>,
input: MintV2InstructionAccounts & MintV2InstructionArgs
input: MintV1InstructionAccounts & MintV1InstructionArgs
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -199,7 +199,7 @@ export function mintV2(
};

// Arguments.
const resolvedArgs: MintV2InstructionArgs = { ...input };
const resolvedArgs: MintV1InstructionArgs = { ...input };

// Default values.
if (!resolvedAccounts.candyGuard.value) {
Expand Down Expand Up @@ -264,8 +264,8 @@ export function mintV2(
);

// Data.
const data = getMintV2InstructionDataSerializer().serialize(
resolvedArgs as MintV2InstructionDataArgs
const data = getMintV1InstructionDataSerializer().serialize(
resolvedArgs as MintV1InstructionDataArgs
);

// Bytes Created On Chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '../shared';

// Accounts.
export type SetCollectionV2InstructionAccounts = {
export type SetCollectionInstructionAccounts = {
/** Candy Machine account. */
candyMachine: PublicKey | Pda;
/** Candy Machine authority. */
Expand Down Expand Up @@ -81,34 +81,37 @@ export type SetCollectionV2InstructionAccounts = {
};

// Data.
export type SetCollectionV2InstructionData = { discriminator: Array<number> };
export type SetCollectionInstructionData = { discriminator: Array<number> };

export type SetCollectionV2InstructionDataArgs = {};
export type SetCollectionInstructionDataArgs = {};

export function getSetCollectionV2InstructionDataSerializer(): Serializer<
SetCollectionV2InstructionDataArgs,
SetCollectionV2InstructionData
export function getSetCollectionInstructionDataSerializer(): Serializer<
SetCollectionInstructionDataArgs,
SetCollectionInstructionData
> {
return mapSerializer<
SetCollectionV2InstructionDataArgs,
SetCollectionInstructionDataArgs,
any,
SetCollectionV2InstructionData
SetCollectionInstructionData
>(
struct<SetCollectionV2InstructionData>(
struct<SetCollectionInstructionData>(
[['discriminator', array(u8(), { size: 8 })]],
{ description: 'SetCollectionV2InstructionData' }
{ description: 'SetCollectionInstructionData' }
),
(value) => ({ ...value, discriminator: [229, 35, 61, 91, 15, 14, 99, 160] })
(value) => ({
...value,
discriminator: [192, 254, 206, 76, 168, 182, 59, 223],
})
) as Serializer<
SetCollectionV2InstructionDataArgs,
SetCollectionV2InstructionData
SetCollectionInstructionDataArgs,
SetCollectionInstructionData
>;
}

// Instruction.
export function setCollectionV2(
export function setCollection(
context: Pick<Context, 'eddsa' | 'identity' | 'payer' | 'programs'>,
input: SetCollectionV2InstructionAccounts
input: SetCollectionInstructionAccounts
): TransactionBuilder {
// Program ID.
const programId = context.programs.getPublicKey(
Expand Down Expand Up @@ -209,7 +212,7 @@ export function setCollectionV2(
);

// Data.
const data = getSetCollectionV2InstructionDataSerializer().serialize({});
const data = getSetCollectionInstructionDataSerializer().serialize({});

// Bytes Created On Chain.
const bytesCreatedOnChain = 0;
Expand Down
Loading

0 comments on commit 53d0845

Please sign in to comment.