@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 CHANGED
@@ -47,26 +47,26 @@ __export(index_exports, {
47
47
  ETH_COIN_TYPE: () => ETH_COIN_TYPE,
48
48
  ETH_NODE: () => ETH_NODE,
49
49
  ForwardResolutionProtocolStep: () => ForwardResolutionProtocolStep,
50
- ITEMS_PER_PAGE_DEFAULT: () => ITEMS_PER_PAGE_DEFAULT,
51
- ITEMS_PER_PAGE_MAX: () => ITEMS_PER_PAGE_MAX,
52
50
  IndexingStatusResponseCodes: () => IndexingStatusResponseCodes,
53
51
  LINEANAMES_NODE: () => LINEANAMES_NODE,
54
52
  LruCache: () => LruCache,
55
53
  OmnichainIndexingStatusIds: () => OmnichainIndexingStatusIds,
56
54
  PROTOCOL_ATTRIBUTE_PREFIX: () => PROTOCOL_ATTRIBUTE_PREFIX,
57
- PaginatedAggregatedReferrersResponseCodes: () => PaginatedAggregatedReferrersResponseCodes,
58
55
  PluginName: () => PluginName,
59
56
  ROOT_NODE: () => ROOT_NODE,
57
+ ReferrerLeaderboardPageResponseCodes: () => ReferrerLeaderboardPageResponseCodes,
60
58
  RegistrarActionTypes: () => RegistrarActionTypes,
61
59
  RegistrarActionsFilterTypes: () => RegistrarActionsFilterTypes,
62
60
  RegistrarActionsOrders: () => RegistrarActionsOrders,
63
61
  RegistrarActionsResponseCodes: () => RegistrarActionsResponseCodes,
64
62
  ResolutionStatusIds: () => ResolutionStatusIds,
65
63
  ReverseResolutionProtocolStep: () => ReverseResolutionProtocolStep,
64
+ SWRCache: () => SWRCache,
66
65
  TheGraphCannotFallbackReasonSchema: () => TheGraphCannotFallbackReasonSchema,
67
66
  TheGraphFallbackSchema: () => TheGraphFallbackSchema,
68
67
  TraceableENSProtocol: () => TraceableENSProtocol,
69
68
  TtlCache: () => TtlCache,
69
+ ZERO_ENCODED_REFERRER: () => ZERO_ENCODED_REFERRER,
70
70
  accountIdEqual: () => accountIdEqual,
71
71
  addDuration: () => addDuration,
72
72
  addPrices: () => addPrices,
@@ -104,8 +104,8 @@ __export(index_exports, {
104
104
  deserializeErrorResponse: () => deserializeErrorResponse,
105
105
  deserializeIndexingStatusResponse: () => deserializeIndexingStatusResponse,
106
106
  deserializeOmnichainIndexingStatusSnapshot: () => deserializeOmnichainIndexingStatusSnapshot,
107
- deserializePaginatedAggregatedReferrersResponse: () => deserializePaginatedAggregatedReferrersResponse,
108
107
  deserializeRealtimeIndexingStatusProjection: () => deserializeRealtimeIndexingStatusProjection,
108
+ deserializeReferrerLeaderboardPageResponse: () => deserializeReferrerLeaderboardPageResponse,
109
109
  deserializeRegistrarActionsResponse: () => deserializeRegistrarActionsResponse,
110
110
  deserializeUnixTimestamp: () => deserializeUnixTimestamp,
111
111
  deserializeUrl: () => deserializeUrl,
@@ -115,6 +115,7 @@ __export(index_exports, {
115
115
  getCurrencyInfo: () => getCurrencyInfo,
116
116
  getENSRootChainId: () => import_datasources2.getENSRootChainId,
117
117
  getEthnamesSubregistryId: () => getEthnamesSubregistryId,
118
+ getLatestIndexedBlockRef: () => getLatestIndexedBlockRef,
118
119
  getNameHierarchy: () => getNameHierarchy,
119
120
  getOmnichainIndexingCursor: () => getOmnichainIndexingCursor,
120
121
  getOmnichainIndexingStatus: () => getOmnichainIndexingStatus,
@@ -162,10 +163,10 @@ __export(index_exports, {
162
163
  serializeIndexingStatusResponse: () => serializeIndexingStatusResponse,
163
164
  serializeNamedRegistrarAction: () => serializeNamedRegistrarAction,
164
165
  serializeOmnichainIndexingStatusSnapshot: () => serializeOmnichainIndexingStatusSnapshot,
165
- serializePaginatedAggregatedReferrersResponse: () => serializePaginatedAggregatedReferrersResponse,
166
166
  serializePrice: () => serializePrice,
167
167
  serializePriceEth: () => serializePriceEth,
168
168
  serializeRealtimeIndexingStatusProjection: () => serializeRealtimeIndexingStatusProjection,
169
+ serializeReferrerLeaderboardPageResponse: () => serializeReferrerLeaderboardPageResponse,
169
170
  serializeRegistrarAction: () => serializeRegistrarAction,
170
171
  serializeRegistrarActionPricing: () => serializeRegistrarActionPricing,
171
172
  serializeRegistrarActionsResponse: () => serializeRegistrarActionsResponse,
@@ -173,13 +174,11 @@ __export(index_exports, {
173
174
  serializeSubregistry: () => serializeSubregistry,
174
175
  serializeUrl: () => serializeUrl,
175
176
  sortChainStatusesByStartBlockAsc: () => sortChainStatusesByStartBlockAsc,
176
- staleWhileRevalidate: () => staleWhileRevalidate,
177
177
  stripNullBytes: () => stripNullBytes,
178
178
  translateDefaultableChainIdToChainId: () => translateDefaultableChainIdToChainId,
179
179
  uint256ToHex32: () => uint256ToHex32,
180
180
  uniq: () => uniq,
181
- validateSupportedLabelSetAndVersion: () => validateSupportedLabelSetAndVersion,
182
- zeroEncodedReferrer: () => zeroEncodedReferrer
181
+ validateSupportedLabelSetAndVersion: () => validateSupportedLabelSetAndVersion
183
182
  });
184
183
  module.exports = __toCommonJS(index_exports);
185
184
 
@@ -187,7 +186,7 @@ module.exports = __toCommonJS(index_exports);
187
186
  var import_v49 = require("zod/v4");
188
187
 
189
188
  // src/api/zod-schemas.ts
190
- var import_viem12 = require("viem");
189
+ var import_viem14 = require("viem");
191
190
  var import_v48 = __toESM(require("zod/v4"), 1);
192
191
 
193
192
  // src/ensindexer/indexing-status/zod-schemas.ts
@@ -223,8 +222,58 @@ function asLowerCaseAddress(address) {
223
222
  return address.toLowerCase();
224
223
  }
225
224
 
226
- // src/shared/cache.ts
225
+ // src/shared/cache/lru-cache.ts
226
+ var LruCache = class {
227
+ _cache = /* @__PURE__ */ new Map();
228
+ _capacity;
229
+ /**
230
+ * Create a new LRU cache with the given capacity.
231
+ *
232
+ * @param capacity The maximum number of items in the cache. If set to 0, the cache is effectively disabled.
233
+ * @throws Error if capacity is not a non-negative integer.
234
+ */
235
+ constructor(capacity) {
236
+ if (!Number.isInteger(capacity)) {
237
+ throw new Error(
238
+ `LruCache requires capacity to be an integer but a capacity of ${capacity} was requested.`
239
+ );
240
+ }
241
+ if (capacity < 0) {
242
+ throw new Error(
243
+ `LruCache requires a non-negative capacity but a capacity of ${capacity} was requested.`
244
+ );
245
+ }
246
+ this._capacity = capacity;
247
+ }
248
+ set(key, value) {
249
+ this._cache.set(key, value);
250
+ if (this._cache.size > this._capacity) {
251
+ const oldestKey = this._cache.keys().next().value;
252
+ this._cache.delete(oldestKey);
253
+ }
254
+ }
255
+ get(key) {
256
+ const value = this._cache.get(key);
257
+ if (value) {
258
+ this._cache.delete(key);
259
+ this._cache.set(key, value);
260
+ }
261
+ return value;
262
+ }
263
+ clear() {
264
+ this._cache.clear();
265
+ }
266
+ get size() {
267
+ return this._cache.size;
268
+ }
269
+ get capacity() {
270
+ return this._capacity;
271
+ }
272
+ };
273
+
274
+ // src/shared/cache/swr-cache.ts
227
275
  var import_date_fns = require("date-fns");
276
+ var import_getUnixTime = require("date-fns/getUnixTime");
228
277
 
229
278
  // src/shared/deserialize.ts
230
279
  var import_v42 = require("zod/v4");
@@ -473,6 +522,13 @@ function reinterpretName(name) {
473
522
  }
474
523
 
475
524
  // src/shared/zod-schemas.ts
525
+ var makeFiniteNonNegativeNumberSchema = (valueLabel = "Value") => import_v4.default.number({
526
+ // NOTE: Zod's implementation of `number` automatically rejects NaN and Infinity values.
527
+ // and therefore the finite check is implicit.
528
+ error: `${valueLabel} must be a finite number.`
529
+ }).nonnegative({
530
+ error: `${valueLabel} must be a non-negative number (>=0).`
531
+ });
476
532
  var makeIntegerSchema = (valueLabel = "Value") => import_v4.default.int({
477
533
  error: `${valueLabel} must be an integer.`
478
534
  });
@@ -547,13 +603,13 @@ var makePriceCurrencySchema = (currency, valueLabel = "Price Currency") => impor
547
603
  });
548
604
  var makePriceEthSchema = (valueLabel = "Price ETH") => makePriceCurrencySchema(CurrencyIds.ETH, valueLabel).transform((v) => v);
549
605
  var makeAccountIdSchema = (valueLabel = "AccountId") => import_v4.default.strictObject({
550
- chainId: makeChainIdStringSchema(`${valueLabel} chain ID`),
606
+ chainId: makeChainIdSchema(`${valueLabel} chain ID`),
551
607
  address: makeLowercaseAddressSchema(`${valueLabel} address`)
552
608
  });
553
609
  var makeSerializedAccountIdSchema = (valueLabel = "Account ID") => import_v4.default.coerce.string().transform((v) => {
554
610
  const result = new import_caip.AccountId(v);
555
611
  return {
556
- chainId: result.chainId.reference,
612
+ chainId: Number(result.chainId.reference),
557
613
  address: result.address
558
614
  };
559
615
  }).pipe(makeAccountIdSchema(valueLabel));
@@ -691,54 +747,185 @@ function addDuration(timestamp, duration) {
691
747
  return deserializeUnixTimestamp(timestamp + duration, "UnixTimestamp");
692
748
  }
693
749
 
694
- // src/shared/cache.ts
695
- var LruCache = class {
696
- _cache = /* @__PURE__ */ new Map();
697
- _capacity;
750
+ // src/shared/cache/background-revalidation-scheduler.ts
751
+ var BackgroundRevalidationScheduler = class {
752
+ activeSchedules = /* @__PURE__ */ new Map();
698
753
  /**
699
- * Create a new LRU cache with the given capacity.
754
+ * Schedule a revalidation function to run on a recurring interval.
700
755
  *
701
- * @param capacity The maximum number of items in the cache. If set to 0, the cache is effectively disabled.
702
- * @throws Error if capacity is not a non-negative integer.
756
+ * @param config Configuration object for the schedule
757
+ * @returns The revalidate function that can be passed to `cancel()` to stop the schedule
703
758
  */
704
- constructor(capacity) {
705
- if (!Number.isInteger(capacity)) {
706
- throw new Error(
707
- `LruCache requires capacity to be an integer but a capacity of ${capacity} was requested.`
708
- );
759
+ schedule(config) {
760
+ const { revalidate, interval, initialDelay = 0, onError } = config;
761
+ if (this.activeSchedules.has(revalidate)) {
762
+ return revalidate;
709
763
  }
710
- if (capacity < 0) {
711
- throw new Error(
712
- `LruCache requires a non-negative capacity but a capacity of ${capacity} was requested.`
713
- );
764
+ const metadata = {
765
+ config,
766
+ timeoutId: null,
767
+ inProgress: false
768
+ };
769
+ this.activeSchedules.set(revalidate, metadata);
770
+ const executeRevalidation = async () => {
771
+ if (metadata.inProgress) return;
772
+ metadata.inProgress = true;
773
+ try {
774
+ await revalidate();
775
+ } catch (error) {
776
+ onError?.(error);
777
+ } finally {
778
+ metadata.inProgress = false;
779
+ }
780
+ };
781
+ const scheduleNext = () => {
782
+ if (!this.activeSchedules.has(revalidate)) return;
783
+ metadata.timeoutId = setTimeout(() => {
784
+ if (this.activeSchedules.has(revalidate)) {
785
+ executeRevalidation().then(() => scheduleNext());
786
+ }
787
+ }, interval);
788
+ };
789
+ if (initialDelay > 0) {
790
+ metadata.timeoutId = setTimeout(() => {
791
+ if (this.activeSchedules.has(revalidate)) {
792
+ executeRevalidation().then(() => scheduleNext());
793
+ }
794
+ }, initialDelay);
795
+ } else {
796
+ scheduleNext();
714
797
  }
715
- this._capacity = capacity;
798
+ return revalidate;
716
799
  }
717
- set(key, value) {
718
- this._cache.set(key, value);
719
- if (this._cache.size > this._capacity) {
720
- const oldestKey = this._cache.keys().next().value;
721
- this._cache.delete(oldestKey);
800
+ /**
801
+ * Cancel a scheduled revalidation by its revalidate function.
802
+ *
803
+ * @param revalidate The revalidation function returned from `schedule()`
804
+ */
805
+ cancel(revalidate) {
806
+ const metadata = this.activeSchedules.get(revalidate);
807
+ if (!metadata) return;
808
+ if (metadata.timeoutId !== null) {
809
+ clearTimeout(metadata.timeoutId);
722
810
  }
811
+ this.activeSchedules.delete(revalidate);
723
812
  }
724
- get(key) {
725
- const value = this._cache.get(key);
726
- if (value) {
727
- this._cache.delete(key);
728
- this._cache.set(key, value);
813
+ /**
814
+ * Cancel all active schedules.
815
+ */
816
+ cancelAll() {
817
+ for (const [, metadata] of this.activeSchedules) {
818
+ if (metadata.timeoutId !== null) {
819
+ clearTimeout(metadata.timeoutId);
820
+ }
729
821
  }
730
- return value;
822
+ this.activeSchedules.clear();
731
823
  }
732
- clear() {
733
- this._cache.clear();
824
+ /**
825
+ * Get the count of active schedules.
826
+ * Useful for debugging and monitoring.
827
+ *
828
+ * @returns The number of currently active schedules
829
+ */
830
+ getActiveScheduleCount() {
831
+ return this.activeSchedules.size;
734
832
  }
735
- get size() {
736
- return this._cache.size;
833
+ };
834
+
835
+ // src/shared/cache/swr-cache.ts
836
+ var bgRevalidationScheduler = new BackgroundRevalidationScheduler();
837
+ var SWRCache = class _SWRCache {
838
+ options;
839
+ cache;
840
+ /**
841
+ * Optional promise of the current in-progress attempt to revalidate the `cache`.
842
+ *
843
+ * If null, no revalidation attempt is currently in progress.
844
+ * If not null, identifies the revalidation attempt that is currently in progress.
845
+ *
846
+ * Used to enforce no concurrent revalidation attempts.
847
+ */
848
+ inProgressRevalidate;
849
+ /**
850
+ * The callback function being managed by `BackgroundRevalidationScheduler`.
851
+ *
852
+ * If null, no background revalidation is scheduled.
853
+ * If not null, identifies the background revalidation that is currently scheduled.
854
+ *
855
+ * Used to enforce no concurrent background revalidation attempts.
856
+ */
857
+ scheduledBackgroundRevalidate;
858
+ constructor(options) {
859
+ this.cache = null;
860
+ this.inProgressRevalidate = null;
861
+ this.scheduledBackgroundRevalidate = null;
862
+ this.options = options;
737
863
  }
738
- get capacity() {
739
- return this._capacity;
864
+ /**
865
+ * Asynchronously create a new `SWRCache` instance.
866
+ *
867
+ * @param options - The {@link SWRCacheOptions} for the SWR cache.
868
+ * @returns a new `SWRCache` instance.
869
+ */
870
+ static async create(options) {
871
+ const cache = new _SWRCache(options);
872
+ if (cache.options.proactivelyInitialize) {
873
+ cache.readCache();
874
+ }
875
+ return cache;
740
876
  }
877
+ revalidate = async () => {
878
+ if (this.inProgressRevalidate) {
879
+ return this.inProgressRevalidate;
880
+ }
881
+ return this.options.fn().then((value) => {
882
+ this.cache = {
883
+ value,
884
+ updatedAt: (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())
885
+ };
886
+ return this.cache;
887
+ }).catch(() => {
888
+ return null;
889
+ }).finally(() => {
890
+ this.inProgressRevalidate = null;
891
+ if (this.options.revalidationInterval === void 0) {
892
+ return;
893
+ }
894
+ if (this.scheduledBackgroundRevalidate) {
895
+ bgRevalidationScheduler.cancel(this.scheduledBackgroundRevalidate);
896
+ }
897
+ const backgroundRevalidate = async () => {
898
+ this.revalidate();
899
+ };
900
+ this.scheduledBackgroundRevalidate = bgRevalidationScheduler.schedule({
901
+ revalidate: backgroundRevalidate,
902
+ interval: (0, import_date_fns.secondsToMilliseconds)(this.options.revalidationInterval)
903
+ });
904
+ });
905
+ };
906
+ /**
907
+ * Read the most recently cached `CachedValue` from the `SWRCache`.
908
+ *
909
+ * @returns a `CachedValue` holding a `value` of `ValueType` that was most recently successfully returned by `fn`
910
+ * or `null` if `fn` has never successfully returned and has always thrown an error,
911
+ */
912
+ readCache = async () => {
913
+ if (!this.cache) {
914
+ this.inProgressRevalidate = this.revalidate();
915
+ return this.inProgressRevalidate;
916
+ }
917
+ if (durationBetween(this.cache.updatedAt, (0, import_getUnixTime.getUnixTime)(/* @__PURE__ */ new Date())) <= this.options.ttl) {
918
+ return this.cache;
919
+ }
920
+ if (!this.inProgressRevalidate) {
921
+ this.inProgressRevalidate = this.revalidate();
922
+ }
923
+ return this.cache;
924
+ };
741
925
  };
926
+
927
+ // src/shared/cache/ttl-cache.ts
928
+ var import_getUnixTime2 = require("date-fns/getUnixTime");
742
929
  var TtlCache = class {
743
930
  _cache = /* @__PURE__ */ new Map();
744
931
  _ttl;
@@ -751,7 +938,7 @@ var TtlCache = class {
751
938
  this._ttl = ttl;
752
939
  }
753
940
  _cleanup() {
754
- const now = (0, import_date_fns.getUnixTime)(/* @__PURE__ */ new Date());
941
+ const now = (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date());
755
942
  for (const [key, entry] of this._cache.entries()) {
756
943
  if (entry.expiresAt <= now) {
757
944
  this._cache.delete(key);
@@ -760,7 +947,7 @@ var TtlCache = class {
760
947
  }
761
948
  set(key, value) {
762
949
  this._cleanup();
763
- const expiresAt = addDuration((0, import_date_fns.getUnixTime)(/* @__PURE__ */ new Date()), this._ttl);
950
+ const expiresAt = addDuration((0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date()), this._ttl);
764
951
  this._cache.set(key, { value, expiresAt });
765
952
  }
766
953
  get(key) {
@@ -769,7 +956,7 @@ var TtlCache = class {
769
956
  if (!entry) {
770
957
  return void 0;
771
958
  }
772
- if (entry.expiresAt <= (0, import_date_fns.getUnixTime)(/* @__PURE__ */ new Date())) {
959
+ if (entry.expiresAt <= (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date())) {
773
960
  this._cache.delete(key);
774
961
  return void 0;
775
962
  }
@@ -791,7 +978,7 @@ var TtlCache = class {
791
978
  if (!entry) {
792
979
  return false;
793
980
  }
794
- if (entry.expiresAt <= (0, import_date_fns.getUnixTime)(/* @__PURE__ */ new Date())) {
981
+ if (entry.expiresAt <= (0, import_getUnixTime2.getUnixTime)(/* @__PURE__ */ new Date())) {
795
982
  this._cache.delete(key);
796
983
  return false;
797
984
  }
@@ -801,39 +988,6 @@ var TtlCache = class {
801
988
  return this._cache.delete(key);
802
989
  }
803
990
  };
804
- function staleWhileRevalidate(options) {
805
- const { fn, ttl } = options;
806
- let cache = null;
807
- let cacheInitializer = null;
808
- return async () => {
809
- if (!cache) {
810
- if (cacheInitializer) {
811
- return cacheInitializer;
812
- }
813
- cacheInitializer = fn().then((value) => {
814
- cache = { value, updatedAt: (0, import_date_fns.getUnixTime)(/* @__PURE__ */ new Date()) };
815
- cacheInitializer = null;
816
- return value;
817
- }).catch(() => {
818
- cacheInitializer = null;
819
- return null;
820
- });
821
- return cacheInitializer;
822
- }
823
- const isStale = durationBetween(cache.updatedAt, (0, import_date_fns.getUnixTime)(/* @__PURE__ */ new Date())) > ttl;
824
- if (!isStale) return cache.value;
825
- if (cache.inProgressRevalidation) return cache.value;
826
- const revalidationPromise = fn().then((value) => {
827
- cache = { value, updatedAt: (0, import_date_fns.getUnixTime)(/* @__PURE__ */ new Date()) };
828
- }).catch(() => {
829
- if (cache) {
830
- cache.inProgressRevalidation = void 0;
831
- }
832
- });
833
- cache.inProgressRevalidation = revalidationPromise;
834
- return cache.value;
835
- };
836
- }
837
991
 
838
992
  // src/shared/collections.ts
839
993
  var uniq = (arr) => [...new Set(arr)];
@@ -1109,6 +1263,16 @@ function sortChainStatusesByStartBlockAsc(chains) {
1109
1263
  );
1110
1264
  return chains;
1111
1265
  }
1266
+ function getLatestIndexedBlockRef(indexingStatus, chainId) {
1267
+ const chainIndexingStatus = indexingStatus.omnichainSnapshot.chains.get(chainId);
1268
+ if (chainIndexingStatus === void 0) {
1269
+ return null;
1270
+ }
1271
+ if (chainIndexingStatus.chainStatus === ChainIndexingStatusIds.Queued) {
1272
+ return null;
1273
+ }
1274
+ return chainIndexingStatus.latestIndexedBlock;
1275
+ }
1112
1276
 
1113
1277
  // src/ensindexer/indexing-status/validations.ts
1114
1278
  function invariant_chainSnapshotQueuedBlocks(ctx) {
@@ -1643,36 +1807,45 @@ var LogLevelSchema = import_v46.z.enum(["fatal", "error", "warn", "info", "debug
1643
1807
  // src/shared/protocol-acceleration/interpret-record-values.ts
1644
1808
  var import_viem10 = require("viem");
1645
1809
 
1646
- // ../ens-referrals/src/referrer.ts
1810
+ // ../ens-referrals/src/address.ts
1647
1811
  var import_viem11 = require("viem");
1812
+
1813
+ // ../ens-referrals/src/encoding.ts
1814
+ var import_viem12 = require("viem");
1648
1815
  var ENCODED_REFERRER_BYTE_OFFSET = 12;
1649
1816
  var ENCODED_REFERRER_BYTE_LENGTH = 32;
1650
- var encodedReferrerPadding = (0, import_viem11.pad)("0x", {
1817
+ var EXPECTED_ENCODED_REFERRER_PADDING = (0, import_viem12.pad)("0x", {
1651
1818
  size: ENCODED_REFERRER_BYTE_OFFSET,
1652
1819
  dir: "left"
1653
1820
  });
1654
- var zeroEncodedReferrer = (0, import_viem11.pad)("0x", {
1821
+ var ZERO_ENCODED_REFERRER = (0, import_viem12.pad)("0x", {
1655
1822
  size: ENCODED_REFERRER_BYTE_LENGTH,
1656
1823
  dir: "left"
1657
1824
  });
1658
1825
  function decodeEncodedReferrer(encodedReferrer) {
1659
- if ((0, import_viem11.size)(encodedReferrer) !== ENCODED_REFERRER_BYTE_LENGTH) {
1826
+ if ((0, import_viem12.size)(encodedReferrer) !== ENCODED_REFERRER_BYTE_LENGTH) {
1660
1827
  throw new Error(
1661
1828
  `Encoded referrer value must be represented by ${ENCODED_REFERRER_BYTE_LENGTH} bytes.`
1662
1829
  );
1663
1830
  }
1664
- const padding = (0, import_viem11.slice)(encodedReferrer, 0, ENCODED_REFERRER_BYTE_OFFSET);
1665
- if (padding !== encodedReferrerPadding) {
1666
- return import_viem11.zeroAddress;
1831
+ const padding = (0, import_viem12.slice)(encodedReferrer, 0, ENCODED_REFERRER_BYTE_OFFSET);
1832
+ if (padding !== EXPECTED_ENCODED_REFERRER_PADDING) {
1833
+ return import_viem12.zeroAddress;
1667
1834
  }
1668
- const decodedReferrer = (0, import_viem11.slice)(encodedReferrer, ENCODED_REFERRER_BYTE_OFFSET);
1835
+ const decodedReferrer = (0, import_viem12.slice)(encodedReferrer, ENCODED_REFERRER_BYTE_OFFSET);
1669
1836
  try {
1670
- return (0, import_viem11.getAddress)(decodedReferrer);
1837
+ return (0, import_viem12.getAddress)(decodedReferrer);
1671
1838
  } catch {
1672
1839
  throw new Error(`Decoded referrer value must be a valid EVM address.`);
1673
1840
  }
1674
1841
  }
1675
1842
 
1843
+ // ../ens-referrals/src/leaderboard-page.ts
1844
+ var REFERRERS_PER_LEADERBOARD_PAGE_MAX = 100;
1845
+
1846
+ // ../ens-referrals/src/link.ts
1847
+ var import_viem13 = require("viem");
1848
+
1676
1849
  // src/registrars/zod-schemas.ts
1677
1850
  var import_v47 = __toESM(require("zod/v4"), 1);
1678
1851
 
@@ -1885,7 +2058,7 @@ var makeIndexingStatusResponseSchema = (valueLabel = "Indexing Status Response")
1885
2058
  function invariant_registrationLifecycleNodeMatchesName(ctx) {
1886
2059
  const { name, action } = ctx.value;
1887
2060
  const expectedNode = action.registrationLifecycle.node;
1888
- const actualNode = (0, import_viem12.namehash)(name);
2061
+ const actualNode = (0, import_viem14.namehash)(name);
1889
2062
  if (actualNode !== expectedNode) {
1890
2063
  ctx.issues.push({
1891
2064
  code: "custom",
@@ -1979,7 +2152,7 @@ ${(0, import_v410.prettifyError)(parsed.error)}
1979
2152
  }
1980
2153
 
1981
2154
  // src/ensindexer/config/label-utils.ts
1982
- var import_viem13 = require("viem");
2155
+ var import_viem15 = require("viem");
1983
2156
  function labelHashToBytes(labelHash) {
1984
2157
  try {
1985
2158
  if (labelHash.length !== 66) {
@@ -1991,7 +2164,7 @@ function labelHashToBytes(labelHash) {
1991
2164
  if (!labelHash.startsWith("0x")) {
1992
2165
  throw new Error("Labelhash must be 0x-prefixed");
1993
2166
  }
1994
- const bytes = (0, import_viem13.hexToBytes)(labelHash);
2167
+ const bytes = (0, import_viem15.hexToBytes)(labelHash);
1995
2168
  if (bytes.length !== 32) {
1996
2169
  throw new Error(`Invalid labelHash length ${bytes.length} bytes (expected 32)`);
1997
2170
  }
@@ -2322,89 +2495,98 @@ var import_v413 = require("zod/v4");
2322
2495
  var import_v412 = __toESM(require("zod/v4"), 1);
2323
2496
 
2324
2497
  // src/ensanalytics/types.ts
2325
- var ITEMS_PER_PAGE_DEFAULT = 25;
2326
- var ITEMS_PER_PAGE_MAX = 100;
2327
- var PaginatedAggregatedReferrersResponseCodes = {
2498
+ var ReferrerLeaderboardPageResponseCodes = {
2328
2499
  /**
2329
- * Represents that the aggregated referrers data is available.
2330
- * @note The response may contain an empty array for the first page if there are no qualified referrers.
2331
- * When the array is empty, total will be 0, page will be 1, and both hasNext and hasPrev will be false.
2500
+ * Represents that the requested referrer leaderboard page is available.
2332
2501
  */
2333
2502
  Ok: "ok",
2334
2503
  /**
2335
- * Represents that the aggregated referrers data is not available.
2504
+ * Represents that the referrer leaderboard data is not available.
2336
2505
  */
2337
2506
  Error: "error"
2338
2507
  };
2339
2508
 
2340
2509
  // src/ensanalytics/zod-schemas.ts
2341
- var makeAggregatedReferrerMetricsSchema = (valueLabel = "AggregatedReferrerMetrics") => import_v412.default.object({
2342
- referrer: makeLowercaseAddressSchema(`${valueLabel}.referrer`),
2343
- totalReferrals: makePositiveIntegerSchema(`${valueLabel}.totalReferrals`),
2344
- totalIncrementalDuration: makeDurationSchema(`${valueLabel}.totalIncrementalDuration`)
2510
+ var makeReferralProgramRulesSchema = (valueLabel = "ReferralProgramRules") => import_v412.default.object({
2511
+ totalAwardPoolValue: makeFiniteNonNegativeNumberSchema(`${valueLabel}.totalAwardPoolValue`),
2512
+ maxQualifiedReferrers: makeNonNegativeIntegerSchema(`${valueLabel}.maxQualifiedReferrers`),
2513
+ startTime: makeUnixTimestampSchema(`${valueLabel}.startTime`),
2514
+ endTime: makeUnixTimestampSchema(`${valueLabel}.endTime`),
2515
+ subregistryId: makeAccountIdSchema(`${valueLabel}.subregistryId`)
2345
2516
  });
2346
- var makeAggregatedReferrerMetricsContributionSchema = (valueLabel = "AggregatedReferrerMetricsContribution") => makeAggregatedReferrerMetricsSchema(valueLabel).extend({
2347
- totalReferralsContribution: import_v412.default.number({
2348
- error: `${valueLabel}.totalReferralsContribution must be a number`
2349
- }).min(0, `${valueLabel}.totalReferralsContribution must be >= 0`).max(1, `${valueLabel}.totalReferralsContribution must be <= 1`),
2350
- totalIncrementalDurationContribution: import_v412.default.number({
2351
- error: `${valueLabel}.totalIncrementalDurationContribution must be a number`
2352
- }).min(0, `${valueLabel}.totalIncrementalDurationContribution must be >= 0`).max(1, `${valueLabel}.totalIncrementalDurationContribution must be <= 1`)
2517
+ var makeAwardedReferrerMetricsSchema = (valueLabel = "AwardedReferrerMetrics") => import_v412.default.object({
2518
+ referrer: makeLowercaseAddressSchema(`${valueLabel}.referrer`),
2519
+ totalReferrals: makeNonNegativeIntegerSchema(`${valueLabel}.totalReferrals`),
2520
+ totalIncrementalDuration: makeDurationSchema(`${valueLabel}.totalIncrementalDuration`),
2521
+ score: makeFiniteNonNegativeNumberSchema(`${valueLabel}.score`),
2522
+ rank: makePositiveIntegerSchema(`${valueLabel}.rank`),
2523
+ isQualified: import_v412.default.boolean(),
2524
+ finalScoreBoost: makeFiniteNonNegativeNumberSchema(`${valueLabel}.finalScoreBoost`).max(
2525
+ 1,
2526
+ `${valueLabel}.finalScoreBoost must be <= 1`
2527
+ ),
2528
+ finalScore: makeFiniteNonNegativeNumberSchema(`${valueLabel}.finalScore`),
2529
+ awardPoolShare: makeFiniteNonNegativeNumberSchema(`${valueLabel}.awardPoolShare`).max(
2530
+ 1,
2531
+ `${valueLabel}.awardPoolShare must be <= 1`
2532
+ ),
2533
+ awardPoolApproxValue: makeFiniteNonNegativeNumberSchema(`${valueLabel}.awardPoolApproxValue`)
2353
2534
  });
2354
- var makePaginationParamsSchema = (valueLabel = "PaginationParams") => import_v412.default.object({
2355
- page: makePositiveIntegerSchema(`${valueLabel}.page`).default(1),
2356
- itemsPerPage: makePositiveIntegerSchema(`${valueLabel}.itemsPerPage`).max(ITEMS_PER_PAGE_MAX, `${valueLabel}.itemsPerPage must not exceed ${ITEMS_PER_PAGE_MAX}`).default(ITEMS_PER_PAGE_DEFAULT)
2535
+ var makeAggregatedReferrerMetricsSchema = (valueLabel = "AggregatedReferrerMetrics") => import_v412.default.object({
2536
+ grandTotalReferrals: makeNonNegativeIntegerSchema(`${valueLabel}.grandTotalReferrals`),
2537
+ grandTotalIncrementalDuration: makeDurationSchema(
2538
+ `${valueLabel}.grandTotalIncrementalDuration`
2539
+ ),
2540
+ grandTotalQualifiedReferrersFinalScore: makeFiniteNonNegativeNumberSchema(
2541
+ `${valueLabel}.grandTotalQualifiedReferrersFinalScore`
2542
+ ),
2543
+ minFinalScoreToQualify: makeFiniteNonNegativeNumberSchema(
2544
+ `${valueLabel}.minFinalScoreToQualify`
2545
+ )
2357
2546
  });
2358
- var makePaginatedAggregatedReferrersSchema = (valueLabel = "PaginatedAggregatedReferrers") => import_v412.default.object({
2359
- referrers: import_v412.default.array(
2360
- makeAggregatedReferrerMetricsContributionSchema(`${valueLabel}.referrers[item]`)
2547
+ var makeReferrerLeaderboardPaginationContextSchema = (valueLabel = "ReferrerLeaderboardPaginationContext") => import_v412.default.object({
2548
+ page: makePositiveIntegerSchema(`${valueLabel}.page`),
2549
+ itemsPerPage: makePositiveIntegerSchema(`${valueLabel}.itemsPerPage`).max(
2550
+ REFERRERS_PER_LEADERBOARD_PAGE_MAX,
2551
+ `${valueLabel}.itemsPerPage must not exceed ${REFERRERS_PER_LEADERBOARD_PAGE_MAX}`
2361
2552
  ),
2362
- total: makeNonNegativeIntegerSchema(`${valueLabel}.total`),
2363
- paginationParams: makePaginationParamsSchema(`${valueLabel}.paginationParams`),
2553
+ totalRecords: makeNonNegativeIntegerSchema(`${valueLabel}.totalRecords`),
2554
+ totalPages: makePositiveIntegerSchema(`${valueLabel}.totalPages`),
2364
2555
  hasNext: import_v412.default.boolean(),
2365
2556
  hasPrev: import_v412.default.boolean(),
2366
- updatedAt: makeUnixTimestampSchema(`${valueLabel}.updatedAt`)
2367
- }).check((ctx) => {
2368
- const { paginationParams, hasNext, hasPrev, total } = ctx.value;
2369
- const expectedHasPrev = paginationParams.page > 1;
2370
- if (hasPrev !== expectedHasPrev) {
2371
- ctx.issues.push({
2372
- code: "custom",
2373
- message: `${valueLabel}.hasPrev must be ${expectedHasPrev} when page is ${paginationParams.page}`,
2374
- input: ctx.value
2375
- });
2376
- }
2377
- const endIndex = paginationParams.page * paginationParams.itemsPerPage;
2378
- const expectedHasNext = endIndex < total;
2379
- if (hasNext !== expectedHasNext) {
2380
- ctx.issues.push({
2381
- code: "custom",
2382
- message: `${valueLabel}.hasNext must be ${expectedHasNext} when page=${paginationParams.page}, itemsPerPage=${paginationParams.itemsPerPage}, total=${total}`,
2383
- input: ctx.value
2384
- });
2385
- }
2557
+ startIndex: import_v412.default.optional(makeNonNegativeIntegerSchema(`${valueLabel}.startIndex`)),
2558
+ endIndex: import_v412.default.optional(makeNonNegativeIntegerSchema(`${valueLabel}.endIndex`))
2386
2559
  });
2387
- var makePaginatedAggregatedReferrersResponseOkSchema = (valueLabel = "PaginatedAggregatedReferrersResponse") => import_v412.default.object({
2388
- responseCode: import_v412.default.literal(PaginatedAggregatedReferrersResponseCodes.Ok),
2389
- data: makePaginatedAggregatedReferrersSchema(`${valueLabel}.data`)
2560
+ var makeReferrerLeaderboardPageSchema = (valueLabel = "ReferrerLeaderboardPage") => import_v412.default.object({
2561
+ rules: makeReferralProgramRulesSchema(`${valueLabel}.rules`),
2562
+ referrers: import_v412.default.array(makeAwardedReferrerMetricsSchema(`${valueLabel}.referrers[item]`)),
2563
+ aggregatedMetrics: makeAggregatedReferrerMetricsSchema(`${valueLabel}.aggregatedMetrics`),
2564
+ paginationContext: makeReferrerLeaderboardPaginationContextSchema(
2565
+ `${valueLabel}.paginationContext`
2566
+ ),
2567
+ accurateAsOf: makeUnixTimestampSchema(`${valueLabel}.accurateAsOf`)
2568
+ });
2569
+ var makeReferrerLeaderboardPageResponseOkSchema = (valueLabel = "ReferrerLeaderboardPageResponseOk") => import_v412.default.object({
2570
+ responseCode: import_v412.default.literal(ReferrerLeaderboardPageResponseCodes.Ok),
2571
+ data: makeReferrerLeaderboardPageSchema(`${valueLabel}.data`)
2390
2572
  });
2391
- var makePaginatedAggregatedReferrersResponseErrorSchema = (_valueLabel = "PaginatedAggregatedReferrersResponse") => import_v412.default.object({
2392
- responseCode: import_v412.default.literal(PaginatedAggregatedReferrersResponseCodes.Error),
2573
+ var makeReferrerLeaderboardPageResponseErrorSchema = (_valueLabel = "ReferrerLeaderboardPageResponseError") => import_v412.default.object({
2574
+ responseCode: import_v412.default.literal(ReferrerLeaderboardPageResponseCodes.Error),
2393
2575
  error: import_v412.default.string(),
2394
2576
  errorMessage: import_v412.default.string()
2395
2577
  });
2396
- var makePaginatedAggregatedReferrersResponseSchema = (valueLabel = "PaginatedAggregatedReferrersResponse") => import_v412.default.union([
2397
- makePaginatedAggregatedReferrersResponseOkSchema(valueLabel),
2398
- makePaginatedAggregatedReferrersResponseErrorSchema(valueLabel)
2578
+ var makeReferrerLeaderboardPageResponseSchema = (valueLabel = "ReferrerLeaderboardPageResponse") => import_v412.default.union([
2579
+ makeReferrerLeaderboardPageResponseOkSchema(valueLabel),
2580
+ makeReferrerLeaderboardPageResponseErrorSchema(valueLabel)
2399
2581
  ]);
2400
2582
 
2401
2583
  // src/ensanalytics/deserialize.ts
2402
- function deserializePaginatedAggregatedReferrersResponse(maybeResponse, valueLabel) {
2403
- const schema = makePaginatedAggregatedReferrersResponseSchema(valueLabel);
2584
+ function deserializeReferrerLeaderboardPageResponse(maybeResponse, valueLabel) {
2585
+ const schema = makeReferrerLeaderboardPageResponseSchema(valueLabel);
2404
2586
  const parsed = schema.safeParse(maybeResponse);
2405
2587
  if (parsed.error) {
2406
2588
  throw new Error(
2407
- `Cannot deserialize PaginatedAggregatedReferrersResponse:
2589
+ `Cannot deserialize SerializedReferrerLeaderboardPageResponse:
2408
2590
  ${(0, import_v413.prettifyError)(parsed.error)}
2409
2591
  `
2410
2592
  );
@@ -2413,11 +2595,11 @@ ${(0, import_v413.prettifyError)(parsed.error)}
2413
2595
  }
2414
2596
 
2415
2597
  // src/ensanalytics/serialize.ts
2416
- function serializePaginatedAggregatedReferrersResponse(response) {
2598
+ function serializeReferrerLeaderboardPageResponse(response) {
2417
2599
  switch (response.responseCode) {
2418
- case PaginatedAggregatedReferrersResponseCodes.Ok:
2600
+ case ReferrerLeaderboardPageResponseCodes.Ok:
2419
2601
  return response;
2420
- case PaginatedAggregatedReferrersResponseCodes.Error:
2602
+ case ReferrerLeaderboardPageResponseCodes.Error:
2421
2603
  return response;
2422
2604
  }
2423
2605
  }
@@ -2707,15 +2889,15 @@ var ENSNodeClient = class _ENSNodeClient {
2707
2889
  return deserializeIndexingStatusResponse(responseData);
2708
2890
  }
2709
2891
  /**
2710
- * Fetch Paginated Aggregated Referrers
2892
+ * Fetch Referrer Leaderboard Page
2711
2893
  *
2712
- * Retrieves a paginated list of aggregated referrer metrics with contribution percentages.
2894
+ * Retrieves a paginated list of referrer leaderboard metrics with contribution percentages.
2713
2895
  * Each referrer's contribution is calculated as a percentage of the grand totals across all referrers.
2714
2896
  *
2715
2897
  * @param request - Pagination parameters
2716
2898
  * @param request.page - The page number to retrieve (1-indexed, default: 1)
2717
2899
  * @param request.itemsPerPage - Number of items per page (default: 25, max: 100)
2718
- * @returns {PaginatedAggregatedReferrersResponse}
2900
+ * @returns {ReferrerLeaderboardPageResponse}
2719
2901
  *
2720
2902
  * @throws if the ENSNode request fails
2721
2903
  * @throws if the ENSNode API returns an error response
@@ -2724,21 +2906,42 @@ var ENSNodeClient = class _ENSNodeClient {
2724
2906
  * @example
2725
2907
  * ```typescript
2726
2908
  * // Get first page with default page size (25 items)
2727
- * const response = await client.getAggregatedReferrers();
2728
- * if (response.responseCode === 'ok') {
2729
- * console.log(response.data.referrers);
2730
- * console.log(`Page ${response.data.paginationParams.page} of ${Math.ceil(response.data.total / response.data.paginationParams.itemsPerPage)}`);
2909
+ * const response = await client.getReferrerLeaderboard();
2910
+ * if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Ok) {
2911
+ * const {
2912
+ * aggregatedMetrics,
2913
+ * referrers,
2914
+ * rules,
2915
+ * paginationContext,
2916
+ * updatedAt
2917
+ * } = response.data;
2918
+ * console.log(aggregatedMetrics);
2919
+ * console.log(referrers);
2920
+ * console.log(rules);
2921
+ * console.log(updatedAt);
2922
+ * console.log(`Page ${paginationContext.page} of ${paginationContext.totalPages}`);
2731
2923
  * }
2732
2924
  * ```
2733
2925
  *
2734
2926
  * @example
2735
2927
  * ```typescript
2736
2928
  * // Get second page with 50 items per page
2737
- * const response = await client.getAggregatedReferrers({ page: 2, itemsPerPage: 50 });
2929
+ * const response = await client.getReferrerLeaderboard({ page: 2, itemsPerPage: 50 });
2930
+ * ```
2931
+ *
2932
+ * @example
2933
+ * ```typescript
2934
+ * // Handle error response, ie. when Referrer Leaderboard is not currently available.
2935
+ * const response = await client.getReferrerLeaderboard();
2936
+ *
2937
+ * if (response.responseCode === ReferrerLeaderboardPageResponseCodes.Error) {
2938
+ * console.error(response.error);
2939
+ * console.error(response.errorMessage);
2940
+ * }
2738
2941
  * ```
2739
2942
  */
2740
- async getAggregatedReferrers(request) {
2741
- const url = new URL(`/ensanalytics/aggregated-referrers`, this.options.url);
2943
+ async getReferrerLeaderboard(request) {
2944
+ const url = new URL(`/ensanalytics/referrers`, this.options.url);
2742
2945
  if (request?.page) url.searchParams.set("page", request.page.toString());
2743
2946
  if (request?.itemsPerPage)
2744
2947
  url.searchParams.set("itemsPerPage", request.itemsPerPage.toString());
@@ -2749,7 +2952,7 @@ var ENSNodeClient = class _ENSNodeClient {
2749
2952
  } catch {
2750
2953
  throw new Error("Malformed response data: invalid JSON");
2751
2954
  }
2752
- return deserializePaginatedAggregatedReferrersResponse(
2955
+ return deserializeReferrerLeaderboardPageResponse(
2753
2956
  responseData
2754
2957
  );
2755
2958
  }