Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into matthew/boost-4259-fo…
Browse files Browse the repository at this point in the history
…undation-referral-param
  • Loading branch information
mmackz committed Jul 17, 2024
2 parents a41821e + 4cc5979 commit 6a3af24
Show file tree
Hide file tree
Showing 40 changed files with 627 additions and 51 deletions.
8 changes: 8 additions & 0 deletions .changeset/chilly-flies-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@rabbitholegg/questdk-plugin-soundxyz": patch
"@rabbitholegg/questdk-plugin-utils": patch
"@rabbitholegg/questdk-plugin-pods": patch
"@rabbitholegg/questdk-plugin-zora": patch
---

add default ref address to utils package
5 changes: 5 additions & 0 deletions .changeset/eleven-maps-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-soundxyz": minor
---

add getExternalUrl function to sound plugin
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
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
5 changes: 5 additions & 0 deletions .changeset/light-rabbits-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-pods": minor
---

implement getExternalUrl for pods
5 changes: 5 additions & 0 deletions .changeset/lovely-pans-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-manifold": minor
---

implement getExternalUrl function
5 changes: 5 additions & 0 deletions .changeset/nine-coats-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-zora": minor
---

use referral param in validation and simulations
5 changes: 5 additions & 0 deletions .changeset/silent-fireants-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-utils": minor
---

allow referral to be optional in MintIntentParams
5 changes: 5 additions & 0 deletions .changeset/two-comics-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-soundxyz": minor
---

use referral param in validation and mint simulation
5 changes: 5 additions & 0 deletions .changeset/warm-insects-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-pods": minor
---

use referral param in validation
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 @@ -410,4 +410,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 @@ -352,6 +353,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
40 changes: 38 additions & 2 deletions packages/manifold/src/Manifold.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getFees, getMintIntent, mint, simulateMint } from './Manifold'
import {
getExternalUrl,
getFees,
getMintIntent,
mint,
simulateMint,
} from './Manifold'
import { ERC721_CONTRACT, ERC1155_CONTRACT } from './constants'
import { failingTestCases, passingTestCases } from './test-transactions'
import { apply } from '@rabbitholegg/questdk'
Expand All @@ -8,7 +14,7 @@ import {
type MintIntentParams,
} from '@rabbitholegg/questdk-plugin-utils'
import axios from 'axios'
import { type Address, parseEther } from 'viem'
import { type Address, parseEther, getAddress } from 'viem'
import { MockedFunction, beforeEach, describe, expect, test, vi } from 'vitest'

vi.mock('axios', () => {
Expand Down Expand Up @@ -218,3 +224,33 @@ describe('simulateMint function', () => {
expect(request.value).toBe(value)
})
})

describe('getExternalUrl function', () => {
beforeEach(() => {
vi.resetAllMocks()
})
test('should return the correct url for a 721 mint', async () => {
const mint = {
chainId: Chains.OPTIMISM,
contractAddress: getAddress('0x6935cd348193bab133f3081f53eb99ee6f0d685b'),
}
;(axios.get as MockedFunction<typeof axios.get>).mockResolvedValue({
status: 200,
data: {
slug: 'girls-man',
},
})

const result = await getExternalUrl(mint)
expect(result).toBe('https://app.manifold.xyz/c/girls-man')
})

test('should return the fallback url for an unknown contract', async () => {
const mint = {
chainId: Chains.OPTIMISM,
contractAddress: getAddress('0x7935cd348193bab133f3081f53eb99ee6f0d685b'),
}
const result = await getExternalUrl(mint)
expect(result).toBe('https://app.manifold.xyz/')
})
})
35 changes: 35 additions & 0 deletions packages/manifold/src/Manifold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,41 @@ export const getFees = async (
}
}

export const getExternalUrl = async (
mint: MintActionParams,
): Promise<string> => {
const { chainId, contractAddress, tokenId } = mint

const baseUrl = 'https://app.manifold.xyz/'

try {
const instanceId = await getInstanceId(
chainId,
contractAddress,
tokenId ?? 1,
)

const { data } = await axios.get<{ slug?: string }>(
`https://apps.api.manifoldxyz.dev/public/instance/data?id=${instanceId}`,
)
const slug = data.slug

if (!slug) {
throw new Error('Slug not found in response')
}

return `${baseUrl}c/${slug}`
} catch (err) {
if (err instanceof Error) {
console.error(err.message)
} else {
console.error(err)
}
// fallback to default manifold url
return baseUrl
}
}

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

