Skip to content

Commit

Permalink
Merge pull request #484 from rabbitholegg/matthew/boost-4259-foundati…
Browse files Browse the repository at this point in the history
…on-referral-param

feat(foundation): add referral param to mint validation
  • Loading branch information
mmackz authored Jul 17, 2024
2 parents 4cc5979 + 6a3af24 commit d792f96
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-impalas-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-foundation": minor
---

use referral param in valildation and sims
21 changes: 14 additions & 7 deletions packages/foundation/src/Foundation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type MintActionParams,
type MintIntentParams,
} from '@rabbitholegg/questdk-plugin-utils'
import { Address, parseEther } from 'viem'
import { Address, parseEther, zeroAddress } from 'viem'
import { describe, expect, test, vi } from 'vitest'

describe('Given the foundation plugin', () => {
Expand Down Expand Up @@ -62,19 +62,22 @@ describe('Given the foundation plugin', () => {
})

describe('should not pass filter with invalid transactions', () => {
failingTestCases.forEach((testCase) => {
for (const testCase of failingTestCases) {
const { transaction, description, params } = testCase
test(description, async () => {
let result: boolean | undefined
try {
const filter = await mint(params)
const result = apply(transaction, filter)
expect(result).toBe(false)
result = apply(transaction, filter)
} catch (error) {
expect(error).toBeDefined()
expect(error).toBeInstanceOf(Error)
}
if (result) {
expect(result).toBe(false)
}
})
})
}
})
})

