Skip to content

Commit

Permalink
new core packages, allow starting edition number
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Apr 10, 2024
1 parent f6aad94 commit 25804d9
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 30 deletions.
4 changes: 2 additions & 2 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"author": "Metaplex Maintainers <[email protected]>",
"license": "Apache-2.0",
"peerDependencies": {
"@metaplex-foundation/mpl-core": ">= 0.4.3 < 1",
"@metaplex-foundation/mpl-core": ">= 0.4.5 < 1",
"@metaplex-foundation/umi": ">= 0.8.2 < 1"
},
"dependencies": {
Expand All @@ -37,7 +37,7 @@
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@identity.com/solana-gateway-ts": "^0.12.0",
"@metaplex-foundation/mpl-core": "^0.4.3",
"@metaplex-foundation/mpl-core": "^0.4.5",
"@metaplex-foundation/mpl-token-auth-rules": "^1.2.0",
"@metaplex-foundation/umi": "^0.8.2",
"@metaplex-foundation/umi-bundle-tests": "^0.8.2",
Expand Down
8 changes: 4 additions & 4 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/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const CANDY_MACHINE_HIDDEN_SECTION =
8 + // max supply
1 + // is mutable
1 + // option (edition start)
8 + // edition start
4 + // edition start
1 + // option (config lines settings)
4 +
MAX_NAME_LENGTH + // u32 + max name length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
mapSerializer,
option,
struct,
u32,
u64,
u8,
} from '@metaplex-foundation/umi/serializers';
Expand Down Expand Up @@ -108,7 +109,7 @@ export type InitializeCandyMachineV2InstructionData = {
/** Indicates if the asset is mutable or not (default yes) */
isMutable: boolean;
/** Edition number to start minting at (none is 0) */
editionStartingNumber: Option<bigint>;
editionStartingNumber: Option<number>;
/** Config line settings */
configLineSettings: Option<ConfigLineSettings>;
/** Hidden setttings */
Expand All @@ -124,7 +125,7 @@ export type InitializeCandyMachineV2InstructionDataArgs = {
/** Indicates if the asset is mutable or not (default yes) */
isMutable?: boolean;
/** Edition number to start minting at (none is 0) */
editionStartingNumber?: OptionOrNullable<number | bigint>;
editionStartingNumber?: OptionOrNullable<number>;
/** Config line settings */
configLineSettings?: OptionOrNullable<ConfigLineSettingsArgs>;
/** Hidden setttings */
Expand All @@ -147,7 +148,7 @@ export function getInitializeCandyMachineV2InstructionDataSerializer(): Serializ
['itemsAvailable', u64()],
['maxEditionSupply', u64()],
['isMutable', bool()],
['editionStartingNumber', option(u64())],
['editionStartingNumber', option(u32())],
['configLineSettings', option(getConfigLineSettingsSerializer())],
['hiddenSettings', option(getHiddenSettingsSerializer())],
['mintType', getMintTypeSerializer()],
Expand Down
7 changes: 4 additions & 3 deletions clients/js/src/generated/types/candyMachineData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
bool,
option,
struct,
u32,
u64,
} from '@metaplex-foundation/umi/serializers';
import {
Expand All @@ -32,7 +33,7 @@ export type CandyMachineData = {
/** Indicates if the asset is mutable or not (default yes) */
isMutable: boolean;
/** Edition number to start minting at (none is 0) */
editionStartingNumber: Option<bigint>;
editionStartingNumber: Option<number>;
/** Config line settings */
configLineSettings: Option<ConfigLineSettings>;
/** Hidden setttings */
Expand All @@ -47,7 +48,7 @@ export type CandyMachineDataArgs = {
/** Indicates if the asset is mutable or not (default yes) */
isMutable: boolean;
/** Edition number to start minting at (none is 0) */
editionStartingNumber: OptionOrNullable<number | bigint>;
editionStartingNumber: OptionOrNullable<number>;
/** Config line settings */
configLineSettings: OptionOrNullable<ConfigLineSettingsArgs>;
/** Hidden setttings */
Expand All @@ -63,7 +64,7 @@ export function getCandyMachineDataSerializer(): Serializer<
['itemsAvailable', u64()],
['maxEditionSupply', u64()],
['isMutable', bool()],
['editionStartingNumber', option(u64())],
['editionStartingNumber', option(u32())],
['configLineSettings', option(getConfigLineSettingsSerializer())],
['hiddenSettings', option(getHiddenSettingsSerializer())],
],
Expand Down
4 changes: 2 additions & 2 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export const assertSuccessfulMint = async (
owner: PublicKey | Signer;
name?: string | RegExp;
uri?: string | RegExp;
edition?: number | bigint;
edition?: number;
}
) => {
const mint = publicKey(input.mint);
Expand All @@ -308,7 +308,7 @@ export const assertSuccessfulMint = async (
});

if (input.edition !== undefined) {
t.is(nft.edition?.number, BigInt(input.edition))
t.is(nft.edition?.number, input.edition)
}

// Name.
Expand Down
40 changes: 39 additions & 1 deletion clients/js/test/edition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,42 @@ test('it can mint edition from a candy machine using hidden settings', async (t)
edition: i,
});
}
});
});

