@namehash/ens-referrals 0.0.0-next-20260102143513
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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/index.cjs +669 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +687 -0
- package/dist/index.d.ts +687 -0
- package/dist/index.js +646 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
import { Address, Hex } from 'viem';
|
|
2
|
+
|
|
3
|
+
declare const validateLowercaseAddress: (address: Address) => void;
|
|
4
|
+
declare const normalizeAddress: (address: Address) => Address;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a quantity of USD.
|
|
8
|
+
*
|
|
9
|
+
* @invariant Guaranteed to be a finite non-negative number (>= 0)
|
|
10
|
+
*/
|
|
11
|
+
type USDQuantity = number;
|
|
12
|
+
declare function isValidUSDQuantity(value: USDQuantity): boolean;
|
|
13
|
+
declare function validateUSDQuantity(value: USDQuantity): void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Unix timestamp value
|
|
17
|
+
*
|
|
18
|
+
* Represents the number of seconds that have elapsed
|
|
19
|
+
* since January 1, 1970 (midnight UTC/GMT). May be zero or negative to represent a time at or
|
|
20
|
+
* before Jan 1, 1970.
|
|
21
|
+
*
|
|
22
|
+
* @invariant Guaranteed to be an integer.
|
|
23
|
+
*/
|
|
24
|
+
type UnixTimestamp = number;
|
|
25
|
+
declare const validateUnixTimestamp: (timestamp: UnixTimestamp) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Duration
|
|
28
|
+
*
|
|
29
|
+
* Represents a duration in seconds.
|
|
30
|
+
*
|
|
31
|
+
* Guaranteed to be a non-negative integer.
|
|
32
|
+
*/
|
|
33
|
+
type Duration = number;
|
|
34
|
+
/**
|
|
35
|
+
* The number of seconds in a year.
|
|
36
|
+
*
|
|
37
|
+
* (60 seconds per minute * 60 minutes per hour *
|
|
38
|
+
* 24 hours per day * 365.2425 days on average per year).
|
|
39
|
+
*/
|
|
40
|
+
declare const SECONDS_PER_YEAR: Duration;
|
|
41
|
+
declare function isValidDuration(duration: Duration): boolean;
|
|
42
|
+
declare function validateDuration(duration: Duration): void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Start date for the ENS Holiday Awards referral program.
|
|
46
|
+
* 2025-12-01T00:00:00Z (December 1, 2025 at 00:00:00 UTC)
|
|
47
|
+
*/
|
|
48
|
+
declare const ENS_HOLIDAY_AWARDS_START_DATE: UnixTimestamp;
|
|
49
|
+
/**
|
|
50
|
+
* End date for the ENS Holiday Awards referral program.
|
|
51
|
+
* 2025-12-31T23:59:59Z (December 31, 2025 at 23:59:59 UTC)
|
|
52
|
+
*/
|
|
53
|
+
declare const ENS_HOLIDAY_AWARDS_END_DATE: UnixTimestamp;
|
|
54
|
+
/**
|
|
55
|
+
* The maximum number of qualified referrers for ENS Holiday Awards.
|
|
56
|
+
*/
|
|
57
|
+
declare const ENS_HOLIDAY_AWARDS_MAX_QUALIFIED_REFERRERS = 10;
|
|
58
|
+
/**
|
|
59
|
+
* The total value of the award pool in USD.
|
|
60
|
+
*/
|
|
61
|
+
declare const ENS_HOLIDAY_AWARDS_TOTAL_AWARD_POOL_VALUE: USDQuantity;
|
|
62
|
+
/**
|
|
63
|
+
* Chain ID
|
|
64
|
+
*
|
|
65
|
+
* Represents a unique identifier for a chain.
|
|
66
|
+
* Guaranteed to be a positive integer.
|
|
67
|
+
**/
|
|
68
|
+
type ChainId = number;
|
|
69
|
+
/**
|
|
70
|
+
* Represents an account (contract or EOA) at `address` on chain `chainId`.
|
|
71
|
+
*
|
|
72
|
+
* @see https://chainagnostic.org/CAIPs/caip-10
|
|
73
|
+
*/
|
|
74
|
+
interface AccountId {
|
|
75
|
+
chainId: ChainId;
|
|
76
|
+
address: Address;
|
|
77
|
+
}
|
|
78
|
+
interface ReferralProgramRules {
|
|
79
|
+
/**
|
|
80
|
+
* The total value of the award pool in USD.
|
|
81
|
+
*
|
|
82
|
+
* NOTE: Awards will actually be distributed in $ENS tokens.
|
|
83
|
+
*/
|
|
84
|
+
totalAwardPoolValue: USDQuantity;
|
|
85
|
+
/**
|
|
86
|
+
* The maximum number of referrers that will qualify to receive a non-zero `awardPoolShare`.
|
|
87
|
+
*
|
|
88
|
+
* @invariant Guaranteed to be a non-negative integer (>= 0)
|
|
89
|
+
*/
|
|
90
|
+
maxQualifiedReferrers: number;
|
|
91
|
+
/**
|
|
92
|
+
* The start time of the referral program.
|
|
93
|
+
*/
|
|
94
|
+
startTime: UnixTimestamp;
|
|
95
|
+
/**
|
|
96
|
+
* The end time of the referral program.
|
|
97
|
+
* @invariant Guaranteed to be greater than or equal to `startTime`
|
|
98
|
+
*/
|
|
99
|
+
endTime: UnixTimestamp;
|
|
100
|
+
/**
|
|
101
|
+
* The account ID of the subregistry for the referral program.
|
|
102
|
+
*/
|
|
103
|
+
subregistryId: AccountId;
|
|
104
|
+
}
|
|
105
|
+
declare const validateReferralProgramRules: (rules: ReferralProgramRules) => void;
|
|
106
|
+
declare const buildReferralProgramRules: (totalAwardPoolValue: USDQuantity, maxQualifiedReferrers: number, startTime: UnixTimestamp, endTime: UnixTimestamp, subregistryId: AccountId) => ReferralProgramRules;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The score of a referrer.
|
|
110
|
+
*
|
|
111
|
+
* @invariant Guaranteed to be a finite non-negative number (>= 0)
|
|
112
|
+
*/
|
|
113
|
+
type ReferrerScore = number;
|
|
114
|
+
declare const isValidReferrerScore: (score: ReferrerScore) => boolean;
|
|
115
|
+
declare const validateReferrerScore: (score: ReferrerScore) => void;
|
|
116
|
+
/**
|
|
117
|
+
* Calculate the score of a referrer based on the total incremental duration
|
|
118
|
+
* (in seconds) of registrations and renewals for direct subnames of .eth
|
|
119
|
+
* referrered by the referrer within the ENS Holiday Awards period.
|
|
120
|
+
*
|
|
121
|
+
* @param totalIncrementalDuration - The total incremental duration (in seconds)
|
|
122
|
+
* of referrals made by a referrer within the {@link ReferralProgramRules}.
|
|
123
|
+
* @returns The score of the referrer.
|
|
124
|
+
*/
|
|
125
|
+
declare const calcReferrerScore: (totalIncrementalDuration: Duration) => ReferrerScore;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The rank of a referrer relative to all other referrers, where 1 is the
|
|
129
|
+
* top-ranked referrer.
|
|
130
|
+
*
|
|
131
|
+
* @invariant Guaranteed to be a positive integer (> 0)
|
|
132
|
+
*/
|
|
133
|
+
type ReferrerRank = number;
|
|
134
|
+
declare const validateReferrerRank: (rank: ReferrerRank) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Determine if a referrer with the given `rank` is qualified to receive a non-zero `awardPoolShare` according to the given `rules`.
|
|
137
|
+
*
|
|
138
|
+
* @param rank - The rank of the referrer relative to all other referrers on a {@link ReferrerLeaderboard}.
|
|
139
|
+
* @param rules - The rules of the referral program that generated the `rank`.
|
|
140
|
+
*/
|
|
141
|
+
declare function isReferrerQualified(rank: ReferrerRank, rules: ReferralProgramRules): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Calculate the final score boost of a referrer based on their rank.
|
|
144
|
+
*
|
|
145
|
+
* @param rank - The rank of the referrer relative to all other referrers, where 1 is the
|
|
146
|
+
* top-ranked referrer.
|
|
147
|
+
* @returns The final score boost of the referrer as a number between 0 and 1 (inclusive).
|
|
148
|
+
*/
|
|
149
|
+
declare function calcReferrerFinalScoreBoost(rank: ReferrerRank, rules: ReferralProgramRules): number;
|
|
150
|
+
/**
|
|
151
|
+
* Calculate the final score multiplier of a referrer based on their rank.
|
|
152
|
+
*
|
|
153
|
+
* @param rank - The rank of the referrer relative to all other referrers, where 1 is the
|
|
154
|
+
* top-ranked referrer.
|
|
155
|
+
* @returns The final score multiplier of the referrer as a number between 1 and 2 (inclusive).
|
|
156
|
+
*/
|
|
157
|
+
declare function calcReferrerFinalScoreMultiplier(rank: ReferrerRank, rules: ReferralProgramRules): number;
|
|
158
|
+
/**
|
|
159
|
+
* Calculate the final score of a referrer based on their score and final score boost.
|
|
160
|
+
*
|
|
161
|
+
* @param rank - The rank of the referrer relative to all other referrers.
|
|
162
|
+
* @param totalIncrementalDuration - The total incremental duration (in seconds)
|
|
163
|
+
* of referrals made by the referrer within the `rules`.
|
|
164
|
+
* @param rules - The rules of the referral program that generated the `rank`.
|
|
165
|
+
* @returns The final score of the referrer.
|
|
166
|
+
*/
|
|
167
|
+
declare function calcReferrerFinalScore(rank: ReferrerRank, totalIncrementalDuration: Duration, rules: ReferralProgramRules): ReferrerScore;
|
|
168
|
+
interface ReferrerMetricsForComparison {
|
|
169
|
+
/**
|
|
170
|
+
* The total incremental duration (in seconds) of all referrals made by the referrer within
|
|
171
|
+
* the {@link ReferralProgramRules}.
|
|
172
|
+
*/
|
|
173
|
+
totalIncrementalDuration: Duration;
|
|
174
|
+
/**
|
|
175
|
+
* The fully lowercase Ethereum address of the referrer.
|
|
176
|
+
*
|
|
177
|
+
* @invariant Guaranteed to be a valid EVM address in lowercase format.
|
|
178
|
+
*/
|
|
179
|
+
referrer: Address;
|
|
180
|
+
}
|
|
181
|
+
declare const compareReferrerMetrics: (a: ReferrerMetricsForComparison, b: ReferrerMetricsForComparison) => number;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Revenue Contribution
|
|
185
|
+
*
|
|
186
|
+
* Represents the total revenue contribution (in Wei) made to the ENS DAO.
|
|
187
|
+
*
|
|
188
|
+
* This is the sum of the total cost paid by registrants for registrar actions.
|
|
189
|
+
* From the perspective of the ENS DAO, this represents revenue received.
|
|
190
|
+
*
|
|
191
|
+
* @invariant Guaranteed to be a non-negative bigint value (>= 0n)
|
|
192
|
+
* @invariant Never null (records with null `total` in the database are treated as 0 when summing)
|
|
193
|
+
*/
|
|
194
|
+
type RevenueContribution = bigint;
|
|
195
|
+
/**
|
|
196
|
+
* Check if a value is a valid revenue contribution.
|
|
197
|
+
*
|
|
198
|
+
* @param value - The value to check
|
|
199
|
+
* @returns true if the value is a non-negative bigint, false otherwise
|
|
200
|
+
*/
|
|
201
|
+
declare function isValidRevenueContribution(value: unknown): value is RevenueContribution;
|
|
202
|
+
/**
|
|
203
|
+
* Validate that a value is a valid revenue contribution.
|
|
204
|
+
*
|
|
205
|
+
* @param value - The value to validate
|
|
206
|
+
* @throws {Error} If the value is not a valid revenue contribution
|
|
207
|
+
*/
|
|
208
|
+
declare function validateRevenueContribution(value: unknown): void;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Represents metrics for a single referrer independent of other referrers.
|
|
212
|
+
*/
|
|
213
|
+
interface ReferrerMetrics {
|
|
214
|
+
/**
|
|
215
|
+
* The fully lowercase Ethereum address of the referrer.
|
|
216
|
+
*
|
|
217
|
+
* @invariant Guaranteed to be a valid EVM address in lowercase format
|
|
218
|
+
*/
|
|
219
|
+
referrer: Address;
|
|
220
|
+
/**
|
|
221
|
+
* The total number of referrals made by the referrer within the {@link ReferralProgramRules}.
|
|
222
|
+
* @invariant Guaranteed to be a non-negative integer (>= 0)
|
|
223
|
+
*/
|
|
224
|
+
totalReferrals: number;
|
|
225
|
+
/**
|
|
226
|
+
* The total incremental duration (in seconds) of all referrals made by the referrer within
|
|
227
|
+
* the {@link ReferralProgramRules}.
|
|
228
|
+
*/
|
|
229
|
+
totalIncrementalDuration: Duration;
|
|
230
|
+
/**
|
|
231
|
+
* The total revenue contribution (in Wei) made to the ENS DAO by all referrals
|
|
232
|
+
* from this referrer.
|
|
233
|
+
*
|
|
234
|
+
* This is the sum of the total cost paid by registrants for all registrar actions
|
|
235
|
+
* where this address was the referrer.
|
|
236
|
+
*
|
|
237
|
+
* @invariant Guaranteed to be a non-negative bigint value (>= 0n)
|
|
238
|
+
* @invariant Never null (records with null `total` in the database are treated as 0 when summing)
|
|
239
|
+
*/
|
|
240
|
+
totalRevenueContribution: RevenueContribution;
|
|
241
|
+
}
|
|
242
|
+
declare const buildReferrerMetrics: (referrer: Address, totalReferrals: number, totalIncrementalDuration: Duration, totalRevenueContribution: RevenueContribution) => ReferrerMetrics;
|
|
243
|
+
declare const validateReferrerMetrics: (metrics: ReferrerMetrics) => void;
|
|
244
|
+
declare const sortReferrerMetrics: (referrers: ReferrerMetrics[]) => ReferrerMetrics[];
|
|
245
|
+
/**
|
|
246
|
+
* Represents metrics for a single referrer independent of other referrers,
|
|
247
|
+
* including a calculation of the referrer's score.
|
|
248
|
+
*/
|
|
249
|
+
interface ScoredReferrerMetrics extends ReferrerMetrics {
|
|
250
|
+
/**
|
|
251
|
+
* The referrer's score.
|
|
252
|
+
*
|
|
253
|
+
* @invariant Guaranteed to be `calcReferrerScore(totalIncrementalDuration)`
|
|
254
|
+
*/
|
|
255
|
+
score: ReferrerScore;
|
|
256
|
+
}
|
|
257
|
+
declare const buildScoredReferrerMetrics: (referrer: ReferrerMetrics) => ScoredReferrerMetrics;
|
|
258
|
+
declare const validateScoredReferrerMetrics: (metrics: ScoredReferrerMetrics) => void;
|
|
259
|
+
/**
|
|
260
|
+
* Extends {@link ScoredReferrerMetrics} to include additional metrics
|
|
261
|
+
* relative to all other referrers on a {@link ReferrerLeaderboard} and {@link ReferralProgramRules}.
|
|
262
|
+
*/
|
|
263
|
+
interface RankedReferrerMetrics extends ScoredReferrerMetrics {
|
|
264
|
+
/**
|
|
265
|
+
* The referrer's rank on the {@link ReferrerLeaderboard} relative to all other referrers.
|
|
266
|
+
*/
|
|
267
|
+
rank: ReferrerRank;
|
|
268
|
+
/**
|
|
269
|
+
* Identifies if the referrer meets the qualifications of the {@link ReferralProgramRules} to receive a non-zero `awardPoolShare`.
|
|
270
|
+
*
|
|
271
|
+
* @invariant true if and only if `rank` is less than or equal to {@link ReferralProgramRules.maxQualifiedReferrers}
|
|
272
|
+
*/
|
|
273
|
+
isQualified: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* The referrer's final score boost.
|
|
276
|
+
*
|
|
277
|
+
* @invariant Guaranteed to be a number between 0 and 1 (inclusive)
|
|
278
|
+
* @invariant Calculated as: `1-((rank-1)/({@link ReferralProgramRules.maxQualifiedReferrers}-1))` if `isQualified` is `true`, else `0`
|
|
279
|
+
*/
|
|
280
|
+
finalScoreBoost: number;
|
|
281
|
+
/**
|
|
282
|
+
* The referrer's final score.
|
|
283
|
+
*
|
|
284
|
+
* @invariant Calculated as: `score * (1 + finalScoreBoost)`
|
|
285
|
+
*/
|
|
286
|
+
finalScore: ReferrerScore;
|
|
287
|
+
}
|
|
288
|
+
declare const validateRankedReferrerMetrics: (metrics: RankedReferrerMetrics, rules: ReferralProgramRules) => void;
|
|
289
|
+
declare const buildRankedReferrerMetrics: (referrer: ScoredReferrerMetrics, rank: ReferrerRank, rules: ReferralProgramRules) => RankedReferrerMetrics;
|
|
290
|
+
/**
|
|
291
|
+
* Calculate the share of the award pool for a referrer.
|
|
292
|
+
* @param referrer - The referrer to calculate the award pool share for.
|
|
293
|
+
* @param aggregatedMetrics - Aggregated metrics for all referrers.
|
|
294
|
+
* @param rules - The rules of the referral program.
|
|
295
|
+
* @returns The referrer's share of the award pool as a number between 0 and 1 (inclusive).
|
|
296
|
+
*/
|
|
297
|
+
declare const calcReferrerAwardPoolShare: (referrer: RankedReferrerMetrics, aggregatedMetrics: AggregatedReferrerMetrics, rules: ReferralProgramRules) => number;
|
|
298
|
+
/**
|
|
299
|
+
* Extends {@link RankedReferrerMetrics} to include additional metrics
|
|
300
|
+
* relative to {@link AggregatedRankedReferrerMetrics}.
|
|
301
|
+
*/
|
|
302
|
+
interface AwardedReferrerMetrics extends RankedReferrerMetrics {
|
|
303
|
+
/**
|
|
304
|
+
* The referrer's share of the award pool.
|
|
305
|
+
*
|
|
306
|
+
* @invariant Guaranteed to be a number between 0 and 1 (inclusive)
|
|
307
|
+
* @invariant Calculated as: `finalScore / {@link AggregatedRankedReferrerMetrics.grandTotalQualifiedReferrersFinalScore}` if `isQualified` is `true`, else `0`
|
|
308
|
+
*/
|
|
309
|
+
awardPoolShare: number;
|
|
310
|
+
/**
|
|
311
|
+
* The approximate {@link USDQuantity} of the referrer's share of the {@link ReferralProgramRules.totalAwardPoolValue}.
|
|
312
|
+
*
|
|
313
|
+
* @invariant Guaranteed to be a number between 0 and {@link ReferralProgramRules.totalAwardPoolValue} (inclusive)
|
|
314
|
+
* @invariant Calculated as: `awardPoolShare` * {@link ReferralProgramRules.totalAwardPoolValue}
|
|
315
|
+
*/
|
|
316
|
+
awardPoolApproxValue: USDQuantity;
|
|
317
|
+
}
|
|
318
|
+
declare const validateAwardedReferrerMetrics: (referrer: AwardedReferrerMetrics, rules: ReferralProgramRules) => void;
|
|
319
|
+
declare const buildAwardedReferrerMetrics: (referrer: RankedReferrerMetrics, aggregatedMetrics: AggregatedReferrerMetrics, rules: ReferralProgramRules) => AwardedReferrerMetrics;
|
|
320
|
+
/**
|
|
321
|
+
* Extends {@link AwardedReferrerMetrics} but with rank set to null to represent
|
|
322
|
+
* a referrer who is not on the leaderboard (has zero referrals within the rules associated with the leaderboard).
|
|
323
|
+
*/
|
|
324
|
+
interface UnrankedReferrerMetrics extends Omit<AwardedReferrerMetrics, "rank" | "isQualified"> {
|
|
325
|
+
/**
|
|
326
|
+
* The referrer is not on the leaderboard and therefore has no rank.
|
|
327
|
+
*/
|
|
328
|
+
rank: null;
|
|
329
|
+
/**
|
|
330
|
+
* Always false for unranked referrers.
|
|
331
|
+
*/
|
|
332
|
+
isQualified: false;
|
|
333
|
+
}
|
|
334
|
+
declare const validateUnrankedReferrerMetrics: (metrics: UnrankedReferrerMetrics) => void;
|
|
335
|
+
/**
|
|
336
|
+
* Build an unranked zero-score referrer record for a referrer address that is not in the leaderboard.
|
|
337
|
+
*
|
|
338
|
+
* This is useful when you want to return a referrer record for an address that has no referrals
|
|
339
|
+
* and is not qualified for the leaderboard.
|
|
340
|
+
*
|
|
341
|
+
* @param referrer - The referrer address
|
|
342
|
+
* @returns An {@link UnrankedReferrerMetrics} with zero values for all metrics and null rank
|
|
343
|
+
*/
|
|
344
|
+
declare const buildUnrankedReferrerMetrics: (referrer: Address) => UnrankedReferrerMetrics;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Represents aggregated metrics for a list of `RankedReferrerMetrics`.
|
|
348
|
+
*/
|
|
349
|
+
interface AggregatedReferrerMetrics {
|
|
350
|
+
/**
|
|
351
|
+
* @invariant The sum of `totalReferrals` across all `RankedReferrerMetrics` in the list.
|
|
352
|
+
* @invariant Guaranteed to be a non-negative integer (>= 0)
|
|
353
|
+
*/
|
|
354
|
+
grandTotalReferrals: number;
|
|
355
|
+
/**
|
|
356
|
+
* @invariant The sum of `totalIncrementalDuration` across all `RankedReferrerMetrics` in the list.
|
|
357
|
+
*/
|
|
358
|
+
grandTotalIncrementalDuration: Duration;
|
|
359
|
+
/**
|
|
360
|
+
* The total revenue contribution (in Wei) to the ENS DAO from all referrals
|
|
361
|
+
* across all referrers on the leaderboard.
|
|
362
|
+
*
|
|
363
|
+
* This is the sum of `totalRevenueContribution` across all `RankedReferrerMetrics` in the list.
|
|
364
|
+
*
|
|
365
|
+
* @invariant Guaranteed to be a non-negative bigint value (>= 0n)
|
|
366
|
+
*/
|
|
367
|
+
grandTotalRevenueContribution: RevenueContribution;
|
|
368
|
+
/**
|
|
369
|
+
* @invariant The sum of `finalScore` across all `RankedReferrerMetrics` where `isQualified` is `true`.
|
|
370
|
+
*/
|
|
371
|
+
grandTotalQualifiedReferrersFinalScore: ReferrerScore;
|
|
372
|
+
/**
|
|
373
|
+
* @invariant Identifies the minimum final score required to become a qualified referrer.
|
|
374
|
+
* @invariant If `rules.maxQualifiedReferrers` is 0, then `minFinalScoreToQualify` is guaranteed to
|
|
375
|
+
* be `Number.MAX_SAFE_INTEGER`.
|
|
376
|
+
* @invariant If `rules.maxQualifiedReferrers` is greater than 0, and there are no current referrers
|
|
377
|
+
* matching the `rules`, then `minFinalScoreToQualify` is guaranteed to be `0`.
|
|
378
|
+
*/
|
|
379
|
+
minFinalScoreToQualify: ReferrerScore;
|
|
380
|
+
}
|
|
381
|
+
declare const validateAggregatedReferrerMetrics: (metrics: AggregatedReferrerMetrics) => void;
|
|
382
|
+
declare const buildAggregatedReferrerMetrics: (referrers: RankedReferrerMetrics[], rules: ReferralProgramRules) => AggregatedReferrerMetrics;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Encoded Referrer
|
|
386
|
+
*
|
|
387
|
+
* Represents a "raw" ENS referrer value.
|
|
388
|
+
*
|
|
389
|
+
* Guaranteed to be a hex string representation of a 32-byte value.
|
|
390
|
+
* For ENS Holiday Awards a correctly encoded referrer is
|
|
391
|
+
* a left-padded lowercase EVM address.
|
|
392
|
+
*/
|
|
393
|
+
type EncodedReferrer = Hex;
|
|
394
|
+
/**
|
|
395
|
+
* Encoded Referrer byte offset for ENS Holiday Awards.
|
|
396
|
+
*
|
|
397
|
+
* The count of left-padded bytes in an {@link EncodedReferrer} value for ENS Holiday Awards.
|
|
398
|
+
*/
|
|
399
|
+
declare const ENCODED_REFERRER_BYTE_OFFSET = 12;
|
|
400
|
+
/**
|
|
401
|
+
* Encoded Referrer byte length
|
|
402
|
+
*
|
|
403
|
+
* The count of bytes the {@link EncodedReferrer} value consists of.
|
|
404
|
+
*/
|
|
405
|
+
declare const ENCODED_REFERRER_BYTE_LENGTH = 32;
|
|
406
|
+
/**
|
|
407
|
+
* Encoded Referrer Padding for ENS Holiday Awards
|
|
408
|
+
*
|
|
409
|
+
* The initial bytes of correctly encoded referrer value for ENS Holiday Awards.
|
|
410
|
+
*/
|
|
411
|
+
declare const EXPECTED_ENCODED_REFERRER_PADDING: Hex;
|
|
412
|
+
/**
|
|
413
|
+
* Zero Encoded Referrer
|
|
414
|
+
*
|
|
415
|
+
* Guaranteed to be a hex string representation of a 32-byte zero value.
|
|
416
|
+
*/
|
|
417
|
+
declare const ZERO_ENCODED_REFERRER: EncodedReferrer;
|
|
418
|
+
/**
|
|
419
|
+
* Build an {@link EncodedReferrer} value for the given {@link Address}
|
|
420
|
+
* according to the subjective referrer encoding used for ENS Holiday Awards.
|
|
421
|
+
*/
|
|
422
|
+
declare function buildEncodedReferrer(address: Address): EncodedReferrer;
|
|
423
|
+
/**
|
|
424
|
+
* Decode an {@link EncodedReferrer} value into a checksummed {@link Address}
|
|
425
|
+
* according to the subjective referrer encoding used for ENS Holiday Awards.
|
|
426
|
+
*
|
|
427
|
+
* @param encodedReferrer - The "raw" {@link EncodedReferrer} value to decode.
|
|
428
|
+
* @returns The decoded referrer checksummed address.
|
|
429
|
+
* @throws when encodedReferrer value is not represented by
|
|
430
|
+
* {@link ENCODED_REFERRER_BYTE_LENGTH} bytes.
|
|
431
|
+
* @throws when decodedReferrer is not a valid EVM address.
|
|
432
|
+
*/
|
|
433
|
+
declare function decodeEncodedReferrer(encodedReferrer: EncodedReferrer): Address;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Represents a leaderboard for any number of referrers.
|
|
437
|
+
*/
|
|
438
|
+
interface ReferrerLeaderboard {
|
|
439
|
+
/**
|
|
440
|
+
* The rules of the referral program that generated the {@link ReferrerLeaderboard}.
|
|
441
|
+
*/
|
|
442
|
+
rules: ReferralProgramRules;
|
|
443
|
+
/**
|
|
444
|
+
* The {@link AggregatedReferrerMetrics} for all `RankedReferrerMetrics` values in `leaderboard`.
|
|
445
|
+
*/
|
|
446
|
+
aggregatedMetrics: AggregatedReferrerMetrics;
|
|
447
|
+
/**
|
|
448
|
+
* Ordered map containing `AwardedReferrerMetrics` for all referrers with 1 or more
|
|
449
|
+
* `totalReferrals` within the `rules` as of `updatedAt`.
|
|
450
|
+
*
|
|
451
|
+
* @invariant Map entries are ordered by `rank` (ascending).
|
|
452
|
+
* @invariant Map is empty if there are no referrers with 1 or more `totalReferrals`
|
|
453
|
+
* within the `rules` as of `updatedAt`.
|
|
454
|
+
* @invariant If a fully-lowercase `Address` is not a key in this map then that `Address` had
|
|
455
|
+
* 0 `totalReferrals`, `totalIncrementalDuration`, and `score` within the
|
|
456
|
+
* `rules` as of `updatedAt`.
|
|
457
|
+
* @invariant Each value in this map is guaranteed to have a non-zero
|
|
458
|
+
* `totalReferrals`, `totalIncrementalDuration`, and `score`.
|
|
459
|
+
*/
|
|
460
|
+
referrers: Map<Address, AwardedReferrerMetrics>;
|
|
461
|
+
/**
|
|
462
|
+
* The {@link UnixTimestamp} of when the data used to build the {@link ReferrerLeaderboard} was accurate as of.
|
|
463
|
+
*/
|
|
464
|
+
accurateAsOf: UnixTimestamp;
|
|
465
|
+
}
|
|
466
|
+
declare const buildReferrerLeaderboard: (allReferrers: ReferrerMetrics[], rules: ReferralProgramRules, accurateAsOf: UnixTimestamp) => ReferrerLeaderboard;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* The default number of referrers per leaderboard page.
|
|
470
|
+
*/
|
|
471
|
+
declare const REFERRERS_PER_LEADERBOARD_PAGE_DEFAULT = 25;
|
|
472
|
+
/**
|
|
473
|
+
* The maximum number of referrers per leaderboard page.
|
|
474
|
+
*/
|
|
475
|
+
declare const REFERRERS_PER_LEADERBOARD_PAGE_MAX = 100;
|
|
476
|
+
/**
|
|
477
|
+
* Pagination params for leaderboard queries.
|
|
478
|
+
*/
|
|
479
|
+
interface ReferrerLeaderboardPageParams {
|
|
480
|
+
/**
|
|
481
|
+
* Requested referrer leaderboard page number (1-indexed)
|
|
482
|
+
* @invariant Must be a positive integer (>= 1)
|
|
483
|
+
* @default 1
|
|
484
|
+
*/
|
|
485
|
+
page?: number;
|
|
486
|
+
/**
|
|
487
|
+
* Maximum number of referrers to return per leaderboard page
|
|
488
|
+
* @invariant Must be a positive integer (>= 1) and less than or equal to {@link REFERRERS_PER_LEADERBOARD_PAGE_MAX}
|
|
489
|
+
* @default {@link REFERRERS_PER_LEADERBOARD_PAGE_DEFAULT}
|
|
490
|
+
*/
|
|
491
|
+
recordsPerPage?: number;
|
|
492
|
+
}
|
|
493
|
+
declare const buildReferrerLeaderboardPageParams: (params: ReferrerLeaderboardPageParams) => Required<ReferrerLeaderboardPageParams>;
|
|
494
|
+
interface ReferrerLeaderboardPageContext extends Required<ReferrerLeaderboardPageParams> {
|
|
495
|
+
/**
|
|
496
|
+
* Total number of referrers across all leaderboard pages
|
|
497
|
+
* @invariant Guaranteed to be a non-negative integer (>= 0)
|
|
498
|
+
*/
|
|
499
|
+
totalRecords: number;
|
|
500
|
+
/**
|
|
501
|
+
* Total number of pages in the leaderboard
|
|
502
|
+
* @invariant Guaranteed to be a positive integer (>= 1)
|
|
503
|
+
*/
|
|
504
|
+
totalPages: number;
|
|
505
|
+
/**
|
|
506
|
+
* Indicates if there is a next page available
|
|
507
|
+
* @invariant true if and only if (`page` * `recordsPerPage` < `total`)
|
|
508
|
+
*/
|
|
509
|
+
hasNext: boolean;
|
|
510
|
+
/**
|
|
511
|
+
* Indicates if there is a previous page available
|
|
512
|
+
* @invariant true if and only if (`page` > 1)
|
|
513
|
+
*/
|
|
514
|
+
hasPrev: boolean;
|
|
515
|
+
/**
|
|
516
|
+
* The start index of the referrers on the page (0-indexed)
|
|
517
|
+
*
|
|
518
|
+
* `undefined` if and only if `totalRecords` is 0.
|
|
519
|
+
*
|
|
520
|
+
* @invariant Guaranteed to be a non-negative integer (>= 0)
|
|
521
|
+
*/
|
|
522
|
+
startIndex?: number;
|
|
523
|
+
/**
|
|
524
|
+
* The end index of the referrers on the page (0-indexed)
|
|
525
|
+
*
|
|
526
|
+
* `undefined` if and only if `totalRecords` is 0.
|
|
527
|
+
*
|
|
528
|
+
* @invariant Guaranteed to be a non-negative integer (>= 0)
|
|
529
|
+
* @invariant If `totalRecords` is > 0:
|
|
530
|
+
* - Guaranteed to be greater than or equal to `startIndex`.
|
|
531
|
+
* - Guaranteed to be less than `totalRecords`.
|
|
532
|
+
*/
|
|
533
|
+
endIndex?: number;
|
|
534
|
+
}
|
|
535
|
+
declare const validateReferrerLeaderboardPageContext: (context: ReferrerLeaderboardPageContext) => void;
|
|
536
|
+
declare const buildReferrerLeaderboardPageContext: (optionalParams: ReferrerLeaderboardPageParams, leaderboard: ReferrerLeaderboard) => ReferrerLeaderboardPageContext;
|
|
537
|
+
/**
|
|
538
|
+
* A page of referrers from the referrer leaderboard.
|
|
539
|
+
*/
|
|
540
|
+
interface ReferrerLeaderboardPage {
|
|
541
|
+
/**
|
|
542
|
+
* The {@link ReferralProgramRules} used to generate the {@link ReferrerLeaderboard}
|
|
543
|
+
* that this {@link ReferrerLeaderboardPage} comes from.
|
|
544
|
+
*/
|
|
545
|
+
rules: ReferralProgramRules;
|
|
546
|
+
/**
|
|
547
|
+
* Ordered list of {@link AwardedReferrerMetrics} for the {@link ReferrerLeaderboardPage}
|
|
548
|
+
* described by `pageContext` within the related {@link ReferrerLeaderboard}.
|
|
549
|
+
*
|
|
550
|
+
* @invariant Array will be empty if `pageContext.totalRecords` is 0.
|
|
551
|
+
* @invariant Array entries are ordered by `rank` (descending).
|
|
552
|
+
*/
|
|
553
|
+
referrers: AwardedReferrerMetrics[];
|
|
554
|
+
/**
|
|
555
|
+
* Aggregated metrics for all referrers on the leaderboard.
|
|
556
|
+
*/
|
|
557
|
+
aggregatedMetrics: AggregatedReferrerMetrics;
|
|
558
|
+
/**
|
|
559
|
+
* The {@link ReferrerLeaderboardPageContext} of this {@link ReferrerLeaderboardPage} relative to the overall
|
|
560
|
+
* {@link ReferrerLeaderboard}.
|
|
561
|
+
*/
|
|
562
|
+
pageContext: ReferrerLeaderboardPageContext;
|
|
563
|
+
/**
|
|
564
|
+
* The {@link UnixTimestamp} of when the data used to build the {@link ReferrerLeaderboardPage} was accurate as of.
|
|
565
|
+
*/
|
|
566
|
+
accurateAsOf: UnixTimestamp;
|
|
567
|
+
}
|
|
568
|
+
declare const getReferrerLeaderboardPage: (pageParams: ReferrerLeaderboardPageParams, leaderboard: ReferrerLeaderboard) => ReferrerLeaderboardPage;
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Build a URL to the official ENS manager app
|
|
572
|
+
* where the given {@link Address} is set as the referrer.
|
|
573
|
+
*/
|
|
574
|
+
declare function buildEnsReferralUrl(address: Address): URL;
|
|
575
|
+
|
|
576
|
+
declare const isInteger: (value: number) => boolean;
|
|
577
|
+
declare const isNonNegativeInteger: (value: number) => boolean;
|
|
578
|
+
declare const isPositiveInteger: (value: number) => boolean;
|
|
579
|
+
declare const validateNonNegativeInteger: (value: number) => void;
|
|
580
|
+
declare const isFiniteNonNegativeNumber: (value: number) => boolean;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* The type of referrer detail data.
|
|
584
|
+
*/
|
|
585
|
+
declare const ReferrerDetailTypeIds: {
|
|
586
|
+
/**
|
|
587
|
+
* Represents a referrer who is ranked on the leaderboard.
|
|
588
|
+
*/
|
|
589
|
+
readonly Ranked: "ranked";
|
|
590
|
+
/**
|
|
591
|
+
* Represents a referrer who is not ranked on the leaderboard.
|
|
592
|
+
*/
|
|
593
|
+
readonly Unranked: "unranked";
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* The derived string union of possible {@link ReferrerDetailTypeIds}.
|
|
597
|
+
*/
|
|
598
|
+
type ReferrerDetailTypeId = (typeof ReferrerDetailTypeIds)[keyof typeof ReferrerDetailTypeIds];
|
|
599
|
+
/**
|
|
600
|
+
* Referrer detail data for a specific referrer address on the leaderboard.
|
|
601
|
+
*
|
|
602
|
+
* Includes the referrer's awarded metrics from the leaderboard plus timestamp.
|
|
603
|
+
*
|
|
604
|
+
* Invariants:
|
|
605
|
+
* - `type` is always {@link ReferrerDetailTypeIds.Ranked}.
|
|
606
|
+
*
|
|
607
|
+
* @see {@link AwardedReferrerMetrics}
|
|
608
|
+
*/
|
|
609
|
+
interface ReferrerDetailRanked {
|
|
610
|
+
/**
|
|
611
|
+
* The type of referrer detail data.
|
|
612
|
+
*/
|
|
613
|
+
type: typeof ReferrerDetailTypeIds.Ranked;
|
|
614
|
+
/**
|
|
615
|
+
* The {@link ReferralProgramRules} used to calculate the {@link AwardedReferrerMetrics}.
|
|
616
|
+
*/
|
|
617
|
+
rules: ReferralProgramRules;
|
|
618
|
+
/**
|
|
619
|
+
* The awarded referrer metrics from the leaderboard.
|
|
620
|
+
*
|
|
621
|
+
* Contains all calculated metrics including score, rank, qualification status,
|
|
622
|
+
* and award pool share information.
|
|
623
|
+
*/
|
|
624
|
+
referrer: AwardedReferrerMetrics;
|
|
625
|
+
/**
|
|
626
|
+
* Aggregated metrics for all referrers on the leaderboard.
|
|
627
|
+
*/
|
|
628
|
+
aggregatedMetrics: AggregatedReferrerMetrics;
|
|
629
|
+
/**
|
|
630
|
+
* The {@link UnixTimestamp} of when the data used to build the {@link ReferrerDetailData} was accurate as of.
|
|
631
|
+
*/
|
|
632
|
+
accurateAsOf: UnixTimestamp;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Referrer detail data for a specific referrer address NOT on the leaderboard.
|
|
636
|
+
*
|
|
637
|
+
* Includes the referrer's unranked metrics (with null rank and isQualified: false) plus timestamp.
|
|
638
|
+
*
|
|
639
|
+
* Invariants:
|
|
640
|
+
* - `type` is always {@link ReferrerDetailTypeIds.Unranked}.
|
|
641
|
+
*
|
|
642
|
+
* @see {@link UnrankedReferrerMetrics}
|
|
643
|
+
*/
|
|
644
|
+
interface ReferrerDetailUnranked {
|
|
645
|
+
/**
|
|
646
|
+
* The type of referrer detail data.
|
|
647
|
+
*/
|
|
648
|
+
type: typeof ReferrerDetailTypeIds.Unranked;
|
|
649
|
+
/**
|
|
650
|
+
* The {@link ReferralProgramRules} used to calculate the {@link UnrankedReferrerMetrics}.
|
|
651
|
+
*/
|
|
652
|
+
rules: ReferralProgramRules;
|
|
653
|
+
/**
|
|
654
|
+
* The unranked referrer metrics (not on the leaderboard).
|
|
655
|
+
*
|
|
656
|
+
* Contains all calculated metrics with rank set to null and isQualified set to false.
|
|
657
|
+
*/
|
|
658
|
+
referrer: UnrankedReferrerMetrics;
|
|
659
|
+
/**
|
|
660
|
+
* Aggregated metrics for all referrers on the leaderboard.
|
|
661
|
+
*/
|
|
662
|
+
aggregatedMetrics: AggregatedReferrerMetrics;
|
|
663
|
+
/**
|
|
664
|
+
* The {@link UnixTimestamp} of when the data used to build the {@link UnrankedReferrerDetailData} was accurate as of.
|
|
665
|
+
*/
|
|
666
|
+
accurateAsOf: UnixTimestamp;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Referrer detail data for a specific referrer address.
|
|
670
|
+
*
|
|
671
|
+
* Use the `type` field to determine the specific type interpretation
|
|
672
|
+
* at runtime.
|
|
673
|
+
*/
|
|
674
|
+
type ReferrerDetail = ReferrerDetailRanked | ReferrerDetailUnranked;
|
|
675
|
+
/**
|
|
676
|
+
* Get the detail for a specific referrer from the leaderboard.
|
|
677
|
+
*
|
|
678
|
+
* Returns a {@link ReferrerDetailRanked} if the referrer is on the leaderboard,
|
|
679
|
+
* or a {@link ReferrerDetailUnranked} if the referrer has no referrals.
|
|
680
|
+
*
|
|
681
|
+
* @param referrer - The referrer address to look up
|
|
682
|
+
* @param leaderboard - The referrer leaderboard to query
|
|
683
|
+
* @returns The appropriate {@link ReferrerDetail} (ranked or unranked)
|
|
684
|
+
*/
|
|
685
|
+
declare const getReferrerDetail: (referrer: Address, leaderboard: ReferrerLeaderboard) => ReferrerDetail;
|
|
686
|
+
|
|
687
|
+
export { type AccountId, type AggregatedReferrerMetrics, type AwardedReferrerMetrics, type ChainId, type Duration, ENCODED_REFERRER_BYTE_LENGTH, ENCODED_REFERRER_BYTE_OFFSET, ENS_HOLIDAY_AWARDS_END_DATE, ENS_HOLIDAY_AWARDS_MAX_QUALIFIED_REFERRERS, ENS_HOLIDAY_AWARDS_START_DATE, ENS_HOLIDAY_AWARDS_TOTAL_AWARD_POOL_VALUE, EXPECTED_ENCODED_REFERRER_PADDING, type EncodedReferrer, REFERRERS_PER_LEADERBOARD_PAGE_DEFAULT, REFERRERS_PER_LEADERBOARD_PAGE_MAX, type RankedReferrerMetrics, type ReferralProgramRules, type ReferrerDetail, type ReferrerDetailRanked, type ReferrerDetailTypeId, ReferrerDetailTypeIds, type ReferrerDetailUnranked, type ReferrerLeaderboard, type ReferrerLeaderboardPage, type ReferrerLeaderboardPageContext, type ReferrerLeaderboardPageParams, type ReferrerMetrics, type ReferrerMetricsForComparison, type ReferrerRank, type ReferrerScore, type RevenueContribution, SECONDS_PER_YEAR, type ScoredReferrerMetrics, type USDQuantity, type UnixTimestamp, type UnrankedReferrerMetrics, ZERO_ENCODED_REFERRER, buildAggregatedReferrerMetrics, buildAwardedReferrerMetrics, buildEncodedReferrer, buildEnsReferralUrl, buildRankedReferrerMetrics, buildReferralProgramRules, buildReferrerLeaderboard, buildReferrerLeaderboardPageContext, buildReferrerLeaderboardPageParams, buildReferrerMetrics, buildScoredReferrerMetrics, buildUnrankedReferrerMetrics, calcReferrerAwardPoolShare, calcReferrerFinalScore, calcReferrerFinalScoreBoost, calcReferrerFinalScoreMultiplier, calcReferrerScore, compareReferrerMetrics, decodeEncodedReferrer, getReferrerDetail, getReferrerLeaderboardPage, isFiniteNonNegativeNumber, isInteger, isNonNegativeInteger, isPositiveInteger, isReferrerQualified, isValidDuration, isValidReferrerScore, isValidRevenueContribution, isValidUSDQuantity, normalizeAddress, sortReferrerMetrics, validateAggregatedReferrerMetrics, validateAwardedReferrerMetrics, validateDuration, validateLowercaseAddress, validateNonNegativeInteger, validateRankedReferrerMetrics, validateReferralProgramRules, validateReferrerLeaderboardPageContext, validateReferrerMetrics, validateReferrerRank, validateReferrerScore, validateRevenueContribution, validateScoredReferrerMetrics, validateUSDQuantity, validateUnixTimestamp, validateUnrankedReferrerMetrics };
|