Skip to content

Commit

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

feat(foundation): implement `getExternalUrl` function
  • Loading branch information
mmackz authored Jul 17, 2024
2 parents 912505d + 6e85c79 commit aa4f44f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fresh-buckets-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-foundation": minor
---

implement getExternalUrl function
35 changes: 34 additions & 1 deletion packages/foundation/src/Foundation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mint } from './Foundation'
import { getExternalUrl, mint } from './Foundation'
// import { getFees, getMintIntent, simulateMint } from './Foundation'
import {
dutchAuctionResponse,
Expand Down Expand Up @@ -403,4 +403,37 @@ describe('Given the foundation plugin', () => {
expect(request.value).toBe(value)
})
})

describe('getExternalUrl function', () => {
test('should return the correct url for a 721 mint', async () => {
const mint: MintActionParams = {
chainId: Chains.BASE,
contractAddress: '0xead6dca70b0465725a57eb81f7d3ab8b5e0b81b4',
}
const result = await getExternalUrl(mint)
expect(result).toBe(
'https://foundation.app/mint/base/0xead6dca70b0465725a57eb81f7d3ab8b5e0b81b4',
)
})

test('should return the base url for 1155 mint', async () => {
const mint: MintActionParams = {
chainId: Chains.BASE,
contractAddress: '0x1d2550d198197df1a10af515cf2ea0d790889b93',
tokenId: 213,
}
const result = await getExternalUrl(mint)
expect(result).toBe('https://foundation.app/')
})

test('should return the base url for unsupported chain', async () => {
const mint: MintActionParams = {
chainId: Chains.OPTIMISM,
contractAddress: '0x1d2550d198197df1a10af515cf2ea0d790889b93',
tokenId: 213,
}
const result = await getExternalUrl(mint)
expect(result).toBe('https://foundation.app/')
})
})
})
13 changes: 13 additions & 0 deletions packages/foundation/src/Foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
REFERRAL_ADDRESS,
} from './constants'
import {
CHAIN_TO_NETWORK_SLUG,
calculateFees,
getContractType,
getDutchAuctionData,
Expand Down Expand Up @@ -341,6 +342,18 @@ export const simulateMint = async (
throw new Error('Invalid contract type')
}

export const getExternalUrl = async (
params: MintActionParams,
): Promise<string> => {
const { chainId, contractAddress, tokenId } = params
const baseUrl = 'https://foundation.app/'
const networkSlug = CHAIN_TO_NETWORK_SLUG[chainId]
if (tokenId != null || !networkSlug) {
return baseUrl
}
return `${baseUrl}mint/${networkSlug}/${contractAddress}`
}

export const getSupportedTokenAddresses = async (
_chainId: number,
): Promise<Address[]> => {
Expand Down
3 changes: 3 additions & 0 deletions packages/foundation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@rabbitholegg/questdk'

import {
getExternalUrl,
getFees,
getMintIntent,
getProjectFees,
Expand All @@ -16,6 +17,8 @@ import {

export const Foundation: IActionPlugin = {
pluginId: 'foundation',
getExternalUrl: async (params: ActionParams) =>
getExternalUrl(params as unknown as MintActionParams),
getFees: async (params: ActionParams) =>
getFees(params as unknown as MintActionParams),
getMintIntent,
Expand Down
6 changes: 6 additions & 0 deletions packages/foundation/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import {
} from './constants'
import { type SaleTerms } from './types'
import {
Chains,
type MintActionParams,
chainIdToViemChain,
} from '@rabbitholegg/questdk-plugin-utils'
import { type Address, type PublicClient, createPublicClient, http } from 'viem'

export const CHAIN_TO_NETWORK_SLUG: Record<number, string | undefined> = {
[Chains.ETHEREUM]: 'eth',
[Chains.BASE]: 'base',
}

export async function getFixedPriceData(
client: PublicClient,
address: Address,
Expand Down

0 comments on commit aa4f44f

Please sign in to comment.