diff --git a/libs/metrics/src/l1/l1MetricsService.ts b/libs/metrics/src/l1/l1MetricsService.ts index 35ebcec..e7d2ad1 100644 --- a/libs/metrics/src/l1/l1MetricsService.ts +++ b/libs/metrics/src/l1/l1MetricsService.ts @@ -1,14 +1,7 @@ import { isNativeError } from "util/types"; import { Inject, Injectable, LoggerService } from "@nestjs/common"; import { WINSTON_MODULE_NEST_PROVIDER } from "nest-winston"; -import { - encodeFunctionData, - erc20Abi, - formatGwei, - formatUnits, - parseEther, - zeroAddress, -} from "viem"; +import { encodeFunctionData, erc20Abi, formatGwei, parseEther, zeroAddress } from "viem"; import { L1ProviderException } from "@zkchainhub/metrics/exceptions/provider.exception"; import { bridgeHubAbi, sharedBridgeAbi } from "@zkchainhub/metrics/l1/abis"; @@ -19,7 +12,6 @@ import { AbiWithAddress, ChainId, L1_CONTRACTS, vitalikAddress } from "@zkchainh import { ETH, WETH } from "@zkchainhub/shared/tokens/tokens"; const ONE_ETHER = parseEther("1"); -const ETHER_DECIMALS = 18; /** * Acts as a wrapper around Viem library to provide methods to interact with an EVM-based blockchain. @@ -100,10 +92,10 @@ export class L1MetricsService { } return { - gasPriceInGwei: Number(formatGwei(gasPrice)), - ethPrice: ethPriceInUsd, - ethTransferGas: Number(ethTransferGasCost), - erc20TransferGas: Number(erc20TransferGasCost), + gasPriceInGwei: formatGwei(gasPrice), + ethPrice: ethPriceInUsd?.toString(), + ethTransferGas: ethTransferGasCost.toString(), + erc20TransferGas: erc20TransferGasCost.toString(), }; } catch (e: unknown) { if (isNativeError(e)) { @@ -113,18 +105,6 @@ export class L1MetricsService { } } - /** - * Calculates the transaction value in USD based on the gas used, gas price, and ether price. - * Formula: (txGas * gasPriceInWei/1e18) * etherPrice - * @param txGas - The amount of gas used for the transaction. - * @param gasPrice - The price of gas in wei. - * @param etherPrice - The current price of ether in USD. - * @returns The transaction value in USD. - */ - private transactionInUsd(txGas: bigint, gasPriceInWei: bigint, etherPrice: number): number { - return Number(formatUnits(txGas * gasPriceInWei, ETHER_DECIMALS)) * etherPrice; - } - //TODO: Implement feeParams. async feeParams(_chainId: number): Promise<{ batchOverheadL1Gas: number; diff --git a/libs/metrics/src/types/gasInfo.type.ts b/libs/metrics/src/types/gasInfo.type.ts index 25e8e0b..d270e51 100644 --- a/libs/metrics/src/types/gasInfo.type.ts +++ b/libs/metrics/src/types/gasInfo.type.ts @@ -1,6 +1,6 @@ export type GasInfo = { - gasPriceInGwei: number; - ethPrice?: number; // USD - ethTransferGas: number; // units of gas - erc20TransferGas: number; // units of gas + gasPriceInGwei: string; + ethPrice?: string; // USD + ethTransferGas: string; // units of gas + erc20TransferGas: string; // units of gas }; diff --git a/libs/metrics/test/unit/l1/l1MetricsService.spec.ts b/libs/metrics/test/unit/l1/l1MetricsService.spec.ts index d9527b7..6ce1bfb 100644 --- a/libs/metrics/test/unit/l1/l1MetricsService.spec.ts +++ b/libs/metrics/test/unit/l1/l1MetricsService.spec.ts @@ -153,10 +153,10 @@ describe("L1MetricsService", () => { expect(mockGetTokenPrices).toHaveBeenCalledWith([ETH.coingeckoId]); expect(result).toEqual({ - gasPriceInGwei: 50, - ethPrice: 2000, - ethTransferGas: 21000, - erc20TransferGas: 65000, + gasPriceInGwei: "50", + ethPrice: "2000", + ethTransferGas: "21000", + erc20TransferGas: "65000", }); }); @@ -175,10 +175,10 @@ describe("L1MetricsService", () => { // Assertions expect(result).toEqual({ - gasPriceInGwei: 50, + gasPriceInGwei: "50", ethPrice: undefined, - ethTransferGas: 21000, - erc20TransferGas: 65000, + ethTransferGas: "21000", + erc20TransferGas: "65000", }); expect(mockEstimateGas).toHaveBeenCalledTimes(2); expect(mockEstimateGas).toHaveBeenNthCalledWith(1, {