@@ -1,6 +1,5 @@
11import { NETWORK_TYPES } from './network';
22import { DEFAULT_GAS_PRICE_GWEI, MAX_GAS_PRICE_GWEI } from './constants';
3−import { formatWait } from 'components/L2/Dropdowns/FeeDropdown';
43import Web3 from 'web3';
54
65// 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'
1413
1514const calculateMaxFee = (baseFee, maxPriorityFee) => feeToWei(Math.round((2 * baseFee) + maxPriorityFee))
1615
16+// Convert seconds to minutes prettily
17+const formatWait = (wait) => Math.round((wait * 100) / 60) / 100;
18+
1719export const defaultGasValues = value => ({
1820 fast: {
1921 price: value,
@@ -40,7 +42,7 @@ export const defaultGasValues = value => ({
4042
4143const getGasForNetwork = async (providerUrl) => {
4244 try {
43− const [etherscanGas, ethgasstationGas] = await Promise.all([
45+ const [feeResponse, waitResponse] = await Promise.all([
4446 fetch(
4547 `${providerUrl}/api` +
4648 '?module=gastracker' +
@@ -52,7 +54,7 @@ const getGasForNetwork = async (providerUrl) => {
5254 }
5355 ),
5456 fetch(
55− 'https://ethgasstation.info/json/ethgasAPI.json',
57+ 'https://ethereum-api.xyz/gas-prices',
5658 {
5759 method: 'GET',
5860 cache: 'no-cache',
@@ -60,35 +62,35 @@ const getGasForNetwork = async (providerUrl) => {
6062 )
6163 ]);
6264
63− const [etherscanGasJson, ethgasstationGasJson] = await Promise.all([
64− etherscanGas.json(),
65− ethgasstationGas.json()
65+ const [feeJson, waitJson] = await Promise.all([
66+ feeResponse.json(),
67+ waitResponse.json()
6668 ])
6769
68− const suggestedBaseFeePerGas = Number(etherscanGasJson.result.suggestBaseFee);
70+ const suggestedBaseFeePerGas = Number(feeJson.result.suggestBaseFee);
6971
7072 // Calculations derived from:
7173 // https://www.blocknative.com/blog/eip-1559-fees
7274 return {
7375 fast: {
74− price: minGas(etherscanGasJson.result.FastGasPrice),
75− wait: formatWait(ethgasstationGasJson.fastWait),
76− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas),
77− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas)),
76+ price: minGas(feeJson.result.FastGasPrice),
77+ wait: formatWait(waitJson.result.fast.time),
78+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.FastGasPrice - suggestedBaseFeePerGas),
79+ maxPriorityFeePerGas: feeToInt((feeJson.result.FastGasPrice - suggestedBaseFeePerGas)),
7880 suggestedBaseFeePerGas
7981 },
8082 average: {
81− price: minGas(etherscanGasJson.result.ProposeGasPrice),
82− wait: formatWait(ethgasstationGasJson.avgWait),
83− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
84− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
83+ price: minGas(feeJson.result.ProposeGasPrice),
84+ wait: formatWait(waitJson.result.average.time),
85+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
86+ maxPriorityFeePerGas: feeToInt((feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
8587 suggestedBaseFeePerGas
8688 },
8789 low: {
88− price: minGas(etherscanGasJson.result.SafeGasPrice),
89− wait: formatWait(ethgasstationGasJson.safeLowWait),
90− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas),
91− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
90+ price: minGas(feeJson.result.SafeGasPrice),
91+ wait: formatWait(waitJson.result.slow.time),
92+ maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, feeJson.result.SafeGasPrice - suggestedBaseFeePerGas),
93+ maxPriorityFeePerGas: feeToInt((feeJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
9294 suggestedBaseFeePerGas
9395 },
9496 };