Skip to content

Commit 62eeb10

Browse files
committed
fix(sdk): fix bug with fork behavior using mine()
NomicFoundation/hardhat#5511
1 parent b6a5476 commit 62eeb10

File tree

4 files changed

+128
-86
lines changed

4 files changed

+128
-86
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@commitlint/config-conventional": "^19.2.2",
3333
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
3434
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
35+
"@nomicfoundation/hardhat-viem": "2.0.4",
3536
"@types/node": "^20.11.24",
3637
"@vitest/coverage-v8": "^1.6.0",
3738
"@wagmi/core": "^2.13.4",

packages/sdk/hardhat.config.cjs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
require('dotenv').config();
12
require('@nomicfoundation/hardhat-toolbox-viem');
2-
33
module.exports = {
4-
solidity: '0.8.24',
4+
networks: {
5+
hardhat: {
6+
// We might not need the mine() function if we use this code https://github.com/NomicFoundation/hardhat/pull/5394/files
7+
chainId: 8453, // Base mainnet chain ID
8+
//hardfork: 'cancun',
9+
forking: {
10+
url:
11+
'https://base-mainnet.g.alchemy.com/v2/' +
12+
process.env.ALCHEMY_API_KEY,
13+
},
14+
},
15+
},
516
};

packages/sdk/test/zora-fork-mint.test.ts

+32-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
import { selectors } from '@boostxyz/signatures/events';
12
import {
23
loadFixture,
3-
reset,
4+
mine,
45
} from '@nomicfoundation/hardhat-toolbox-viem/network-helpers';
5-
import { type Address, type Hex, parseEther } from 'viem';
6+
import hre from 'hardhat';
7+
import {
8+
type Address,
9+
type Hex,
10+
type PublicClient,
11+
type WalletClient,
12+
parseEther,
13+
} from 'viem';
614
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
715
import { BoostCore } from '../src/BoostCore';
816
import {
@@ -19,53 +27,66 @@ import {
1927
deployFixtures,
2028
fundBudget,
2129
} from './helpers';
30+
import { setupConfig, testAccount } from './viem';
2231

2332
let fixtures: Fixtures, budgets: BudgetFixtures;
2433

2534
describe('Boost with NFT Minting Incentive', () => {
26-
const ZORA_CHAIN_URL = process.env.VITE_BASE_MAINNET_RPC;
27-
const ZORA_CHAIN_BLOCK = 19694536; // Replace with actual block number
35+
// We take the address of the imposter from the transaction above
36+
const boostImpostor = '0xE59C9Ca7FFA00471AA2ADA42C0a65C6CaabD06B8' as Address;
2837

38+
const selector = selectors[
39+
'Purchased(address,address,uint256,uint256,uint256)'
40+
] as Hex;
2941
beforeAll(async () => {
30-
await reset(ZORA_CHAIN_URL, ZORA_CHAIN_BLOCK);
42+
//await reset(BASE_CHAIN_URL, BASE_CHAIN_BLOCK);
3143
fixtures = await loadFixture(deployFixtures);
3244
});
45+
3346
beforeEach(async () => {
3447
budgets = await loadFixture(fundBudget(defaultOptions, fixtures));
3548
});
3649

3750
test('should create a boost for incentivizing NFT minting', async () => {
3851
const { budget, erc20 } = budgets;
3952
const targetContract = '0xDa8dD2807A33FDA5983F56812765a88B46f0B90B';
53+
const walletClient = await hre.viem.getWalletClient(testAccount.address);
4054

55+
// This is the zora contract we're going to push a transaction against
56+
//const contractEntryPoint = '0x9D2FC5fFE5939Efd1d573f975BC5EEFd364779ae';
4157
const { core, bases } = fixtures;
4258
const client = new BoostCore({
43-
...defaultOptions,
59+
// biome-ignore lint/suspicious/noExplicitAny: The hardhat and wagmi wallet clients are compatible
60+
config: setupConfig(walletClient as any),
61+
account: testAccount,
4462
address: core.assertValidAddress(),
4563
});
4664
const owner = defaultOptions.account.address;
65+
// This is a workaround to this known issue: https://github.com/NomicFoundation/hardhat/issues/5511
66+
await mine();
4767

4868
// Step defining the action for Transfer event
4969
const eventActionStep: ActionStep = {
50-
signature: '0xddf252ad', // Transfer(address,address,uint256) event signature
70+
signature: selector, // Transfer(address,address,uint256) event signature
5171
signatureType: SignatureType.EVENT, // We're working with an event
5272
actionType: 0, // Custom action type (set as 0 for now)
5373
targetContract: targetContract, // Address of the ERC20 contract
74+
// We want to target the Minter property on the Purchase event
5475
actionParameter: {
5576
filterType: FilterType.EQUAL, // Filter to check for equality
5677
fieldType: PrimitiveType.ADDRESS, // The field we're filtering is an address
57-
fieldIndex: 0, // Field 0 is the 'from' address in the event
58-
filterData: targetContract, // Filtering based on the core address
78+
fieldIndex: 1, // Might need to be 2, we'll see - let's log this
79+
filterData: boostImpostor, // Filtering based on the core address
5980
},
6081
};
6182

6283
// Define EventActionPayload manually
6384
const eventActionPayload = {
6485
actionClaimant: {
6586
signatureType: SignatureType.EVENT,
66-
signature: '0xddf252ad' as Hex, // Transfer(address,address,uint256) event signature
87+
signature: selector, // Transfer(address,address,uint256) event signature
6788
fieldIndex: 0, // Targeting the 'from' address
68-
targetContract: targetContract as Address, // The ERC20 contract we're monitoring
89+
targetContract: boostImpostor, // The ERC20 contract we're monitoring
6990
},
7091
actionStepOne: eventActionStep, // Use the custom step for action
7192
actionStepTwo: eventActionStep, // Repeat the action step if necessary
@@ -79,11 +100,6 @@ describe('Boost with NFT Minting Incentive', () => {
79100
eventActionPayload,
80101
);
81102

82-
console.log('Creating boost with EventAction');
83-
console.log('owner:', owner);
84-
console.log('budget:', budget);
85-
console.log('eventAction:', eventAction);
86-
console.log('erc20:', erc20);
87103
// Create the boost using the custom EventAction
88104
await client.createBoost({
89105
protocolFee: 1n,

0 commit comments

Comments
 (0)