Use provider-specified suggested priority fee when available, otherwise fallback onto existing logic of 1 gwei (#4463).
This commit is contained in:
parent
4681b83d51
commit
f8f11c754a
@ -383,6 +383,8 @@ export type PerformActionRequest = {
|
|||||||
} | {
|
} | {
|
||||||
method: "getLogs",
|
method: "getLogs",
|
||||||
filter: PerformActionFilter
|
filter: PerformActionFilter
|
||||||
|
} | {
|
||||||
|
method: "getPriorityFee"
|
||||||
} | {
|
} | {
|
||||||
method: "getStorage",
|
method: "getStorage",
|
||||||
address: string, position: bigint, blockTag: BlockTag
|
address: string, position: bigint, blockTag: BlockTag
|
||||||
@ -906,14 +908,21 @@ export class AbstractProvider implements Provider {
|
|||||||
const network = await this.getNetwork();
|
const network = await this.getNetwork();
|
||||||
|
|
||||||
const getFeeDataFunc = async () => {
|
const getFeeDataFunc = async () => {
|
||||||
const { _block, gasPrice } = await resolveProperties({
|
const { _block, gasPrice, priorityFee } = await resolveProperties({
|
||||||
_block: this.#getBlock("latest", false),
|
_block: this.#getBlock("latest", false),
|
||||||
gasPrice: ((async () => {
|
gasPrice: ((async () => {
|
||||||
try {
|
try {
|
||||||
const gasPrice = await this.#perform({ method: "getGasPrice" });
|
const value = await this.#perform({ method: "getGasPrice" });
|
||||||
return getBigInt(gasPrice, "%response");
|
return getBigInt(value, "%response");
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
return null
|
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
|
// These are the recommended EIP-1559 heuristics for fee data
|
||||||
const block = this._wrapBlock(_block, network);
|
const block = this._wrapBlock(_block, network);
|
||||||
if (block && block.baseFeePerGas) {
|
if (block && block.baseFeePerGas) {
|
||||||
maxPriorityFeePerGas = BigInt("1000000000");
|
maxPriorityFeePerGas = (priorityFee != null) ? priorityFee: BigInt("1000000000");
|
||||||
maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas;
|
maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
// See: https://chainlist.org
|
||||||
let injected = false;
|
let injected = false;
|
||||||
function injectCommonNetworks(): void {
|
function injectCommonNetworks(): void {
|
||||||
@ -409,11 +389,11 @@ function injectCommonNetworks(): void {
|
|||||||
registerEth("kovan", 42, { ensNetwork: 42 });
|
registerEth("kovan", 42, { ensNetwork: 42 });
|
||||||
registerEth("sepolia", 11155111, { ensNetwork: 11155111 });
|
registerEth("sepolia", 11155111, { ensNetwork: 11155111 });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
registerEth("classic", 61, { });
|
registerEth("classic", 61, { });
|
||||||
registerEth("classicKotti", 6, { });
|
registerEth("classicKotti", 6, { });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
registerEth("arbitrum", 42161, {
|
registerEth("arbitrum", 42161, {
|
||||||
ensNetwork: 1,
|
ensNetwork: 1,
|
||||||
});
|
});
|
||||||
@ -444,9 +424,7 @@ function injectCommonNetworks(): void {
|
|||||||
|
|
||||||
registerEth("optimism", 10, {
|
registerEth("optimism", 10, {
|
||||||
ensNetwork: 1,
|
ensNetwork: 1,
|
||||||
plugins: [
|
plugins: [ ]
|
||||||
getPriorityFeePlugin(BigInt("1000000"))
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
registerEth("optimism-goerli", 420, { });
|
registerEth("optimism-goerli", 420, { });
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import {
|
|||||||
hexlify, toQuantity,
|
hexlify, toQuantity,
|
||||||
FetchRequest,
|
FetchRequest,
|
||||||
assert, assertArgument, isError,
|
assert, assertArgument, isError,
|
||||||
|
// parseUnits,
|
||||||
toUtf8String
|
toUtf8String
|
||||||
} from "../utils/index.js";
|
} from "../utils/index.js";
|
||||||
|
|
||||||
@ -421,6 +422,43 @@ export class EtherscanProvider extends AbstractProvider {
|
|||||||
case "getGasPrice":
|
case "getGasPrice":
|
||||||
return this.fetch("proxy", { action: "eth_gasPrice" });
|
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":
|
case "getBalance":
|
||||||
// Returns base-10 result
|
// Returns base-10 result
|
||||||
return this.fetch("account", {
|
return this.fetch("account", {
|
||||||
|
@ -458,6 +458,8 @@ export class FallbackProvider extends AbstractProvider {
|
|||||||
return await provider.getCode(req.address, req.blockTag);
|
return await provider.getCode(req.address, req.blockTag);
|
||||||
case "getGasPrice":
|
case "getGasPrice":
|
||||||
return (await provider.getFeeData()).gasPrice;
|
return (await provider.getFeeData()).gasPrice;
|
||||||
|
case "getPriorityFee":
|
||||||
|
return (await provider.getFeeData()).maxPriorityFeePerGas;
|
||||||
case "getLogs":
|
case "getLogs":
|
||||||
return await provider.getLogs(req.filter);
|
return await provider.getLogs(req.filter);
|
||||||
case "getStorage":
|
case "getStorage":
|
||||||
@ -614,6 +616,7 @@ export class FallbackProvider extends AbstractProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "getGasPrice":
|
case "getGasPrice":
|
||||||
|
case "getPriorityFee":
|
||||||
case "estimateGas":
|
case "estimateGas":
|
||||||
return getMedian(this.quorum, results);
|
return getMedian(this.quorum, results);
|
||||||
|
|
||||||
|
@ -821,6 +821,9 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
|
|||||||
case "getGasPrice":
|
case "getGasPrice":
|
||||||
return { method: "eth_gasPrice", args: [] };
|
return { method: "eth_gasPrice", args: [] };
|
||||||
|
|
||||||
|
case "getPriorityFee":
|
||||||
|
return { method: "eth_maxPriorityFeePerGas", args: [ ] };
|
||||||
|
|
||||||
case "getBalance":
|
case "getBalance":
|
||||||
return {
|
return {
|
||||||
method: "eth_getBalance",
|
method: "eth_getBalance",
|
||||||
|
Loading…
Reference in New Issue
Block a user