Skip to content

Commit

Permalink
Better baseFee calculation (#1610).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jun 15, 2021
1 parent c5bca77 commit 91fff14
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/abstract-provider/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,22 @@ export abstract class Provider implements OnceBlockable {
abstract getGasPrice(): Promise<BigNumber>;
async getFeeData(): Promise<FeeData> {
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 };
Expand Down

0 comments on commit 91fff14

Please sign in to comment.