@namehash/ens-referrals 1.10.1 → 1.11.1
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 +234 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +211 -24
- package/dist/index.d.ts +211 -24
- package/dist/index.js +234 -61
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -353,7 +353,8 @@ function scaleBigintByNumber(value, scaleFactor) {
|
|
|
353
353
|
var CurrencyIds = {
|
|
354
354
|
ETH: "ETH",
|
|
355
355
|
USDC: "USDC",
|
|
356
|
-
DAI: "DAI"
|
|
356
|
+
DAI: "DAI",
|
|
357
|
+
ENSTokens: "ENSTokens"
|
|
357
358
|
};
|
|
358
359
|
var currencyInfo = {
|
|
359
360
|
[CurrencyIds.ETH]: {
|
|
@@ -370,6 +371,11 @@ var currencyInfo = {
|
|
|
370
371
|
id: CurrencyIds.DAI,
|
|
371
372
|
name: "Dai Stablecoin",
|
|
372
373
|
decimals: 18
|
|
374
|
+
},
|
|
375
|
+
[CurrencyIds.ENSTokens]: {
|
|
376
|
+
id: CurrencyIds.ENSTokens,
|
|
377
|
+
name: "$ENS Tokens",
|
|
378
|
+
decimals: 18
|
|
373
379
|
}
|
|
374
380
|
};
|
|
375
381
|
function priceEth(amount) {
|
|
@@ -484,6 +490,34 @@ var makeAccountIdSchema = (valueLabel = "AccountId") => z.strictObject({
|
|
|
484
490
|
address: makeNormalizedAddressSchema(`${valueLabel} address`)
|
|
485
491
|
});
|
|
486
492
|
|
|
493
|
+
// ../ensnode-sdk/src/indexing-status/omnichain-indexing-status-snapshot.ts
|
|
494
|
+
var OmnichainIndexingStatusIds = {
|
|
495
|
+
/**
|
|
496
|
+
* Represents that omnichain indexing is not ready to begin yet because
|
|
497
|
+
* ENSIndexer is in its initialization phase and the data to build a "true"
|
|
498
|
+
* {@link OmnichainIndexingStatusSnapshot} is still being loaded.
|
|
499
|
+
*/
|
|
500
|
+
Unstarted: "omnichain-unstarted",
|
|
501
|
+
/**
|
|
502
|
+
* Represents that omnichain indexing is in an overall "backfill" status because
|
|
503
|
+
* - At least one indexed chain has a `chainStatus` of
|
|
504
|
+
* {@link ChainIndexingStatusIds.Backfill}; and
|
|
505
|
+
* - No indexed chain has a `chainStatus` of {@link ChainIndexingStatusIds.Following}.
|
|
506
|
+
*/
|
|
507
|
+
Backfill: "omnichain-backfill",
|
|
508
|
+
/**
|
|
509
|
+
* Represents that omnichain indexing is in an overall "following" status because
|
|
510
|
+
* at least one indexed chain has a `chainStatus` of
|
|
511
|
+
* {@link ChainIndexingStatusIds.Following}.
|
|
512
|
+
*/
|
|
513
|
+
Following: "omnichain-following",
|
|
514
|
+
/**
|
|
515
|
+
* Represents that omnichain indexing has completed because all indexed chains have
|
|
516
|
+
* a `chainStatus` of {@link ChainIndexingStatusIds.Completed}.
|
|
517
|
+
*/
|
|
518
|
+
Completed: "omnichain-completed"
|
|
519
|
+
};
|
|
520
|
+
|
|
487
521
|
// ../ensnode-sdk/src/shared/serialize.ts
|
|
488
522
|
function serializePrice(price) {
|
|
489
523
|
return {
|
|
@@ -504,6 +538,62 @@ import z3 from "zod/v4";
|
|
|
504
538
|
// src/award-models/shared/api/zod-schemas.ts
|
|
505
539
|
import z2 from "zod/v4";
|
|
506
540
|
|
|
541
|
+
// src/edition.ts
|
|
542
|
+
var REFERRAL_PROGRAM_EDITION_SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
543
|
+
function validateReferralProgramEditionConfigSet(configSet) {
|
|
544
|
+
const violation = Array.from(configSet.entries()).find(([key, config]) => key !== config.slug);
|
|
545
|
+
if (violation) {
|
|
546
|
+
const [key, config] = violation;
|
|
547
|
+
throw new Error(
|
|
548
|
+
`Edition config set invariant violation: map key "${key}" does not match config.slug "${config.slug}"`
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
const overlap = findOverlappingEditionPair(Array.from(configSet.values()));
|
|
552
|
+
if (overlap) {
|
|
553
|
+
const [a, b] = overlap;
|
|
554
|
+
throw new Error(
|
|
555
|
+
`Edition config set invariant violation: editions "${a.slug}" and "${b.slug}" have overlapping time ranges for subregistryId ${a.rules.subregistryId.chainId}:${a.rules.subregistryId.address} (startTime and endTime are inclusive)`
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
function findOverlappingEditionPair(editions) {
|
|
560
|
+
const byRegistry = /* @__PURE__ */ new Map();
|
|
561
|
+
for (const edition of editions) {
|
|
562
|
+
const key = `${edition.rules.subregistryId.chainId}:${edition.rules.subregistryId.address}`;
|
|
563
|
+
const group = byRegistry.get(key);
|
|
564
|
+
if (group) {
|
|
565
|
+
group.push(edition);
|
|
566
|
+
} else {
|
|
567
|
+
byRegistry.set(key, [edition]);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
for (const group of byRegistry.values()) {
|
|
571
|
+
if (group.length < 2) continue;
|
|
572
|
+
group.sort((a, b) => a.rules.startTime - b.rules.startTime);
|
|
573
|
+
for (let i = 1; i < group.length; i++) {
|
|
574
|
+
const prev = group[i - 1];
|
|
575
|
+
const curr = group[i];
|
|
576
|
+
if (curr.rules.startTime <= prev.rules.endTime) {
|
|
577
|
+
return [prev, curr];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
function buildReferralProgramEditionConfigSet(configs) {
|
|
584
|
+
const slugCounts = configs.reduce((counts, config) => {
|
|
585
|
+
counts.set(config.slug, (counts.get(config.slug) || 0) + 1);
|
|
586
|
+
return counts;
|
|
587
|
+
}, /* @__PURE__ */ new Map());
|
|
588
|
+
const duplicates = Array.from(slugCounts.entries()).filter(([_, count]) => count > 1).map(([slug, count]) => `"${slug}" (${count} occurrences)`);
|
|
589
|
+
if (duplicates.length > 0) {
|
|
590
|
+
throw new Error(`Duplicate edition config slugs detected: ${duplicates.join(", ")}`);
|
|
591
|
+
}
|
|
592
|
+
const configSet = new Map(configs.map((config) => [config.slug, config]));
|
|
593
|
+
validateReferralProgramEditionConfigSet(configSet);
|
|
594
|
+
return configSet;
|
|
595
|
+
}
|
|
596
|
+
|
|
507
597
|
// src/number.ts
|
|
508
598
|
var isInteger = (value) => {
|
|
509
599
|
return Number.isInteger(value);
|
|
@@ -710,6 +800,15 @@ var calcBaseReferralProgramEditionStatus = (rules, now) => {
|
|
|
710
800
|
};
|
|
711
801
|
|
|
712
802
|
// src/award-models/shared/api/zod-schemas.ts
|
|
803
|
+
var makeReferralProgramEditionSlugSchema = (valueLabel = "ReferralProgramEditionSlug") => z2.string().min(1, `${valueLabel} must not be empty`).regex(
|
|
804
|
+
REFERRAL_PROGRAM_EDITION_SLUG_PATTERN,
|
|
805
|
+
`${valueLabel} must contain only lowercase letters, digits, and hyphens. Must not start or end with a hyphen.`
|
|
806
|
+
);
|
|
807
|
+
var makeBaseReferralProgramEditionConfigSchema = (valueLabel = "BaseReferralProgramEditionConfig") => z2.object({
|
|
808
|
+
slug: makeReferralProgramEditionSlugSchema(`${valueLabel}.slug`),
|
|
809
|
+
displayName: z2.string().min(1, `${valueLabel}.displayName must not be empty`),
|
|
810
|
+
rules: makeBaseReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
811
|
+
});
|
|
713
812
|
var makeBaseReferralProgramRulesSchema = (valueLabel) => z2.object({
|
|
714
813
|
awardModel: z2.string(),
|
|
715
814
|
startTime: makeUnixTimestampSchema(`${valueLabel}.startTime`),
|
|
@@ -735,12 +834,9 @@ var makeReferrerLeaderboardPageContextSchema = (valueLabel = "ReferrerLeaderboar
|
|
|
735
834
|
endIndex: z2.optional(makeNonNegativeIntegerSchema(`${valueLabel}.endIndex`))
|
|
736
835
|
});
|
|
737
836
|
var makeReferralProgramStatusSchema = (_valueLabel = "status") => z2.enum(ReferralProgramEditionStatuses);
|
|
738
|
-
var makeBaseReferralProgramEditionSummarySchema = (valueLabel) =>
|
|
837
|
+
var makeBaseReferralProgramEditionSummarySchema = (valueLabel) => makeBaseReferralProgramEditionConfigSchema(valueLabel).safeExtend({
|
|
739
838
|
awardModel: z2.string(),
|
|
740
|
-
|
|
741
|
-
displayName: z2.string().min(1, `${valueLabel}.displayName must not be empty`),
|
|
742
|
-
status: makeReferralProgramStatusSchema(`${valueLabel}.status`),
|
|
743
|
-
rules: makeBaseReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
839
|
+
status: makeReferralProgramStatusSchema(`${valueLabel}.status`)
|
|
744
840
|
});
|
|
745
841
|
var makeBaseReferrerLeaderboardPageSchema = (valueLabel) => z2.object({
|
|
746
842
|
awardModel: z2.string(),
|
|
@@ -1321,10 +1417,6 @@ var makeReferrerEditionMetricsSchema = (valueLabel = "ReferrerEditionMetrics") =
|
|
|
1321
1417
|
};
|
|
1322
1418
|
});
|
|
1323
1419
|
};
|
|
1324
|
-
var makeReferralProgramEditionSlugSchema = (valueLabel = "ReferralProgramEditionSlug") => z5.string().min(1, `${valueLabel} must not be empty`).regex(
|
|
1325
|
-
/^[a-z0-9]+(-[a-z0-9]+)*$/,
|
|
1326
|
-
`${valueLabel} must contain only lowercase letters, digits, and hyphens. Must not start or end with a hyphen.`
|
|
1327
|
-
);
|
|
1328
1420
|
var makeReferrerMetricsEditionsResponseOkSchema = (valueLabel = "ReferrerMetricsEditionsResponseOk") => z5.object({
|
|
1329
1421
|
responseCode: z5.literal(ReferrerMetricsEditionsResponseCodes.Ok),
|
|
1330
1422
|
data: z5.record(
|
|
@@ -1341,12 +1433,7 @@ var makeReferrerMetricsEditionsResponseSchema = (valueLabel = "ReferrerMetricsEd
|
|
|
1341
1433
|
makeReferrerMetricsEditionsResponseOkSchema(valueLabel),
|
|
1342
1434
|
makeReferrerMetricsEditionsResponseErrorSchema(valueLabel)
|
|
1343
1435
|
]);
|
|
1344
|
-
var
|
|
1345
|
-
slug: makeReferralProgramEditionSlugSchema(`${valueLabel}.slug`),
|
|
1346
|
-
displayName: z5.string().min(1, `${valueLabel}.displayName must not be empty`),
|
|
1347
|
-
rules: makeBaseReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
1348
|
-
});
|
|
1349
|
-
var makeReferralProgramEditionConfigSchema = (valueLabel = "ReferralProgramEditionConfig") => makeReferralProgramEditionConfigBaseSchema(valueLabel).safeExtend({
|
|
1436
|
+
var makeReferralProgramEditionConfigSchema = (valueLabel = "ReferralProgramEditionConfig") => makeBaseReferralProgramEditionConfigSchema(valueLabel).safeExtend({
|
|
1350
1437
|
rules: makeReferralProgramRulesSchema(`${valueLabel}.rules`)
|
|
1351
1438
|
});
|
|
1352
1439
|
var makeReferralProgramEditionConfigSetArraySchema = (valueLabel = "ReferralProgramEditionConfigSetArray") => {
|
|
@@ -1357,7 +1444,7 @@ var makeReferralProgramEditionConfigSetArraySchema = (valueLabel = "ReferralProg
|
|
|
1357
1444
|
const looseItemSchema = z5.looseObject({
|
|
1358
1445
|
rules: z5.looseObject({ awardModel: z5.string() })
|
|
1359
1446
|
});
|
|
1360
|
-
const unrecognizedBaseSchema =
|
|
1447
|
+
const unrecognizedBaseSchema = makeBaseReferralProgramEditionConfigSchema(
|
|
1361
1448
|
`${valueLabel}[edition]`
|
|
1362
1449
|
);
|
|
1363
1450
|
return z5.array(looseItemSchema).transform((items, ctx) => {
|
|
@@ -1398,6 +1485,15 @@ var makeReferralProgramEditionConfigSetArraySchema = (valueLabel = "ReferralProg
|
|
|
1398
1485
|
}
|
|
1399
1486
|
slugs.add(edition.slug);
|
|
1400
1487
|
}
|
|
1488
|
+
const overlap = findOverlappingEditionPair(result);
|
|
1489
|
+
if (overlap) {
|
|
1490
|
+
const [a, b] = overlap;
|
|
1491
|
+
ctx.addIssue({
|
|
1492
|
+
code: "custom",
|
|
1493
|
+
message: `${valueLabel}: editions "${a.slug}" and "${b.slug}" have overlapping time ranges for subregistryId ${a.rules.subregistryId.chainId}:${a.rules.subregistryId.address} (startTime and endTime are inclusive)`
|
|
1494
|
+
});
|
|
1495
|
+
return [];
|
|
1496
|
+
}
|
|
1401
1497
|
return result;
|
|
1402
1498
|
});
|
|
1403
1499
|
};
|
|
@@ -1438,6 +1534,15 @@ var makeReferralProgramEditionSummarySchema = (valueLabel = "ReferralProgramEdit
|
|
|
1438
1534
|
};
|
|
1439
1535
|
var makeReferralProgramEditionSummariesDataSchema = (valueLabel = "ReferralProgramEditionSummariesData") => z5.object({
|
|
1440
1536
|
editions: z5.array(makeReferralProgramEditionSummarySchema(`${valueLabel}.editions[edition]`))
|
|
1537
|
+
}).superRefine((data, ctx) => {
|
|
1538
|
+
const overlap = findOverlappingEditionPair(data.editions);
|
|
1539
|
+
if (!overlap) return;
|
|
1540
|
+
const [a, b] = overlap;
|
|
1541
|
+
ctx.addIssue({
|
|
1542
|
+
code: "custom",
|
|
1543
|
+
path: ["editions"],
|
|
1544
|
+
message: `${valueLabel}: editions "${a.slug}" and "${b.slug}" have overlapping time ranges for subregistryId ${a.rules.subregistryId.chainId}:${a.rules.subregistryId.address} (startTime and endTime are inclusive)`
|
|
1545
|
+
});
|
|
1441
1546
|
});
|
|
1442
1547
|
var makeReferralProgramEditionSummariesResponseOkSchema = (valueLabel = "ReferralProgramEditionSummariesResponseOk") => z5.object({
|
|
1443
1548
|
responseCode: z5.literal(ReferralProgramEditionSummariesResponseCodes.Ok),
|
|
@@ -1503,6 +1608,36 @@ ${prettifyError(parsed.error)}
|
|
|
1503
1608
|
return parsed.data;
|
|
1504
1609
|
}
|
|
1505
1610
|
|
|
1611
|
+
// src/api/prerequisites.ts
|
|
1612
|
+
var ensAnalyticsRequiredPlugins = [
|
|
1613
|
+
"subgraph" /* Subgraph */,
|
|
1614
|
+
"basenames" /* Basenames */,
|
|
1615
|
+
"lineanames" /* Lineanames */,
|
|
1616
|
+
"registrars" /* Registrars */
|
|
1617
|
+
];
|
|
1618
|
+
function hasEnsAnalyticsConfigSupport(config) {
|
|
1619
|
+
const supported = ensAnalyticsRequiredPlugins.every((plugin) => config.plugins.includes(plugin));
|
|
1620
|
+
if (supported) return { supported };
|
|
1621
|
+
return {
|
|
1622
|
+
supported: false,
|
|
1623
|
+
reason: `The ENSAnalytics API requires all of the following plugins to be activated in the connected ENSNode's Config: ${ensAnalyticsRequiredPlugins.map((plugin) => `'${plugin}'`).join(", ")}.`
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
var ensAnalyticsSupportedIndexingStatusIds = [
|
|
1627
|
+
OmnichainIndexingStatusIds.Completed,
|
|
1628
|
+
OmnichainIndexingStatusIds.Following
|
|
1629
|
+
];
|
|
1630
|
+
function hasEnsAnalyticsIndexingStatusSupport(omnichainIndexingStatusId) {
|
|
1631
|
+
const supported = ensAnalyticsSupportedIndexingStatusIds.some(
|
|
1632
|
+
(supportedIndexingStatusId) => supportedIndexingStatusId === omnichainIndexingStatusId
|
|
1633
|
+
);
|
|
1634
|
+
if (supported) return { supported };
|
|
1635
|
+
return {
|
|
1636
|
+
supported: false,
|
|
1637
|
+
reason: `The ENSAnalytics API requires the connected ENSNode's Indexing Status to be one of the following: ${ensAnalyticsSupportedIndexingStatusIds.join(", ")}.`
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1506
1641
|
// src/award-models/pie-split/api/serialize.ts
|
|
1507
1642
|
function serializeReferralProgramRulesPieSplit(rules) {
|
|
1508
1643
|
return {
|
|
@@ -1917,31 +2052,6 @@ var buildAggregatedReferrerMetricsPieSplit = (referrers, rules) => {
|
|
|
1917
2052
|
return result;
|
|
1918
2053
|
};
|
|
1919
2054
|
|
|
1920
|
-
// src/edition.ts
|
|
1921
|
-
var REFERRAL_PROGRAM_EDITION_SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
1922
|
-
function validateReferralProgramEditionConfigSet(configSet) {
|
|
1923
|
-
const violation = Array.from(configSet.entries()).find(([key, config]) => key !== config.slug);
|
|
1924
|
-
if (violation) {
|
|
1925
|
-
const [key, config] = violation;
|
|
1926
|
-
throw new Error(
|
|
1927
|
-
`Edition config set invariant violation: map key "${key}" does not match config.slug "${config.slug}"`
|
|
1928
|
-
);
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
function buildReferralProgramEditionConfigSet(configs) {
|
|
1932
|
-
const slugCounts = configs.reduce((counts, config) => {
|
|
1933
|
-
counts.set(config.slug, (counts.get(config.slug) || 0) + 1);
|
|
1934
|
-
return counts;
|
|
1935
|
-
}, /* @__PURE__ */ new Map());
|
|
1936
|
-
const duplicates = Array.from(slugCounts.entries()).filter(([_, count]) => count > 1).map(([slug, count]) => `"${slug}" (${count} occurrences)`);
|
|
1937
|
-
if (duplicates.length > 0) {
|
|
1938
|
-
throw new Error(`Duplicate edition config slugs detected: ${duplicates.join(", ")}`);
|
|
1939
|
-
}
|
|
1940
|
-
const configSet = new Map(configs.map((config) => [config.slug, config]));
|
|
1941
|
-
validateReferralProgramEditionConfigSet(configSet);
|
|
1942
|
-
return configSet;
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
2055
|
// src/award-models/shared/edition-summary.ts
|
|
1946
2056
|
var validateBaseReferralProgramEditionSummary = (summary) => {
|
|
1947
2057
|
if (!REFERRAL_PROGRAM_EDITION_SLUG_PATTERN.test(summary.slug)) {
|
|
@@ -2237,7 +2347,7 @@ var buildUnrankedReferrerMetricsPieSplit = (referrer) => {
|
|
|
2237
2347
|
};
|
|
2238
2348
|
|
|
2239
2349
|
// src/award-models/pie-split/leaderboard.ts
|
|
2240
|
-
var
|
|
2350
|
+
var buildReferralEditionSnapshotPieSplit = (allReferrers, rules, accurateAsOf) => {
|
|
2241
2351
|
assertLeaderboardInputs(allReferrers, rules, accurateAsOf);
|
|
2242
2352
|
const sortedReferrers = sortReferrerMetrics(allReferrers);
|
|
2243
2353
|
const scoredReferrers = sortedReferrers.map((r) => buildScoredReferrerMetricsPieSplit(r));
|
|
@@ -2249,7 +2359,14 @@ var buildReferrerLeaderboardPieSplit = (allReferrers, rules, accurateAsOf) => {
|
|
|
2249
2359
|
(r) => buildAwardedReferrerMetricsPieSplit(r, aggregatedMetrics, rules)
|
|
2250
2360
|
);
|
|
2251
2361
|
const referrers = new Map(awardedReferrers.map((r) => [r.referrer, r]));
|
|
2252
|
-
|
|
2362
|
+
const leaderboard = {
|
|
2363
|
+
awardModel: rules.awardModel,
|
|
2364
|
+
rules,
|
|
2365
|
+
aggregatedMetrics,
|
|
2366
|
+
referrers,
|
|
2367
|
+
accurateAsOf
|
|
2368
|
+
};
|
|
2369
|
+
return { awardModel: rules.awardModel, leaderboard };
|
|
2253
2370
|
};
|
|
2254
2371
|
|
|
2255
2372
|
// src/award-models/pie-split/leaderboard-page.ts
|
|
@@ -2527,9 +2644,14 @@ function sortReferralEvents(events) {
|
|
|
2527
2644
|
}
|
|
2528
2645
|
|
|
2529
2646
|
// src/award-models/rev-share-cap/leaderboard.ts
|
|
2530
|
-
var
|
|
2647
|
+
var buildReferralEditionSnapshotRevShareCap = (events, rules, accurateAsOf) => {
|
|
2531
2648
|
const sortedEvents = sortReferralEvents(events);
|
|
2649
|
+
const adminActionByReferrer = /* @__PURE__ */ new Map();
|
|
2650
|
+
for (const action of rules.adminActions) {
|
|
2651
|
+
adminActionByReferrer.set(action.referrer, action);
|
|
2652
|
+
}
|
|
2532
2653
|
const referrerStates = /* @__PURE__ */ new Map();
|
|
2654
|
+
const accountingRecords = [];
|
|
2533
2655
|
let awardPoolRemaining = rules.awardPool;
|
|
2534
2656
|
for (const event of sortedEvents) {
|
|
2535
2657
|
const referrerId = event.referrer;
|
|
@@ -2550,27 +2672,65 @@ var buildReferrerLeaderboardRevShareCap = (events, rules, accurateAsOf) => {
|
|
|
2550
2672
|
referrerState.totalRevenueContribution,
|
|
2551
2673
|
event.incrementalRevenueContribution
|
|
2552
2674
|
);
|
|
2553
|
-
const
|
|
2675
|
+
const hasQualifiedBefore = referrerState.hasQualified;
|
|
2676
|
+
const awardPoolRemainingBefore = awardPoolRemaining;
|
|
2677
|
+
const adminAction = adminActionByReferrer.get(referrerId);
|
|
2678
|
+
const adminDisqualification = adminAction?.actionType === AdminActionTypes.Disqualification ? adminAction : null;
|
|
2679
|
+
const accumulatedBaseRevenueContribution = calcBaseRevenueContribution(
|
|
2554
2680
|
rules,
|
|
2555
2681
|
referrerState.totalIncrementalDuration
|
|
2556
2682
|
);
|
|
2557
|
-
const
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2683
|
+
const incrementalBaseRevenueContribution = calcBaseRevenueContribution(
|
|
2684
|
+
rules,
|
|
2685
|
+
event.incrementalDuration
|
|
2686
|
+
);
|
|
2687
|
+
const isNowQualified = isReferrerQualifiedRevShareCap(
|
|
2688
|
+
referrerId,
|
|
2689
|
+
accumulatedBaseRevenueContribution,
|
|
2690
|
+
rules
|
|
2691
|
+
);
|
|
2692
|
+
let incrementalTentativeAward = priceUsdc(0n);
|
|
2693
|
+
if (isNowQualified && !hasQualifiedBefore) {
|
|
2694
|
+
const accumulatedUncappedAward = scalePrice(
|
|
2695
|
+
accumulatedBaseRevenueContribution,
|
|
2696
|
+
rules.maxBaseRevenueShare
|
|
2697
|
+
);
|
|
2698
|
+
incrementalTentativeAward = minPrice(accumulatedUncappedAward, awardPoolRemainingBefore);
|
|
2563
2699
|
referrerState.hasQualified = true;
|
|
2564
|
-
} else if (
|
|
2565
|
-
const incrementalBaseRevenue = calcBaseRevenueContribution(rules, event.incrementalDuration);
|
|
2700
|
+
} else if (hasQualifiedBefore) {
|
|
2566
2701
|
const incrementalUncappedAward = scalePrice(
|
|
2567
|
-
|
|
2702
|
+
incrementalBaseRevenueContribution,
|
|
2568
2703
|
rules.maxBaseRevenueShare
|
|
2569
2704
|
);
|
|
2570
|
-
|
|
2571
|
-
referrerState.cappedAward = addPrices(referrerState.cappedAward, incrementalCappedAward);
|
|
2572
|
-
awardPoolRemaining = subtractPrice(awardPoolRemaining, incrementalCappedAward);
|
|
2705
|
+
incrementalTentativeAward = minPrice(incrementalUncappedAward, awardPoolRemainingBefore);
|
|
2573
2706
|
}
|
|
2707
|
+
referrerState.cappedAward = addPrices(referrerState.cappedAward, incrementalTentativeAward);
|
|
2708
|
+
awardPoolRemaining = subtractPrice(awardPoolRemaining, incrementalTentativeAward);
|
|
2709
|
+
const tentativeAward = {
|
|
2710
|
+
incrementalRevenueContribution: event.incrementalRevenueContribution,
|
|
2711
|
+
accumulatedRevenueContribution: referrerState.totalRevenueContribution,
|
|
2712
|
+
incrementalBaseRevenueContribution,
|
|
2713
|
+
accumulatedBaseRevenueContribution,
|
|
2714
|
+
awardPoolRemaining: awardPoolRemainingBefore,
|
|
2715
|
+
disqualified: adminDisqualification !== null,
|
|
2716
|
+
...adminDisqualification !== null && {
|
|
2717
|
+
disqualificationReason: adminDisqualification.reason
|
|
2718
|
+
},
|
|
2719
|
+
maxRevShare: rules.maxBaseRevenueShare,
|
|
2720
|
+
effectiveBaseRevShare: incrementalBaseRevenueContribution.amount === 0n ? 0 : Number(incrementalTentativeAward.amount) / Number(incrementalBaseRevenueContribution.amount),
|
|
2721
|
+
incrementalTentativeAward
|
|
2722
|
+
};
|
|
2723
|
+
accountingRecords.push({
|
|
2724
|
+
registrarActionId: event.id,
|
|
2725
|
+
timestamp: event.timestamp,
|
|
2726
|
+
name: event.name,
|
|
2727
|
+
actionType: event.actionType,
|
|
2728
|
+
transactionHash: event.transactionHash,
|
|
2729
|
+
registrant: event.registrant,
|
|
2730
|
+
referrer: referrerId,
|
|
2731
|
+
incrementalDuration: event.incrementalDuration,
|
|
2732
|
+
tentativeAward
|
|
2733
|
+
});
|
|
2574
2734
|
}
|
|
2575
2735
|
const sortedEntries = [...referrerStates.entries()].sort(
|
|
2576
2736
|
([referrerIdA, referrerStateA], [referrerIdB, referrerStateB]) => {
|
|
@@ -2616,7 +2776,17 @@ var buildReferrerLeaderboardRevShareCap = (events, rules, accurateAsOf) => {
|
|
|
2616
2776
|
awardPoolRemaining
|
|
2617
2777
|
);
|
|
2618
2778
|
const referrers = new Map(awardedReferrers.map((r) => [r.referrer, r]));
|
|
2619
|
-
return {
|
|
2779
|
+
return {
|
|
2780
|
+
awardModel: rules.awardModel,
|
|
2781
|
+
leaderboard: {
|
|
2782
|
+
awardModel: rules.awardModel,
|
|
2783
|
+
rules,
|
|
2784
|
+
aggregatedMetrics,
|
|
2785
|
+
referrers,
|
|
2786
|
+
accurateAsOf
|
|
2787
|
+
},
|
|
2788
|
+
accountingRecords
|
|
2789
|
+
};
|
|
2620
2790
|
};
|
|
2621
2791
|
|
|
2622
2792
|
// src/award-models/rev-share-cap/leaderboard-page.ts
|
|
@@ -3065,13 +3235,13 @@ export {
|
|
|
3065
3235
|
buildLeaderboardPageRevShareCap,
|
|
3066
3236
|
buildRankedReferrerMetricsPieSplit,
|
|
3067
3237
|
buildRankedReferrerMetricsRevShareCap,
|
|
3238
|
+
buildReferralEditionSnapshotPieSplit,
|
|
3239
|
+
buildReferralEditionSnapshotRevShareCap,
|
|
3068
3240
|
buildReferralProgramEditionConfigSet,
|
|
3069
3241
|
buildReferralProgramRulesPieSplit,
|
|
3070
3242
|
buildReferralProgramRulesRevShareCap,
|
|
3071
3243
|
buildReferrerLeaderboardPageContext,
|
|
3072
3244
|
buildReferrerLeaderboardPageParams,
|
|
3073
|
-
buildReferrerLeaderboardPieSplit,
|
|
3074
|
-
buildReferrerLeaderboardRevShareCap,
|
|
3075
3245
|
buildReferrerMetrics,
|
|
3076
3246
|
buildReferrerMetricsRevShareCap,
|
|
3077
3247
|
buildScoredReferrerMetricsPieSplit,
|
|
@@ -3088,8 +3258,11 @@ export {
|
|
|
3088
3258
|
deserializeReferralProgramEditionSummariesResponse,
|
|
3089
3259
|
deserializeReferrerLeaderboardPageResponse,
|
|
3090
3260
|
deserializeReferrerMetricsEditionsResponse,
|
|
3261
|
+
findOverlappingEditionPair,
|
|
3091
3262
|
getReferrerEditionMetrics,
|
|
3092
3263
|
getReferrerLeaderboardPage,
|
|
3264
|
+
hasEnsAnalyticsConfigSupport,
|
|
3265
|
+
hasEnsAnalyticsIndexingStatusSupport,
|
|
3093
3266
|
isFiniteNonNegativeNumber,
|
|
3094
3267
|
isInteger,
|
|
3095
3268
|
isNonNegativeInteger,
|