Skip to content

Commit

Permalink
wip: new mpl core, all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Mar 7, 2024
1 parent 8427151 commit 51a8584
Show file tree
Hide file tree
Showing 50 changed files with 228 additions and 524 deletions.
2 changes: 1 addition & 1 deletion clients/js/src/defaultGuards/freezeSolPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const thawRouteInstruction: RouteParser<FreezeSolPaymentRouteArgsThaw> = (
const remainingAccounts: GuardRemainingAccount[] = [
{ publicKey: freezeEscrow, isWritable: true },
{ publicKey: args.asset, isWritable: true },
{ publicKey: args.collection, isWritable: false },
{ publicKey: args.collection, isWritable: true },
{ publicKey: getMplCoreProgramId(context), isWritable: false },
{ publicKey: getSplSystemProgramId(context), isWritable: false },
];
Expand Down
3 changes: 2 additions & 1 deletion clients/js/src/defaultGuards/freezeTokenPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const freezeTokenPaymentGuardManifest: GuardManifest<
{ publicKey: freezeEscrow, isWritable: true },
{ publicKey: tokenAddress, isWritable: true },
{ publicKey: freezeAta, isWritable: true },
{ publicKey: getSplTokenProgramId(context), isWritable: false}
],
};
},
Expand Down Expand Up @@ -238,7 +239,7 @@ const thawRouteInstruction: RouteParser<FreezeTokenPaymentRouteArgsThaw> = (
const remainingAccounts: GuardRemainingAccount[] = [
{ publicKey: freezeEscrow, isWritable: true },
{ publicKey: args.asset, isWritable: true },
{ publicKey: args.collection, isWritable: false },
{ publicKey: args.collection, isWritable: true },
{ publicKey: getMplCoreProgramId(context), isWritable: false },
{ publicKey: getSplSystemProgramId(context), isWritable: false },
];
Expand Down
5 changes: 4 additions & 1 deletion clients/js/src/defaultGuards/nftBurn.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
import { findAssociatedTokenPda, getSplTokenProgramId } from '@metaplex-foundation/mpl-toolbox';
import {
findMasterEditionPda,
findMetadataPda,
findTokenRecordPda,
getMplTokenMetadataProgramId,
isProgrammable,
TokenStandard,
} from '@metaplex-foundation/mpl-token-metadata';
Expand Down Expand Up @@ -47,6 +48,8 @@ export const nftBurnGuardManifest: GuardManifest<
{ publicKey: nftMasterEdition, isWritable: true },
{ publicKey: args.mint, isWritable: true },
{ publicKey: collectionMetadata, isWritable: true },
{ publicKey: getSplTokenProgramId(context), isWritable: false },
{ publicKey: getMplTokenMetadataProgramId(context), isWritable: false },
];

if (isProgrammable(args.tokenStandard)) {
Expand Down
10 changes: 10 additions & 0 deletions clients/js/src/defaultGuards/nftPayment.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {
findAssociatedTokenPda,
getSplAssociatedTokenProgramId,
getSplTokenProgramId,
} from '@metaplex-foundation/mpl-toolbox';
import {
findMasterEditionPda,
findMetadataPda,
findTokenRecordPda,
getMplTokenMetadataProgramId,
isProgrammable,
TokenStandard,
} from '@metaplex-foundation/mpl-token-metadata';
Expand Down Expand Up @@ -58,6 +60,14 @@ export const nftPaymentGuardManifest: GuardManifest<
publicKey: getSplAssociatedTokenProgramId(context),
isWritable: false,
},
{
publicKey: getSplTokenProgramId(context),
isWritable: false,
},
{
publicKey: getMplTokenMetadataProgramId(context),
isWritable: false,
}
];

if (isProgrammable(args.tokenStandard)) {
Expand Down
3 changes: 2 additions & 1 deletion clients/js/src/defaultGuards/tokenBurn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
import { findAssociatedTokenPda, getSplTokenProgramId } from '@metaplex-foundation/mpl-toolbox';
import { getTokenBurnSerializer, TokenBurn, TokenBurnArgs } from '../generated';
import { GuardManifest, noopParser } from '../guards';

Expand Down Expand Up @@ -28,6 +28,7 @@ export const tokenBurnGuardManifest: GuardManifest<
remainingAccounts: [
{ publicKey: tokenAccount, isWritable: true },
{ publicKey: args.mint, isWritable: true },
{ publicKey: getSplTokenProgramId(context), isWritable: false },
],
};
},
Expand Down
3 changes: 2 additions & 1 deletion clients/js/src/defaultGuards/tokenPayment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox';
import { findAssociatedTokenPda, getSplTokenProgramId } from '@metaplex-foundation/mpl-toolbox';
import {
getTokenPaymentSerializer,
TokenPayment,
Expand Down Expand Up @@ -32,6 +32,7 @@ export const tokenPaymentGuardManifest: GuardManifest<
remainingAccounts: [
{ publicKey: sourceAta, isWritable: true },
{ publicKey: args.destinationAta, isWritable: true },
{ publicKey: getSplTokenProgramId(context), isWritable: false },
],
};
},
Expand Down
89 changes: 8 additions & 81 deletions clients/js/src/generated/instructions/mintV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,18 @@ export type MintV2InstructionAccounts = {

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

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

tokenMetadataProgram?: PublicKey | Pda;
mplCoreProgram?: PublicKey | Pda;
/**
* Token Metadata program.
*
* SPL Token program.
* System program.
*/

mplCoreProgram?: PublicKey | Pda;
/** SPL Token program. */
splTokenProgram?: PublicKey | Pda;
/** SPL Associated Token program. */
splAtaProgram?: PublicKey | Pda;
/** System program. */
systemProgram?: PublicKey | Pda;
/**
* Instructions sysvar account.
Expand All @@ -109,18 +99,6 @@ export type MintV2InstructionAccounts = {
*/

recentSlothashes?: PublicKey | Pda;
/**
* Token Authorization Rules program.
*
*/

authorizationRulesProgram?: PublicKey | Pda;
/**
* Token Authorization rules account for the collection metadata (if any).
*
*/

authorizationRules?: PublicKey | Pda;
};

