diff --git a/libs/metrics/src/l1/l1MetricsService.ts b/libs/metrics/src/l1/l1MetricsService.ts index 5681028..ae0598b 100644 --- a/libs/metrics/src/l1/l1MetricsService.ts +++ b/libs/metrics/src/l1/l1MetricsService.ts @@ -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 { @@ -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 [ diff --git a/libs/metrics/src/types/feeParams.type.ts b/libs/metrics/src/types/feeParams.type.ts index b177298..9c32e22 100644 --- a/libs/metrics/src/types/feeParams.type.ts +++ b/libs/metrics/src/types/feeParams.type.ts @@ -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;