Skip to content

Commit

Permalink
Merge pull request #511 from rabbitholegg/matthew/boost-4477-zora-get…
Browse files Browse the repository at this point in the history
…fees-fails-for-1155-wo-tokenid-plugin

fix(zora): add tokenId to zora SDK getToken call for 1155s
  • Loading branch information
mmackz authored Aug 15, 2024
2 parents 9143d6e + 33ab22d commit 180e8e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-peas-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-zora": patch
---

add tokenId to zora SDK call for 1155s
25 changes: 25 additions & 0 deletions packages/zora/src/Zora.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,31 @@ describe('Given the getFee function', () => {
expect(fee.projectFee).equals(BigInt('777000000000000'))
expect(fee.actionFee).equals(BigInt('0'))
})

test('should return the correct project + action fee for V1 1155 mint w/o tokenId', async () => {
const contractAddress: Address =
'0x34ce43d58d0d4ecf2581f4eb6238178c77fb32d9'
const tokenId = undefined
const mintParams = {
contractAddress,
tokenId,
chainId: Chains.OPTIMISM,
amount: 1,
}

const mockFns = {
getFees: async (_mint: MintActionParams) => ({
projectFee: parseEther('0.000777'),
actionFee: parseEther('0.29'),
}),
}

const getFeesSpy = vi.spyOn(mockFns, 'getFees')
const fee = await mockFns.getFees(mintParams)
expect(getFeesSpy.mock.calls.length).toBe(1)
expect(fee.projectFee).equals(parseEther('0.000777'))
expect(fee.actionFee).equals(parseEther('0.29'))
})
})

describe('simulateMint function', () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/zora/src/Zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ export const getFees = async (
mint: MintActionParams,
): Promise<{ actionFee: bigint; projectFee: bigint }> => {
try {
const { chainId, contractAddress, tokenId, amount } = mint
const { chainId, contractAddress, amount } = mint
let tokenId = mint.tokenId

const client = getPublicClient(chainId)

Expand All @@ -471,6 +472,12 @@ export const getFees = async (
publicClient: client,
})

// if no tokenId is provided for 1155, we need to get the latest tokenId
if (contractType === '1155' && tokenId == null) {
const nextTokenId = await getNextTokenId(client, contractAddress)
tokenId = Number(nextTokenId)
}

const quantityToMint = formatAmountToInteger(amount)
const { prepareMint } = await collectorClient.getToken({
tokenContract: contractAddress,
Expand Down

0 comments on commit 180e8e6

Please sign in to comment.