Skip to content

Commit dfcc929

Browse files
committed
feat(megaeth): add MegaETH mainnet and testnet support
- Add MegaETH mainnet (Chain ID: 4326) network configuration - Fix MegaETH testnet chain ID from 6342 to 6343 - Update testnet explorer to use Etherscan v2 API - Add EIP-1559 gas configuration for MegaETH - Add MegaETH-specific gas estimation handling in deploy script Ticket: WIN-8361
1 parent 646f350 commit dfcc929

4 files changed

Lines changed: 50 additions & 11 deletions

File tree

config/chainIds.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const CHAIN_IDS = {
8686
KAVAEVM_TESTNET: 2221,
8787
PLUME_TESTNET: 98867,
8888
FLOW_TESTNET: 545,
89-
MEGAETH_TESTNET: 6342,
89+
MEGAETH_TESTNET: 6343,
9090
HBAREVM_TESTNET: 296,
9191
FLUENTETH_TESTNET: 20994,
9292
MANTLE_TESTNET: 5003,

hardhat.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,8 +1528,8 @@ const config: HardhatUserConfig = {
15281528
network: 'megaethTestnet',
15291529
chainId: CHAIN_IDS.MEGAETH_TESTNET,
15301530
urls: {
1531-
apiURL: 'https://carrot.megaeth.com/mafia/api',
1532-
browserURL: 'https://www.megaexplorer.xyz/'
1531+
apiURL: `${ETHERSCAN_V2_URL}${CHAIN_IDS.MEGAETH_TESTNET}`,
1532+
browserURL: 'https://testnet-mega.etherscan.io/'
15331533
}
15341534
},
15351535
{

scripts/chainConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ export async function getChainConfig(chainId: number): Promise<ChainConfig> {
246246
break;
247247

248248
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;
249260

250261
case CHAIN_IDS.HBAREVM:
251262
case CHAIN_IDS.HBAREVM_TESTNET:

scripts/deploy.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)