@@ -11,6 +11,8 @@ const feeToInt = f => (f < 1 ? 1 : Math.round(f));
1111
1212const feeToWei = fee => Web3.utils.toHex(Web3.utils.toWei(String(fee), 'gwei'));
1313
14+const weiToGwei = wei => Math.ceil(wei / 1_000_000_000);
15+
1416const calculateMaxFee = (baseFee, maxPriorityFee) =>
1517 feeToWei(Math.round(2 * baseFee + maxPriorityFee));
1618
@@ -43,68 +45,32 @@ export const defaultGasValues = value => ({
4345
4446const getGasForNetwork = async providerUrl => {
4547 try {
46− const [feeResponse, waitResponse] = await Promise.all([
47− fetch(
48− `${providerUrl}/api` +
49− '?module=gastracker' +
50− '&action=gasoracle' +
51− '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
52− {
53− method: 'GET',
54− cache: 'no-cache',
55− }
56− ),
57− fetch('https://ethereum-api.xyz/gas-prices', {
58− method: 'GET',
48+ const feeResponse = await fetch(
49+ providerUrl,
50+ {
51+ method: 'get',
5952 cache: 'no-cache',
60− }),
61− ]);
62−
63− const [feeJson, waitJson] = await Promise.all([
64− feeResponse.json(),
65− waitResponse.json(),
66− ]);
67−
68− const suggestedBaseFeePerGas = Number(feeJson.result.suggestBaseFee);
53+ }
54+ );
55+ const feeJson = await feeResponse.json();
6956
7057 // Calculations derived from:
7158 // https://www.blocknative.com/blog/eip-1559-fees
7259 return {
7360 fast: {
74− price: minGas(feeJson.result.FastGasPrice),
75− wait: formatWait(waitJson.result.fast.time),
76− maxFeePerGas: calculateMaxFee(
77− suggestedBaseFeePerGas,
78− feeJson.result.FastGasPrice - suggestedBaseFeePerGas
79− ),
80− maxPriorityFeePerGas: feeToInt(
81− feeJson.result.FastGasPrice - suggestedBaseFeePerGas
82− ),
83− suggestedBaseFeePerGas,
61+ price: minGas(weiToGwei(feeJson.data.rapid)),
62+ wait: formatWait(15),
63+ maxFeePerGas: weiToGwei(feeJson.data.rapid)
8464 },
8565 average: {
86− price: minGas(feeJson.result.ProposeGasPrice),
87− wait: formatWait(waitJson.result.average.time),
88− maxFeePerGas: calculateMaxFee(
89− suggestedBaseFeePerGas,
90− feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas
91− ),
92− maxPriorityFeePerGas: feeToInt(
93− feeJson.result.ProposeGasPrice - suggestedBaseFeePerGas
94− ),
95− suggestedBaseFeePerGas,
66+ price: minGas(weiToGwei(feeJson.data.fast)),
67+ wait: formatWait(60),
68+ maxFeePerGas: weiToGwei(feeJson.data.fast)
9669 },
9770 low: {
98− price: minGas(feeJson.result.SafeGasPrice),
99− wait: formatWait(waitJson.result.slow.time),
100− maxFeePerGas: calculateMaxFee(
101− suggestedBaseFeePerGas,
102− feeJson.result.SafeGasPrice - suggestedBaseFeePerGas
103− ),
104− maxPriorityFeePerGas: feeToInt(
105− feeJson.result.SafeGasPrice - suggestedBaseFeePerGas
106− ),
107− suggestedBaseFeePerGas,
71+ price: minGas(weiToGwei(feeJson.data.standard)),
72+ wait: formatWait(180),
73+ maxFeePerGas: weiToGwei(feeJson.data.standard)
10874 },
10975 };
11076 } catch (e) {
@@ -116,11 +82,11 @@ const getGasForNetwork = async providerUrl => {
11682export default async function getSuggestedGasPrice(networkType) {
11783 switch (networkType) {
11884 case NETWORK_TYPES.GOERLI:
119− return getGasForNetwork('https://api-goerli.etherscan.io');
85+ return getGasForNetwork('https://beaconcha.in/api/v1/execution/gasnow');
12086 case NETWORK_TYPES.OFFLINE:
12187 return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
12288 case NETWORK_TYPES.LOCAL:
12389 default:
124− return getGasForNetwork('https://api.etherscan.io/');
90+ return getGasForNetwork('https://beaconcha.in/api/v1/execution/gasnow');
12591 }
12692}