test('it overflows when trying to mint editions out of bounds', async (t) => {
// Given a candy machine with hidden settings.
const umi = await createUmi();
const collection = (await createCollection(umi)).publicKey;
const { publicKey: candyMachine } = await createV2(umi, {
collection,
itemsAvailable: 100,
configLineSettings: none(),
mintType: MintType.CoreEdition,
hiddenSettings: {
name: 'Degen #$ID+1$',
uri: 'https://example.com/degen/$ID+1$',
hash: new Uint8Array(32),
},
guards: {},
editionStartingNumber: some(2**32 - 1)
});

// When we try to mint out of bounds.
const mint = generateSigner(umi);
const minter = generateSigner(umi);
const res = transactionBuilder()
.add(setComputeUnitLimit(umi, { units: 600_000 }))
.add(
mintV2(umi, {
candyMachine,
minter,
asset: mint,
collection,
})
)
.sendAndConfirm(umi);

// Then the mint failed.
// TODO propogate candy core errors through the guard correctly
await t.throwsAsync(res, {name: 'IncorrectOwner'})
})
2 changes: 1 addition & 1 deletion clients/js/test/updateCandyMachine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('it can update the data of a candy machine', async (t) => {
isSequential: false,
}),
hiddenSettings: none(),
editionStartingNumber: some(BigInt(1))
editionStartingNumber: some(1)
},
});
});
Expand Down
2 changes: 2 additions & 0 deletions configs/program-scripts/dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ if [ -z ${RPC+x} ]; then
RPC="https://api.mainnet-beta.solana.com"
fi

echo "dump using RPC: ${RPC}"

