Skip to content

Commit

Permalink
Merge pull request #49 from dominant-strategies/baseFee
Browse files Browse the repository at this point in the history
Base fee
  • Loading branch information
Denis2626 authored Mar 14, 2024
2 parents 36d6463 + a49f7bd commit 7c6e187
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ export type PerformActionRequest = {
method: "getCode",
address: string, blockTag: BlockTag
} | {
method: "getGasPrice"
method: "getGasPrice",
txType: boolean
} | {
method: "getLogs",
filter: PerformActionFilter
Expand Down Expand Up @@ -915,37 +916,35 @@ export class AbstractProvider implements Provider {
return await this.#perform({ method: "getProtocolTrieExpansionCount" });
}

async getFeeData(): Promise<FeeData> {
async getFeeData(txType: boolean = true): Promise<FeeData> {
const network = await this.getNetwork();
const getFeeDataFunc = async () => {
const { _block, gasPrice, priorityFee } = await resolveProperties({
_block: this.#getBlock("latest", false),
const { gasPrice, priorityFee } = await resolveProperties({
gasPrice: ((async () => {
try {
const value = await this.#perform({ method: "getGasPrice" });
const value = await this.#perform({ method: "getGasPrice", txType });
return getBigInt(value, "%response");
} catch (error) { }
return null
})()),
priorityFee: ((async () => {
try {
const value = await this.#perform({ method: "getMaxPriorityFeePerGas" });
const value = txType ? await this.#perform({ method: "getMaxPriorityFeePerGas" }): 0;
return getBigInt(value, "%response");
} catch (error) { }
return null;
})())
});

if (gasPrice == null) { throw new Error("could not determine gasPrice"); }

let maxFeePerGas: null | bigint = null;
let maxPriorityFeePerGas: null | bigint = null;

// These are the recommended EIP-1559 heuristics for fee data

const block = this._wrapBlock(_block, network);
if (block && block.baseFeePerGas) {
maxPriorityFeePerGas = (priorityFee != null) ? priorityFee: BigInt("1000000000");
maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas;
}
maxPriorityFeePerGas = (priorityFee != null) ? priorityFee: BigInt("1000000000");
maxFeePerGas = (gasPrice * BN_2) + maxPriorityFeePerGas;

return new FeeData(gasPrice, maxFeePerGas, maxPriorityFeePerGas);
};
Expand Down
5 changes: 4 additions & 1 deletion src.ts/providers/provider-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,10 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
return { method: "quai_blockNumber", args: [ ] };

case "getGasPrice":
return { method: "quai_gasPrice", args: [] };
return {
method: "quai_baseFee",
args: [ req.txType ]
};

case "getMaxPriorityFeePerGas":
return { method: "quai_maxPriorityFeePerGas", args: []};
Expand Down

0 comments on commit 7c6e187

Please sign in to comment.