diff --git a/packages/blocknumber/src/providers/evmBlockNumberProvider.ts b/packages/blocknumber/src/providers/evmBlockNumberProvider.ts index ae7a652..b986625 100644 --- a/packages/blocknumber/src/providers/evmBlockNumberProvider.ts +++ b/packages/blocknumber/src/providers/evmBlockNumberProvider.ts @@ -9,7 +9,6 @@ import { UnsupportedBlockNumber, UnsupportedBlockTimestamps, } from "../exceptions/index.js"; -import logger from "../utils/logger.js"; import { BlockNumberProvider } from "./blockNumberProvider.js"; const BINARY_SEARCH_BLOCKS_LOOKBACK = 10_000n; @@ -201,7 +200,7 @@ export class EvmBlockNumberProvider implements BlockNumberProvider { if (low > high) throw new UnexpectedSearchRange(low, high); - logger.debug(`Starting block binary search for timestamp ${timestamp}...`); + this.logger.debug(`Starting block binary search for timestamp ${timestamp}...`); while (low <= high) { currentBlockNumber = (high + low) / 2n; @@ -209,7 +208,7 @@ export class EvmBlockNumberProvider implements BlockNumberProvider { const currentBlock = await this.client.getBlock({ blockNumber: currentBlockNumber }); const nextBlock = await this.client.getBlock({ blockNumber: currentBlockNumber + 1n }); - logger.debug( + this.logger.debug( `Analyzing block number #${currentBlock.number} with timestamp ${currentBlock.timestamp}`, ); @@ -223,7 +222,7 @@ export class EvmBlockNumberProvider implements BlockNumberProvider { currentBlock.timestamp <= timestamp && nextBlock.timestamp > timestamp; if (blockContainsTimestamp) { - logger.debug(`Block #${currentBlock.number} contains timestamp.`); + this.logger.debug(`Block #${currentBlock.number} contains timestamp.`); return currentBlock.number; } else if (currentBlock.timestamp <= timestamp) { diff --git a/packages/blocknumber/src/utils/index.ts b/packages/blocknumber/src/utils/index.ts index 1c13af1..112754c 100644 --- a/packages/blocknumber/src/utils/index.ts +++ b/packages/blocknumber/src/utils/index.ts @@ -1,2 +1 @@ export * from "./caip/caip2.js"; -export * from "./logger.js"; diff --git a/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts b/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts index e2ed814..41f01c3 100644 --- a/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts +++ b/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts @@ -1,3 +1,4 @@ +import { Logger } from "@ebo-agent/shared"; import { Block, createPublicClient, GetBlockParameters, http } from "viem"; import { mainnet } from "viem/chains"; import { describe, expect, it, vi } from "vitest"; @@ -21,7 +22,7 @@ describe("EvmBlockNumberProvider", () => { const endTimestamp = Date.UTC(2024, 1, 11, 0, 0, 0, 0); const rpcProvider = mockRpcProvider(blockNumber, startTimestamp, endTimestamp); - evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig); + evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger); const day5 = Date.UTC(2024, 1, 5, 2, 0, 0, 0); const epochBlockNumber = await evmProvider.getEpochBlockNumber(day5); @@ -35,7 +36,7 @@ describe("EvmBlockNumberProvider", () => { const endTimestamp = Date.UTC(2024, 1, 1, 0, 0, 11, 0); const rpcProvider = mockRpcProvider(lastBlockNumber, startTimestamp, endTimestamp); - evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig); + evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger); const exactDay5 = Date.UTC(2024, 1, 1, 0, 0, 5, 0); const epochBlockNumber = await evmProvider.getEpochBlockNumber(exactDay5); @@ -49,7 +50,7 @@ describe("EvmBlockNumberProvider", () => { const endTimestamp = Date.UTC(2024, 1, 1, 0, 0, 11, 0); const rpcProvider = mockRpcProvider(lastBlockNumber, startTimestamp, endTimestamp); - evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig); + evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger); const futureTimestamp = Date.UTC(2025, 1, 1, 0, 0, 0, 0); @@ -64,7 +65,7 @@ describe("EvmBlockNumberProvider", () => { const endTimestamp = Date.UTC(2024, 1, 1, 0, 0, 11, 0); const rpcProvider = mockRpcProvider(lastBlockNumber, startTimestamp, endTimestamp); - evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig); + evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger); const futureTimestamp = Date.UTC(1970, 1, 1, 0, 0, 0, 0); @@ -84,7 +85,7 @@ describe("EvmBlockNumberProvider", () => { { number: 4n, timestamp: afterTimestamp }, ]); - evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig); + evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger); expect(evmProvider.getEpochBlockNumber(Number(timestamp))).rejects.toBeInstanceOf( UnsupportedBlockTimestamps, @@ -97,7 +98,7 @@ describe("EvmBlockNumberProvider", () => { { number: null, timestamp: BigInt(timestamp) }, ]); - evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig); + evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger); expect(evmProvider.getEpochBlockNumber(Number(timestamp))).rejects.toBeInstanceOf( UnsupportedBlockNumber, @@ -109,7 +110,7 @@ describe("EvmBlockNumberProvider", () => { client.getBlock = vi.fn().mockRejectedValue(null); - evmProvider = new EvmBlockNumberProvider(client, searchConfig); + evmProvider = new EvmBlockNumberProvider(client, searchConfig, logger); const timestamp = Date.UTC(2024, 1, 1, 0, 0, 0, 0); expect(evmProvider.getEpochBlockNumber(timestamp)).rejects.toBeDefined();