Skip to content

Commit

Permalink
[fix-gas] improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Cast0001 committed Nov 16, 2023
1 parent dac5987 commit d869914
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/getGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ const getGas = async (value: GetGasInput): Promise<bigint> => {

validateArgs.bigint({ estimatedGas })

const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = await provider.getFeeData()
const [ feeData, latestBlock ] = await Promise.all([
provider.getFeeData(),
provider.getBlock('latest'),
])

const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = feeData
const baseFeePerGas = latestBlock?.baseFeePerGas || 0n

const isEIP1559 = Boolean(maxFeePerGas && maxPriorityFeePerGas)

const gas = isEIP1559
? estimatedGas * (maxFeePerGas as bigint)
? estimatedGas * (baseFeePerGas + (maxPriorityFeePerGas || 0n))
: estimatedGas * (gasPrice as bigint)

return gas
Expand Down

0 comments on commit d869914

Please sign in to comment.