diff --git a/package.json b/package.json index ef2c4e099..24bc0964e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@across-protocol/sdk", "author": "UMA Team", - "version": "3.1.35", + "version": "3.1.36", "license": "AGPL-3.0", "homepage": "https://docs.across.to/reference/sdk", "files": [ diff --git a/src/gasPriceOracle/adapters/polygon.ts b/src/gasPriceOracle/adapters/polygon.ts index fd95e4982..9b8c93ea5 100644 --- a/src/gasPriceOracle/adapters/polygon.ts +++ b/src/gasPriceOracle/adapters/polygon.ts @@ -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"; @@ -27,8 +27,6 @@ type GasStationArgs = BaseHTTPAdapterArgs & { const { POLYGON } = CHAIN_IDs; -// @dev toBNWei() is not imported from ../utils because of a circular dependency loop. -// The fix is probably to relocate the function estimateTotalGasRequiredByUnsignedTransaction(). class PolygonGasStation extends BaseHTTPAdapter { readonly chainId: number; @@ -42,7 +40,7 @@ class PolygonGasStation extends BaseHTTPAdapter { async getFeeData(strategy: "safeLow" | "standard" | "fast" = "fast"): Promise { const gas = await this.query("v2", {}); - const gasPrice: Polygon1559GasPrice = (gas as GasStationV2Response)?.[strategy]; + const gasPrice = (gas as GasStationV2Response)?.[strategy]; if (!this.isPolygon1559GasPrice(gasPrice)) { // @todo: generalise gasPriceError() to accept a reason/cause? gasPriceError("getFeeData()", this.chainId, bnZero); @@ -69,12 +67,25 @@ class PolygonGasStation extends BaseHTTPAdapter { } } -export function gasStation(provider: providers.Provider, chainId: number): Promise { - const gasStation = new PolygonGasStation({ chainId: chainId }); +export async function gasStation(provider: providers.Provider, chainId: number): Promise { + 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 }; } diff --git a/src/priceClient/adapters/baseAdapter.ts b/src/priceClient/adapters/baseAdapter.ts index 007af2473..06d9600ca 100644 --- a/src/priceClient/adapters/baseAdapter.ts +++ b/src/priceClient/adapters/baseAdapter.ts @@ -40,6 +40,7 @@ export class BaseHTTPAdapter { protected async query(path: string, urlArgs?: object): Promise { const url = `https://${this.host}/${path ?? ""}`; const args = { + headers: { "User-Agent": process.env.ACROSS_USER_AGENT ?? "across-protocol" }, timeout: this.timeout, params: urlArgs ?? {}, };