Skip to content

Commit

Permalink
wip: make minting to real collections via delegate work
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Feb 29, 2024
1 parent 0d1752f commit 6a23e2c
Show file tree
Hide file tree
Showing 59 changed files with 383 additions and 1,065 deletions.
2 changes: 1 addition & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@metaplex-foundation/umi": ">= 0.8.2 < 1"
},
"dependencies": {
"@metaplex-foundation/mpl-asset": "^0.1.0",
"@metaplex-foundation/mpl-core": "^0.1.0",
"@metaplex-foundation/mpl-token-metadata": "3.0.0-alpha.27",
"@metaplex-foundation/mpl-toolbox": "^0.9.0",
"@noble/hashes": "^1.2.0",
Expand Down
1 change: 0 additions & 1 deletion clients/js/src/createCandyMachineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const createCandyMachineV2 = async (
const space = getCandyMachineSize(
input.itemsAvailable,
input.configLineSettings ?? none(),
input.tokenStandard
);
const lamports = await context.rpc.getRent(space);
return transactionBuilder()
Expand Down
8 changes: 4 additions & 4 deletions clients/js/src/createLutForCandyMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TransactionBuilder,
uniquePublicKeys,
} from '@metaplex-foundation/umi';
import { getMplAssetProgramId } from '@metaplex-foundation/mpl-asset';
import { getMplCoreProgramId } from '@metaplex-foundation/mpl-core';
import {
fetchCandyMachine,
getMplCandyMachineCoreProgramId,
Expand Down Expand Up @@ -48,18 +48,18 @@ export const getLutAddressesForCandyMachine = async (
collectionUpdateAuthority?: PublicKey
): Promise<PublicKey[]> => {
const candyMachineAccount = await fetchCandyMachine(context, candyMachine);
const { mintAuthority, collectionMint } = candyMachineAccount;
const { mintAuthority, collection } = candyMachineAccount;
collectionUpdateAuthority ??= context.identity.publicKey;

return uniquePublicKeys([
candyMachine,
mintAuthority,
collectionMint,
collection,
collectionUpdateAuthority,
findCandyMachineAuthorityPda(context, { candyMachine })[0],
getSysvar('instructions'),
getSysvar('slotHashes'),
getMplAssetProgramId(context),
getMplCoreProgramId(context),
getSplTokenProgramId(context),
getSplAssociatedTokenProgramId(context),
getMplTokenMetadataProgramId(context),
Expand Down
4 changes: 2 additions & 2 deletions clients/js/src/generated/accounts/candyMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function getCandyMachineGpaBuilder(
features: Array<number>;
authority: PublicKey;
mintAuthority: PublicKey;
collectionMint: PublicKey;
collection: PublicKey;
itemsRedeemed: number | bigint;
data: CandyMachineDataArgs;
}>({
Expand All @@ -120,7 +120,7 @@ export function getCandyMachineGpaBuilder(
features: [9, array(u8(), { size: 6 })],
authority: [15, publicKeySerializer()],
mintAuthority: [47, publicKeySerializer()],
collectionMint: [79, publicKeySerializer()],
collection: [79, publicKeySerializer()],
itemsRedeemed: [111, u64()],
data: [119, getCandyMachineDataSerializer()],
})
Expand Down
1 change: 0 additions & 1 deletion clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export * from './initializeCandyMachineV2';
export * from './mintAssetFromCandyMachine';
export * from './setCandyGuardAuthority';
export * from './setCandyMachineAuthority';
export * from './setCollection';
export * from './setCollectionV2';
export * from './setMintAuthority';
export * from './unwrap';
Expand Down
25 changes: 9 additions & 16 deletions clients/js/src/generated/instructions/initializeCandyMachineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export type InitializeCandyMachineV2InstructionAccounts = {
*
*/

assetProgram?: PublicKey | Pda;
mplCoreProgram?: PublicKey | Pda;
/** System program. */
systemProgram?: PublicKey | Pda;
/**
Expand Down Expand Up @@ -121,7 +121,6 @@ export type InitializeCandyMachineV2InstructionData = {
configLineSettings: Option<ConfigLineSettings>;
/** Hidden setttings */
hiddenSettings: Option<HiddenSettings>;
tokenStandard: number;
};

export type InitializeCandyMachineV2InstructionDataArgs = {
Expand All @@ -141,7 +140,6 @@ export type InitializeCandyMachineV2InstructionDataArgs = {
configLineSettings?: OptionOrNullable<ConfigLineSettingsArgs>;
/** Hidden setttings */
hiddenSettings?: OptionOrNullable<HiddenSettingsArgs>;
tokenStandard: number;
};

export function getInitializeCandyMachineV2InstructionDataSerializer(): Serializer<
Expand All @@ -164,7 +162,6 @@ export function getInitializeCandyMachineV2InstructionDataSerializer(): Serializ
['creators', array(getCreatorSerializer())],
['configLineSettings', option(getConfigLineSettingsSerializer())],
['hiddenSettings', option(getHiddenSettingsSerializer())],
['tokenStandard', u8()],
],
{ description: 'InitializeCandyMachineV2InstructionData' }
),
Expand Down Expand Up @@ -213,20 +210,16 @@ export function initializeCandyMachineV2(
},
authority: { index: 2, isWritable: false, value: input.authority ?? null },
payer: { index: 3, isWritable: true, value: input.payer ?? null },
collection: {
index: 4,
isWritable: false,
value: input.collection ?? null,
},
collection: { index: 4, isWritable: true, value: input.collection ?? null },
collectionUpdateAuthority: {
index: 5,
isWritable: true,
value: input.collectionUpdateAuthority ?? null,
},
assetProgram: {
mplCoreProgram: {
index: 6,
isWritable: false,
value: input.assetProgram ?? null,
value: input.mplCoreProgram ?? null,
},
systemProgram: {
index: 7,
Expand Down Expand Up @@ -256,12 +249,12 @@ export function initializeCandyMachineV2(
if (!resolvedAccounts.payer.value) {
resolvedAccounts.payer.value = context.payer;
}
if (!resolvedAccounts.assetProgram.value) {
resolvedAccounts.assetProgram.value = context.programs.getPublicKey(
'mplAsset',
'ASSETp3DinZKfiAyvdQG16YWWLJ2X3ZKjg9zku7n1sZD'
if (!resolvedAccounts.mplCoreProgram.value) {
resolvedAccounts.mplCoreProgram.value = context.programs.getPublicKey(
'mplCore',
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL'
);
resolvedAccounts.assetProgram.isWritable = false;
resolvedAccounts.mplCoreProgram.isWritable = false;
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
Expand Down
33 changes: 11 additions & 22 deletions clients/js/src/generated/instructions/mintAssetFromCandyMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,12 @@ export type MintAssetFromCandyMachineInstructionAccounts = {
*/

collection: PublicKey | Pda;
/**
* Update authority of the collection NFT.
*
*/

collectionUpdateAuthority: PublicKey | Pda;
/**
* Token Metadata program.
*
*/

assetProgram?: PublicKey | Pda;
mplCoreProgram?: PublicKey | Pda;
/** System program. */
systemProgram?: PublicKey | Pda;
/**
Expand Down Expand Up @@ -157,28 +151,23 @@ export function mintAssetFromCandyMachine(
},
asset: { index: 5, isWritable: true, value: input.asset ?? null },
collection: { index: 6, isWritable: true, value: input.collection ?? null },
collectionUpdateAuthority: {
mplCoreProgram: {
index: 7,
isWritable: false,
value: input.collectionUpdateAuthority ?? null,
},
assetProgram: {
index: 8,
isWritable: false,
value: input.assetProgram ?? null,
value: input.mplCoreProgram ?? null,
},
systemProgram: {
index: 9,
index: 8,
isWritable: false,
value: input.systemProgram ?? null,
},
sysvarInstructions: {
index: 10,
index: 9,
isWritable: false,
value: input.sysvarInstructions ?? null,
},
recentSlothashes: {
index: 11,
index: 10,
isWritable: false,
value: input.recentSlothashes ?? null,
},
Expand All @@ -194,12 +183,12 @@ export function mintAssetFromCandyMachine(
if (!resolvedAccounts.payer.value) {
resolvedAccounts.payer.value = context.payer;
}
if (!resolvedAccounts.assetProgram.value) {
resolvedAccounts.assetProgram.value = context.programs.getPublicKey(
'mplAsset',
'ASSETp3DinZKfiAyvdQG16YWWLJ2X3ZKjg9zku7n1sZD'
if (!resolvedAccounts.mplCoreProgram.value) {
resolvedAccounts.mplCoreProgram.value = context.programs.getPublicKey(
'mplCore',
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL'
);
resolvedAccounts.assetProgram.isWritable = false;
resolvedAccounts.mplCoreProgram.isWritable = false;
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
Expand Down
16 changes: 8 additions & 8 deletions clients/js/src/generated/instructions/mintV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type MintV2InstructionAccounts = {
*
*/

assetProgram?: PublicKey | Pda;
mplCoreProgram?: PublicKey | Pda;
/** SPL Token program. */
splTokenProgram?: PublicKey | Pda;
/** SPL Associated Token program. */
Expand Down Expand Up @@ -205,10 +205,10 @@ export function mintV2(
isWritable: false,
value: input.tokenMetadataProgram ?? null,
},
assetProgram: {
mplCoreProgram: {
index: 10,
isWritable: false,
value: input.assetProgram ?? null,
value: input.mplCoreProgram ?? null,
},
splTokenProgram: {
index: 11,
Expand Down Expand Up @@ -282,12 +282,12 @@ export function mintV2(
);
resolvedAccounts.tokenMetadataProgram.isWritable = false;
}
if (!resolvedAccounts.assetProgram.value) {
resolvedAccounts.assetProgram.value = context.programs.getPublicKey(
'mplAsset',
'ASSETp3DinZKfiAyvdQG16YWWLJ2X3ZKjg9zku7n1sZD'
if (!resolvedAccounts.mplCoreProgram.value) {
resolvedAccounts.mplCoreProgram.value = context.programs.getPublicKey(
'mplCore',
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL'
);
resolvedAccounts.assetProgram.isWritable = false;
resolvedAccounts.mplCoreProgram.isWritable = false;
}
if (!resolvedAccounts.splTokenProgram.value) {
resolvedAccounts.splTokenProgram.value = context.programs.getPublicKey(
Expand Down
Loading

0 comments on commit 6a23e2c

Please sign in to comment.