// Data.
Expand Down Expand Up @@ -195,56 +173,26 @@ export function mintV2(
minter: { index: 5, isWritable: true, value: input.minter ?? null },
asset: { index: 6, isWritable: true, value: input.asset ?? null },
collection: { index: 7, isWritable: true, value: input.collection ?? null },
collectionUpdateAuthority: {
index: 8,
isWritable: false,
value: input.collectionUpdateAuthority ?? null,
},
tokenMetadataProgram: {
index: 9,
isWritable: false,
value: input.tokenMetadataProgram ?? null,
},
mplCoreProgram: {
index: 10,
index: 8,
isWritable: false,
value: input.mplCoreProgram ?? null,
},
splTokenProgram: {
index: 11,
isWritable: false,
value: input.splTokenProgram ?? null,
},
splAtaProgram: {
index: 12,
isWritable: false,
value: input.splAtaProgram ?? null,
},
systemProgram: {
index: 13,
index: 9,
isWritable: false,
value: input.systemProgram ?? null,
},
sysvarInstructions: {
index: 14,
index: 10,
isWritable: false,
value: input.sysvarInstructions ?? null,
},
recentSlothashes: {
index: 15,
index: 11,
isWritable: false,
value: input.recentSlothashes ?? null,
},
authorizationRulesProgram: {
index: 16,
isWritable: false,
value: input.authorizationRulesProgram ?? null,
},
authorizationRules: {
index: 17,
isWritable: false,
value: input.authorizationRules ?? null,
},
};

