diff --git a/packages/blocknumber/src/services/blockNumberService.ts b/packages/blocknumber/src/services/blockNumberService.ts index da11eba..8088cfe 100644 --- a/packages/blocknumber/src/services/blockNumberService.ts +++ b/packages/blocknumber/src/services/blockNumberService.ts @@ -1,3 +1,4 @@ +import { Logger, supportedChains } from "@ebo-agent/shared"; import { createPublicClient, fallback, @@ -50,9 +51,12 @@ export class BlockNumberService { private buildBlockNumberProviders(chainRpcUrls: Map) { if (chainRpcUrls.size == 0) throw new EmptyRpcUrls(); + const supportedChainIds = this.getSupportedChainIds(supportedChains); const providers = new Map(); for (const [chainId, urls] of chainRpcUrls) { + if (!supportedChainIds.includes(chainId)) throw new UnsupportedChain(chainId); + const client = createPublicClient({ transport: fallback(urls.map((url) => http(url))), }); @@ -67,6 +71,14 @@ export class BlockNumberService { return providers; } + private getSupportedChainIds(chainsConfig: typeof supportedChains) { + const namespacesChains = Object.values(chainsConfig); + + return namespacesChains.reduce((acc, namespaceChains) => { + return [...acc, ...Object.values(namespaceChains.chains)]; + }, [] as string[]); + } + public static buildProvider( chainId: Caip2ChainId, client: PublicClient>, @@ -74,8 +86,12 @@ export class BlockNumberService { const chainNamespace = Caip2.getNamespace(chainId); switch (chainNamespace) { - case "eip155": - return new EvmBlockNumberProvider(client, DEFAULT_PROVIDER_CONFIG); + case supportedChains.evm.namespace: + return new EvmBlockNumberProvider( + client, + DEFAULT_PROVIDER_CONFIG, + Logger.getInstance(), // Should we drop this arg? + ); default: throw new UnsupportedChain(chainId); diff --git a/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts b/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts index 41f01c3..5bf18fd 100644 --- a/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts +++ b/packages/blocknumber/test/providers/evmBlockNumberProvider.spec.ts @@ -14,6 +14,7 @@ import { EvmBlockNumberProvider } from "../../src/providers/evmBlockNumberProvid describe("EvmBlockNumberProvider", () => { describe("getEpochBlockNumber", () => { const searchConfig = { blocksLookback: 2n, deltaMultiplier: 2n }; + const logger = Logger.getInstance(); let evmProvider: EvmBlockNumberProvider; it("returns the first of two consecutive blocks when their timestamp contains the searched timestamp", async () => { diff --git a/packages/shared/src/constants.ts b/packages/shared/src/constants.ts index e69de29..2c7074f 100644 --- a/packages/shared/src/constants.ts +++ b/packages/shared/src/constants.ts @@ -0,0 +1,10 @@ +export const supportedChains = { + evm: { + namespace: "eip155", + chains: { + ethereum: "eip155:1", + polygon: "eip155:137", + arbitrum: "eip155:42161", + }, + }, +} as const;