import {
getExternalUrl,
getFees,
getMintIntent,
getProjectFees,
Expand All @@ -23,6 +24,8 @@ export const Manifold: IActionPlugin = {
getProjectFees(params as unknown as MintActionParams),
getFees: async (params: ActionParams) =>
getFees(params as unknown as MintActionParams),
getExternalUrl: async (params: ActionParams) =>
getExternalUrl(params as unknown as MintActionParams),
getMintIntent,
simulateMint,
}
57 changes: 55 additions & 2 deletions packages/pods/src/Pods.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
Chains,
DEFAULT_REFERRAL,
type MintActionParams,
type MintIntentParams,
} from '@rabbitholegg/questdk-plugin-utils'
import { apply } from '@rabbitholegg/questdk'
import { type Address, parseEther } from 'viem'
import { type Address, parseEther, getAddress, zeroAddress } from 'viem'
import { describe, expect, test, vi } from 'vitest'
import { getMintIntent, mint } from './Pods'
import { getExternalUrl, getMintIntent, mint } from './Pods'
import { failingTestCases, passingTestCases } from './test-setup'
import { EXPECTED_ENCODED_DATA_1155 } from './test-transactions'

Expand Down Expand Up @@ -79,6 +80,7 @@ describe('Given the getMintIntent function', () => {
contractAddress: CONTRACT_ADDRESS,
amount: BigInt('10'),
recipient: RECIPIENT_ADDRESS,
referral: '0xe3bba2a4f8e0f5c32ef5097f988a4d88075c8b48',
}

const result = await getMintIntent(mint)
Expand Down Expand Up @@ -124,6 +126,7 @@ describe('simulateMint function', () => {
tokenId: 1,
amount: BigInt(1),
recipient: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
referral: '0xe3bba2a4f8e0f5c32ef5097f988a4d88075c8b48',
}
const value = parseEther('0.0007')
const address = mint.recipient as Address
Expand Down Expand Up @@ -165,6 +168,7 @@ describe('simulateMint function', () => {
contractAddress: '0x7e0b40af1d6f26f2141b90170c513e57b5edd74e',
amount: BigInt(1),
recipient: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
referral: '0xe3bba2a4f8e0f5c32ef5097f988a4d88075c8b48',
}
const value = parseEther('0.0007')
const address = mint.recipient as Address
Expand Down Expand Up @@ -201,3 +205,52 @@ describe('simulateMint function', () => {
expect(request.value).toBe(value)
})
})

describe('getExternalUrl function', () => {
test('should return correct url for mint w/tokenId and referral', async () => {
const params = {
chainId: Chains.BASE,
contractAddress: getAddress('0x7e0b40af1d6f26f2141b90170c513e57b5edd74e'),
tokenId: 21,
referral: getAddress('0x1234567890123456789012345678901234567890'),
}
const result = await getExternalUrl(params)
expect(result).toBe(
'https://pods.media/mint-podcast/why-social-needs-a-layer-2-ft-ryan-li-of-cyber?referrer=0x1234567890123456789012345678901234567890',
)
})

test('should return correct url for mint w/tokenId and w/o referral', async () => {
const params = {
chainId: Chains.BASE,
contractAddress: getAddress('0x7e0b40af1d6f26f2141b90170c513e57b5edd74e'),
tokenId: 21,
}
const result = await getExternalUrl(params)
expect(result).toBe(
`https://pods.media/mint-podcast/why-social-needs-a-layer-2-ft-ryan-li-of-cyber?referrer=${DEFAULT_REFERRAL}`,
)
})

test('should return correct url for mint w/out tokenId', async () => {
const params = {
chainId: Chains.BASE,
contractAddress: getAddress('0x7e0b40af1d6f26f2141b90170c513e57b5edd74e'),
referral: getAddress('0x1234567890123456789012345678901234567890'),
}
const result = await getExternalUrl(params)
expect(result).toBe(
'https://pods.media/mint-podcast?referrer=0x1234567890123456789012345678901234567890',
)
})

test('should return fallback url if error occurs', async () => {
const params = {
chainId: Chains.BASE,
contractAddress: zeroAddress,
referral: getAddress('0x1234567890123456789012345678901234567890'),
}
const result = await getExternalUrl(params)
expect(result).toBe('https://pods.media')
})
})
Loading

0 comments on commit 6a3af24

Please sign in to comment.