Skip to content

Commit

Permalink
Merge branch 'main' of github.com:soundxyz/sdk into pabloszx/create-s…
Browse files Browse the repository at this point in the history
…ound-edition-v2_1
  • Loading branch information
vigneshka committed Dec 21, 2023
2 parents fe2d21d + 4dce1f4 commit ccf7fdd
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilled-pants-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@soundxyz/legacy-sdk': minor
'@soundxyz/sdk': minor
---

Fix default salt for create
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
4 changes: 2 additions & 2 deletions packages/legacy-sdk/src/client/edition/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 23 additions & 4 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 @@ -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({
Expand All @@ -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,
},
],
Expand Down Expand Up @@ -302,7 +321,7 @@ export async function getExpectedEditionAddress<Client extends Pick<PublicClient
client: Client,
{ deployer, salt: customSalt }: GetExpectedEditionAddressParams,
): Promise<GetExpectedEditionAddressReturnType> {
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,
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 ccf7fdd

Please sign in to comment.