if [ -z "$OUTPUT" ]; then
echo "missing output directory"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion idls/candy_machine_core.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@
"Edition number to start minting at (none is 0)"
],
"type": {
"option": "u64"
"option": "u32"
}
},
{
Expand Down
4 changes: 3 additions & 1 deletion programs/candy-guard/Cargo.lock

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

2 changes: 1 addition & 1 deletion programs/candy-guard/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ arrayref = "0.3.6"
mpl-candy-guard-derive = { path = "../macro", version = "0.2.0" }
mpl-core-candy-machine-core = { path = "../../candy-machine-core/program", version = "0.2.0", features = ["cpi"] }
mpl-token-metadata = "3.2.1"
mpl-core = { path = "../../../../mpl-core/clients/rust", version = "0.4.0" }
mpl-core = { version = "0.4.3" }
solana-program = "~1.16.5"
spl-associated-token-account = { version = ">= 1.1.3, < 3.0", features = ["no-entrypoint"] }
spl-token = { version = ">= 3.5.0, < 5.0", features = ["no-entrypoint"] }
Expand Down
4 changes: 3 additions & 1 deletion programs/candy-machine-core/Cargo.lock

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

2 changes: 1 addition & 1 deletion programs/candy-machine-core/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ anchor-lang = "0.28.0"
arrayref = "0.3.6"
mpl-token-metadata = "3.2.1"
mpl-utils = { version = "0.3", default-features = false }
mpl-core = { path = "../../../../mpl-core/clients/rust", version = "0.4.0" }
mpl-core = { version = "0.4.3" }
solana-program = "~1.16.5"
spl-associated-token-account = { version = ">= 1.1.3, < 3.0", features = ["no-entrypoint"] }
spl-token = { version = ">= 3.5.0, < 5.0", features = ["no-entrypoint"] }
2 changes: 1 addition & 1 deletion programs/candy-machine-core/program/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub const HIDDEN_SECTION: usize = 8 // discriminator
+ 8 // max supply
+ 1 // is mutable
+ 1 // option (edition start)
+ 8 // edition start
+ 4 // edition start
+ 1 // option (config lines settings)
+ 4 + MAX_NAME_LENGTH // u32 + max name length
+ 4 // name length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use crate::{
AccountVersion, ApproveAssetDelegateHelperAccounts, MintType,
};

pub fn initialize_v2(ctx: Context<InitializeV2>, data: CandyMachineData, mint_type: MintType) -> Result<()> {
pub fn initialize_v2(
ctx: Context<InitializeV2>,
data: CandyMachineData,
mint_type: MintType,
) -> Result<()> {
let candy_machine_account = &mut ctx.accounts.candy_machine;

let candy_machine = CandyMachine {
Expand All @@ -20,13 +24,12 @@ pub fn initialize_v2(ctx: Context<InitializeV2>, data: CandyMachineData, mint_ty
items_redeemed: 0,
};


// validates the config lines settings
candy_machine.data.validate()?;

let mut struct_data = CandyMachine::discriminator().try_to_vec().unwrap();
struct_data.append(&mut candy_machine.try_to_vec().unwrap());

let mut account_data = candy_machine_account.data.borrow_mut();
account_data[0..struct_data.len()].copy_from_slice(&struct_data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,16 @@ fn create_and_mint(
.ok_or(CandyError::MissingInstructionsSysvar)?;

let plugins = if candy_machine.mint_type == MintType::CoreEdition {
let num: u32 = candy_machine
.items_redeemed
.try_into()
.map_err(|_| CandyError::NumericalOverflowError)?;

vec![PluginAuthorityPair {
plugin: Plugin::Edition(Edition {
number: candy_machine.items_redeemed + candy_machine.data.edition_starting_number.unwrap_or(0),
number: num
.checked_add(candy_machine.data.edition_starting_number.unwrap_or(0))
.ok_or(CandyError::NumericalOverflowError)?,
}),
authority: None,
}]
Expand Down
6 changes: 5 additions & 1 deletion programs/candy-machine-core/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ pub mod candy_machine_core {
/// 11. `[]` Instructions sysvar account
/// 12. `[optional]` Token Authorization Rules program
/// 13. `[optional]` Token authorization rules account
pub fn initialize_v2(ctx: Context<InitializeV2>, data: CandyMachineData, mint_type: MintType) -> Result<()> {
pub fn initialize_v2(
ctx: Context<InitializeV2>,
data: CandyMachineData,
mint_type: MintType,
) -> Result<()> {
instructions::initialize_v2(ctx, data, mint_type)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct CandyMachineData {
/// Indicates if the asset is mutable or not (default yes)
pub is_mutable: bool,
/// Edition number to start minting at (none is 0)
pub edition_starting_number: Option<u64>,
pub edition_starting_number: Option<u32>,
/// Config line settings
pub config_line_settings: Option<ConfigLineSettings>,
/// Hidden setttings
Expand Down

0 comments on commit 25804d9

Please sign in to comment.