// Arguments.
Expand Down Expand Up @@ -275,34 +223,13 @@ export function mintV2(
if (!resolvedAccounts.minter.value) {
resolvedAccounts.minter.value = context.identity;
}
if (!resolvedAccounts.tokenMetadataProgram.value) {
resolvedAccounts.tokenMetadataProgram.value = context.programs.getPublicKey(
'mplTokenMetadata',
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'
);
resolvedAccounts.tokenMetadataProgram.isWritable = false;
}
if (!resolvedAccounts.mplCoreProgram.value) {
resolvedAccounts.mplCoreProgram.value = context.programs.getPublicKey(
'mplCore',
'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL'
);
resolvedAccounts.mplCoreProgram.isWritable = false;
}
if (!resolvedAccounts.splTokenProgram.value) {
resolvedAccounts.splTokenProgram.value = context.programs.getPublicKey(
'splToken',
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
);
resolvedAccounts.splTokenProgram.isWritable = false;
}
if (!resolvedAccounts.splAtaProgram.value) {
resolvedAccounts.splAtaProgram.value = context.programs.getPublicKey(
'splAssociatedToken',
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'
);
resolvedAccounts.splAtaProgram.isWritable = false;
}
if (!resolvedAccounts.systemProgram.value) {
resolvedAccounts.systemProgram.value = context.programs.getPublicKey(
'splSystem',
Expand Down
7 changes: 3 additions & 4 deletions clients/js/src/generated/types/freezeTokenPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import {
*
* 0. `[writable]` Freeze PDA to receive the funds (seeds `["freeze_escrow",
* destination_ata pubkey, candy guard pubkey, candy machine pubkey]`).
* 1. `[]` Associate token account of the NFT (seeds `[payer pubkey, token
* program pubkey, nft mint pubkey]`).
* 2. `[writable]` Token account holding the required amount.
* 3. `[writable]` Associate token account of the Freeze PDA (seeds `[freeze PDA
* 1. `[writable]` Token account holding the required amount.
* 2. `[writable]` Associate token account of the Freeze PDA (seeds `[freeze PDA
* pubkey, token program pubkey, nft mint pubkey]`).
* 3. `[]` SPL Token program.
*/

export type FreezeTokenPayment = {
Expand Down
4 changes: 3 additions & 1 deletion clients/js/src/generated/types/nftBurn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import {
* 2. `[writeable]` Master Edition account of the NFT.
* 3. `[writeable]` Mint account of the NFT.
* 4. `[writeable]` Collection metadata account of the NFT.
* 5. `[writeable]` Token Record of the NFT (pNFT).
* 5. `[]` SPL token program.
* 6. `[]` Token Metadata program.
* 7. `[writeable]` Token Record of the NFT (pNFT).
*/

export type NftBurn = { requiredCollection: PublicKey };
Expand Down
12 changes: 7 additions & 5 deletions clients/js/src/generated/types/nftPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import {
* 3. `[]` Account to receive the NFT.
* 4. `[writeable]` Destination PDA key (seeds [destination pubkey, token program id, nft mint pubkey]).
* 5. `[]` spl-associate-token program ID.
* 6. `[]` Master edition (pNFT)
* 7. `[writable]` Owner token record (pNFT)
* 8. `[writable]` Destination token record (pNFT)
* 9. `[]` Token Authorization Rules program (pNFT)
* 10. `[]` Token Authorization Rules account (pNFT)
* 6. `[]` SPL token program.
* 7. `[]` Token Metadata program.
* 8. `[]` Master edition (pNFT)
* 9. `[writable]` Owner token record (pNFT)
* 10. `[writable]` Destination token record (pNFT)
* 11. `[]` Token Authorization Rules program (pNFT)
* 12. `[]` Token Authorization Rules account (pNFT)
*/

export type NftPayment = {
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/generated/types/tokenBurn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
*
* 0. `[writable]` Token account holding the required amount.
* 1. `[writable]` Token mint account.
* 2. `[]` SPL token program.
*/

export type TokenBurn = { amount: bigint; mint: PublicKey };
Expand Down
1 change: 1 addition & 0 deletions clients/js/src/generated/types/tokenPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
*
* 0. `[writable]` Token account holding the required amount.
* 1. `[writable]` Address of the ATA to receive the tokens.
* 2. `[]` SPL token program.
*/

export type TokenPayment = {
Expand Down
19 changes: 6 additions & 13 deletions clients/js/src/mintV2.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import {
getMintSize,
getTokenSize,
} from '@metaplex-foundation/mpl-toolbox';
import {
ACCOUNT_HEADER_SIZE,
Option,
OptionOrNullable,
TransactionBuilder,
isSigner,
none,
publicKey,
transactionBuilder,
} from '@metaplex-foundation/umi';
import { MASTER_EDITION_SIZE, METADATA_SIZE } from './constants';
import { DefaultGuardSetMintArgs } from './defaultGuards';
import {
MintV2InstructionAccounts,
Expand Down Expand Up @@ -79,13 +72,13 @@ export function mintV2<MA extends GuardSetMintArgs = DefaultGuardSetMintArgs>(
ix.instruction.keys.push(...keys);
ix.signers.push(...signers);
// TODO fix size calculation
ix.bytesCreatedOnChain =
METADATA_SIZE + MASTER_EDITION_SIZE + 2 * ACCOUNT_HEADER_SIZE;
// ix.bytesCreatedOnChain =
// METADATA_SIZE + MASTER_EDITION_SIZE + 2 * ACCOUNT_HEADER_SIZE;

if (isSigner(input.asset)) {
ix.bytesCreatedOnChain +=
getMintSize() + getTokenSize() + 2 * ACCOUNT_HEADER_SIZE;
}
// if (isSigner(input.asset)) {
// ix.bytesCreatedOnChain +=
// getMintSize() + getTokenSize() + 2 * ACCOUNT_HEADER_SIZE;
// }

return transactionBuilder([ix]);
}
1 change: 0 additions & 1 deletion clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ export const assertSuccessfulMint = async (

// Nft.

// TODO check plugins
const nft = await fetchAsset(umi, mint)

t.like(nft, <Asset>{
Expand Down
1 change: 0 additions & 1 deletion clients/js/test/createLutForCandyMachine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ test('it can create a LUT for a candy machine v2', async (t) => {
candyMachine,
asset: mint,
collection,
collectionUpdateAuthority: umi.identity.publicKey,
})
);

Expand Down
3 changes: 0 additions & 3 deletions clients/js/test/defaultGuards/addressGate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ test('it allows minting from a specific address only', async (t) => {
asset: mint,
minter: allowedAddress,
collection,
collectionUpdateAuthority: umi.identity.publicKey,
})
)
.sendAndConfirm(umi);
Expand Down Expand Up @@ -70,7 +69,6 @@ test('it forbids minting from anyone else', async (t) => {
asset: mint,
minter: unauthorizedMinter,
collection,
collectionUpdateAuthority: umi.identity.publicKey,
})
)
.sendAndConfirm(umi);
Expand Down Expand Up @@ -103,7 +101,6 @@ test('it charges a bot tax when trying to mint using the wrong address', async (
asset: mint,
minter: unauthorizedMinter,
collection,
collectionUpdateAuthority: umi.identity.publicKey,
})
)
.sendAndConfirm(umi);
Expand Down
Loading

0 comments on commit 51a8584

Please sign in to comment.