Skip to content

Commit

Permalink
Merge pull request #482 from rabbitholegg/matthew/boost-4266-implemen…
Browse files Browse the repository at this point in the history
…t-getexternalurl-zora

feat(zora): implement `getExternalUrl` function
  • Loading branch information
mmackz authored Jul 16, 2024
2 parents 1f3dfb0 + ca73899 commit 0bf2cf6
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-boats-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-zora": minor
---

implement getExternalUrl function
43 changes: 42 additions & 1 deletion packages/zora/src/Zora.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
create,
getDynamicNameParams,
getExternalUrl,
getMintIntent,
mint,
simulateMint,
Expand All @@ -24,11 +25,12 @@ 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'
import { validatePremint } from './validate'
import { ZORA_DEPLOYER_ADDRESS } from './contract-addresses'

const MockedPremintResponse: PremintResponse = [
{
Expand Down Expand Up @@ -513,3 +515,42 @@ describe('getDynamicNameParams function', () => {
).rejects.toThrow(`Invalid action type "${params.type}"`)
})
})

describe('getExternalUrl function', () => {
test('should return correct url for 1155 mint with token id w/referral', 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 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,
contractAddress: getAddress('0x393c46fe7887697124a73f6028f39751aa1961a3'),
referral: getAddress('0x1234567890123456789012345678901234567890'),
}
const result = await getExternalUrl(params)
expect(result).toBe(
'https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3?referrer=0x1234567890123456789012345678901234567890',
)
})
})
15 changes: 14 additions & 1 deletion packages/zora/src/Zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -426,3 +426,16 @@ export const getDynamicNameParams = async (
}
return values
}

export const getExternalUrl = async (
params: MintActionParams,
): Promise<string> => {
const { chainId, contractAddress, tokenId, referral } = params
const chainSlug = CHAIN_ID_TO_ZORA_SLUG[chainId]
const referralParams = `?referrer=${referral ?? ZORA_DEPLOYER_ADDRESS}`
const baseUrl = `https://zora.co/collect/${chainSlug}:${contractAddress}`

return tokenId != null
? `${baseUrl}/${tokenId}${referralParams}`
: `${baseUrl}${referralParams}`
}
9 changes: 9 additions & 0 deletions packages/zora/src/chain-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ export const CHAIN_ID_ARRAY = [
Chains.OPTIMISM,
Chains.ZORA,
]

export const CHAIN_ID_TO_ZORA_SLUG: Record<number, string> = {
[Chains.ARBITRUM_ONE]: 'arb',
[Chains.BASE]: 'base',
[Chains.BLAST]: 'blast',
[Chains.ETHEREUM]: 'eth',
[Chains.OPTIMISM]: 'oeth',
[Chains.ZORA]: 'zora',
}
3 changes: 3 additions & 0 deletions packages/zora/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
create,
getDynamicNameParams,
getExternalUrl,
getFees,
getMintIntent,
getProjectFees,
Expand All @@ -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) =>
Expand Down

0 comments on commit 0bf2cf6

Please sign in to comment.