-
Notifications
You must be signed in to change notification settings - Fork 16
feat(ensindex): introduce registrars plugin
#1249
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4895125
feat(registrars): introduce db schema
tk-o daca767
Merge remote-tracking branch 'origin/main' into feat/1228-registrars-…
tk-o 094d17b
refactor(ensnode-schema): update registrars schema
tk-o 1bc51cf
Merge remote-tracking branch 'origin/main' into feat/1228-registrars-…
tk-o 52b1a44
feat(ensnode-sdk): improve shared modules
tk-o 6d0b858
feat(ensnode-sdk): create `registrars` module
tk-o f1fb889
feat(ensindexer): create `registrars` plugin
tk-o 71cc8e8
Merge remote-tracking branch 'origin/main' into feat/1228-registrars-…
tk-o 5de8777
feat(ensnode-sdk): create `datetime` module
tk-o 0de2587
feat(ensnode-schema): improve docs
tk-o 25e35b9
refactor(ensindexer): update registrars plugin
tk-o 24af62a
fix(ensnode-schema): drop unused index
tk-o 84df66d
refactor(ensindexer): rename event handlers for `registrars` plugin
tk-o d9d95db
Merge remote-tracking branch 'origin/main' into feat/1228-registrars-…
tk-o 8b27c16
apply pr feedback
tk-o 182c43b
docs(changeset): Introduces a new `registrars` plugin for tracking al…
tk-o 0b4b32b
apply pr feedback
tk-o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@ensnode/ensnode-schema": minor | ||
| "@ensnode/ensnode-sdk": minor | ||
| "ensindexer": minor | ||
| --- | ||
|
|
||
| Introduces a new `registrars` plugin for tracking all registrations and renewals for direct subnames of `eth`, `base.eth`, and `linea.eth`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # `registrars` plugin for ENSIndexer | ||
|
|
||
| This plugin enables tracking all registrations and renewals that ever happened for subregistries managing the following: | ||
| - direct subnames of the Ethnames registrar managed name (ex: `eth` for all namespaces). | ||
| - direct subnames of the Basenames registrar managed name (ex: for mainnet `base.eth` but varies for other namespaces). | ||
| - direct subnames of the Lineanames registrar managed name (ex: for mainnet `linea.eth` but varies for other namespaces). | ||
|
|
||
| Additionally indexes: | ||
| - All ENS Referrals (for Registrar Controllers supporting ENS Referral Programs). |
124 changes: 124 additions & 0 deletions
124
apps/ensindexer/src/plugins/registrars/basenames/handlers/Basenames_Registrar.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import config from "@/config"; | ||
|
|
||
| import { ponder } from "ponder:registry"; | ||
| import { namehash } from "viem/ens"; | ||
|
|
||
| import { DatasourceNames } from "@ensnode/datasources"; | ||
| import { | ||
| type BlockRef, | ||
| bigIntToNumber, | ||
| makeSubdomainNode, | ||
| PluginName, | ||
| type Subregistry, | ||
| } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import { getDatasourceContract } from "@/lib/datasource-helpers"; | ||
| import { namespaceContract } from "@/lib/plugin-helpers"; | ||
|
|
||
| import { | ||
| handleRegistrarEventRegistration, | ||
| handleRegistrarEventRenewal, | ||
| } from "../../shared/lib/registrar-events"; | ||
| import { upsertSubregistry } from "../../shared/lib/subregistry"; | ||
| import { getRegistrarManagedName, tokenIdToLabelHash } from "../lib/registrar-helpers"; | ||
|
|
||
| /** | ||
| * Registers event handlers with Ponder. | ||
| */ | ||
| export default function () { | ||
| const pluginName = PluginName.Registrars; | ||
| const parentNode = namehash(getRegistrarManagedName(config.namespace)); | ||
|
|
||
| const subregistryId = getDatasourceContract( | ||
| config.namespace, | ||
| DatasourceNames.Basenames, | ||
| "BaseRegistrar", | ||
| ); | ||
| const subregistry = { | ||
| subregistryId, | ||
| node: parentNode, | ||
| } satisfies Subregistry; | ||
|
|
||
| // support NameRegisteredWithRecord for BaseRegistrar as it used by Base's RegistrarControllers | ||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_BaseRegistrar:NameRegisteredWithRecord"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = tokenIdToLabelHash(event.args.id); | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const registrant = event.transaction.from; | ||
| const expiresAt = bigIntToNumber(event.args.expires); | ||
| const block = { | ||
| number: bigIntToNumber(event.block.number), | ||
| timestamp: bigIntToNumber(event.block.timestamp), | ||
| } satisfies BlockRef; | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await upsertSubregistry(context, subregistry); | ||
|
|
||
| await handleRegistrarEventRegistration(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| registrant, | ||
| expiresAt, | ||
| block, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_BaseRegistrar:NameRegistered"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = tokenIdToLabelHash(event.args.id); | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const registrant = event.transaction.from; | ||
| const expiresAt = bigIntToNumber(event.args.expires); | ||
| const block = { | ||
| number: bigIntToNumber(event.block.number), | ||
| timestamp: bigIntToNumber(event.block.timestamp), | ||
| } satisfies BlockRef; | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await upsertSubregistry(context, subregistry); | ||
|
|
||
| await handleRegistrarEventRegistration(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| registrant, | ||
| expiresAt, | ||
| block, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_BaseRegistrar:NameRenewed"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = tokenIdToLabelHash(event.args.id); | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const registrant = event.transaction.from; | ||
| const expiresAt = bigIntToNumber(event.args.expires); | ||
| const block = { | ||
| number: bigIntToNumber(event.block.number), | ||
| timestamp: bigIntToNumber(event.block.timestamp), | ||
| } satisfies BlockRef; | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await handleRegistrarEventRenewal(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| registrant, | ||
| expiresAt, | ||
| block, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
| } | ||
161 changes: 161 additions & 0 deletions
161
apps/ensindexer/src/plugins/registrars/basenames/handlers/Basenames_RegistrarController.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import config from "@/config"; | ||
|
|
||
| import { ponder } from "ponder:registry"; | ||
| import { namehash } from "viem/ens"; | ||
|
|
||
| import { DatasourceNames } from "@ensnode/datasources"; | ||
| import { | ||
| makeSubdomainNode, | ||
| PluginName, | ||
| type RegistrarActionPricingUnknown, | ||
| type RegistrarActionReferralNotApplicable, | ||
| } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import { getDatasourceContract } from "@/lib/datasource-helpers"; | ||
| import { namespaceContract } from "@/lib/plugin-helpers"; | ||
|
|
||
| import { handleRegistrarControllerEvent } from "../../shared/lib/registrar-controller-events"; | ||
| import { getRegistrarManagedName } from "../lib/registrar-helpers"; | ||
|
|
||
| /** | ||
| * Registers event handlers with Ponder. | ||
| */ | ||
| export default function () { | ||
| const pluginName = PluginName.Registrars; | ||
| const parentNode = namehash(getRegistrarManagedName(config.namespace)); | ||
|
|
||
| const subregistryId = getDatasourceContract( | ||
| config.namespace, | ||
| DatasourceNames.Basenames, | ||
| "BaseRegistrar", | ||
| ); | ||
|
|
||
| /** | ||
| * No Registrar Controller for Basenames implements premiums or | ||
tk-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * emits distinct baseCost or premium (as opposed to just a simple price) | ||
| * in events. | ||
| * | ||
| * TODO: [Index the pricing data for "logical registrar actions" for Basenames.](https://github.com/namehash/ensnode/issues/1256) | ||
| */ | ||
| const pricing = { | ||
| baseCost: null, | ||
| premium: null, | ||
| total: null, | ||
| } satisfies RegistrarActionPricingUnknown; | ||
|
|
||
| /** | ||
| * No Registrar Controller for Basenames implements referrals or | ||
| * emits a referrer in events. | ||
| */ | ||
| const referral = { | ||
| encodedReferrer: null, | ||
| decodedReferrer: null, | ||
| } satisfies RegistrarActionReferralNotApplicable; | ||
|
|
||
| /** | ||
| * Basenames_EARegistrarController Event Handlers | ||
| */ | ||
|
|
||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_EARegistrarController:NameRegistered"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = event.args.label; // this field is the labelhash, not the label | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await handleRegistrarControllerEvent(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| pricing, | ||
| referral, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| /** | ||
| * Basenames_RegistrarController Event Handlers | ||
| */ | ||
|
|
||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_RegistrarController:NameRegistered"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = event.args.label; // this field is the labelhash, not the label | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await handleRegistrarControllerEvent(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| pricing, | ||
| referral, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_RegistrarController:NameRenewed"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = event.args.label; // this field is the labelhash, not the label | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await handleRegistrarControllerEvent(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| pricing, | ||
| referral, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| /** | ||
| * Basenames_UpgradeableRegistrarController Event Handlers | ||
| */ | ||
|
|
||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_UpgradeableRegistrarController:NameRegistered"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = event.args.label; // this field is the labelhash, not the label | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await handleRegistrarControllerEvent(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| pricing, | ||
| referral, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| ponder.on( | ||
| namespaceContract(pluginName, "Basenames_UpgradeableRegistrarController:NameRenewed"), | ||
| async ({ context, event }) => { | ||
| const id = event.id; | ||
| const labelHash = event.args.label; // this field is the labelhash, not the label | ||
| const node = makeSubdomainNode(labelHash, parentNode); | ||
| const transactionHash = event.transaction.hash; | ||
|
|
||
| await handleRegistrarControllerEvent(context, { | ||
| id, | ||
| subregistryId, | ||
| node, | ||
| pricing, | ||
| referral, | ||
| transactionHash, | ||
| }); | ||
| }, | ||
| ); | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
apps/ensindexer/src/plugins/registrars/basenames/lib/registrar-helpers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import type { ENSNamespaceId } from "@ensnode/datasources"; | ||
| import { type LabelHash, uint256ToHex32 } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| import type { RegistrarManagedName } from "@/lib/types"; | ||
|
|
||
| /** | ||
| * When direct subnames of Basenames are registered through | ||
| * the Basenames RegistrarController contract, | ||
| * an ERC721 NFT is minted that tokenizes ownership of the registration. | ||
| * The minted NFT will be assigned a unique tokenId represented as | ||
| * uint256(labelhash(label)) where label is the direct subname of | ||
| * the Basename that was registered. | ||
| * https://github.com/base/basenames/blob/1b5c1ad/src/L2/RegistrarController.sol#L488 | ||
| */ | ||
| export function tokenIdToLabelHash(tokenId: bigint): LabelHash { | ||
| return uint256ToHex32(tokenId); | ||
| } | ||
|
|
||
| /** | ||
| * Get registrar managed name for `basenames` subregistry for selected ENS namespace. | ||
| * | ||
| * @param namespaceId | ||
| * @returns registrar managed name | ||
| * @throws an error when no registrar managed name could be returned | ||
| */ | ||
| export function getRegistrarManagedName(namespaceId: ENSNamespaceId): RegistrarManagedName { | ||
| switch (namespaceId) { | ||
| case "mainnet": | ||
| return "base.eth"; | ||
| case "sepolia": | ||
| return "basetest.eth"; | ||
| case "holesky": | ||
| case "ens-test-env": | ||
| throw new Error( | ||
| `No registrar managed name is known for the 'basenames' subregistry within the "${namespaceId}" namespace.`, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I note how we are building an object like this in several files. Should there be a ... satisfies X on each of these?
Appreciate if you can please update all the relevant files. Thanks