From 20bb212e82623d116f3f60ebc135a7c7cee5efe7 Mon Sep 17 00:00:00 2001 From: Tomasz Kopacki Date: Tue, 24 Jun 2025 13:07:39 +0200 Subject: [PATCH 1/2] Revert "refactor(datasources): define ENSNamespaceId enum (#804)" This reverts commit 1b7737920bcb29ba1a025143ae137990d6d209c0. --- .changeset/icy-clubs-shave.md | 7 ------- .../indexing-status/view-models.test.ts | 7 +++---- apps/ensindexer/src/config/config.schema.ts | 6 +++--- apps/ensindexer/src/config/types.ts | 4 ++-- apps/ensindexer/src/lib/lib-config.ts | 3 +-- apps/ensindexer/src/lib/plugin-helpers.ts | 4 +--- .../basenames/lib/registrar-helpers.ts | 1 - .../lineanames/lib/registrar-helpers.ts | 1 - apps/ensindexer/test/dns-helpers.test.ts | 4 ++-- packages/datasources/src/lib/types.ts | 19 ++++++++++++------- 10 files changed, 24 insertions(+), 32 deletions(-) delete mode 100644 .changeset/icy-clubs-shave.md diff --git a/.changeset/icy-clubs-shave.md b/.changeset/icy-clubs-shave.md deleted file mode 100644 index 351600a0f..000000000 --- a/.changeset/icy-clubs-shave.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"@ensnode/datasources": minor -"ensindexer": minor -"ensadmin": minor ---- - -Replace inline string literals with the `ENSNamespaceId` enum values. diff --git a/apps/ensadmin/src/components/indexing-status/view-models.test.ts b/apps/ensadmin/src/components/indexing-status/view-models.test.ts index e23474f09..eedc21dd2 100644 --- a/apps/ensadmin/src/components/indexing-status/view-models.test.ts +++ b/apps/ensadmin/src/components/indexing-status/view-models.test.ts @@ -1,4 +1,3 @@ -import { ENSNamespaceId } from "@ensnode/datasources"; import { PluginName } from "@ensnode/ensnode-sdk"; import { fromUnixTime } from "date-fns"; import { base, mainnet } from "viem/chains"; @@ -33,12 +32,12 @@ describe("View Models", () => { const result = ensNodeEnvViewModel({ ACTIVE_PLUGINS: [PluginName.Subgraph], DATABASE_SCHEMA: "public", - NAMESPACE: ENSNamespaceId.EnsTestEnv, + NAMESPACE: "ens-test-env", }); expect(result).toEqual([ { label: "Active Plugins", value: [PluginName.Subgraph] }, - { label: "ENS Namespace", value: ENSNamespaceId.EnsTestEnv }, + { label: "ENS Namespace", value: "ens-test-env" }, { label: "Database Schema", value: "public" }, ]); }); @@ -51,7 +50,7 @@ describe("View Models", () => { const mainnetStatus = ensNodeNetworkStatus[mainnet.id]; const baseStatus = ensNodeNetworkStatus[base.id]; - expect(globalIndexingStatusViewModel(ensNodeNetworkStatus, ENSNamespaceId.Mainnet)).toEqual({ + expect(globalIndexingStatusViewModel(ensNodeNetworkStatus, "mainnet")).toEqual({ networkStatuses: [ { name: "Ethereum", diff --git a/apps/ensindexer/src/config/config.schema.ts b/apps/ensindexer/src/config/config.schema.ts index ff8e61ff9..0d64e029e 100644 --- a/apps/ensindexer/src/config/config.schema.ts +++ b/apps/ensindexer/src/config/config.schema.ts @@ -18,7 +18,7 @@ import { DEFAULT_RPC_RATE_LIMIT, } from "@/lib/lib-config"; import { uniq } from "@/lib/lib-helpers"; -import { ENSNamespaceId } from "@ensnode/datasources"; +import { ENSNamespaceIds } from "@ensnode/datasources"; import { PluginName } from "@ensnode/ensnode-sdk"; const chainIdSchema = z.number().int().min(1); @@ -56,9 +56,9 @@ const RpcConfigSchema = z.object({ }); const ENSNamespaceSchema = z - .enum(ENSNamespaceId, { + .enum(ENSNamespaceIds, { error: (issue) => { - return `Invalid NAMESPACE. Supported ENS namespaces are: ${Object.keys(ENSNamespaceId).join(", ")}`; + return `Invalid NAMESPACE. Supported ENS namespaces are: ${Object.keys(ENSNamespaceIds).join(", ")}`; }, }) .default(DEFAULT_NAMESPACE); diff --git a/apps/ensindexer/src/config/types.ts b/apps/ensindexer/src/config/types.ts index 939b1717d..5a03dddea 100644 --- a/apps/ensindexer/src/config/types.ts +++ b/apps/ensindexer/src/config/types.ts @@ -1,5 +1,5 @@ import { Blockrange } from "@/lib/types"; -import type { ENSNamespaceId } from "@ensnode/datasources"; +import type { ENSNamespaceId, ENSNamespaceIds } from "@ensnode/datasources"; import type { PluginName } from "@ensnode/ensnode-sdk"; /** @@ -32,7 +32,7 @@ export interface ENSIndexerConfig { /** * The ENS namespace that ENSNode operates in the context of, defaulting to 'mainnet' (DEFAULT_NAMESPACE). * - * See {@link ENSNamespaceId} for available namespace identifiers. + * See {@link ENSNamespaceIds} for available namespace identifiers. */ namespace: ENSNamespaceId; diff --git a/apps/ensindexer/src/lib/lib-config.ts b/apps/ensindexer/src/lib/lib-config.ts index 1ae48ab52..eb1a9496a 100644 --- a/apps/ensindexer/src/lib/lib-config.ts +++ b/apps/ensindexer/src/lib/lib-config.ts @@ -1,12 +1,11 @@ import type { ENSIndexerConfig, RpcConfigEnvironment } from "@/config/types"; -import { ENSNamespaceId } from "@ensnode/datasources"; export const DEFAULT_RPC_RATE_LIMIT = 500; export const DEFAULT_ENSADMIN_URL = "https://admin.ensnode.io"; export const DEFAULT_PORT = 42069; export const DEFAULT_HEAL_REVERSE_ADDRESSES = true; export const DEFAULT_INDEX_ADDITIONAL_RESOLVER_RECORDS = true; -export const DEFAULT_NAMESPACE = ENSNamespaceId.Mainnet; +export const DEFAULT_NAMESPACE = "mainnet"; /** * Extracts dynamic chain configuration from environment variables. diff --git a/apps/ensindexer/src/lib/plugin-helpers.ts b/apps/ensindexer/src/lib/plugin-helpers.ts index 724e80b99..10c51d5b9 100644 --- a/apps/ensindexer/src/lib/plugin-helpers.ts +++ b/apps/ensindexer/src/lib/plugin-helpers.ts @@ -205,9 +205,7 @@ export function parseLabelAndNameFromOnChainMetadata(uri: string): [Label, Name] * those plugins pass the typechecker. ENSNode ensures that non-active plugins are not executed, * so the issue of type/value mismatch does not occur during execution. */ -type ENSNamespaceFullyDefinedAtCompileTime = ReturnType< - typeof getENSNamespace ->; +type ENSNamespaceFullyDefinedAtCompileTime = ReturnType>; /** * Returns the ENSNamespace for the provided `namespaceId`, cast to ENSNamespaceFullyDefinedAtCompileTime. diff --git a/apps/ensindexer/src/plugins/basenames/lib/registrar-helpers.ts b/apps/ensindexer/src/plugins/basenames/lib/registrar-helpers.ts index 830e99aca..aa1ea52b4 100644 --- a/apps/ensindexer/src/plugins/basenames/lib/registrar-helpers.ts +++ b/apps/ensindexer/src/plugins/basenames/lib/registrar-helpers.ts @@ -17,7 +17,6 @@ export function getRegistrarManagedName(namespaceId: ENSNamespaceId): RegistrarM return "basetest.eth"; case "holesky": case "ens-test-env": - default: throw new Error( `No registrar managed name is known for the Basenames plugin within the "${namespaceId}" namespace.`, ); diff --git a/apps/ensindexer/src/plugins/lineanames/lib/registrar-helpers.ts b/apps/ensindexer/src/plugins/lineanames/lib/registrar-helpers.ts index d6ccebea5..5062596ec 100644 --- a/apps/ensindexer/src/plugins/lineanames/lib/registrar-helpers.ts +++ b/apps/ensindexer/src/plugins/lineanames/lib/registrar-helpers.ts @@ -17,7 +17,6 @@ export function getRegistrarManagedName(namespaceId: ENSNamespaceId): RegistrarM return "linea-sepolia.eth"; case "holesky": case "ens-test-env": - default: throw new Error( `No registrar managed name is known for the Linea Names plugin within the "${namespaceId}" namespace.`, ); diff --git a/apps/ensindexer/test/dns-helpers.test.ts b/apps/ensindexer/test/dns-helpers.test.ts index de5f81eb7..0f8178589 100644 --- a/apps/ensindexer/test/dns-helpers.test.ts +++ b/apps/ensindexer/test/dns-helpers.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import { decodeDNSPacketBytes, decodeTXTData, parseRRSet } from "@/lib/dns-helpers"; -import { ENSNamespaceId, getDatasource } from "@ensnode/datasources"; +import { getDatasource } from "@ensnode/datasources"; import { TxtAnswer } from "dns-packet"; import { decodeEventLog, hexToBytes, toBytes, zeroHash } from "viem"; @@ -10,7 +10,7 @@ import { decodeEventLog, hexToBytes, toBytes, zeroHash } from "viem"; const { args: { record }, } = decodeEventLog({ - abi: getDatasource(ENSNamespaceId.Mainnet, "threedns-base").contracts.Resolver.abi, + abi: getDatasource("mainnet", "threedns-base").contracts.Resolver.abi, topics: [ "0xaaac3b4b3e6807b5b4585562beabaa2de9bd07db514a1eba2c11d1af5b9d9dc7", "0x6470e2677db6a5bb6c69e51fce7271aeeb5f2808ea7dfdf34b703749555b3e10", diff --git a/packages/datasources/src/lib/types.ts b/packages/datasources/src/lib/types.ts index 639ba5686..93fc7207e 100644 --- a/packages/datasources/src/lib/types.ts +++ b/packages/datasources/src/lib/types.ts @@ -1,7 +1,7 @@ import type { Abi, Address, Chain } from "viem"; /** - * ENSNamespaceId enum encodes the set of identifiers for well-known ENS namespaces. + * ENSNamespaceIds encodes the set of identifiers for well-known ENS namespaces. * * Each ENS namespace is a single, unified set of ENS names with a distinct onchain root * Registry (the ensroot Datasource) and the capability of spanning from that root Registry across @@ -26,12 +26,17 @@ import type { Abi, Address, Chain } from "viem"; * protocol changes, running deterministic test suites, and local development. * https://github.com/ensdomains/ens-test-env */ -export enum ENSNamespaceId { - Mainnet = "mainnet", - Sepolia = "sepolia", - Holesky = "holesky", - EnsTestEnv = "ens-test-env", -} +export const ENSNamespaceIds = { + Mainnet: "mainnet", + Sepolia: "sepolia", + Holesky: "holesky", + EnsTestEnv: "ens-test-env", +} as const; + +/** + * ENSNamespaceId is the derived string union of possible ENS namespace identifiers. + */ +export type ENSNamespaceId = (typeof ENSNamespaceIds)[keyof typeof ENSNamespaceIds]; /** * A Datasource describes a set of contracts on a given chain that interact with the ENS protocol. From ec8f7c464c8ecf31af869bb63c882a6dc959dafa Mon Sep 17 00:00:00 2001 From: Tomasz Kopacki Date: Tue, 24 Jun 2025 13:15:10 +0200 Subject: [PATCH 2/2] use named reference for `DEFAULT_NAMESPACE` --- apps/ensindexer/src/lib/lib-config.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/ensindexer/src/lib/lib-config.ts b/apps/ensindexer/src/lib/lib-config.ts index eb1a9496a..70590deed 100644 --- a/apps/ensindexer/src/lib/lib-config.ts +++ b/apps/ensindexer/src/lib/lib-config.ts @@ -1,11 +1,12 @@ import type { ENSIndexerConfig, RpcConfigEnvironment } from "@/config/types"; +import { ENSNamespaceIds } from "@ensnode/datasources"; export const DEFAULT_RPC_RATE_LIMIT = 500; export const DEFAULT_ENSADMIN_URL = "https://admin.ensnode.io"; export const DEFAULT_PORT = 42069; export const DEFAULT_HEAL_REVERSE_ADDRESSES = true; export const DEFAULT_INDEX_ADDITIONAL_RESOLVER_RECORDS = true; -export const DEFAULT_NAMESPACE = "mainnet"; +export const DEFAULT_NAMESPACE = ENSNamespaceIds.Mainnet; /** * Extracts dynamic chain configuration from environment variables.