Skip to content

Commit

Permalink
Fix bug when blobBaseFee is sub-gwei (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke authored Apr 6, 2024
1 parent 1127a79 commit 1075278
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/lib/render/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function generateMarkdownTable(
let gasPrices: string[][];
let l1gwei: string | number | undefined;
let l2gwei: string | number | undefined;
let l1GweiBlobBaseFee: string | number | undefined;
const { network, currency, nonZeroMsg, intrinsicMsg } = getCommonTableVals(options);
let tokenPrice = "-";
let rate: string;
Expand All @@ -60,6 +61,7 @@ export function generateMarkdownTable(
({
l1gwei,
l2gwei,
l1GweiBlobBaseFee,
rate,
token
} = getCommonTableVals(options));
Expand All @@ -72,7 +74,7 @@ export function generateMarkdownTable(
]
: [
[`L1 Base Fee`, `${options.baseFee!} gwei`],
[`L1 Blob Base Fee`, `${options.blobBaseFee!} gwei`],
[`L1 Blob Base Fee`, `${l1GweiBlobBaseFee!} gwei`],
[`L2 Gas Price`, `${l2gwei} gwei` ]
]

Expand Down
3 changes: 2 additions & 1 deletion src/lib/render/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export function generateTerminalTextTable(
l2gwei,
l1gweiNote,
l2gweiNote,
l1GweiBlobBaseFee,
network,
rate,
currency,
Expand Down Expand Up @@ -327,7 +328,7 @@ export function generateTerminalTextTable(
opStackConfig.push({
hAlign: "left",
colSpan: 2,
content: chalk.cyan(`L1: ${options.blobBaseFee!} gwei (blobBaseFee)`)
content: chalk.cyan(`L1: ${l1GweiBlobBaseFee!} gwei (blobBaseFee)`)
});
opStackConfig.push({
hAlign: "left",
Expand Down
7 changes: 4 additions & 3 deletions src/utils/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ export async function setGasAndPriceRates(options: GasReporterOptions): Promise<
!options.blobBaseFee
) {
try {
const blobBaseFee = await axiosInstance.get(blobBaseFeeUrl);
checkForEtherscanError(blobBaseFee.data.result);
options.blobBaseFee = Math.round(hexWeiToIntGwei(blobBaseFee.data.result))
const response = await axiosInstance.get(blobBaseFeeUrl);
checkForEtherscanError(response.data.result);
const blobBaseFee = hexWeiToIntGwei(response.data.result);
options.blobBaseFee = (blobBaseFee >= 1 ) ? Math.round(blobBaseFee) : blobBaseFee;
} catch (error) {
options.blobBaseFee = DEFAULT_BLOB_BASE_FEE;
warnings.push(warnBlobBaseFeeRemoteCallFailed(error));
Expand Down
6 changes: 6 additions & 0 deletions src/utils/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export function getCommonTableVals(options: GasReporterOptions) {

let l2BaseFeeNote = "(baseFee)";
let l1GweiForL2 = options.baseFee;
let l1GweiBlobBaseFee: string | number | undefined = options.blobBaseFee;

if (options.L2 === "arbitrum"){
l2BaseFeeNote = "(baseFeePerByte)"
Expand Down Expand Up @@ -245,6 +246,10 @@ export function getCommonTableVals(options: GasReporterOptions) {
l2gwei = parseFloat(l2gwei.toString()).toFixed(DEFAULT_GAS_PRICE_PRECISION);
}

if (typeof l1GweiBlobBaseFee === "number" && l1GweiBlobBaseFee < 1) {
l1GweiBlobBaseFee = parseFloat(l1GweiBlobBaseFee.toString()).toFixed(DEFAULT_GAS_PRICE_PRECISION);
}

const nonZeroMsg = "Cost was non-zero but below the precision setting for the currency display (see options)";
const intrinsicMsg = "Execution gas for this method does not include intrinsic gas overhead ";

Expand All @@ -253,6 +258,7 @@ export function getCommonTableVals(options: GasReporterOptions) {
l2gwei,
l1gweiNote,
l2gweiNote,
l1GweiBlobBaseFee,
network,
rate,
currency,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/options.e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("Options E (OPStack:optimism with live pricing & `reportPureAndViewMeth
assert.isDefined(options.gasPrice);
assert.isDefined(options.blobBaseFee);
assert.isBelow(options.gasPrice!, 1);
assert.isAbove(options.blobBaseFee!, 1);
assert.isAbove(options.blobBaseFee!, 0);

assert.isDefined(options.tokenPrice);
assert.isAbove(parseFloat(options.tokenPrice!), 1000); // Eth-ish
Expand Down
2 changes: 1 addition & 1 deletion test/integration/options.f.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("Options F (OPStack:base with live pricing & `reportPureAndViewMethods`
assert.isDefined(options.gasPrice);
assert.isDefined(options.blobBaseFee);
assert.isBelow(options.gasPrice!, 1);
assert.isAbove(options.blobBaseFee!, 1);
assert.isAbove(options.blobBaseFee!, 0);

assert.isDefined(options.tokenPrice);
assert.isAbove(parseFloat(options.tokenPrice!), 1000); // Eth-ish
Expand Down
2 changes: 1 addition & 1 deletion test/integration/options.g.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Options G (Arbitrum with live pricing & `reportPureAndViewMethods`)",
assert.isDefined(options.gasPrice);
assert.isDefined(options.baseFeePerByte);
assert.isBelow(options.gasPrice!, 1);
assert.isAbove(options.baseFeePerByte!, 1);
assert.isAbove(options.baseFeePerByte!, 0);

assert.isDefined(options.tokenPrice);
assert.isAbove(parseFloat(options.tokenPrice!), 1000); // Eth-ish
Expand Down
1 change: 1 addition & 0 deletions test/projects/options/hardhat.options.g.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const config: HardhatUserConfig = {
},
gasReporter: {
coinmarketcap: process.env.CMC_API_KEY,
currencyDisplayPrecision: 4,
L2: "arbitrum",
L1Etherscan: process.env.ETHERSCAN_API_KEY,
L2Etherscan: process.env.ARBITRUM_API_KEY,
Expand Down

0 comments on commit 1075278

Please sign in to comment.