Expand Down Expand Up @@ -194,14 +197,15 @@ describe('Given the foundation plugin', () => {
contractAddress: CONTRACT_ADDRESS,
amount: 1n,
recipient: RECIPIENT_ADDRESS,
referral: zeroAddress,
}

// mock
const mockFns = {
getMintIntent: async (mint: MintIntentParams) => ({
from: mint.recipient,
to: mint.contractAddress,
data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000e3bba2a4f8e0f5c32ef5097f988a4d88075c8b4800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000',
data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000',
}),
}
const getMintIntentSpy = vi.spyOn(mockFns, 'getMintIntent')
Expand All @@ -213,7 +217,7 @@ describe('Given the foundation plugin', () => {
expect(result).toEqual({
from: mint.recipient,
to: mint.contractAddress,
data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000e3bba2a4f8e0f5c32ef5097f988a4d88075c8b4800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000',
data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000',
})
})

Expand All @@ -225,6 +229,7 @@ describe('Given the foundation plugin', () => {
contractAddress: CONTRACT_ADDRESS,
amount: 1n,
recipient: RECIPIENT_ADDRESS,
referral: zeroAddress,
}

// mock
Expand Down Expand Up @@ -294,6 +299,7 @@ describe('Given the foundation plugin', () => {
})

test('should simulate a mint with a dutch auction', async () => {
// ! fails when using live data (dutch auction not supported)
const mint = {
chainId: Chains.BASE,
contractAddress: '0x6a41fcce9d075a9f6324b626af56cf632c509ec9',
Expand Down Expand Up @@ -362,6 +368,7 @@ describe('Given the foundation plugin', () => {
})

test('should simulate a mint with an 1155 OE mint', async () => {
// ! fails when using live data (mint expired)
const mint = {
chainId: Chains.BASE,
contractAddress: '0x1d2550d198197df1a10af515cf2ea0d790889b93',
Expand Down
25 changes: 18 additions & 7 deletions packages/foundation/src/Foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import {
export const mint = async (
mint: MintActionParams,
): Promise<TransactionFilter> => {
const { chainId, contractAddress, amount, recipient, tokenId } = mint
const { chainId, contractAddress, amount, recipient, tokenId, referral } =
mint

// 721
const dropFactoryAddress = CHAIN_TO_CONTRACT_ADDRESS[chainId]
Expand Down Expand Up @@ -72,6 +73,7 @@ export const mint = async (
count: formatAmount(amount),
nftContract: contractAddress,
nftRecipient: recipient,
buyReferrer: referral,
},
{
// 1155 NFTMarketRouter
Expand All @@ -81,6 +83,7 @@ export const mint = async (
tokenQuantities: {
$some: { tokenId, quantity: formatAmount(amount) },
},
referrer: referral,
},
],
},
Expand Down Expand Up @@ -166,7 +169,8 @@ export const getFees = async (
export const getMintIntent = async (
mint: MintIntentParams,
): Promise<TransactionRequest> => {
const { chainId, contractAddress, tokenId, amount, recipient } = mint
const { chainId, contractAddress, tokenId, amount, recipient, referral } =
mint

const client = createPublicClient({
chain: chainIdToViemChain(chainId),
Expand Down Expand Up @@ -194,7 +198,7 @@ export const getMintIntent = async (
contractAddress,
mintAmount,
recipient,
REFERRAL_ADDRESS,
referral ?? REFERRAL_ADDRESS,
[],
]

Expand Down Expand Up @@ -244,7 +248,7 @@ export const getMintIntent = async (
contractAddress,
[{ tokenId, quantity: 1n }],
recipient,
REFERRAL_ADDRESS,
referral ?? REFERRAL_ADDRESS,
]

const data = encodeFunctionData({
Expand All @@ -270,7 +274,8 @@ export const simulateMint = async (
account?: Address,
client?: PublicClient,
): Promise<SimulateContractReturnType> => {
const { chainId, contractAddress, amount, recipient, tokenId } = mint
const { chainId, contractAddress, amount, recipient, tokenId, referral } =
mint

const _client =
client ||
Expand Down Expand Up @@ -301,7 +306,13 @@ export const simulateMint = async (
value,
abi: FIXED_PRICE_FRAGMENTS,
functionName: 'mintFromFixedPriceSaleWithEarlyAccessAllowlistV2',
args: [contractAddress, mintAmount, recipient, REFERRAL_ADDRESS, []],
args: [
contractAddress,
mintAmount,
recipient,
referral ?? REFERRAL_ADDRESS,
[],
],
account: account || DEFAULT_ACCOUNT,
})
return result
Expand Down Expand Up @@ -333,7 +344,7 @@ export const simulateMint = async (
contractAddress,
[[tokenId ?? 1, mintAmount]],
recipient,
REFERRAL_ADDRESS,
referral ?? REFERRAL_ADDRESS,
],
account: account || DEFAULT_ACCOUNT,
})
Expand Down
10 changes: 10 additions & 0 deletions packages/foundation/src/test-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type TestParams,
createTestCase,
} from '@rabbitholegg/questdk-plugin-utils'
import { zeroAddress } from 'viem'

const MINT_BASE: TestParams<MintActionParams> = {
transaction: {
Expand All @@ -18,6 +19,7 @@ const MINT_BASE: TestParams<MintActionParams> = {
chainId: 8453,
contractAddress: '0xead6dca70b0465725a57eb81f7d3ab8b5e0b81b4',
recipient: '0x22cf7cb48c74b07e1c0dcab5c047c5ed73292805',
referral: zeroAddress,
},
}

Expand All @@ -35,6 +37,7 @@ const MINT_ETHEREUM: TestParams<MintActionParams> = {
chainId: 1,
contractAddress: '0x42cfdea063311dfe9bbb3d7b598fea24067909b4',
recipient: '0xd76dfe29f0371fb0640906c699165b6bab33c522',
referral: zeroAddress,
},
}

Expand Down Expand Up @@ -72,6 +75,7 @@ const MINT_OE_1155: TestParams<MintActionParams> = {
recipient: '0xd3432463Cf264F4DEf759ca6F8843d47Dd00b2FD',
tokenId: 213,
amount: '1',
referral: zeroAddress,
},
}

Expand All @@ -91,4 +95,10 @@ export const failingTestCases = [
contractAddress: '0x62037b26fff91929655aa3a060f327b47d1e2b3e',
}),
createTestCase(MINT_BASE, 'when amount is not sufficient', { amount: '99' }),
createTestCase(MINT_BASE, 'when when minting with wrong referral (721)', {
referral: '0x62037b26fff91929655aa3a060f327b47d1e2b3e',
}),
createTestCase(MINT_OE_1155, 'when when minting with wrong referral (1155)', {
referral: '0x62037b26fff91929655aa3a060f327b47d1e2b3e',
}),
]

0 comments on commit d792f96

Please sign in to comment.