Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zora): implement getExternalUrl function #482

Merged
merged 10 commits into from
Jul 16, 2024
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
30 changes: 29 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,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'
Expand Down Expand Up @@ -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'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] we can also have a test without referral

}
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',
)
})
})
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 = referral ? `?referrer=${referral}` : ''
mmackz marked this conversation as resolved.
Show resolved Hide resolved
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
Loading