Skip to content

Commit

Permalink
fix(gas): correct gas estimation logic on Arbitrum Sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Jul 24, 2024
1 parent c82c524 commit b2858a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-vans-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix gas estimation on arbitrum sepolia
9 changes: 6 additions & 3 deletions packages/thirdweb/src/gas/fee-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export async function getDefaultGasOverrides(
// if chain is in the force gas price list, always use gas price
if (!FORCE_GAS_PRICE_CHAIN_IDS.includes(chain.id)) {
const feeData = await getDynamicFeeData(client, chain);
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
if (
feeData.maxFeePerGas !== null &&
feeData.maxPriorityFeePerGas !== null
) {
return {
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
Expand Down Expand Up @@ -153,12 +156,12 @@ async function getDynamicFeeData(
if (chainId === 80002 || chainId === 137) {
// for polygon, get fee data from gas station
maxPriorityFeePerGas_ = await getPolygonGasPriorityFee(chainId);
} else if (maxPriorityFeePerGas) {
} else if (maxPriorityFeePerGas !== null) {
// prioritize fee from eth_maxPriorityFeePerGas
maxPriorityFeePerGas_ = maxPriorityFeePerGas;
}

if (!maxPriorityFeePerGas_) {
if (maxPriorityFeePerGas_ == null) {
// chain does not support eip-1559, return null for both
return { maxFeePerGas: null, maxPriorityFeePerGas: null };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { TEST_WALLET_B } from "../../../test/src/addresses.js";
import { FORKED_ETHEREUM_CHAIN } from "../../../test/src/chains.js";
import { TEST_CLIENT } from "../../../test/src/test-clients.js";

import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
import { ZERO_ADDRESS } from "../../constants/addresses.js";
import { toWei } from "../../utils/units.js";
import {
type PreparedTransaction,
Expand Down Expand Up @@ -400,4 +402,18 @@ describe("toSerializableTransaction", () => {
).not.toThrow();
});
});

test("should respect 0 maxPriorityFeePerGas chains", async () => {
const serializableTransaction = await toSerializableTransaction({
transaction: prepareTransaction({
to: TEST_WALLET_B,
chain: arbitrumSepolia,
value: toWei("0.000001"),
client: TEST_CLIENT,
}),
from: ZERO_ADDRESS,
});

expect(serializableTransaction.gasPrice).toBe(null);
});
});

0 comments on commit b2858a0

Please sign in to comment.