Skip to content

Commit 2b03c62

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 2b03c62

2 files changed

Lines changed: 69 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: 67 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,101 @@ 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 (${3_000_000}) 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(...[])),
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(deployerAddress)), // Use deployer address as placeholder
99+
from: deployerAddress
100+
});
101+
totalEstimatedCost += factoryGas;
102+
break;
120103
}
121104
}
122105

123106
if (
124107
!output.forwarderImplementation ||
125108
!(await isContractDeployed(output.forwarderImplementation))
126109
) {
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;
110+
switch (useConfiguredGasLimit) {
111+
case true:
112+
totalEstimatedCost += BigInt(3_000_000);
113+
break;
114+
default:
115+
const ForwarderV4 = await ethers.getContractFactory(
116+
chainConfig.forwarderContractName
117+
);
118+
const forwarderGas = await deployer.estimateGas({
119+
...(await ForwarderV4.getDeployTransaction()),
120+
from: deployerAddress
121+
});
122+
totalEstimatedCost += forwarderGas;
123+
break;
140124
}
141125
}
142126

143127
if (
144128
!output.forwarderFactory ||
145129
!(await isContractDeployed(output.forwarderFactory))
146130
) {
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;
131+
switch (useConfiguredGasLimit) {
132+
case true:
133+
totalEstimatedCost += BigInt(3_000_000);
134+
break;
135+
default:
136+
const ForwarderFactory = await ethers.getContractFactory(
137+
chainConfig.forwarderFactoryContractName
138+
);
139+
const forwarderFactoryGas = await deployer.estimateGas({
140+
...(await ForwarderFactory.getDeployTransaction(deployerAddress)), // Use deployer address as placeholder
141+
from: deployerAddress
142+
});
143+
totalEstimatedCost += forwarderFactoryGas;
144+
break;
163145
}
164146
}
165147

0 commit comments

Comments
 (0)