Skip to content

Commit

Permalink
Merge pull request #4150 from JoinColony/fix/max-priority-fee-per-gas
Browse files Browse the repository at this point in the history
Account for Metamask not supporting the `eth_maxPriorityFeePerGas` call
  • Loading branch information
rdig authored Jan 23, 2025
2 parents eef756b + f74b8da commit 0f0e20e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/redux/sagas/transactions/estimateGasCost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export default function* estimateGasCost({
},
}),
);
}

// wait for transactions options to be updated
yield take(ActionTypes.TRANSACTION_UPDATED_IN_DB);
// wait for transactions options to be updated
yield take(ActionTypes.TRANSACTION_UPDATED_IN_DB);
}

yield put(transactionSend(id));
} catch (error) {
Expand Down
74 changes: 61 additions & 13 deletions src/redux/sagas/utils/getGasPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,35 @@ const fetchGasPrices = async (): Promise<GasPricesProps> => {
const cheaper = defaultGasPrices.network;
const { maxFeePerGas } = await userWallet.ethersProvider.getFeeData();

// Ethers v5.7 just returns 1.5 GWei for maxPriorityFeePerGas. We should get it ourselves
const maxPriorityFeePerGasResponse = await userWallet.ethersProvider.send(
'eth_maxPriorityFeePerGas',
[],
);
const maxPriorityFeePerGas = BigNumber.from(maxPriorityFeePerGasResponse);
// In cases where we cannot make the `eth_maxPriorityFeePerGas` call, we'll just default to zero
// This might, and most likely will happen with Metamask since, even if the RPC provider support EIP-1559,
// Metamask will block the call
// See this PR for more info: https://github.com/MetaMask/metamask-extension/pull/29818
//
// Defaulting to zero (0) here means that the user will not pay any "extra" atop of what the actual
// gas required for the transaction.
// This works fine for Arbitrum, Arbitrum Sepolia, Local Dev, basically everywhere where a miner doesn't
// have an incentive to include the transaction in a block via this "tip", or in the case of Arbitrum,
// a sequencer
// https://docs.arbitrum.io/learn-more/faq#do-i-need-to-pay-a-tip-or-priority-fee-for-my-arbitrum-transactions
//
// However this will definetly not work on Mainnet, Gnosis for example since there the miners
// are actively looking for this
//
// If we ever have to re-deploy to mainnet, this will need to be revisited and somehow fixed

let maxPriorityFeePerGas = BigNumber.from(0);
try {
// Ethers v5.7 just returns 1.5 GWei for maxPriorityFeePerGas. We should get it ourselves
const maxPriorityFeePerGasResponse =
await userWallet.ethersProvider.send('eth_maxPriorityFeePerGas', []);

maxPriorityFeePerGas = BigNumber.from(maxPriorityFeePerGasResponse);
} catch (error) {
debugLogging(
`The "eth_maxPriorityFeePerGas" provider call failed: "${error.message}"`,
);
}

debugLogging('ARBITRUM GAS DEBUG', {
maxFeePerGas,
Expand Down Expand Up @@ -205,12 +228,37 @@ const fetchGasPrices = async (): Promise<GasPricesProps> => {
const cheaper = defaultGasPrices.network;
const { maxFeePerGas } = await userWallet.ethersProvider.getFeeData();

// Ethers v5.7 just returns 1.5 GWei for maxPriorityFeePerGas. We should get it ourselves
const maxPriorityFeePerGasResponse = await userWallet.ethersProvider.send(
'eth_maxPriorityFeePerGas',
[],
);
const maxPriorityFeePerGas = BigNumber.from(maxPriorityFeePerGasResponse);
// In cases where we cannot make the `eth_maxPriorityFeePerGas` call, we'll just default to zero
// This might, and most likely will happen with Metamask since, even if the RPC provider support EIP-1559,
// Metamask will block the call
// See this PR for more info: https://github.com/MetaMask/metamask-extension/pull/29818
//
// Defaulting to zero (0) here means that the user will not pay any "extra" atop of what the actual
// gas required for the transaction.
// This works fine for Arbitrum, Arbitrum Sepolia, Local Dev, basically everywhere where a miner doesn't
// have an incentive to include the transaction in a block via this "tip", or in the case of Arbitrum,
// a sequencer
// https://docs.arbitrum.io/learn-more/faq#do-i-need-to-pay-a-tip-or-priority-fee-for-my-arbitrum-transactions
//
// However this will definetly not work on Mainnet, Gnosis for example since there the miners
// are actively looking for this
//
// If we ever have to re-deploy to mainnet, this will need to be revisited and somehow fixed

let maxPriorityFeePerGas = BigNumber.from(0);
try {
// Ethers v5.7 just returns 1.5 GWei for maxPriorityFeePerGas. We should get it ourselves
const maxPriorityFeePerGasResponse = await userWallet.ethersProvider.send(
'eth_maxPriorityFeePerGas',
[],
);

maxPriorityFeePerGas = BigNumber.from(maxPriorityFeePerGasResponse);
} catch (error) {
debugLogging(
`The "eth_maxPriorityFeePerGas" provider call failed: "${error.message}"`,
);
}

// This wil essentially make the local dev gas price estimation act more like production
const defaultNetworkGasPrices = {
Expand All @@ -234,7 +282,7 @@ const fetchGasPrices = async (): Promise<GasPricesProps> => {

return defaultNetworkGasPrices;
} catch (caughtError) {
console.info(
debugLogging(
`Could not get ${DEFAULT_NETWORK} network gas prices: ${caughtError.message}`,
);
// Default values
Expand Down

0 comments on commit 0f0e20e

Please sign in to comment.