From 930c40b0262b167806e1dbb90789eec27f948695 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 14:24:24 -0700 Subject: [PATCH 1/8] feat(zora): map chain id to zora slug --- packages/zora/src/chain-ids.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/zora/src/chain-ids.ts b/packages/zora/src/chain-ids.ts index df114f702..cd4869d6d 100644 --- a/packages/zora/src/chain-ids.ts +++ b/packages/zora/src/chain-ids.ts @@ -8,3 +8,12 @@ export const CHAIN_ID_ARRAY = [ Chains.OPTIMISM, Chains.ZORA, ] + +export const CHAIN_ID_TO_ZORA_SLUG: Record = { + [Chains.ARBITRUM_ONE]: 'arb', + [Chains.BASE]: 'base', + [Chains.BLAST]: 'blast', + [Chains.ETHEREUM]: 'eth', + [Chains.OPTIMISM]: 'oeth', + [Chains.ZORA]: 'zora', +} From 97e9dbec920342e1dd260a43ec800012b7da97c5 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 14:24:43 -0700 Subject: [PATCH 2/8] feat(zora): implement getExternalUrl function --- packages/zora/src/Zora.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index 4d752deaf..5ec59d058 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -6,7 +6,7 @@ import { ZORA_MINTER_ABI_1155, ZORA_MINTER_ABI_1155_LEGACY, } from './abi' -import { CHAIN_ID_ARRAY } from './chain-ids' +import { CHAIN_ID_ARRAY, CHAIN_ID_TO_ZORA_SLUG } from './chain-ids' import { FIXED_PRICE_SALE_STRATS, ZORA_1155_FACTORY, @@ -426,3 +426,14 @@ export const getDynamicNameParams = async ( } return values } + +export const getExternalUrl = async ( + params: MintActionParams, +): Promise => { + const { chainId, contractAddress, tokenId, referral } = params + const chainSlug = CHAIN_ID_TO_ZORA_SLUG[chainId] + const referralParams = referral ? `?referrer=${referral}` : '' + const baseUrl = `https://zora.co/collect/${chainSlug}:${contractAddress}` + + return tokenId != null ? `${baseUrl}/${tokenId}${referralParams}` : `${baseUrl}${referralParams}` +} From 3830cac4eb74ba4b3c6f2043eff4e1d1d039aa1d Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 14:29:24 -0700 Subject: [PATCH 3/8] test(zora): add test for getExternalUrl --- packages/zora/src/Zora.test.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/zora/src/Zora.test.ts b/packages/zora/src/Zora.test.ts index 91b20cd66..b18be8d11 100644 --- a/packages/zora/src/Zora.test.ts +++ b/packages/zora/src/Zora.test.ts @@ -1,6 +1,7 @@ import { create, getDynamicNameParams, + getExternalUrl, getMintIntent, mint, simulateMint, @@ -24,7 +25,7 @@ import { type PremintActionParams, } from '@rabbitholegg/questdk-plugin-utils' import { apply } from '@rabbitholegg/questdk' -import { type Address, parseEther } from 'viem' +import { type Address, getAddress, parseEther } from 'viem' import { describe, expect, test, vi, beforeEach, MockedFunction } from 'vitest' import { PremintResponse } from './types' import axios from 'axios' @@ -513,3 +514,30 @@ describe('getDynamicNameParams function', () => { ).rejects.toThrow(`Invalid action type "${params.type}"`) }) }) + +describe('getExternalUrl function', () => { + test('should return correct url for 1155 mint with token id', async () => { + const params = { + chainId: Chains.ZORA, + contractAddress: getAddress('0x393c46fe7887697124a73f6028f39751aa1961a3'), + tokenId: 1, + referral: getAddress('0x1234567890123456789012345678901234567890'), + } + const result = await getExternalUrl(params) + expect(result).toBe( + 'https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3/1?referrer=0x1234567890123456789012345678901234567890', + ) + }) + + test('should return correct url for 1155 mint without token id', async () => { + const params = { + chainId: Chains.ZORA, + contractAddress: getAddress('0x393c46fe7887697124a73f6028f39751aa1961a3'), + referral: getAddress('0x1234567890123456789012345678901234567890'), + } + const result = await getExternalUrl(params) + expect(result).toBe( + 'https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3?referrer=0x1234567890123456789012345678901234567890', + ) + }) +}) From c7095cc3604de03685df12df54f55dfb6f916898 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 14:29:41 -0700 Subject: [PATCH 4/8] chore: format --- packages/zora/src/Zora.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index 5ec59d058..e5dbb277a 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -435,5 +435,7 @@ export const getExternalUrl = async ( const referralParams = referral ? `?referrer=${referral}` : '' const baseUrl = `https://zora.co/collect/${chainSlug}:${contractAddress}` - return tokenId != null ? `${baseUrl}/${tokenId}${referralParams}` : `${baseUrl}${referralParams}` + return tokenId != null + ? `${baseUrl}/${tokenId}${referralParams}` + : `${baseUrl}${referralParams}` } From 379f7fc05703a705b23ec89e8b25cdd5ba2eb35c Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 14:30:15 -0700 Subject: [PATCH 5/8] chore: generate changeset --- .changeset/hot-boats-help.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hot-boats-help.md diff --git a/.changeset/hot-boats-help.md b/.changeset/hot-boats-help.md new file mode 100644 index 000000000..a3e4d26c0 --- /dev/null +++ b/.changeset/hot-boats-help.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-zora": minor +--- + +implement getExternalUrl function From 78532a4d1966a289086ecc43c11b032f508168f2 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 14:41:45 -0700 Subject: [PATCH 6/8] feat(zora): export getExternalUrl function --- packages/zora/src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/zora/src/index.ts b/packages/zora/src/index.ts index b945b6a03..e03944aa7 100644 --- a/packages/zora/src/index.ts +++ b/packages/zora/src/index.ts @@ -8,6 +8,7 @@ import { import { create, getDynamicNameParams, + getExternalUrl, getFees, getMintIntent, getProjectFees, @@ -28,6 +29,8 @@ export const Zora: IActionPlugin = { swap: async () => new PluginActionNotImplementedError(), mint, getDynamicNameParams, + getExternalUrl: async (params: ActionParams) => + getExternalUrl(params as unknown as MintActionParams), getProjectFees: async (params: ActionParams) => getProjectFees(params as unknown as MintActionParams), getFees: async (params: ActionParams) => From f792e9aaa12bf0a2967a3a1152d078ade13b4c0e Mon Sep 17 00:00:00 2001 From: mmackz Date: Tue, 16 Jul 2024 12:13:03 -0700 Subject: [PATCH 7/8] feat(zora): fallback to zora deplyer if no referral passed in --- packages/zora/src/Zora.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index e5dbb277a..c30ea5d6f 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -432,7 +432,7 @@ export const getExternalUrl = async ( ): Promise => { const { chainId, contractAddress, tokenId, referral } = params const chainSlug = CHAIN_ID_TO_ZORA_SLUG[chainId] - const referralParams = referral ? `?referrer=${referral}` : '' + const referralParams = `?referrer=${referral ?? ZORA_DEPLOYER_ADDRESS}` const baseUrl = `https://zora.co/collect/${chainSlug}:${contractAddress}` return tokenId != null From ca73899a6c71921f2524ed28c7af59d4a0370a87 Mon Sep 17 00:00:00 2001 From: mmackz Date: Tue, 16 Jul 2024 12:14:41 -0700 Subject: [PATCH 8/8] test: add additional test for no referral --- packages/zora/src/Zora.test.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/zora/src/Zora.test.ts b/packages/zora/src/Zora.test.ts index b18be8d11..f625c295e 100644 --- a/packages/zora/src/Zora.test.ts +++ b/packages/zora/src/Zora.test.ts @@ -30,6 +30,7 @@ import { describe, expect, test, vi, beforeEach, MockedFunction } from 'vitest' import { PremintResponse } from './types' import axios from 'axios' import { validatePremint } from './validate' +import { ZORA_DEPLOYER_ADDRESS } from './contract-addresses' const MockedPremintResponse: PremintResponse = [ { @@ -516,7 +517,7 @@ describe('getDynamicNameParams function', () => { }) describe('getExternalUrl function', () => { - test('should return correct url for 1155 mint with token id', async () => { + test('should return correct url for 1155 mint with token id w/referral', async () => { const params = { chainId: Chains.ZORA, contractAddress: getAddress('0x393c46fe7887697124a73f6028f39751aa1961a3'), @@ -529,6 +530,18 @@ describe('getExternalUrl function', () => { ) }) + test('should return correct url for 1155 mint with token id w/o referral', async () => { + const params = { + chainId: Chains.ZORA, + contractAddress: getAddress('0x393c46fe7887697124a73f6028f39751aa1961a3'), + tokenId: 1, + } + const result = await getExternalUrl(params) + expect(result).toBe( + `https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3/1?referrer=${ZORA_DEPLOYER_ADDRESS}`, + ) + }) + test('should return correct url for 1155 mint without token id', async () => { const params = { chainId: Chains.ZORA,