@namehash/ens-referrals 1.9.0 → 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.
@@ -1,2098 +0,0 @@
1
- import { Address } from 'viem';
2
- import { UnixTimestamp, AccountId, PriceUsdc, Duration, PriceEth, SerializedPriceEth, SerializedPriceUsdc, ENSNamespaceId } from '@ensnode/ensnode-sdk';
3
-
4
- declare const validateLowercaseAddress: (address: Address) => void;
5
- declare const normalizeAddress: (address: Address) => Address;
6
-
7
- /**
8
- * Discriminant values for the award model used in a referral program edition.
9
- *
10
- * @remarks Clients MUST check `awardModel` before accessing model-specific fields.
11
- * Editions with unrecognized `awardModel` values are preserved as
12
- * {@link ReferralProgramRulesUnrecognized} during parsing (see
13
- * `makeReferralProgramEditionConfigSetArraySchema`). Clients must handle this variant — typically
14
- * by skipping those editions with a warning log rather than crashing.
15
- */
16
- declare const ReferralProgramAwardModels: {
17
- readonly PieSplit: "pie-split";
18
- readonly RevShareLimit: "rev-share-limit";
19
- readonly Unrecognized: "unrecognized";
20
- };
21
- type ReferralProgramAwardModel = (typeof ReferralProgramAwardModels)[keyof typeof ReferralProgramAwardModels];
22
- /**
23
- * Base fields shared across all referral program rule types.
24
- *
25
- * Both `ReferralProgramRulesPieSplit` and `ReferralProgramRulesRevShareLimit` are structurally
26
- * compatible with this interface, so it can be used wherever only the common fields are needed
27
- * (e.g., `assertLeaderboardInputs`).
28
- */
29
- interface BaseReferralProgramRules {
30
- /**
31
- * Discriminant: identifies the award model for this edition.
32
- */
33
- awardModel: ReferralProgramAwardModel;
34
- /**
35
- * The start time of the referral program.
36
- */
37
- startTime: UnixTimestamp;
38
- /**
39
- * The end time of the referral program.
40
- * @invariant Guaranteed to be greater than or equal to `startTime`
41
- */
42
- endTime: UnixTimestamp;
43
- /**
44
- * The account ID of the subregistry for the referral program.
45
- */
46
- subregistryId: AccountId;
47
- /**
48
- * URL to the full rules document for these rules.
49
- * @example new URL("https://ensawards.org/ens-holiday-awards-rules")
50
- */
51
- rulesUrl: URL;
52
- /**
53
- * Whether the awards for this edition have been distributed.
54
- *
55
- * When `true` and `now > endTime`, the status transitions from `AwardsReview` to `Closed`.
56
- */
57
- areAwardsDistributed: boolean;
58
- }
59
- /**
60
- * Rules for a referral program edition whose `awardModel` is not recognized by this client version.
61
- *
62
- * @remarks
63
- * This is a **client-side forward-compatibility** type only. It is never serialized or processed
64
- * by business logic on the backend. When the server introduces a new award model type, older
65
- * clients preserve the edition rather than silently dropping it, and downstream code that
66
- * encounters this type should skip it with a warning log rather than crashing.
67
- */
68
- interface ReferralProgramRulesUnrecognized extends BaseReferralProgramRules {
69
- /**
70
- * Discriminant — always `"unrecognized"`.
71
- */
72
- awardModel: typeof ReferralProgramAwardModels.Unrecognized;
73
- /**
74
- * The original, unrecognized `awardModel` string received from the server.
75
- *
76
- * @remarks Preserved for logging and debugging. Never used for business logic.
77
- */
78
- originalAwardModel: string;
79
- }
80
- declare const validateBaseReferralProgramRules: (rules: BaseReferralProgramRules) => void;
81
-
82
- interface ReferralProgramRulesPieSplit extends BaseReferralProgramRules {
83
- /**
84
- * Discriminant: identifies this as a "pie-split" award model edition.
85
- *
86
- * In pie-split, the top-N referrers split an award pool proportionally
87
- * based on their scored duration (with rank-based boost).
88
- */
89
- awardModel: typeof ReferralProgramAwardModels.PieSplit;
90
- /**
91
- * The total value of the award pool in USDC.
92
- *
93
- * NOTE: Awards will actually be distributed in $ENS tokens.
94
- */
95
- totalAwardPoolValue: PriceUsdc;
96
- /**
97
- * The maximum number of referrers that will qualify to receive a non-zero `awardPoolShare`.
98
- *
99
- * @invariant Guaranteed to be a non-negative integer (>= 0)
100
- */
101
- maxQualifiedReferrers: number;
102
- }
103
- declare const validateReferralProgramRulesPieSplit: (rules: ReferralProgramRulesPieSplit) => void;
104
- declare const buildReferralProgramRulesPieSplit: (totalAwardPoolValue: PriceUsdc, maxQualifiedReferrers: number, startTime: UnixTimestamp, endTime: UnixTimestamp, subregistryId: AccountId, rulesUrl: URL, areAwardsDistributed: boolean) => ReferralProgramRulesPieSplit;
105
-
106
- /**
107
- * An admin-imposed disqualification entry of a specific referrer in an edition.
108
- */
109
- interface ReferralProgramEditionDisqualification {
110
- /**
111
- * The address of the disqualified referrer.
112
- *
113
- * @invariant Guaranteed to be a valid EVM address in lowercase format.
114
- */
115
- referrer: Address;
116
- /**
117
- * A human-readable explanation of why the referrer was disqualified.
118
- *
119
- * @invariant Must be a non-empty string.
120
- */
121
- reason: string;
122
- }
123
- /**
124
- * Base revenue contribution per year of incremental duration.
125
- *
126
- * Used in `rev-share-limit` qualification and award calculations:
127
- * 1 year of incremental duration = $5 in base revenue (base-fee-only, excluding premiums).
128
- */
129
- declare const BASE_REVENUE_CONTRIBUTION_PER_YEAR: PriceUsdc;
130
- interface ReferralProgramRulesRevShareLimit extends BaseReferralProgramRules {
131
- /**
132
- * Discriminant: identifies this as a "rev-share-limit" award model edition.
133
- *
134
- * In rev-share-limit, each qualified referrer receives a share of their base revenue
135
- * contribution (base-fee-only: $5 × years of incremental duration), subject to a
136
- * pool cap and a minimum qualification threshold.
137
- */
138
- awardModel: typeof ReferralProgramAwardModels.RevShareLimit;
139
- /**
140
- * The total value of the award pool in USDC (acts as a cap on total payouts).
141
- */
142
- totalAwardPoolValue: PriceUsdc;
143
- /**
144
- * The minimum base revenue contribution required for a referrer to qualify.
145
- */
146
- minQualifiedRevenueContribution: PriceUsdc;
147
- /**
148
- * The fraction of the referrer's base revenue contribution that constitutes their potential award.
149
- *
150
- * @invariant Guaranteed to be a number between 0 and 1 (inclusive)
151
- */
152
- qualifiedRevenueShare: number;
153
- /**
154
- * Admin-imposed disqualifications for this edition.
155
- * Disqualified referrers receive no awards.
156
- *
157
- * @invariant No duplicate referrer addresses.
158
- */
159
- disqualifications: ReferralProgramEditionDisqualification[];
160
- }
161
- declare const validateReferralProgramRulesRevShareLimit: (rules: ReferralProgramRulesRevShareLimit) => void;
162
- declare const buildReferralProgramRulesRevShareLimit: (totalAwardPoolValue: PriceUsdc, minQualifiedRevenueContribution: PriceUsdc, qualifiedRevenueShare: number, startTime: UnixTimestamp, endTime: UnixTimestamp, subregistryId: AccountId, rulesUrl: URL, areAwardsDistributed: boolean, disqualifications?: ReferralProgramEditionDisqualification[]) => ReferralProgramRulesRevShareLimit;
163
- /**
164
- * Determine if a referrer is qualified under rev-share-limit rules.
165
- *
166
- * A referrer is qualified if they meet the revenue threshold AND are not admin-disqualified.
167
- *
168
- * @param referrer - The referrer's address.
169
- * @param totalBaseRevenueContribution - The referrer's total base revenue contribution.
170
- * @param rules - The rev-share-limit rules of the referral program.
171
- */
172
- declare function isReferrerQualifiedRevShareLimit(referrer: Address, totalBaseRevenueContribution: PriceUsdc, rules: ReferralProgramRulesRevShareLimit): boolean;
173
-
174
- /**
175
- * The rules of a referral program edition.
176
- *
177
- * Use `awardModel` to discriminate between rule types at runtime:
178
- * - `"pie-split"` → {@link ReferralProgramRulesPieSplit}
179
- * - `"rev-share-limit"` → {@link ReferralProgramRulesRevShareLimit}
180
- * - `"unrecognized"` → {@link ReferralProgramRulesUnrecognized} (client-side forward-compatibility
181
- * placeholder for editions whose `awardModel` string is not known to this client version)
182
- *
183
- * Internal business logic only handles the known variants (`pie-split`, `rev-share-limit`).
184
- * Unrecognized editions should be skipped with a warning log rather than crashing.
185
- */
186
- type ReferralProgramRules = ReferralProgramRulesPieSplit | ReferralProgramRulesRevShareLimit | ReferralProgramRulesUnrecognized;
187
-
188
- /**
189
- * Referral program edition slug.
190
- *
191
- * A URL-safe identifier for a referral program edition. Each edition represents
192
- * a distinct referral program period with its own rules, leaderboard, and
193
- * award distribution.
194
- *
195
- * @invariant Must contain only lowercase letters (a-z), digits (0-9), and hyphens (-).
196
- * Must not start or end with a hyphen. Pattern: `^[a-z0-9]+(-[a-z0-9]+)*$`
197
- *
198
- * @example "2025-12" // December 2025 edition
199
- * @example "2026-03" // March 2026 edition
200
- * @example "holiday-special" // Custom named edition
201
- */
202
- type ReferralProgramEditionSlug = string;
203
- /**
204
- * Regex pattern that all {@link ReferralProgramEditionSlug} values must match.
205
- *
206
- * Allows lowercase letters (a-z), digits (0-9), and hyphens (-).
207
- * Must not start or end with a hyphen.
208
- */
209
- declare const REFERRAL_PROGRAM_EDITION_SLUG_PATTERN: RegExp;
210
- /**
211
- * Represents a referral program edition configuration.
212
- */
213
- interface ReferralProgramEditionConfig {
214
- /**
215
- * Unique slug identifier for the edition.
216
- */
217
- slug: ReferralProgramEditionSlug;
218
- /**
219
- * Human-readable display name for the edition.
220
- * @example "ENS Holiday Awards"
221
- */
222
- displayName: string;
223
- /**
224
- * The rules that govern this referral program edition.
225
- */
226
- rules: ReferralProgramRules;
227
- }
228
- /**
229
- * A map from edition slug to edition configuration.
230
- *
231
- * Used to store and look up all configured referral program editions.
232
- *
233
- * @invariant For each key-value pair in the map, the key must equal the value's slug property.
234
- * That is, for all entries: `map.get(key)?.slug === key`
235
- */
236
- type ReferralProgramEditionConfigSet = Map<ReferralProgramEditionSlug, ReferralProgramEditionConfig>;
237
- /**
238
- * Validates that a ReferralProgramEditionConfigSet maintains the invariant
239
- * that each map key equals the corresponding config's slug.
240
- *
241
- * @param configSet - The edition config set to validate
242
- * @throws {Error} If any entry violates the invariant (key !== value.slug)
243
- */
244
- declare function validateReferralProgramEditionConfigSet(configSet: ReferralProgramEditionConfigSet): void;
245
- /**
246
- * Builds a new ReferralProgramEditionConfigSet from an array of configs and validates the invariant.
247
- *
248
- * @param configs - Array of edition configurations to add to the set
249
- * @returns A validated edition config set
250
- * @throws {Error} If duplicate slugs are detected or if any config would violate the invariant
251
- */
252
- declare function buildReferralProgramEditionConfigSet(configs: ReferralProgramEditionConfig[]): ReferralProgramEditionConfigSet;
253
-
254
- /**
255
- * The score of a referrer.
256
- *
257
- * @invariant Guaranteed to be a finite non-negative number (>= 0)
258
- */
259
- type ReferrerScore = number;
260
- declare const isValidReferrerScore: (score: ReferrerScore) => boolean;
261
- declare const validateReferrerScore: (score: ReferrerScore) => void;
262
-
263
- /**
264
- * Metrics for a single referrer, as aggregated from the DB layer.
265
- * Independent of other referrers and award model; does not carry an `awardModel` discriminant.
266
- */
267
- interface ReferrerMetrics {
268
- /**
269
- * The fully lowercase Ethereum address of the referrer.
270
- *
271
- * @invariant Guaranteed to be a valid EVM address in lowercase format
272
- */
273
- referrer: Address;
274
- /**
275
- * The total number of referrals made by the referrer within the {@link ReferralProgramRules}.
276
- * @invariant Guaranteed to be a non-negative integer (>= 0)
277
- */
278
- totalReferrals: number;
279
- /**
280
- * The total incremental duration (in seconds) of all referrals made by the referrer within
281
- * the {@link ReferralProgramRules}.
282
- */
283
- totalIncrementalDuration: Duration;
284
- /**
285
- * The total revenue contribution in ETH made to the ENS DAO by all referrals
286
- * from this referrer.
287
- *
288
- * This is the sum of the total cost paid by registrants for all registrar actions
289
- * where this address was the referrer.
290
- *
291
- * @invariant Guaranteed to be a valid PriceEth with non-negative amount (>= 0n)
292
- * @invariant Never null (records with null `total` in the database are treated as 0 when summing)
293
- */
294
- totalRevenueContribution: PriceEth;
295
- }
296
- declare const buildReferrerMetrics: (referrer: Address, totalReferrals: number, totalIncrementalDuration: Duration, totalRevenueContribution: PriceEth) => ReferrerMetrics;
297
- declare const validateReferrerMetrics: (metrics: ReferrerMetrics) => void;
298
-
299
- /**
300
- * The rank of a referrer relative to all other referrers, where 1 is the
301
- * top-ranked referrer.
302
- *
303
- * @invariant Guaranteed to be a positive integer (> 0)
304
- */
305
- type ReferrerRank = number;
306
- declare const validateReferrerRank: (rank: ReferrerRank) => void;
307
- interface ReferrerMetricsForComparison {
308
- /**
309
- * The total incremental duration (in seconds) of all referrals made by the referrer within
310
- * the {@link ReferralProgramRules}.
311
- */
312
- totalIncrementalDuration: Duration;
313
- /**
314
- * The fully lowercase Ethereum address of the referrer.
315
- *
316
- * @invariant Guaranteed to be a valid EVM address in lowercase format.
317
- */
318
- referrer: Address;
319
- }
320
- declare const compareReferrerMetrics: (a: ReferrerMetricsForComparison, b: ReferrerMetricsForComparison) => number;
321
- /**
322
- * Sorts a list of referrers for leaderboard ranking.
323
- * Returns a new array — does not mutate the input.
324
- */
325
- declare const sortReferrerMetrics: (referrers: ReferrerMetrics[]) => ReferrerMetrics[];
326
-
327
- /**
328
- * Represents metrics for a single referrer independent of other referrers,
329
- * including a calculation of the referrer's score.
330
- */
331
- interface ScoredReferrerMetricsPieSplit extends ReferrerMetrics {
332
- /**
333
- * The referrer's score.
334
- *
335
- * @invariant Guaranteed to be `calcReferrerScorePieSplit(totalIncrementalDuration)`
336
- */
337
- score: ReferrerScore;
338
- }
339
- declare const buildScoredReferrerMetricsPieSplit: (referrer: ReferrerMetrics) => ScoredReferrerMetricsPieSplit;
340
- declare const validateScoredReferrerMetricsPieSplit: (metrics: ScoredReferrerMetricsPieSplit) => void;
341
- /**
342
- * Extends {@link ScoredReferrerMetricsPieSplit} to include additional metrics relative to all
343
- * other referrers on a {@link ReferrerLeaderboardPieSplit} and {@link ReferralProgramRulesPieSplit}.
344
- */
345
- interface RankedReferrerMetricsPieSplit extends ScoredReferrerMetricsPieSplit {
346
- /**
347
- * The referrer's rank on the {@link ReferrerLeaderboardPieSplit} relative to all other referrers.
348
- */
349
- rank: ReferrerRank;
350
- /**
351
- * Identifies if the referrer meets the qualifications of the {@link ReferralProgramRulesPieSplit} to receive a non-zero `awardPoolShare`.
352
- *
353
- * @invariant true if and only if `rank` is less than or equal to {@link ReferralProgramRulesPieSplit.maxQualifiedReferrers}
354
- */
355
- isQualified: boolean;
356
- /**
357
- * The referrer's final score boost.
358
- *
359
- * @invariant Guaranteed to be a number between 0 and 1 (inclusive)
360
- * @invariant Calculated as: `1-((rank-1)/({@link ReferralProgramRulesPieSplit.maxQualifiedReferrers}-1))` if `isQualified` is `true`, else `0`
361
- */
362
- finalScoreBoost: number;
363
- /**
364
- * The referrer's final score.
365
- *
366
- * @invariant Calculated as: `score * (1 + finalScoreBoost)`
367
- */
368
- finalScore: ReferrerScore;
369
- }
370
- declare const validateRankedReferrerMetricsPieSplit: (metrics: RankedReferrerMetricsPieSplit, rules: ReferralProgramRulesPieSplit) => void;
371
- declare const buildRankedReferrerMetricsPieSplit: (referrer: ScoredReferrerMetricsPieSplit, rank: ReferrerRank, rules: ReferralProgramRulesPieSplit) => RankedReferrerMetricsPieSplit;
372
- /**
373
- * Calculate the share of the award pool for a referrer.
374
- * @param referrer - The referrer to calculate the award pool share for.
375
- * @param aggregatedMetrics - Aggregated metrics for all referrers.
376
- * @returns The referrer's share of the award pool as a number between 0 and 1 (inclusive).
377
- */
378
- declare const calcReferrerAwardPoolSharePieSplit: (referrer: RankedReferrerMetricsPieSplit, aggregatedMetrics: AggregatedReferrerMetricsPieSplit) => number;
379
- /**
380
- * Extends {@link RankedReferrerMetricsPieSplit} to include additional metrics
381
- * relative to {@link AggregatedReferrerMetricsPieSplit}.
382
- */
383
- interface AwardedReferrerMetricsPieSplit extends RankedReferrerMetricsPieSplit {
384
- /**
385
- * The referrer's share of the award pool.
386
- *
387
- * @invariant Guaranteed to be a number between 0 and 1 (inclusive)
388
- * @invariant Calculated as: `finalScore / {@link AggregatedReferrerMetricsPieSplit.grandTotalQualifiedReferrersFinalScore}` if `isQualified` is `true`, else `0`
389
- */
390
- awardPoolShare: number;
391
- /**
392
- * The approximate USDC value of the referrer's share of the {@link ReferralProgramRulesPieSplit.totalAwardPoolValue}.
393
- *
394
- * @invariant Guaranteed to be a valid PriceUsdc with amount between 0 and {@link ReferralProgramRulesPieSplit.totalAwardPoolValue.amount} (inclusive)
395
- * @invariant Calculated as: `awardPoolShare` * {@link ReferralProgramRulesPieSplit.totalAwardPoolValue.amount}
396
- */
397
- awardPoolApproxValue: PriceUsdc;
398
- }
399
- declare const validateAwardedReferrerMetricsPieSplit: (referrer: AwardedReferrerMetricsPieSplit, rules: ReferralProgramRulesPieSplit) => void;
400
- declare const buildAwardedReferrerMetricsPieSplit: (referrer: RankedReferrerMetricsPieSplit, aggregatedMetrics: AggregatedReferrerMetricsPieSplit, rules: ReferralProgramRulesPieSplit) => AwardedReferrerMetricsPieSplit;
401
- /**
402
- * Extends {@link AwardedReferrerMetricsPieSplit} but with rank set to null to represent
403
- * a referrer who is not on the leaderboard (has zero referrals within the rules associated with the leaderboard).
404
- */
405
- interface UnrankedReferrerMetricsPieSplit extends Omit<AwardedReferrerMetricsPieSplit, "rank" | "isQualified"> {
406
- /**
407
- * The referrer is not on the leaderboard and therefore has no rank.
408
- */
409
- rank: null;
410
- /**
411
- * Always false for unranked referrers.
412
- */
413
- isQualified: false;
414
- }
415
- declare const validateUnrankedReferrerMetricsPieSplit: (metrics: UnrankedReferrerMetricsPieSplit) => void;
416
- /**
417
- * Build an unranked zero-score referrer record for a referrer address that is not in the leaderboard.
418
- *
419
- * This is useful when you want to return a referrer record for an address that has no referrals
420
- * and is not qualified for the leaderboard.
421
- *
422
- * @param referrer - The referrer address
423
- * @returns An {@link UnrankedReferrerMetricsPieSplit} with zero values for all metrics and null rank
424
- */
425
- declare const buildUnrankedReferrerMetricsPieSplit: (referrer: Address) => UnrankedReferrerMetricsPieSplit;
426
-
427
- /**
428
- * Represents aggregated metrics for a list of {@link RankedReferrerMetricsPieSplit}.
429
- */
430
- interface AggregatedReferrerMetricsPieSplit {
431
- /**
432
- * @invariant The sum of `totalReferrals` across all {@link RankedReferrerMetricsPieSplit} in the list.
433
- * @invariant Guaranteed to be a non-negative integer (>= 0)
434
- */
435
- grandTotalReferrals: number;
436
- /**
437
- * @invariant The sum of `totalIncrementalDuration` across all {@link RankedReferrerMetricsPieSplit} in the list.
438
- */
439
- grandTotalIncrementalDuration: Duration;
440
- /**
441
- * The total revenue contribution in ETH to the ENS DAO from all referrals
442
- * across all referrers on the leaderboard.
443
- *
444
- * This is the sum of `totalRevenueContribution` across all {@link RankedReferrerMetricsPieSplit} in the list.
445
- *
446
- * @invariant Guaranteed to be a valid PriceEth with non-negative amount (>= 0n)
447
- */
448
- grandTotalRevenueContribution: PriceEth;
449
- /**
450
- * @invariant The sum of `finalScore` across all {@link RankedReferrerMetricsPieSplit} where `isQualified` is `true`.
451
- */
452
- grandTotalQualifiedReferrersFinalScore: ReferrerScore;
453
- /**
454
- * @invariant Identifies the minimum final score required to become a qualified referrer.
455
- * @invariant If `rules.maxQualifiedReferrers` is 0, then `minFinalScoreToQualify` is guaranteed to
456
- * be `Number.MAX_SAFE_INTEGER`.
457
- * @invariant If `rules.maxQualifiedReferrers` is greater than 0, and there are no current referrers
458
- * matching the `rules`, then `minFinalScoreToQualify` is guaranteed to be `0`.
459
- */
460
- minFinalScoreToQualify: ReferrerScore;
461
- }
462
- declare const validateAggregatedReferrerMetricsPieSplit: (metrics: AggregatedReferrerMetricsPieSplit) => void;
463
- /**
464
- * Builds aggregated pie-split metrics from a complete, globally ranked list of referrers.
465
- *
466
- * **IMPORTANT: This function expects a complete ranking of all referrers.**
467
- *
468
- * @param referrers - Must be a complete, globally ranked list of {@link RankedReferrerMetricsPieSplit}
469
- * where ranks start at 1 and are consecutive.
470
- * **This must NOT be a paginated or partial slice of the rankings.**
471
- *
472
- * @param rules - The {@link ReferralProgramRulesPieSplit} object that define qualification criteria,
473
- * including `maxQualifiedReferrers` (the maximum number of referrers
474
- * that can qualify for rewards).
475
- *
476
- * @returns Aggregated metrics including totals across all referrers and the minimum
477
- * score required to qualify.
478
- *
479
- * @remarks
480
- * - If you need to work with paginated data, aggregate the full ranking first before
481
- * calling this function, or call this function on the complete dataset and then paginate
482
- * the results.
483
- * - If `rules.maxQualifiedReferrers === 0`, no referrers can qualify and
484
- * `minFinalScoreToQualify` will be set to `Number.MAX_SAFE_INTEGER`.
485
- * - If `referrers` is empty and `rules.maxQualifiedReferrers > 0`,
486
- * `minFinalScoreToQualify` will be set to `0` (anyone can qualify).
487
- */
488
- declare const buildAggregatedReferrerMetricsPieSplit: (referrers: RankedReferrerMetricsPieSplit[], rules: ReferralProgramRulesPieSplit) => AggregatedReferrerMetricsPieSplit;
489
-
490
- /**
491
- * The type of referrer edition metrics data.
492
- */
493
- declare const ReferrerEditionMetricsTypeIds: {
494
- /**
495
- * Represents a referrer who is ranked on the leaderboard.
496
- */
497
- readonly Ranked: "ranked";
498
- /**
499
- * Represents a referrer who is not ranked on the leaderboard.
500
- */
501
- readonly Unranked: "unranked";
502
- };
503
- /**
504
- * The derived string union of possible {@link ReferrerEditionMetricsTypeIds}.
505
- */
506
- type ReferrerEditionMetricsTypeId = (typeof ReferrerEditionMetricsTypeIds)[keyof typeof ReferrerEditionMetricsTypeIds];
507
- /**
508
- * Referrer edition metrics for an edition whose `awardModel` is not recognized by this client version.
509
- *
510
- * @remarks
511
- * This is a **client-side forward-compatibility** type only. It is never serialized or processed
512
- * by business logic on the backend. When the server introduces a new award model type, older
513
- * clients preserve the metrics rather than throwing, and downstream code that encounters this type
514
- * should handle it gracefully rather than crashing.
515
- */
516
- interface ReferrerEditionMetricsUnrecognized {
517
- /**
518
- * Discriminant — always `"unrecognized"`.
519
- */
520
- awardModel: typeof ReferralProgramAwardModels.Unrecognized;
521
- /**
522
- * The original, unrecognized `awardModel` string received from the server.
523
- *
524
- * @remarks Preserved for logging and debugging. Never used for business logic.
525
- */
526
- originalAwardModel: string;
527
- }
528
-
529
- /**
530
- * The type of referral program edition's status.
531
- */
532
- declare const ReferralProgramEditionStatuses: {
533
- /**
534
- * Represents a referral program edition that has been announced, but hasn't started yet.
535
- */
536
- readonly Scheduled: "Scheduled";
537
- /**
538
- * Represents a currently ongoing referral program edition.
539
- */
540
- readonly Active: "Active";
541
- /**
542
- * Represents a referral program edition that is still within its active window
543
- * but whose award pool has been fully consumed.
544
- *
545
- * @note Not all award models may support this status.
546
- */
547
- readonly Exhausted: "Exhausted";
548
- /**
549
- * Represents a referral program edition that has passed its end time but whose awards have not yet
550
- * been distributed. The edition is in a review window before full closure.
551
- *
552
- * Transitions to {@link ReferralProgramEditionStatuses.Closed} once `areAwardsDistributed` is set to `true`.
553
- */
554
- readonly AwardsReview: "AwardsReview";
555
- /**
556
- * Represents a referral program edition that has already ended and whose awards have been distributed.
557
- */
558
- readonly Closed: "Closed";
559
- };
560
- /**
561
- * The derived string union of possible {@link ReferralProgramEditionStatuses}.
562
- */
563
- type ReferralProgramEditionStatusId = (typeof ReferralProgramEditionStatuses)[keyof typeof ReferralProgramEditionStatuses];
564
- /**
565
- * Calculate the base status of a referral program edition using only its rules and
566
- * the current time (makes no consideration of the awards possibly being exhausted).
567
- *
568
- * @param rules - Related referral program's rules containing program's start/end date and
569
- * `areAwardsDistributed` flag.
570
- * @param now - Current date in {@link UnixTimestamp} format.
571
- */
572
- declare const calcBaseReferralProgramEditionStatus: (rules: BaseReferralProgramRules, now: UnixTimestamp) => ReferralProgramEditionStatusId;
573
-
574
- /**
575
- * Referrer edition metrics data for a specific referrer address on the pie-split leaderboard.
576
- *
577
- * Includes the referrer's awarded metrics from the leaderboard plus timestamp.
578
- *
579
- * Invariants:
580
- * - `type` is always {@link ReferrerEditionMetricsTypeIds.Ranked}.
581
- * - `awardModel` is always {@link ReferralProgramAwardModels.PieSplit} and equals `rules.awardModel`.
582
- *
583
- * @see {@link AwardedReferrerMetricsPieSplit}
584
- */
585
- interface ReferrerEditionMetricsRankedPieSplit {
586
- /**
587
- * Discriminant identifying this as data from a pie-split leaderboard edition.
588
- *
589
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.PieSplit}).
590
- */
591
- awardModel: typeof ReferralProgramAwardModels.PieSplit;
592
- /**
593
- * The type of referrer edition metrics data.
594
- */
595
- type: typeof ReferrerEditionMetricsTypeIds.Ranked;
596
- /**
597
- * The {@link ReferralProgramRulesPieSplit} used to calculate the {@link AwardedReferrerMetricsPieSplit}.
598
- */
599
- rules: ReferralProgramRulesPieSplit;
600
- /**
601
- * The awarded referrer metrics from the leaderboard.
602
- *
603
- * Contains all calculated metrics including score, rank, qualification status,
604
- * and award pool share information.
605
- */
606
- referrer: AwardedReferrerMetricsPieSplit;
607
- /**
608
- * Aggregated metrics for all referrers on the leaderboard.
609
- */
610
- aggregatedMetrics: AggregatedReferrerMetricsPieSplit;
611
- /**
612
- * The status of the referral program edition
613
- * calculated based on the program's timing relative to {@link accurateAsOf}.
614
- */
615
- status: ReferralProgramEditionStatusId;
616
- /**
617
- * The {@link UnixTimestamp} of when the data used to build the {@link ReferrerEditionMetricsRankedPieSplit} was accurate as of.
618
- */
619
- accurateAsOf: UnixTimestamp;
620
- }
621
- /**
622
- * Referrer edition metrics data for a specific referrer address NOT on the pie-split leaderboard.
623
- *
624
- * Includes the referrer's unranked metrics (with null rank and isQualified: false) plus timestamp.
625
- *
626
- * Invariants:
627
- * - `type` is always {@link ReferrerEditionMetricsTypeIds.Unranked}.
628
- * - `awardModel` is always {@link ReferralProgramAwardModels.PieSplit} and equals `rules.awardModel`.
629
- *
630
- * @see {@link UnrankedReferrerMetricsPieSplit}
631
- */
632
- interface ReferrerEditionMetricsUnrankedPieSplit {
633
- /**
634
- * Discriminant identifying this as data from a pie-split leaderboard edition.
635
- *
636
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.PieSplit}).
637
- */
638
- awardModel: typeof ReferralProgramAwardModels.PieSplit;
639
- /**
640
- * The type of referrer edition metrics data.
641
- */
642
- type: typeof ReferrerEditionMetricsTypeIds.Unranked;
643
- /**
644
- * The {@link ReferralProgramRulesPieSplit} used to calculate the {@link UnrankedReferrerMetricsPieSplit}.
645
- */
646
- rules: ReferralProgramRulesPieSplit;
647
- /**
648
- * The unranked referrer metrics (not on the leaderboard).
649
- *
650
- * Contains all calculated metrics with rank set to null and isQualified set to false.
651
- */
652
- referrer: UnrankedReferrerMetricsPieSplit;
653
- /**
654
- * Aggregated metrics for all referrers on the leaderboard.
655
- */
656
- aggregatedMetrics: AggregatedReferrerMetricsPieSplit;
657
- /**
658
- * The status of the referral program edition
659
- * calculated based on the program's timing relative to {@link accurateAsOf}.
660
- */
661
- status: ReferralProgramEditionStatusId;
662
- /**
663
- * The {@link UnixTimestamp} of when the data used to build the {@link ReferrerEditionMetricsUnrankedPieSplit} was accurate as of.
664
- */
665
- accurateAsOf: UnixTimestamp;
666
- }
667
- /**
668
- * All referrer edition metrics variants for the pie-split award model.
669
- *
670
- * Use `type` to determine if the referrer is ranked or unranked.
671
- */
672
- type ReferrerEditionMetricsPieSplit = ReferrerEditionMetricsRankedPieSplit | ReferrerEditionMetricsUnrankedPieSplit;
673
-
674
- /**
675
- * Base fields shared by all edition summary variants.
676
- */
677
- interface BaseReferralProgramEditionSummary {
678
- /**
679
- * Discriminant: identifies the award model for this edition.
680
- *
681
- * @invariant Always equals `rules.awardModel`.
682
- */
683
- awardModel: ReferralProgramAwardModel;
684
- /**
685
- * Unique slug identifier for the edition.
686
- */
687
- slug: ReferralProgramEditionSlug;
688
- /**
689
- * Human-readable display name for the edition.
690
- */
691
- displayName: string;
692
- /**
693
- * The current runtime status of the edition.
694
- */
695
- status: ReferralProgramEditionStatusId;
696
- /**
697
- * The rules for this edition. Per-model subtypes narrow this to their specific rules type.
698
- */
699
- rules: BaseReferralProgramRules;
700
- }
701
- /**
702
- * Edition summary for an edition whose `awardModel` is not recognized by this client version.
703
- *
704
- * @remarks
705
- * This is a **client-side forward-compatibility** type only. It is never serialized or produced
706
- * by the server. When the server sends a new award model, older clients preserve the edition
707
- * summary rather than crashing, and downstream code should handle it gracefully.
708
- */
709
- interface ReferralProgramEditionSummaryUnrecognized extends BaseReferralProgramEditionSummary {
710
- /**
711
- * Discriminant — always `"unrecognized"`.
712
- */
713
- awardModel: typeof ReferralProgramAwardModels.Unrecognized;
714
- /**
715
- * The unrecognized rules — preserves `originalAwardModel` for logging/debugging.
716
- */
717
- rules: ReferralProgramRulesUnrecognized;
718
- }
719
- declare const validateBaseReferralProgramEditionSummary: (summary: BaseReferralProgramEditionSummary) => void;
720
-
721
- /**
722
- * Represents a leaderboard with the pie-split award model for any number of referrers.
723
- */
724
- interface ReferrerLeaderboardPieSplit {
725
- /**
726
- * Discriminant identifying this as a pie-split leaderboard.
727
- *
728
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.PieSplit}).
729
- */
730
- awardModel: typeof ReferralProgramAwardModels.PieSplit;
731
- /**
732
- * The rules of the referral program that generated the {@link ReferrerLeaderboardPieSplit}.
733
- */
734
- rules: ReferralProgramRulesPieSplit;
735
- /**
736
- * The {@link AggregatedReferrerMetricsPieSplit} for all {@link RankedReferrerMetricsPieSplit} values in `referrers`.
737
- */
738
- aggregatedMetrics: AggregatedReferrerMetricsPieSplit;
739
- /**
740
- * Ordered map containing `AwardedReferrerMetricsPieSplit` for all referrers with 1 or more
741
- * `totalReferrals` within the `rules` as of `accurateAsOf`.
742
- *
743
- * @invariant Map entries are ordered by `rank` (ascending).
744
- * @invariant Map is empty if there are no referrers with 1 or more `totalReferrals`
745
- * within the `rules` as of `accurateAsOf`.
746
- * @invariant If a fully-lowercase `Address` is not a key in this map then that `Address` had
747
- * 0 `totalReferrals`, `totalIncrementalDuration`, and `score` within the
748
- * `rules` as of `accurateAsOf`.
749
- * @invariant Each value in this map is guaranteed to have a non-zero
750
- * `totalReferrals`, `totalIncrementalDuration`, and `score`.
751
- */
752
- referrers: Map<Address, AwardedReferrerMetricsPieSplit>;
753
- /**
754
- * The {@link UnixTimestamp} of when the data used to build the {@link ReferrerLeaderboardPieSplit} was accurate as of.
755
- */
756
- accurateAsOf: UnixTimestamp;
757
- }
758
- declare const buildReferrerLeaderboardPieSplit: (allReferrers: ReferrerMetrics[], rules: ReferralProgramRulesPieSplit, accurateAsOf: UnixTimestamp) => ReferrerLeaderboardPieSplit;
759
-
760
- /**
761
- * Edition summary for a `pie-split` referral program edition.
762
- */
763
- interface ReferralProgramEditionSummaryPieSplit extends BaseReferralProgramEditionSummary {
764
- /**
765
- * Discriminant — always `"pie-split"`.
766
- *
767
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.PieSplit}).
768
- */
769
- awardModel: typeof ReferralProgramAwardModels.PieSplit;
770
- /**
771
- * The pie-split rules for this edition.
772
- */
773
- rules: ReferralProgramRulesPieSplit;
774
- }
775
- declare const validateEditionSummaryPieSplit: (summary: ReferralProgramEditionSummaryPieSplit) => void;
776
- /**
777
- * Build a {@link ReferralProgramEditionSummaryPieSplit} from a pie-split edition config and the
778
- * edition's leaderboard.
779
- */
780
- declare function buildEditionSummaryPieSplit(slug: ReferralProgramEditionSlug, displayName: string, rules: ReferralProgramRulesPieSplit, leaderboard: ReferrerLeaderboardPieSplit): ReferralProgramEditionSummaryPieSplit;
781
-
782
- /**
783
- * Extends {@link ReferrerMetrics} with computed base revenue contribution.
784
- */
785
- interface ReferrerMetricsRevShareLimit extends ReferrerMetrics {
786
- /**
787
- * The referrer's base revenue contribution (base-fee-only: $5 × years of incremental duration).
788
- * Used for qualification and award calculation in the rev-share-limit model.
789
- *
790
- * @invariant Guaranteed to be `priceUsdc(BASE_REVENUE_CONTRIBUTION_PER_YEAR.amount * BigInt(totalIncrementalDuration) / BigInt(SECONDS_PER_YEAR))`
791
- */
792
- totalBaseRevenueContribution: PriceUsdc;
793
- }
794
- declare const validateReferrerMetricsRevShareLimit: (metrics: ReferrerMetricsRevShareLimit) => void;
795
- declare const buildReferrerMetricsRevShareLimit: (metrics: ReferrerMetrics) => ReferrerMetricsRevShareLimit;
796
- /**
797
- * Extends {@link ReferrerMetricsRevShareLimit} with rank, qualification status, and admin disqualification.
798
- */
799
- interface RankedReferrerMetricsRevShareLimit extends ReferrerMetricsRevShareLimit {
800
- /**
801
- * The referrer's rank on the {@link ReferrerLeaderboardRevShareLimit} relative to all other referrers.
802
- */
803
- rank: ReferrerRank;
804
- /**
805
- * Identifies if the referrer meets the qualifications of the {@link ReferralProgramRulesRevShareLimit} to receive a non-zero `awardPoolShare`.
806
- *
807
- * @invariant true if and only if `totalBaseRevenueContribution` is greater than or equal to
808
- * {@link ReferralProgramRulesRevShareLimit.minQualifiedRevenueContribution} AND
809
- * {@link isAdminDisqualified} is false.
810
- */
811
- isQualified: boolean;
812
- /**
813
- * Whether this referrer has been admin-disqualified from the edition.
814
- *
815
- * @invariant When true, {@link isQualified} is false.
816
- */
817
- isAdminDisqualified: boolean;
818
- /**
819
- * The reason for admin disqualification, or null if not disqualified.
820
- *
821
- * @invariant null when {@link isAdminDisqualified} is false.
822
- * @invariant Non-empty string when {@link isAdminDisqualified} is true.
823
- */
824
- adminDisqualificationReason: string | null;
825
- }
826
- declare const validateRankedReferrerMetricsRevShareLimit: (metrics: RankedReferrerMetricsRevShareLimit, rules: ReferralProgramRulesRevShareLimit) => void;
827
- declare const buildRankedReferrerMetricsRevShareLimit: (referrer: ReferrerMetricsRevShareLimit, rank: ReferrerRank, rules: ReferralProgramRulesRevShareLimit) => RankedReferrerMetricsRevShareLimit;
828
- /**
829
- * Extends {@link RankedReferrerMetricsRevShareLimit} with approximate award value.
830
- */
831
- interface AwardedReferrerMetricsRevShareLimit extends RankedReferrerMetricsRevShareLimit {
832
- /**
833
- * The standard (uncapped) USDC award value for this referrer, computed as
834
- * `qualifiedRevenueShare × totalBaseRevenueContribution`.
835
- *
836
- * Represents what the referrer would receive if the pool were unlimited and the referrer were qualified.
837
- * Independent of the pool state and qualification status.
838
- */
839
- standardAwardValue: PriceUsdc;
840
- /**
841
- * The approximate USDC value of the referrer's award.
842
- *
843
- * This is the amount actually claimed from the pool by this referrer, capped by
844
- * the remaining pool at the time of their qualifying events.
845
- *
846
- * @invariant Guaranteed to be a valid PriceUsdc with amount between 0 and {@link ReferralProgramRulesRevShareLimit.totalAwardPoolValue.amount} (inclusive)
847
- * @invariant Always <= standardAwardValue.amount
848
- * @invariant Amount equal to 0 when {@link isAdminDisqualified} is true.
849
- */
850
- awardPoolApproxValue: PriceUsdc;
851
- }
852
- declare const validateAwardedReferrerMetricsRevShareLimit: (metrics: AwardedReferrerMetricsRevShareLimit, rules: ReferralProgramRulesRevShareLimit) => void;
853
- declare const buildAwardedReferrerMetricsRevShareLimit: (referrer: RankedReferrerMetricsRevShareLimit, standardAwardValue: PriceUsdc, awardPoolApproxValue: PriceUsdc, rules: ReferralProgramRulesRevShareLimit) => AwardedReferrerMetricsRevShareLimit;
854
- /**
855
- * Extends {@link AwardedReferrerMetricsRevShareLimit} but with rank set to null to represent
856
- * a referrer who is not on the leaderboard (has zero referrals within the rules associated with the leaderboard).
857
- */
858
- interface UnrankedReferrerMetricsRevShareLimit extends Omit<AwardedReferrerMetricsRevShareLimit, "rank" | "isQualified"> {
859
- /**
860
- * The referrer is not on the leaderboard and therefore has no rank.
861
- */
862
- rank: null;
863
- /**
864
- * Always false for unranked referrers.
865
- */
866
- isQualified: false;
867
- }
868
- declare const validateUnrankedReferrerMetricsRevShareLimit: (metrics: UnrankedReferrerMetricsRevShareLimit, rules: ReferralProgramRulesRevShareLimit) => void;
869
- /**
870
- * Build an unranked zero-metrics rev-share-limit referrer record for an address not on the leaderboard.
871
- */
872
- declare const buildUnrankedReferrerMetricsRevShareLimit: (referrer: Address, rules: ReferralProgramRulesRevShareLimit) => UnrankedReferrerMetricsRevShareLimit;
873
-
874
- /**
875
- * Represents aggregated metrics for a list of referrers on a rev-share-limit leaderboard.
876
- */
877
- interface AggregatedReferrerMetricsRevShareLimit {
878
- /**
879
- * @invariant The sum of `totalReferrals` across all referrers in the list.
880
- * @invariant Guaranteed to be a non-negative integer (>= 0)
881
- */
882
- grandTotalReferrals: number;
883
- /**
884
- * @invariant The sum of `totalIncrementalDuration` across all referrers in the list.
885
- */
886
- grandTotalIncrementalDuration: Duration;
887
- /**
888
- * The total revenue contribution in ETH to the ENS DAO from all referrals
889
- * across all referrers on the leaderboard.
890
- *
891
- * This is the sum of `totalRevenueContribution` across all referrers in the list.
892
- *
893
- * @invariant Guaranteed to be a valid PriceEth with non-negative amount (>= 0n)
894
- */
895
- grandTotalRevenueContribution: PriceEth;
896
- /**
897
- * The remaining amount in the award pool after subtracting all qualified awards
898
- * claimed during the sequential race processing.
899
- *
900
- * @invariant Guaranteed to be a valid PriceUsdc with non-negative amount (>= 0n)
901
- */
902
- awardPoolRemaining: PriceUsdc;
903
- }
904
- declare const validateAggregatedReferrerMetricsRevShareLimit: (metrics: AggregatedReferrerMetricsRevShareLimit) => void;
905
- /**
906
- * Builds aggregated rev-share-limit metrics from a complete list of referrers and
907
- * the award pool remaining after sequential race processing.
908
- *
909
- * **IMPORTANT: This function expects a complete list of all referrers.**
910
- *
911
- * @param referrers - Must be a complete list of referrers with their totals.
912
- * **This must NOT be a paginated or partial slice.**
913
- *
914
- * @param awardPoolRemaining - The amount remaining in the award pool after the sequential
915
- * race algorithm has processed all events.
916
- *
917
- * @returns Aggregated metrics including totals across all referrers and the award pool remaining.
918
- */
919
- declare const buildAggregatedReferrerMetricsRevShareLimit: (referrers: AwardedReferrerMetricsRevShareLimit[], awardPoolRemaining: PriceUsdc) => AggregatedReferrerMetricsRevShareLimit;
920
-
921
- /**
922
- * Represents a single raw referral event.
923
- *
924
- * Used as input to the sequential race algorithm for the rev-share-limit award model.
925
- * Events are processed in chronological order to determine award claims from the pool.
926
- */
927
- interface ReferralEvent {
928
- /**
929
- * The fully lowercase Ethereum address of the referrer.
930
- */
931
- referrer: Address;
932
- /**
933
- * Unix seconds block timestamp.
934
- */
935
- timestamp: UnixTimestamp;
936
- /**
937
- * Registrar action ID.
938
- *
939
- * @invariant Deterministic and globally unique identifier for the "logical registrar action"
940
- * associated with this ReferralEvent.
941
- * @invariant Sorting by this value achieves a chronological ordering of each registrar action
942
- * by the order they were executed onchain.
943
- */
944
- id: string;
945
- /**
946
- * Duration in seconds contributed by this single referral event.
947
- */
948
- incrementalDuration: Duration;
949
- /**
950
- * Revenue contribution in ETH from this single referral event.
951
- */
952
- incrementalRevenueContribution: PriceEth;
953
- }
954
-
955
- /**
956
- * Represents a leaderboard with the rev-share-limit award model for any number of referrers.
957
- */
958
- interface ReferrerLeaderboardRevShareLimit {
959
- /**
960
- * Discriminant identifying this as a rev-share-limit leaderboard.
961
- *
962
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.RevShareLimit}).
963
- */
964
- awardModel: typeof ReferralProgramAwardModels.RevShareLimit;
965
- /**
966
- * The rules of the referral program that generated the {@link ReferrerLeaderboardRevShareLimit}.
967
- */
968
- rules: ReferralProgramRulesRevShareLimit;
969
- /**
970
- * The {@link AggregatedReferrerMetricsRevShareLimit} for all {@link AwardedReferrerMetricsRevShareLimit} values in `referrers`.
971
- */
972
- aggregatedMetrics: AggregatedReferrerMetricsRevShareLimit;
973
- /**
974
- * Ordered map containing {@link AwardedReferrerMetricsRevShareLimit} for all referrers with 1 or more
975
- * `totalReferrals` within the `rules` as of `accurateAsOf`.
976
- *
977
- * @invariant Map entries are ordered by `rank` (ascending).
978
- * @invariant Map is empty if there are no referrers with 1 or more `totalReferrals`
979
- * within the `rules` as of `accurateAsOf`.
980
- * @invariant If a fully-lowercase `Address` is not a key in this map then that `Address` had
981
- * 0 `totalReferrals`, `totalIncrementalDuration`, and `totalRevenueContribution` within the
982
- * `rules` as of `accurateAsOf`.
983
- * @invariant Each value in this map is guaranteed to have a non-zero
984
- * `totalReferrals` and `totalIncrementalDuration`.
985
- */
986
- referrers: Map<Address, AwardedReferrerMetricsRevShareLimit>;
987
- /**
988
- * The {@link UnixTimestamp} of when the data used to build the {@link ReferrerLeaderboardRevShareLimit} was accurate as of.
989
- */
990
- accurateAsOf: UnixTimestamp;
991
- }
992
- /**
993
- * Builds a {@link ReferrerLeaderboardRevShareLimit} using a sequential "first-come, first-served"
994
- * race algorithm over individual referral events.
995
- *
996
- * Events are processed in chronological order. When a referrer first crosses the qualification
997
- * threshold, they claim ALL accumulated standard award value at once (capped by remaining pool).
998
- * After qualifying, each subsequent event claims that event's incremental standard award (also
999
- * capped). Once the pool reaches $0, no further awards are issued to anyone.
1000
- *
1001
- * @param events - Raw referral events from the database (unsorted; will be sorted internally).
1002
- * @param rules - The {@link ReferralProgramRulesRevShareLimit} defining the program parameters.
1003
- * @param accurateAsOf - Timestamp indicating data freshness.
1004
- */
1005
- declare const buildReferrerLeaderboardRevShareLimit: (events: ReferralEvent[], rules: ReferralProgramRulesRevShareLimit, accurateAsOf: UnixTimestamp) => ReferrerLeaderboardRevShareLimit;
1006
-
1007
- /**
1008
- * Represents a leaderboard for any number of referrers.
1009
- *
1010
- * Use `awardModel` to narrow the specific variant at runtime.
1011
- */
1012
- type ReferrerLeaderboard = ReferrerLeaderboardPieSplit | ReferrerLeaderboardRevShareLimit;
1013
-
1014
- /**
1015
- * The default number of referrers per leaderboard page.
1016
- */
1017
- declare const REFERRERS_PER_LEADERBOARD_PAGE_DEFAULT = 25;
1018
- /**
1019
- * The maximum number of referrers per leaderboard page.
1020
- */
1021
- declare const REFERRERS_PER_LEADERBOARD_PAGE_MAX = 100;
1022
- /**
1023
- * Pagination params for leaderboard queries.
1024
- */
1025
- interface ReferrerLeaderboardPageParams {
1026
- /**
1027
- * Requested referrer leaderboard page number (1-indexed)
1028
- * @invariant Must be a positive integer (>= 1)
1029
- * @default 1
1030
- */
1031
- page?: number;
1032
- /**
1033
- * Maximum number of referrers to return per leaderboard page
1034
- * @invariant Must be a positive integer (>= 1) and less than or equal to {@link REFERRERS_PER_LEADERBOARD_PAGE_MAX}
1035
- * @default {@link REFERRERS_PER_LEADERBOARD_PAGE_DEFAULT}
1036
- */
1037
- recordsPerPage?: number;
1038
- }
1039
- declare const buildReferrerLeaderboardPageParams: (params: ReferrerLeaderboardPageParams) => Required<ReferrerLeaderboardPageParams>;
1040
- interface ReferrerLeaderboardPageContext extends Required<ReferrerLeaderboardPageParams> {
1041
- /**
1042
- * Total number of referrers across all leaderboard pages
1043
- * @invariant Guaranteed to be a non-negative integer (>= 0)
1044
- */
1045
- totalRecords: number;
1046
- /**
1047
- * Total number of pages in the leaderboard
1048
- * @invariant Guaranteed to be a positive integer (>= 1)
1049
- */
1050
- totalPages: number;
1051
- /**
1052
- * Indicates if there is a next page available
1053
- * @invariant true if and only if (`page` * `recordsPerPage` < `totalRecords`)
1054
- */
1055
- hasNext: boolean;
1056
- /**
1057
- * Indicates if there is a previous page available
1058
- * @invariant true if and only if (`page` > 1)
1059
- */
1060
- hasPrev: boolean;
1061
- /**
1062
- * The start index of the referrers on the page (0-indexed)
1063
- *
1064
- * `undefined` if and only if `totalRecords` is 0.
1065
- *
1066
- * @invariant Guaranteed to be a non-negative integer (>= 0)
1067
- */
1068
- startIndex?: number;
1069
- /**
1070
- * The end index of the referrers on the page (0-indexed)
1071
- *
1072
- * `undefined` if and only if `totalRecords` is 0.
1073
- *
1074
- * @invariant Guaranteed to be a non-negative integer (>= 0)
1075
- * @invariant If `totalRecords` is > 0:
1076
- * - Guaranteed to be greater than or equal to `startIndex`.
1077
- * - Guaranteed to be less than `totalRecords`.
1078
- */
1079
- endIndex?: number;
1080
- }
1081
- declare const validateReferrerLeaderboardPageContext: (context: ReferrerLeaderboardPageContext) => void;
1082
- declare const buildReferrerLeaderboardPageContext: (optionalParams: ReferrerLeaderboardPageParams, leaderboard: ReferrerLeaderboard) => ReferrerLeaderboardPageContext;
1083
- /**
1084
- * Base fields shared by all leaderboard page variants.
1085
- */
1086
- interface BaseReferrerLeaderboardPage {
1087
- /**
1088
- * Discriminant identifying the award model for this leaderboard page.
1089
- */
1090
- awardModel: ReferralProgramAwardModel;
1091
- /**
1092
- * The {@link ReferrerLeaderboardPageContext} of this page relative to the overall leaderboard.
1093
- */
1094
- pageContext: ReferrerLeaderboardPageContext;
1095
- /**
1096
- * The status of the referral program edition.
1097
- */
1098
- status: ReferralProgramEditionStatusId;
1099
- /**
1100
- * The {@link UnixTimestamp} of when the data used to build this page was accurate as of.
1101
- */
1102
- accurateAsOf: UnixTimestamp;
1103
- }
1104
- /**
1105
- * A leaderboard page whose `awardModel` is not recognized by this client version.
1106
- *
1107
- * @remarks
1108
- * This is a **client-side forward-compatibility** type only. It is never serialized or processed
1109
- * by business logic on the backend. When the server introduces a new award model type, older
1110
- * clients preserve the page rather than throwing, and downstream code that encounters this type
1111
- * should handle it gracefully rather than crashing.
1112
- */
1113
- interface ReferrerLeaderboardPageUnrecognized extends BaseReferrerLeaderboardPage {
1114
- /**
1115
- * Discriminant — always `"unrecognized"`.
1116
- */
1117
- awardModel: typeof ReferralProgramAwardModels.Unrecognized;
1118
- /**
1119
- * The original, unrecognized `awardModel` string received from the server.
1120
- *
1121
- * @remarks Preserved for logging and debugging. Never used for business logic.
1122
- */
1123
- originalAwardModel: string;
1124
- }
1125
- /**
1126
- * Extracts the referrers for the current page from a fully-ranked Map.
1127
- * Generic over the referrer type so each model variant retains its specific type.
1128
- */
1129
- declare function sliceReferrers<T>(referrers: Map<Address, T>, pageContext: ReferrerLeaderboardPageContext): T[];
1130
-
1131
- /**
1132
- * A page of referrers from the pie-split referrer leaderboard.
1133
- */
1134
- interface ReferrerLeaderboardPagePieSplit extends BaseReferrerLeaderboardPage {
1135
- /**
1136
- * Discriminant identifying this as a page from a pie-split leaderboard.
1137
- *
1138
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.PieSplit}).
1139
- */
1140
- awardModel: typeof ReferralProgramAwardModels.PieSplit;
1141
- /**
1142
- * The {@link ReferralProgramRulesPieSplit} used to generate the {@link ReferrerLeaderboardPieSplit}
1143
- * that this {@link ReferrerLeaderboardPagePieSplit} comes from.
1144
- */
1145
- rules: ReferralProgramRulesPieSplit;
1146
- /**
1147
- * Ordered list of {@link AwardedReferrerMetricsPieSplit} for the {@link ReferrerLeaderboardPagePieSplit}
1148
- * described by {@link pageContext} within the related {@link ReferrerLeaderboardPieSplit}.
1149
- *
1150
- * @invariant Array will be empty if `pageContext.totalRecords` is 0.
1151
- * @invariant Array entries are ordered by `rank` (ascending).
1152
- */
1153
- referrers: AwardedReferrerMetricsPieSplit[];
1154
- /**
1155
- * The aggregated metrics for all referrers on the leaderboard.
1156
- */
1157
- aggregatedMetrics: AggregatedReferrerMetricsPieSplit;
1158
- }
1159
- declare function buildLeaderboardPagePieSplit(pageContext: ReferrerLeaderboardPageContext, leaderboard: ReferrerLeaderboardPieSplit): ReferrerLeaderboardPagePieSplit;
1160
-
1161
- /**
1162
- * Serialized representation of {@link ReferralProgramRulesPieSplit}.
1163
- */
1164
- interface SerializedReferralProgramRulesPieSplit extends Omit<ReferralProgramRulesPieSplit, "totalAwardPoolValue" | "rulesUrl"> {
1165
- totalAwardPoolValue: SerializedPriceUsdc;
1166
- rulesUrl: string;
1167
- }
1168
- /**
1169
- * Serialized representation of {@link AggregatedReferrerMetricsPieSplit}.
1170
- */
1171
- interface SerializedAggregatedReferrerMetricsPieSplit extends Omit<AggregatedReferrerMetricsPieSplit, "grandTotalRevenueContribution"> {
1172
- grandTotalRevenueContribution: SerializedPriceEth;
1173
- }
1174
- /**
1175
- * Serialized representation of {@link AwardedReferrerMetricsPieSplit}.
1176
- */
1177
- interface SerializedAwardedReferrerMetricsPieSplit extends Omit<AwardedReferrerMetricsPieSplit, "totalRevenueContribution" | "awardPoolApproxValue"> {
1178
- totalRevenueContribution: SerializedPriceEth;
1179
- awardPoolApproxValue: SerializedPriceUsdc;
1180
- }
1181
- /**
1182
- * Serialized representation of {@link UnrankedReferrerMetricsPieSplit}.
1183
- */
1184
- interface SerializedUnrankedReferrerMetricsPieSplit extends Omit<UnrankedReferrerMetricsPieSplit, "totalRevenueContribution" | "awardPoolApproxValue"> {
1185
- totalRevenueContribution: SerializedPriceEth;
1186
- awardPoolApproxValue: SerializedPriceUsdc;
1187
- }
1188
- /**
1189
- * Serialized representation of {@link ReferrerLeaderboardPagePieSplit}.
1190
- */
1191
- interface SerializedReferrerLeaderboardPagePieSplit extends Omit<ReferrerLeaderboardPagePieSplit, "rules" | "referrers" | "aggregatedMetrics"> {
1192
- rules: SerializedReferralProgramRulesPieSplit;
1193
- referrers: SerializedAwardedReferrerMetricsPieSplit[];
1194
- aggregatedMetrics: SerializedAggregatedReferrerMetricsPieSplit;
1195
- }
1196
- /**
1197
- * Serialized representation of {@link ReferrerEditionMetricsRankedPieSplit}.
1198
- */
1199
- interface SerializedReferrerEditionMetricsRankedPieSplit extends Omit<ReferrerEditionMetricsRankedPieSplit, "rules" | "referrer" | "aggregatedMetrics"> {
1200
- rules: SerializedReferralProgramRulesPieSplit;
1201
- referrer: SerializedAwardedReferrerMetricsPieSplit;
1202
- aggregatedMetrics: SerializedAggregatedReferrerMetricsPieSplit;
1203
- }
1204
- /**
1205
- * Serialized representation of {@link ReferrerEditionMetricsUnrankedPieSplit}.
1206
- */
1207
- interface SerializedReferrerEditionMetricsUnrankedPieSplit extends Omit<ReferrerEditionMetricsUnrankedPieSplit, "rules" | "referrer" | "aggregatedMetrics"> {
1208
- rules: SerializedReferralProgramRulesPieSplit;
1209
- referrer: SerializedUnrankedReferrerMetricsPieSplit;
1210
- aggregatedMetrics: SerializedAggregatedReferrerMetricsPieSplit;
1211
- }
1212
- /**
1213
- * Serialized representation of {@link ReferrerEditionMetricsPieSplit}.
1214
- */
1215
- type SerializedReferrerEditionMetricsPieSplit = SerializedReferrerEditionMetricsRankedPieSplit | SerializedReferrerEditionMetricsUnrankedPieSplit;
1216
- /**
1217
- * Serialized representation of {@link ReferralProgramEditionSummaryPieSplit}.
1218
- */
1219
- interface SerializedReferralProgramEditionSummaryPieSplit extends Omit<ReferralProgramEditionSummaryPieSplit, "rules"> {
1220
- rules: SerializedReferralProgramRulesPieSplit;
1221
- }
1222
-
1223
- /**
1224
- * Referrer edition metrics data for a specific referrer on a rev-share-limit leaderboard.
1225
- *
1226
- * Includes the referrer's awarded metrics from the leaderboard plus timestamp.
1227
- *
1228
- * @see {@link AwardedReferrerMetricsRevShareLimit}
1229
- */
1230
- interface ReferrerEditionMetricsRankedRevShareLimit {
1231
- /**
1232
- * Discriminant identifying this as data from a rev-share-limit leaderboard edition.
1233
- *
1234
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.RevShareLimit}).
1235
- */
1236
- awardModel: typeof ReferralProgramAwardModels.RevShareLimit;
1237
- /**
1238
- * The type of referrer edition metrics data.
1239
- */
1240
- type: typeof ReferrerEditionMetricsTypeIds.Ranked;
1241
- /**
1242
- * The {@link ReferralProgramRulesRevShareLimit} used to calculate the {@link AwardedReferrerMetricsRevShareLimit}.
1243
- */
1244
- rules: ReferralProgramRulesRevShareLimit;
1245
- /**
1246
- * The awarded referrer metrics from the leaderboard.
1247
- *
1248
- * Contains all calculated metrics including rank, qualification status,
1249
- * standard award value, and award pool approximate value.
1250
- */
1251
- referrer: AwardedReferrerMetricsRevShareLimit;
1252
- /**
1253
- * Aggregated metrics for all referrers on the leaderboard.
1254
- */
1255
- aggregatedMetrics: AggregatedReferrerMetricsRevShareLimit;
1256
- /**
1257
- * The status of the referral program edition
1258
- * calculated based on the program's timing relative to {@link accurateAsOf}.
1259
- */
1260
- status: ReferralProgramEditionStatusId;
1261
- /**
1262
- * The {@link UnixTimestamp} of when the data used to build the {@link ReferrerEditionMetricsRankedRevShareLimit} was accurate as of.
1263
- */
1264
- accurateAsOf: UnixTimestamp;
1265
- }
1266
- /**
1267
- * Referrer edition metrics data for a specific referrer address NOT on the rev-share-limit leaderboard.
1268
- *
1269
- * Includes the referrer's unranked metrics (with null rank and isQualified: false) plus timestamp.
1270
- *
1271
- * @see {@link UnrankedReferrerMetricsRevShareLimit}
1272
- */
1273
- interface ReferrerEditionMetricsUnrankedRevShareLimit {
1274
- /**
1275
- * Discriminant identifying this as data from a rev-share-limit leaderboard edition.
1276
- *
1277
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.RevShareLimit}).
1278
- */
1279
- awardModel: typeof ReferralProgramAwardModels.RevShareLimit;
1280
- /**
1281
- * The type of referrer edition metrics data.
1282
- */
1283
- type: typeof ReferrerEditionMetricsTypeIds.Unranked;
1284
- /**
1285
- * The {@link ReferralProgramRulesRevShareLimit} used to calculate the {@link UnrankedReferrerMetricsRevShareLimit}.
1286
- */
1287
- rules: ReferralProgramRulesRevShareLimit;
1288
- /**
1289
- * The unranked referrer metrics (not on the leaderboard).
1290
- *
1291
- * Contains all calculated metrics with rank set to null and isQualified set to false.
1292
- */
1293
- referrer: UnrankedReferrerMetricsRevShareLimit;
1294
- /**
1295
- * Aggregated metrics for all referrers on the leaderboard.
1296
- */
1297
- aggregatedMetrics: AggregatedReferrerMetricsRevShareLimit;
1298
- /**
1299
- * The status of the referral program edition
1300
- * calculated based on the program's timing relative to {@link accurateAsOf}.
1301
- */
1302
- status: ReferralProgramEditionStatusId;
1303
- /**
1304
- * The {@link UnixTimestamp} of when the data used to build the {@link ReferrerEditionMetricsUnrankedRevShareLimit} was accurate as of.
1305
- */
1306
- accurateAsOf: UnixTimestamp;
1307
- }
1308
- /**
1309
- * All referrer edition metrics variants for the rev-share-limit award model.
1310
- *
1311
- * Use `type` to determine if the referrer is ranked or unranked.
1312
- */
1313
- type ReferrerEditionMetricsRevShareLimit = ReferrerEditionMetricsRankedRevShareLimit | ReferrerEditionMetricsUnrankedRevShareLimit;
1314
-
1315
- /**
1316
- * Edition summary for a `rev-share-limit` referral program edition.
1317
- *
1318
- * Includes `awardPoolRemaining` so consumers can display pool exhaustion state
1319
- * without needing to fetch the full leaderboard.
1320
- */
1321
- interface ReferralProgramEditionSummaryRevShareLimit extends BaseReferralProgramEditionSummary {
1322
- /**
1323
- * Discriminant — always `"rev-share-limit"`.
1324
- *
1325
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.RevShareLimit}).
1326
- */
1327
- awardModel: typeof ReferralProgramAwardModels.RevShareLimit;
1328
- /**
1329
- * The rev-share-limit rules for this edition.
1330
- */
1331
- rules: ReferralProgramRulesRevShareLimit;
1332
- /**
1333
- * The remaining award pool after sequential race processing.
1334
- *
1335
- * When `0n`, the edition's status will be {@link ReferralProgramEditionStatuses.Exhausted}
1336
- * if the edition is still within its active window.
1337
- */
1338
- awardPoolRemaining: PriceUsdc;
1339
- }
1340
- declare const validateEditionSummaryRevShareLimit: (summary: ReferralProgramEditionSummaryRevShareLimit) => void;
1341
- /**
1342
- * Build a {@link ReferralProgramEditionSummaryRevShareLimit} from a rev-share-limit edition
1343
- * config and the edition's leaderboard.
1344
- */
1345
- declare function buildEditionSummaryRevShareLimit(slug: ReferralProgramEditionSlug, displayName: string, rules: ReferralProgramRulesRevShareLimit, leaderboard: ReferrerLeaderboardRevShareLimit): ReferralProgramEditionSummaryRevShareLimit;
1346
-
1347
- /**
1348
- * A page of referrers from the rev-share-limit referrer leaderboard.
1349
- */
1350
- interface ReferrerLeaderboardPageRevShareLimit extends BaseReferrerLeaderboardPage {
1351
- /**
1352
- * Discriminant identifying this as a page from a rev-share-limit leaderboard.
1353
- *
1354
- * @invariant Always equals `rules.awardModel` ({@link ReferralProgramAwardModels.RevShareLimit}).
1355
- */
1356
- awardModel: typeof ReferralProgramAwardModels.RevShareLimit;
1357
- /**
1358
- * The {@link ReferralProgramRulesRevShareLimit} used to generate the {@link ReferrerLeaderboardRevShareLimit}
1359
- * that this {@link ReferrerLeaderboardPageRevShareLimit} comes from.
1360
- */
1361
- rules: ReferralProgramRulesRevShareLimit;
1362
- /**
1363
- * Ordered list of {@link AwardedReferrerMetricsRevShareLimit} for the {@link ReferrerLeaderboardPageRevShareLimit}
1364
- * described by {@link pageContext} within the related {@link ReferrerLeaderboard}.
1365
- *
1366
- * @invariant Array will be empty if `pageContext.totalRecords` is 0.
1367
- * @invariant Array entries are ordered by `rank` (ascending).
1368
- */
1369
- referrers: AwardedReferrerMetricsRevShareLimit[];
1370
- /**
1371
- * The aggregated metrics for all referrers on the leaderboard.
1372
- */
1373
- aggregatedMetrics: AggregatedReferrerMetricsRevShareLimit;
1374
- }
1375
- declare function buildLeaderboardPageRevShareLimit(pageContext: ReferrerLeaderboardPageContext, leaderboard: ReferrerLeaderboardRevShareLimit): ReferrerLeaderboardPageRevShareLimit;
1376
-
1377
- /**
1378
- * Serialized representation of {@link ReferralProgramRulesRevShareLimit}.
1379
- */
1380
- interface SerializedReferralProgramRulesRevShareLimit extends Omit<ReferralProgramRulesRevShareLimit, "totalAwardPoolValue" | "minQualifiedRevenueContribution" | "rulesUrl"> {
1381
- totalAwardPoolValue: SerializedPriceUsdc;
1382
- minQualifiedRevenueContribution: SerializedPriceUsdc;
1383
- rulesUrl: string;
1384
- }
1385
- /**
1386
- * Serialized representation of {@link AggregatedReferrerMetricsRevShareLimit}.
1387
- */
1388
- interface SerializedAggregatedReferrerMetricsRevShareLimit extends Omit<AggregatedReferrerMetricsRevShareLimit, "grandTotalRevenueContribution" | "awardPoolRemaining"> {
1389
- grandTotalRevenueContribution: SerializedPriceEth;
1390
- awardPoolRemaining: SerializedPriceUsdc;
1391
- }
1392
- /**
1393
- * Serialized representation of {@link AwardedReferrerMetricsRevShareLimit}.
1394
- */
1395
- interface SerializedAwardedReferrerMetricsRevShareLimit extends Omit<AwardedReferrerMetricsRevShareLimit, "totalRevenueContribution" | "totalBaseRevenueContribution" | "standardAwardValue" | "awardPoolApproxValue"> {
1396
- totalRevenueContribution: SerializedPriceEth;
1397
- totalBaseRevenueContribution: SerializedPriceUsdc;
1398
- standardAwardValue: SerializedPriceUsdc;
1399
- awardPoolApproxValue: SerializedPriceUsdc;
1400
- }
1401
- /**
1402
- * Serialized representation of {@link UnrankedReferrerMetricsRevShareLimit}.
1403
- */
1404
- interface SerializedUnrankedReferrerMetricsRevShareLimit extends Omit<UnrankedReferrerMetricsRevShareLimit, "totalRevenueContribution" | "totalBaseRevenueContribution" | "standardAwardValue" | "awardPoolApproxValue"> {
1405
- totalRevenueContribution: SerializedPriceEth;
1406
- totalBaseRevenueContribution: SerializedPriceUsdc;
1407
- standardAwardValue: SerializedPriceUsdc;
1408
- awardPoolApproxValue: SerializedPriceUsdc;
1409
- }
1410
- /**
1411
- * Serialized representation of {@link ReferrerLeaderboardPageRevShareLimit}.
1412
- */
1413
- interface SerializedReferrerLeaderboardPageRevShareLimit extends Omit<ReferrerLeaderboardPageRevShareLimit, "rules" | "referrers" | "aggregatedMetrics"> {
1414
- rules: SerializedReferralProgramRulesRevShareLimit;
1415
- referrers: SerializedAwardedReferrerMetricsRevShareLimit[];
1416
- aggregatedMetrics: SerializedAggregatedReferrerMetricsRevShareLimit;
1417
- }
1418
- /**
1419
- * Serialized representation of {@link ReferrerEditionMetricsRankedRevShareLimit}.
1420
- */
1421
- interface SerializedReferrerEditionMetricsRankedRevShareLimit extends Omit<ReferrerEditionMetricsRankedRevShareLimit, "rules" | "referrer" | "aggregatedMetrics"> {
1422
- rules: SerializedReferralProgramRulesRevShareLimit;
1423
- referrer: SerializedAwardedReferrerMetricsRevShareLimit;
1424
- aggregatedMetrics: SerializedAggregatedReferrerMetricsRevShareLimit;
1425
- }
1426
- /**
1427
- * Serialized representation of {@link ReferrerEditionMetricsUnrankedRevShareLimit}.
1428
- */
1429
- interface SerializedReferrerEditionMetricsUnrankedRevShareLimit extends Omit<ReferrerEditionMetricsUnrankedRevShareLimit, "rules" | "referrer" | "aggregatedMetrics"> {
1430
- rules: SerializedReferralProgramRulesRevShareLimit;
1431
- referrer: SerializedUnrankedReferrerMetricsRevShareLimit;
1432
- aggregatedMetrics: SerializedAggregatedReferrerMetricsRevShareLimit;
1433
- }
1434
- /**
1435
- * Serialized representation of {@link ReferrerEditionMetricsRevShareLimit}.
1436
- */
1437
- type SerializedReferrerEditionMetricsRevShareLimit = SerializedReferrerEditionMetricsRankedRevShareLimit | SerializedReferrerEditionMetricsUnrankedRevShareLimit;
1438
- /**
1439
- * Serialized representation of {@link ReferralProgramEditionSummaryRevShareLimit}.
1440
- */
1441
- interface SerializedReferralProgramEditionSummaryRevShareLimit extends Omit<ReferralProgramEditionSummaryRevShareLimit, "rules" | "awardPoolRemaining"> {
1442
- rules: SerializedReferralProgramRulesRevShareLimit;
1443
- awardPoolRemaining: SerializedPriceUsdc;
1444
- }
1445
-
1446
- /**
1447
- * Referrer edition metrics data for a specific referrer address.
1448
- *
1449
- * Use `awardModel` to narrow the award model variant, then `type` to narrow ranked vs unranked.
1450
- * When `awardModel` is `"unrecognized"`, the data was produced by a server running a newer
1451
- * version — use {@link ReferrerEditionMetricsUnrecognized} to access `originalAwardModel`.
1452
- */
1453
- type ReferrerEditionMetrics = ReferrerEditionMetricsPieSplit | ReferrerEditionMetricsRevShareLimit | ReferrerEditionMetricsUnrecognized;
1454
- /**
1455
- * Get the edition metrics for a specific referrer from the leaderboard.
1456
- *
1457
- * Returns a {@link ReferrerEditionMetricsPieSplit} or {@link ReferrerEditionMetricsRevShareLimit}
1458
- * with `type: "ranked"` if the referrer is on the leaderboard, or `type: "unranked"` otherwise.
1459
- *
1460
- * @param referrer - The referrer address to look up
1461
- * @param leaderboard - The referrer leaderboard to query
1462
- * @returns The appropriate {@link ReferrerEditionMetrics}
1463
- */
1464
- declare const getReferrerEditionMetrics: (referrer: Address, leaderboard: ReferrerLeaderboard) => ReferrerEditionMetrics;
1465
-
1466
- /**
1467
- * Runtime summary of a referral program edition, enriched with current status and pool data.
1468
- *
1469
- * Use `awardModel` to discriminate between variants at runtime.
1470
- */
1471
- type ReferralProgramEditionSummary = ReferralProgramEditionSummaryPieSplit | ReferralProgramEditionSummaryRevShareLimit | ReferralProgramEditionSummaryUnrecognized;
1472
- /**
1473
- * Build a runtime edition summary from an edition config and the edition's leaderboard.
1474
- * Dispatches to the appropriate per-model builder based on `leaderboard.awardModel`.
1475
- *
1476
- * @param config - The edition configuration (provides `slug` and `displayName`).
1477
- * @param leaderboard - The resolved leaderboard for this edition.
1478
- */
1479
- declare function buildEditionSummary(config: ReferralProgramEditionConfig, leaderboard: ReferrerLeaderboard): ReferralProgramEditionSummary;
1480
-
1481
- /**
1482
- * A page of referrers from the referrer leaderboard.
1483
- *
1484
- * Use `awardModel` to narrow the specific variant at runtime. Within each variant,
1485
- * `rules`, `referrers`, and `aggregatedMetrics` are all guaranteed to be from the same model.
1486
- * When `awardModel` is `"unrecognized"`, the page was produced by a server running a newer
1487
- * version — use {@link ReferrerLeaderboardPageUnrecognized} to access `originalAwardModel`.
1488
- */
1489
- type ReferrerLeaderboardPage = ReferrerLeaderboardPagePieSplit | ReferrerLeaderboardPageRevShareLimit | ReferrerLeaderboardPageUnrecognized;
1490
- declare const getReferrerLeaderboardPage: (pageParams: ReferrerLeaderboardPageParams, leaderboard: ReferrerLeaderboard) => ReferrerLeaderboardPage;
1491
-
1492
- /**
1493
- * Request parameters for a referrer leaderboard page query.
1494
- */
1495
- interface ReferrerLeaderboardPageRequest extends ReferrerLeaderboardPageParams {
1496
- /** The referral program edition slug */
1497
- edition: ReferralProgramEditionSlug;
1498
- }
1499
- /**
1500
- * A status code for a referrer leaderboard page API response.
1501
- */
1502
- declare const ReferrerLeaderboardPageResponseCodes: {
1503
- /**
1504
- * Represents that the requested referrer leaderboard page is available.
1505
- */
1506
- readonly Ok: "ok";
1507
- /**
1508
- * Represents that the referrer leaderboard data is not available.
1509
- */
1510
- readonly Error: "error";
1511
- };
1512
- /**
1513
- * The derived string union of possible {@link ReferrerLeaderboardPageResponseCodes}.
1514
- */
1515
- type ReferrerLeaderboardPageResponseCode = (typeof ReferrerLeaderboardPageResponseCodes)[keyof typeof ReferrerLeaderboardPageResponseCodes];
1516
- /**
1517
- * A referrer leaderboard page response when the data is available.
1518
- */
1519
- type ReferrerLeaderboardPageResponseOk = {
1520
- responseCode: typeof ReferrerLeaderboardPageResponseCodes.Ok;
1521
- data: ReferrerLeaderboardPage;
1522
- };
1523
- /**
1524
- * A referrer leaderboard page response when the data is not available.
1525
- */
1526
- type ReferrerLeaderboardPageResponseError = {
1527
- responseCode: typeof ReferrerLeaderboardPageResponseCodes.Error;
1528
- error: string;
1529
- errorMessage: string;
1530
- };
1531
- /**
1532
- * A referrer leaderboard page API response.
1533
- *
1534
- * Use the `responseCode` field to determine the specific type interpretation
1535
- * at runtime.
1536
- */
1537
- type ReferrerLeaderboardPageResponse = ReferrerLeaderboardPageResponseOk | ReferrerLeaderboardPageResponseError;
1538
- /**
1539
- * Maximum number of editions that can be requested in a single {@link ReferrerMetricsEditionsRequest}.
1540
- */
1541
- declare const MAX_EDITIONS_PER_REQUEST = 20;
1542
- /**
1543
- * Request parameters for referrer metrics query.
1544
- */
1545
- interface ReferrerMetricsEditionsRequest {
1546
- /** The Ethereum address of the referrer to query */
1547
- referrer: Address;
1548
- /** Array of edition slugs to query (min 1, max {@link MAX_EDITIONS_PER_REQUEST}, must be distinct) */
1549
- editions: ReferralProgramEditionSlug[];
1550
- }
1551
- /**
1552
- * A status code for referrer metrics API responses.
1553
- */
1554
- declare const ReferrerMetricsEditionsResponseCodes: {
1555
- /**
1556
- * Represents that the referrer metrics data for the requested editions is available.
1557
- */
1558
- readonly Ok: "ok";
1559
- /**
1560
- * Represents that an error occurred while fetching the data.
1561
- */
1562
- readonly Error: "error";
1563
- };
1564
- /**
1565
- * The derived string union of possible {@link ReferrerMetricsEditionsResponseCodes}.
1566
- */
1567
- type ReferrerMetricsEditionsResponseCode = (typeof ReferrerMetricsEditionsResponseCodes)[keyof typeof ReferrerMetricsEditionsResponseCodes];
1568
- /**
1569
- * Referrer metrics data for requested editions.
1570
- *
1571
- * Maps each requested edition slug to the referrer's metrics for that edition.
1572
- * Uses Partial because TypeScript cannot know at compile time which specific edition
1573
- * slugs are requested. At runtime, when responseCode is Ok, all requested edition slugs
1574
- * are guaranteed to be present in this record.
1575
- */
1576
- type ReferrerMetricsEditionsData = Partial<Record<ReferralProgramEditionSlug, ReferrerEditionMetrics>>;
1577
- /**
1578
- * A successful response containing referrer metrics for the requested editions.
1579
- */
1580
- type ReferrerMetricsEditionsResponseOk = {
1581
- responseCode: typeof ReferrerMetricsEditionsResponseCodes.Ok;
1582
- data: ReferrerMetricsEditionsData;
1583
- };
1584
- /**
1585
- * A referrer metrics editions response when an error occurs.
1586
- */
1587
- type ReferrerMetricsEditionsResponseError = {
1588
- responseCode: typeof ReferrerMetricsEditionsResponseCodes.Error;
1589
- error: string;
1590
- errorMessage: string;
1591
- };
1592
- /**
1593
- * A referrer metrics editions API response.
1594
- *
1595
- * Use the `responseCode` field to determine the specific type interpretation
1596
- * at runtime.
1597
- */
1598
- type ReferrerMetricsEditionsResponse = ReferrerMetricsEditionsResponseOk | ReferrerMetricsEditionsResponseError;
1599
- /**
1600
- * A status code for referral program edition summaries API responses.
1601
- */
1602
- declare const ReferralProgramEditionSummariesResponseCodes: {
1603
- /**
1604
- * Represents that the edition summaries are available.
1605
- */
1606
- readonly Ok: "ok";
1607
- /**
1608
- * Represents that the edition summaries are not available.
1609
- */
1610
- readonly Error: "error";
1611
- };
1612
- /**
1613
- * The derived string union of possible {@link ReferralProgramEditionSummariesResponseCodes}.
1614
- */
1615
- type ReferralProgramEditionSummariesResponseCode = (typeof ReferralProgramEditionSummariesResponseCodes)[keyof typeof ReferralProgramEditionSummariesResponseCodes];
1616
- /**
1617
- * The data payload containing edition summaries.
1618
- * Editions are sorted in descending order by start timestamp.
1619
- */
1620
- type ReferralProgramEditionSummariesData = {
1621
- editions: ReferralProgramEditionSummary[];
1622
- };
1623
- /**
1624
- * A successful response containing edition summaries.
1625
- */
1626
- type ReferralProgramEditionSummariesResponseOk = {
1627
- responseCode: typeof ReferralProgramEditionSummariesResponseCodes.Ok;
1628
- data: ReferralProgramEditionSummariesData;
1629
- };
1630
- /**
1631
- * An edition summaries response when an error occurs.
1632
- */
1633
- type ReferralProgramEditionSummariesResponseError = {
1634
- responseCode: typeof ReferralProgramEditionSummariesResponseCodes.Error;
1635
- error: string;
1636
- errorMessage: string;
1637
- };
1638
- /**
1639
- * A referral program edition summaries API response.
1640
- *
1641
- * Use the `responseCode` field to determine the specific type interpretation
1642
- * at runtime.
1643
- */
1644
- type ReferralProgramEditionSummariesResponse = ReferralProgramEditionSummariesResponseOk | ReferralProgramEditionSummariesResponseError;
1645
-
1646
- /**
1647
- * Serialized representation of {@link ReferralProgramRules}.
1648
- */
1649
- type SerializedReferralProgramRules = SerializedReferralProgramRulesPieSplit | SerializedReferralProgramRulesRevShareLimit;
1650
- /**
1651
- * Serialized representation of {@link ReferrerLeaderboardPage}.
1652
- */
1653
- type SerializedReferrerLeaderboardPage = SerializedReferrerLeaderboardPagePieSplit | SerializedReferrerLeaderboardPageRevShareLimit;
1654
- /**
1655
- * Serialized representation of {@link ReferrerEditionMetrics}.
1656
- */
1657
- type SerializedReferrerEditionMetrics = SerializedReferrerEditionMetricsPieSplit | SerializedReferrerEditionMetricsRevShareLimit;
1658
- /**
1659
- * Serialized representation of {@link ReferrerLeaderboardPageResponseError}.
1660
- *
1661
- * Note: All fields are already serializable, so this type is identical to the source type.
1662
- */
1663
- type SerializedReferrerLeaderboardPageResponseError = ReferrerLeaderboardPageResponseError;
1664
- /**
1665
- * Serialized representation of {@link ReferrerLeaderboardPageResponseOk}.
1666
- */
1667
- interface SerializedReferrerLeaderboardPageResponseOk extends Omit<ReferrerLeaderboardPageResponseOk, "data"> {
1668
- data: SerializedReferrerLeaderboardPage;
1669
- }
1670
- /**
1671
- * Serialized representation of {@link ReferrerLeaderboardPageResponse}.
1672
- */
1673
- type SerializedReferrerLeaderboardPageResponse = SerializedReferrerLeaderboardPageResponseOk | SerializedReferrerLeaderboardPageResponseError;
1674
- /**
1675
- * Serialized representation of {@link ReferralProgramEditionSummary}.
1676
- */
1677
- type SerializedReferralProgramEditionSummary = SerializedReferralProgramEditionSummaryPieSplit | SerializedReferralProgramEditionSummaryRevShareLimit;
1678
- /**
1679
- * Serialized representation of referrer metrics data for requested editions.
1680
- * Uses Partial because TypeScript cannot know at compile time which specific edition
1681
- * slugs are requested. At runtime, when responseCode is Ok, all requested edition slugs
1682
- * are guaranteed to be present in this record.
1683
- */
1684
- type SerializedReferrerMetricsEditionsData = Partial<Record<ReferralProgramEditionSlug, SerializedReferrerEditionMetrics>>;
1685
- /**
1686
- * Serialized representation of {@link ReferrerMetricsEditionsResponseOk}.
1687
- */
1688
- interface SerializedReferrerMetricsEditionsResponseOk extends Omit<ReferrerMetricsEditionsResponseOk, "data"> {
1689
- data: SerializedReferrerMetricsEditionsData;
1690
- }
1691
- /**
1692
- * Serialized representation of {@link ReferrerMetricsEditionsResponseError}.
1693
- *
1694
- * Note: All fields are already serializable, so this type is identical to the source type.
1695
- */
1696
- type SerializedReferrerMetricsEditionsResponseError = ReferrerMetricsEditionsResponseError;
1697
- /**
1698
- * Serialized representation of {@link ReferrerMetricsEditionsResponse}.
1699
- */
1700
- type SerializedReferrerMetricsEditionsResponse = SerializedReferrerMetricsEditionsResponseOk | SerializedReferrerMetricsEditionsResponseError;
1701
- /**
1702
- * Serialized representation of {@link ReferralProgramEditionSummariesData}.
1703
- */
1704
- interface SerializedReferralProgramEditionSummariesData extends Omit<ReferralProgramEditionSummariesData, "editions"> {
1705
- editions: SerializedReferralProgramEditionSummary[];
1706
- }
1707
- /**
1708
- * Serialized representation of {@link ReferralProgramEditionSummariesResponseOk}.
1709
- */
1710
- interface SerializedReferralProgramEditionSummariesResponseOk extends Omit<ReferralProgramEditionSummariesResponseOk, "data"> {
1711
- data: SerializedReferralProgramEditionSummariesData;
1712
- }
1713
- /**
1714
- * Serialized representation of {@link ReferralProgramEditionSummariesResponseError}.
1715
- *
1716
- * Note: All fields are already serializable, so this type is identical to the source type.
1717
- */
1718
- type SerializedReferralProgramEditionSummariesResponseError = ReferralProgramEditionSummariesResponseError;
1719
- /**
1720
- * Serialized representation of {@link ReferralProgramEditionSummariesResponse}.
1721
- */
1722
- type SerializedReferralProgramEditionSummariesResponse = SerializedReferralProgramEditionSummariesResponseOk | SerializedReferralProgramEditionSummariesResponseError;
1723
-
1724
- /**
1725
- * Deserialize a {@link ReferrerLeaderboardPageResponse} object.
1726
- */
1727
- declare function deserializeReferrerLeaderboardPageResponse(maybeResponse: SerializedReferrerLeaderboardPageResponse, valueLabel?: string): ReferrerLeaderboardPageResponse;
1728
- /**
1729
- * Deserialize a {@link ReferrerMetricsEditionsResponse} object.
1730
- */
1731
- declare function deserializeReferrerMetricsEditionsResponse(maybeResponse: SerializedReferrerMetricsEditionsResponse, valueLabel?: string): ReferrerMetricsEditionsResponse;
1732
- /**
1733
- * Deserializes an array of {@link ReferralProgramEditionConfig} objects.
1734
- */
1735
- declare function deserializeReferralProgramEditionConfigSetArray(maybeArray: unknown, valueLabel?: string): ReferralProgramEditionConfig[];
1736
- /**
1737
- * Deserialize a {@link ReferralProgramEditionSummariesResponse} object.
1738
- */
1739
- declare function deserializeReferralProgramEditionSummariesResponse(maybeResponse: SerializedReferralProgramEditionSummariesResponse, valueLabel?: string): ReferralProgramEditionSummariesResponse;
1740
-
1741
- /**
1742
- * Serializes a {@link ReferralProgramRules} object.
1743
- *
1744
- * @throws if called with a {@link ReferralProgramRulesUnrecognized} — unrecognized editions are
1745
- * client-side forward-compatibility placeholders and must never be serialized.
1746
- */
1747
- declare function serializeReferralProgramRules(rules: ReferralProgramRules): SerializedReferralProgramRules;
1748
- /**
1749
- * Serializes a {@link ReferralProgramEditionSummary} object.
1750
- *
1751
- * @throws if called with a {@link ReferralProgramEditionSummaryUnrecognized} — unrecognized
1752
- * summaries are client-side forward-compatibility placeholders and must never be serialized.
1753
- */
1754
- declare function serializeReferralProgramEditionSummary(summary: ReferralProgramEditionSummary): SerializedReferralProgramEditionSummary;
1755
- /**
1756
- * Serialize a {@link ReferrerLeaderboardPageResponse} object.
1757
- */
1758
- declare function serializeReferrerLeaderboardPageResponse(response: ReferrerLeaderboardPageResponse): SerializedReferrerLeaderboardPageResponse;
1759
- /**
1760
- * Serialize a {@link ReferrerMetricsEditionsResponse} object.
1761
- */
1762
- declare function serializeReferrerMetricsEditionsResponse(response: ReferrerMetricsEditionsResponse): SerializedReferrerMetricsEditionsResponse;
1763
- /**
1764
- * Serialize a {@link ReferralProgramEditionSummariesResponse} object.
1765
- */
1766
- declare function serializeReferralProgramEditionSummariesResponse(response: ReferralProgramEditionSummariesResponse): SerializedReferralProgramEditionSummariesResponse;
1767
-
1768
- /**
1769
- * Calculate the score of a referrer based on the total incremental duration
1770
- * (in seconds) of registrations and renewals for direct subnames of .eth
1771
- * referred by the referrer within the referral program edition.
1772
- *
1773
- * Used exclusively in the pie-split award model pipeline.
1774
- *
1775
- * @param totalIncrementalDuration - The total incremental duration (in seconds)
1776
- * of referrals made by a referrer within the {@link ReferralProgramRulesPieSplit}.
1777
- */
1778
- declare const calcReferrerScorePieSplit: (totalIncrementalDuration: Duration) => ReferrerScore;
1779
-
1780
- /**
1781
- * Calculate the status of a `pie-split` referral program.
1782
- *
1783
- * Delegates entirely to {@link calcBaseReferralProgramEditionStatus} — pie-split has no additional
1784
- * runtime conditions that affect status beyond the time-based lifecycle.
1785
- *
1786
- * @param rules - The pie-split rules for the edition.
1787
- * @param now - Current date in {@link UnixTimestamp} format.
1788
- */
1789
- declare const calcReferralProgramEditionStatusPieSplit: (rules: ReferralProgramRulesPieSplit, now: UnixTimestamp) => ReferralProgramEditionStatusId;
1790
-
1791
- /**
1792
- * Calculate the status of a `rev-share-limit` referral program.
1793
- *
1794
- * Returns `Exhausted` when the program is `Active` but its award pool has been fully consumed
1795
- * (`awardPoolRemaining.amount === 0n`). Otherwise delegates to {@link calcBaseReferralProgramEditionStatus}.
1796
- *
1797
- * @param rules - The rev-share-limit rules for the edition.
1798
- * @param now - Current date in {@link UnixTimestamp} format.
1799
- * @param aggregatedMetrics - The aggregated leaderboard metrics, used to check `awardPoolRemaining`.
1800
- */
1801
- declare const calcReferralProgramEditionStatusRevShareLimit: (rules: ReferralProgramRulesRevShareLimit, now: UnixTimestamp, aggregatedMetrics: AggregatedReferrerMetricsRevShareLimit) => ReferralProgramEditionStatusId;
1802
-
1803
- /**
1804
- * Default ENSNode API endpoint URL
1805
- */
1806
- declare const DEFAULT_ENSNODE_API_URL: "https://api.alpha.ensnode.io";
1807
- /**
1808
- * Configuration options for ENS Referrals API client
1809
- */
1810
- interface ClientOptions {
1811
- /** The ENSNode API URL */
1812
- url: URL;
1813
- }
1814
- /**
1815
- * ENS Referrals API Client
1816
- *
1817
- * Provides access to ENS Referrals data and leaderboard information.
1818
- *
1819
- * @example
1820
- * ```typescript
1821
- * // Create client with default options
1822
- * const client = new ENSReferralsClient();
1823
- *
1824
- * // Get referrer leaderboard for December 2025 edition
1825
- * const leaderboardPage = await client.getReferrerLeaderboardPage({
1826
- * edition: "2025-12",
1827
- * page: 1,
1828
- * recordsPerPage: 25
1829
- * });
1830
- * ```
1831
- *
1832
- * @example
1833
- * ```typescript
1834
- * // Custom configuration
1835
- * const client = new ENSReferralsClient({
1836
- * url: new URL("https://my-ensnode-instance.com"),
1837
- * });
1838
- * ```
1839
- */
1840
- declare class ENSReferralsClient {
1841
- private readonly options;
1842
- static defaultOptions(): ClientOptions;
1843
- constructor(options?: Partial<ClientOptions>);
1844
- getOptions(): Readonly<ClientOptions>;
1845
- /**
1846
- * Get Referral Program Edition Config Set
1847
- *
1848
- * Fetches and deserializes a referral program edition config set from a remote URL.
1849
- *
1850
- * @param url - The URL to fetch the edition config set from
1851
- * @returns A ReferralProgramEditionConfigSet (Map of edition slugs to edition configurations)
1852
- *
1853
- * @remarks Editions whose `rules.awardModel` is not recognized by this client version are
1854
- * preserved as {@link ReferralProgramRulesUnrecognized}. The returned map includes all
1855
- * editions — recognized and unrecognized alike. Callers should check `editionConfig.rules.awardModel`
1856
- * and skip editions with `"unrecognized"` as appropriate. At least one edition of any kind must
1857
- * be present, otherwise deserialization throws.
1858
- *
1859
- * @throws if the fetch fails
1860
- * @throws if the response is not valid JSON
1861
- * @throws if the data doesn't match the expected schema
1862
- *
1863
- * @example
1864
- * ```typescript
1865
- * const url = new URL("https://example.com/editions.json");
1866
- * const editionConfigSet = await ENSReferralsClient.getReferralProgramEditionConfigSet(url);
1867
- * console.log(`Loaded ${editionConfigSet.size} editions`);
1868
- * ```
1869
- */
1870
- static getReferralProgramEditionConfigSet(url: URL): Promise<ReferralProgramEditionConfigSet>;
1871
- /**
1872
- * Fetch Referrer Leaderboard Page
1873
- *
1874
- * Retrieves a paginated list of referrer leaderboard metrics for a specific referral program edition.
1875
- *
1876
- * @param request - Request parameters including edition and pagination
1877
- * @param request.edition - The referral program edition slug (e.g., "2025-12", "2026-03", or any other configured edition slug)
1878
- * @param request.page - The page number to retrieve (1-indexed, default: 1)
1879
- * @param request.recordsPerPage - Number of records per page (default: 25, max: 100)
1880
- * @returns {ReferrerLeaderboardPageResponse}
1881
- *
1882
- * @remarks If the server returns a leaderboard page whose `awardModel` is not recognized by
1883
- * this client version, it is preserved as {@link ReferrerLeaderboardPageUnrecognized}. Callers
1884
- * should check `response.data.awardModel` and handle the `"unrecognized"` case accordingly.
1885
- *
1886
- * @throws if the ENSNode request fails
1887
- * @throws if the ENSNode API returns an error response
1888
- * @throws if the ENSNode response breaks required invariants
1889
- *
1890
- * @example
1891
- * ```typescript
1892
- * // Get first page of 2025-12 leaderboard with default page size (25 records)
1893
- * const editionSlug = "2025-12";
1894
- * const response = await client.getReferrerLeaderboardPage({ edition: editionSlug });
1895
- * if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Ok) {
1896
- * const { awardModel, pageContext, accurateAsOf } = response.data;
1897
- * if (awardModel === ReferralProgramAwardModels.Unrecognized) {
1898
- * console.log(`Unrecognized award model: ${response.data.originalAwardModel} — skipping`);
1899
- * } else {
1900
- * const { aggregatedMetrics, referrers, rules } = response.data;
1901
- * console.log(`Edition: ${editionSlug}`);
1902
- * console.log(`Subregistry: ${rules.subregistryId}`);
1903
- * console.log(`Total Referrers: ${pageContext.totalRecords}`);
1904
- * console.log(`Page ${pageContext.page} of ${pageContext.totalPages}`);
1905
- * }
1906
- * }
1907
- * ```
1908
- *
1909
- * @example
1910
- * ```typescript
1911
- * // Get second page of 2026-03 with 50 records per page
1912
- * const response = await client.getReferrerLeaderboardPage({
1913
- * edition: "2026-03",
1914
- * page: 2,
1915
- * recordsPerPage: 50
1916
- * });
1917
- * ```
1918
- *
1919
- * @example
1920
- * ```typescript
1921
- * // Handle error response (e.g., unknown edition or data not available)
1922
- * const response = await client.getReferrerLeaderboardPage({ edition: "2025-12" });
1923
- *
1924
- * if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Error) {
1925
- * console.error(response.error);
1926
- * console.error(response.errorMessage);
1927
- * }
1928
- * ```
1929
- */
1930
- getReferrerLeaderboardPage(request: ReferrerLeaderboardPageRequest): Promise<ReferrerLeaderboardPageResponse>;
1931
- /**
1932
- * Fetch Referrer Metrics for Specific Editions
1933
- *
1934
- * Retrieves detailed information about a specific referrer for the requested
1935
- * referral program editions. Returns a record mapping each requested edition slug
1936
- * to the referrer's metrics for that edition.
1937
- *
1938
- * The response data maps edition slugs to referrer metrics. Each edition's entry is a
1939
- * {@link ReferrerEditionMetrics} discriminated union. Narrow on `awardModel` first to
1940
- * exclude unrecognized models, then on `type` to distinguish ranked from unranked:
1941
- *
1942
- * - `awardModel: "unrecognized"` ({@link ReferrerEditionMetricsUnrecognized}): the server
1943
- * returned an award model this client does not recognize. Only `originalAwardModel` is
1944
- * available; no model-specific fields are present.
1945
- * - `type: "ranked"` ({@link ReferrerEditionMetricsTypeIds.Ranked}): the referrer appears on
1946
- * the leaderboard. `referrer` contains rank, qualification status, and award share.
1947
- * - `type: "unranked"` ({@link ReferrerEditionMetricsTypeIds.Unranked}): the referrer has no
1948
- * activity in this edition. `referrer` contains zero-value placeholders.
1949
- *
1950
- * **Note:** This endpoint does not allow partial success. When `responseCode === Ok`,
1951
- * all requested editions are guaranteed to be present in the response data. If any
1952
- * requested edition cannot be returned, the entire request fails with an error.
1953
- *
1954
- * @see {@link https://www.npmjs.com/package/@namehash/ens-referrals|@namehash/ens-referrals} for calculation details
1955
- *
1956
- * @param request The referrer address and edition slugs to query
1957
- * @returns {ReferrerMetricsEditionsResponse} Returns the referrer metrics for requested editions
1958
- *
1959
- * @remarks If the server returns metrics for an edition whose `awardModel` is not recognized by
1960
- * this client version, that edition's entry in `response.data` is preserved as
1961
- * {@link ReferrerEditionMetricsUnrecognized}. Callers should check each edition's `awardModel`
1962
- * and handle the `"unrecognized"` case accordingly.
1963
- *
1964
- * @throws if the ENSNode request fails
1965
- * @throws if the response data is malformed
1966
- *
1967
- * @example
1968
- * ```typescript
1969
- * // Get referrer metrics for specific editions
1970
- * const response = await client.getReferrerMetricsEditions({
1971
- * referrer: "0x1234567890123456789012345678901234567890",
1972
- * editions: ["2025-12", "2026-01"]
1973
- * });
1974
- * if (response.responseCode === ReferrerMetricsEditionsResponseCodes.Ok) {
1975
- * // All requested editions are present in response.data
1976
- * for (const [editionSlug, detail] of Object.entries(response.data)) {
1977
- * console.log(`Edition: ${editionSlug}`);
1978
- * if (detail.awardModel === ReferralProgramAwardModels.Unrecognized) {
1979
- * console.log(`Unrecognized award model: ${detail.originalAwardModel} — skipping`);
1980
- * continue;
1981
- * }
1982
- * console.log(`Type: ${detail.type}`);
1983
- * if (detail.type === ReferrerEditionMetricsTypeIds.Ranked) {
1984
- * console.log(`Rank: ${detail.referrer.rank}`);
1985
- * console.log(`Award Share: ${detail.referrer.awardPoolShare * 100}%`);
1986
- * }
1987
- * }
1988
- * }
1989
- * ```
1990
- *
1991
- * @example
1992
- * ```typescript
1993
- * // Access specific edition data directly (edition is guaranteed to exist when OK)
1994
- * const response = await client.getReferrerMetricsEditions({
1995
- * referrer: "0x1234567890123456789012345678901234567890",
1996
- * editions: ["2025-12"]
1997
- * });
1998
- * if (response.responseCode === ReferrerMetricsEditionsResponseCodes.Ok) {
1999
- * const detail = response.data["2025-12"];
2000
- * if (detail && detail.awardModel === ReferralProgramAwardModels.Unrecognized) {
2001
- * console.log(`Unrecognized award model: ${detail.originalAwardModel} — skipping`);
2002
- * } else if (detail && detail.type === ReferrerEditionMetricsTypeIds.Ranked) {
2003
- * console.log(`Edition 2025-12 Rank: ${detail.referrer.rank}`);
2004
- * } else if (detail) {
2005
- * console.log("Referrer is not on the leaderboard for 2025-12");
2006
- * }
2007
- * }
2008
- * ```
2009
- *
2010
- * @example
2011
- * ```typescript
2012
- * // Handle error response (e.g., unknown edition or data not available)
2013
- * const response = await client.getReferrerMetricsEditions({
2014
- * referrer: "0x1234567890123456789012345678901234567890",
2015
- * editions: ["2025-12", "invalid-edition"]
2016
- * });
2017
- *
2018
- * if (response.responseCode === ReferrerMetricsEditionsResponseCodes.Error) {
2019
- * console.error(response.error);
2020
- * console.error(response.errorMessage);
2021
- * }
2022
- * ```
2023
- */
2024
- getReferrerMetricsEditions(request: ReferrerMetricsEditionsRequest): Promise<ReferrerMetricsEditionsResponse>;
2025
- /**
2026
- * Get the currently configured referral program edition summaries.
2027
- * Editions are sorted in descending order by start timestamp (most recent first).
2028
- *
2029
- * @returns A response containing edition summaries, or an error response if unavailable.
2030
- *
2031
- * @remarks Editions whose `rules.awardModel` is not recognized by this client version are
2032
- * preserved as {@link ReferralProgramEditionSummaryUnrecognized}. The returned response includes all
2033
- * editions — recognized and unrecognized alike. Callers should check `edition.awardModel`
2034
- * and skip editions with `"unrecognized"` as appropriate. At least one edition of any kind must
2035
- * be present, otherwise deserialization throws.
2036
- *
2037
- * @example
2038
- * ```typescript
2039
- * const response = await client.getEditionSummaries();
2040
- *
2041
- * if (response.responseCode === ReferralProgramEditionSummariesResponseCodes.Ok) {
2042
- * console.log(`Found ${response.data.editions.length} editions`);
2043
- * for (const edition of response.data.editions) {
2044
- * console.log(`${edition.slug}: ${edition.displayName}`);
2045
- * }
2046
- * }
2047
- * ```
2048
- *
2049
- * @example
2050
- * ```typescript
2051
- * // Handle error response
2052
- * const response = await client.getEditionSummaries();
2053
- *
2054
- * if (response.responseCode === ReferralProgramEditionSummariesResponseCodes.Error) {
2055
- * console.error(response.error);
2056
- * console.error(response.errorMessage);
2057
- * }
2058
- * ```
2059
- */
2060
- getEditionSummaries(): Promise<ReferralProgramEditionSummariesResponse>;
2061
- }
2062
-
2063
- /**
2064
- * Returns the default referral program edition set with pre-built edition configurations.
2065
- *
2066
- * This function maps from an ENS namespace to the appropriate subregistry (BaseRegistrar)
2067
- * and builds the default referral program editions for that namespace.
2068
- *
2069
- * @param ensNamespaceId - The ENS namespace slug to get the default editions for
2070
- * @returns A map of edition slugs to their pre-built edition configurations
2071
- * @throws Error if the subregistry contract is not found for the given namespace
2072
- */
2073
- declare function getDefaultReferralProgramEditionConfigSet(ensNamespaceId: ENSNamespaceId): ReferralProgramEditionConfigSet;
2074
-
2075
- /**
2076
- * Build a URL to the official ENS manager app
2077
- * where the given {@link Address} is set as the referrer.
2078
- */
2079
- declare function buildEnsReferralUrl(address: Address): URL;
2080
-
2081
- declare const isInteger: (value: number) => boolean;
2082
- declare const isNonNegativeInteger: (value: number) => boolean;
2083
- declare const isPositiveInteger: (value: number) => boolean;
2084
- declare const validateNonNegativeInteger: (value: number) => void;
2085
- declare const isFiniteNonNegativeNumber: (value: number) => boolean;
2086
-
2087
- declare const validateUnixTimestamp: (timestamp: UnixTimestamp) => void;
2088
- /**
2089
- * The number of seconds in a year.
2090
- *
2091
- * (60 seconds per minute * 60 minutes per hour *
2092
- * 24 hours per day * 365.2425 days on average per year).
2093
- */
2094
- declare const SECONDS_PER_YEAR: Duration;
2095
- declare function isValidDuration(duration: Duration): boolean;
2096
- declare function validateDuration(duration: Duration): void;
2097
-
2098
- export { type AggregatedReferrerMetricsPieSplit, type AggregatedReferrerMetricsRevShareLimit, type AwardedReferrerMetricsPieSplit, type AwardedReferrerMetricsRevShareLimit, BASE_REVENUE_CONTRIBUTION_PER_YEAR, type BaseReferralProgramEditionSummary, type BaseReferralProgramRules, type BaseReferrerLeaderboardPage, type ClientOptions, DEFAULT_ENSNODE_API_URL, ENSReferralsClient, MAX_EDITIONS_PER_REQUEST, REFERRAL_PROGRAM_EDITION_SLUG_PATTERN, REFERRERS_PER_LEADERBOARD_PAGE_DEFAULT, REFERRERS_PER_LEADERBOARD_PAGE_MAX, type RankedReferrerMetricsPieSplit, type RankedReferrerMetricsRevShareLimit, type ReferralEvent, type ReferralProgramAwardModel, ReferralProgramAwardModels, type ReferralProgramEditionConfig, type ReferralProgramEditionConfigSet, type ReferralProgramEditionDisqualification, type ReferralProgramEditionSlug, type ReferralProgramEditionStatusId, ReferralProgramEditionStatuses, type ReferralProgramEditionSummariesData, type ReferralProgramEditionSummariesResponse, type ReferralProgramEditionSummariesResponseCode, ReferralProgramEditionSummariesResponseCodes, type ReferralProgramEditionSummariesResponseError, type ReferralProgramEditionSummariesResponseOk, type ReferralProgramEditionSummary, type ReferralProgramEditionSummaryPieSplit, type ReferralProgramEditionSummaryRevShareLimit, type ReferralProgramEditionSummaryUnrecognized, type ReferralProgramRules, type ReferralProgramRulesPieSplit, type ReferralProgramRulesRevShareLimit, type ReferralProgramRulesUnrecognized, type ReferrerEditionMetrics, type ReferrerEditionMetricsPieSplit, type ReferrerEditionMetricsRankedPieSplit, type ReferrerEditionMetricsRankedRevShareLimit, type ReferrerEditionMetricsRevShareLimit, type ReferrerEditionMetricsTypeId, ReferrerEditionMetricsTypeIds, type ReferrerEditionMetricsUnrankedPieSplit, type ReferrerEditionMetricsUnrankedRevShareLimit, type ReferrerEditionMetricsUnrecognized, type ReferrerLeaderboard, type ReferrerLeaderboardPage, type ReferrerLeaderboardPageContext, type ReferrerLeaderboardPageParams, type ReferrerLeaderboardPagePieSplit, type ReferrerLeaderboardPageRequest, type ReferrerLeaderboardPageResponse, type ReferrerLeaderboardPageResponseCode, ReferrerLeaderboardPageResponseCodes, type ReferrerLeaderboardPageResponseError, type ReferrerLeaderboardPageResponseOk, type ReferrerLeaderboardPageRevShareLimit, type ReferrerLeaderboardPageUnrecognized, type ReferrerLeaderboardPieSplit, type ReferrerLeaderboardRevShareLimit, type ReferrerMetrics, type ReferrerMetricsEditionsData, type ReferrerMetricsEditionsRequest, type ReferrerMetricsEditionsResponse, type ReferrerMetricsEditionsResponseCode, ReferrerMetricsEditionsResponseCodes, type ReferrerMetricsEditionsResponseError, type ReferrerMetricsEditionsResponseOk, type ReferrerMetricsForComparison, type ReferrerMetricsRevShareLimit, type ReferrerRank, type ReferrerScore, SECONDS_PER_YEAR, type ScoredReferrerMetricsPieSplit, type SerializedAggregatedReferrerMetricsPieSplit, type SerializedAggregatedReferrerMetricsRevShareLimit, type SerializedAwardedReferrerMetricsPieSplit, type SerializedAwardedReferrerMetricsRevShareLimit, type SerializedReferralProgramEditionSummariesData, type SerializedReferralProgramEditionSummariesResponse, type SerializedReferralProgramEditionSummariesResponseError, type SerializedReferralProgramEditionSummariesResponseOk, type SerializedReferralProgramEditionSummary, type SerializedReferralProgramEditionSummaryPieSplit, type SerializedReferralProgramEditionSummaryRevShareLimit, type SerializedReferralProgramRules, type SerializedReferralProgramRulesPieSplit, type SerializedReferralProgramRulesRevShareLimit, type SerializedReferrerEditionMetrics, type SerializedReferrerEditionMetricsPieSplit, type SerializedReferrerEditionMetricsRankedPieSplit, type SerializedReferrerEditionMetricsRankedRevShareLimit, type SerializedReferrerEditionMetricsRevShareLimit, type SerializedReferrerEditionMetricsUnrankedPieSplit, type SerializedReferrerEditionMetricsUnrankedRevShareLimit, type SerializedReferrerLeaderboardPage, type SerializedReferrerLeaderboardPagePieSplit, type SerializedReferrerLeaderboardPageResponse, type SerializedReferrerLeaderboardPageResponseError, type SerializedReferrerLeaderboardPageResponseOk, type SerializedReferrerLeaderboardPageRevShareLimit, type SerializedReferrerMetricsEditionsData, type SerializedReferrerMetricsEditionsResponse, type SerializedReferrerMetricsEditionsResponseError, type SerializedReferrerMetricsEditionsResponseOk, type SerializedUnrankedReferrerMetricsPieSplit, type SerializedUnrankedReferrerMetricsRevShareLimit, type UnrankedReferrerMetricsPieSplit, type UnrankedReferrerMetricsRevShareLimit, buildAggregatedReferrerMetricsPieSplit, buildAggregatedReferrerMetricsRevShareLimit, buildAwardedReferrerMetricsPieSplit, buildAwardedReferrerMetricsRevShareLimit, buildEditionSummary, buildEditionSummaryPieSplit, buildEditionSummaryRevShareLimit, buildEnsReferralUrl, buildLeaderboardPagePieSplit, buildLeaderboardPageRevShareLimit, buildRankedReferrerMetricsPieSplit, buildRankedReferrerMetricsRevShareLimit, buildReferralProgramEditionConfigSet, buildReferralProgramRulesPieSplit, buildReferralProgramRulesRevShareLimit, buildReferrerLeaderboardPageContext, buildReferrerLeaderboardPageParams, buildReferrerLeaderboardPieSplit, buildReferrerLeaderboardRevShareLimit, buildReferrerMetrics, buildReferrerMetricsRevShareLimit, buildScoredReferrerMetricsPieSplit, buildUnrankedReferrerMetricsPieSplit, buildUnrankedReferrerMetricsRevShareLimit, calcBaseReferralProgramEditionStatus, calcReferralProgramEditionStatusPieSplit, calcReferralProgramEditionStatusRevShareLimit, calcReferrerAwardPoolSharePieSplit, calcReferrerScorePieSplit, compareReferrerMetrics, deserializeReferralProgramEditionConfigSetArray, deserializeReferralProgramEditionSummariesResponse, deserializeReferrerLeaderboardPageResponse, deserializeReferrerMetricsEditionsResponse, getDefaultReferralProgramEditionConfigSet, getReferrerEditionMetrics, getReferrerLeaderboardPage, isFiniteNonNegativeNumber, isInteger, isNonNegativeInteger, isPositiveInteger, isReferrerQualifiedRevShareLimit, isValidDuration, isValidReferrerScore, normalizeAddress, serializeReferralProgramEditionSummariesResponse, serializeReferralProgramEditionSummary, serializeReferralProgramRules, serializeReferrerLeaderboardPageResponse, serializeReferrerMetricsEditionsResponse, sliceReferrers, sortReferrerMetrics, validateAggregatedReferrerMetricsPieSplit, validateAggregatedReferrerMetricsRevShareLimit, validateAwardedReferrerMetricsPieSplit, validateAwardedReferrerMetricsRevShareLimit, validateBaseReferralProgramEditionSummary, validateBaseReferralProgramRules, validateDuration, validateEditionSummaryPieSplit, validateEditionSummaryRevShareLimit, validateLowercaseAddress, validateNonNegativeInteger, validateRankedReferrerMetricsPieSplit, validateRankedReferrerMetricsRevShareLimit, validateReferralProgramEditionConfigSet, validateReferralProgramRulesPieSplit, validateReferralProgramRulesRevShareLimit, validateReferrerLeaderboardPageContext, validateReferrerMetrics, validateReferrerMetricsRevShareLimit, validateReferrerRank, validateReferrerScore, validateScoredReferrerMetricsPieSplit, validateUnixTimestamp, validateUnrankedReferrerMetricsPieSplit, validateUnrankedReferrerMetricsRevShareLimit };