Skip to content

Commit

Permalink
Fix the calculation for estimated gas price
Browse files Browse the repository at this point in the history
The gas price returned by the rpc is base_fee + max_priority_fee.
So we shouldn't add the max_priority_fee onto that value since it's
already included. Also the logic used by viem for applying the
multiplier is to only apply the multiplier to the base fee and not the
priority fee, so we match that approach here.
  • Loading branch information
piersy committed Oct 14, 2024
1 parent 471a3f8 commit 3ed6e3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/celo/fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ describe('celo/fees', () => {
},
} as any)

// The fees maxFeePerGas is calculated as (baseFee * multiplier) + maxPriorityFeePerGas
// Which is ((15057755162-602286) * 150 / 100) + 602286 = 22586331600
expect(fees).toMatchInlineSnapshot(`
{
"maxFeePerGas": 22587235029n,
"maxFeePerGas": 22586331600n,
"maxPriorityFeePerGas": 602286n,
}
`)
Expand Down
5 changes: 2 additions & 3 deletions src/celo/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ export const fees: ChainFees<typeof formatters> = {
),
])

const suggestedMaxFeePerGas =
params.multiply(maxFeePerGas) + maxPriorityFeePerGas
const adjustedBasFee = params.multiply(maxFeePerGas-maxPriorityFeePerGas)

return {
maxFeePerGas: suggestedMaxFeePerGas,
maxFeePerGas: adjustedBasFee + maxPriorityFeePerGas,
maxPriorityFeePerGas,
}
},
Expand Down

0 comments on commit 3ed6e3d

Please sign in to comment.