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/sdk/src/contract/edition-v2/read/create.ts b/packages/sdk/src/contract/edition-v2/read/create.ts index bdb551a0..7cbc6e4a 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' @@ -98,6 +98,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({ @@ -115,8 +135,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, }, ], 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) => {