Skip to content

Commit

Permalink
Add support for Platform Airdrop schedule mode (#302)
Browse files Browse the repository at this point in the history
* Add support for Platform Airdrop schedule mode

* guard
  • Loading branch information
PabloSzx authored Dec 21, 2023
1 parent def1710 commit 6f7f687
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-lies-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@soundxyz/sdk': major
---

Add support for Platform Airdrop schedule mode
25 changes: 22 additions & 3 deletions packages/sdk/src/contract/edition-v2/read/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand All @@ -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,
},
],
Expand Down
56 changes: 49 additions & 7 deletions packages/sdk/src/contract/edition-v2/read/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -146,11 +158,41 @@ export async function mintingSchedules<Client extends Pick<PublicClient, 'readCo
args: [editionAddress],
})
.then((schedules) =>
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<SuperMinterSchedule, 'mode'>
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) => {
Expand Down

0 comments on commit 6f7f687

Please sign in to comment.