Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Aug 9, 2024
1 parent a8bda96 commit 0187395
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
11 changes: 6 additions & 5 deletions libs/metrics/src/l1/l1MetricsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
L1MetricsServiceException,
} from "@zkchainhub/metrics/exceptions";
import { bridgeHubAbi, diamondProxyAbi, sharedBridgeAbi } from "@zkchainhub/metrics/l1/abis";
import { AssetTvl, FeeParams, feeParamsFieldLengths, GasInfo } from "@zkchainhub/metrics/types";
import { AssetTvl, FeeParams, feeParamsFieldHexDigits, GasInfo } from "@zkchainhub/metrics/types";
import { IPricingService, PRICING_PROVIDER } from "@zkchainhub/pricing";
import { EvmProviderService } from "@zkchainhub/providers";
import {
Expand Down Expand Up @@ -345,15 +345,16 @@ export class L1MetricsService {
throw new L1MetricsServiceException("Failed to get fee params from L1.");
}

const strippedParamsData = feeParamsData.slice(2); // Remove the 0x prefix
const strippedParamsData = feeParamsData.replace(/^0x/, "");
let cursor = strippedParamsData.length;
const values: string[] = [];

for (const value of Object.values(feeParamsFieldLengths)) {
const hexValue = strippedParamsData.slice(cursor - value, cursor);
//read fields from Right to Left
for (const digits of feeParamsFieldHexDigits) {
const hexValue = strippedParamsData.slice(cursor - digits, cursor);
assert(hexValue, "Error parsing fee params");
values.push(hexValue);
cursor -= value;
cursor -= digits;
}

const [
Expand Down
19 changes: 11 additions & 8 deletions libs/metrics/src/types/feeParams.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ export type FeeParams = {
};

// Define the lengths for each field (in hex digits, each byte is 2 hex digits)
export const feeParamsFieldLengths = {
pubdataPricingMode: 2, // uint8 -> 1 byte -> 2 hex digits
batchOverheadL1Gas: 8, // uint32 -> 4 bytes -> 8 hex digits
maxPubdataPerBatch: 8, // uint32 -> 4 bytes -> 8 hex digits
maxL2GasPerBatch: 8, // uint32 -> 4 bytes -> 8 hex digits
priorityTxMaxPubdata: 8, // uint32 -> 4 bytes -> 8 hex digits
minimalL2GasPrice: 16, // uint64 -> 8 bytes -> 16 hex digits
} as const;
/*
{
pubdataPricingMode: uint8 -> 1 byte -> 2 hex digits
batchOverheadL1Gas: uint32 -> 4 bytes -> 8 hex digits
maxPubdataPerBatch: uint32 -> 4 bytes -> 8 hex digits
maxL2GasPerBatch: uint32 -> 4 bytes -> 8 hex digits
priorityTxMaxPubdata: uint32 -> 4 bytes -> 8 hex digits
minimalL2GasPrice: uint64 -> 8 bytes -> 16 hex digits
}
*/
export const feeParamsFieldHexDigits = [2, 8, 8, 8, 8, 16] as const;

0 comments on commit 0187395

Please sign in to comment.