Skip to content

Commit

Permalink
Merge pull request #152 from rabbitholegg/mmackz-zora-batchmint-fix
Browse files Browse the repository at this point in the history
fix(zora): fix overindexing issue with batchmint function
  • Loading branch information
mmackz authored Dec 28, 2023
2 parents 22c4f2c + 7111a23 commit ab22d36
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-pumas-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-zora": patch
---

fix overindexing issue with batchmint
62 changes: 59 additions & 3 deletions packages/zora/src/Zora.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ 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_1155, ZORA_MINTER_ABI_721 } from './abi'
import {
ZORA_MINTER_ABI_1155,
ZORA_MINTER_ABI_721,
UNIVERSAL_MINTER_ABI,
} from './abi'

describe('Given the zora plugin', () => {
describe('When handling the mint', () => {
Expand All @@ -21,7 +25,59 @@ describe('Given the zora plugin', () => {
input: {
$or: [
{
$abiAbstract: ZORA_MINTER_ABI_721,
$abiAbstract: UNIVERSAL_MINTER_ABI,
_targets: {
$some: '0xfFF631EF40557f8705e89053aF794a1DCFA0A90b',
},
_calldatas: {
$some: {
$or: [
{
$abi: ZORA_MINTER_ABI_721,
$and: [
{
$or: [
{
recipient:
'0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
tokenRecipient:
'0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
],
},
],
},
{
$abi: ZORA_MINTER_ABI_1155,
$and: [
{
$or: [
{
recipient:
'0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
tokenRecipient:
'0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
{
to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367',
},
],
},
],
},
],
},
},
},
{
$abi: ZORA_MINTER_ABI_721,
$and: [
{
$or: [
Expand All @@ -40,7 +96,7 @@ describe('Given the zora plugin', () => {
],
},
{
$abiAbstract: ZORA_MINTER_ABI_1155,
$abi: ZORA_MINTER_ABI_1155,
$and: [
{
$or: [
Expand Down
34 changes: 26 additions & 8 deletions packages/zora/src/Zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {
compressJson,
} from '@rabbitholegg/questdk'
import { zoraUniversalMinterAddress } from '@zoralabs/universal-minter'
import { type Address } from 'viem'
import { type Address, getAddress } from 'viem'
import { CHAIN_ID_ARRAY } from './chain-ids'
import { ZORA_MINTER_ABI_1155, ZORA_MINTER_ABI_721 } from './abi'
import {
UNIVERSAL_MINTER_ABI,
ZORA_MINTER_ABI_1155,
ZORA_MINTER_ABI_721,
} from './abi'
import type { Chains } from './utils'

export const mint = async (
Expand Down Expand Up @@ -40,19 +44,33 @@ export const mint = async (
})
}

const ERC721_FILTER = {
$abi: ZORA_MINTER_ABI_721,
$and: andArray721.length !== 0 ? andArray721 : undefined,
}

const ERC1155_FILTER = {
$abi: ZORA_MINTER_ABI_1155,
$and: andArray1155.length !== 0 ? andArray1155 : undefined,
}

return compressJson({
chainId,
to: mintContract,
input: {
$or: [
{
$abiAbstract: ZORA_MINTER_ABI_721,
$and: andArray721.length !== 0 ? andArray721 : undefined,
},
{
$abiAbstract: ZORA_MINTER_ABI_1155,
$and: andArray1155.length !== 0 ? andArray1155 : undefined,
// batchmint function
$abiAbstract: UNIVERSAL_MINTER_ABI,
_targets: { $some: getAddress(contractAddress) },
_calldatas: {
$some: {
$or: [ERC721_FILTER, ERC1155_FILTER],
},
},
},
ERC721_FILTER,
ERC1155_FILTER,
],
},
})
Expand Down
7 changes: 5 additions & 2 deletions packages/zora/src/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ export const ZORA_MINTER_ABI_1155 = [
stateMutability: 'payable',
type: 'function',
}, // Legacy SoundEditionV1_2
]

export const UNIVERSAL_MINTER_ABI = [
{
inputs: [
{ internalType: 'address[]', name: '_targets', type: 'address[]' },
Expand All @@ -347,5 +350,5 @@ export const ZORA_MINTER_ABI_1155 = [
outputs: [],
stateMutability: 'payable',
type: 'function',
}, // universal batch mint
]
},
] // universal batch mint
22 changes: 22 additions & 0 deletions packages/zora/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export const passingTestCases = [
createTestCase(MINT_WITH_REWARDS, 'when contractAddress is checksummed', {
contractAddress: getAddress(MINT_WITH_REWARDS.params.contractAddress),
}),
createTestCase(MINT_BATCH_WITHOUT_FEES, 'using "any tokenId" on batchmint', {
tokenId: undefined,
amount: undefined,
}),
createTestCase(MINT_WITH_REWARDS, 'using "any tokenId" on single mint', {
tokenId: undefined,
amount: undefined,
}),
]

export const failingTestCases = [
Expand All @@ -33,4 +41,18 @@ export const failingTestCases = [
createTestCase(MINT_WITH_REWARDS_1155, 'when amount is incorrect', {
amount: '72',
}),
createTestCase(
MINT_BATCH_WITHOUT_FEES,
'when using batchMint and contractAddress is incorrect',
{
contractAddress: '0x4f330940159fB3368F5b06b34212C0cDB4e2C032',
},
),
createTestCase(
MINT_BATCH_WITHOUT_FEES,
'when using batchMint and tokenId is incorrect',
{
tokenId: 10,
},
),
]

0 comments on commit ab22d36

Please sign in to comment.