diff --git a/shared/constants/network.js b/shared/constants/network.js index 01891d57c..0101ab723 100644 --- a/shared/constants/network.js +++ b/shared/constants/network.js @@ -19,6 +19,8 @@ export const GOERLI_CHAIN_ID = '0x5'; export const KOVAN_CHAIN_ID = '0x2a'; export const LOCALHOST_CHAIN_ID = '0x539'; 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. @@ -120,3 +122,8 @@ export const NATIVE_CURRENCY_TOKEN_IMAGE_MAP = { }; export const INFURA_BLOCKED_KEY = 'countryBlocked'; + +export const CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP = { + [OPTIMISM_CHAIN_ID]: 1, + [OPTIMISM_TESTNET_CHAIN_ID]: 1, +}; diff --git a/ui/ducks/send/send.js b/ui/ducks/send/send.js index c8e926296..037f56cdf 100644 --- a/ui/ducks/send/send.js +++ b/ui/ducks/send/send.js @@ -80,6 +80,7 @@ import { isBurnAddress, isValidHexAddress, } from '../../../shared/modules/hexstring-utils'; +import { CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP } from '../../../shared/constants/network'; // typedefs /** @@ -176,6 +177,7 @@ async function estimateGasLimitForSend({ to, data, isNonStandardEthChain, + chainId, ...options }) { let isSimpleSendOnNonStandardNetwork = false; @@ -262,7 +264,12 @@ async function estimateGasLimitForSend({ // // Gas estimation of simple sends should, however, be deterministic. As such // 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 { // call into the background process that will simulate transaction @@ -328,6 +335,7 @@ export const computeEstimatedGasLimit = createAsyncThunk( const state = thunkApi.getState(); const { send, metamask } = state; const isNonStandardEthChain = getIsNonStandardEthChain(state); + const chainId = getCurrentChainId(state); if (send.stage !== SEND_STAGES.EDIT) { const gasLimit = await estimateGasLimitForSend({ gasPrice: send.gas.gasPrice, @@ -338,6 +346,7 @@ export const computeEstimatedGasLimit = createAsyncThunk( value: send.amount.value, data: send.draftTransaction.userInputHexData, isNonStandardEthChain, + chainId, }); await thunkApi.dispatch(setCustomGasLimit(gasLimit)); return { @@ -363,6 +372,7 @@ export const initializeSendState = createAsyncThunk( async (_, thunkApi) => { const state = thunkApi.getState(); const isNonStandardEthChain = getIsNonStandardEthChain(state); + const chainId = getCurrentChainId(state); const { send: { asset, stage, recipient, amount, draftTransaction }, metamask, @@ -410,6 +420,7 @@ export const initializeSendState = createAsyncThunk( value: amount.value, data: draftTransaction.userInputHexData, isNonStandardEthChain, + chainId, }); gasLimit = estimatedGasLimit || gasLimit; }