mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
9fa15dda6f
* Support for Layer 2 networks with transaction fees on both layers * Use variable name in transaction-breakdown * Add comment on code source to ui/helpers/utils/optimism/fetchEstimatedL1Fee.js * Fix unit tests * Ensure values passed to are defined * Fix activity log
25 lines
997 B
JavaScript
25 lines
997 B
JavaScript
import * as ethers from 'ethers';
|
|
import * as optimismContracts from '@eth-optimism/contracts';
|
|
import buildUnserializedTransaction from './buildUnserializedTransaction';
|
|
|
|
// The code in this file is largely drawn from https://community.optimism.io/docs/developers/l2/new-fees.html#for-frontend-and-wallet-developers
|
|
|
|
function buildOVMGasPriceOracleContract(eth) {
|
|
const OVMGasPriceOracle = optimismContracts
|
|
.getContractFactory('OVM_GasPriceOracle')
|
|
.attach(optimismContracts.predeploys.OVM_GasPriceOracle);
|
|
const abi = JSON.parse(
|
|
OVMGasPriceOracle.interface.format(ethers.utils.FormatTypes.json),
|
|
);
|
|
return eth.contract(abi).at(OVMGasPriceOracle.address);
|
|
}
|
|
|
|
export default async function fetchEstimatedL1Fee(eth, txMeta) {
|
|
const contract = buildOVMGasPriceOracleContract(eth);
|
|
const serializedTransaction = buildUnserializedTransaction(
|
|
txMeta,
|
|
).serialize();
|
|
const result = await contract.getL1Fee(serializedTransaction);
|
|
return result?.[0]?.toString(16);
|
|
}
|