@namehash/ens-referrals 1.11.0 → 1.12.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 +140 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +183 -6
- package/dist/index.d.ts +183 -6
- package/dist/index.js +140 -20
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -56,13 +56,13 @@ __export(index_exports, {
|
|
|
56
56
|
buildLeaderboardPageRevShareCap: () => buildLeaderboardPageRevShareCap,
|
|
57
57
|
buildRankedReferrerMetricsPieSplit: () => buildRankedReferrerMetricsPieSplit,
|
|
58
58
|
buildRankedReferrerMetricsRevShareCap: () => buildRankedReferrerMetricsRevShareCap,
|
|
59
|
+
buildReferralEditionSnapshotPieSplit: () => buildReferralEditionSnapshotPieSplit,
|
|
60
|
+
buildReferralEditionSnapshotRevShareCap: () => buildReferralEditionSnapshotRevShareCap,
|
|
59
61
|
buildReferralProgramEditionConfigSet: () => buildReferralProgramEditionConfigSet,
|
|
60
62
|
buildReferralProgramRulesPieSplit: () => buildReferralProgramRulesPieSplit,
|
|
61
63
|
buildReferralProgramRulesRevShareCap: () => buildReferralProgramRulesRevShareCap,
|
|
62
64
|
buildReferrerLeaderboardPageContext: () => buildReferrerLeaderboardPageContext,
|
|
63
65
|
buildReferrerLeaderboardPageParams: () => buildReferrerLeaderboardPageParams,
|
|
64
|
-
buildReferrerLeaderboardPieSplit: () => buildReferrerLeaderboardPieSplit,
|
|
65
|
-
buildReferrerLeaderboardRevShareCap: () => buildReferrerLeaderboardRevShareCap,
|
|
66
66
|
buildReferrerMetrics: () => buildReferrerMetrics,
|
|
67
67
|
buildReferrerMetricsRevShareCap: () => buildReferrerMetricsRevShareCap,
|
|
68
68
|
buildScoredReferrerMetricsPieSplit: () => buildScoredReferrerMetricsPieSplit,
|
|
@@ -82,6 +82,8 @@ __export(index_exports, {
|
|
|
82
82
|
findOverlappingEditionPair: () => findOverlappingEditionPair,
|
|
83
83
|
getReferrerEditionMetrics: () => getReferrerEditionMetrics,
|
|
84
84
|
getReferrerLeaderboardPage: () => getReferrerLeaderboardPage,
|
|
85
|
+
hasEnsAnalyticsConfigSupport: () => hasEnsAnalyticsConfigSupport,
|
|
86
|
+
hasEnsAnalyticsIndexingStatusSupport: () => hasEnsAnalyticsIndexingStatusSupport,
|
|
85
87
|
isFiniteNonNegativeNumber: () => isFiniteNonNegativeNumber,
|
|
86
88
|
isInteger: () => isInteger,
|
|
87
89
|
isNonNegativeInteger: () => isNonNegativeInteger,
|
|
@@ -616,6 +618,34 @@ var makeAccountIdSchema = (valueLabel = "AccountId") => import_v4.z.strictObject
|
|
|
616
618
|
address: makeNormalizedAddressSchema(`${valueLabel} address`)
|
|
617
619
|
});
|
|
618
620
|
|
|
621
|
+
// ../ensnode-sdk/src/indexing-status/omnichain-indexing-status-snapshot.ts
|
|
622
|
+
var OmnichainIndexingStatusIds = {
|
|
623
|
+
/**
|
|
624
|
+
* Represents that omnichain indexing is not ready to begin yet because
|
|
625
|
+
* ENSIndexer is in its initialization phase and the data to build a "true"
|
|
626
|
+
* {@link OmnichainIndexingStatusSnapshot} is still being loaded.
|
|
627
|
+
*/
|
|
628
|
+
Unstarted: "omnichain-unstarted",
|
|
629
|
+
/**
|
|
630
|
+
* Represents that omnichain indexing is in an overall "backfill" status because
|
|
631
|
+
* - At least one indexed chain has a `chainStatus` of
|
|
632
|
+
* {@link ChainIndexingStatusIds.Backfill}; and
|
|
633
|
+
* - No indexed chain has a `chainStatus` of {@link ChainIndexingStatusIds.Following}.
|
|
634
|
+
*/
|
|
635
|
+
Backfill: "omnichain-backfill",
|
|
636
|
+
/**
|
|
637
|
+
* Represents that omnichain indexing is in an overall "following" status because
|
|
638
|
+
* at least one indexed chain has a `chainStatus` of
|
|
639
|
+
* {@link ChainIndexingStatusIds.Following}.
|
|
640
|
+
*/
|
|
641
|
+
Following: "omnichain-following",
|
|
642
|
+
/**
|
|
643
|
+
* Represents that omnichain indexing has completed because all indexed chains have
|
|
644
|
+
* a `chainStatus` of {@link ChainIndexingStatusIds.Completed}.
|
|
645
|
+
*/
|
|
646
|
+
Completed: "omnichain-completed"
|
|
647
|
+
};
|
|
648
|
+
|
|
619
649
|
// ../ensnode-sdk/src/shared/serialize.ts
|
|
620
650
|
function serializePrice(price) {
|
|
621
651
|
return {
|
|
@@ -1706,6 +1736,36 @@ ${(0, import_v46.prettifyError)(parsed.error)}
|
|
|
1706
1736
|
return parsed.data;
|
|
1707
1737
|
}
|
|
1708
1738
|
|
|
1739
|
+
// src/api/prerequisites.ts
|
|
1740
|
+
var ensAnalyticsRequiredPlugins = [
|
|
1741
|
+
"subgraph" /* Subgraph */,
|
|
1742
|
+
"basenames" /* Basenames */,
|
|
1743
|
+
"lineanames" /* Lineanames */,
|
|
1744
|
+
"registrars" /* Registrars */
|
|
1745
|
+
];
|
|
1746
|
+
function hasEnsAnalyticsConfigSupport(config) {
|
|
1747
|
+
const supported = ensAnalyticsRequiredPlugins.every((plugin) => config.plugins.includes(plugin));
|
|
1748
|
+
if (supported) return { supported };
|
|
1749
|
+
return {
|
|
1750
|
+
supported: false,
|
|
1751
|
+
reason: `The ENSAnalytics API requires all of the following plugins to be activated in the connected ENSNode's Config: ${ensAnalyticsRequiredPlugins.map((plugin) => `'${plugin}'`).join(", ")}.`
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
var ensAnalyticsSupportedIndexingStatusIds = [
|
|
1755
|
+
OmnichainIndexingStatusIds.Completed,
|
|
1756
|
+
OmnichainIndexingStatusIds.Following
|
|
1757
|
+
];
|
|
1758
|
+
function hasEnsAnalyticsIndexingStatusSupport(omnichainIndexingStatusId) {
|
|
1759
|
+
const supported = ensAnalyticsSupportedIndexingStatusIds.some(
|
|
1760
|
+
(supportedIndexingStatusId) => supportedIndexingStatusId === omnichainIndexingStatusId
|
|
1761
|
+
);
|
|
1762
|
+
if (supported) return { supported };
|
|
1763
|
+
return {
|
|
1764
|
+
supported: false,
|
|
1765
|
+
reason: `The ENSAnalytics API requires the connected ENSNode's Indexing Status to be one of the following: ${ensAnalyticsSupportedIndexingStatusIds.join(", ")}.`
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1709
1769
|
// src/award-models/pie-split/api/serialize.ts
|
|
1710
1770
|
function serializeReferralProgramRulesPieSplit(rules) {
|
|
1711
1771
|
return {
|
|
@@ -2415,7 +2475,7 @@ var buildUnrankedReferrerMetricsPieSplit = (referrer) => {
|
|
|
2415
2475
|
};
|
|
2416
2476
|
|
|
2417
2477
|
// src/award-models/pie-split/leaderboard.ts
|
|
2418
|
-
var
|
|
2478
|
+
var buildReferralEditionSnapshotPieSplit = (allReferrers, rules, accurateAsOf) => {
|
|
2419
2479
|
assertLeaderboardInputs(allReferrers, rules, accurateAsOf);
|
|
2420
2480
|
const sortedReferrers = sortReferrerMetrics(allReferrers);
|
|
2421
2481
|
const scoredReferrers = sortedReferrers.map((r) => buildScoredReferrerMetricsPieSplit(r));
|
|
@@ -2427,7 +2487,14 @@ var buildReferrerLeaderboardPieSplit = (allReferrers, rules, accurateAsOf) => {
|
|
|
2427
2487
|
(r) => buildAwardedReferrerMetricsPieSplit(r, aggregatedMetrics, rules)
|
|
2428
2488
|
);
|
|
2429
2489
|
const referrers = new Map(awardedReferrers.map((r) => [r.referrer, r]));
|
|
2430
|
-
|
|
2490
|
+
const leaderboard = {
|
|
2491
|
+
awardModel: rules.awardModel,
|
|
2492
|
+
rules,
|
|
2493
|
+
aggregatedMetrics,
|
|
2494
|
+
referrers,
|
|
2495
|
+
accurateAsOf
|
|
2496
|
+
};
|
|
2497
|
+
return { awardModel: rules.awardModel, leaderboard };
|
|
2431
2498
|
};
|
|
2432
2499
|
|
|
2433
2500
|
// src/award-models/pie-split/leaderboard-page.ts
|
|
@@ -2705,9 +2772,14 @@ function sortReferralEvents(events) {
|
|
|
2705
2772
|
}
|
|
2706
2773
|
|
|
2707
2774
|
// src/award-models/rev-share-cap/leaderboard.ts
|
|
2708
|
-
var
|
|
2775
|
+
var buildReferralEditionSnapshotRevShareCap = (events, rules, accurateAsOf) => {
|
|
2709
2776
|
const sortedEvents = sortReferralEvents(events);
|
|
2777
|
+
const adminActionByReferrer = /* @__PURE__ */ new Map();
|
|
2778
|
+
for (const action of rules.adminActions) {
|
|
2779
|
+
adminActionByReferrer.set(action.referrer, action);
|
|
2780
|
+
}
|
|
2710
2781
|
const referrerStates = /* @__PURE__ */ new Map();
|
|
2782
|
+
const accountingRecords = [];
|
|
2711
2783
|
let awardPoolRemaining = rules.awardPool;
|
|
2712
2784
|
for (const event of sortedEvents) {
|
|
2713
2785
|
const referrerId = event.referrer;
|
|
@@ -2728,27 +2800,65 @@ var buildReferrerLeaderboardRevShareCap = (events, rules, accurateAsOf) => {
|
|
|
2728
2800
|
referrerState.totalRevenueContribution,
|
|
2729
2801
|
event.incrementalRevenueContribution
|
|
2730
2802
|
);
|
|
2731
|
-
const
|
|
2803
|
+
const hasQualifiedBefore = referrerState.hasQualified;
|
|
2804
|
+
const awardPoolRemainingBefore = awardPoolRemaining;
|
|
2805
|
+
const adminAction = adminActionByReferrer.get(referrerId);
|
|
2806
|
+
const adminDisqualification = adminAction?.actionType === AdminActionTypes.Disqualification ? adminAction : null;
|
|
2807
|
+
const accumulatedBaseRevenueContribution = calcBaseRevenueContribution(
|
|
2732
2808
|
rules,
|
|
2733
2809
|
referrerState.totalIncrementalDuration
|
|
2734
2810
|
);
|
|
2735
|
-
const
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2811
|
+
const incrementalBaseRevenueContribution = calcBaseRevenueContribution(
|
|
2812
|
+
rules,
|
|
2813
|
+
event.incrementalDuration
|
|
2814
|
+
);
|
|
2815
|
+
const isNowQualified = isReferrerQualifiedRevShareCap(
|
|
2816
|
+
referrerId,
|
|
2817
|
+
accumulatedBaseRevenueContribution,
|
|
2818
|
+
rules
|
|
2819
|
+
);
|
|
2820
|
+
let incrementalTentativeAward = priceUsdc(0n);
|
|
2821
|
+
if (isNowQualified && !hasQualifiedBefore) {
|
|
2822
|
+
const accumulatedUncappedAward = scalePrice(
|
|
2823
|
+
accumulatedBaseRevenueContribution,
|
|
2824
|
+
rules.maxBaseRevenueShare
|
|
2825
|
+
);
|
|
2826
|
+
incrementalTentativeAward = minPrice(accumulatedUncappedAward, awardPoolRemainingBefore);
|
|
2741
2827
|
referrerState.hasQualified = true;
|
|
2742
|
-
} else if (
|
|
2743
|
-
const incrementalBaseRevenue = calcBaseRevenueContribution(rules, event.incrementalDuration);
|
|
2828
|
+
} else if (hasQualifiedBefore) {
|
|
2744
2829
|
const incrementalUncappedAward = scalePrice(
|
|
2745
|
-
|
|
2830
|
+
incrementalBaseRevenueContribution,
|
|
2746
2831
|
rules.maxBaseRevenueShare
|
|
2747
2832
|
);
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2833
|
+
incrementalTentativeAward = minPrice(incrementalUncappedAward, awardPoolRemainingBefore);
|
|
2834
|
+
}
|
|
2835
|
+
referrerState.cappedAward = addPrices(referrerState.cappedAward, incrementalTentativeAward);
|
|
2836
|
+
awardPoolRemaining = subtractPrice(awardPoolRemaining, incrementalTentativeAward);
|
|
2837
|
+
const tentativeAward = {
|
|
2838
|
+
incrementalRevenueContribution: event.incrementalRevenueContribution,
|
|
2839
|
+
accumulatedRevenueContribution: referrerState.totalRevenueContribution,
|
|
2840
|
+
incrementalBaseRevenueContribution,
|
|
2841
|
+
accumulatedBaseRevenueContribution,
|
|
2842
|
+
awardPoolRemaining: awardPoolRemainingBefore,
|
|
2843
|
+
disqualified: adminDisqualification !== null,
|
|
2844
|
+
...adminDisqualification !== null && {
|
|
2845
|
+
disqualificationReason: adminDisqualification.reason
|
|
2846
|
+
},
|
|
2847
|
+
maxRevShare: rules.maxBaseRevenueShare,
|
|
2848
|
+
effectiveBaseRevShare: incrementalBaseRevenueContribution.amount === 0n ? 0 : Number(incrementalTentativeAward.amount) / Number(incrementalBaseRevenueContribution.amount),
|
|
2849
|
+
incrementalTentativeAward
|
|
2850
|
+
};
|
|
2851
|
+
accountingRecords.push({
|
|
2852
|
+
registrarActionId: event.id,
|
|
2853
|
+
timestamp: event.timestamp,
|
|
2854
|
+
name: event.name,
|
|
2855
|
+
actionType: event.actionType,
|
|
2856
|
+
transactionHash: event.transactionHash,
|
|
2857
|
+
registrant: event.registrant,
|
|
2858
|
+
referrer: referrerId,
|
|
2859
|
+
incrementalDuration: event.incrementalDuration,
|
|
2860
|
+
tentativeAward
|
|
2861
|
+
});
|
|
2752
2862
|
}
|
|
2753
2863
|
const sortedEntries = [...referrerStates.entries()].sort(
|
|
2754
2864
|
([referrerIdA, referrerStateA], [referrerIdB, referrerStateB]) => {
|
|
@@ -2794,7 +2904,17 @@ var buildReferrerLeaderboardRevShareCap = (events, rules, accurateAsOf) => {
|
|
|
2794
2904
|
awardPoolRemaining
|
|
2795
2905
|
);
|
|
2796
2906
|
const referrers = new Map(awardedReferrers.map((r) => [r.referrer, r]));
|
|
2797
|
-
return {
|
|
2907
|
+
return {
|
|
2908
|
+
awardModel: rules.awardModel,
|
|
2909
|
+
leaderboard: {
|
|
2910
|
+
awardModel: rules.awardModel,
|
|
2911
|
+
rules,
|
|
2912
|
+
aggregatedMetrics,
|
|
2913
|
+
referrers,
|
|
2914
|
+
accurateAsOf
|
|
2915
|
+
},
|
|
2916
|
+
accountingRecords
|
|
2917
|
+
};
|
|
2798
2918
|
};
|
|
2799
2919
|
|
|
2800
2920
|
// src/award-models/rev-share-cap/leaderboard-page.ts
|