-
Notifications
You must be signed in to change notification settings - Fork 16
refactor: unified polymorphic domain + registry #1983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
db21e8e
a7e70bb
10e0307
0af2647
5418244
707f33f
8a7bca8
e57f87c
5534db0
2b3e296
d29a5fb
c38284f
a2434ec
e13da69
ef9f65a
9a3f33c
5c05677
3ae0993
0f34ce1
c37a9a4
9d59225
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ensapi": minor | ||
| --- | ||
|
|
||
| `Query.root` is now non-null and returns the namespace's Root Registry — preferring the ENSv2 Root Registry when defined, falling back to the ENSv1 Root Registry. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| "enssdk": minor | ||
| "@ensnode/ensdb-sdk": minor | ||
| "@ensnode/ensnode-sdk": minor | ||
| "ensindexer": minor | ||
| "ensapi": minor | ||
| --- | ||
|
|
||
| Unify `v1Domain` + `v2Domain` into a single polymorphic `domain` table discriminated by a `type` enum (`"ENSv1Domain"` | `"ENSv2Domain"`), and make Registry polymorphic across concrete ENSv1 (mainnet Registry, Basenames Registry, Lineanames Registry), ENSv1 Virtual (per-parent-domain virtual Registry managed by each ENSv1 domain that has children), and ENSv2 Registries. | ||
|
|
||
| ### Breaking schema + id format changes | ||
|
|
||
| - `ENSv1DomainId` is now CAIP-shaped: `${ENSv1RegistryId}/${node}` (was `Node`). Every ENSv1 Domain is addressable through a concrete Registry, so bare `node` values no longer identify a Domain by themselves. | ||
| - `RegistryId` is a union of `ENSv1RegistryId`, `ENSv1VirtualRegistryId`, and `ENSv2RegistryId`. New id constructors: `makeENSv1RegistryId`, `makeENSv2RegistryId`, `makeENSv1VirtualRegistryId`. `makeENSv1DomainId` now takes `(AccountId, Node)`. `makeRegistryId` is retained as a union-returning helper for callsites that can't narrow. | ||
| - `domains` table: replaces `v1_domains` + `v2_domains`. Adds `type`, nullable `tokenId` (non-null iff ENSv2), nullable `node` (non-null iff ENSv1), nullable `rootRegistryOwnerId` (v1 only). `parentId` removed; parent relationships flow through `registryCanonicalDomain` for both v1 and v2. | ||
| - `registries` table: adds `type` enum column and nullable `node` (non-null iff `ENSv1VirtualRegistry`). Unique `(chainId, address)` index becomes a plain index so virtual Registries can share their concrete parent's `(chainId, address)`. | ||
| - `registryCanonicalDomain.domainId` is typed as the unified `DomainId`. | ||
|
|
||
| ### GraphQL | ||
|
|
||
| - `Registry` becomes a GraphQL interface with `ENSv1Registry`, `ENSv1VirtualRegistry`, and `ENSv2Registry` implementations. `ENSv1VirtualRegistry` exposes `node: Node!`. | ||
| - `Domain` interface gains `parent: Domain` (resolved via the canonical-path dataloader); `ENSv1Domain` exposes `node: Node!` and `rootRegistryOwner`; `ENSv2Domain` exposes `tokenId`, `registry`, `subregistry`, `permissions`. | ||
| - `Query.registry(by: { contract })` now DB-looks up the concrete Registry by `(chainId, address, type IN (ENSv1Registry, ENSv2Registry))`. Virtual Registries are not addressable via `AccountId` alone. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { eq, isNotNull, isNull, or } from "drizzle-orm"; | ||
| import { eq } from "drizzle-orm"; | ||
|
|
||
| import { ensDb } from "@/lib/ensdb/singleton"; | ||
|
|
||
|
|
@@ -7,25 +7,13 @@ import { type BaseDomainSet, selectBase } from "./base-domain-set"; | |
|
|
||
| /** | ||
| * Filter a base domain set to only include Canonical Domains. | ||
| * | ||
| * All v1Domains are Canonical (registryId IS NULL). | ||
| * v2Domains are Canonical iff their registryId is reachable from the ENSv2 Root Registry. | ||
| * | ||
| * Uses LEFT JOIN with canonical registries CTE: v1 domains pass through (registryId IS NULL), | ||
| * v2 domains must match a canonical registry. | ||
| */ | ||
| export function filterByCanonical(base: BaseDomainSet) { | ||
| const canonicalRegistries = getCanonicalRegistriesCTE(); | ||
|
|
||
| return ensDb | ||
| .select(selectBase(base)) | ||
| .from(base) | ||
| .leftJoin(canonicalRegistries, eq(canonicalRegistries.id, base.registryId)) | ||
| .where( | ||
| or( | ||
| isNull(base.registryId), // v1 domains are always canonical | ||
| isNotNull(canonicalRegistries.id), // v2 domains must be in a canonical registry | ||
| ), | ||
| ) | ||
| .innerJoin(canonicalRegistries, eq(canonicalRegistries.id, base.registryId)) | ||
| .as("baseDomains"); | ||
| } | ||
|
Comment on lines
14
to
19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Uh oh!
There was an error while loading. Please reload this page.