diff --git a/.changeset/chilled-pants-compete.md b/.changeset/chilled-pants-compete.md new file mode 100644 index 00000000..3ae9f069 --- /dev/null +++ b/.changeset/chilled-pants-compete.md @@ -0,0 +1,6 @@ +--- +'@soundxyz/legacy-sdk': minor +'@soundxyz/sdk': minor +--- + +Fix default salt for create diff --git a/.changeset/loud-lies-juggle.md b/.changeset/loud-lies-juggle.md new file mode 100644 index 00000000..3df9b5da --- /dev/null +++ b/.changeset/loud-lies-juggle.md @@ -0,0 +1,5 @@ +--- +'@soundxyz/sdk': major +--- + +Add support for Platform Airdrop schedule mode diff --git a/packages/legacy-sdk/src/client/edition/create.ts b/packages/legacy-sdk/src/client/edition/create.ts index 64505675..d0a72f1a 100644 --- a/packages/legacy-sdk/src/client/edition/create.ts +++ b/packages/legacy-sdk/src/client/edition/create.ts @@ -50,7 +50,7 @@ async function createEditionHelper( maxPriorityFeePerGas, } - const formattedSalt = keccak256(toHex(customSalt || Math.random() * 1_000_000_000_000_000)) + const formattedSalt = keccak256(toHex(customSalt || Math.floor(Math.random() * 1_000_000_000_000_000))) // Precompute the edition address. const [editionAddress, _] = await retry( @@ -355,7 +355,7 @@ export async function expectedEditionAddress( { deployer, salt: customSalt }: { deployer: Address; salt: string | number }, ) { const { readContract } = await this.expectClient() - const formattedSalt = keccak256(toHex(customSalt || Math.random() * 1_000_000_000_000_000)) + const formattedSalt = keccak256(toHex(customSalt)) const [editionAddress, exists] = await readContract({ abi: soundCreatorV1Abi, diff --git a/packages/sdk/src/contract/edition-v2/read/create.ts b/packages/sdk/src/contract/edition-v2/read/create.ts index 9d85ceee..824113ce 100644 --- a/packages/sdk/src/contract/edition-v2/read/create.ts +++ b/packages/sdk/src/contract/edition-v2/read/create.ts @@ -11,7 +11,7 @@ import { } from 'viem' import { MINT_GAS_LIMIT_MULTIPLIER, UINT32_MAX } from '../../../utils/constants' import { InvalidUint32 } from '../../../utils/errors' -import { curry, scaleAmount } from '../../../utils/helpers' +import { curry, exhaustiveGuard, scaleAmount } from '../../../utils/helpers' import type { Prettify, TransactionGasOptions } from '../../../utils/types' import type { ContractCall } from '../../types' import { SPLIT_MAIN_ABI, SPLIT_MAIN_ADDRESS } from '../abi/external/split-main' @@ -99,6 +99,26 @@ export function createTieredEditionArgs({ }) } + const mode: number = (() => { + switch (mintConfig.mode) { + case 'DEFAULT': { + return 0 + } + case 'VERIFY_MERKLE': { + return 1 + } + case 'VERIFY_SIGNATURE': { + return 2 + } + case 'PLATFORM_AIRDROP': { + return 3 + } + default: { + exhaustiveGuard(mintConfig) + } + } + })() + contractCalls.push({ contractAddress: SUPER_MINTER_V2_ADDRESS, calldata: encodeFunctionData({ @@ -116,8 +136,7 @@ export function createTieredEditionArgs({ affiliateMerkleRoot: mintConfig.affiliateMerkleRoot, tier: mintConfig.tier, platform: mintConfig.platform, - // TODO: add better typesafety here - mode: mintConfig.mode === 'DEFAULT' ? 0 : mintConfig.mode === 'VERIFY_MERKLE' ? 1 : 2, + mode, merkleRoot: mintConfig.mode === 'VERIFY_MERKLE' ? mintConfig.merkleRoot : EMPTY_MERKLE_ROOT, }, ], @@ -302,7 +321,7 @@ export async function getExpectedEditionAddress { - const formattedSalt = keccak256(toHex(customSalt || Math.random() * 1_000_000_000_000_000)) + const formattedSalt = keccak256(toHex(customSalt || Math.floor(Math.random() * 1_000_000_000_000_000))) const [edition, exists] = await client.readContract({ abi: SOUND_CREATOR_V2_ABI, diff --git a/packages/sdk/src/contract/edition-v2/read/info.ts b/packages/sdk/src/contract/edition-v2/read/info.ts index d33de7a8..7f269baa 100644 --- a/packages/sdk/src/contract/edition-v2/read/info.ts +++ b/packages/sdk/src/contract/edition-v2/read/info.ts @@ -100,7 +100,16 @@ export type MerkleScheduleConfig = ScheduleConfigBase & { export type SignatureScheduleConfig = ScheduleConfigBase & { mode: 'VERIFY_SIGNATURE' } -export type MinterScheduleConfig = DefaultScheduleConfig | MerkleScheduleConfig | SignatureScheduleConfig + +export type PlatformAirdropScheduleConfig = ScheduleConfigBase & { + mode: 'PLATFORM_AIRDROP' +} + +export type MinterScheduleConfig = + | DefaultScheduleConfig + | MerkleScheduleConfig + | SignatureScheduleConfig + | PlatformAirdropScheduleConfig export type ScheduleBase = ScheduleConfigBase & { minterAddress: Address @@ -119,8 +128,11 @@ export type MerkleSchedule = ScheduleBase & { export type SignatureSchedule = ScheduleBase & { mode: 'VERIFY_SIGNATURE' } +export type PlatformAirdropSchedule = ScheduleBase & { + mode: 'PLATFORM_AIRDROP' +} -export type SuperMinterSchedule = DefaultSchedule | MerkleSchedule | SignatureSchedule +export type SuperMinterSchedule = DefaultSchedule | MerkleSchedule | SignatureSchedule | PlatformAirdropSchedule export type GetMintingSchedulesParams = { editionAddress: Address @@ -146,11 +158,41 @@ export async function mintingSchedules - schedules.map((schedule) => ({ - ...schedule, - mode: schedule.mode === 0 ? 'DEFAULT' : schedule.mode === 1 ? 'VERIFY_MERKLE' : 'VERIFY_SIGNATURE', - minterAddress: address, - })), + schedules.map((schedule): SuperMinterSchedule => { + const scheduleData = { + ...schedule, + minterAddress: address, + } satisfies Omit + switch (schedule.mode) { + case 0: { + return { + ...scheduleData, + mode: 'DEFAULT', + } + } + case 1: { + return { + ...scheduleData, + mode: 'VERIFY_MERKLE', + } + } + case 2: { + return { + ...scheduleData, + mode: 'VERIFY_SIGNATURE', + } + } + case 3: { + return { + ...scheduleData, + mode: 'PLATFORM_AIRDROP', + } + } + default: { + throw Error(`Unsupported schedule mode ${schedule.mode}`) + } + } + }), ) const activeSchedules = schedules.filter((mintSchedule) => {