Skip to content

Commit

Permalink
dep update
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Mar 28, 2024
1 parent 1a549c1 commit 5b24af6
Show file tree
Hide file tree
Showing 40 changed files with 236 additions and 177 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Metaplex Candy Machine

# Docs/readmes inside this repo are not up to date, check the tests for usage examples
# Docs/readmes inside this repo are not up to date, for glass chewers check the tests for usage examples

The Metaplex Protocol Candy Machine is the leading minting and distribution program for fair NFT collection launches on Solana. It allows creators to bring their digital assets on-chain in a secure and customisable way.

Expand Down
2 changes: 1 addition & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"license": "Apache-2.0",
"peerDependencies": {
"@metaplex-foundation/umi": ">= 0.8.2 < 1",
"@metaplex-foundation/mpl-core": "^0.1.0"
"@metaplex-foundation/mpl-core": "^0.3.0"
},
"dependencies": {
"@metaplex-foundation/mpl-token-metadata": "3.0.0-alpha.27",
Expand Down
30 changes: 15 additions & 15 deletions clients/js/pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion clients/js/src/createCandyMachineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const createCandyMachineV2 = async (
): Promise<TransactionBuilder> => {
const space = getCandyMachineSize(
input.itemsAvailable,
input.configLineSettings ?? none(),
input.configLineSettings ?? none()
);
const lamports = await context.rpc.getRent(space);
return transactionBuilder()
Expand Down
4 changes: 1 addition & 3 deletions clients/js/src/createLutForCandyMachine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
getMplTokenMetadataProgramId,
} from '@metaplex-foundation/mpl-token-metadata';
import { getMplTokenMetadataProgramId } from '@metaplex-foundation/mpl-token-metadata';
import {
createLut,
getSysvar,
Expand Down
11 changes: 3 additions & 8 deletions clients/js/src/defaultGuards/freezeSolPayment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
getSplSystemProgramId,
} from '@metaplex-foundation/mpl-toolbox';
import { getSplSystemProgramId } from '@metaplex-foundation/mpl-toolbox';
import { PublicKey, Signer } from '@metaplex-foundation/umi';
import { tuple, u64 } from '@metaplex-foundation/umi/serializers';
import { getMplCoreProgramId } from '@metaplex-foundation/mpl-core';
Expand Down Expand Up @@ -44,9 +42,7 @@ export const freezeSolPaymentGuardManifest: GuardManifest<

return {
data: new Uint8Array(),
remainingAccounts: [
{ publicKey: freezeEscrow, isWritable: true },
],
remainingAccounts: [{ publicKey: freezeEscrow, isWritable: true }],
};
},
routeParser: (context, routeContext, args) => {
Expand All @@ -70,8 +66,7 @@ export const freezeSolPaymentGuardManifest: GuardManifest<
export type FreezeSolPaymentMintArgs = Omit<
FreezeSolPaymentArgs,
'lamports'
> & {
};
> & {};

/**
* The settings for the freezeSolPayment guard that should be provided
Expand Down
5 changes: 2 additions & 3 deletions clients/js/src/defaultGuards/freezeTokenPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const freezeTokenPaymentGuardManifest: GuardManifest<
{ publicKey: freezeEscrow, isWritable: true },
{ publicKey: tokenAddress, isWritable: true },
{ publicKey: freezeAta, isWritable: true },
{ publicKey: getSplTokenProgramId(context), isWritable: false}
{ publicKey: getSplTokenProgramId(context), isWritable: false },
],
};
},
Expand All @@ -84,8 +84,7 @@ export const freezeTokenPaymentGuardManifest: GuardManifest<
export type FreezeTokenPaymentMintArgs = Omit<
FreezeTokenPaymentArgs,
'amount'
> & {
};
> & {};

/**
* The settings for the freezeTokenPayment guard that should be provided
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,4 +1,7 @@
import { findAssociatedTokenPda, getSplTokenProgramId } from '@metaplex-foundation/mpl-toolbox';
import {
findAssociatedTokenPda,
getSplTokenProgramId,
} from '@metaplex-foundation/mpl-toolbox';
import {
findMasterEditionPda,
findMetadataPda,
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/defaultGuards/nftPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const nftPaymentGuardManifest: GuardManifest<
{
publicKey: getMplTokenMetadataProgramId(context),
isWritable: false,
}
},
];

if (isProgrammable(args.tokenStandard)) {
Expand Down
5 changes: 4 additions & 1 deletion clients/js/src/defaultGuards/tokenBurn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { findAssociatedTokenPda, getSplTokenProgramId } 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
5 changes: 4 additions & 1 deletion clients/js/src/defaultGuards/tokenPayment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { findAssociatedTokenPda, getSplTokenProgramId } from '@metaplex-foundation/mpl-toolbox';
import {
findAssociatedTokenPda,
getSplTokenProgramId,
} from '@metaplex-foundation/mpl-toolbox';
import {
getTokenPaymentSerializer,
TokenPayment,
Expand Down
3 changes: 1 addition & 2 deletions clients/js/src/hooked/candyMachineAccountData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ export function getCandyMachineAccountDataSerializer(): Serializer<
['itemsLeftToMint', array(u32(), { size: itemsAvailable })],
]);

const [hiddenSection] =
hiddenSectionSerializer.deserialize(slice);
const [hiddenSection] = hiddenSectionSerializer.deserialize(slice);

const itemsLeftToMint = hiddenSection.itemsLeftToMint.slice(
0,
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const mplCandyMachine = (): UmiPlugin => ({
allocationGuardManifest,
token2022PaymentGuardManifest,
solFixedFeeGuardManifest,
nftMintLimitGuardManifest,
nftMintLimitGuardManifest
);
},
});
Expand Down
21 changes: 9 additions & 12 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
findMetadataPda,
verifyCollectionV1,
} from '@metaplex-foundation/mpl-token-metadata';
import {
import {
AssetV1,
fetchAssetV1,
createCollectionV1 as baseCreateCollection,
} from '@metaplex-foundation/mpl-core'
} from '@metaplex-foundation/mpl-core';
import {
createAssociatedToken,
createMint,
Expand Down Expand Up @@ -98,7 +98,7 @@ export const createCollection = async (
}).sendAndConfirm(umi);

return mint;
}
};

export const createCollectionNft = async (
umi: Umi,
Expand Down Expand Up @@ -246,7 +246,7 @@ export const defaultAssetData = () => ({
name: 'My Asset',
sellerFeeBasisPoints: percentAmount(10, 2),
uri: 'https://example.com/my-asset.json',
plugins: []
plugins: [],
});

export const defaultCandyMachineData = (
Expand Down Expand Up @@ -303,21 +303,17 @@ export const assertSuccessfulMint = async (
) => {
const mint = publicKey(input.mint);
const owner = publicKey(input.owner);
const {
name,
uri,
} = input;
const { name, uri } = input;

// Nft.

const nft = await fetchAssetV1(umi, mint)
const nft = await fetchAssetV1(umi, mint);

t.like(nft, <AssetV1>{
publicKey: publicKey(mint),
owner
owner,
});


// Name.
if (typeof name === 'string') t.is(nft.name, name);
else if (name !== undefined) t.regex(nft.name, name);
Expand Down Expand Up @@ -372,4 +368,5 @@ export const yesterday = (): DateTime => now() - 3600n * 24n;
export const tomorrow = (): DateTime => now() + 3600n * 24n;

// TODO move to mpl-core
export const isFrozen = (asset: AssetV1): boolean => asset.freezeDelegate?.frozen || false;
export const isFrozen = (asset: AssetV1): boolean =>
asset.freezeDelegate?.frozen || false;
6 changes: 1 addition & 5 deletions clients/js/test/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import {
GuardGroup,
GuardSet,
} from '../src';
import {
createCollection,
createUmi,
defaultCandyMachineData,
} from './_setup';
import { createCollection, createUmi, defaultCandyMachineData } from './_setup';

test('it can create a candy machine with an associated candy guard', async (t) => {
// Given an existing collection NFT.
Expand Down
7 changes: 1 addition & 6 deletions clients/js/test/createCandyMachineV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import {
Creator,
fetchCandyMachine,
} from '../src';
import {
createCollection,
createUmi,
defaultCandyMachineData,
} from './_setup';
import { createCollection, createUmi, defaultCandyMachineData } from './_setup';

test('it can create a candy machine using config line settings', async (t) => {
// Given an existing collection NFT.
Expand Down Expand Up @@ -230,4 +226,3 @@ test("it can create a candy machine that's bigger than 10Kb", async (t) => {
data: { itemsAvailable: 20000n },
});
});

6 changes: 2 additions & 4 deletions clients/js/test/createLutForCandyMachine.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-promise-executor-return */
import {
getMplTokenMetadataProgramId,
} from '@metaplex-foundation/mpl-token-metadata';
import { getMplTokenMetadataProgramId } from '@metaplex-foundation/mpl-token-metadata';
import {
getSplAssociatedTokenProgramId,
getSplTokenProgramId,
Expand Down Expand Up @@ -81,7 +79,7 @@ test('it can create a LUT for a candy machine v2', async (t) => {

// And we expect the mint builder to be smaller with the LUT.
const builderWithLut = builderWithoutLut.setAddressLookupTables([lut]);

// TODO actually compare real tx size
// const transactionSizeDifference =
// builderWithoutLut.getTransactionSize(umi) -
Expand Down
53 changes: 34 additions & 19 deletions clients/js/test/defaultGuards/freezeSolPayment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ test('it transfers SOL to an escrow account and freezes the NFT', async (t) => {
t.is(isFrozen(asset), true, 'NFT is frozen');

// And cannot be thawed since not all NFTs have been minted.
const promise = thawNft(umi, candyMachine, destination, mint.publicKey, collection);
const promise = thawNft(
umi,
candyMachine,
destination,
mint.publicKey,
collection
);
await t.throwsAsync(promise, { message: /ThawNotEnabled/ });

// And the treasury escrow received SOLs.
Expand Down Expand Up @@ -379,10 +385,9 @@ test('it can have multiple freeze escrow and reuse the same ones', async (t) =>
// Then all NFTs except for group D have been frozen.
const [tokenA, tokenB, tokenC, tokenD] = await Promise.all(
[mintA, mintB, mintC, mintD].map(
({ publicKey: mint }): Promise<AssetV1> =>
fetchAssetV1(umi, mint)
({ publicKey: mint }): Promise<AssetV1> => fetchAssetV1(umi, mint)
)
);
);

t.is(isFrozen(tokenA), true, 'NFT A is frozen');
t.is(isFrozen(tokenB), true, 'NFT B is frozen');
Expand Down Expand Up @@ -628,7 +633,13 @@ test('it transfers SOL to an escrow account and locks the Programmable NFT', asy
t.is(isFrozen(asset), true);

// And cannot be thawed since not all NFTs have been minted.
const promise = thawNft(umi, candyMachine, destination, mint.publicKey, collection);
const promise = thawNft(
umi,
candyMachine,
destination,
mint.publicKey,
collection
);
await t.throwsAsync(promise, { message: /ThawNotEnabled/ });

// And the treasury escrow received SOLs.
Expand Down Expand Up @@ -817,20 +828,24 @@ const thawNft = async (
destination: PublicKey,
asset: PublicKey,
collection: PublicKey,
group?: string,
) => {
await route(umi, {
candyMachine,
guard: 'freezeSolPayment',
group: group ? some(group) : none(),
routeArgs: {
path: 'thaw',
asset,
collection,
destination,
},
}).sendAndConfirm(umi);
};
group?: string
) =>
transactionBuilder()
.add(setComputeUnitLimit(umi, { units: 600_000 }))
.add(
route(umi, {
candyMachine,
guard: 'freezeSolPayment',
group: group ? some(group) : none(),
routeArgs: {
path: 'thaw',
asset,
collection,
destination,
},
})
)
.sendAndConfirm(umi);

const unlockFunds = async (
umi: Umi,
Expand Down
Loading

0 comments on commit 5b24af6

Please sign in to comment.