@ensnode/ensnode-sdk 1.0.2 → 1.1.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 +369 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +200 -183
- package/dist/index.d.ts +200 -183
- package/dist/index.js +361 -158
- package/dist/index.js.map +1 -1
- package/package.json +12 -7
package/dist/index.js
CHANGED
|
@@ -38,8 +38,58 @@ function asLowerCaseAddress(address) {
|
|
|
38
38
|
return address.toLowerCase();
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
// src/shared/cache.ts
|
|
42
|
-
|
|
41
|
+
// src/shared/cache/lru-cache.ts
|
|
42
|
+
var LruCache = class {
|
|
43
|
+
_cache = /* @__PURE__ */ new Map();
|
|
44
|
+
_capacity;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new LRU cache with the given capacity.
|
|
47
|
+
*
|
|
48
|
+
* @param capacity The maximum number of items in the cache. If set to 0, the cache is effectively disabled.
|
|
49
|
+
* @throws Error if capacity is not a non-negative integer.
|
|
50
|
+
*/
|
|
51
|
+
constructor(capacity) {
|
|
52
|
+
if (!Number.isInteger(capacity)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`LruCache requires capacity to be an integer but a capacity of ${capacity} was requested.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (capacity < 0) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`LruCache requires a non-negative capacity but a capacity of ${capacity} was requested.`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
this._capacity = capacity;
|
|
63
|
+
}
|
|
64
|
+
set(key, value) {
|
|
65
|
+
this._cache.set(key, value);
|
|
66
|
+
if (this._cache.size > this._capacity) {
|
|
67
|
+
const oldestKey = this._cache.keys().next().value;
|
|
68
|
+
this._cache.delete(oldestKey);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
get(key) {
|
|
72
|
+
const value = this._cache.get(key);
|
|
73
|
+
if (value) {
|
|
74
|
+
this._cache.delete(key);
|
|
75
|
+
this._cache.set(key, value);
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
clear() {
|
|
80
|
+
this._cache.clear();
|
|
81
|
+
}
|
|
82
|
+
get size() {
|
|
83
|
+
return this._cache.size;
|
|
84
|
+
}
|
|
85
|
+
get capacity() {
|
|
86
|
+
return this._capacity;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/shared/cache/swr-cache.ts
|
|
91
|
+
import { secondsToMilliseconds } from "date-fns";
|
|
92
|
+
import { getUnixTime } from "date-fns/getUnixTime";
|
|
43
93
|
|
|
44
94
|
// src/shared/deserialize.ts
|
|
45
95
|
import { prettifyError } from "zod/v4";
|
|
@@ -291,6 +341,13 @@ function reinterpretName(name) {
|
|
|
291
341
|
}
|
|
292
342
|
|
|
293
343
|
// src/shared/zod-schemas.ts
|
|
344
|
+
var makeFiniteNonNegativeNumberSchema = (valueLabel = "Value") => z.number({
|
|
345
|
+
// NOTE: Zod's implementation of `number` automatically rejects NaN and Infinity values.
|
|
346
|
+
// and therefore the finite check is implicit.
|
|
347
|
+
error: `${valueLabel} must be a finite number.`
|
|
348
|
+
}).nonnegative({
|
|
349
|
+
error: `${valueLabel} must be a non-negative number (>=0).`
|
|
350
|
+
});
|
|
294
351
|
var makeIntegerSchema = (valueLabel = "Value") => z.int({
|
|
295
352
|
error: `${valueLabel} must be an integer.`
|
|
296
353
|
});
|
|
@@ -365,13 +422,13 @@ var makePriceCurrencySchema = (currency, valueLabel = "Price Currency") => z.str
|
|
|
365
422
|
});
|
|
366
423
|
var makePriceEthSchema = (valueLabel = "Price ETH") => makePriceCurrencySchema(CurrencyIds.ETH, valueLabel).transform((v) => v);
|
|
367
424
|
var makeAccountIdSchema = (valueLabel = "AccountId") => z.strictObject({
|
|
368
|
-
chainId:
|
|
425
|
+
chainId: makeChainIdSchema(`${valueLabel} chain ID`),
|
|
369
426
|
address: makeLowercaseAddressSchema(`${valueLabel} address`)
|
|
370
427
|
});
|
|
371
428
|
var makeSerializedAccountIdSchema = (valueLabel = "Account ID") => z.coerce.string().transform((v) => {
|
|
372
429
|
const result = new CaipAccountId(v);
|
|
373
430
|
return {
|
|
374
|
-
chainId: result.chainId.reference,
|
|
431
|
+
chainId: Number(result.chainId.reference),
|
|
375
432
|
address: result.address
|
|
376
433
|
};
|
|
377
434
|
}).pipe(makeAccountIdSchema(valueLabel));
|
|
@@ -509,54 +566,185 @@ function addDuration(timestamp, duration) {
|
|
|
509
566
|
return deserializeUnixTimestamp(timestamp + duration, "UnixTimestamp");
|
|
510
567
|
}
|
|
511
568
|
|
|
512
|
-
// src/shared/cache.ts
|
|
513
|
-
var
|
|
514
|
-
|
|
515
|
-
_capacity;
|
|
569
|
+
// src/shared/cache/background-revalidation-scheduler.ts
|
|
570
|
+
var BackgroundRevalidationScheduler = class {
|
|
571
|
+
activeSchedules = /* @__PURE__ */ new Map();
|
|
516
572
|
/**
|
|
517
|
-
*
|
|
573
|
+
* Schedule a revalidation function to run on a recurring interval.
|
|
518
574
|
*
|
|
519
|
-
* @param
|
|
520
|
-
* @
|
|
575
|
+
* @param config Configuration object for the schedule
|
|
576
|
+
* @returns The revalidate function that can be passed to `cancel()` to stop the schedule
|
|
521
577
|
*/
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
);
|
|
578
|
+
schedule(config) {
|
|
579
|
+
const { revalidate, interval, initialDelay = 0, onError } = config;
|
|
580
|
+
if (this.activeSchedules.has(revalidate)) {
|
|
581
|
+
return revalidate;
|
|
527
582
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
583
|
+
const metadata = {
|
|
584
|
+
config,
|
|
585
|
+
timeoutId: null,
|
|
586
|
+
inProgress: false
|
|
587
|
+
};
|
|
588
|
+
this.activeSchedules.set(revalidate, metadata);
|
|
589
|
+
const executeRevalidation = async () => {
|
|
590
|
+
if (metadata.inProgress) return;
|
|
591
|
+
metadata.inProgress = true;
|
|
592
|
+
try {
|
|
593
|
+
await revalidate();
|
|
594
|
+
} catch (error) {
|
|
595
|
+
onError?.(error);
|
|
596
|
+
} finally {
|
|
597
|
+
metadata.inProgress = false;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
const scheduleNext = () => {
|
|
601
|
+
if (!this.activeSchedules.has(revalidate)) return;
|
|
602
|
+
metadata.timeoutId = setTimeout(() => {
|
|
603
|
+
if (this.activeSchedules.has(revalidate)) {
|
|
604
|
+
executeRevalidation().then(() => scheduleNext());
|
|
605
|
+
}
|
|
606
|
+
}, interval);
|
|
607
|
+
};
|
|
608
|
+
if (initialDelay > 0) {
|
|
609
|
+
metadata.timeoutId = setTimeout(() => {
|
|
610
|
+
if (this.activeSchedules.has(revalidate)) {
|
|
611
|
+
executeRevalidation().then(() => scheduleNext());
|
|
612
|
+
}
|
|
613
|
+
}, initialDelay);
|
|
614
|
+
} else {
|
|
615
|
+
scheduleNext();
|
|
532
616
|
}
|
|
533
|
-
|
|
617
|
+
return revalidate;
|
|
534
618
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
619
|
+
/**
|
|
620
|
+
* Cancel a scheduled revalidation by its revalidate function.
|
|
621
|
+
*
|
|
622
|
+
* @param revalidate The revalidation function returned from `schedule()`
|
|
623
|
+
*/
|
|
624
|
+
cancel(revalidate) {
|
|
625
|
+
const metadata = this.activeSchedules.get(revalidate);
|
|
626
|
+
if (!metadata) return;
|
|
627
|
+
if (metadata.timeoutId !== null) {
|
|
628
|
+
clearTimeout(metadata.timeoutId);
|
|
540
629
|
}
|
|
630
|
+
this.activeSchedules.delete(revalidate);
|
|
541
631
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
632
|
+
/**
|
|
633
|
+
* Cancel all active schedules.
|
|
634
|
+
*/
|
|
635
|
+
cancelAll() {
|
|
636
|
+
for (const [, metadata] of this.activeSchedules) {
|
|
637
|
+
if (metadata.timeoutId !== null) {
|
|
638
|
+
clearTimeout(metadata.timeoutId);
|
|
639
|
+
}
|
|
547
640
|
}
|
|
548
|
-
|
|
641
|
+
this.activeSchedules.clear();
|
|
549
642
|
}
|
|
550
|
-
|
|
551
|
-
|
|
643
|
+
/**
|
|
644
|
+
* Get the count of active schedules.
|
|
645
|
+
* Useful for debugging and monitoring.
|
|
646
|
+
*
|
|
647
|
+
* @returns The number of currently active schedules
|
|
648
|
+
*/
|
|
649
|
+
getActiveScheduleCount() {
|
|
650
|
+
return this.activeSchedules.size;
|
|
552
651
|
}
|
|
553
|
-
|
|
554
|
-
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// src/shared/cache/swr-cache.ts
|
|
655
|
+
var bgRevalidationScheduler = new BackgroundRevalidationScheduler();
|
|
656
|
+
var SWRCache = class _SWRCache {
|
|
657
|
+
options;
|
|
658
|
+
cache;
|
|
659
|
+
/**
|
|
660
|
+
* Optional promise of the current in-progress attempt to revalidate the `cache`.
|
|
661
|
+
*
|
|
662
|
+
* If null, no revalidation attempt is currently in progress.
|
|
663
|
+
* If not null, identifies the revalidation attempt that is currently in progress.
|
|
664
|
+
*
|
|
665
|
+
* Used to enforce no concurrent revalidation attempts.
|
|
666
|
+
*/
|
|
667
|
+
inProgressRevalidate;
|
|
668
|
+
/**
|
|
669
|
+
* The callback function being managed by `BackgroundRevalidationScheduler`.
|
|
670
|
+
*
|
|
671
|
+
* If null, no background revalidation is scheduled.
|
|
672
|
+
* If not null, identifies the background revalidation that is currently scheduled.
|
|
673
|
+
*
|
|
674
|
+
* Used to enforce no concurrent background revalidation attempts.
|
|
675
|
+
*/
|
|
676
|
+
scheduledBackgroundRevalidate;
|
|
677
|
+
constructor(options) {
|
|
678
|
+
this.cache = null;
|
|
679
|
+
this.inProgressRevalidate = null;
|
|
680
|
+
this.scheduledBackgroundRevalidate = null;
|
|
681
|
+
this.options = options;
|
|
555
682
|
}
|
|
556
|
-
|
|
557
|
-
|
|
683
|
+
/**
|
|
684
|
+
* Asynchronously create a new `SWRCache` instance.
|
|
685
|
+
*
|
|
686
|
+
* @param options - The {@link SWRCacheOptions} for the SWR cache.
|
|
687
|
+
* @returns a new `SWRCache` instance.
|
|
688
|
+
*/
|
|
689
|
+
static async create(options) {
|
|
690
|
+
const cache = new _SWRCache(options);
|
|
691
|
+
if (cache.options.proactivelyInitialize) {
|
|
692
|
+
cache.readCache();
|
|
693
|
+
}
|
|
694
|
+
return cache;
|
|
558
695
|
}
|
|
696
|
+
revalidate = async () => {
|
|
697
|
+
if (this.inProgressRevalidate) {
|
|
698
|
+
return this.inProgressRevalidate;
|
|
699
|
+
}
|
|
700
|
+
return this.options.fn().then((value) => {
|
|
701
|
+
this.cache = {
|
|
702
|
+
value,
|
|
703
|
+
updatedAt: getUnixTime(/* @__PURE__ */ new Date())
|
|
704
|
+
};
|
|
705
|
+
return this.cache;
|
|
706
|
+
}).catch(() => {
|
|
707
|
+
return null;
|
|
708
|
+
}).finally(() => {
|
|
709
|
+
this.inProgressRevalidate = null;
|
|
710
|
+
if (this.options.revalidationInterval === void 0) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (this.scheduledBackgroundRevalidate) {
|
|
714
|
+
bgRevalidationScheduler.cancel(this.scheduledBackgroundRevalidate);
|
|
715
|
+
}
|
|
716
|
+
const backgroundRevalidate = async () => {
|
|
717
|
+
this.revalidate();
|
|
718
|
+
};
|
|
719
|
+
this.scheduledBackgroundRevalidate = bgRevalidationScheduler.schedule({
|
|
720
|
+
revalidate: backgroundRevalidate,
|
|
721
|
+
interval: secondsToMilliseconds(this.options.revalidationInterval)
|
|
722
|
+
});
|
|
723
|
+
});
|
|
724
|
+
};
|
|
725
|
+
/**
|
|
726
|
+
* Read the most recently cached `CachedValue` from the `SWRCache`.
|
|
727
|
+
*
|
|
728
|
+
* @returns a `CachedValue` holding a `value` of `ValueType` that was most recently successfully returned by `fn`
|
|
729
|
+
* or `null` if `fn` has never successfully returned and has always thrown an error,
|
|
730
|
+
*/
|
|
731
|
+
readCache = async () => {
|
|
732
|
+
if (!this.cache) {
|
|
733
|
+
this.inProgressRevalidate = this.revalidate();
|
|
734
|
+
return this.inProgressRevalidate;
|
|
735
|
+
}
|
|
736
|
+
if (durationBetween(this.cache.updatedAt, getUnixTime(/* @__PURE__ */ new Date())) <= this.options.ttl) {
|
|
737
|
+
return this.cache;
|
|
738
|
+
}
|
|
739
|
+
if (!this.inProgressRevalidate) {
|
|
740
|
+
this.inProgressRevalidate = this.revalidate();
|
|
741
|
+
}
|
|
742
|
+
return this.cache;
|
|
743
|
+
};
|
|
559
744
|
};
|
|
745
|
+
|
|
746
|
+
// src/shared/cache/ttl-cache.ts
|
|
747
|
+
import { getUnixTime as getUnixTime2 } from "date-fns/getUnixTime";
|
|
560
748
|
var TtlCache = class {
|
|
561
749
|
_cache = /* @__PURE__ */ new Map();
|
|
562
750
|
_ttl;
|
|
@@ -569,7 +757,7 @@ var TtlCache = class {
|
|
|
569
757
|
this._ttl = ttl;
|
|
570
758
|
}
|
|
571
759
|
_cleanup() {
|
|
572
|
-
const now =
|
|
760
|
+
const now = getUnixTime2(/* @__PURE__ */ new Date());
|
|
573
761
|
for (const [key, entry] of this._cache.entries()) {
|
|
574
762
|
if (entry.expiresAt <= now) {
|
|
575
763
|
this._cache.delete(key);
|
|
@@ -578,7 +766,7 @@ var TtlCache = class {
|
|
|
578
766
|
}
|
|
579
767
|
set(key, value) {
|
|
580
768
|
this._cleanup();
|
|
581
|
-
const expiresAt = addDuration(
|
|
769
|
+
const expiresAt = addDuration(getUnixTime2(/* @__PURE__ */ new Date()), this._ttl);
|
|
582
770
|
this._cache.set(key, { value, expiresAt });
|
|
583
771
|
}
|
|
584
772
|
get(key) {
|
|
@@ -587,7 +775,7 @@ var TtlCache = class {
|
|
|
587
775
|
if (!entry) {
|
|
588
776
|
return void 0;
|
|
589
777
|
}
|
|
590
|
-
if (entry.expiresAt <=
|
|
778
|
+
if (entry.expiresAt <= getUnixTime2(/* @__PURE__ */ new Date())) {
|
|
591
779
|
this._cache.delete(key);
|
|
592
780
|
return void 0;
|
|
593
781
|
}
|
|
@@ -609,7 +797,7 @@ var TtlCache = class {
|
|
|
609
797
|
if (!entry) {
|
|
610
798
|
return false;
|
|
611
799
|
}
|
|
612
|
-
if (entry.expiresAt <=
|
|
800
|
+
if (entry.expiresAt <= getUnixTime2(/* @__PURE__ */ new Date())) {
|
|
613
801
|
this._cache.delete(key);
|
|
614
802
|
return false;
|
|
615
803
|
}
|
|
@@ -619,39 +807,6 @@ var TtlCache = class {
|
|
|
619
807
|
return this._cache.delete(key);
|
|
620
808
|
}
|
|
621
809
|
};
|
|
622
|
-
function staleWhileRevalidate(options) {
|
|
623
|
-
const { fn, ttl } = options;
|
|
624
|
-
let cache = null;
|
|
625
|
-
let cacheInitializer = null;
|
|
626
|
-
return async () => {
|
|
627
|
-
if (!cache) {
|
|
628
|
-
if (cacheInitializer) {
|
|
629
|
-
return cacheInitializer;
|
|
630
|
-
}
|
|
631
|
-
cacheInitializer = fn().then((value) => {
|
|
632
|
-
cache = { value, updatedAt: getUnixTime(/* @__PURE__ */ new Date()) };
|
|
633
|
-
cacheInitializer = null;
|
|
634
|
-
return value;
|
|
635
|
-
}).catch(() => {
|
|
636
|
-
cacheInitializer = null;
|
|
637
|
-
return null;
|
|
638
|
-
});
|
|
639
|
-
return cacheInitializer;
|
|
640
|
-
}
|
|
641
|
-
const isStale = durationBetween(cache.updatedAt, getUnixTime(/* @__PURE__ */ new Date())) > ttl;
|
|
642
|
-
if (!isStale) return cache.value;
|
|
643
|
-
if (cache.inProgressRevalidation) return cache.value;
|
|
644
|
-
const revalidationPromise = fn().then((value) => {
|
|
645
|
-
cache = { value, updatedAt: getUnixTime(/* @__PURE__ */ new Date()) };
|
|
646
|
-
}).catch(() => {
|
|
647
|
-
if (cache) {
|
|
648
|
-
cache.inProgressRevalidation = void 0;
|
|
649
|
-
}
|
|
650
|
-
});
|
|
651
|
-
cache.inProgressRevalidation = revalidationPromise;
|
|
652
|
-
return cache.value;
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
810
|
|
|
656
811
|
// src/shared/collections.ts
|
|
657
812
|
var uniq = (arr) => [...new Set(arr)];
|
|
@@ -927,6 +1082,16 @@ function sortChainStatusesByStartBlockAsc(chains) {
|
|
|
927
1082
|
);
|
|
928
1083
|
return chains;
|
|
929
1084
|
}
|
|
1085
|
+
function getLatestIndexedBlockRef(indexingStatus, chainId) {
|
|
1086
|
+
const chainIndexingStatus = indexingStatus.omnichainSnapshot.chains.get(chainId);
|
|
1087
|
+
if (chainIndexingStatus === void 0) {
|
|
1088
|
+
return null;
|
|
1089
|
+
}
|
|
1090
|
+
if (chainIndexingStatus.chainStatus === ChainIndexingStatusIds.Queued) {
|
|
1091
|
+
return null;
|
|
1092
|
+
}
|
|
1093
|
+
return chainIndexingStatus.latestIndexedBlock;
|
|
1094
|
+
}
|
|
930
1095
|
|
|
931
1096
|
// src/ensindexer/indexing-status/validations.ts
|
|
932
1097
|
function invariant_chainSnapshotQueuedBlocks(ctx) {
|
|
@@ -1478,15 +1643,18 @@ var LogLevelSchema = z5.enum(["fatal", "error", "warn", "info", "debug", "trace"
|
|
|
1478
1643
|
// src/shared/protocol-acceleration/interpret-record-values.ts
|
|
1479
1644
|
import { isAddress as isAddress3, isAddressEqual as isAddressEqual2, zeroAddress } from "viem";
|
|
1480
1645
|
|
|
1481
|
-
// ../ens-referrals/src/
|
|
1646
|
+
// ../ens-referrals/src/address.ts
|
|
1647
|
+
import { isAddress as isAddress4 } from "viem";
|
|
1648
|
+
|
|
1649
|
+
// ../ens-referrals/src/encoding.ts
|
|
1482
1650
|
import { getAddress, pad, size as size2, slice, zeroAddress as zeroAddress2 } from "viem";
|
|
1483
1651
|
var ENCODED_REFERRER_BYTE_OFFSET = 12;
|
|
1484
1652
|
var ENCODED_REFERRER_BYTE_LENGTH = 32;
|
|
1485
|
-
var
|
|
1653
|
+
var EXPECTED_ENCODED_REFERRER_PADDING = pad("0x", {
|
|
1486
1654
|
size: ENCODED_REFERRER_BYTE_OFFSET,
|
|
1487
1655
|
dir: "left"
|
|
1488
1656
|
});
|
|
1489
|
-
var
|
|
1657
|
+
var ZERO_ENCODED_REFERRER = pad("0x", {
|
|
1490
1658
|
size: ENCODED_REFERRER_BYTE_LENGTH,
|
|
1491
1659
|
dir: "left"
|
|
1492
1660
|
});
|
|
@@ -1497,7 +1665,7 @@ function decodeEncodedReferrer(encodedReferrer) {
|
|
|
1497
1665
|
);
|
|
1498
1666
|
}
|
|
1499
1667
|
const padding = slice(encodedReferrer, 0, ENCODED_REFERRER_BYTE_OFFSET);
|
|
1500
|
-
if (padding !==
|
|
1668
|
+
if (padding !== EXPECTED_ENCODED_REFERRER_PADDING) {
|
|
1501
1669
|
return zeroAddress2;
|
|
1502
1670
|
}
|
|
1503
1671
|
const decodedReferrer = slice(encodedReferrer, ENCODED_REFERRER_BYTE_OFFSET);
|
|
@@ -1508,6 +1676,12 @@ function decodeEncodedReferrer(encodedReferrer) {
|
|
|
1508
1676
|
}
|
|
1509
1677
|
}
|
|
1510
1678
|
|
|
1679
|
+
// ../ens-referrals/src/leaderboard-page.ts
|
|
1680
|
+
var REFERRERS_PER_LEADERBOARD_PAGE_MAX = 100;
|
|
1681
|
+
|
|
1682
|
+
// ../ens-referrals/src/link.ts
|
|
1683
|
+
import { getAddress as getAddress2 } from "viem";
|
|
1684
|
+
|
|
1511
1685
|
// src/registrars/zod-schemas.ts
|
|
1512
1686
|
import z6 from "zod/v4";
|
|
1513
1687
|
|
|
@@ -2157,89 +2331,98 @@ import { prettifyError as prettifyError5 } from "zod/v4";
|
|
|
2157
2331
|
import z8 from "zod/v4";
|
|
2158
2332
|
|
|
2159
2333
|
// src/ensanalytics/types.ts
|
|
2160
|
-
var
|
|
2161
|
-
var ITEMS_PER_PAGE_MAX = 100;
|
|
2162
|
-
var PaginatedAggregatedReferrersResponseCodes = {
|
|
2334
|
+
var ReferrerLeaderboardPageResponseCodes = {
|
|
2163
2335
|
/**
|
|
2164
|
-
* Represents that the
|
|
2165
|
-
* @note The response may contain an empty array for the first page if there are no qualified referrers.
|
|
2166
|
-
* When the array is empty, total will be 0, page will be 1, and both hasNext and hasPrev will be false.
|
|
2336
|
+
* Represents that the requested referrer leaderboard page is available.
|
|
2167
2337
|
*/
|
|
2168
2338
|
Ok: "ok",
|
|
2169
2339
|
/**
|
|
2170
|
-
* Represents that the
|
|
2340
|
+
* Represents that the referrer leaderboard data is not available.
|
|
2171
2341
|
*/
|
|
2172
2342
|
Error: "error"
|
|
2173
2343
|
};
|
|
2174
2344
|
|
|
2175
2345
|
// src/ensanalytics/zod-schemas.ts
|
|
2176
|
-
var
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2346
|
+
var makeReferralProgramRulesSchema = (valueLabel = "ReferralProgramRules") => z8.object({
|
|
2347
|
+
totalAwardPoolValue: makeFiniteNonNegativeNumberSchema(`${valueLabel}.totalAwardPoolValue`),
|
|
2348
|
+
maxQualifiedReferrers: makeNonNegativeIntegerSchema(`${valueLabel}.maxQualifiedReferrers`),
|
|
2349
|
+
startTime: makeUnixTimestampSchema(`${valueLabel}.startTime`),
|
|
2350
|
+
endTime: makeUnixTimestampSchema(`${valueLabel}.endTime`),
|
|
2351
|
+
subregistryId: makeAccountIdSchema(`${valueLabel}.subregistryId`)
|
|
2180
2352
|
});
|
|
2181
|
-
var
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2353
|
+
var makeAwardedReferrerMetricsSchema = (valueLabel = "AwardedReferrerMetrics") => z8.object({
|
|
2354
|
+
referrer: makeLowercaseAddressSchema(`${valueLabel}.referrer`),
|
|
2355
|
+
totalReferrals: makeNonNegativeIntegerSchema(`${valueLabel}.totalReferrals`),
|
|
2356
|
+
totalIncrementalDuration: makeDurationSchema(`${valueLabel}.totalIncrementalDuration`),
|
|
2357
|
+
score: makeFiniteNonNegativeNumberSchema(`${valueLabel}.score`),
|
|
2358
|
+
rank: makePositiveIntegerSchema(`${valueLabel}.rank`),
|
|
2359
|
+
isQualified: z8.boolean(),
|
|
2360
|
+
finalScoreBoost: makeFiniteNonNegativeNumberSchema(`${valueLabel}.finalScoreBoost`).max(
|
|
2361
|
+
1,
|
|
2362
|
+
`${valueLabel}.finalScoreBoost must be <= 1`
|
|
2363
|
+
),
|
|
2364
|
+
finalScore: makeFiniteNonNegativeNumberSchema(`${valueLabel}.finalScore`),
|
|
2365
|
+
awardPoolShare: makeFiniteNonNegativeNumberSchema(`${valueLabel}.awardPoolShare`).max(
|
|
2366
|
+
1,
|
|
2367
|
+
`${valueLabel}.awardPoolShare must be <= 1`
|
|
2368
|
+
),
|
|
2369
|
+
awardPoolApproxValue: makeFiniteNonNegativeNumberSchema(`${valueLabel}.awardPoolApproxValue`)
|
|
2188
2370
|
});
|
|
2189
|
-
var
|
|
2190
|
-
|
|
2191
|
-
|
|
2371
|
+
var makeAggregatedReferrerMetricsSchema = (valueLabel = "AggregatedReferrerMetrics") => z8.object({
|
|
2372
|
+
grandTotalReferrals: makeNonNegativeIntegerSchema(`${valueLabel}.grandTotalReferrals`),
|
|
2373
|
+
grandTotalIncrementalDuration: makeDurationSchema(
|
|
2374
|
+
`${valueLabel}.grandTotalIncrementalDuration`
|
|
2375
|
+
),
|
|
2376
|
+
grandTotalQualifiedReferrersFinalScore: makeFiniteNonNegativeNumberSchema(
|
|
2377
|
+
`${valueLabel}.grandTotalQualifiedReferrersFinalScore`
|
|
2378
|
+
),
|
|
2379
|
+
minFinalScoreToQualify: makeFiniteNonNegativeNumberSchema(
|
|
2380
|
+
`${valueLabel}.minFinalScoreToQualify`
|
|
2381
|
+
)
|
|
2192
2382
|
});
|
|
2193
|
-
var
|
|
2194
|
-
|
|
2195
|
-
|
|
2383
|
+
var makeReferrerLeaderboardPaginationContextSchema = (valueLabel = "ReferrerLeaderboardPaginationContext") => z8.object({
|
|
2384
|
+
page: makePositiveIntegerSchema(`${valueLabel}.page`),
|
|
2385
|
+
itemsPerPage: makePositiveIntegerSchema(`${valueLabel}.itemsPerPage`).max(
|
|
2386
|
+
REFERRERS_PER_LEADERBOARD_PAGE_MAX,
|
|
2387
|
+
`${valueLabel}.itemsPerPage must not exceed ${REFERRERS_PER_LEADERBOARD_PAGE_MAX}`
|
|
2196
2388
|
),
|
|
2197
|
-
|
|
2198
|
-
|
|
2389
|
+
totalRecords: makeNonNegativeIntegerSchema(`${valueLabel}.totalRecords`),
|
|
2390
|
+
totalPages: makePositiveIntegerSchema(`${valueLabel}.totalPages`),
|
|
2199
2391
|
hasNext: z8.boolean(),
|
|
2200
2392
|
hasPrev: z8.boolean(),
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
const { paginationParams, hasNext, hasPrev, total } = ctx.value;
|
|
2204
|
-
const expectedHasPrev = paginationParams.page > 1;
|
|
2205
|
-
if (hasPrev !== expectedHasPrev) {
|
|
2206
|
-
ctx.issues.push({
|
|
2207
|
-
code: "custom",
|
|
2208
|
-
message: `${valueLabel}.hasPrev must be ${expectedHasPrev} when page is ${paginationParams.page}`,
|
|
2209
|
-
input: ctx.value
|
|
2210
|
-
});
|
|
2211
|
-
}
|
|
2212
|
-
const endIndex = paginationParams.page * paginationParams.itemsPerPage;
|
|
2213
|
-
const expectedHasNext = endIndex < total;
|
|
2214
|
-
if (hasNext !== expectedHasNext) {
|
|
2215
|
-
ctx.issues.push({
|
|
2216
|
-
code: "custom",
|
|
2217
|
-
message: `${valueLabel}.hasNext must be ${expectedHasNext} when page=${paginationParams.page}, itemsPerPage=${paginationParams.itemsPerPage}, total=${total}`,
|
|
2218
|
-
input: ctx.value
|
|
2219
|
-
});
|
|
2220
|
-
}
|
|
2393
|
+
startIndex: z8.optional(makeNonNegativeIntegerSchema(`${valueLabel}.startIndex`)),
|
|
2394
|
+
endIndex: z8.optional(makeNonNegativeIntegerSchema(`${valueLabel}.endIndex`))
|
|
2221
2395
|
});
|
|
2222
|
-
var
|
|
2223
|
-
|
|
2224
|
-
|
|
2396
|
+
var makeReferrerLeaderboardPageSchema = (valueLabel = "ReferrerLeaderboardPage") => z8.object({
|
|
2397
|
+
rules: makeReferralProgramRulesSchema(`${valueLabel}.rules`),
|
|
2398
|
+
referrers: z8.array(makeAwardedReferrerMetricsSchema(`${valueLabel}.referrers[item]`)),
|
|
2399
|
+
aggregatedMetrics: makeAggregatedReferrerMetricsSchema(`${valueLabel}.aggregatedMetrics`),
|
|
2400
|
+
paginationContext: makeReferrerLeaderboardPaginationContextSchema(
|
|
2401
|
+
`${valueLabel}.paginationContext`
|
|
2402
|
+
),
|
|
2403
|
+
accurateAsOf: makeUnixTimestampSchema(`${valueLabel}.accurateAsOf`)
|
|
2225
2404
|
});
|
|
2226
|
-
var
|
|
2227
|
-
responseCode: z8.literal(
|
|
2405
|
+
var makeReferrerLeaderboardPageResponseOkSchema = (valueLabel = "ReferrerLeaderboardPageResponseOk") => z8.object({
|
|
2406
|
+
responseCode: z8.literal(ReferrerLeaderboardPageResponseCodes.Ok),
|
|
2407
|
+
data: makeReferrerLeaderboardPageSchema(`${valueLabel}.data`)
|
|
2408
|
+
});
|
|
2409
|
+
var makeReferrerLeaderboardPageResponseErrorSchema = (_valueLabel = "ReferrerLeaderboardPageResponseError") => z8.object({
|
|
2410
|
+
responseCode: z8.literal(ReferrerLeaderboardPageResponseCodes.Error),
|
|
2228
2411
|
error: z8.string(),
|
|
2229
2412
|
errorMessage: z8.string()
|
|
2230
2413
|
});
|
|
2231
|
-
var
|
|
2232
|
-
|
|
2233
|
-
|
|
2414
|
+
var makeReferrerLeaderboardPageResponseSchema = (valueLabel = "ReferrerLeaderboardPageResponse") => z8.union([
|
|
2415
|
+
makeReferrerLeaderboardPageResponseOkSchema(valueLabel),
|
|
2416
|
+
makeReferrerLeaderboardPageResponseErrorSchema(valueLabel)
|
|
2234
2417
|
]);
|
|
2235
2418
|
|
|
2236
2419
|
// src/ensanalytics/deserialize.ts
|
|
2237
|
-
function
|
|
2238
|
-
const schema =
|
|
2420
|
+
function deserializeReferrerLeaderboardPageResponse(maybeResponse, valueLabel) {
|
|
2421
|
+
const schema = makeReferrerLeaderboardPageResponseSchema(valueLabel);
|
|
2239
2422
|
const parsed = schema.safeParse(maybeResponse);
|
|
2240
2423
|
if (parsed.error) {
|
|
2241
2424
|
throw new Error(
|
|
2242
|
-
`Cannot deserialize
|
|
2425
|
+
`Cannot deserialize SerializedReferrerLeaderboardPageResponse:
|
|
2243
2426
|
${prettifyError5(parsed.error)}
|
|
2244
2427
|
`
|
|
2245
2428
|
);
|
|
@@ -2248,11 +2431,11 @@ ${prettifyError5(parsed.error)}
|
|
|
2248
2431
|
}
|
|
2249
2432
|
|
|
2250
2433
|
// src/ensanalytics/serialize.ts
|
|
2251
|
-
function
|
|
2434
|
+
function serializeReferrerLeaderboardPageResponse(response) {
|
|
2252
2435
|
switch (response.responseCode) {
|
|
2253
|
-
case
|
|
2436
|
+
case ReferrerLeaderboardPageResponseCodes.Ok:
|
|
2254
2437
|
return response;
|
|
2255
|
-
case
|
|
2438
|
+
case ReferrerLeaderboardPageResponseCodes.Error:
|
|
2256
2439
|
return response;
|
|
2257
2440
|
}
|
|
2258
2441
|
}
|
|
@@ -2542,15 +2725,15 @@ var ENSNodeClient = class _ENSNodeClient {
|
|
|
2542
2725
|
return deserializeIndexingStatusResponse(responseData);
|
|
2543
2726
|
}
|
|
2544
2727
|
/**
|
|
2545
|
-
* Fetch
|
|
2728
|
+
* Fetch Referrer Leaderboard Page
|
|
2546
2729
|
*
|
|
2547
|
-
* Retrieves a paginated list of
|
|
2730
|
+
* Retrieves a paginated list of referrer leaderboard metrics with contribution percentages.
|
|
2548
2731
|
* Each referrer's contribution is calculated as a percentage of the grand totals across all referrers.
|
|
2549
2732
|
*
|
|
2550
2733
|
* @param request - Pagination parameters
|
|
2551
2734
|
* @param request.page - The page number to retrieve (1-indexed, default: 1)
|
|
2552
2735
|
* @param request.itemsPerPage - Number of items per page (default: 25, max: 100)
|
|
2553
|
-
* @returns {
|
|
2736
|
+
* @returns {ReferrerLeaderboardPageResponse}
|
|
2554
2737
|
*
|
|
2555
2738
|
* @throws if the ENSNode request fails
|
|
2556
2739
|
* @throws if the ENSNode API returns an error response
|
|
@@ -2559,21 +2742,42 @@ var ENSNodeClient = class _ENSNodeClient {
|
|
|
2559
2742
|
* @example
|
|
2560
2743
|
* ```typescript
|
|
2561
2744
|
* // Get first page with default page size (25 items)
|
|
2562
|
-
* const response = await client.
|
|
2563
|
-
* if (response.responseCode ===
|
|
2564
|
-
*
|
|
2565
|
-
*
|
|
2745
|
+
* const response = await client.getReferrerLeaderboard();
|
|
2746
|
+
* if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Ok) {
|
|
2747
|
+
* const {
|
|
2748
|
+
* aggregatedMetrics,
|
|
2749
|
+
* referrers,
|
|
2750
|
+
* rules,
|
|
2751
|
+
* paginationContext,
|
|
2752
|
+
* updatedAt
|
|
2753
|
+
* } = response.data;
|
|
2754
|
+
* console.log(aggregatedMetrics);
|
|
2755
|
+
* console.log(referrers);
|
|
2756
|
+
* console.log(rules);
|
|
2757
|
+
* console.log(updatedAt);
|
|
2758
|
+
* console.log(`Page ${paginationContext.page} of ${paginationContext.totalPages}`);
|
|
2566
2759
|
* }
|
|
2567
2760
|
* ```
|
|
2568
2761
|
*
|
|
2569
2762
|
* @example
|
|
2570
2763
|
* ```typescript
|
|
2571
2764
|
* // Get second page with 50 items per page
|
|
2572
|
-
* const response = await client.
|
|
2765
|
+
* const response = await client.getReferrerLeaderboard({ page: 2, itemsPerPage: 50 });
|
|
2766
|
+
* ```
|
|
2767
|
+
*
|
|
2768
|
+
* @example
|
|
2769
|
+
* ```typescript
|
|
2770
|
+
* // Handle error response, ie. when Referrer Leaderboard is not currently available.
|
|
2771
|
+
* const response = await client.getReferrerLeaderboard();
|
|
2772
|
+
*
|
|
2773
|
+
* if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Error) {
|
|
2774
|
+
* console.error(response.error);
|
|
2775
|
+
* console.error(response.errorMessage);
|
|
2776
|
+
* }
|
|
2573
2777
|
* ```
|
|
2574
2778
|
*/
|
|
2575
|
-
async
|
|
2576
|
-
const url = new URL(`/ensanalytics/
|
|
2779
|
+
async getReferrerLeaderboard(request) {
|
|
2780
|
+
const url = new URL(`/ensanalytics/referrers`, this.options.url);
|
|
2577
2781
|
if (request?.page) url.searchParams.set("page", request.page.toString());
|
|
2578
2782
|
if (request?.itemsPerPage)
|
|
2579
2783
|
url.searchParams.set("itemsPerPage", request.itemsPerPage.toString());
|
|
@@ -2584,7 +2788,7 @@ var ENSNodeClient = class _ENSNodeClient {
|
|
|
2584
2788
|
} catch {
|
|
2585
2789
|
throw new Error("Malformed response data: invalid JSON");
|
|
2586
2790
|
}
|
|
2587
|
-
return
|
|
2791
|
+
return deserializeReferrerLeaderboardPageResponse(
|
|
2588
2792
|
responseData
|
|
2589
2793
|
);
|
|
2590
2794
|
}
|
|
@@ -2798,26 +3002,26 @@ export {
|
|
|
2798
3002
|
ETH_COIN_TYPE,
|
|
2799
3003
|
ETH_NODE,
|
|
2800
3004
|
ForwardResolutionProtocolStep,
|
|
2801
|
-
ITEMS_PER_PAGE_DEFAULT,
|
|
2802
|
-
ITEMS_PER_PAGE_MAX,
|
|
2803
3005
|
IndexingStatusResponseCodes,
|
|
2804
3006
|
LINEANAMES_NODE,
|
|
2805
3007
|
LruCache,
|
|
2806
3008
|
OmnichainIndexingStatusIds,
|
|
2807
3009
|
PROTOCOL_ATTRIBUTE_PREFIX,
|
|
2808
|
-
PaginatedAggregatedReferrersResponseCodes,
|
|
2809
3010
|
PluginName,
|
|
2810
3011
|
ROOT_NODE,
|
|
3012
|
+
ReferrerLeaderboardPageResponseCodes,
|
|
2811
3013
|
RegistrarActionTypes,
|
|
2812
3014
|
RegistrarActionsFilterTypes,
|
|
2813
3015
|
RegistrarActionsOrders,
|
|
2814
3016
|
RegistrarActionsResponseCodes,
|
|
2815
3017
|
ResolutionStatusIds,
|
|
2816
3018
|
ReverseResolutionProtocolStep,
|
|
3019
|
+
SWRCache,
|
|
2817
3020
|
TheGraphCannotFallbackReasonSchema,
|
|
2818
3021
|
TheGraphFallbackSchema,
|
|
2819
3022
|
TraceableENSProtocol,
|
|
2820
3023
|
TtlCache,
|
|
3024
|
+
ZERO_ENCODED_REFERRER,
|
|
2821
3025
|
accountIdEqual,
|
|
2822
3026
|
addDuration,
|
|
2823
3027
|
addPrices,
|
|
@@ -2855,8 +3059,8 @@ export {
|
|
|
2855
3059
|
deserializeErrorResponse,
|
|
2856
3060
|
deserializeIndexingStatusResponse,
|
|
2857
3061
|
deserializeOmnichainIndexingStatusSnapshot,
|
|
2858
|
-
deserializePaginatedAggregatedReferrersResponse,
|
|
2859
3062
|
deserializeRealtimeIndexingStatusProjection,
|
|
3063
|
+
deserializeReferrerLeaderboardPageResponse,
|
|
2860
3064
|
deserializeRegistrarActionsResponse,
|
|
2861
3065
|
deserializeUnixTimestamp,
|
|
2862
3066
|
deserializeUrl,
|
|
@@ -2866,6 +3070,7 @@ export {
|
|
|
2866
3070
|
getCurrencyInfo,
|
|
2867
3071
|
getENSRootChainId,
|
|
2868
3072
|
getEthnamesSubregistryId,
|
|
3073
|
+
getLatestIndexedBlockRef,
|
|
2869
3074
|
getNameHierarchy,
|
|
2870
3075
|
getOmnichainIndexingCursor,
|
|
2871
3076
|
getOmnichainIndexingStatus,
|
|
@@ -2913,10 +3118,10 @@ export {
|
|
|
2913
3118
|
serializeIndexingStatusResponse,
|
|
2914
3119
|
serializeNamedRegistrarAction,
|
|
2915
3120
|
serializeOmnichainIndexingStatusSnapshot,
|
|
2916
|
-
serializePaginatedAggregatedReferrersResponse,
|
|
2917
3121
|
serializePrice,
|
|
2918
3122
|
serializePriceEth,
|
|
2919
3123
|
serializeRealtimeIndexingStatusProjection,
|
|
3124
|
+
serializeReferrerLeaderboardPageResponse,
|
|
2920
3125
|
serializeRegistrarAction,
|
|
2921
3126
|
serializeRegistrarActionPricing,
|
|
2922
3127
|
serializeRegistrarActionsResponse,
|
|
@@ -2924,12 +3129,10 @@ export {
|
|
|
2924
3129
|
serializeSubregistry,
|
|
2925
3130
|
serializeUrl,
|
|
2926
3131
|
sortChainStatusesByStartBlockAsc,
|
|
2927
|
-
staleWhileRevalidate,
|
|
2928
3132
|
stripNullBytes,
|
|
2929
3133
|
translateDefaultableChainIdToChainId,
|
|
2930
3134
|
uint256ToHex32,
|
|
2931
3135
|
uniq,
|
|
2932
|
-
validateSupportedLabelSetAndVersion
|
|
2933
|
-
zeroEncodedReferrer
|
|
3136
|
+
validateSupportedLabelSetAndVersion
|
|
2934
3137
|
};
|
|
2935
3138
|
//# sourceMappingURL=index.js.map
|