Skip to content

Commit

Permalink
fix: delete unused function and update return types
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Aug 6, 2024
1 parent 27a2ea0 commit 865eca3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
30 changes: 5 additions & 25 deletions libs/metrics/src/l1/l1MetricsService.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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.
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions libs/metrics/src/types/gasInfo.type.ts
Original file line number Diff line number Diff line change
@@ -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
};
14 changes: 7 additions & 7 deletions libs/metrics/test/unit/l1/l1MetricsService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
});

Expand All @@ -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, {
Expand Down

0 comments on commit 865eca3

Please sign in to comment.