Skip to content

Commit

Permalink
Also enforce minimum of 30Gwei priority fee
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Sep 17, 2024
1 parent 59c8dc6 commit 62f8d91
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/gasPriceOracle/adapters/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { providers } from "ethers";
import { BaseHTTPAdapter, BaseHTTPAdapterArgs } from "../../priceClient/adapters/baseAdapter";
import { bnZero, isDefined, parseUnits } from "../../utils";
import { BigNumber, bnZero, isDefined, parseUnits } from "../../utils";
import { CHAIN_IDs } from "../../constants";
import { GasPriceEstimate } from "../types";
import { gasPriceError } from "../util";
Expand Down Expand Up @@ -67,12 +67,25 @@ class PolygonGasStation extends BaseHTTPAdapter {
}
}

export function gasStation(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
export async function gasStation(provider: providers.Provider, chainId: number): Promise<GasPriceEstimate> {
const gasStation = new PolygonGasStation({ chainId: chainId, timeout: 2000, retries: 0 });
let maxPriorityFeePerGas: BigNumber;
let maxFeePerGas: BigNumber;
try {
return gasStation.getFeeData();
({ maxPriorityFeePerGas, maxFeePerGas } = await gasStation.getFeeData());
} catch (err) {
// Fall back to the RPC provider. May be less accurate.
return eip1559(provider, chainId);
({ maxPriorityFeePerGas, maxFeePerGas } = await eip1559(provider, chainId));

// Per the GasStation docs, the minimum priority fee on Polygon is 30 Gwei.
// https://docs.polygon.technology/tools/gas/polygon-gas-station/#interpretation
const minPriorityFee = parseUnits("30", 9);
if (maxPriorityFeePerGas.lt(minPriorityFee)) {
const priorityDelta = minPriorityFee.sub(maxPriorityFeePerGas);
maxPriorityFeePerGas = minPriorityFee;
maxFeePerGas = maxFeePerGas.add(priorityDelta);
}
}

return { maxPriorityFeePerGas, maxFeePerGas };
}

0 comments on commit 62f8d91

Please sign in to comment.