Skip to content

Commit

Permalink
Merge pull request #3630 from JoinColony/maintenance/ensure-2gwei-gas…
Browse files Browse the repository at this point in the history
…-price

Ensure Gas Prices is at least 2 GWEI when on Gnosis Chain
  • Loading branch information
rdig authored Jul 15, 2022
2 parents 5a71156 + 294bcc7 commit d9543e2
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/modules/core/sagas/utils/getGasPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,33 @@ const fetchGasPrices = async (
// API prices are in Gwei, so they need to be normalised
const oneGwei = bigNumberify(10 ** 9);

let { average } = data;
let { fast } = data;
/*
* @NOTE IF we're on Gnosis Chain, ensure that transactions alway pay at
* least 2gwei for gas
*
* This to counteract some unpleasantness coming from the Blockscout gas oracle
*
* Locally this is not a problem (and we don't even use the oracle to estimate)
*/
if (
DEFAULT_NETWORK === Network.Xdai ||
DEFAULT_NETWORK === Network.XdaiFork
) {
average = data.average > 2 ? data.average : 2;
fast = data.fast > 2 ? data.fast : 2;
}
/*
* @NOTE Split the values into integer and remainder
* (1.22 becomes 1 and 22)
*
* The integer part gets multiplied by 1 gwei, while the remainder
* gets padded with 9 zeros. Everything will be added together.
*/
const [averageInteger, averageRemainder = 0] = String(data.average).split(
'.',
);
const [averageInteger, averageRemainder = 0] = String(average).split('.');
const [slowInteger, slowRemainder = 0] = String(data.slow).split('.');
const [fastInteger, fastRemainder = 0] = String(data.fast).split('.');
const [fastInteger, fastRemainder = 0] = String(fast).split('.');

return {
...defaultGasPrices,
Expand All @@ -127,9 +142,11 @@ const fetchGasPrices = async (

return defaultGasPrices;
} catch (caughtError) {
log.warn(
`Could not get ${DEFAULT_NETWORK} network gas prices: ${caughtError.message}`,
);
if (process.env.NODE_ENV !== 'development') {
log.warn(
`Could not get ${DEFAULT_NETWORK} network gas prices: ${caughtError.message}`,
);
}
// Default values
return {
...defaultGasPrices,
Expand Down

0 comments on commit d9543e2

Please sign in to comment.