diff --git a/.changeset/gorgeous-impalas-bake.md b/.changeset/gorgeous-impalas-bake.md new file mode 100644 index 000000000..65bcd3816 --- /dev/null +++ b/.changeset/gorgeous-impalas-bake.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-foundation": minor +--- + +use referral param in valildation and sims diff --git a/packages/foundation/src/Foundation.test.ts b/packages/foundation/src/Foundation.test.ts index a387adf5f..c2b512aed 100644 --- a/packages/foundation/src/Foundation.test.ts +++ b/packages/foundation/src/Foundation.test.ts @@ -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', () => { @@ -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) + } }) - }) + } }) }) @@ -194,6 +197,7 @@ describe('Given the foundation plugin', () => { contractAddress: CONTRACT_ADDRESS, amount: 1n, recipient: RECIPIENT_ADDRESS, + referral: zeroAddress, } // mock @@ -201,7 +205,7 @@ describe('Given the foundation plugin', () => { getMintIntent: async (mint: MintIntentParams) => ({ from: mint.recipient, to: mint.contractAddress, - data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000e3bba2a4f8e0f5c32ef5097f988a4d88075c8b4800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', + data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', }), } const getMintIntentSpy = vi.spyOn(mockFns, 'getMintIntent') @@ -213,7 +217,7 @@ describe('Given the foundation plugin', () => { expect(result).toEqual({ from: mint.recipient, to: mint.contractAddress, - data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000e3bba2a4f8e0f5c32ef5097f988a4d88075c8b4800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', + data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', }) }) @@ -225,6 +229,7 @@ describe('Given the foundation plugin', () => { contractAddress: CONTRACT_ADDRESS, amount: 1n, recipient: RECIPIENT_ADDRESS, + referral: zeroAddress, } // mock @@ -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', @@ -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', diff --git a/packages/foundation/src/Foundation.ts b/packages/foundation/src/Foundation.ts index cbc25a0ef..43f1515eb 100644 --- a/packages/foundation/src/Foundation.ts +++ b/packages/foundation/src/Foundation.ts @@ -44,7 +44,8 @@ import { export const mint = async ( mint: MintActionParams, ): Promise => { - const { chainId, contractAddress, amount, recipient, tokenId } = mint + const { chainId, contractAddress, amount, recipient, tokenId, referral } = + mint // 721 const dropFactoryAddress = CHAIN_TO_CONTRACT_ADDRESS[chainId] @@ -72,6 +73,7 @@ export const mint = async ( count: formatAmount(amount), nftContract: contractAddress, nftRecipient: recipient, + buyReferrer: referral, }, { // 1155 NFTMarketRouter @@ -81,6 +83,7 @@ export const mint = async ( tokenQuantities: { $some: { tokenId, quantity: formatAmount(amount) }, }, + referrer: referral, }, ], }, @@ -166,7 +169,8 @@ export const getFees = async ( export const getMintIntent = async ( mint: MintIntentParams, ): Promise => { - const { chainId, contractAddress, tokenId, amount, recipient } = mint + const { chainId, contractAddress, tokenId, amount, recipient, referral } = + mint const client = createPublicClient({ chain: chainIdToViemChain(chainId), @@ -194,7 +198,7 @@ export const getMintIntent = async ( contractAddress, mintAmount, recipient, - REFERRAL_ADDRESS, + referral ?? REFERRAL_ADDRESS, [], ] @@ -244,7 +248,7 @@ export const getMintIntent = async ( contractAddress, [{ tokenId, quantity: 1n }], recipient, - REFERRAL_ADDRESS, + referral ?? REFERRAL_ADDRESS, ] const data = encodeFunctionData({ @@ -270,7 +274,8 @@ export const simulateMint = async ( account?: Address, client?: PublicClient, ): Promise => { - const { chainId, contractAddress, amount, recipient, tokenId } = mint + const { chainId, contractAddress, amount, recipient, tokenId, referral } = + mint const _client = client || @@ -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 @@ -333,7 +344,7 @@ export const simulateMint = async ( contractAddress, [[tokenId ?? 1, mintAmount]], recipient, - REFERRAL_ADDRESS, + referral ?? REFERRAL_ADDRESS, ], account: account || DEFAULT_ACCOUNT, }) diff --git a/packages/foundation/src/test-transactions.ts b/packages/foundation/src/test-transactions.ts index 4f35b6924..138004055 100644 --- a/packages/foundation/src/test-transactions.ts +++ b/packages/foundation/src/test-transactions.ts @@ -3,6 +3,7 @@ import { type TestParams, createTestCase, } from '@rabbitholegg/questdk-plugin-utils' +import { zeroAddress } from 'viem' const MINT_BASE: TestParams = { transaction: { @@ -18,6 +19,7 @@ const MINT_BASE: TestParams = { chainId: 8453, contractAddress: '0xead6dca70b0465725a57eb81f7d3ab8b5e0b81b4', recipient: '0x22cf7cb48c74b07e1c0dcab5c047c5ed73292805', + referral: zeroAddress, }, } @@ -35,6 +37,7 @@ const MINT_ETHEREUM: TestParams = { chainId: 1, contractAddress: '0x42cfdea063311dfe9bbb3d7b598fea24067909b4', recipient: '0xd76dfe29f0371fb0640906c699165b6bab33c522', + referral: zeroAddress, }, } @@ -72,6 +75,7 @@ const MINT_OE_1155: TestParams = { recipient: '0xd3432463Cf264F4DEf759ca6F8843d47Dd00b2FD', tokenId: 213, amount: '1', + referral: zeroAddress, }, } @@ -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', + }), ]