diff --git a/src.ts/providers/abstract-provider.ts b/src.ts/providers/abstract-provider.ts index 302ad1052b..12c57e9a91 100644 --- a/src.ts/providers/abstract-provider.ts +++ b/src.ts/providers/abstract-provider.ts @@ -383,6 +383,8 @@ export type PerformActionRequest = { } | { method: "getLogs", filter: PerformActionFilter +} | { + method: "getPriorityFee" } | { method: "getStorage", address: string, position: bigint, blockTag: BlockTag @@ -906,14 +908,21 @@ export class AbstractProvider implements Provider { const network = await this.getNetwork(); const getFeeDataFunc = async () => { - const { _block, gasPrice } = await resolveProperties({ + const { _block, gasPrice, priorityFee } = await resolveProperties({ _block: this.#getBlock("latest", false), gasPrice: ((async () => { try { - const gasPrice = await this.#perform({ method: "getGasPrice" }); - return getBigInt(gasPrice, "%response"); + const value = await this.#perform({ method: "getGasPrice" }); + return getBigInt(value, "%response"); } catch (error) { } return null + })()), + priorityFee: ((async () => { + try { + const value = await this.#perform({ method: "getPriorityFee" }); + return getBigInt(value, "%response"); + } catch (error) { } + return null; })()) }); @@ -923,7 +932,7 @@ export class AbstractProvider implements Provider { // These are the recommended EIP-1559 heuristics for fee data const block = this._wrapBlock(_block, network); if (block && block.baseFeePerGas) { - maxPriorityFeePerGas = BigInt("1000000000"); + maxPriorityFeePerGas = (priorityFee != null) ? priorityFee: BigInt("1000000000"); maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas; } diff --git a/src.ts/providers/network.ts b/src.ts/providers/network.ts index 88a1fa45ae..9e05f6876b 100644 --- a/src.ts/providers/network.ts +++ b/src.ts/providers/network.ts @@ -346,26 +346,6 @@ function getGasStationPlugin(url: string) { }); } -// Used by Optimism for a custom priority fee -function getPriorityFeePlugin(maxPriorityFeePerGas: bigint) { - return new FetchUrlFeeDataNetworkPlugin("data:", async (fetchFeeData, provider, request) => { - const feeData = await fetchFeeData(); - - // This should always fail - if (feeData.maxFeePerGas == null || feeData.maxPriorityFeePerGas == null) { - return feeData; - } - - // Compute the corrected baseFee to recompute the updated values - const baseFee = feeData.maxFeePerGas - feeData.maxPriorityFeePerGas; - return { - gasPrice: feeData.gasPrice, - maxFeePerGas: (baseFee + maxPriorityFeePerGas), - maxPriorityFeePerGas - }; - }); -} - // See: https://chainlist.org let injected = false; function injectCommonNetworks(): void { @@ -409,10 +389,10 @@ function injectCommonNetworks(): void { registerEth("kovan", 42, { ensNetwork: 42 }); registerEth("sepolia", 11155111, { ensNetwork: 11155111 }); - registerEth("classic", 61, { }); - registerEth("classicKotti", 6, { }); + registerEth("classic", 61, { }); + registerEth("classicKotti", 6, { }); registerEth("arbitrum", 42161, { ensNetwork: 1, @@ -444,9 +424,7 @@ function injectCommonNetworks(): void { registerEth("optimism", 10, { ensNetwork: 1, - plugins: [ - getPriorityFeePlugin(BigInt("1000000")) - ] + plugins: [ ] }); registerEth("optimism-goerli", 420, { }); diff --git a/src.ts/providers/provider-etherscan.ts b/src.ts/providers/provider-etherscan.ts index 899d8abdf5..c6b00dd730 100644 --- a/src.ts/providers/provider-etherscan.ts +++ b/src.ts/providers/provider-etherscan.ts @@ -26,6 +26,7 @@ import { hexlify, toQuantity, FetchRequest, assert, assertArgument, isError, +// parseUnits, toUtf8String } from "../utils/index.js"; @@ -421,6 +422,43 @@ export class EtherscanProvider extends AbstractProvider { case "getGasPrice": return this.fetch("proxy", { action: "eth_gasPrice" }); + case "getPriorityFee": + // This is temporary until Etherscan completes support + if (this.network.name === "mainnet") { + return "1000000000"; + } else if (this.network.name === "optimism") { + return "1000000"; + } else { + throw new Error("fallback onto the AbstractProvider default"); + } + /* Working with Etherscan to get this added: + try { + const test = await this.fetch("proxy", { + action: "eth_maxPriorityFeePerGas" + }); + console.log(test); + return test; + } catch (e) { + console.log("DEBUG", e); + throw e; + } + */ + /* This might be safe; but due to rounding neither myself + or Etherscan are necessarily comfortable with this. :) + try { + const result = await this.fetch("gastracker", { action: "gasoracle" }); + console.log(result); + const gasPrice = parseUnits(result.SafeGasPrice, "gwei"); + const baseFee = parseUnits(result.suggestBaseFee, "gwei"); + const priorityFee = gasPrice - baseFee; + if (priorityFee < 0) { throw new Error("negative priority fee; defer to abstract provider default"); } + return priorityFee; + } catch (error) { + console.log("DEBUG", error); + throw error; + } + */ + case "getBalance": // Returns base-10 result return this.fetch("account", { diff --git a/src.ts/providers/provider-fallback.ts b/src.ts/providers/provider-fallback.ts index f5a00f7cfe..6b194f12b6 100644 --- a/src.ts/providers/provider-fallback.ts +++ b/src.ts/providers/provider-fallback.ts @@ -458,6 +458,8 @@ export class FallbackProvider extends AbstractProvider { return await provider.getCode(req.address, req.blockTag); case "getGasPrice": return (await provider.getFeeData()).gasPrice; + case "getPriorityFee": + return (await provider.getFeeData()).maxPriorityFeePerGas; case "getLogs": return await provider.getLogs(req.filter); case "getStorage": @@ -614,6 +616,7 @@ export class FallbackProvider extends AbstractProvider { } case "getGasPrice": + case "getPriorityFee": case "estimateGas": return getMedian(this.quorum, results); diff --git a/src.ts/providers/provider-jsonrpc.ts b/src.ts/providers/provider-jsonrpc.ts index 8674964e43..c1c20dfdb5 100644 --- a/src.ts/providers/provider-jsonrpc.ts +++ b/src.ts/providers/provider-jsonrpc.ts @@ -821,6 +821,9 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { case "getGasPrice": return { method: "eth_gasPrice", args: [] }; + case "getPriorityFee": + return { method: "eth_maxPriorityFeePerGas", args: [ ] }; + case "getBalance": return { method: "eth_getBalance",