Transitioning to use AccountId as the referrer identifier#2038
Conversation
🦋 Changeset detectedLatest commit: 9b377a0 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.
|
📝 WalkthroughWalkthroughMigrates referrer identity from ChangesReferrer Standardization via CAIP-10 AccountId
Sequence Diagram(s)(omitted — changes are broad migration/refactor and don't introduce a new multi-component sequential flow requiring visualization) Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 migrates the referrer identifier throughout
Confidence Score: 5/5Safe to merge — all referrer comparisons, map lookups, and serialization paths are consistently updated throughout the domain layer, API layer, and client. The migration is systematic and complete: every point where a referrer is compared, stored as a map key, serialized into a URL, or deserialized from a path param has been updated. The Zod schema fix correctly replaces a throw-from-transform antipattern with ctx.addIssue/z.NEVER. The leaderboard test-data inconsistency fix eliminates a latent test correctness issue. The sorting tie-break using AccountIdString is order-preserving for same-chain referrers. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as ENSReferralsClient
participant Route as Hono Route
participant Schema as Zod Schema (makeAccountIdStringSchema)
participant Handler as API Handler
participant DB as Database Layer
participant LB as Leaderboard Map AccountIdString
Client->>Route: "GET /referrer/{encodeURIComponent(CAIP-10)}"
Route->>Schema: parse URL-decoded path param
Schema->>Schema: CaipAccountId(v) then pipe makeAccountIdSchema
Schema-->>Handler: AccountId object
Handler->>DB: getReferralEvents(rules)
DB-->>Handler: ReferralEvent[] referrer AccountId from rules.subregistryId.chainId
Handler->>LB: buildReferralEditionSnapshot(events, rules)
LB-->>Handler: Map AccountIdString to AwardedReferrerMetrics
Handler->>LB: referrers.get(stringifyAccountId(referrer))
LB-->>Handler: AwardedReferrerMetrics or undefined
Handler-->>Client: ReferrerEditionMetrics ranked or zero-score unranked
Reviews (6): Last reviewed commit: "Merge remote-tracking branch 'origin' in..." | 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
|
@greptile |
|
@CodeRabbit do the review |
|
✅ Actions performedReview triggered.
|
Transitioning to use
AccountIdas the referrer identifiercloses: #1956
Summary
AccountIdorAccountIdStringfor keysensnode-sdkWhy
Testing
Notes for Reviewer
ensnode-sdkAccountId(e.g.,eip155:11155111:0xcfa4f8192ad39d1ee09f473e88e79d267e09ddca)Pre-Review Checklist (Blocking)