From 91fff1449df5e337fd3b4681b5a04b151d92f5a1 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 14 Jun 2021 23:42:11 -0400 Subject: [PATCH] Better baseFee calculation (#1610). --- packages/abstract-provider/src.ts/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/abstract-provider/src.ts/index.ts b/packages/abstract-provider/src.ts/index.ts index 419b0c86c2..1a821cd939 100644 --- a/packages/abstract-provider/src.ts/index.ts +++ b/packages/abstract-provider/src.ts/index.ts @@ -227,17 +227,22 @@ export abstract class Provider implements OnceBlockable { abstract getGasPrice(): Promise; async getFeeData(): Promise { const { block, gasPrice } = await resolveProperties({ - block: this.getBlock(-1), - gasPrice: this.getGasPrice() + block: this.getBlock("latest"), + gasPrice: this.getGasPrice().catch((error) => { + // @TODO: Why is this now failing on Calaveras? + //console.log(error); + return null; + }) }); let maxFeePerGas = null, maxPriorityFeePerGas = null; if (block && block.baseFee) { - maxFeePerGas = block.baseFee.mul(2); - //maxPriorityFeePerGas = BigNumber.from("1000000000"); - // @TODO: This needs to come from somewhere. - maxPriorityFeePerGas = BigNumber.from("1"); + // We may want to compute this more accurately in the future, + // using the formula "check if the base fee is correct". + // See: https://eips.ethereum.org/EIPS/eip-1559 + maxPriorityFeePerGas = BigNumber.from("1000000000"); + maxFeePerGas = block.baseFee.mul(2).add(maxPriorityFeePerGas); } return { maxFeePerGas, maxPriorityFeePerGas, gasPrice };