Skip to content

Commit

Permalink
Include current baseFee in feeData for easier custom fee calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Aug 16, 2022
1 parent e52fbfb commit 8314236
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/abstract-provider/src.ts/index.ts
Expand Up @@ -124,6 +124,7 @@ export interface TransactionReceipt {
};

export interface FeeData {
lastBaseFeePerGas: null | BigNumber;
maxFeePerGas: null | BigNumber;
maxPriorityFeePerGas: null | BigNumber;
gasPrice: null | BigNumber;
Expand Down Expand Up @@ -241,17 +242,18 @@ export abstract class Provider implements OnceBlockable {
})
});

let maxFeePerGas = null, maxPriorityFeePerGas = null;
let lastBaseFeePerGas = null, maxFeePerGas = null, maxPriorityFeePerGas = null;

if (block && block.baseFeePerGas) {
// 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
lastBaseFeePerGas = block.baseFeePerGas;
maxPriorityFeePerGas = BigNumber.from("1500000000");
maxFeePerGas = block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas);
}

return { maxFeePerGas, maxPriorityFeePerGas, gasPrice };
return { lastBaseFeePerGas, maxFeePerGas, maxPriorityFeePerGas, gasPrice };
}

// Account
Expand Down

0 comments on commit 8314236

Please sign in to comment.