Skip to content

Using NormalizedAddress in referral program logic#1938

Merged
Goader merged 4 commits intomainfrom
task/normalized-address-in-ens-referrals
Apr 16, 2026
Merged

Using NormalizedAddress in referral program logic#1938
Goader merged 4 commits intomainfrom
task/normalized-address-in-ens-referrals

Conversation

@Goader
Copy link
Copy Markdown
Member

@Goader Goader commented Apr 15, 2026

Using NormalizedAddress in referral program logic

closes: #1910

Summary


Why


Testing

  • Automatic CI and manual validation

Notes for Reviewer

  • Not sure about the example in the README.md (changing import from viem to enssdk)

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 Apr 15, 2026
Copilot AI review requested due to automatic review settings April 15, 2026 23:44
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: 73085b3

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 Patch
ensapi Patch
ensindexer Patch
ensadmin Patch
ensrainbow Patch
fallback-ensapi Patch
enssdk Patch
enscli Patch
enskit Patch
ensskills Patch
@ensnode/datasources Patch
@ensnode/ensrainbow-sdk Patch
@ensnode/ensdb-sdk Patch
@ensnode/ensnode-react Patch
@ensnode/ensnode-sdk Patch
@ensnode/ponder-sdk Patch
@ensnode/ponder-subgraph Patch
@ensnode/shared-configs Patch
@docs/ensnode Patch
@docs/ensrainbow Patch
@docs/mintlify Patch
@namehash/namehash-ui Patch
@ensnode/enskit-react-example Patch
@ensnode/integration-test-env 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 Apr 15, 2026

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

Project Deployment Actions Updated (UTC)
admin.ensnode.io Ready Ready Preview, Comment Apr 16, 2026 0:24am
ensnode.io Ready Ready Preview, Comment Apr 16, 2026 0:24am
ensrainbow.io Ready Ready Preview, Comment Apr 16, 2026 0:24am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

This pull request refines the referral program's type system to consistently use NormalizedAddress instead of Address across public surfaces, including validation functions, request types, leaderboard interfaces, and utility functions. The changeset documents this as a patch-level update to the @namehash/ens-referrals package.

Changes

Cohort / File(s) Summary
Changesets & Documentation
.changeset/every-areas-draw.md, packages/ens-referrals/README.md
Added changesets entry documenting the public API refinement; updated README example to import Address from enssdk instead of viem.
Core Validation & Type Definitions
packages/ens-referrals/src/address.ts, packages/ens-referrals/src/api/types.ts
Renamed exported validation function from validateAddress to validateNormalizedAddress; updated ReferrerMetricsEditionsRequest.referrer field type from Address to NormalizedAddress.
Award Model Leaderboards
packages/ens-referrals/src/award-models/pie-split/leaderboard.ts, packages/ens-referrals/src/award-models/rev-share-cap/leaderboard.ts
Updated ReferrerLeaderboardPieSplit.referrers map key type and JSDoc invariants from Address to NormalizedAddress; updated rev-share-cap leaderboard JSDoc to reflect NormalizedAddress keys.
Award Model Validation & Shared Utilities
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/referrer-metrics.ts
Updated validation calls to use validateNormalizedAddress instead of validateAddress; changed sliceReferrers function parameter type from Map<Address, T> to Map<NormalizedAddress, T>; updated validateReferrerMetrics to validate referrer using validateNormalizedAddress.
Tests
packages/ens-referrals/src/leaderboard-page.test.ts
Updated test map type annotations and imports from Address to NormalizedAddress to reflect new type signatures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

ensanalytics

Poem

