Skip to content

Commit 91094b6

Browse files
committed
feat(megaeth): add MegaETH mainnet and testnet support
- Add MegaETH mainnet (Chain ID: 4326) and testnet (Chain ID: 6343) - Add network config and Etherscan v2 verification support - MegaETH uses same gas params as Apechain (no special handling) Ticket: WIN-8361
1 parent dfcc929 commit 91094b6

2 files changed

Lines changed: 75 additions & 98 deletions

File tree

scripts/chainConfig.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
106106
case CHAIN_IDS.PHAROS_TESTNET:
107107
case CHAIN_IDS.APECHAIN:
108108
case CHAIN_IDS.APECHAIN_TESTNET:
109+
case CHAIN_IDS.MEGAETH:
110+
case CHAIN_IDS.MEGAETH_TESTNET:
109111
case CHAIN_IDS.CORE_DAO:
110112
case CHAIN_IDS.CORE_DAO_TESTNET:
111113
case CHAIN_IDS.LINEAETH:
@@ -245,19 +247,6 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
245247
forwarderFactoryContractName = 'ForwarderFactoryV4';
246248
break;
247249

248-
case CHAIN_IDS.MEGAETH_TESTNET:
249-
case CHAIN_IDS.MEGAETH:
250-
// MegaETH: Must use EIP-1559 params with high gas limit
251-
// Gas price is very low (~0.001 Gwei), so high limit is cheap
252-
gasParams = {
253-
maxFeePerGas: feeData.maxFeePerGas ?? 2_000_000n,
254-
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? 1_000_000n,
255-
gasLimit: 30_000_000 // MegaETH needs higher gas limits
256-
};
257-
forwarderContractName = 'ForwarderV4';
258-
forwarderFactoryContractName = 'ForwarderFactoryV4';
259-
break;
260-
261250
case CHAIN_IDS.HBAREVM:
262251
case CHAIN_IDS.HBAREVM_TESTNET:
263252

scripts/deploy.ts

Lines changed: 73 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +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-
// 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-
}
32+
const gasOverrides = chainConfig.gasParams;
4333

