@@ -4,14 +4,32 @@ const { newWalletOptions } = require('../wallet-options');
44const { loadEnvironmentInfo } = require ( '../environment' ) ;
55const fs = require ( 'fs' ) ;
66
7- // Import viem for signature (following Biconomy SDK pattern)
7+ // Import viem for signature and utilities (following Biconomy SDK pattern)
88const { privateKeyToAccount } = require ( 'viem/accounts' ) ;
9+ const {
10+ createPublicClient,
11+ http,
12+ parseEther,
13+ formatEther,
14+ zeroAddress,
15+ encodeAbiParameters,
16+ parseAbiParameters,
17+ concat
18+ } = require ( 'viem' ) ;
919
1020// Import Biconomy SDK for production testing
1121const { createSmartAccountClient } = require ( '@biconomy/abstractjs' ) ;
1222const { toNexusAccount } = require ( '@biconomy/abstractjs' ) ;
1323const { getMEEVersion, DEFAULT_MEE_VERSION } = require ( '@biconomy/abstractjs' ) ;
14- const { http } = require ( 'viem' ) ;
24+
25+ // Create viem public client helper
26+ function createViemPublicClient ( network ) {
27+ const networkConfig = hre . network . config ;
28+ const rpcUrl = networkConfig . url || 'http://localhost:8545' ;
29+ return createPublicClient ( {
30+ transport : http ( rpcUrl )
31+ } ) ;
32+ }
1533
1634// Generate working initData for Nexus deployment
1735async function generateWorkingInitData ( signerAddress , bootstrapAddress , k1ValidatorAddress ) {
@@ -36,15 +54,15 @@ async function generateWorkingInitData(signerAddress, bootstrapAddress, k1Valida
3654 signerAddress , // defaultValidatorInitData (signer address for K1Validator)
3755 [ ] , // validators - EMPTY because K1Validator is already the DEFAULT_VALIDATOR
3856 [ ] , // executors (empty array for 1.2.x)
39- { module : hre . ethers . constants . AddressZero , data : '0x' } , // hook (empty)
57+ { module : zeroAddress , data : '0x' } , // hook (empty)
4058 [ ] , // fallbacks (empty array for 1.2.x)
4159 [ ] // prevalidationHooks (empty array for 1.2.x)
4260 ]
4361 ) ;
4462
4563 // Create the complete initData structure: [bootstrap_address, bootstrap_call_data]
46- const initData = hre . ethers . utils . defaultAbiCoder . encode (
47- [ 'address' , ' bytes'] ,
64+ const initData = encodeAbiParameters (
65+ parseAbiParameters ( 'address, bytes' ) ,
4866 [ bootstrapAddress , bootstrapCallData ]
4967 ) ;
5068
@@ -116,10 +134,10 @@ async function testWalletWithOfficialSDK(deployer, network) {
116134
117135 try {
118136 const targetAddress = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8' ;
119- const transferAmount = hre . ethers . utils . parseEther ( '0.001' ) ;
137+ const transferAmount = parseEther ( '0.001' ) ;
120138
121139 console . log ( `[${ network } ] 🎯 Target: ${ targetAddress } ` ) ;
122- console . log ( `[${ network } ] 💰 Amount: ${ hre . ethers . utils . formatEther ( transferAmount ) } ETH` ) ;
140+ console . log ( `[${ network } ] 💰 Amount: ${ formatEther ( transferAmount ) } ETH` ) ;
123141
124142 const userOp = await smartAccountClient . prepareUserOperation ( {
125143 calls : [ {
@@ -226,16 +244,19 @@ async function deployInfrastructureAndWalletWithCFA() {
226244
227245 console . log ( 'Deployer:' , await deployer . getAddress ( ) ) ;
228246 console . log ( 'Network:' , network ) ;
229- console . log ( 'Balance:' , hre . ethers . utils . formatEther ( await deployer . getBalance ( ) ) , 'ETH' ) ;
247+ console . log ( 'Balance:' , formatEther ( await deployer . getBalance ( ) ) , 'ETH' ) ;
230248 console . log ( '🎯 Deployment Method:' , deploymentMethod ) ;
231249 console . log ( '🔄 CFA Compatibility: ENABLED' ) ;
232250 console . log ( '' ) ;
233251
252+ // Initialize viem public client for code verification
253+ const publicClient = createViemPublicClient ( network ) ;
254+
234255 // PHASE 1: Deploy Infrastructure
235256 console . log ( '🏗️ PHASE 1: DEPLOYING INFRASTRUCTURE WITH CFA COMPATIBILITY' ) ;
236257 console . log ( '===========================================================' ) ;
237258
238- const infrastructure = await deployInfrastructureWithCFA ( deployer , network ) ;
259+ const infrastructure = await deployInfrastructureWithCFA ( deployer , network , publicClient ) ;
239260
240261 // PHASE 2: Deploy Wallet
241262 console . log ( '\n🎯 PHASE 2: DEPLOYING WALLET WITH CFA COMPATIBILITY' ) ;
@@ -314,7 +335,7 @@ async function deployInfrastructureAndWalletWithCFA() {
314335 console . log ( '📁 Complete results saved to complete-deployment-cfa-success.json' ) ;
315336}
316337
317- async function deployInfrastructureWithCFA ( deployer , network ) {
338+ async function deployInfrastructureWithCFA ( deployer , network , publicClient ) {
318339 console . log ( '📦 Deploying infrastructure components with CFA compatibility...\n' ) ;
319340
320341 // Load EntryPoint artifact once for reuse throughout the function
@@ -345,8 +366,8 @@ async function deployInfrastructureWithCFA(deployer, network) {
345366
346367 // Wait and verify
347368 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
348- const factoryCode = await hre . ethers . provider . getCode ( factory . address ) ;
349- if ( factoryCode === '0x' ) throw new Error ( 'Factory deployment verification failed' ) ;
369+ const factoryCode = await publicClient . getCode ( { address : factory . address } ) ;
370+ if ( ! factoryCode || factoryCode === '0x' ) throw new Error ( 'Factory deployment verification failed' ) ;
350371 console . log ( '✅ Old Factory verified with' , Math . floor ( factoryCode . length / 2 ) , 'bytes' ) ;
351372
352373 // 3. Deploy LatestWalletImplLocator (Step 2)
@@ -361,8 +382,8 @@ async function deployInfrastructureWithCFA(deployer, network) {
361382
362383 // Wait and verify
363384 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
364- const locatorCode = await hre . ethers . provider . getCode ( latestWalletImplLocator . address ) ;
365- if ( locatorCode === '0x' ) throw new Error ( 'LatestWalletImplLocator deployment verification failed' ) ;
385+ const locatorCode = await publicClient . getCode ( { address : latestWalletImplLocator . address } ) ;
386+ if ( ! locatorCode || locatorCode === '0x' ) throw new Error ( 'LatestWalletImplLocator deployment verification failed' ) ;
366387 console . log ( '✅ LatestWalletImplLocator verified with' , Math . floor ( locatorCode . length / 2 ) , 'bytes' ) ;
367388
368389 // 4. Deploy StartupWalletImpl (Step 3)
@@ -376,8 +397,8 @@ async function deployInfrastructureWithCFA(deployer, network) {
376397
377398 // Wait and verify
378399 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
379- const startupCode = await hre . ethers . provider . getCode ( startupWalletImpl . address ) ;
380- if ( startupCode === '0x' ) throw new Error ( 'StartupWalletImpl deployment verification failed' ) ;
400+ const startupCode = await publicClient . getCode ( { address : startupWalletImpl . address } ) ;
401+ if ( ! startupCode || startupCode === '0x' ) throw new Error ( 'StartupWalletImpl deployment verification failed' ) ;
381402 console . log ( '✅ StartupWalletImpl verified with' , Math . floor ( startupCode . length / 2 ) , 'bytes' ) ;
382403
383404 // 5. Deploy K1Validator (Nexus Core - Step 4)
@@ -389,15 +410,15 @@ async function deployInfrastructureWithCFA(deployer, network) {
389410
390411 // Wait and verify
391412 await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
392- const validatorCode = await hre . ethers . provider . getCode ( k1Validator . address ) ;
393- if ( validatorCode === '0x' ) throw new Error ( 'K1Validator deployment verification failed' ) ;
413+ const validatorCode = await publicClient . getCode ( { address : k1Validator . address } ) ;
414+ if ( ! validatorCode || validatorCode === '0x' ) throw new Error ( 'K1Validator deployment verification failed' ) ;
394415 console . log ( '✅ K1Validator verified with' , Math . floor ( validatorCode . length / 2 ) , 'bytes' ) ;
395416
396417 // 6. Deploy Nexus Implementation (Step 4)
397418 console . log ( '\n6️⃣ Deploying Nexus Implementation (Step 4)...' ) ;
398419 const NexusFactory = await hre . ethers . getContractFactory ( 'Nexus' , deployer ) ;
399420 const testEntryPoint = '0x70997970C51812dc3A010C7d01b50e0d17dc79C8' ; // Test EntryPoint
400- const initData = hre . ethers . utils . hexConcat ( [ await deployer . getAddress ( ) ] ) ;
421+ const initData = concat ( [ await deployer . getAddress ( ) ] ) ;
401422
402423 const nexus = await NexusFactory . deploy (
403424 testEntryPoint , // entryPoint
@@ -459,7 +480,7 @@ async function deployInfrastructureWithCFA(deployer, network) {
459480 await deployer . getAddress ( ) , // factoryOwner
460481 k1Validator . address , // K1_VALIDATOR
461482 nexusBootstrap . address , // BOOTSTRAPPER
462- hre . ethers . constants . AddressZero // REGISTRY (minimal for now)
483+ zeroAddress // REGISTRY (minimal for now)
463484 ) ;
464485 await k1ValidatorFactory . deployed ( ) ;
465486 console . log ( '✅ K1ValidatorFactory:' , k1ValidatorFactory . address ) ;
@@ -776,18 +797,18 @@ async function testWalletOperations(infrastructure, walletAddress, deployer, net
776797 console . log ( '1️⃣ Testing ETH reception...' ) ;
777798
778799 const initialBalance = await hre . ethers . provider . getBalance ( walletAddress ) ;
779- console . log ( ` Initial wallet balance: ${ hre . ethers . utils . formatEther ( initialBalance ) } ETH` ) ;
800+ console . log ( ` Initial wallet balance: ${ formatEther ( initialBalance ) } ETH` ) ;
780801
781802 // Send some ETH to the wallet
782803 const sendTx = await deployer . sendTransaction ( {
783804 to : walletAddress ,
784- value : hre . ethers . utils . parseEther ( '0.1' ) ,
805+ value : parseEther ( '0.1' ) ,
785806 gasLimit : 100000
786807 } ) ;
787808 await sendTx . wait ( ) ;
788809
789810 const newBalance = await hre . ethers . provider . getBalance ( walletAddress ) ;
790- console . log ( ` ✅ ETH sent successfully! New balance: ${ hre . ethers . utils . formatEther ( newBalance ) } ETH` ) ;
811+ console . log ( ` ✅ ETH sent successfully! New balance: ${ formatEther ( newBalance ) } ETH` ) ;
791812
792813 // Test 2: Check wallet code and type
793814 console . log ( '\n2️⃣ Analyzing wallet structure...' ) ;
0 commit comments