From b86813f7edddd75f4edc67c0ab192505af790e48 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Fri, 22 Dec 2023 14:48:40 -0800 Subject: [PATCH 1/5] fix(zora): (WIP) fix batch int function --- packages/zora/src/Zora.test.ts | 128 ++++++++++++++++---------------- packages/zora/src/Zora.ts | 42 ++++++++++- packages/zora/src/abi.ts | 7 +- packages/zora/src/test-setup.ts | 12 +-- 4 files changed, 113 insertions(+), 76 deletions(-) diff --git a/packages/zora/src/Zora.test.ts b/packages/zora/src/Zora.test.ts index 0a0beaed3..0c6d73e7e 100644 --- a/packages/zora/src/Zora.test.ts +++ b/packages/zora/src/Zora.test.ts @@ -7,61 +7,61 @@ import { ZORA_MINTER_ABI_1155, ZORA_MINTER_ABI_721 } from './abi' describe('Given the zora plugin', () => { describe('When handling the mint', () => { - test('should return a valid action filter', async () => { - const { params } = BASIC_PURCHASE - const filter = await mint(params) - expect(filter).to.deep.equal({ - chainId: 10, - to: { - $or: [ - '0xfff631ef40557f8705e89053af794a1dcfa0a90b', - '0x97eb05b8db496b12244bccf17cf377d00a99b67a', - ], - }, - input: { - $or: [ - { - $abiAbstract: ZORA_MINTER_ABI_721, - $and: [ - { - $or: [ - { - recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - }, - { - tokenRecipient: - '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - }, - { - to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - }, - ], - }, - ], - }, - { - $abiAbstract: ZORA_MINTER_ABI_1155, - $and: [ - { - $or: [ - { - recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - }, - { - tokenRecipient: - '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - }, - { - to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - }, - ], - }, - ], - }, - ], - }, - }) - }) + // test('should return a valid action filter', async () => { + // const { params } = BASIC_PURCHASE + // const filter = await mint(params) + // expect(filter).to.deep.equal({ + // chainId: 10, + // to: { + // $or: [ + // '0xfff631ef40557f8705e89053af794a1dcfa0a90b', + // '0x97eb05b8db496b12244bccf17cf377d00a99b67a', + // ], + // }, + // input: { + // $or: [ + // { + // $abiAbstract: ZORA_MINTER_ABI_721, + // $and: [ + // { + // $or: [ + // { + // recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + // }, + // { + // tokenRecipient: + // '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + // }, + // { + // to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + // }, + // ], + // }, + // ], + // }, + // { + // $abiAbstract: ZORA_MINTER_ABI_1155, + // $and: [ + // { + // $or: [ + // { + // recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + // }, + // { + // tokenRecipient: + // '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + // }, + // { + // to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + // }, + // ], + // }, + // ], + // }, + // ], + // }, + // }) + // }) describe('should pass filter with valid transactions', () => { passingTestCases.forEach((testCase) => { @@ -73,14 +73,14 @@ describe('Given the zora plugin', () => { }) }) - describe('should not pass filter with invalid transactions', () => { - failingTestCases.forEach((testCase) => { - const { transaction, params, description } = testCase - test(description, async () => { - const filter = await mint(params) - expect(apply(transaction, filter)).to.be.false - }) - }) - }) + // describe('should not pass filter with invalid transactions', () => { + // failingTestCases.forEach((testCase) => { + // const { transaction, params, description } = testCase + // test(description, async () => { + // const filter = await mint(params) + // expect(apply(transaction, filter)).to.be.false + // }) + // }) + // }) }) }) diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index 3122f60cb..ed1703e27 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -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 ( @@ -45,12 +49,42 @@ export const mint = async ( to: mintContract, input: { $or: [ + + + { + $abiAbstract: UNIVERSAL_MINTER_ABI, + + // This only works if the contractAddress is the only one in the array. + // We need to find out if it is anywhere in the array. + // Tried using $some, but I couldnt get it to work. + _targets: [contractAddress], + + // Not sure if this also needs to use an array operator. It is an array of calldata (mintWithRewards function) + _calldatas: [ + { + $or: [ + { + $abiAbstract: ZORA_MINTER_ABI_1155, + quantity: amount, + tokenId + }, + { + $abiAbstract: ZORA_MINTER_ABI_721, + quantity: amount, + } + ] + } + + ] + }, + + { - $abiAbstract: ZORA_MINTER_ABI_721, + $abi: ZORA_MINTER_ABI_721, $and: andArray721.length !== 0 ? andArray721 : undefined, }, { - $abiAbstract: ZORA_MINTER_ABI_1155, + $abi: ZORA_MINTER_ABI_1155, $and: andArray1155.length !== 0 ? andArray1155 : undefined, }, ], diff --git a/packages/zora/src/abi.ts b/packages/zora/src/abi.ts index 03877b6a2..1bfb7fca2 100644 --- a/packages/zora/src/abi.ts +++ b/packages/zora/src/abi.ts @@ -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[]' }, @@ -347,5 +350,5 @@ export const ZORA_MINTER_ABI_1155 = [ outputs: [], stateMutability: 'payable', type: 'function', - }, // universal batch mint -] + }, +] // universal batch mint diff --git a/packages/zora/src/test-setup.ts b/packages/zora/src/test-setup.ts index 832366a5a..d3b7e28f3 100644 --- a/packages/zora/src/test-setup.ts +++ b/packages/zora/src/test-setup.ts @@ -8,13 +8,13 @@ import { } from './test-transactions' export const passingTestCases = [ - createTestCase(BASIC_PURCHASE, 'when doing a basic purchase'), - createTestCase(MINT_WITH_REWARDS, 'Minting with rewards'), - createTestCase(MINT_WITH_REWARDS_1155, 'Minting with rewards 1155'), + // createTestCase(BASIC_PURCHASE, 'when doing a basic purchase'), + // createTestCase(MINT_WITH_REWARDS, 'Minting with rewards'), + // createTestCase(MINT_WITH_REWARDS_1155, 'Minting with rewards 1155'), createTestCase(MINT_BATCH_WITHOUT_FEES, 'When using the batch mint function'), - createTestCase(MINT_WITH_REWARDS, 'when contractAddress is checksummed', { - contractAddress: getAddress(MINT_WITH_REWARDS.params.contractAddress), - }), + // createTestCase(MINT_WITH_REWARDS, 'when contractAddress is checksummed', { + // contractAddress: getAddress(MINT_WITH_REWARDS.params.contractAddress), + // }), ] export const failingTestCases = [ From ca0007cf6600c5fba528a4da79d6a627811b621a Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 27 Dec 2023 15:17:09 -0800 Subject: [PATCH 2/5] fix(zora): fix overindexing on batchmint issue --- packages/zora/src/Zora.ts | 54 ++++++++++++++------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index ed1703e27..dc64667ea 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -44,49 +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: [ - - { + // batchmint function $abiAbstract: UNIVERSAL_MINTER_ABI, - - // This only works if the contractAddress is the only one in the array. - // We need to find out if it is anywhere in the array. - // Tried using $some, but I couldnt get it to work. - _targets: [contractAddress], - - // Not sure if this also needs to use an array operator. It is an array of calldata (mintWithRewards function) - _calldatas: [ - { - $or: [ - { - $abiAbstract: ZORA_MINTER_ABI_1155, - quantity: amount, - tokenId - }, - { - $abiAbstract: ZORA_MINTER_ABI_721, - quantity: amount, - } - ] - } - - ] - }, - - - { - $abi: ZORA_MINTER_ABI_721, - $and: andArray721.length !== 0 ? andArray721 : undefined, - }, - { - $abi: ZORA_MINTER_ABI_1155, - $and: andArray1155.length !== 0 ? andArray1155 : undefined, + _targets: { $some: getAddress(contractAddress) }, + _calldatas: { + $some: { + $or: [ERC721_FILTER, ERC1155_FILTER], + }, + }, }, + ERC721_FILTER, + ERC1155_FILTER, ], }, }) From e1350e2b08c050d0b440fc7925efe75aca68b47f Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 27 Dec 2023 15:30:57 -0800 Subject: [PATCH 3/5] test(zora): add additional tests for batch mint function --- packages/zora/src/Zora.test.ts | 186 +++++++++++++++++++++----------- packages/zora/src/test-setup.ts | 20 ++-- 2 files changed, 135 insertions(+), 71 deletions(-) diff --git a/packages/zora/src/Zora.test.ts b/packages/zora/src/Zora.test.ts index 0c6d73e7e..641a927bc 100644 --- a/packages/zora/src/Zora.test.ts +++ b/packages/zora/src/Zora.test.ts @@ -3,65 +3,121 @@ 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', () => { - // test('should return a valid action filter', async () => { - // const { params } = BASIC_PURCHASE - // const filter = await mint(params) - // expect(filter).to.deep.equal({ - // chainId: 10, - // to: { - // $or: [ - // '0xfff631ef40557f8705e89053af794a1dcfa0a90b', - // '0x97eb05b8db496b12244bccf17cf377d00a99b67a', - // ], - // }, - // input: { - // $or: [ - // { - // $abiAbstract: ZORA_MINTER_ABI_721, - // $and: [ - // { - // $or: [ - // { - // recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - // }, - // { - // tokenRecipient: - // '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - // }, - // { - // to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - // }, - // ], - // }, - // ], - // }, - // { - // $abiAbstract: ZORA_MINTER_ABI_1155, - // $and: [ - // { - // $or: [ - // { - // recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - // }, - // { - // tokenRecipient: - // '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - // }, - // { - // to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', - // }, - // ], - // }, - // ], - // }, - // ], - // }, - // }) - // }) + test('should return a valid action filter', async () => { + const { params } = BASIC_PURCHASE + const filter = await mint(params) + expect(filter).to.deep.equal({ + chainId: 10, + to: { + $or: [ + '0xfff631ef40557f8705e89053af794a1dcfa0a90b', + '0x97eb05b8db496b12244bccf17cf377d00a99b67a', + ], + }, + input: { + $or: [ + { + $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: [ + { + recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + }, + { + tokenRecipient: + '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + }, + { + to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + }, + ], + }, + ], + }, + { + $abi: ZORA_MINTER_ABI_1155, + $and: [ + { + $or: [ + { + recipient: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + }, + { + tokenRecipient: + '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + }, + { + to: '0x628d4c61d81ac4f286b1778a063ed2f8810bc367', + }, + ], + }, + ], + }, + ], + }, + }) + }) describe('should pass filter with valid transactions', () => { passingTestCases.forEach((testCase) => { @@ -73,14 +129,14 @@ describe('Given the zora plugin', () => { }) }) - // describe('should not pass filter with invalid transactions', () => { - // failingTestCases.forEach((testCase) => { - // const { transaction, params, description } = testCase - // test(description, async () => { - // const filter = await mint(params) - // expect(apply(transaction, filter)).to.be.false - // }) - // }) - // }) + describe('should not pass filter with invalid transactions', () => { + failingTestCases.forEach((testCase) => { + const { transaction, params, description } = testCase + test(description, async () => { + const filter = await mint(params) + expect(apply(transaction, filter)).to.be.false + }) + }) + }) }) }) diff --git a/packages/zora/src/test-setup.ts b/packages/zora/src/test-setup.ts index d3b7e28f3..272ac3dd4 100644 --- a/packages/zora/src/test-setup.ts +++ b/packages/zora/src/test-setup.ts @@ -8,13 +8,15 @@ import { } from './test-transactions' export const passingTestCases = [ - // createTestCase(BASIC_PURCHASE, 'when doing a basic purchase'), - // createTestCase(MINT_WITH_REWARDS, 'Minting with rewards'), - // createTestCase(MINT_WITH_REWARDS_1155, 'Minting with rewards 1155'), + createTestCase(BASIC_PURCHASE, 'when doing a basic purchase'), + createTestCase(MINT_WITH_REWARDS, 'Minting with rewards'), + createTestCase(MINT_WITH_REWARDS_1155, 'Minting with rewards 1155'), createTestCase(MINT_BATCH_WITHOUT_FEES, 'When using the batch mint function'), - // createTestCase(MINT_WITH_REWARDS, 'when contractAddress is checksummed', { - // contractAddress: getAddress(MINT_WITH_REWARDS.params.contractAddress), - // }), + 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 = [ @@ -33,4 +35,10 @@ 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, + }), ] From 2d0ed070ed98a497e994b28b394849328a23fd83 Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 27 Dec 2023 15:31:28 -0800 Subject: [PATCH 4/5] chore(pnpm): format --- packages/zora/src/Zora.test.ts | 2 +- packages/zora/src/test-setup.ts | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/zora/src/Zora.test.ts b/packages/zora/src/Zora.test.ts index 641a927bc..eb517fa2a 100644 --- a/packages/zora/src/Zora.test.ts +++ b/packages/zora/src/Zora.test.ts @@ -116,7 +116,7 @@ describe('Given the zora plugin', () => { }, ], }, - }) + }) }) describe('should pass filter with valid transactions', () => { diff --git a/packages/zora/src/test-setup.ts b/packages/zora/src/test-setup.ts index 272ac3dd4..8217f92b7 100644 --- a/packages/zora/src/test-setup.ts +++ b/packages/zora/src/test-setup.ts @@ -15,8 +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 }) + 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 = [ @@ -35,10 +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, - }), + 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, + }, + ), ] From c7161af13a9ae4d71c430910fc92069a2b9c331a Mon Sep 17 00:00:00 2001 From: Mmackz Date: Wed, 27 Dec 2023 15:33:15 -0800 Subject: [PATCH 5/5] chore(pnpm): generate changes for zora fix --- .changeset/rude-pumas-camp.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rude-pumas-camp.md diff --git a/.changeset/rude-pumas-camp.md b/.changeset/rude-pumas-camp.md new file mode 100644 index 000000000..80dce9b72 --- /dev/null +++ b/.changeset/rude-pumas-camp.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-zora": patch +--- + +fix overindexing issue with batchmint