4434
// Handle BigBlocks setup automatically if supported
4535
if (isBigBlocksSupported(Number(chainId))) {
@@ -57,109 +47,107 @@ async function main() {
5747
// Estimate gas costs for all potential deployments
5848
let totalEstimatedCost = 0n;
5949

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;
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
6752

68-
if (useConfiguredGasLimit && !isMegaETH) {
69-
console.log(
70-
`⚠️ Using configured gas limit (${gasOverrides.gasLimit}) instead of estimation for this chain`
71-
);
72-
} else if (isMegaETH) {
73-
console.log(
74-
'ℹ️ MegaETH: skipping gas estimation, will use auto-estimation during deployment'
75-
);
53+
switch (useConfiguredGasLimit) {
54+
case true:
55+
console.log(
56+
`⚠️ Using configured gas limit (${gasOverrides.gasLimit}) instead of estimation for this chain`
57+
);
58+
break;
59+
default:
60+
break;
7661
}
7762

7863
// Only estimate if we need to deploy (not already deployed)
7964
if (
8065
!output.walletImplementation ||
8166
!(await isContractDeployed(output.walletImplementation))
8267
) {
83-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
84-
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);
88-
} else {
89-
const WalletSimple = await ethers.getContractFactory(
90-
chainConfig.walletImplementationContractName
91-
);
92-
const walletGas = await deployer.estimateGas({
93-
...(await WalletSimple.getDeployTransaction(...[], gasOverrides)),
94-
from: deployerAddress
95-
});
96-
totalEstimatedCost += walletGas;
68+
switch (useConfiguredGasLimit) {
69+
case true:
70+
totalEstimatedCost += BigInt(3_000_000);
71+
break;
72+
default:
73+
const WalletSimple = await ethers.getContractFactory(
74+
chainConfig.walletImplementationContractName
75+
);
76+
const walletGas = await deployer.estimateGas({
77+
...(await WalletSimple.getDeployTransaction(...[], gasOverrides)),
78+
from: deployerAddress
79+
});
80+
totalEstimatedCost += walletGas;
81+
break;
9782
}
9883
}
9984

10085
if (
10186
!output.walletFactory ||
10287
!(await isContractDeployed(output.walletFactory))
10388
) {
104-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
105-
totalEstimatedCost += BigInt(gasOverrides.gasLimit);
106-
} else if (isMegaETH) {
107-
totalEstimatedCost += BigInt(3_000_000);
108-
} else {
109-
const WalletFactory = await ethers.getContractFactory(
110-
chainConfig.walletFactoryContractName
111-
);
112-
const factoryGas = await deployer.estimateGas({
113-
...(await WalletFactory.getDeployTransaction(
114-
deployerAddress,
115-
gasOverrides
116-
)), // Use deployer address as placeholder
117-
from: deployerAddress
118-
});
119-
totalEstimatedCost += factoryGas;
89+
switch (useConfiguredGasLimit) {
90+
case true:
91+
totalEstimatedCost += BigInt(3_000_000);
92+
break;
93+
default:
94+
const WalletFactory = await ethers.getContractFactory(
95+
chainConfig.walletFactoryContractName
96+
);
97+
const factoryGas = await deployer.estimateGas({
98+
...(await WalletFactory.getDeployTransaction(
99+
deployerAddress,
100+
gasOverrides
101+
)), // Use deployer address as placeholder
102+
from: deployerAddress
103+
});
104+
totalEstimatedCost += factoryGas;
105+
break;
120106
}
121107
}
122108

123109
if (
124110
!output.forwarderImplementation ||
125111
!(await isContractDeployed(output.forwarderImplementation))
126112
) {
127-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
128-
totalEstimatedCost += BigInt(gasOverrides.gasLimit);
129-
} else if (isMegaETH) {
130-
totalEstimatedCost += BigInt(3_000_000);
131-
} else {
132-
const ForwarderV4 = await ethers.getContractFactory(
133-
chainConfig.forwarderContractName
134-
);
135-
const forwarderGas = await deployer.estimateGas({
136-
...(await ForwarderV4.getDeployTransaction(gasOverrides)),
137-
from: deployerAddress
138-
});
139-
totalEstimatedCost += forwarderGas;
113+
switch (useConfiguredGasLimit) {
114+
case true:
115+
totalEstimatedCost += BigInt(3_000_000);
116+
break;
117+
default:
118+
const ForwarderV4 = await ethers.getContractFactory(
119+
chainConfig.forwarderContractName
120+
);
121+
const forwarderGas = await deployer.estimateGas({
122+
...(await ForwarderV4.getDeployTransaction(gasOverrides)),
123+
from: deployerAddress
124+
});
125+
totalEstimatedCost += forwarderGas;
126+
break;
140127
}
141128
}
142129

143130
if (
144131
!output.forwarderFactory ||
145132
!(await isContractDeployed(output.forwarderFactory))
146133
) {
147-
if (useConfiguredGasLimit && gasOverrides.gasLimit) {
148-
totalEstimatedCost += BigInt(gasOverrides.gasLimit);
149-
} else if (isMegaETH) {
150-
totalEstimatedCost += BigInt(3_000_000);
151-
} else {
152-
const ForwarderFactory = await ethers.getContractFactory(
153-
chainConfig.forwarderFactoryContractName
154-
);
155-
const forwarderFactoryGas = await deployer.estimateGas({
156-
...(await ForwarderFactory.getDeployTransaction(
157-
deployerAddress,
158-
gasOverrides
159-
)), // Use deployer address as placeholder
160-
from: deployerAddress
161-
});
162-
totalEstimatedCost += forwarderFactoryGas;
134+
switch (useConfiguredGasLimit) {
135+
case true:
136+
totalEstimatedCost += BigInt(3_000_000);
137+
break;
138+
default:
139+
const ForwarderFactory = await ethers.getContractFactory(
140+
chainConfig.forwarderFactoryContractName
141+
);
142+
const forwarderFactoryGas = await deployer.estimateGas({
143+
...(await ForwarderFactory.getDeployTransaction(
144+
deployerAddress,
145+
gasOverrides
146+
)), // Use deployer address as placeholder
147+
from: deployerAddress
148+
});
149+
totalEstimatedCost += forwarderFactoryGas;
150+
break;
163151
}
164152
}
165153

0 commit comments

Comments
 (0)