Transitioning to use AccountId as the referrer identifier#2038
Transitioning to use AccountId as the referrer identifier#2038
AccountId as the referrer identifier#2038Conversation
🦋 Changeset detectedLatest commit: c888b6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR transitions the referrer identifier from a bare Confidence Score: 5/5Safe 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 apps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.ts — the Important Files Changed
Sequence DiagramsequenceDiagram
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)
Reviews (2): Last reviewed commit: "fixture fix" | Re-trigger Greptile |
There was a problem hiding this comment.
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
NormalizedAddressreferrer identifiers withAccountId/AccountIdStringacross@namehash/ens-referralsdomain 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
makeAccountIdStringSchemato report invalid CAIP-10 input via Zod issues (non-throwingsafeParse) 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.
There was a problem hiding this comment.
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 winKeep each fixture key in sync with its
referrervalue.Several
Map<AccountIdString, ...>entries now use a different CAIP-10 key than thereferrerstored in the value. The test still passes because it only checkssize, but it no longer validates the new keying invariant. Please derive each key from the sameAccountIdyou 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
📒 Files selected for processing (33)
.changeset/magical-hedgehog-jump.md.changeset/quiet-foxes-stumble.mdapps/ensapi/src/handlers/ensanalytics/ensanalytics-api.routes.tsapps/ensapi/src/handlers/ensanalytics/ensanalytics-api.test.tsapps/ensapi/src/handlers/ensanalytics/ensanalytics-api.tsapps/ensapi/src/lib/ensanalytics/referrer-leaderboard/database.tsapps/ensapi/src/lib/ensanalytics/referrer-leaderboard/format-accounting-csv.tsapps/ensapi/src/lib/ensanalytics/referrer-leaderboard/mocks.tsdocs/ensnode.io/ensapi-openapi.jsonpackages/ens-referrals/src/api/types.tspackages/ens-referrals/src/api/zod-schemas.test.tspackages/ens-referrals/src/api/zod-schemas.tspackages/ens-referrals/src/award-models/pie-split/api/zod-schemas.tspackages/ens-referrals/src/award-models/pie-split/edition-metrics.tspackages/ens-referrals/src/award-models/pie-split/leaderboard.tspackages/ens-referrals/src/award-models/pie-split/metrics.tspackages/ens-referrals/src/award-models/rev-share-cap/accounting.test.tspackages/ens-referrals/src/award-models/rev-share-cap/accounting.tspackages/ens-referrals/src/award-models/rev-share-cap/api/zod-schemas.tspackages/ens-referrals/src/award-models/rev-share-cap/edition-metrics.tspackages/ens-referrals/src/award-models/rev-share-cap/leaderboard.test.tspackages/ens-referrals/src/award-models/rev-share-cap/leaderboard.tspackages/ens-referrals/src/award-models/rev-share-cap/metrics.tspackages/ens-referrals/src/award-models/rev-share-cap/referral-event.tspackages/ens-referrals/src/award-models/rev-share-cap/rules.tspackages/ens-referrals/src/award-models/shared/leaderboard-page.tspackages/ens-referrals/src/award-models/shared/rank.tspackages/ens-referrals/src/client.tspackages/ens-referrals/src/edition-metrics.tspackages/ens-referrals/src/leaderboard-page.test.tspackages/ens-referrals/src/referrer-metrics.tspackages/ensnode-sdk/src/shared/account-id.test.tspackages/ensnode-sdk/src/shared/zod-schemas.ts
Transitioning to use
AccountIdas the referrer identifiercloses: #1956
Summary
AccountIdorAccountIdStringfor keysensnode-sdkWhy
Testing
Notes for Reviewer
ensnode-sdkPre-Review Checklist (Blocking)