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