@@ -20,25 +20,149 @@ 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 ( 
38+   userAddress : string , 
39+   chainId : number 
40+ ) : Promise < boolean >  { 
41+   const  config  =  getBigBlocksConfig ( chainId ) ; 
42+   if  ( ! config )  { 
43+     throw  new  Error ( `Chain with ID ${ chainId }   is not supported for BigBlocks.` ) ; 
44+   } 
45+   console . log ( 'Useradd'  +  userAddress ) ; 
46+   console . log ( 
47+     `Checking BigBlocks status for ${ userAddress }   on ${ config . name }  ...` 
48+   ) ; 
49+   console . log ( `Making RPC call to: ${ config . rpcUrl }  ` ) ; 
50+   try  { 
51+     const  requestBody  =  { 
52+       jsonrpc : '2.0' , 
53+       id : 0 , 
54+       method : 'eth_usingBigBlocks' , 
55+       params : [ userAddress ] 
56+     } ; 
57+ 
58+     const  res  =  await  fetch ( config . rpcUrl ,  { 
59+       method : 'POST' , 
60+       headers : { 
61+         'Content-Type' : 'application/json' 
62+       } , 
63+       body : JSON . stringify ( requestBody ) 
64+     } ) ; 
65+ 
66+     if  ( ! res . ok )  { 
67+       throw  new  Error ( `HTTP Error: ${ res . status }   ${ await  res . text ( ) }  ` ) ; 
68+     } 
69+ 
70+     const  result  =  ( await  res . json ( ) )  as  JsonRpcResponse ; 
71+ 
72+     console . log ( result ) ; 
73+ 
74+     if  ( result . error )  { 
75+       throw  new  Error ( 
76+         `RPC Error: ${ result . error . code }   - ${ result . error . message }  ` 
77+       ) ; 
78+     } 
79+ 
80+     return  result . result  ||  false ; 
81+   }  catch  ( err )  { 
82+     console . error ( 'Failed to fetch BigBlocks status.' ) ; 
83+     throw  err ; 
84+   } 
85+ } 
86+ 
87+ /** 
88+  * Enable BigBlocks with retry mechanism 
89+  */ 
90+ async  function  enableBigBlocksWithRetry ( 
91+   config : any , 
92+   chainId : number , 
93+   maxRetries : number  =  3 
94+ ) : Promise < void >  { 
95+   for  ( let  attempt  =  1 ;  attempt  <=  maxRetries ;  attempt ++ )  { 
96+     try  { 
97+       console . log ( 
98+         ` Attempt ${ attempt }  /${ maxRetries }  : Enabling BigBlocks on ${ config . name }  ` 
99+       ) ; 
100+       await  enableBigBlocks ( config . envKey ,  true ,  chainId ) ; 
101+       console . log ( ` BigBlocks enabled on ${ config . name }   (attempt ${ attempt }  )` ) ; 
102+       return ; 
103+     }  catch  ( error )  { 
104+       console . log ( 
105+         `Attempt ${ attempt }  /${ maxRetries }   failed:` , 
106+         ( error  as  Error ) . message 
107+       ) ; 
108+ 
109+       if  ( attempt  ===  maxRetries )  { 
110+         throw  new  Error ( 
111+           `Failed to enable BigBlocks on ${  
112+             config . name  
113+           }   after ${ maxRetries }   attempts: ${ ( error  as  Error ) . message }  `
114+         ) ; 
115+       } 
116+ 
117+       // Wait 2 seconds before retry 
118+       console . log ( ' Waiting 2 seconds before retry...' ) ; 
119+       await  new  Promise ( ( resolve )  =>  setTimeout ( resolve ,  2000 ) ) ; 
120+     } 
121+   } 
122+ } 
123+ 
124+ /** 
125+  * Setup BigBlocks for a specific chain 
126+  */ 
127+ async  function  setupBigBlocks ( 
128+   chainId : number , 
129+   deployerAddress : string 
130+ ) : Promise < void >  { 
27131  const  config  =  getBigBlocksConfig ( chainId ) ; 
28132  if  ( ! config )  return ; 
29133
30134  if  ( ! config . envKey )  { 
31135    throw  new  Error ( `Please set the private key for ${ config . name }  .` ) ; 
32136  } 
33137
34-   console . log ( `Using BigBlocks on ${ config . name }  ` ) ; 
35-   try  { 
36-     await  enableBigBlocks ( config . envKey ,  true ,  chainId ) ; 
37-   }  catch  ( error )  { 
138+   console . log ( ` Checking BigBlocks status on ${ config . name }  ...` ) ; 
139+ 
140+   // Check if BigBlocks is already enabled 
141+   const  isEnabled  =  await  checkBigBlocksStatus ( deployerAddress ,  chainId ) ; 
142+ 
143+   if  ( isEnabled )  { 
144+     console . log ( `BigBlocks already enabled on ${ config . name }  ` ) ; 
145+     return ; 
146+   } 
147+ 
148+   console . log ( 
149+     ` BigBlocks not enabled on ${ config . name }  , attempting to enable...` 
150+   ) ; 
151+ 
152+   // Try to enable BigBlocks with retry mechanism 
153+   await  enableBigBlocksWithRetry ( config ,  chainId ,  3 ) ; 
154+ 
155+   // Verify it was enabled successfully 
156+   console . log ( `Verifying BigBlocks was enabled...` ) ; 
157+   const  isEnabledAfter  =  await  checkBigBlocksStatus ( deployerAddress ,  chainId ) ; 
158+ 
159+   if  ( ! isEnabledAfter )  { 
38160    throw  new  Error ( 
39-       `Failed to setup BigBlocks  on ${ config . name } :  ${ ( error   as   Error ) . message }  ` 
161+       `BigBlocks enable command succeeded but verification failed  on ${ config . name }  ` 
40162    ) ; 
41163  } 
164+ 
165+   console . log ( `BigBlocks successfully verified as enabled on ${ config . name }  ` ) ; 
42166} 
43167
44168async  function  main ( )  { 
@@ -47,15 +171,16 @@ async function main() {
47171  const  currentNonce  =  await  ethers . provider . getTransactionCount ( 
48172    deployerAddress 
49173  ) ; 
50-   const  {  chainId }  =  await  ethers . provider . getNetwork ( ) ;   // More direct way to get chainId 
174+   const  {  chainId }  =  await  ethers . provider . getNetwork ( ) ; 
51175  const  chainConfig  =  await  getChainConfig ( Number ( chainId ) ) ; 
52176  const  output : DeploymentAddresses  =  loadOutput ( ) ; 
53177
54178  const  gasOverrides  =  chainConfig . gasParams ; 
55179
180+   // Handle BigBlocks setup automatically if supported 
56181  if  ( isBigBlocksSupported ( Number ( chainId ) ) )  { 
57-     console . log ( '🔄 Setting up BigBlocks ...' ) ; 
58-     await  setupBigBlocks ( Number ( chainId ) ) ; 
182+     console . log ( '🔍 BigBlocks supported on this chain, checking status ...' ) ; 
183+     await  setupBigBlocks ( Number ( chainId ) ,   deployerAddress ) ; 
59184  } 
60185
61186  console . log ( 
@@ -105,7 +230,7 @@ async function main() {
105230      const  WalletFactory  =  await  ethers . getContractFactory ( 
106231        chainConfig . walletFactoryContractName 
107232      ) ; 
108-       const  contract  =  await  WalletFactory . deploy ( walletAddress ,  gasOverrides ) ;   // constructor args + overrides 
233+       const  contract  =  await  WalletFactory . deploy ( walletAddress ,  gasOverrides ) ; 
109234      await  contract . waitForDeployment ( ) ; 
110235      console . log ( 
111236        `✅ ${ chainConfig . walletFactoryContractName }   deployed at ${ contract . target }  ` 
@@ -132,7 +257,7 @@ async function main() {
132257      const  Forwarder  =  await  ethers . getContractFactory ( 
133258        chainConfig . forwarderContractName 
134259      ) ; 
135-       const  contract  =  await  Forwarder . deploy ( gasOverrides ) ;   // overrides only 
260+       const  contract  =  await  Forwarder . deploy ( gasOverrides ) ; 
136261      await  contract . waitForDeployment ( ) ; 
137262      console . log ( 
138263        `✅ ${ chainConfig . forwarderContractName }   deployed at ${ contract . target }  ` 
@@ -157,7 +282,7 @@ async function main() {
157282      const  contract  =  await  ForwarderFactory . deploy ( 
158283        forwarderAddress , 
159284        gasOverrides 
160-       ) ;   // constructor args + overrides 
285+       ) ; 
161286      await  contract . waitForDeployment ( ) ; 
162287      console . log ( 
163288        `✅ ${ chainConfig . forwarderFactoryContractName }   deployed at ${ contract . target }  ` 
0 commit comments