Skip to content

Commit 69a4e0f

Browse files
vigneshkaPabloSzx
andauthored
sdk changes for SuperMinterV2 (#292)
* support SuperMinterV1_1 * handle null case * export createTieredEditionArgs * fix salt * changeset * fix import * fix type * change address * return minter address * superminter v2 changes * fix type * improve typing * Update .changeset/six-seas-approve.md * save promise wrapper * refactor * Update .changeset/six-seas-approve.md * Create silly-pumpkins-prove.md --------- Co-authored-by: Pablo Sáez <pablosaez1995@gmail.com>
1 parent 1ea02a1 commit 69a4e0f

File tree

20 files changed

+1269
-152
lines changed

20 files changed

+1269
-152
lines changed

.changeset/silly-pumpkins-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@soundxyz/legacy-sdk": patch
3+
---
4+
5+
Remove keccak dependency

.changeset/six-seas-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@soundxyz/sdk': minor
3+
---
4+
5+
support SuperMinterV2

examples/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"superjson": "^2.0.0",
2222
"undici": "^5.26.3",
2323
"valtio": "^1.11.2",
24-
"viem": "^1.16.6",
24+
"viem": "^1.20.0",
2525
"wagmi": "^1.4.4",
2626
"zod": "^3.22.4"
2727
},

packages/legacy-sdk/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"tsc": "tsc -p tsconfig.build.json"
3737
},
3838
"dependencies": {
39-
"keccak256": "^1.0.6",
4039
"zod": "^3.22.4"
4140
},
4241
"devDependencies": {
@@ -57,10 +56,10 @@
5756
"merkletreejs": "^0.3.10",
5857
"require-env-variable": "^4.0.2",
5958
"typescript": "5.2.2",
60-
"viem": "^1.16.6"
59+
"viem": "^1.20.0"
6160
},
6261
"peerDependencies": {
63-
"viem": "^1.10.8"
62+
"viem": "^1.20.0"
6463
},
6564
"publishConfig": {
6665
"access": "public",

packages/legacy-sdk/src/client/edition/create.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type Address, type Chain } from 'viem'
2-
import { encodeFunctionData } from 'viem/utils'
2+
import { encodeFunctionData, keccak256, toHex } from 'viem/utils'
33
import { soundCreatorV1Abi } from '../../abi/sound-creator-v1'
44
import {
55
InvalidEditionMaxMintableError,
@@ -10,7 +10,7 @@ import {
1010
} from '../../errors'
1111
import type { ContractCall, EditionConfig, MintConfig, TransactionGasOptions } from '../../types'
1212
import { editionInitFlags, MINTER_ROLE, NULL_ADDRESS, NULL_BYTES32, UINT32_MAX } from '../../utils/constants'
13-
import { getSaltAsBytes32, retry } from '../../utils/helpers'
13+
import { retry } from '../../utils/helpers'
1414
import { SoundClientInstance } from '../instance'
1515
import { soundEditionV1_2Abi } from '../../abi/sound-edition-v1_2'
1616
import { rangeEditionMinterV2_1Abi } from '../../abi/range-edition-minter-v2_1'
@@ -50,7 +50,7 @@ async function createEditionHelper(
5050
maxPriorityFeePerGas,
5151
}
5252

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

5555
// Precompute the edition address.
5656
const [editionAddress, _] = await retry(
@@ -352,15 +352,16 @@ export async function expectedEditionAddress(
352352
}: {
353353
creatorAddress: Address
354354
},
355-
{ deployer, salt }: { deployer: Address; salt: string | number },
355+
{ deployer, salt: customSalt }: { deployer: Address; salt: string | number },
356356
) {
357357
const { readContract } = await this.expectClient()
358+
const formattedSalt = keccak256(toHex(customSalt || Math.random() * 1_000_000_000_000_000))
358359

359360
const [editionAddress, exists] = await readContract({
360361
abi: soundCreatorV1Abi,
361362
address: creatorAddress,
362363
functionName: 'soundEditionAddress',
363-
args: [deployer, getSaltAsBytes32(salt)],
364+
args: [deployer, formattedSalt],
364365
})
365366

366367
return {

packages/legacy-sdk/src/utils/helpers.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import keccak256 from 'keccak256'
21
import { isHex, type Hex } from 'viem'
32

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

8-
export function getSaltAsBytes32(salt: string | number) {
9-
return `0x${keccak256(salt.toString()).toString('hex')}` as const
10-
}
11-
127
export function getLazyOption<T extends object>(option: T | (() => T | Promise<T>)) {
138
return typeof option === 'function' ? option() : option
149
}

packages/legacy-sdk/test/helpers/merkle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { keccak256 as solidityKeccak256 } from '@ethersproject/solidity'
2-
import keccak256 from 'keccak256'
2+
import keccak256 from 'viem/utils'
33
import { MerkleTree } from 'merkletreejs'
44
import { type Address, type Hex } from 'viem'
55

packages/legacy-sdk/test/test-constants.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { getSaltAsBytes32 } from '../src/utils/helpers'
1+
import { keccak256, toHex } from 'viem/utils'
2+
3+
export const DEFAULT_SALT = keccak256(toHex(12345678))
24

3-
export const DEFAULT_SALT = getSaltAsBytes32(12345678)
45
export const SOUND_FEE = 0
56
export const ONE_HOUR = 3600
67
export const PRICE = 420420420n

packages/sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151
"esbuild": "^0.19.4",
5252
"prettier": "^3.0.3",
5353
"typescript": "5.2.2",
54-
"viem": "^1.16.6",
54+
"viem": "^1.20.0",
5555
"zod": "^3.22.4"
5656
},
5757
"peerDependencies": {
58-
"viem": "^1.16.6",
58+
"viem": "^1.20.0",
5959
"zod": "^3.22.4"
6060
},
6161
"publishConfig": {

packages/sdk/src/contract/edition-v2/abi/super-minter.ts renamed to packages/sdk/src/contract/edition-v2/abi/super-minter-v1.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export const SUPER_MINTER_ADDRESS = '0x0000000000CF4558c36229ac0026ee16D3aE35Cd'
1+
export const SUPER_MINTER_V1_ADDRESS = '0x0000000000CF4558c36229ac0026ee16D3aE35Cd'
22

3-
export const SUPER_MINTER_ABI = [
3+
export const SUPER_MINTER_V1_ABI = [
44
{ inputs: [], name: 'CallerNotDelegated', type: 'error' },
55
{ inputs: [], name: 'ExceedsMaxPerAccount', type: 'error' },
66
{ inputs: [], name: 'ExceedsMintSupply', type: 'error' },
@@ -981,3 +981,9 @@ export const SUPER_MINTER_ABI = [
981981
},
982982
{ stateMutability: 'payable', type: 'receive' },
983983
] as const
984+
985+
export const SUPER_MINTER_V1 = {
986+
version: '1',
987+
address: SUPER_MINTER_V1_ADDRESS,
988+
abi: SUPER_MINTER_V1_ABI,
989+
} as const

0 commit comments

Comments
 (0)