From 588dece188532ab88c46ef086cb23da12d9ba575 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 15:30:39 -0700 Subject: [PATCH 1/9] feat(foundation): add referral param to simulateMint --- packages/foundation/src/Foundation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/foundation/src/Foundation.ts b/packages/foundation/src/Foundation.ts index 7966acf30..a646502ff 100644 --- a/packages/foundation/src/Foundation.ts +++ b/packages/foundation/src/Foundation.ts @@ -269,7 +269,7 @@ 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 || @@ -300,7 +300,7 @@ 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 @@ -332,7 +332,7 @@ export const simulateMint = async ( contractAddress, [[tokenId ?? 1, mintAmount]], recipient, - REFERRAL_ADDRESS, + referral ?? REFERRAL_ADDRESS, ], account: account || DEFAULT_ACCOUNT, }) From c5317a1da6e964d9d6122fdd5370229b0482d7e4 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 15:31:23 -0700 Subject: [PATCH 2/9] feat(foundation): add referral to mintIntents function --- packages/foundation/src/Foundation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/foundation/src/Foundation.ts b/packages/foundation/src/Foundation.ts index a646502ff..e737351d1 100644 --- a/packages/foundation/src/Foundation.ts +++ b/packages/foundation/src/Foundation.ts @@ -165,7 +165,7 @@ 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), @@ -193,7 +193,7 @@ export const getMintIntent = async ( contractAddress, mintAmount, recipient, - REFERRAL_ADDRESS, + referral ?? REFERRAL_ADDRESS, [], ] @@ -243,7 +243,7 @@ export const getMintIntent = async ( contractAddress, [{ tokenId, quantity: 1n }], recipient, - REFERRAL_ADDRESS, + referral ?? REFERRAL_ADDRESS, ] const data = encodeFunctionData({ From 6211f436cc3d5b100b6ddf9475b8cd2d9cc62daa Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 15:33:50 -0700 Subject: [PATCH 3/9] feat(foundation): add referral to mint validation --- packages/foundation/src/Foundation.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/foundation/src/Foundation.ts b/packages/foundation/src/Foundation.ts index e737351d1..61b588686 100644 --- a/packages/foundation/src/Foundation.ts +++ b/packages/foundation/src/Foundation.ts @@ -43,7 +43,7 @@ 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] @@ -71,6 +71,7 @@ export const mint = async ( count: formatAmount(amount), nftContract: contractAddress, nftRecipient: recipient, + buyReferrer: referral, }, { // 1155 NFTMarketRouter @@ -80,6 +81,7 @@ export const mint = async ( tokenQuantities: { $some: { tokenId, quantity: formatAmount(amount) }, }, + referrer: referral, }, ], }, From 60aa5af6288ebf760d436e2d2d907acfd6b80552 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 16:13:58 -0700 Subject: [PATCH 4/9] test(foundation): add tests for referral param --- packages/foundation/src/test-transactions.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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', + }), ] From 2dd30a4eb372ad085f542ace104de27c19bda8cd Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 16:15:08 -0700 Subject: [PATCH 5/9] test(foundation): refactor failing testcases --- packages/foundation/src/Foundation.test.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/foundation/src/Foundation.test.ts b/packages/foundation/src/Foundation.test.ts index a0d86c7b3..d611908d0 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 @@ -225,6 +229,7 @@ describe('Given the foundation plugin', () => { contractAddress: CONTRACT_ADDRESS, amount: 1n, recipient: RECIPIENT_ADDRESS, + referral: zeroAddress, } // mock From 6a507f14a1a784c35ef2f246083cd202fc2e60e7 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 16:15:27 -0700 Subject: [PATCH 6/9] chore: format --- packages/foundation/src/Foundation.test.ts | 2 +- packages/foundation/src/Foundation.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/foundation/src/Foundation.test.ts b/packages/foundation/src/Foundation.test.ts index d611908d0..9766eaf69 100644 --- a/packages/foundation/src/Foundation.test.ts +++ b/packages/foundation/src/Foundation.test.ts @@ -73,7 +73,7 @@ describe('Given the foundation plugin', () => { expect(error).toBeDefined() expect(error).toBeInstanceOf(Error) } - if (result) { + if (result) { expect(result).toBe(false) } }) diff --git a/packages/foundation/src/Foundation.ts b/packages/foundation/src/Foundation.ts index 61b588686..b0d2a8eb7 100644 --- a/packages/foundation/src/Foundation.ts +++ b/packages/foundation/src/Foundation.ts @@ -43,7 +43,8 @@ import { export const mint = async ( mint: MintActionParams, ): Promise => { - const { chainId, contractAddress, amount, recipient, tokenId, referral } = mint + const { chainId, contractAddress, amount, recipient, tokenId, referral } = + mint // 721 const dropFactoryAddress = CHAIN_TO_CONTRACT_ADDRESS[chainId] @@ -167,7 +168,8 @@ export const getFees = async ( export const getMintIntent = async ( mint: MintIntentParams, ): Promise => { - const { chainId, contractAddress, tokenId, amount, recipient, referral } = mint + const { chainId, contractAddress, tokenId, amount, recipient, referral } = + mint const client = createPublicClient({ chain: chainIdToViemChain(chainId), @@ -271,7 +273,8 @@ export const simulateMint = async ( account?: Address, client?: PublicClient, ): Promise => { - const { chainId, contractAddress, amount, recipient, tokenId, referral } = mint + const { chainId, contractAddress, amount, recipient, tokenId, referral } = + mint const _client = client || @@ -302,7 +305,13 @@ export const simulateMint = async ( value, abi: FIXED_PRICE_FRAGMENTS, functionName: 'mintFromFixedPriceSaleWithEarlyAccessAllowlistV2', - args: [contractAddress, mintAmount, recipient, referral ?? REFERRAL_ADDRESS, []], + args: [ + contractAddress, + mintAmount, + recipient, + referral ?? REFERRAL_ADDRESS, + [], + ], account: account || DEFAULT_ACCOUNT, }) return result From 9806eaeb44a864bab3ed2876b0c4b18564d828f3 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 16:16:30 -0700 Subject: [PATCH 7/9] chore: generate changeset --- .changeset/gorgeous-impalas-bake.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-impalas-bake.md 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 From f869a2183579a35289baa1b34f571340b49fc980 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 16:36:07 -0700 Subject: [PATCH 8/9] test(foundation): update mock calldata --- packages/foundation/src/Foundation.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/foundation/src/Foundation.test.ts b/packages/foundation/src/Foundation.test.ts index 9766eaf69..f26680fa7 100644 --- a/packages/foundation/src/Foundation.test.ts +++ b/packages/foundation/src/Foundation.test.ts @@ -205,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') @@ -217,7 +217,7 @@ describe('Given the foundation plugin', () => { expect(result).toEqual({ from: mint.recipient, to: mint.contractAddress, - data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000e3bba2a4f8e0f5c32ef5097f988a4d88075c8b4800000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', + data: '0x0cafb11300000000000000000000000054d8109b459cefa530cdba2c3a2218c14e08090700000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000', }) }) From 933c9b46aebe99e3c75137d90a1595a2b016bc3b Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 16:41:39 -0700 Subject: [PATCH 9/9] docs(foundation): add comments to failing tests --- packages/foundation/src/Foundation.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/foundation/src/Foundation.test.ts b/packages/foundation/src/Foundation.test.ts index f26680fa7..599e38537 100644 --- a/packages/foundation/src/Foundation.test.ts +++ b/packages/foundation/src/Foundation.test.ts @@ -299,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', @@ -367,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',