@@ -1,6 +1,5 @@
1import { NETWORK_TYPES } from './network';
1import { NETWORK_TYPES } from './network';
2import { DEFAULT_GAS_PRICE_GWEI, MAX_GAS_PRICE_GWEI } from './constants';
2import { DEFAULT_GAS_PRICE_GWEI, MAX_GAS_PRICE_GWEI } from './constants';
3−import { formatWait } from 'components/L2/Dropdowns/FeeDropdown';
4import Web3 from 'web3';
3import Web3 from 'web3';
6// ethgasstation returns values in floating point, one order of magitude
5// ethgasstation returns values in floating point, one order of magitude
@@ -14,6 +13,9 @@ const feeToWei = (fee) => Web3.utils.toHex(Web3.utils.toWei(String(fee), 'gwei'
15const calculateMaxFee = (baseFee, maxPriorityFee) => feeToWei(Math.round((2 * baseFee) + maxPriorityFee))
14const calculateMaxFee = (baseFee, maxPriorityFee) => feeToWei(Math.round((2 * baseFee) + maxPriorityFee))
16+// Convert seconds to minutes prettily
17+const formatWait = (wait) => Math.round((wait * 100) / 60) / 100;
17export const defaultGasValues = value => ({
19export const defaultGasValues = value => ({
19 price: value,
21 price: value,
@@ -40,7 +42,7 @@ export const defaultGasValues = value => ({
41const getGasForNetwork = async (providerUrl) => {
43const getGasForNetwork = async (providerUrl) => {
43− const [etherscanGas, ethgasstationGas] = await Promise.all([
45+ const [feeResponse, waitResponse] = await Promise.all([
45 `${providerUrl}/api` +
47 `${providerUrl}/api` +
46 '?module=gastracker' +
48 '?module=gastracker' +
@@ -52,7 +54,7 @@ const getGasForNetwork = async (providerUrl) => {
55− 'https://ethgasstation.info/json/ethgasAPI.json',
57+ 'https://ethereum-api.xyz/gas-prices',
57 method: 'GET',
59 method: 'GET',
58 cache: 'no-cache',
60 cache: 'no-cache',
@@ -60,35 +62,35 @@ const getGasForNetwork = async (providerUrl) => {
63− const [etherscanGasJson, ethgasstationGasJson] = await Promise.all([
65+ const [feeJson, waitJson] = await Promise.all([
64− etherscanGas.json(),
66+ feeResponse.json(),
65− ethgasstationGas.json()
67+ waitResponse.json()
68− const suggestedBaseFeePerGas = Number(etherscanGasJson.result.suggestBaseFee);
70+ const suggestedBaseFeePerGas = Number(feeJson.result.suggestBaseFee);
70 // Calculations derived from:
72 // Calculations derived from:
71 // https://www.blocknative.com/blog/eip-1559-fees
73 // https://www.blocknative.com/blog/eip-1559-fees
74− price: minGas(etherscanGasJson.result.FastGasPrice),
76+ price: minGas(feeJson.result.FastGasPrice),
75− wait: formatWait(ethgasstationGasJson.fastWait),
77+ wait: formatWait(waitJson.result.fast.time),
76− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas),
78+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.FastGasPrice - suggestedBaseFeePerGas),
77− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas)),
79+ maxPriorityFeePerGas: feeToInt((feeJson.result.FastGasPrice - suggestedBaseFeePerGas)),
78 suggestedBaseFeePerGas
80 suggestedBaseFeePerGas
80 average: {
82 average: {
81− price: minGas(etherscanGasJson.result.ProposeGasPrice),
83+ price: minGas(feeJson.result.ProposeGasPrice),
82− wait: formatWait(ethgasstationGasJson.avgWait),
84+ wait: formatWait(waitJson.result.average.time),
83− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
85+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
84− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
86+ maxPriorityFeePerGas: feeToInt((feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
85 suggestedBaseFeePerGas
87 suggestedBaseFeePerGas
88− price: minGas(etherscanGasJson.result.SafeGasPrice),
90+ price: minGas(feeJson.result.SafeGasPrice),
89− wait: formatWait(ethgasstationGasJson.safeLowWait),
91+ wait: formatWait(waitJson.result.slow.time),
90− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas),
92+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.SafeGasPrice - suggestedBaseFeePerGas),
91− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
93+ maxPriorityFeePerGas: feeToInt((feeJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
92 suggestedBaseFeePerGas
94 suggestedBaseFeePerGas