Skip to content

Commit 5fd952d

Browse files
committed
refactor(megaeth): use standard config like Apechain
- Add MegaETH to same case block as Apechain (no special gas handling) - Remove skipGasEstimation and defaultGasEstimate from interface - Remove all MegaETH-specific code from deploy.ts - MegaETH now uses standard gas params like other chains Ticket: WIN-8361
1 parent 19b3ecf commit 5fd952d

2 files changed

Lines changed: 10 additions & 58 deletions

File tree

scripts/chainConfig.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export interface ChainConfig {
88
forwarderFactoryContractName: string;
99
contractPath: string;
1010
gasParams: GasParams;
11-
skipGasEstimation?: boolean; // For chains that need auto gas estimation
12-
defaultGasEstimate?: number; // Default gas estimate when skipping actual estimation
1311
}
1412

1513
export type GasParams = {
@@ -50,8 +48,6 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
5048
let forwarderContractName = 'Forwarder';
5149
let forwarderFactoryContractName = 'ForwarderFactoryV4';
5250
let contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`;
53-
let skipGasEstimation = false;
54-
let defaultGasEstimate: number | undefined = undefined;
5551

5652
switch (chainId) {
5753
case CHAIN_IDS.ETH_MAINNET:
@@ -110,6 +106,8 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
110106
case CHAIN_IDS.PHAROS_TESTNET:
111107
case CHAIN_IDS.APECHAIN:
112108
case CHAIN_IDS.APECHAIN_TESTNET:
109+
case CHAIN_IDS.MEGAETH:
110+
case CHAIN_IDS.MEGAETH_TESTNET:
113111
case CHAIN_IDS.CORE_DAO:
114112
case CHAIN_IDS.CORE_DAO_TESTNET:
115113
case CHAIN_IDS.LINEAETH:
@@ -249,15 +247,6 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
249247
forwarderFactoryContractName = 'ForwarderFactoryV4';
250248
break;
251249

252-
case CHAIN_IDS.MEGAETH_TESTNET:
253-
case CHAIN_IDS.MEGAETH:
254-
// MegaETH requires auto gas estimation - gasLimit will be removed during deployment
255-
skipGasEstimation = true;
256-
defaultGasEstimate = 3_000_000; // Used for balance check when skipping estimation
257-
forwarderContractName = 'ForwarderV4';
258-
forwarderFactoryContractName = 'ForwarderFactoryV4';
259-
break;
260-
261250
case CHAIN_IDS.HBAREVM:
262251
case CHAIN_IDS.HBAREVM_TESTNET:
263252

@@ -334,8 +323,6 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
334323
forwarderContractName,
335324
forwarderFactoryContractName,
336325
contractPath,
337-
gasParams,
338-
skipGasEstimation,
339-
defaultGasEstimate
326+
gasParams
340327
};
341328
}

scripts/deploy.ts

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,7 @@ async function main() {
2929
const chainConfig = await getChainConfig(Number(chainId));
3030
const output: DeploymentAddresses = loadOutput();
3131

32-
let gasOverrides: any = chainConfig.gasParams;
33-
34-
// For chains that need auto gas estimation, remove gasLimit
35-
if (chainConfig.skipGasEstimation) {
36-
const { gasLimit, ...gasOverridesWithoutLimit } = gasOverrides;
37-
gasOverrides = gasOverridesWithoutLimit;
38-
console.log(
39-
'ℹ️ Chain configured for auto gas estimation (no gasLimit override)'
40-
);
41-
}
32+
const gasOverrides = chainConfig.gasParams;
4233

4334
// Handle BigBlocks setup automatically if supported
4435
if (isBigBlocksSupported(Number(chainId))) {
@@ -56,33 +47,22 @@ async function main() {
5647
// Estimate gas costs for all potential deployments
5748
let totalEstimatedCost = 0n;
5849

59-
// For chains with very high gas limits (like Mantle) or chains that skip gas estimation
60-
const useConfiguredGasLimit =
61-
gasOverrides.gasLimit && gasOverrides.gasLimit > 10_000_000_000;
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
6252

6353
if (useConfiguredGasLimit) {
6454
console.log(
6555
`⚠️ Using configured gas limit (${gasOverrides.gasLimit}) instead of estimation for this chain`
6656
);
67-
} else if (chainConfig.skipGasEstimation) {
68-
console.log(
69-
'ℹ️ Skipping gas estimation, will use auto-estimation during deployment'
70-
);
7157
}
7258

7359
// Only estimate if we need to deploy (not already deployed)
7460
if (
7561
!output.walletImplementation ||
7662
!(await isContractDeployed(output.walletImplementation))
7763
) {
78-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
64+
if (useConfiguredGasLimit) {
7965
totalEstimatedCost += BigInt(gasOverrides.gasLimit);
80-
} else if (
81-
chainConfig.skipGasEstimation &&
82-
chainConfig.defaultGasEstimate
83-
) {
84-
// Skip estimation - use configured default for cost check
85-
totalEstimatedCost += BigInt(chainConfig.defaultGasEstimate);
8666
} else {
8767
const WalletSimple = await ethers.getContractFactory(
8868
chainConfig.walletImplementationContractName
@@ -99,13 +79,8 @@ async function main() {
9979
!output.walletFactory ||
10080
!(await isContractDeployed(output.walletFactory))
10181
) {
102-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
82+
if (useConfiguredGasLimit) {
10383
totalEstimatedCost += BigInt(gasOverrides.gasLimit);
104-
} else if (
105-
chainConfig.skipGasEstimation &&
106-
chainConfig.defaultGasEstimate
107-
) {
108-
totalEstimatedCost += BigInt(chainConfig.defaultGasEstimate);
10984
} else {
11085
const WalletFactory = await ethers.getContractFactory(
11186
chainConfig.walletFactoryContractName
@@ -125,13 +100,8 @@ async function main() {
125100
!output.forwarderImplementation ||
126101
!(await isContractDeployed(output.forwarderImplementation))
127102
) {
128-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
103+
if (useConfiguredGasLimit) {
129104
totalEstimatedCost += BigInt(gasOverrides.gasLimit);
130-
} else if (
131-
chainConfig.skipGasEstimation &&
132-
chainConfig.defaultGasEstimate
133-
) {
134-
totalEstimatedCost += BigInt(chainConfig.defaultGasEstimate);
135105
} else {
136106
const ForwarderV4 = await ethers.getContractFactory(
137107
chainConfig.forwarderContractName
@@ -148,13 +118,8 @@ async function main() {
148118
!output.forwarderFactory ||
149119
!(await isContractDeployed(output.forwarderFactory))
150120
) {
151-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
121+
if (useConfiguredGasLimit) {
152122
totalEstimatedCost += BigInt(gasOverrides.gasLimit);
153-
} else if (
154-
chainConfig.skipGasEstimation &&
155-
chainConfig.defaultGasEstimate
156-
) {
157-
totalEstimatedCost += BigInt(chainConfig.defaultGasEstimate);
158123
} else {
159124
const ForwarderFactory = await ethers.getContractFactory(
160125
chainConfig.forwarderFactoryContractName

0 commit comments

Comments
 (0)