@namehash/ens-referrals 1.8.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +153 -14
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ENS Referrals
2
2
 
3
- This package provides utilities for working with ENS Referrals, including useful types and utility functions.
3
+ Utilities for working with ENS Referrals data. This package is intended for developers who want to build referral dashboards, stats pages, or other integrations on top of ENS Referrals APIs.
4
+
5
+ The main entry point today is [`v1`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/v1), which includes the current client and response types for the latest ENS Referrals program format.
4
6
 
5
7
  ## Installation
6
8
 
@@ -8,24 +10,161 @@ This package provides utilities for working with ENS Referrals, including useful
8
10
  npm install @namehash/ens-referrals viem
9
11
  ```
10
12
 
11
- ### Basic Usage
13
+ ## Quick Start
14
+
15
+ `v1` is the recommended version for new integrations.
16
+
17
+ - [`v1`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/v1) is the actively supported version that reflects the current ENS Referrals program rules and awards.
18
+ - The root [`@namehash/ens-referrals`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/client.ts) import is deprecated and is planned to be removed soon.
19
+
20
+ ### Set up `ENSReferralsClient`
21
+
22
+ `ENSReferralsClient` is the main way to read referral data from ENSNode.
12
23
 
13
24
  ```typescript
14
- import {
15
- buildEncodedReferrer,
16
- decodeEncodedReferrer,
17
- buildEnsReferralUrl
18
- } from "@namehash/ens-referrals";
19
- import type { Address } from 'viem';
25
+ import { ENSReferralsClient } from "@namehash/ens-referrals/v1";
20
26
 
21
- const referrerAddress: Address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
27
+ // Create a client with the default ENSNode API URL
28
+ const client = new ENSReferralsClient();
29
+ ```
30
+
31
+ If you want to use a specific ENSNode deployment, pass its URL to the client:
32
+
33
+ ```typescript
34
+ const client = new ENSReferralsClient({
35
+ url: new URL("https://my-ensnode-instance.com"),
36
+ });
37
+ ```
38
+
39
+ ## Use ENS Referrals API (`v1`)
40
+
41
+ ### Get all referral program editions → `getEditionSummaries()`
42
+
43
+ Returns the currently configured referral program editions. Editions are sorted by start time, with the newest edition first.
44
+
45
+ Use these edition slugs when calling the leaderboard and referrer endpoints.
46
+
47
+ ```typescript
48
+ const response = await client.getEditionSummaries();
49
+
50
+ if (response.responseCode === ReferralProgramEditionSummariesResponseCodes.Ok) {
51
+ console.log(`Found ${response.data.editions.length} editions`);
52
+
53
+ for (const edition of response.data.editions) {
54
+ console.log(`${edition.slug}: ${edition.displayName}`);
55
+ }
56
+ }
57
+ ```
58
+
59
+ More examples are available in [`packages/ens-referrals/src/v1/client.ts`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/v1/client.ts).
60
+
61
+ ### Get a referrer leaderboard page → `getReferrerLeaderboardPage()`
62
+
63
+ Returns a paginated leaderboard for a specific referral program edition.
64
+
65
+ ```typescript
66
+ const editionSlug = "2025-12";
22
67
 
23
- // Build an encoded referrer value (according to the subjective referrer encoding used for ENS Holiday Awards)
24
- const encodedReferrer = buildEncodedReferrer(referrerAddress); // 0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045
68
+ const response = await client.getReferrerLeaderboardPage({
69
+ edition: editionSlug,
70
+ });
25
71
 
