Skip to content

Commit 558a10a

Browse files
authored
Merge pull request #467 from rabbitholegg/mmackz/zora/amount-zero
fix(zora): amount zero fix
2 parents 1b8d7c0 + 3da6174 commit 558a10a

File tree

6 files changed

+59
-43
lines changed

6 files changed

+59
-43
lines changed

.changeset/little-insects-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rabbitholegg/questdk-plugin-zora": minor
3+
---
4+
5+
amount zero fix

packages/zora/src/Zora.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import {
1212
ZORA_1155_FACTORY,
1313
ZORA_DEPLOYER_ADDRESS,
1414
} from './contract-addresses'
15+
import { AndArrayItem } from './types'
1516
import { validatePremint } from './validate'
1617
import {
1718
type MintActionParams,
1819
type CreateActionParams,
1920
type TransactionFilter,
2021
compressJson,
2122
} from '@rabbitholegg/questdk'
23+
import { formatAmount } from '@rabbitholegg/questdk-plugin-utils'
2224
import {
2325
ActionType,
2426
DEFAULT_ACCOUNT,
@@ -105,8 +107,12 @@ export const mint = async (
105107
] as Address[])
106108
: contractAddress
107109

108-
const andArray721 = []
109-
const andArray1155 = []
110+
const quantityCheck = {
111+
quantity: formatAmount(amount),
112+
}
113+
const andArray721: AndArrayItem[] = [quantityCheck]
114+
const andArray1155: AndArrayItem[] = [quantityCheck]
115+
110116
if (recipient) {
111117
andArray721.push({
112118
$or: [{ recipient }, { tokenRecipient: recipient }, { to: recipient }],
@@ -115,34 +121,30 @@ export const mint = async (
115121
$or: [{ recipient }, { tokenRecipient: recipient }, { to: recipient }],
116122
})
117123
}
118-
if (tokenId || amount) {
119-
andArray721.push({
120-
quantity: amount,
121-
})
124+
if (tokenId) {
122125
andArray1155.push({
123-
quantity: amount,
124126
tokenId,
125127
})
126128
}
127129

128130
const ERC721_FILTER_ABSTRACT = {
129131
$abiAbstract: ZORA_MINTER_ABI_721,
130-
$and: andArray721.length !== 0 ? andArray721 : undefined,
132+
$and: andArray721,
131133
}
132134

133135
const ERC1155_FILTER_ABSTRACT = {
134136
$abiAbstract: ZORA_MINTER_ABI_1155.concat(ZORA_MINTER_ABI_1155_LEGACY),
135-
$and: andArray1155.length !== 0 ? andArray1155 : undefined,
137+
$and: andArray1155,
136138
}
137139

138140
const ERC721_FILTER = {
139141
$abi: ZORA_MINTER_ABI_721,
140-
$and: andArray721.length !== 0 ? andArray721 : undefined,
142+
$and: andArray721,
141143
}
142144

143145
const ERC1155_FILTER = {
144146
$abi: ZORA_MINTER_ABI_1155.concat(ZORA_MINTER_ABI_1155_LEGACY),
145-
$and: andArray1155.length !== 0 ? andArray1155 : undefined,
147+
$and: andArray1155,
146148
}
147149

148150
const UNIVERSAL_MINT_FILTER = {

packages/zora/src/abi.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -323,30 +323,6 @@ export const ZORA_MINTER_ABI_1155 = [
323323
stateMutability: 'payable',
324324
type: 'function',
325325
}, // ZoraCreator1155Impl,
326-
{
327-
inputs: [
328-
{
329-
internalType: 'address',
330-
name: 'tokenRecipient',
331-
type: 'address',
332-
},
333-
{
334-
internalType: 'string',
335-
name: 'message',
336-
type: 'string',
337-
},
338-
],
339-
name: 'purchase',
340-
outputs: [
341-
{
342-
internalType: 'uint256',
343-
name: 'tokenId',
344-
type: 'uint256',
345-
},
346-
],
347-
stateMutability: 'payable',
348-
type: 'function',
349-
}, // Legacy WritingEditions
350326
// https://github.com/soundxyz/sound-protocol/blob/0c29ae2f5ce2f27f3823cacf66b5180906070805/contracts/core/SoundEditionV1_2.sol#L274
351327
{
352328
inputs: [

packages/zora/src/test-setup.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import {
2-
BASIC_PURCHASE,
32
BATCH_MINT_ARB,
43
CREATE_COLLECTION_BASE,
54
CREATE_COLLECTION_ZORA,
65
LAYER_ZERO_MINT,
76
MINT_BATCH_WITHOUT_FEES,
87
MINT_WITH_REWARDS,
98
MINT_WITH_REWARDS_1155,
9+
ZERO_QUANTITY,
1010
} from './test-transactions'
1111
import { createTestCase } from '@rabbitholegg/questdk-plugin-utils'
1212
import { getAddress } from 'viem'
1313

1414
export const passingTestCasesMint = [
15-
createTestCase(BASIC_PURCHASE, 'when doing a basic purchase'),
1615
createTestCase(MINT_WITH_REWARDS, 'Minting with rewards'),
1716
createTestCase(MINT_WITH_REWARDS_1155, 'Minting with rewards 1155'),
1817
createTestCase(MINT_BATCH_WITHOUT_FEES, 'When using the batch mint function'),
@@ -32,13 +31,13 @@ export const passingTestCasesMint = [
3231
]
3332

3433
export const failingTestCasesMint = [
35-
createTestCase(BASIC_PURCHASE, 'when chainId is incorrect', {
36-
chainId: 1,
34+
createTestCase(MINT_WITH_REWARDS, 'when chainId is incorrect', {
35+
chainId: 10,
3736
}),
38-
createTestCase(BASIC_PURCHASE, 'when contractAddress is incorrect', {
39-
contractAddress: '0x4f330940159fB3368F5b06b34212C0cDB4e2C032',
37+
createTestCase(MINT_WITH_REWARDS, 'when contractAddress is incorrect', {
38+
contractAddress: '0x323c74b3dae9844c113d41e9c3db2743c500a26d',
4039
}),
41-
createTestCase(BASIC_PURCHASE, 'when recipient is incorrect', {
40+
createTestCase(MINT_WITH_REWARDS, 'when recipient is incorrect', {
4241
recipient: '0xd31143Ca8503b25DdE780dc1B92E9aA61D0E326d',
4342
}),
4443
createTestCase(MINT_WITH_REWARDS_1155, 'when tokenId is incorrect', {
@@ -61,6 +60,7 @@ export const failingTestCasesMint = [
6160
tokenId: 10,
6261
},
6362
),
63+
createTestCase(ZERO_QUANTITY, 'when quantity minted is 0'),
6464
]
6565

6666
export const passingTestCasesCreate = [

packages/zora/src/test-transactions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ export const MINT_BATCH_WITHOUT_FEES: TestParams<MintActionParams> = {
7474
},
7575
}
7676

77+
export const ZERO_QUANTITY: TestParams<MintActionParams> = {
78+
transaction: {
79+
chainId: 10, // Optimism
80+
from: '0x1671b592610fb7427ed788b66fa3e9217ff41047',
81+
to: '0x025b81bfcb62a02b7bd47520e0a28bbe5c5b262b',
82+
hash: '0xc80ab930d86db58afbf4aa52b37e96d6ef041f0b51491a76ff38df8faee373e0',
83+
input:
84+
'0x9dbb844d0000000000000000000000003678862f04290e565cca2ef163baeb92bb76790c0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000f3d63166f0ca56c3c1a3508fce03ff0cf3fb691e000000000000000000000000000000000000000000000000000000000000006000000000000000000000000010a1db5d3a971cf1e565b28a86d5ce9e576a7b81000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000001d4da48b243cb5c30214f47d',
85+
value: '0',
86+
},
87+
params: {
88+
chainId: Chains.OPTIMISM,
89+
contractAddress: '0x025b81bfcb62a02b7bd47520e0a28bbe5c5b262b',
90+
tokenId: 1,
91+
},
92+
}
93+
7794
export const EXPECTED_ENCODED_DATA_721 =
7895
'0xefef39a1000000000000000000000000000000000000000000000000000000000000000a'
7996
export const EXPECTED_ENCODED_DATA_1155 =

packages/zora/src/types.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { z } from 'zod'
2-
import { EthAddressSchema } from '@rabbitholegg/questdk-plugin-utils'
2+
import {
3+
type FilterOperator,
4+
EthAddressSchema,
5+
} from '@rabbitholegg/questdk-plugin-utils'
36

47
export const PremintResponseSchema = z.array(
58
z.object({
@@ -33,3 +36,16 @@ export const PremintResponseSchema = z.array(
3336
}),
3437
)
3538
export type PremintResponse = z.infer<typeof PremintResponseSchema>
39+
40+
type RecipientCondition = {
41+
$or: Array<{
42+
recipient?: string
43+
tokenRecipient?: string
44+
to?: string
45+
}>
46+
}
47+
48+
export type AndArrayItem =
49+
| { quantity: string | number | bigint | FilterOperator }
50+
| RecipientCondition
51+
| { tokenId: string | number }

0 commit comments

Comments
 (0)