Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk changes for SuperMinterV2 #292

Merged
merged 17 commits into from
Dec 18, 2023
5 changes: 5 additions & 0 deletions .changeset/silly-pumpkins-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@soundxyz/legacy-sdk": patch
---

Remove keccak dependency
5 changes: 5 additions & 0 deletions .changeset/six-seas-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@soundxyz/sdk': minor
---

support SuperMinterV2
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"superjson": "^2.0.0",
"undici": "^5.26.3",
"valtio": "^1.11.2",
"viem": "^1.16.6",
"viem": "^1.20.0",
"wagmi": "^1.4.4",
"zod": "^3.22.4"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/legacy-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"tsc": "tsc -p tsconfig.build.json"
},
"dependencies": {
"keccak256": "^1.0.6",
"zod": "^3.22.4"
},
"devDependencies": {
Expand All @@ -57,10 +56,10 @@
"merkletreejs": "^0.3.10",
"require-env-variable": "^4.0.2",
"typescript": "5.2.2",
"viem": "^1.16.6"
"viem": "^1.20.0"
},
"peerDependencies": {
"viem": "^1.10.8"
"viem": "^1.20.0"
},
"publishConfig": {
"access": "public",
Expand Down
11 changes: 6 additions & 5 deletions packages/legacy-sdk/src/client/edition/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Address, type Chain } from 'viem'
import { encodeFunctionData } from 'viem/utils'
import { encodeFunctionData, keccak256, toHex } from 'viem/utils'
import { soundCreatorV1Abi } from '../../abi/sound-creator-v1'
import {
InvalidEditionMaxMintableError,
Expand All @@ -10,7 +10,7 @@ import {
} from '../../errors'
import type { ContractCall, EditionConfig, MintConfig, TransactionGasOptions } from '../../types'
import { editionInitFlags, MINTER_ROLE, NULL_ADDRESS, NULL_BYTES32, UINT32_MAX } from '../../utils/constants'
import { getSaltAsBytes32, retry } from '../../utils/helpers'
import { retry } from '../../utils/helpers'
import { SoundClientInstance } from '../instance'
import { soundEditionV1_2Abi } from '../../abi/sound-edition-v1_2'
import { rangeEditionMinterV2_1Abi } from '../../abi/range-edition-minter-v2_1'
Expand Down Expand Up @@ -50,7 +50,7 @@ async function createEditionHelper(
maxPriorityFeePerGas,
}

const formattedSalt = getSaltAsBytes32(customSalt || Math.random() * 1_000_000_000_000_000)
const formattedSalt = keccak256(toHex(customSalt || Math.random() * 1_000_000_000_000_000))

// Precompute the edition address.
const [editionAddress, _] = await retry(
Expand Down Expand Up @@ -352,15 +352,16 @@ export async function expectedEditionAddress(
}: {
creatorAddress: Address
},
{ deployer, salt }: { deployer: Address; salt: string | number },
{ 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 [editionAddress, exists] = await readContract({
abi: soundCreatorV1Abi,
address: creatorAddress,
functionName: 'soundEditionAddress',
args: [deployer, getSaltAsBytes32(salt)],
args: [deployer, formattedSalt],
})

return {
Expand Down
5 changes: 0 additions & 5 deletions packages/legacy-sdk/src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import keccak256 from 'keccak256'
import { isHex, type Hex } from 'viem'

export function isHexList(list: string[]): list is Hex[] {
return list.every((value) => isHex(value))
}

export function getSaltAsBytes32(salt: string | number) {
return `0x${keccak256(salt.toString()).toString('hex')}` as const
}

export function getLazyOption<T extends object>(option: T | (() => T | Promise<T>)) {
return typeof option === 'function' ? option() : option
}
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy-sdk/test/helpers/merkle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { keccak256 as solidityKeccak256 } from '@ethersproject/solidity'
import keccak256 from 'keccak256'
import keccak256 from 'viem/utils'
import { MerkleTree } from 'merkletreejs'
import { type Address, type Hex } from 'viem'

Expand Down
5 changes: 3 additions & 2 deletions packages/legacy-sdk/test/test-constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getSaltAsBytes32 } from '../src/utils/helpers'
import { keccak256, toHex } from 'viem/utils'

export const DEFAULT_SALT = keccak256(toHex(12345678))

export const DEFAULT_SALT = getSaltAsBytes32(12345678)
export const SOUND_FEE = 0
export const ONE_HOUR = 3600
export const PRICE = 420420420n
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@
"esbuild": "^0.19.4",
"prettier": "^3.0.3",
"typescript": "5.2.2",
"viem": "^1.16.6",
"viem": "^1.20.0",
"zod": "^3.22.4"
},
"peerDependencies": {
"viem": "^1.16.6",
"viem": "^1.20.0",
"zod": "^3.22.4"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const SUPER_MINTER_ADDRESS = '0x0000000000CF4558c36229ac0026ee16D3aE35Cd'
export const SUPER_MINTER_V1_ADDRESS = '0x0000000000CF4558c36229ac0026ee16D3aE35Cd'

export const SUPER_MINTER_ABI = [
export const SUPER_MINTER_V1_ABI = [
{ inputs: [], name: 'CallerNotDelegated', type: 'error' },
{ inputs: [], name: 'ExceedsMaxPerAccount', type: 'error' },
{ inputs: [], name: 'ExceedsMintSupply', type: 'error' },
Expand Down Expand Up @@ -981,3 +981,9 @@ export const SUPER_MINTER_ABI = [
},
{ stateMutability: 'payable', type: 'receive' },
] as const

export const SUPER_MINTER_V1 = {
version: '1',
address: SUPER_MINTER_V1_ADDRESS,
abi: SUPER_MINTER_V1_ABI,
} as const
Loading
Loading