🐰 Hoppy times in type-land bright,
Addresses normalized, all set right!
From Address old to Normalized new,
Type safety hops—validation through and through!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly summarizes the main change of updating referral program logic to use NormalizedAddress instead of Address.
Linked Issues check ✅ Passed The PR substantially addresses issue #1910 by replacing Address with NormalizedAddress across referral program types, function signatures, and validation logic.
Out of Scope Changes check ✅ Passed All code changes are directly related to issue #1910: updating type annotations from Address to NormalizedAddress and corresponding validation function calls throughout the referral program.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed PR description follows the template structure with all required sections (Summary, Why, Testing, Notes, Checklist) completed and includes a related issue reference.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/normalized-address-in-ens-referrals

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.

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

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 Address usages with NormalizedAddress in referral metrics, leaderboards, and API request types.
  • Rename address validation helper to validateNormalizedAddress and 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.

Comment thread .changeset/every-areas-draw.md
Comment thread packages/ens-referrals/src/address.ts
Comment thread packages/ens-referrals/src/api/types.ts
Comment thread .changeset/every-areas-draw.md
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 16, 2026

Greptile Summary

This PR tightens the referral program's internal types by replacing Address with NormalizedAddress in leaderboard map keys (ReferrerLeaderboardPieSplit, ReferrerLeaderboardRevShareCap, sliceReferrers) and renames validateAddress to validateNormalizedAddress across all call sites. Since NormalizedAddress is a type alias of Address in enssdk, there is no runtime behavior change.

One minor documentation concern: the README's "Other Utilities" example now imports Address from enssdk (a direct dependency, so it will be present), but the installation snippet still only mentions viem — users who copy-paste both code blocks may wonder where enssdk comes from.

Confidence Score: 5/5

Safe to merge — purely a type-level and documentation tightening with no runtime behavior changes.

All findings are P2. NormalizedAddress is a type alias for Address in enssdk, so no logic, runtime validation, or API contracts are altered. The rename of validateAddress is applied consistently across all three call sites. The only minor concern is the README import source change (enssdk vs viem), which is a documentation style issue and not a correctness problem.

No files require special attention.

Important Files Changed

Filename Overview
packages/ens-referrals/src/address.ts Renamed validateAddress to validateNormalizedAddress; logic unchanged.
packages/ens-referrals/src/award-models/pie-split/leaderboard.ts Swapped Address import to NormalizedAddress; map key type and JSDoc updated accordingly.
packages/ens-referrals/src/award-models/rev-share-cap/leaderboard.ts JSDoc @invariant updated to reference NormalizedAddress; map type was already correct in runtime code.
packages/ens-referrals/src/award-models/shared/leaderboard-page.ts Swapped Address import to NormalizedAddress in sliceReferrers generic parameter; no logic change.
packages/ens-referrals/src/referrer-metrics.ts Updated call from validateAddress to validateNormalizedAddress; no logic change.
packages/ens-referrals/src/leaderboard-page.test.ts Test type annotation updated from Address to NormalizedAddress; test logic unchanged.
packages/ens-referrals/README.md Import source for Address changed from viem to enssdk; technically correct but may surprise users following the installation guide that only lists viem.
.changeset/every-areas-draw.md Accurate patch-level changeset describing the type tightening with no runtime behavior change.

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)"]
Loading

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";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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.

Suggested change
import type { Address } from "enssdk";
import type { Address } from "viem";

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

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.

Comment thread packages/ens-referrals/src/address.ts
Comment thread .changeset/every-areas-draw.md
import { isNormalizedAddress } from "enssdk";

export const validateAddress = (address: NormalizedAddress): void => {
export const validateNormalizedAddress = (address: NormalizedAddress): void => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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).

Suggested change
export const validateNormalizedAddress = (address: NormalizedAddress): void => {
export const validateNormalizedAddress = (address: Unvalidated<NormalizedAddress>): void => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

@tk-o tk-o left a comment

Choose a reason for hiding this comment

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

LGTM

@Goader Goader merged commit ab20d4d into main Apr 16, 2026
23 of 24 checks passed
@Goader Goader deleted the task/normalized-address-in-ens-referrals branch April 16, 2026 12:43
@github-actions github-actions Bot mentioned this pull request Apr 16, 2026
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.

Refine use of NormalizedAddress in referral program logic

3 participants