@@ -20,25 +20,125 @@ const NONCE = {
2020  FORWARDER_FACTORY : 3 
2121} ; 
2222
23+ // Add interface for JSON RPC response 
24+ interface  JsonRpcResponse  { 
25+   jsonrpc : string ; 
26+   id : number ; 
27+   result ?: boolean ; 
28+   error ?: { 
29+     code : number ; 
30+     message : string ; 
31+   } ; 
32+ } 
33+ 
2334/** 
24-  * Configure  BigBlocks for HypeEVM network  
35+  * Check if  BigBlocks is already enabled using RPC call  
2536 */ 
26- async  function  setupBigBlocks ( chainId : number ) : Promise < void >  { 
37+ async  function  checkBigBlocksStatus ( userAddress : string ,  chainId : number ) : Promise < boolean >  { 
38+   const  config  =  getBigBlocksConfig ( chainId ) ; 
39+   if  ( ! config )  { 
40+     throw  new  Error ( `Chain with ID ${ chainId }   is not supported for BigBlocks.` ) ; 
41+   } 
42+    console . log ( "Useradd"  +  userAddress ) ; 
43+   console . log ( `Checking BigBlocks status for ${ userAddress }   on ${ config . name }  ...` ) ; 
44+   console . log ( `Making RPC call to: ${ config . rpcUrl }  ` ) ; 
45+   try  { 
46+     const  requestBody  =  { 
47+       jsonrpc : '2.0' , 
48+       id : 0 , 
49+       method : 'eth_usingBigBlocks' , 
50+       params : [ userAddress ] , 
51+     } ; 
52+ 
53+     const  res  =  await  fetch ( config . rpcUrl ,  { 
54+       method : 'POST' , 
55+       headers : { 
56+         'Content-Type' : 'application/json' , 
57+       } , 
58+       body : JSON . stringify ( requestBody ) , 
59+     } ) ; 
60+ 
61+     if  ( ! res . ok )  { 
62+       throw  new  Error ( `HTTP Error: ${ res . status }   ${ await  res . text ( ) }  ` ) ; 
63+     } 
64+ 
65+     const  result  =  ( await  res . json ( ) )  as  JsonRpcResponse ; 
66+ 
67+     console . log ( result ) ; 
68+ 
69+     if  ( result . error )  { 
70+       throw  new  Error ( `RPC Error: ${ result . error . code }   - ${ result . error . message }  ` ) ; 
71+     } 
72+ 
73+     return  result . result  ||  false ; 
74+ 
75+   }  catch  ( err )  { 
76+     console . error ( 'Failed to fetch BigBlocks status.' ) ; 
77+     throw  err ; 
78+   } 
79+ } 
80+ 
81+ /** 
82+  * Enable BigBlocks with retry mechanism 
83+  */ 
84+ async  function  enableBigBlocksWithRetry ( config : any ,  chainId : number ,  maxRetries : number  =  3 ) : Promise < void >  { 
85+   for  ( let  attempt  =  1 ;  attempt  <=  maxRetries ;  attempt ++ )  { 
86+     try  { 
87+       console . log ( ` Attempt ${ attempt }  /${ maxRetries }  : Enabling BigBlocks on ${ config . name }  ` ) ; 
88+       await  enableBigBlocks ( config . envKey ,  true ,  chainId ) ; 
89+       console . log ( ` BigBlocks enabled on ${ config . name }   (attempt ${ attempt }  )` ) ; 
90+       return ; 
91+     }  catch  ( error )  { 
92+       console . log ( `Attempt ${ attempt }  /${ maxRetries }   failed:` ,  ( error  as  Error ) . message ) ; 
93+       
94+       if  ( attempt  ===  maxRetries )  { 
95+         throw  new  Error ( 
96+           `Failed to enable BigBlocks on ${ config . name }   after ${ maxRetries }   attempts: ${ ( error  as  Error ) . message }  ` 
97+         ) ; 
98+       } 
99+       
100+       // Wait 2 seconds before retry 
101+       console . log ( ' Waiting 2 seconds before retry...' ) ; 
102+       await  new  Promise ( resolve  =>  setTimeout ( resolve ,  2000 ) ) ; 
103+     } 
104+   } 
105+ } 
106+ 
107+ /** 
108+  * Setup BigBlocks for a specific chain 
109+  */ 
110+ async  function  setupBigBlocks ( chainId : number ,  deployerAddress : string ) : Promise < void >  { 
27111  const  config  =  getBigBlocksConfig ( chainId ) ; 
28112  if  ( ! config )  return ; 
29113
30114  if  ( ! config . envKey )  { 
31115    throw  new  Error ( `Please set the private key for ${ config . name }  .` ) ; 
32116  } 
33117
34-   console . log ( `Using BigBlocks on ${ config . name }  ` ) ; 
35-   try  { 
36-     await  enableBigBlocks ( config . envKey ,  true ,  chainId ) ; 
37-   }  catch  ( error )  { 
38-     throw  new  Error ( 
39-       `Failed to setup BigBlocks on ${ config . name }  : ${ ( error  as  Error ) . message }  ` 
40-     ) ; 
118+   console . log ( ` Checking BigBlocks status on ${ config . name }  ...` ) ; 
119+   
120+   // Check if BigBlocks is already enabled 
121+   const  isEnabled  =  await  checkBigBlocksStatus ( deployerAddress ,  chainId ) ; 
122+   
123+   if  ( isEnabled )  { 
124+     console . log ( `BigBlocks already enabled on ${ config . name }  ` ) ; 
125+     return ; 
41126  } 
127+ 
128+   console . log ( ` BigBlocks not enabled on ${ config . name }  , attempting to enable...` ) ; 
129+   
130+   // Try to enable BigBlocks with retry mechanism 
131+   await  enableBigBlocksWithRetry ( config ,  chainId ,  3 ) ; 
132+   
133+   // Verify it was enabled successfully 
134+   console . log ( `Verifying BigBlocks was enabled...` ) ; 
135+   const  isEnabledAfter  =  await  checkBigBlocksStatus ( deployerAddress ,  chainId ) ; 
136+   
137+   if  ( ! isEnabledAfter )  { 
138+     throw  new  Error ( `BigBlocks enable command succeeded but verification failed on ${ config . name }  ` ) ; 
139+   } 
140+   
141+   console . log ( `BigBlocks successfully verified as enabled on ${ config . name }  ` ) ; 
42142} 
43143
44144async  function  main ( )  { 
@@ -47,15 +147,16 @@ async function main() {
47147  const  currentNonce  =  await  ethers . provider . getTransactionCount ( 
48148    deployerAddress 
49149  ) ; 
50-   const  {  chainId }  =  await  ethers . provider . getNetwork ( ) ;   // More direct way to get chainId 
150+   const  {  chainId }  =  await  ethers . provider . getNetwork ( ) ; 
51151  const  chainConfig  =  await  getChainConfig ( Number ( chainId ) ) ; 
52152  const  output : DeploymentAddresses  =  loadOutput ( ) ; 
53153
54154  const  gasOverrides  =  chainConfig . gasParams ; 
55155
156+   // Handle BigBlocks setup automatically if supported 
56157  if  ( isBigBlocksSupported ( Number ( chainId ) ) )  { 
57-     console . log ( '🔄 Setting up BigBlocks ...' ) ; 
58-     await  setupBigBlocks ( Number ( chainId ) ) ; 
158+     console . log ( '🔍 BigBlocks supported on this chain, checking status ...' ) ; 
159+     await  setupBigBlocks ( Number ( chainId ) ,   deployerAddress ) ; 
59160  } 
60161
61162  console . log ( 
@@ -105,7 +206,7 @@ async function main() {
105206      const  WalletFactory  =  await  ethers . getContractFactory ( 
106207        chainConfig . walletFactoryContractName 
107208      ) ; 
108-       const  contract  =  await  WalletFactory . deploy ( walletAddress ,  gasOverrides ) ;   // constructor args + overrides 
209+       const  contract  =  await  WalletFactory . deploy ( walletAddress ,  gasOverrides ) ; 
109210      await  contract . waitForDeployment ( ) ; 
110211      console . log ( 
111212        `✅ ${ chainConfig . walletFactoryContractName }   deployed at ${ contract . target }  ` 
@@ -132,7 +233,7 @@ async function main() {
132233      const  Forwarder  =  await  ethers . getContractFactory ( 
133234        chainConfig . forwarderContractName 
134235      ) ; 
135-       const  contract  =  await  Forwarder . deploy ( gasOverrides ) ;   // overrides only 
236+       const  contract  =  await  Forwarder . deploy ( gasOverrides ) ; 
136237      await  contract . waitForDeployment ( ) ; 
137238      console . log ( 
138239        `✅ ${ chainConfig . forwarderContractName }   deployed at ${ contract . target }  ` 
@@ -157,7 +258,7 @@ async function main() {
157258      const  contract  =  await  ForwarderFactory . deploy ( 
158259        forwarderAddress , 
159260        gasOverrides 
160-       ) ;   // constructor args + overrides 
261+       ) ; 
161262      await  contract . waitForDeployment ( ) ; 
162263      console . log ( 
163264        `✅ ${ chainConfig . forwarderFactoryContractName }   deployed at ${ contract . target }  ` 
@@ -180,4 +281,4 @@ async function main() {
180281main ( ) . catch ( ( error )  =>  { 
181282  console . error ( error ) ; 
182283  process . exitCode  =  1 ; 
183- } ) ; 
284+ } ) ; 
0 commit comments