@namehash/ens-referrals 1.8.1 → 1.10.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.
- package/README.md +151 -14
- package/dist/index.cjs +2360 -828
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1525 -426
- package/dist/index.d.ts +1525 -426
- package/dist/index.js +2347 -825
- package/dist/index.js.map +1 -1
- package/package.json +4 -13
- package/dist/v1/index.cjs +0 -20902
- package/dist/v1/index.cjs.map +0 -1
- package/dist/v1/index.d.cts +0 -2098
- package/dist/v1/index.d.ts +0 -2098
- package/dist/v1/index.js +0 -20879
- package/dist/v1/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ENS Referrals
|
|
2
2
|
|
|
3
|
-
This package
|
|
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
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,24 +8,161 @@ This package provides utilities for working with ENS Referrals, including useful
|
|
|
8
8
|
npm install @namehash/ens-referrals viem
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Set up `ENSReferralsClient`
|
|
14
|
+
|
|
15
|
+
`ENSReferralsClient` is the main way to read referral data from ENSNode.
|
|
12
16
|
|
|
13
17
|
```typescript
|
|
14
|
-
import {
|
|
15
|
-
buildEncodedReferrer,
|
|
16
|
-
decodeEncodedReferrer,
|
|
17
|
-
buildEnsReferralUrl
|
|
18
|
-
} from "@namehash/ens-referrals";
|
|
19
|
-
import type { Address } from 'viem';
|
|
18
|
+
import { ENSReferralsClient } from "@namehash/ens-referrals";
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
// Create a client with the default ENSNode URL
|
|
21
|
+
const client = new ENSReferralsClient();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
If you want to use a specific ENSNode deployment, pass its URL to the client:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
const client = new ENSReferralsClient({
|
|
28
|
+
url: new URL("https://my-ensnode-instance.com"),
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Use ENS Referrals API
|
|
33
|
+
|
|
34
|
+
### Get all referral program editions → `getEditionSummaries()`
|
|
35
|
+
|
|
36
|
+
Returns the currently configured referral program editions. Editions are sorted by start time, with the newest edition first.
|
|
37
|
+
|
|
38
|
+
Use these edition slugs when calling the leaderboard and referrer endpoints.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const response = await client.getEditionSummaries();
|
|
42
|
+
|
|
43
|
+
if (response.responseCode === ReferralProgramEditionSummariesResponseCodes.Ok) {
|
|
44
|
+
console.log(`Found ${response.data.editions.length} editions`);
|
|
45
|
+
|
|
46
|
+
for (const edition of response.data.editions) {
|
|
47
|
+
console.log(`${edition.slug}: ${edition.displayName}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
More examples are available in [`packages/ens-referrals/src/client.ts`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/client.ts).
|
|
53
|
+
|
|
54
|
+
### Get a referrer leaderboard page → `getReferrerLeaderboardPage()`
|
|
55
|
+
|
|
56
|
+
Returns a paginated leaderboard for a specific referral program edition.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const editionSlug = "2025-12";
|
|
60
|
+
|
|
61
|
+
const response = await client.getReferrerLeaderboardPage({
|
|
62
|
+
edition: editionSlug,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Ok) {
|
|
66
|
+
const leaderboardPage = response.data;
|
|
67
|
+
|
|
68
|
+
if (leaderboardPage.awardModel === ReferralProgramAwardModels.Unrecognized) {
|
|
69
|
+
// gracefully handle forwards-compatibility as new award models are added in the future
|
|
70
|
+
console.log(`Unrecognized award model: ${leaderboardPage.originalAwardModel} - skipping`);
|
|
71
|
+
} else {
|
|
72
|
+
console.log(`Edition: ${editionSlug}`);
|
|
73
|
+
console.log(`Subregistry: ${leaderboardPage.rules.subregistryId}`);
|
|
74
|
+
console.log(`Total Referrers: ${leaderboardPage.pageContext.totalRecords}`);
|
|
75
|
+
console.log(
|
|
76
|
+
`Page ${leaderboardPage.pageContext.page} of ${leaderboardPage.pageContext.totalPages}`,
|
|
77
|
+
);
|
|
22
78
|
|
|
23
|
-
|
|
24
|
-
const
|
|
79
|
+
const noReferrersFallback = "No referrers in this edition";
|
|
80
|
+
const firstReferrer = leaderboardPage.referrers[0] ?? null;
|
|
25
81
|
|
|
26
|
-
|
|
27
|
-
|
|
82
|
+
if (leaderboardPage.awardModel === ReferralProgramAwardModels.PieSplit) {
|
|
83
|
+
console.log(`Max Qualified Referrers: ${leaderboardPage.rules.maxQualifiedReferrers}`);
|
|
84
|
+
console.log(
|
|
85
|
+
`First Referrer's Final Score Boost: ${firstReferrer !== null ? firstReferrer.finalScoreBoost : noReferrersFallback}`,
|
|
86
|
+
);
|
|
87
|
+
console.log(
|
|
88
|
+
`First Referrer's Award Pool Share: ${firstReferrer !== null ? firstReferrer.awardPoolShare : noReferrersFallback}`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (leaderboardPage.awardModel === ReferralProgramAwardModels.RevShareCap) {
|
|
93
|
+
console.log(
|
|
94
|
+
`Min Base Revenue Contribution: ${leaderboardPage.rules.minBaseRevenueContribution}`,
|
|
95
|
+
);
|
|
96
|
+
console.log(`Max Base Revenue Share: ${leaderboardPage.rules.maxBaseRevenueShare}`);
|
|
97
|
+
console.log(
|
|
98
|
+
`Tentative award for the top ranked referrer: ${firstReferrer !== null ? firstReferrer.cappedAward : noReferrersFallback}`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
More examples are available in [`packages/ens-referrals/src/client.ts`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/client.ts).
|
|
106
|
+
|
|
107
|
+
### Get a referrer's metrics across editions → `getReferrerMetricsEditions()`
|
|
108
|
+
|
|
109
|
+
Returns referrer metrics for a specified referrer across one or more editions.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const response = await client.getReferrerMetricsEditions({
|
|
113
|
+
referrer: "0x1234567890123456789012345678901234567890",
|
|
114
|
+
editions: ["2025-12", "2026-04"],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (response.responseCode === ReferrerMetricsEditionsResponseCodes.Ok) {
|
|
118
|
+
for (const [editionSlug, detail] of Object.entries(response.data)) {
|
|
119
|
+
console.log(`Edition: ${editionSlug}`);
|
|
120
|
+
|
|
121
|
+
if (detail.awardModel === ReferralProgramAwardModels.Unrecognized) {
|
|
122
|
+
// gracefully handle forwards-compatibility as new award models are added in the future
|
|
123
|
+
console.log(`Unrecognized award model: ${detail.originalAwardModel} - skipping`);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.log(`Type: ${detail.type}`);
|
|
128
|
+
|
|
129
|
+
if (detail.type === ReferrerEditionMetricsTypeIds.Ranked) {
|
|
130
|
+
console.log(`Rank: ${detail.referrer.rank}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (detail.awardModel === ReferralProgramAwardModels.PieSplit) {
|
|
134
|
+
console.log(`Referrer's Final Score: ${detail.referrer.finalScore}`);
|
|
135
|
+
console.log(`Referrer's Award Pool Share: ${detail.referrer.awardPoolShare * 100}%`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (detail.awardModel === ReferralProgramAwardModels.RevShareCap) {
|
|
139
|
+
console.log(
|
|
140
|
+
`Referrer's total base revenue contribution: ${detail.referrer.totalBaseRevenueContribution}`,
|
|
141
|
+
);
|
|
142
|
+
console.log(`Referrer's uncapped award value: ${detail.referrer.uncappedAward}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
More examples are available in [`packages/ens-referrals/src/client.ts`](https://github.com/namehash/ensnode/tree/main/packages/ens-referrals/src/client.ts).
|
|
149
|
+
|
|
150
|
+
## See how current Referral Program Editions are configured
|
|
151
|
+
|
|
152
|
+
Check out [`production-editions.json`](https://ensawards.org/production-editions.json) — the live config file powering our production deployment.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
## Other Utilities
|
|
156
|
+
|
|
157
|
+
The package also includes helpers for building referral links.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { buildEnsReferralUrl } from "@namehash/ens-referrals";
|
|
161
|
+
import type { Address } from "enssdk";
|
|
162
|
+
|
|
163
|
+
const referrerAddress: Address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
|
|
28
164
|
|
|
29
165
|
// Build a referrer URL to the official ENS manager app
|
|
30
|
-
const referrerUrl = buildEnsReferralUrl(referrerAddress).toString();
|
|
166
|
+
const referrerUrl = buildEnsReferralUrl(referrerAddress).toString();
|
|
167
|
+
// https://app.ens.domains/?referrer=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
|
|
31
168
|
```
|