Skip to content

Transitioning to use AccountId as the referrer identifier#2038

Open
Goader wants to merge 13 commits intomainfrom
task/enhance-referrers-data-model
Open

Transitioning to use AccountId as the referrer identifier#2038
Goader wants to merge 13 commits intomainfrom
task/enhance-referrers-data-model

Conversation

@Goader
Copy link
Copy Markdown
Member

@Goader Goader commented May 1, 2026

Transitioning to use AccountId as the referrer identifier

closes: #1956

Summary

  • Transitioned to use AccountId or AccountIdString for keys
  • Fixed the bug in the Zod schema in ensnode-sdk

Why


Testing

  • Automatic CI and manual validation
  • New tests

Notes for Reviewer

  • The bug in ensnode-sdk

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

@Goader Goader self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 15:43
@Goader Goader requested a review from a team as a code owner May 1, 2026 15:43
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 1, 2026

🦋 Changeset detected

Latest commit: c888b6d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@namehash/ens-referrals Major
ensapi Major
@ensnode/ensnode-sdk Major
ensadmin Major
ensindexer Major
ensrainbow Major
fallback-ensapi Major
@ensnode/ensdb-sdk Major
@ensnode/ensnode-react Major
@ensnode/ensrainbow-sdk Major
@ensnode/integration-test-env Major
@namehash/namehash-ui Major
@docs/ensnode Major
@docs/ensrainbow Major
enssdk Major
enscli Major
enskit Major
ensskills Major
@ensnode/datasources Major
@ensnode/ponder-sdk Major
@ensnode/ponder-subgraph Major
@ensnode/shared-configs Major
@ensnode/ensindexer-perf-testing Major
@ensnode/enskit-react-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
admin.ensnode.io Skipped Skipped May 1, 2026 3:57pm
ensnode.io Skipped Skipped May 1, 2026 3:57pm
ensrainbow.io Skipped Skipped May 1, 2026 3:57pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bd034d3f-b303-4234-9acf-a60200a0648f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/enhance-referrers-data-model

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Greptile Summary

This PR transitions the referrer identifier from a bare Address (EVM address string) to an AccountId (CAIP-10 { chainId, address } object) throughout the ens-referrals package and ensapi app, updating domain types, leaderboard map keys, API route params, Zod schemas, tests, and the OpenAPI spec. It also fixes a pre-existing bug in makeAccountIdStringSchema where an invalid CAIP-10 string caused new CaipAccountId(v) to throw synchronously inside a transform, bypassing safeParse error handling.

Confidence Score: 5/5

Safe to merge — changes are consistent and well-tested with no regressions introduced.

All type transitions from Address to AccountId are applied consistently across domain types, schemas, map keys, API routes, tests, and OpenAPI docs. The Zod bug fix is correct (try/catch + ctx.addIssue + z.NEVER). No P1 or P0 issues found; the only mild pre-existing concern (DB address cast via as NormalizedAddress) was present before this PR and is not a regression.

apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts — the as NormalizedAddress cast on raw DB strings is worth a follow-up to add runtime normalization, but is pre-existing.

Important Files Changed

Filename Overview
packages/ensnode-sdk/src/shared/zod-schemas.ts Fixes makeAccountIdStringSchema to catch the synchronous CaipAccountId constructor error and surface it as a Zod issue via ctx.addIssue + z.NEVER instead of letting it propagate through safeParse.
packages/ensnode-sdk/src/shared/account-id.test.ts New tests verifying that makeAccountIdStringSchema.safeParse never throws for malformed/undefined inputs and that parseAccountId raises a clean error for invalid CAIP-10 strings.
apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts Constructs AccountId objects from raw DB record.referrer strings + rules.subregistryId.chainId in both getReferrerMetrics and getReferralEvents. The address is still cast with as NormalizedAddress without runtime normalization, matching the pre-existing pattern.
apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.routes.ts Replaces referrerAddressSchema (plain EVM address) with referrerAccountIdSchema (CAIP-10 AccountId string parsed by makeAccountIdStringSchema). Route description updated accordingly.
packages/ens-referrals/src/referrer-metrics.ts Updated ReferrerMetrics.referrer type from Address to AccountId; buildReferrerMetrics and validateReferrerMetrics now use makeAccountIdSchema.
packages/ens-referrals/src/award-models/rev-share-cap/referral-event.ts Updated ReferralEvent.referrer type from Address to AccountId.
packages/ens-referrals/src/award-models/rev-share-cap/rules.ts Updated AdminActionDisqualification.referrer and AdminActionWarning.referrer types from Address to AccountId; duplicate-referrer check in adminActions now uses stringifyAccountId to produce stable string keys.
apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/mocks.ts All mock ReferrerMetrics entries and leaderboard map keys updated to AccountId / AccountIdString using new acct / acctKey helpers pinned to chainId=1.
packages/ens-referrals/src/client.ts Client now imports stringifyAccountId and encodes the referrer AccountId as a CAIP-10 string in the getReferrerMetricsEditions request URL.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Route as ensapi Route
    participant Schema as makeAccountIdStringSchema
    participant Handler as ensanalytics-api
    participant DB as database.ts

    Client->>Route: GET /referrer/eip155%3A1%3A0xabc...?editions=2025-12
    Route->>Schema: parse URL-decoded CAIP-10 string
    Schema->>Schema: new CaipAccountId(v) [try/catch → Zod issue on failure]
    Schema->>Schema: pipe through makeAccountIdSchema (normalize address)
    Schema-->>Route: AccountId { chainId: 1, address: "0xabc..." }
    Route->>Handler: { referrer: AccountId, editions: [...] }
    Handler->>DB: getReferrerMetrics(rules)
    DB->>DB: { chainId: rules.subregistryId.chainId, address: record.referrer }
    DB-->>Handler: ReferrerMetrics[] (referrer: AccountId)
    Handler-->>Client: JSON response (referrer serialized as AccountId object)
