@@ -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" ;
1117import { sendTransaction } from "viem/actions" ;
1218import {
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
7991const 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
0 commit comments