Skip to content

Commit 91fff14

Browse files
committed
Better baseFee calculation (#1610).
1 parent c5bca77 commit 91fff14

File tree

1 file changed

+11
-6
lines changed
  • packages/abstract-provider/src.ts

1 file changed

+11
-6
lines changed

packages/abstract-provider/src.ts/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,22 @@ export abstract class Provider implements OnceBlockable {
227227
abstract getGasPrice(): Promise<BigNumber>;
228228
async getFeeData(): Promise<FeeData> {
229229
const { block, gasPrice } = await resolveProperties({
230-
block: this.getBlock(-1),
231-
gasPrice: this.getGasPrice()
230+
block: this.getBlock("latest"),
231+
gasPrice: this.getGasPrice().catch((error) => {
232+
// @TODO: Why is this now failing on Calaveras?
233+
//console.log(error);
234+
return null;
235+
})
232236
});
233237

234238
let maxFeePerGas = null, maxPriorityFeePerGas = null;
235239

236240
if (block && block.baseFee) {
237-
maxFeePerGas = block.baseFee.mul(2);
238-
//maxPriorityFeePerGas = BigNumber.from("1000000000");
239-
// @TODO: This needs to come from somewhere.
240-
maxPriorityFeePerGas = BigNumber.from("1");
241+
// We may want to compute this more accurately in the future,
242+
// using the formula "check if the base fee is correct".
243+
// See: https://eips.ethereum.org/EIPS/eip-1559
244+
maxPriorityFeePerGas = BigNumber.from("1000000000");
245+
maxFeePerGas = block.baseFee.mul(2).add(maxPriorityFeePerGas);
241246
}
242247

243248
return { maxFeePerGas, maxPriorityFeePerGas, gasPrice };

0 commit comments

Comments
 (0)