Loading

Reviews (2): Last reviewed commit: "fixture fix" | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Transitions ENSAnalytics/ENS Referrals referrer identification from bare EVM addresses to AccountId (CAIP-10), aligning domain models, API surface, client helpers, and OpenAPI docs; also fixes a Zod schema bug so invalid CAIP-10 strings surface as Zod issues instead of throwing.

Changes:

  • Replace NormalizedAddress referrer identifiers with AccountId/AccountIdString across @namehash/ens-referrals domain types and leaderboard maps.
  • Update ENSAnalytics v1 API route param to be a URL-encoded CAIP-10 string and update client + server parsing/serialization/tests accordingly.
  • Fix makeAccountIdStringSchema to report invalid CAIP-10 input via Zod issues (non-throwing safeParse) and add regression tests.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/ensnode-sdk/src/shared/zod-schemas.ts Make CAIP-10 parsing non-throwing by emitting Zod issues in transform.
packages/ensnode-sdk/src/shared/account-id.test.ts Add tests ensuring safeParse doesn’t throw and invalid CAIP-10 is surfaced cleanly.
packages/ens-referrals/src/referrer-metrics.ts Switch referrer field/type + validation from NormalizedAddress to AccountId.
packages/ens-referrals/src/leaderboard-page.test.ts Update fixtures to use AccountId + AccountIdString keys.
packages/ens-referrals/src/edition-metrics.ts Use stringifyAccountId for referrer lookups into leaderboard maps.
packages/ens-referrals/src/client.ts Serialize AccountId into URL-encoded CAIP-10 for /referrer/{referrer} requests.
packages/ens-referrals/src/award-models/shared/rank.ts Deterministic tie-breaker now compares CAIP-10 strings derived from AccountId.
packages/ens-referrals/src/award-models/shared/leaderboard-page.ts Update sliceReferrers to accept maps keyed by AccountIdString.
packages/ens-referrals/src/award-models/rev-share-cap/rules.ts Replace address comparisons with accountIdEqual + dedupe via CAIP-10 string keys.
packages/ens-referrals/src/award-models/rev-share-cap/referral-event.ts Update ReferralEvent.referrer type to AccountId.
packages/ens-referrals/src/award-models/rev-share-cap/metrics.ts Replace referrer equality with accountIdEqual in rules/metrics consistency checks.
packages/ens-referrals/src/award-models/rev-share-cap/leaderboard.ts Key internal maps by CAIP-10 string; preserve AccountId in race state for output.
packages/ens-referrals/src/award-models/rev-share-cap/leaderboard.test.ts Update rev-share-cap leaderboard tests to use AccountId + CAIP-10 map keys.
packages/ens-referrals/src/award-models/rev-share-cap/edition-metrics.ts Documentation-only wording update (“referrer” vs “referrer address”).
packages/ens-referrals/src/award-models/rev-share-cap/api/zod-schemas.ts Update schemas to parse AccountId and compare with accountIdEqual; dedupe via CAIP-10 key.
packages/ens-referrals/src/award-models/rev-share-cap/accounting.ts Update accounting record referrer type to AccountId.
packages/ens-referrals/src/award-models/rev-share-cap/accounting.test.ts Update accounting tests for AccountId and CAIP-10 keyed maps.
packages/ens-referrals/src/award-models/pie-split/metrics.ts Update unranked builder signature/docs to take AccountId.
packages/ens-referrals/src/award-models/pie-split/leaderboard.ts Key leaderboard maps by CAIP-10 string produced from AccountId.
packages/ens-referrals/src/award-models/pie-split/edition-metrics.ts Documentation-only wording update (“referrer” vs “referrer address”).
packages/ens-referrals/src/award-models/pie-split/api/zod-schemas.ts Update API schemas to accept AccountId referrers.
packages/ens-referrals/src/api/zod-schemas.ts Change request schema referrer to parse CAIP-10 (via makeAccountIdStringSchema).
packages/ens-referrals/src/api/zod-schemas.test.ts Update tests/fixtures to use AccountId objects for referrers/admin actions.
packages/ens-referrals/src/api/types.ts Update API request typing to use AccountId for referrer.
docs/ensnode.io/ensapi-openapi.json Document /referrer/{referrer} as CAIP-10 string path param.
apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/mocks.ts Update server mocks to build AccountId objects and CAIP-10 keyed maps.
apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/format-accounting-csv.ts Serialize referrer as CAIP-10 string in CSV export.
apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts Wrap DB decodedReferrer with chainId into AccountId for metrics/events.
apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.ts Handler now treats route param as referrer (AccountId) rather than address string.
apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.test.ts Update API tests to URL-encode CAIP-10 referrer and assert AccountId shapes.
apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.routes.ts Update OpenAPI route param schema/description to CAIP-10 AccountId string.
.changeset/quiet-foxes-stumble.md Patch changeset for ensnode-sdk Zod fix.
.changeset/magical-hedgehog-jump.md Minor changeset for breaking-ish API/domain referrer identifier shift.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/ens-referrals/src/award-models/shared/rank.ts
Comment thread packages/ens-referrals/src/leaderboard-page.test.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/ens-referrals/src/leaderboard-page.test.ts (1)

