@@ -38,70 +38,74 @@ export const defaultGasValues = value => ({
41+const getGasForNetwork = async (providerUrl) => {
43+ const [etherscanGas, ethgasstationGas] = await Promise.all([
45+ `${providerUrl}/api` +
46+ '?module=gastracker' +
47+ '&action=gasoracle' +
48+ '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
55+ 'https://ethgasstation.info/json/ethgasAPI.json',
63+ const [etherscanGasJson, ethgasstationGasJson] = await Promise.all([
65+ ethgasstationGas.json()
68+ const suggestedBaseFeePerGas = Number(etherscanGasJson.result.suggestBaseFee);
70+ // Calculations derived from:
71+ // https://www.blocknative.com/blog/eip-1559-fees
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)),
78+ suggestedBaseFeePerGas
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)),
85+ suggestedBaseFeePerGas
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)),
92+ suggestedBaseFeePerGas
97+ return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
41export default async function getSuggestedGasPrice(networkType) {
101export default async function getSuggestedGasPrice(networkType) {
42 switch (networkType) {
102 switch (networkType) {
43 case NETWORK_TYPES.GOERLI:
103 case NETWORK_TYPES.GOERLI:
44− return defaultGasValues(10);
104+ return getGasForNetwork('https://api-goerli.etherscan.io')
45 case NETWORK_TYPES.OFFLINE:
105 case NETWORK_TYPES.OFFLINE:
46 return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
106 return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
47 case NETWORK_TYPES.LOCAL:
107 case NETWORK_TYPES.LOCAL:
50− const [etherscanGas, ethgasstationGas] = await Promise.all([
52− 'https://api.etherscan.io/api' +
109+ return getGasForNetwork('https://api.etherscan.io/');
53− '?module=gastracker' +
54− '&action=gasoracle' +
55− '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
62− 'https://ethgasstation.info/json/ethgasAPI.json',
70− const [etherscanGasJson, ethgasstationGasJson] = await Promise.all([
72− ethgasstationGas.json()
75− const suggestedBaseFeePerGas = Number(etherscanGasJson.result.suggestBaseFee);
77− // Calculations derived from:
78− // https://www.blocknative.com/blog/eip-1559-fees
81− price: minGas(etherscanGasJson.result.FastGasPrice),
82− wait: formatWait(ethgasstationGasJson.fastWait),
83− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas),
84− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.FastGasPrice - suggestedBaseFeePerGas)),
85− suggestedBaseFeePerGas
88− price: minGas(etherscanGasJson.result.ProposeGasPrice),
89− wait: formatWait(ethgasstationGasJson.avgWait),
90− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas),
91− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.ProposeGasPrice - suggestedBaseFeePerGas)),
92− suggestedBaseFeePerGas
95− price: minGas(etherscanGasJson.result.SafeGasPrice),
96− wait: formatWait(ethgasstationGasJson.safeLowWait),
97− maxFeePerGas: calculateMaxFee(suggestedBaseFeePerGas, etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas),
98− maxPriorityFeePerGas: feeToInt((etherscanGasJson.result.SafeGasPrice - suggestedBaseFeePerGas)),
99− suggestedBaseFeePerGas
104− return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);