Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch priorityFeePerGas in a native way for merge and optimism chains #4463

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ export type PerformActionRequest = {
address: string, blockTag: BlockTag
} | {
method: "getGasPrice"
} | {
method: "getPriorityFeePerGas"
} | {
method: "getLogs",
filter: PerformActionFilter
Expand Down Expand Up @@ -896,14 +898,23 @@ export class AbstractProvider implements Provider {
const network = await this.getNetwork();

const getFeeDataFunc = async () => {
const { _block, gasPrice } = await resolveProperties({
const { _block, gasPrice, priorityFeePerGas } = await resolveProperties({
_block: this.#getBlock("latest", false),
gasPrice: ((async () => {
try {
const gasPrice = await this.#perform({ method: "getGasPrice" });
return getBigInt(gasPrice, "%response");
} catch (error) { }
return null
})()),
priorityFeePerGas: ((async () => {
try {
const priorityFeePerGas = await this.#perform({ method: "getPriorityFeePerGas" });
return getBigInt(priorityFeePerGas, "%response");
} catch (error) {
// Return 1 GWei as a fallback for non EIP-1559 enabled chains or if the method isn't implemented
return BigInt("1000000000");
}
})())
});

Expand All @@ -913,7 +924,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 = priorityFeePerGas;
maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas;
}

Expand Down
3 changes: 3 additions & 0 deletions src.ts/providers/provider-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
case "getGasPrice":
return { method: "eth_gasPrice", args: [] };

case "getPriorityFeePerGas":
return { method: "eth_maxPriorityFeePerGas", args: [] };

case "getBalance":
return {
method: "eth_getBalance",
Expand Down