1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Add list of custom networks with special gas limit buffers (#11435)

This commit is contained in:
Dan J Miller 2021-07-01 19:18:30 -02:30 committed by GitHub
parent 581567d541
commit bda4d0cbca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -19,6 +19,8 @@ export const GOERLI_CHAIN_ID = '0x5';
export const KOVAN_CHAIN_ID = '0x2a'; export const KOVAN_CHAIN_ID = '0x2a';
export const LOCALHOST_CHAIN_ID = '0x539'; export const LOCALHOST_CHAIN_ID = '0x539';
export const BSC_CHAIN_ID = '0x38'; export const BSC_CHAIN_ID = '0x38';
export const OPTIMISM_CHAIN_ID = '0xa';
export const OPTIMISM_TESTNET_CHAIN_ID = '0x45';
/** /**
* The largest possible chain ID we can handle. * The largest possible chain ID we can handle.
@ -141,3 +143,8 @@ export const HARDFORKS = {
BERLIN: 'berlin', BERLIN: 'berlin',
LONDON: 'london', LONDON: 'london',
}; };
export const CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP = {
[OPTIMISM_CHAIN_ID]: 1,
[OPTIMISM_TESTNET_CHAIN_ID]: 1,
};

View File

@ -80,6 +80,7 @@ import {
isBurnAddress, isBurnAddress,
isValidHexAddress, isValidHexAddress,
} from '../../../shared/modules/hexstring-utils'; } from '../../../shared/modules/hexstring-utils';
import { CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP } from '../../../shared/constants/network';
// typedefs // typedefs
/** /**
@ -176,6 +177,7 @@ async function estimateGasLimitForSend({
to, to,
data, data,
isNonStandardEthChain, isNonStandardEthChain,
chainId,
...options ...options
}) { }) {
let isSimpleSendOnNonStandardNetwork = false; let isSimpleSendOnNonStandardNetwork = false;
@ -262,7 +264,12 @@ async function estimateGasLimitForSend({
// //
// Gas estimation of simple sends should, however, be deterministic. As such // Gas estimation of simple sends should, however, be deterministic. As such
// no buffer is needed in those cases. // no buffer is needed in those cases.
const bufferMultiplier = isSimpleSendOnNonStandardNetwork ? 1 : 1.5; let bufferMultiplier = 1.5;
if (isSimpleSendOnNonStandardNetwork) {
bufferMultiplier = 1;
} else if (CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP[chainId]) {
bufferMultiplier = CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP[chainId];
}
try { try {
// call into the background process that will simulate transaction // call into the background process that will simulate transaction
@ -328,6 +335,7 @@ export const computeEstimatedGasLimit = createAsyncThunk(
const state = thunkApi.getState(); const state = thunkApi.getState();
const { send, metamask } = state; const { send, metamask } = state;
const isNonStandardEthChain = getIsNonStandardEthChain(state); const isNonStandardEthChain = getIsNonStandardEthChain(state);
const chainId = getCurrentChainId(state);
if (send.stage !== SEND_STAGES.EDIT) { if (send.stage !== SEND_STAGES.EDIT) {
const gasLimit = await estimateGasLimitForSend({ const gasLimit = await estimateGasLimitForSend({
gasPrice: send.gas.gasPrice, gasPrice: send.gas.gasPrice,
@ -338,6 +346,7 @@ export const computeEstimatedGasLimit = createAsyncThunk(
value: send.amount.value, value: send.amount.value,
data: send.draftTransaction.userInputHexData, data: send.draftTransaction.userInputHexData,
isNonStandardEthChain, isNonStandardEthChain,
chainId,
}); });
await thunkApi.dispatch(setCustomGasLimit(gasLimit)); await thunkApi.dispatch(setCustomGasLimit(gasLimit));
return { return {
@ -363,6 +372,7 @@ export const initializeSendState = createAsyncThunk(
async (_, thunkApi) => { async (_, thunkApi) => {
const state = thunkApi.getState(); const state = thunkApi.getState();
const isNonStandardEthChain = getIsNonStandardEthChain(state); const isNonStandardEthChain = getIsNonStandardEthChain(state);
const chainId = getCurrentChainId(state);
const { const {
send: { asset, stage, recipient, amount, draftTransaction }, send: { asset, stage, recipient, amount, draftTransaction },
metamask, metamask,
@ -410,6 +420,7 @@ export const initializeSendState = createAsyncThunk(
value: amount.value, value: amount.value,
data: draftTransaction.userInputHexData, data: draftTransaction.userInputHexData,
isNonStandardEthChain, isNonStandardEthChain,
chainId,
}); });
gasLimit = estimatedGasLimit || gasLimit; gasLimit = estimatedGasLimit || gasLimit;
} }