Skip to content

Commit d6e5e24

Browse files
committed
fix(mock-contract-deployer): resolve deployment stalling issues
- Use viem test client with generatePrivateKey for wallet creation - Seed deployer wallet with ETH before contract deployment - Replace custom anvilMine with viem's built-in mine method - Add proper nonce synchronization with sleep interval - Normalize addresses using getAddress for consistency - Update TypeScript config with explicit compiler options
1 parent 78a4322 commit d6e5e24

3 files changed

Lines changed: 64 additions & 42 deletions

File tree

mock-contract-deployer/src/index.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ import {
66
createWalletClient,
77
defineChain,
88
parseEther,
9+
getAddress,
10+
Chain,
911
} from "viem";
10-
import { mnemonicToAccount } from "viem/accounts";
12+
import {
13+
generatePrivateKey,
14+
mnemonicToAccount,
15+
privateKeyToAccount,
16+
} from "viem/accounts";
1117
import { sendTransaction } from "viem/actions";
1218
import {
1319
BICONOMY_ACCOUNT_V2_LOGIC_CREATECALL,
@@ -46,13 +52,19 @@ import {
4652
SIMPLE_ACCOUNT_FACTORY_V08_CREATECALL,
4753
SIMPLE_7702_ACCOUNT_IMPLEMENTATION_V08_CREATECALL,
4854
} from "./constants";
49-
import { anvilMine, sleep } from "./utils"
50-
51-
const DETERMINISTIC_DEPLOYER = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
52-
const SAFE_SINGLETON_FACTORY = "0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7";
53-
const BICONOMY_SINGLETON_FACTORY = "0x988C135a1049Ce61730724afD342fb7C56CD2776";
54-
55-
async function getChain(): Promise<ReturnType<typeof defineChain>> {
55+
import { sleep } from "./utils";
56+
57+
const DETERMINISTIC_DEPLOYER = getAddress(
58+
"0x4e59b44847b379578588920ca78fbf26c0b4956c",
59+
);
60+
const SAFE_SINGLETON_FACTORY = getAddress(
61+
"0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7",
62+
);
63+
const BICONOMY_SINGLETON_FACTORY = getAddress(
64+
"0x988C135a1049Ce61730724afD342fb7C56CD2776",
65+
);
66+
67+
async function getChain(): Promise<Chain> {
5668
const tempClient = createPublicClient({
5769
transport: http(process.env.ANVIL_RPC),
5870
});
@@ -77,15 +89,9 @@ async function getChain(): Promise<ReturnType<typeof defineChain>> {
7789
}
7890

7991
const main = async () => {
80-
const chain = await getChain();
81-
const walletClient = createWalletClient({
82-
account: mnemonicToAccount(
83-
"test test test test test test test test test test test junk",
84-
),
85-
chain,
86-
transport: http(process.env.ANVIL_RPC),
87-
});
92+
const chain: Chain = await getChain();
8893

94+
// Create clients.
8995
const anvilClient = createTestClient({
9096
transport: http(process.env.ANVIL_RPC),
9197
mode: "anvil",
@@ -97,6 +103,18 @@ const main = async () => {
97103
chain,
98104
});
99105

106+
const walletClient = createWalletClient({
107+
account: privateKeyToAccount(generatePrivateKey()),
108+
chain,
109+
transport: http(process.env.ANVIL_RPC),
110+
});
111+
112+
// Seed wallet with ETH for deployment.
113+
await anvilClient.setBalance({
114+
address: walletClient.account.address,
115+
value: parseEther("1000"),
116+
});
117+
100118
const verifyDeployed = async (addresses: Address[]) => {
101119
for (const address of addresses) {
102120
const bytecode = await client.getCode({
@@ -160,7 +178,6 @@ const main = async () => {
160178
data: ENTRY_POINT_V08_CREATECALL,
161179
gas: 15_000_000n,
162180
nonce: nonce++,
163-
chain,
164181
})
165182
.then(() => console.log("[V0.8 CORE] Deploying EntryPoint"));
166183

@@ -509,10 +526,14 @@ const main = async () => {
509526
let onchainNonce = 0;
510527
do {
511528
// Mine a new block including all pending txs so the nonce syncs
512-
await anvilMine(1);
529+
await anvilClient.mine({ blocks: 1 });
530+
531+
// Update nonce
513532
onchainNonce = await client.getTransactionCount({
514533
address: walletClient.account.address,
515534
});
535+
536+
// Sleep for a bit to ensure the nonce is updated
516537
await sleep(500);
517538
} while (onchainNonce !== nonce);
518539

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
const url = new URL(process.env.ANVIL_RPC || 'http://anvil:8545');
2-
3-
export async function anvilMine(numBlocks: number = 1, interval?: number) {
4-
await fetch(url, {
5-
method: "POST",
6-
headers: { "content-type": "application/json" },
7-
body: JSON.stringify({
8-
jsonrpc: "2.0",
9-
id: 1,
10-
method: "anvil_mine",
11-
params: [ numBlocks, interval ]
12-
})
13-
}).then(res => {
14-
if (!res.ok) throw new Error("anvil_mine failed")
15-
})
16-
}
17-
181
export async function sleep(ms: number) {
19-
return new Promise(resolve => setTimeout(resolve, ms))
20-
}
2+
return new Promise((resolve) => setTimeout(resolve, ms));
3+
}
Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
{
2-
"extends": "@tsconfig/node22/tsconfig.json",
3-
"include": [
4-
"src/**/*.ts"
5-
]
6-
}
2+
"compilerOptions": {
3+
"outDir": "esm",
4+
"target": "esnext",
5+
"module": "ESNext",
6+
"esModuleInterop": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"strict": true,
9+
"noImplicitReturns": true,
10+
"noUnusedLocals": true,
11+
"preserveConstEnums": true,
12+
"removeComments": false,
13+
"resolveJsonModule": true,
14+
"sourceMap": true,
15+
"skipLibCheck": true,
16+
"declaration": true,
17+
"declarationMap": true,
18+
"moduleResolution": "node"
19+
},
20+
"tsc-alias": {
21+
"resolveFullPaths": true,
22+
}
23+
}
24+

0 commit comments

Comments
 (0)