Using NormalizedAddress in referral program logic#1938
Conversation
🦋 Changeset detectedLatest commit: 73085b3 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.
|
📝 WalkthroughWalkthroughThis pull request refines the referral program's type system to consistently use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Pull request overview
Updates @namehash/ens-referrals to consistently model referrer addresses as NormalizedAddress across referral-program/leaderboard types, aligning with the enssdk normalization helpers and invariants (Issue #1910).
Changes:
- Replace remaining
Addressusages withNormalizedAddressin referral metrics, leaderboards, and API request types. - Rename address validation helper to
validateNormalizedAddressand update call sites. - Update docs and add a changeset for the package release.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ens-referrals/src/referrer-metrics.ts | Switches validation to validateNormalizedAddress for referrer. |
| packages/ens-referrals/src/leaderboard-page.test.ts | Updates test map key types to NormalizedAddress. |
| packages/ens-referrals/src/award-models/shared/leaderboard-page.ts | Tightens sliceReferrers map key type to NormalizedAddress. |
| packages/ens-referrals/src/award-models/rev-share-cap/rules.ts | Validates disqualification referrers as NormalizedAddress. |
| packages/ens-referrals/src/award-models/rev-share-cap/leaderboard.ts | Updates invariant doc wording to NormalizedAddress. |
| packages/ens-referrals/src/award-models/pie-split/leaderboard.ts | Updates leaderboard map key type and invariant doc wording. |
| packages/ens-referrals/src/api/types.ts | Changes ReferrerMetricsEditionsRequest.referrer to NormalizedAddress. |
| packages/ens-referrals/src/address.ts | Renames validator to validateNormalizedAddress. |
| packages/ens-referrals/README.md | Updates type import in referral link example. |
| .changeset/every-areas-draw.md | Adds release note for the type tightening change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Greptile SummaryThis PR tightens the referral program's internal types by replacing One minor documentation concern: the README's "Other Utilities" example now imports Confidence Score: 5/5Safe to merge — purely a type-level and documentation tightening with no runtime behavior changes. All findings are P2. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["ReferralEvent / ReferrerMetrics\n(referrer: NormalizedAddress)"] --> B["validateNormalizedAddress\n(address.ts)"]
B --> C{isNormalizedAddress?}
C -- Yes --> D["Leaderboard Maps\nMap<NormalizedAddress, T>"]
C -- No --> E["throw Error"]
D --> F["ReferrerLeaderboardPieSplit\n.referrers"]
D --> G["ReferrerLeaderboardRevShareCap\n.referrers"]
D --> H["sliceReferrers()\n(leaderboard-page.ts)"]
H --> I["ReferrerLeaderboardPage\n(paginated output)"]
Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin' in..." | Re-trigger Greptile |
| ```typescript | ||
| import { buildEnsReferralUrl } from "@namehash/ens-referrals"; | ||
| import type { Address } from "viem"; | ||
| import type { Address } from "enssdk"; |
There was a problem hiding this comment.
Import source inconsistent with installation instructions
The example now imports Address from enssdk, but the installation guide at the top of the README only lists viem as a required peer (npm install @namehash/ens-referrals viem). While enssdk is a direct dependency of the package (so it will be present on disk), users following the docs step-by-step may find it unexpected that they need to import from a package they never explicitly installed. Consider either keeping the import from viem (which is the documented peer dependency), or updating the installation instructions to mention enssdk.
| import type { Address } from "enssdk"; | |
| import type { Address } from "viem"; |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { isNormalizedAddress } from "enssdk"; | ||
|
|
||
| export const validateAddress = (address: NormalizedAddress): void => { | ||
| export const validateNormalizedAddress = (address: NormalizedAddress): void => { |
There was a problem hiding this comment.
Feel free to have a look at Unvalidated<T> type from ENSNode SDK. It's a helper type that allows to distinguish unvalidated value from the validated one (even if they are technically the same runtime type).
| export const validateNormalizedAddress = (address: NormalizedAddress): void => { | |
| export const validateNormalizedAddress = (address: Unvalidated<NormalizedAddress>): void => { |
There was a problem hiding this comment.
Thank you for the tip! In this case validation functions work more like runtime assertions and guards rather than a way to handle unvalidated objects. From what I see in the Unvalidated<T> documentation, assertions and guards are not exactly the purpose of it, no?
Using
NormalizedAddressin referral program logiccloses: #1910
Summary
validateAddresswas renamed tovalidateNormalizedAddressWhy
NormalizedAddressin referral program logic #1910Testing
Notes for Reviewer
viemtoenssdk)Pre-Review Checklist (Blocking)