Skip to content

Commit

Permalink
fix: Pass correct optimism chain id to gas estimation (#18478)
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDDDanica authored Apr 6, 2023
1 parent 18ff108 commit f92e463
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export default function MultilayerFeeMessage({
useEffect(() => {
const getEstimatedL1Fee = async () => {
try {
const result = await fetchEstimatedL1Fee(transaction);
const result = await fetchEstimatedL1Fee(
transaction.chainId,
transaction.txParams,
);
setLayer1Total(result);
} catch (e) {
captureException(e);
Expand Down Expand Up @@ -75,15 +78,15 @@ export default function MultilayerFeeMessage({
return (
<div className="multi-layer-fee-message">
<TransactionDetailItem
key="total-item"
key="total-item-gas-fee"
detailTitle={t('gasFee')}
detailTotal={layer1Total}
detailText={feeTotalInFiat}
noBold={plainStyle}
flexWidthValues={plainStyle}
/>
<TransactionDetailItem
key="total-item"
key="total-item-total"
detailTitle={t('total')}
detailTotal={totalInEth}
detailText={totalInFiat}
Expand Down
2 changes: 1 addition & 1 deletion ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export const computeEstimatedGasLimit = createAsyncThunk(

let gasTotalForLayer1;
if (isMultiLayerFeeNetwork) {
gasTotalForLayer1 = await fetchEstimatedL1Fee({
gasTotalForLayer1 = await fetchEstimatedL1Fee(chainId, {
txParams: {
gasPrice: draftTransaction.gas.gasPrice,
gas: draftTransaction.gas.gasLimit,
Expand Down
13 changes: 9 additions & 4 deletions ui/helpers/utils/optimism/fetchEstimatedL1Fee.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ const OPTIMISM_GAS_PRICE_ORACLE_ABI = [
const OPTIMISM_GAS_PRICE_ORACLE_ADDRESS =
'0x420000000000000000000000000000000000000F';

export default async function fetchEstimatedL1Fee(txMeta, ethersProvider) {
export default async function fetchEstimatedL1Fee(
chainId,
txMeta,
ethersProvider,
) {
const networkId = Number(chainId);
const provider = global.ethereumProvider
? new Web3Provider(global.ethereumProvider, 10)
? new Web3Provider(global.ethereumProvider, networkId)
: ethersProvider;

if (process.env.IN_TEST) {
provider.detectNetwork = async () => ({
name: 'optimism',
chainId: 10,
chainId: networkId,
});
}
const contract = new Contract(
Expand All @@ -36,7 +42,6 @@ export default async function fetchEstimatedL1Fee(txMeta, ethersProvider) {
);
const serializedTransaction =
buildUnserializedTransaction(txMeta).serialize();

const result = await contract.getL1Fee(serializedTransaction);
return result?.toHexString();
}
3 changes: 1 addition & 2 deletions ui/helpers/utils/optimism/fetchEstimatedL1Fee.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('fetchEstimatedL1Fee', () => {
result: `0x0000000000000000000000000000000000000000000000000000${expectedGasFeeResult}`,
});

const gasFee = await fetchEstimatedL1Fee({
const gasFee = await fetchEstimatedL1Fee('10', {
txParams: {
gasPrice: '0xf4240',
gas: '0xcf08',
Expand All @@ -43,7 +43,6 @@ describe('fetchEstimatedL1Fee', () => {
data: null,
type: '0x0',
},
chainId: '10',
});
expect(gasFee).toStrictEqual(`0x${expectedGasFeeResult}`);
});
Expand Down
3 changes: 1 addition & 2 deletions ui/pages/swaps/view-quote/view-quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,13 +896,12 @@ export default function ViewQuote() {
try {
let l1ApprovalFeeTotal = '0x0';
if (approveTxParams) {
l1ApprovalFeeTotal = await fetchEstimatedL1Fee({
l1ApprovalFeeTotal = await fetchEstimatedL1Fee(chainId, {
txParams: {
...approveTxParams,
gasPrice: addHexPrefix(approveTxParams.gasPrice),
value: '0x0', // For approval txs we need to use "0x0" here.
},
chainId,
});
setMultiLayerL1ApprovalFeeTotal(l1ApprovalFeeTotal);
}
Expand Down

0 comments on commit f92e463

Please sign in to comment.