Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/four-doodles-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ensnode/datasources": minor
"ensindexer": minor
---

Replace inline string literals with the `DatasourceName` enum values.
17 changes: 9 additions & 8 deletions apps/ensindexer/src/plugins/basenames/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* The Basenames plugin describes indexing behavior for the Basenames ENS Datasource, leveraging
* the shared Subgraph-compatible indexing logic.
*/
import { DatasourceNames } from "@ensnode/datasources";

import { DatasourceName } from "@ensnode/datasources";
import { PluginName } from "@ensnode/ensnode-sdk";
import { createConfig } from "ponder";

Expand All @@ -19,16 +20,16 @@ import {
const pluginName = PluginName.Basenames;

// Define the Datasources required by the plugin
const requiredDatasources = [DatasourceNames.Basenames];
const requiredDatasources = [DatasourceName.Basenames];

// construct a unique contract namespace for this plugin
// Construct a unique plugin namespace to wrap contract names
const pluginNamespace = makePluginNamespace(pluginName);

// config object factory used to derive PluginConfig type
function createPonderConfig(config: ENSIndexerConfig) {
const { chain, contracts } = getDatasourceAsFullyDefinedAtCompileTime(
config.namespace,
DatasourceNames.Basenames,
DatasourceName.Basenames,
);

return createConfig({
Expand Down Expand Up @@ -58,7 +59,7 @@ function createPonderConfig(config: ENSIndexerConfig) {
});
}

// implicitly define the type returned by createPonderConfig
// Implicitly define the type returned by createPonderConfig
type PonderConfig = ReturnType<typeof createPonderConfig>;

export default {
Expand All @@ -76,9 +77,9 @@ export default {
}),

/**
* Load the plugin configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the plugin configuration
* is only built when the plugin is activated.
* Create the ponder configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the ponder configuration
* is only created for this plugin when it is activated.
*/
createPonderConfig,

Expand Down
24 changes: 12 additions & 12 deletions apps/ensindexer/src/plugins/lineanames/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* The Lineanames plugin describes indexing behavior for the Lineanames ENS Datasource, leveraging
* the shared Subgraph-compatible indexing logic.
*/
import { DatasourceNames } from "@ensnode/datasources";

import { DatasourceName } from "@ensnode/datasources";
import { PluginName } from "@ensnode/ensnode-sdk";
import { createConfig } from "ponder";

Expand All @@ -18,18 +19,17 @@ import {

const pluginName = PluginName.Lineanames;

// enlist datasources used within createPonderConfig function
// useful for config validation
const requiredDatasources = [DatasourceNames.Lineanames];
// Define the Datasources required by the plugin
const requiredDatasources = [DatasourceName.Lineanames];

// construct a unique contract namespace for this plugin
// Construct a unique plugin namespace to wrap contract names
const pluginNamespace = makePluginNamespace(pluginName);

// config object factory used to derive PluginConfig type
function createPonderConfig(config: ENSIndexerConfig) {
const { chain, contracts } = getDatasourceAsFullyDefinedAtCompileTime(
config.namespace,
DatasourceNames.Lineanames,
DatasourceName.Lineanames,
);

return createConfig({
Expand Down Expand Up @@ -59,7 +59,7 @@ function createPonderConfig(config: ENSIndexerConfig) {
});
}

// construct a specific type for plugin configuration
// Implicitly define the type returned by createPonderConfig
type PonderConfig = ReturnType<typeof createPonderConfig>;

export default {
Expand All @@ -78,15 +78,15 @@ export default {
}),

/**
* Load the plugin configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the plugin configuration
* is only built when the plugin is activated.
* Create the ponder configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the ponder configuration
* is only created for this plugin when it is activated.
*/
createPonderConfig,

/** The plugin name, used for identification */
/** The unique plugin name */
pluginName,

/** A list of required datasources for the plugin */
/** The plugin's required Datasources */
requiredDatasources,
} as const satisfies ENSIndexerPlugin<PluginName.Lineanames, PonderConfig>;
24 changes: 12 additions & 12 deletions apps/ensindexer/src/plugins/subgraph/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* The Subgraph plugin describes indexing behavior for the 'Root' Datasource, in alignment with the
* legacy ENS Subgraph indexing logic.
*/
import { DatasourceNames } from "@ensnode/datasources";

import { DatasourceName } from "@ensnode/datasources";
import { PluginName } from "@ensnode/ensnode-sdk";
import { createConfig } from "ponder";

Expand All @@ -18,18 +19,17 @@ import {

const pluginName = PluginName.Subgraph;

// enlist datasources used within createPonderConfig function
// useful for config validation
const requiredDatasources = [DatasourceNames.ENSRoot];
// Define the Datasources required by the plugin
const requiredDatasources = [DatasourceName.ENSRoot];

// construct a unique contract namespace for this plugin
// Construct a unique plugin namespace to wrap contract names
const pluginNamespace = makePluginNamespace(pluginName);

// config object factory used to derive PluginConfig type
function createPonderConfig(config: ENSIndexerConfig) {
const { chain, contracts } = getDatasourceAsFullyDefinedAtCompileTime(
config.namespace,
DatasourceNames.ENSRoot,
DatasourceName.ENSRoot,
);

return createConfig({
Expand Down Expand Up @@ -67,7 +67,7 @@ function createPonderConfig(config: ENSIndexerConfig) {
});
}

// construct a specific type for plugin configuration
// Implicitly define the type returned by createPluginConfig
type PonderConfig = ReturnType<typeof createPonderConfig>;

export default {
Expand All @@ -86,15 +86,15 @@ export default {
}),

/**
* Load the plugin configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the plugin configuration
* is only built when the plugin is activated.
* Create the ponder configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the ponder configuration
* is only created for this plugin when it is activated.
*/
createPonderConfig,

/** The plugin name, used for identification */
/** The unique plugin name */
pluginName,

/** A list of required datasources for the plugin */
/** The plugin's required Datasources */
requiredDatasources,
} as const satisfies ENSIndexerPlugin<PluginName.Subgraph, PonderConfig>;
26 changes: 13 additions & 13 deletions apps/ensindexer/src/plugins/threedns/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* The ThreeDNS plugin describes indexing behavior for 3DNSToken on both Optimism and Base.
*/
import { DatasourceNames } from "@ensnode/datasources";

import { DatasourceName } from "@ensnode/datasources";
import { PluginName } from "@ensnode/ensnode-sdk";
import { createConfig } from "ponder";

Expand All @@ -17,21 +18,20 @@ import {

const pluginName = PluginName.ThreeDNS;

// enlist datasources used within createPonderConfig function
// useful for config validation
const requiredDatasources = [DatasourceNames.ThreeDNSOptimism, DatasourceNames.ThreeDNSBase];
// Define the Datasources required by the plugin
const requiredDatasources = [DatasourceName.ThreeDNSOptimism, DatasourceName.ThreeDNSBase];

// construct a unique contract namespace for this plugin
// Construct a unique plugin namespace to wrap contract names
const pluginNamespace = makePluginNamespace(pluginName);

// config object factory used to derive PluginConfig type
function createPonderConfig(config: ENSIndexerConfig) {
const { chain: optimism, contracts: optimismContracts } =
getDatasourceAsFullyDefinedAtCompileTime(config.namespace, DatasourceNames.ThreeDNSOptimism);
getDatasourceAsFullyDefinedAtCompileTime(config.namespace, DatasourceName.ThreeDNSOptimism);

const { chain: base, contracts: baseContracts } = getDatasourceAsFullyDefinedAtCompileTime(
config.namespace,
DatasourceNames.ThreeDNSBase,
DatasourceName.ThreeDNSBase,
);

return createConfig({
Expand All @@ -58,7 +58,7 @@ function createPonderConfig(config: ENSIndexerConfig) {
});
}

// construct a specific type for plugin configuration
// Implicitly define the type returned by createPluginConfig
type PonderConfig = ReturnType<typeof createPonderConfig>;

export default {
Expand All @@ -72,15 +72,15 @@ export default {
}),

/**
* Load the plugin configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the plugin configuration
* is only built when the plugin is activated.
* Create the ponder configuration lazily to prevent premature execution of
* nested factory functions, i.e. to ensure that the ponder configuration
* is only created for this plugin when it is activated.
*/
createPonderConfig,

/** The plugin name, used for identification */
/** The unique plugin name */
pluginName,

/** A list of required datasources for the plugin */
/** The plugin's required Datasources */
requiredDatasources,
} as const satisfies ENSIndexerPlugin<PluginName.ThreeDNS, PonderConfig>;
4 changes: 2 additions & 2 deletions apps/ensindexer/test/dns-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -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 { DatasourceName, ENSNamespaceId, getDatasource } from "@ensnode/datasources";
import { TxtAnswer } from "dns-packet";
import { decodeEventLog, hexToBytes, toBytes, zeroHash } from "viem";

Expand All @@ -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(ENSNamespaceId.Mainnet, DatasourceName.ThreeDNSBase).contracts.Resolver.abi,
topics: [
"0xaaac3b4b3e6807b5b4585562beabaa2de9bd07db514a1eba2c11d1af5b9d9dc7",
"0x6470e2677db6a5bb6c69e51fce7271aeeb5f2808ea7dfdf34b703749555b3e10",
Expand Down
4 changes: 2 additions & 2 deletions packages/datasources/src/ens-test-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Address } from "viem";
import { anvil } from "viem/chains";

import { ResolverConfig } from "./lib/resolver";
import { DatasourceNames, type ENSNamespace } from "./lib/types";
import { DatasourceName, type ENSNamespace } from "./lib/types";

// ABIs for ENSRoot Datasource
import { BaseRegistrar as root_BaseRegistrar } from "./abis/root/BaseRegistrar";
Expand Down Expand Up @@ -43,7 +43,7 @@ export default {
* Addresses and Start Blocks from ens-test-env
* https://github.com/ensdomains/ens-test-env/
*/
[DatasourceNames.ENSRoot]: {
[DatasourceName.ENSRoot]: {
// ens-test-env runs on a local Anvil chain with id 1337
chain: { ...anvil, id: 1337 },
contracts: {
Expand Down
4 changes: 2 additions & 2 deletions packages/datasources/src/holesky.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { holesky } from "viem/chains";

import { ResolverConfig } from "./lib/resolver";
import { DatasourceNames, type ENSNamespace } from "./lib/types";
import { DatasourceName, type ENSNamespace } from "./lib/types";

// ABIs for ENSRoot Datasource
import { BaseRegistrar as root_BaseRegistrar } from "./abis/root/BaseRegistrar";
Expand All @@ -20,7 +20,7 @@ export default {
* Addresses and Start Blocks from ENS Holesky Subgraph Manifest
* https://ipfs.io/ipfs/Qmd94vseLpkUrSFvJ3GuPubJSyHz8ornhNrwEAt6pjcbex
*/
[DatasourceNames.ENSRoot]: {
[DatasourceName.ENSRoot]: {
chain: holesky,
contracts: {
RegistryOld: {
Expand Down
4 changes: 2 additions & 2 deletions packages/datasources/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DatasourceNames, ENSNamespace, ENSNamespaceId } from "./lib/types";
import { DatasourceName, ENSNamespace, ENSNamespaceId } from "./lib/types";

import ensTestEnv from "./ens-test-env";
import holesky from "./holesky";
Expand Down Expand Up @@ -49,4 +49,4 @@ export const getDatasource = <
* @returns the chain ID that hosts the ENS Root
*/
export const getENSRootChainId = (namespaceId: ENSNamespaceId) =>
getDatasource(namespaceId, DatasourceNames.ENSRoot).chain.id;
getDatasource(namespaceId, DatasourceName.ENSRoot).chain.id;
20 changes: 9 additions & 11 deletions packages/datasources/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ export interface Datasource {
/**
* DatasourceNames encodes a unique id for each known Datasource.
*/
export const DatasourceNames = {
ENSRoot: "ensroot",
Basenames: "basenames",
Lineanames: "lineanames",
ThreeDNSOptimism: "threedns-optimism",
ThreeDNSBase: "threedns-base",
} as const;

export type DatasourceName = (typeof DatasourceNames)[keyof typeof DatasourceNames];
export enum DatasourceName {
ENSRoot = "ensroot",
Basenames = "basenames",
Lineanames = "lineanames",
ThreeDNSOptimism = "threedns-optimism",
ThreeDNSBase = "threedns-base",
}

/**
* EventFilter specifies a given event's name and arguments to filter that event by.
Expand Down Expand Up @@ -96,5 +94,5 @@ export type ContractConfig =
* within the ENSNamespace are optional.
*/
export type ENSNamespace = {
[DatasourceNames.ENSRoot]: Datasource;
} & Partial<Record<Exclude<DatasourceName, "ensroot">, Datasource>>;
[DatasourceName.ENSRoot]: Datasource;
} & Partial<Record<Exclude<DatasourceName, DatasourceName.ENSRoot>, Datasource>>;
Loading