@@ -29,7 +29,17 @@ async function main() {
2929 const chainConfig = await getChainConfig ( Number ( chainId ) ) ;
3030 const output : DeploymentAddresses = loadOutput ( ) ;
3131
32- const gasOverrides = chainConfig . gasParams ;
32+ let gasOverrides : any = chainConfig . gasParams ;
33+
34+ // MegaETH chains: remove gasLimit to let network auto-estimate (required for MegaETH)
35+ const MEGAETH_CHAINS = [ 4326 , 6343 ] ; // mainnet and testnet
36+ if ( MEGAETH_CHAINS . includes ( Number ( chainId ) ) ) {
37+ const { gasLimit, ...gasOverridesWithoutLimit } = gasOverrides ;
38+ gasOverrides = gasOverridesWithoutLimit ;
39+ console . log (
40+ 'ℹ️ MegaETH detected: using auto gas estimation (no gasLimit)'
41+ ) ;
42+ }
3343
3444 // Handle BigBlocks setup automatically if supported
3545 if ( isBigBlocksSupported ( Number ( chainId ) ) ) {
@@ -47,22 +57,34 @@ async function main() {
4757 // Estimate gas costs for all potential deployments
4858 let totalEstimatedCost = 0n ;
4959
50- // For chains with very high gas limits (like Mantle), skip estimation and use configured limit
51- const useConfiguredGasLimit = gasOverrides . gasLimit > 10_000_000_000 ; // > 10 billion
60+ // For chains with very high gas limits (like Mantle) or chains with estimation issues (like MegaETH)
61+ // skip estimation and use configured limit
62+ const CHAINS_SKIP_ESTIMATION = [ 4326 , 6343 ] ; // MegaETH mainnet and testnet
63+ const isMegaETH = CHAINS_SKIP_ESTIMATION . includes ( Number ( chainId ) ) ;
64+ const useConfiguredGasLimit =
65+ ( gasOverrides . gasLimit && gasOverrides . gasLimit > 10_000_000_000 ) ||
66+ isMegaETH ;
5267
53- if ( useConfiguredGasLimit ) {
68+ if ( useConfiguredGasLimit && ! isMegaETH ) {
5469 console . log (
5570 `⚠️ Using configured gas limit (${ gasOverrides . gasLimit } ) instead of estimation for this chain`
5671 ) ;
72+ } else if ( isMegaETH ) {
73+ console . log (
74+ 'ℹ️ MegaETH: skipping gas estimation, will use auto-estimation during deployment'
75+ ) ;
5776 }
5877
5978 // Only estimate if we need to deploy (not already deployed)
6079 if (
6180 ! output . walletImplementation ||
6281 ! ( await isContractDeployed ( output . walletImplementation ) )
6382 ) {
64- if ( useConfiguredGasLimit ) {
83+ if ( useConfiguredGasLimit && gasOverrides . gasLimit ) {
6584 totalEstimatedCost += BigInt ( gasOverrides . gasLimit ) ;
85+ } else if ( isMegaETH ) {
86+ // Skip estimation for MegaETH - use reasonable default for cost check
87+ totalEstimatedCost += BigInt ( 3_000_000 ) ;
6688 } else {
6789 const WalletSimple = await ethers . getContractFactory (
6890 chainConfig . walletImplementationContractName
@@ -79,8 +101,10 @@ async function main() {
79101 ! output . walletFactory ||
80102 ! ( await isContractDeployed ( output . walletFactory ) )
81103 ) {
82- if ( useConfiguredGasLimit ) {
104+ if ( useConfiguredGasLimit && gasOverrides . gasLimit ) {
83105 totalEstimatedCost += BigInt ( gasOverrides . gasLimit ) ;
106+ } else if ( isMegaETH ) {
107+ totalEstimatedCost += BigInt ( 3_000_000 ) ;
84108 } else {
85109 const WalletFactory = await ethers . getContractFactory (
86110 chainConfig . walletFactoryContractName
@@ -100,8 +124,10 @@ async function main() {
100124 ! output . forwarderImplementation ||
101125 ! ( await isContractDeployed ( output . forwarderImplementation ) )
102126 ) {
103- if ( useConfiguredGasLimit ) {
127+ if ( useConfiguredGasLimit && gasOverrides . gasLimit ) {
104128 totalEstimatedCost += BigInt ( gasOverrides . gasLimit ) ;
129+ } else if ( isMegaETH ) {
130+ totalEstimatedCost += BigInt ( 3_000_000 ) ;
105131 } else {
106132 const ForwarderV4 = await ethers . getContractFactory (
107133 chainConfig . forwarderContractName
@@ -118,8 +144,10 @@ async function main() {
118144 ! output . forwarderFactory ||
119145 ! ( await isContractDeployed ( output . forwarderFactory ) )
120146 ) {
121- if ( useConfiguredGasLimit ) {
147+ if ( useConfiguredGasLimit && gasOverrides . gasLimit ) {
122148 totalEstimatedCost += BigInt ( gasOverrides . gasLimit ) ;
149+ } else if ( isMegaETH ) {
150+ totalEstimatedCost += BigInt ( 3_000_000 ) ;
123151 } else {
124152 const ForwarderFactory = await ethers . getContractFactory (
125153 chainConfig . forwarderFactoryContractName
0 commit comments