Skip to content

Commit ccea4fa

Browse files
feat: extend Mantle layer 1 gas fee flow to support Mantle Sepolia testnet
Add Mantle Sepolia (chain ID 0x138b) to MantleLayer1GasFeeFlow so the tokenRatio conversion applies to testnet transactions as well.
1 parent 74b3af9 commit ccea4fa

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

packages/transaction-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Add Mantle layer 1 gas fee flow with tokenRatio conversion for accurate MNT-denominated gas estimates ([#8376](https://github.com/MetaMask/core/pull/8376))
13+
- Extend Mantle layer 1 gas fee flow to support Mantle Sepolia testnet (chain ID `0x138b`)
1314

1415
### Changed
1516

packages/transaction-controller/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const CHAIN_IDS = {
3434
MEGAETH_TESTNET: '0x18c6',
3535
SEI: '0x531',
3636
MANTLE: '0x1388',
37+
MANTLE_SEPOLIA: '0x138b',
3738
} as const;
3839

3940
/** Extract of the Wrapped ERC-20 ABI required for simulation. */

packages/transaction-controller/src/gas-flows/MantleLayer1GasFeeFlow.test.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ const TRANSACTION_META_MOCK: TransactionMeta = {
3333
txParams: TRANSACTION_PARAMS_MOCK,
3434
};
3535

36+
const TRANSACTION_META_TESTNET_MOCK: TransactionMeta = {
37+
id: '2',
38+
chainId: CHAIN_IDS.MANTLE_SEPOLIA,
39+
networkClientId: 'testNetworkClientId',
40+
status: TransactionStatus.unapproved,
41+
time: 0,
42+
txParams: TRANSACTION_PARAMS_MOCK,
43+
};
44+
3645
const SERIALIZED_TRANSACTION_MOCK = '0x1234';
3746
// L1 fee in ETH (returned by oracle)
3847
const L1_FEE_MOCK = '0x0de0b6b3a7640000'; // 1e18 (1 ETH in wei)
@@ -104,6 +113,17 @@ describe('MantleLayer1GasFeeFlow', () => {
104113
).toBe(true);
105114
});
106115

116+
it('returns true if chain ID is Mantle Sepolia', async () => {
117+
const flow = new MantleLayer1GasFeeFlow();
118+
119+
expect(
120+
await flow.matchesTransaction({
121+
transactionMeta: TRANSACTION_META_TESTNET_MOCK,
122+
messenger,
123+
}),
124+
).toBe(true);
125+
});
126+
107127
it('returns false if chain ID is not Mantle', async () => {
108128
const flow = new MantleLayer1GasFeeFlow();
109129

@@ -243,7 +263,7 @@ describe('MantleLayer1GasFeeFlow', () => {
243263
);
244264
});
245265

246-
it('uses default OP Stack oracle address', () => {
266+
it('uses default OP Stack oracle address for mainnet', () => {
247267
class TestableMantleLayer1GasFeeFlow extends MantleLayer1GasFeeFlow {
248268
exposeOracleAddress(chainId: Hex): Hex {
249269
return super.getOracleAddressForChain(chainId);
@@ -255,5 +275,55 @@ describe('MantleLayer1GasFeeFlow', () => {
255275
'0x420000000000000000000000000000000000000F',
256276
);
257277
});
278+
279+
it('uses default OP Stack oracle address for Mantle Sepolia', () => {
280+
class TestableMantleLayer1GasFeeFlow extends MantleLayer1GasFeeFlow {
281+
exposeOracleAddress(chainId: Hex): Hex {
282+
return super.getOracleAddressForChain(chainId);
283+
}
284+
}
285+
286+
const flow = new TestableMantleLayer1GasFeeFlow();
287+
expect(flow.exposeOracleAddress(CHAIN_IDS.MANTLE_SEPOLIA)).toBe(
288+
'0x420000000000000000000000000000000000000F',
289+
);
290+
});
291+
292+
it('computes correct fee for Mantle Sepolia transactions', async () => {
293+
const gasUsed = '0x5208';
294+
request = {
295+
...request,
296+
transactionMeta: {
297+
...TRANSACTION_META_TESTNET_MOCK,
298+
gasUsed,
299+
},
300+
};
301+
302+
contractGetOperatorFeeMock.mockResolvedValueOnce(
303+
bnFromHex(OPERATOR_FEE_MOCK),
304+
);
305+
306+
jest
307+
.spyOn(TransactionFactory, 'fromTxData')
308+
.mockReturnValueOnce(
309+
createMockTypedTransaction(
310+
Buffer.from(SERIALIZED_TRANSACTION_MOCK, 'hex'),
311+
),
312+
);
313+
314+
const flow = new MantleLayer1GasFeeFlow();
315+
const response = await flow.getLayer1Fee(request);
316+
317+
const expectedL1FeeInMnt = bnFromHex(L1_FEE_MOCK).mul(TOKEN_RATIO_MOCK);
318+
const expectedTotal = expectedL1FeeInMnt.add(
319+
bnFromHex(OPERATOR_FEE_MOCK),
320+
);
321+
322+
expect(contractTokenRatioMock).toHaveBeenCalledTimes(1);
323+
expect(contractGetOperatorFeeMock).toHaveBeenCalledTimes(1);
324+
expect(response).toStrictEqual({
325+
layer1Fee: add0x(padHexToEvenLength(expectedTotal.toString(16))),
326+
});
327+
});
258328
});
259329
});

packages/transaction-controller/src/gas-flows/MantleLayer1GasFeeFlow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { padHexToEvenLength, toBN } from '../utils/utils';
1919

2020
const log = createModuleLogger(projectLogger, 'mantle-layer1-gas-fee-flow');
2121

22-
const MANTLE_CHAIN_IDS: Hex[] = [CHAIN_IDS.MANTLE];
22+
const MANTLE_CHAIN_IDS: Hex[] = [CHAIN_IDS.MANTLE, CHAIN_IDS.MANTLE_SEPOLIA];
2323

2424
const ZERO = new BN(0);
2525

0 commit comments

Comments
 (0)