26
- // Decode an encoded referrer value (according to the subjective referrer encoding used for ENS Holiday Awards)
27
- const decodedReferrer = decodeEncodedReferrer(encodedReferrer); // 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
72
+ if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Ok) {
73
+ const leaderboardPage = response.data;
74
+
75
+ if (leaderboardPage.awardModel === ReferralProgramAwardModels.Unrecognized) {
76
+ // gracefully handle forwards-compatibility as new award models are added in the future
77
+ console.log(`Unrecognized award model: ${leaderboardPage.originalAwardModel} - skipping`);
78
+ } else {
79
+ console.log(`Edition: ${editionSlug}`);
80
+ console.log(`Subregistry: ${leaderboardPage.rules.subregistryId}`);
81
+ console.log(`Total Referrers: ${leaderboardPage.pageContext.totalRecords}`);
82
+ console.log(
83
+ `Page ${leaderboardPage.pageContext.page} of ${leaderboardPage.pageContext.totalPages}`,
84
+ );
85
+
86
+ const noReferrersFallback = "No referrers in this edition";
87
+ const firstReferrer = leaderboardPage.referrers[0] ?? null;
88
+
89
+ if (leaderboardPage.awardModel === ReferralProgramAwardModels.PieSplit) {
90
+ console.log(`Max Qualified Referrers: ${leaderboardPage.rules.maxQualifiedReferrers}`);
91
+ console.log(
92
+ `First Referrer's Final Score Boost: ${firstReferrer !== null ? firstReferrer.finalScoreBoost : noReferrersFallback}`,
93
+ );
94
+ console.log(
95
+ `First Referrer's Award Pool Share: ${firstReferrer !== null ? firstReferrer.awardPoolShare : noReferrersFallback}`,
96
+ );
97
+ }
98
+
99
+ if (leaderboardPage.awardModel === ReferralProgramAwardModels.RevShareLimit) {
100
+ console.log(
101
+ `Min Qualified Revenue Contribution: ${leaderboardPage.rules.minQualifiedRevenueContribution}`,
102
+ );
103
+ console.log(`Qualified Revenue Share: ${leaderboardPage.rules.qualifiedRevenueShare}`);
104
+ console.log(
105
+ `Tentative award for the best referrer: ${firstReferrer !== null ? firstReferrer.awardPoolApproxValue : noReferrersFallback}`,
106
+ );
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ More examples are available in [`packages/ens-referrals/src/v1/client.ts`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/v1/client.ts).
113
+
114
+ ### Get a referrer's metrics across editions → `getReferrerMetricsEditions()`
115
+
116
+ Returns referrer metrics for a specified referrer across one or more editions.
117
+
118
+ ```typescript
119
+ const response = await client.getReferrerMetricsEditions({
120
+ referrer: "0x1234567890123456789012345678901234567890",
121
+ editions: ["2025-12", "2026-01"],
122
+ });
123
+
124
+ if (response.responseCode === ReferrerMetricsEditionsResponseCodes.Ok) {
125
+ for (const [editionSlug, detail] of Object.entries(response.data)) {
126
+ console.log(`Edition: ${editionSlug}`);
127
+
128
+ if (detail.awardModel === ReferralProgramAwardModels.Unrecognized) {
129
+ // gracefully handle forwards-compatibility as new award models are added in the future
130
+ console.log(`Unrecognized award model: ${detail.originalAwardModel} - skipping`);
131
+ continue;
132
+ }
133
+
134
+ console.log(`Type: ${detail.type}`);
135
+
136
+ if (detail.type === ReferrerEditionMetricsTypeIds.Ranked) {
137
+ console.log(`Rank: ${detail.referrer.rank}`);
138
+ }
139
+
140
+ if (detail.awardModel === ReferralProgramAwardModels.PieSplit) {
141
+ console.log(`Referrer's Final Score: ${detail.referrer.finalScore}`);
142
+ console.log(`Referrer's Award Pool Share: ${detail.referrer.awardPoolShare * 100}%`);
143
+ }
144
+
145
+ if (detail.awardModel === ReferralProgramAwardModels.RevShareLimit) {
146
+ console.log(
147
+ `Referrer's total base revenue contribution: ${detail.referrer.totalBaseRevenueContribution}`,
148
+ );
149
+ console.log(`Referrer's standard award value: ${detail.referrer.standardAwardValue}`);
150
+ }
151
+ }
152
+ }
153
+ ```
154
+
155
+ More examples are available in [`packages/ens-referrals/src/v1/client.ts`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/v1/client.ts).
156
+
157
+ ## Other Utilities
158
+
159
+ The package also includes helpers for building referral links.
160
+
161
+ ```typescript
162
+ import { buildEnsReferralUrl } from "@namehash/ens-referrals/v1";
163
+ import type { Address } from "viem";
164
+
165
+ const referrerAddress: Address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
28
166
 
29
167
  // Build a referrer URL to the official ENS manager app
30
- const referrerUrl = buildEnsReferralUrl(referrerAddress).toString(); // https://app.ens.domains/?referrer=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
168
+ const referrerUrl = buildEnsReferralUrl(referrerAddress).toString();
169
+ // https://app.ens.domains/?referrer=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
31
170
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namehash/ens-referrals",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "type": "module",
5
5
  "description": "Utilities for ENS Referrals.",
6
6
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "zod": "^4.3.6",
53
- "@ensnode/ensnode-sdk": "1.8.1"
53
+ "@ensnode/ensnode-sdk": "1.9.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/node": "24.10.9",
@@ -58,7 +58,7 @@
58
58
  "typescript": "^5.7.3",
59
59
  "viem": "^2.22.13",
60
60
  "vitest": "^4.0.2",
61
- "@ensnode/shared-configs": "1.8.1"
61
+ "@ensnode/shared-configs": "1.9.0"
62
62
  },
63
63
  "scripts": {
64
64
  "prepublish": "tsup",