Skip to content

Commit

Permalink
Merge pull request #134 from rabbitholegg/zora_721_hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Quazia authored Dec 16, 2023
2 parents 53c0c2d + 956d05d commit ff83a19
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-kiwis-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-zora": minor
---

Fix issues with 721 vs 1155 collections and empty $and array
42 changes: 33 additions & 9 deletions packages/zora/src/Zora.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest'
import { failingTestCases, passingTestCases } from './test-setup'
import { BASIC_PURCHASE } from './test-transactions'
import { mint } from './Zora'
import { ZORA_MINTER_ABI } from './abi'
import { ZORA_MINTER_ABI_1155, ZORA_MINTER_ABI_721 } from './abi'

describe('Given the zora plugin', () => {
describe('When handling the mint', () => {
Expand All @@ -19,18 +19,42 @@ describe('Given the zora plugin', () => {
],
},
input: {
$abiAbstract: ZORA_MINTER_ABI,
$and: [
$or: [
{
$or: [
{
recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
$abiAbstract: ZORA_MINTER_ABI_721,
$and: [
{
tokenRecipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
$or: [
{
recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
tokenRecipient:
'0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
],
},
],
},
{
$abiAbstract: ZORA_MINTER_ABI_1155,
$and: [
{
to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
$or: [
{
recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
tokenRecipient:
'0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
],
},
],
},
Expand Down
27 changes: 21 additions & 6 deletions packages/zora/src/Zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { zoraUniversalMinterAddress } from '@zoralabs/universal-minter'
import { type Address } from 'viem'
import { CHAIN_ID_ARRAY } from './chain-ids'
import { ZORA_MINTER_ABI } from './abi'
import { ZORA_MINTER_ABI_1155, ZORA_MINTER_ABI_721 } from './abi'
import type { Chains } from './utils'

export const mint = async (
Expand All @@ -22,14 +22,21 @@ export const mint = async (
? { $or: [contractAddress.toLowerCase(), universalMinter] }
: contractAddress

const andArray = []
const andArray721 = []
const andArray1155 = []
if (recipient) {
andArray.push({
andArray721.push({
$or: [{ recipient }, { tokenRecipient: recipient }, { to: recipient }],
})
andArray1155.push({
$or: [{ recipient }, { tokenRecipient: recipient }, { to: recipient }],
})
}
if (tokenId || amount) {
andArray.push({
andArray721.push({
quantity: amount,
})
andArray1155.push({
quantity: amount,
tokenId,
})
Expand All @@ -39,8 +46,16 @@ export const mint = async (
chainId,
to: mintContract,
input: {
$abiAbstract: ZORA_MINTER_ABI,
$and: andArray,
$or: [
{
$abiAbstract: ZORA_MINTER_ABI_721,
$and: andArray721.length !== 0 ? andArray721 : undefined,
},
{
$abiAbstract: ZORA_MINTER_ABI_1155,
$and: andArray1155.length !== 0 ? andArray1155 : undefined,
},
],
},
})
}
Expand Down
5 changes: 4 additions & 1 deletion packages/zora/src/abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ZORA_MINTER_ABI = [
export const ZORA_MINTER_ABI_721 = [
// https://github.com/ourzora/zora-721-contracts/blob/main/src/ERC721Drop.sol#L384
{
inputs: [
Expand Down Expand Up @@ -224,6 +224,9 @@ export const ZORA_MINTER_ABI = [
type: 'function',
}, // ERC721Drop
// https://github.com/ourzora/zora-protocol/blob/8d1fe9bdd79a552a8f74b4712451185f6aebf9a0/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol#L427
]

export const ZORA_MINTER_ABI_1155 = [
{
inputs: [
{
Expand Down

0 comments on commit ff83a19

Please sign in to comment.