33-166: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Keep each fixture key in sync with its referrer value.

Several Map<AccountIdString, ...> entries now use a different CAIP-10 key than the referrer stored in the value. The test still passes because it only checks size, but it no longer validates the new keying invariant. Please derive each key from the same AccountId you store in the value.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ens-referrals/src/leaderboard-page.test.ts` around lines 33 - 166,
The Map keys in the ReferrerLeaderboardPieSplit fixtures do not match the
referrer values (acctKey("...") vs referrer: acct("...")), breaking the
invariant that the key is derived from the stored AccountId; update each Map
entry so the key is derived from the same AccountId used in the value (e.g.,
assign the AccountId to a variable via acct("...") and call
acctKey(thatAccountId) for the Map key) for all entries in the
Map<AccountIdString, AwardedReferrerMetricsPieSplit> used by
buildReferrerLeaderboardPageContext.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/ens-referrals/src/leaderboard-page.test.ts`:
- Around line 33-166: The Map keys in the ReferrerLeaderboardPieSplit fixtures
do not match the referrer values (acctKey("...") vs referrer: acct("...")),
breaking the invariant that the key is derived from the stored AccountId; update
each Map entry so the key is derived from the same AccountId used in the value
(e.g., assign the AccountId to a variable via acct("...") and call
acctKey(thatAccountId) for the Map key) for all entries in the
Map<AccountIdString, AwardedReferrerMetricsPieSplit> used by
buildReferrerLeaderboardPageContext.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 028ced1d-b223-4611-b85a-2cb1ffb9b38a

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf0a7c and a39ae4d.

📒 Files selected for processing (33)
  • .changeset/magical-hedgehog-jump.md
  • .changeset/quiet-foxes-stumble.md
  • apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.routes.ts
  • apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.test.ts
  • apps/ensapi/src/handlers/ensanalytics/ensanalytics-api.ts
  • apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts
  • apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/format-accounting-csv.ts
  • apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/mocks.ts
  • docs/ensnode.io/ensapi-openapi.json
  • packages/ens-referrals/src/api/types.ts
  • packages/ens-referrals/src/api/zod-schemas.test.ts
  • packages/ens-referrals/src/api/zod-schemas.ts
  • packages/ens-referrals/src/award-models/pie-split/api/zod-schemas.ts
  • packages/ens-referrals/src/award-models/pie-split/edition-metrics.ts
  • packages/ens-referrals/src/award-models/pie-split/leaderboard.ts
  • packages/ens-referrals/src/award-models/pie-split/metrics.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/accounting.test.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/accounting.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/api/zod-schemas.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/edition-metrics.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/leaderboard.test.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/leaderboard.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/metrics.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/referral-event.ts
  • packages/ens-referrals/src/award-models/rev-share-cap/rules.ts
  • packages/ens-referrals/src/award-models/shared/leaderboard-page.ts
  • packages/ens-referrals/src/award-models/shared/rank.ts
  • packages/ens-referrals/src/client.ts
  • packages/ens-referrals/src/edition-metrics.ts
  • packages/ens-referrals/src/leaderboard-page.test.ts
  • packages/ens-referrals/src/referrer-metrics.ts
  • packages/ensnode-sdk/src/shared/account-id.test.ts
  • packages/ensnode-sdk/src/shared/zod-schemas.ts

@vercel vercel Bot temporarily deployed to Preview – ensnode.io May 1, 2026 15:57 Inactive
@vercel vercel Bot temporarily deployed to Preview – ensrainbow.io May 1, 2026 15:57 Inactive
@vercel vercel Bot temporarily deployed to Preview – admin.ensnode.io May 1, 2026 15:57 Inactive
Base automatically changed from feature/award-accounting to main May 6, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants