@gvnrdao/dh-sdk 0.0.291 → 0.0.293

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.mjs CHANGED
@@ -3750,7 +3750,7 @@ var require_abstract_coder = __commonJS({
3750
3750
  function toObject2(names2, items, deep) {
3751
3751
  if (names2.indexOf(null) >= 0) {
3752
3752
  return items.map((item, index) => {
3753
- if (item instanceof Result11) {
3753
+ if (item instanceof Result10) {
3754
3754
  return toObject2(getNames2(item), item, deep);
3755
3755
  }
3756
3756
  return item;
@@ -3759,7 +3759,7 @@ var require_abstract_coder = __commonJS({
3759
3759
  return names2.reduce((accum, name, index) => {
3760
3760
  let item = items.getValue(name);
3761
3761
  if (!(name in accum)) {
3762
- if (deep && item instanceof Result11) {
3762
+ if (deep && item instanceof Result10) {
3763
3763
  item = toObject2(getNames2(item), item, deep);
3764
3764
  }
3765
3765
  accum[name] = item;
@@ -3767,7 +3767,7 @@ var require_abstract_coder = __commonJS({
3767
3767
  return accum;
3768
3768
  }, {});
3769
3769
  }
3770
- var Result11 = class _Result extends Array {
3770
+ var Result10 = class _Result extends Array {
3771
3771
  // No longer used; but cannot be removed as it will remove the
3772
3772
  // #private field from the .d.ts which may break backwards
3773
3773
  // compatibility
@@ -3971,7 +3971,7 @@ var require_abstract_coder = __commonJS({
3971
3971
  return new _Result(_guard5, items, keys);
3972
3972
  }
3973
3973
  };
3974
- exports2.Result = Result11;
3974
+ exports2.Result = Result10;
3975
3975
  function checkResultErrors2(result) {
3976
3976
  const errors2 = [];
3977
3977
  const checkErrors = function(path2, object2) {
@@ -34949,8 +34949,8 @@ function getMainnetConfig() {
34949
34949
  bitcoinWithdrawalAddressRegistry: MAINNET_CONTRACTS.BitcoinWithdrawalAddressRegistry || ""
34950
34950
  },
34951
34951
  subgraphs: {
34952
- diamondHandsUrl: "https://gateway-arbitrum.network.thegraph.com/api/subgraphs/id/CCTPsdYqco2jChDLLBQTbdJWwoukVoMt1cXeR9ti6r9A"
34953
- // Published Sepolia subgraph on Arbitrum One
34952
+ diamondHandsUrl: "https://api.studio.thegraph.com/query/1755201/diamond-hands/v1.0.0-mainnet"
34953
+ // Mainnet subgraph (keyless studio endpoint, browser-queryable)
34954
34954
  },
34955
34955
  litNetwork: "chipotle",
34956
34956
  debug: false
@@ -109745,365 +109745,106 @@ function createContractManager(config) {
109745
109745
  }
109746
109746
 
109747
109747
  // src/modules/cache/cache-manager.module.ts
109748
- var LRUCache = class {
109749
- cache;
109750
- /**
109751
- * Audit M-J: singleflight registry for `getOrCompute` / `getOrComputeResult`.
109752
- * Concurrent cache-miss callers for the same key share one inflight promise
109753
- * instead of each running `compute()` independently — important when the
109754
- * compute spends a paid LIT capacity credit or hits a rate-limited upstream.
109755
- */
109756
- inflight = /* @__PURE__ */ new Map();
109757
- inflightResult = /* @__PURE__ */ new Map();
109748
+ var Cache = class {
109749
+ cache = /* @__PURE__ */ new Map();
109758
109750
  maxSize;
109759
109751
  ttlMs;
109760
- debug;
109761
- name;
109762
- // Statistics
109763
- stats = {
109764
- hits: 0,
109765
- misses: 0,
109766
- evictions: 0
109767
- };
109768
- constructor(config = {}) {
109769
- this.cache = /* @__PURE__ */ new Map();
109770
- this.maxSize = config.maxSize || 1e3;
109771
- this.ttlMs = config.ttlMs || 6e4;
109772
- this.debug = config.debug || false;
109773
- this.name = config.name || "Cache";
109774
- if (this.debug) {
109775
- console.log(
109776
- `\u{1F4BE} [${this.name}] Initialized: maxSize=${this.maxSize}, ttl=${this.ttlMs}ms`
109777
- );
109778
- }
109752
+ constructor(config) {
109753
+ this.maxSize = config.maxSize;
109754
+ this.ttlMs = config.ttlMs;
109779
109755
  }
109780
109756
  /**
109781
109757
  * Get value from cache
109782
- *
109783
- * Returns null if:
109784
- * - Key not found
109785
- * - Entry has expired
109786
- *
109787
- * @param key - Cache key
109788
- * @returns Cached value or null
109789
109758
  */
109790
109759
  get(key) {
109791
109760
  const entry = this.cache.get(key);
109792
109761
  if (!entry) {
109793
- this.stats.misses++;
109794
- if (this.debug) {
109795
- console.log(`\u274C [${this.name}] Cache MISS: ${String(key)}`);
109796
- }
109797
- return null;
109762
+ return void 0;
109798
109763
  }
109799
- if (this.isExpired(entry)) {
109764
+ const now = Date.now();
109765
+ if (now - entry.timestamp > entry.ttl) {
109800
109766
  this.cache.delete(key);
109801
- this.stats.misses++;
109802
- if (this.debug) {
109803
- const age = Date.now() - entry.timestamp;
109804
- console.log(`\u23F0 [${this.name}] Cache EXPIRED: ${String(key)} (age: ${age}ms)`);
109805
- }
109806
- return null;
109807
- }
109808
- entry.hits++;
109809
- entry.lastAccessed = Date.now();
109810
- this.cache.set(key, entry);
109811
- this.stats.hits++;
109812
- if (this.debug) {
109813
- const age = Date.now() - entry.timestamp;
109814
- console.log(
109815
- `\u2705 [${this.name}] Cache HIT: ${String(key)} (age: ${age}ms, hits: ${entry.hits})`
109816
- );
109767
+ return void 0;
109817
109768
  }
109818
109769
  return entry.value;
109819
109770
  }
109820
- /**
109821
- * Get value from cache with Result wrapper
109822
- *
109823
- * Useful when you want to distinguish between "not found" and "expired"
109824
- */
109825
- getResult(key) {
109826
- const value = this.get(key);
109827
- if (value === null) {
109828
- return failure(
109829
- new SDKError({
109830
- message: `Cache miss for key: ${String(key)}`,
109831
- category: "CACHE" /* CACHE */,
109832
- severity: "LOW" /* LOW */,
109833
- originalError: new Error("Cache miss")
109834
- })
109835
- );
109836
- }
109837
- return success(value);
109838
- }
109839
109771
  /**
109840
109772
  * Set value in cache
109841
- *
109842
- * If cache is full, evicts the least recently used entry
109843
- *
109844
- * @param key - Cache key
109845
- * @param value - Value to cache
109846
- * @param ttl - Optional custom TTL for this entry (ms)
109847
109773
  */
109848
109774
  set(key, value, ttl) {
109849
109775
  if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
109850
- this.evictLRU();
109776
+ const firstKey = this.cache.keys().next().value;
109777
+ if (firstKey) {
109778
+ this.cache.delete(firstKey);
109779
+ }
109851
109780
  }
109852
- const entry = {
109781
+ this.cache.set(key, {
109853
109782
  value,
109854
109783
  timestamp: Date.now(),
109855
- hits: 0,
109856
- lastAccessed: Date.now()
109857
- };
109858
- this.cache.set(key, entry);
109859
- if (this.debug) {
109860
- const effectiveTtl = ttl || this.ttlMs;
109861
- console.log(
109862
- `\u{1F4BE} [${this.name}] Cache SET: ${String(key)} (ttl: ${effectiveTtl}ms, size: ${this.cache.size}/${this.maxSize})`
109863
- );
109864
- }
109865
- }
109866
- /**
109867
- * Set value in cache with Result wrapper
109868
- */
109869
- setResult(key, value, ttl) {
109870
- try {
109871
- this.set(key, value, ttl);
109872
- return success(void 0);
109873
- } catch (error2) {
109874
- return failure(
109875
- new SDKError({
109876
- message: `Failed to set cache value for key: ${String(key)}`,
109877
- category: "CACHE" /* CACHE */,
109878
- severity: "MEDIUM" /* MEDIUM */,
109879
- originalError: error2 instanceof Error ? error2 : new Error(String(error2))
109880
- })
109881
- );
109882
- }
109784
+ ttl: ttl || this.ttlMs
109785
+ });
109883
109786
  }
109884
109787
  /**
109885
- * Check if key exists in cache (without affecting stats)
109788
+ * Check if key exists in cache
109886
109789
  */
109887
109790
  has(key) {
109888
- const entry = this.cache.get(key);
109889
- return entry !== void 0 && !this.isExpired(entry);
109791
+ return this.get(key) !== void 0;
109890
109792
  }
109891
109793
  /**
109892
- * Delete specific key from cache
109794
+ * Delete key from cache
109893
109795
  */
109894
109796
  delete(key) {
109895
- const deleted = this.cache.delete(key);
109896
- if (deleted && this.debug) {
109897
- console.log(`\u{1F5D1}\uFE0F [${this.name}] Cache DELETE: ${String(key)}`);
109898
- }
109899
- return deleted;
109797
+ return this.cache.delete(key);
109900
109798
  }
109901
109799
  /**
109902
- * Clear entire cache
109800
+ * Clear all cache entries
109903
109801
  */
109904
109802
  clear() {
109905
- const previousSize = this.cache.size;
109906
109803
  this.cache.clear();
109907
- this.stats = {
109908
- hits: 0,
109909
- misses: 0,
109910
- evictions: 0
109911
- };
109912
- if (this.debug) {
109913
- console.log(`\u{1F9F9} [${this.name}] Cache CLEARED: removed ${previousSize} entries`);
109914
- }
109915
- }
109916
- /**
109917
- * Get current cache size
109918
- */
109919
- size() {
109920
- return this.cache.size;
109921
- }
109922
- /**
109923
- * Get cache statistics
109924
- */
109925
- getStats() {
109926
- const entries = Array.from(this.cache.values());
109927
- const timestamps = entries.map((e) => e.timestamp);
109928
- const total = this.stats.hits + this.stats.misses;
109929
- const hitRate = total === 0 ? 0 : this.stats.hits / total * 100;
109930
- return {
109931
- size: this.cache.size,
109932
- hits: this.stats.hits,
109933
- misses: this.stats.misses,
109934
- evictions: this.stats.evictions,
109935
- oldestEntry: timestamps.length > 0 ? Math.min(...timestamps) : 0,
109936
- newestEntry: timestamps.length > 0 ? Math.max(...timestamps) : 0,
109937
- hitRate
109938
- };
109939
109804
  }
109940
109805
  /**
109941
- * Get hit rate percentage
109942
- */
109943
- getHitRate() {
109944
- const total = this.stats.hits + this.stats.misses;
109945
- return total === 0 ? 0 : this.stats.hits / total * 100;
109946
- }
109947
- /**
109948
- * Get all cached keys (for debugging)
109949
- */
109950
- getKeys() {
109951
- return Array.from(this.cache.keys());
109952
- }
109953
- /**
109954
- * Get all cached values (for debugging)
109955
- */
109956
- getValues() {
109957
- return Array.from(this.cache.values()).map((entry) => entry.value);
109958
- }
109959
- /**
109960
- * Get all cache entries with metadata (for debugging)
109961
- */
109962
- getEntries() {
109963
- return Array.from(this.cache.entries()).map(([key, entry]) => ({
109964
- key,
109965
- value: entry.value,
109966
- metadata: {
109967
- timestamp: entry.timestamp,
109968
- hits: entry.hits,
109969
- lastAccessed: entry.lastAccessed
109970
- }
109971
- }));
109972
- }
109973
- /**
109974
- * Clean up expired entries
109975
- *
109976
- * Useful for periodic maintenance
109977
- *
109978
- * @returns Number of entries cleaned
109806
+ * Clean expired entries
109979
109807
  */
109980
109808
  cleanExpired() {
109981
109809
  const now = Date.now();
109982
- let cleanedCount = 0;
109810
+ let cleaned = 0;
109983
109811
  for (const [key, entry] of this.cache.entries()) {
109984
- if (now - entry.timestamp > this.ttlMs) {
109812
+ if (now - entry.timestamp > entry.ttl) {
109985
109813
  this.cache.delete(key);
109986
- cleanedCount++;
109987
- }
109988
- }
109989
- if (cleanedCount > 0 && this.debug) {
109990
- console.log(`\u{1F9F9} [${this.name}] Cleaned ${cleanedCount} expired entries`);
109991
- }
109992
- return cleanedCount;
109993
- }
109994
- /**
109995
- * Check if cache entry is expired
109996
- */
109997
- isExpired(entry) {
109998
- return Date.now() - entry.timestamp > this.ttlMs;
109999
- }
110000
- /**
110001
- * Evict least recently used entry
110002
- */
110003
- evictLRU() {
110004
- let oldestKey = null;
110005
- let oldestAccess = Infinity;
110006
- for (const [key, entry] of this.cache.entries()) {
110007
- if (entry.lastAccessed < oldestAccess) {
110008
- oldestAccess = entry.lastAccessed;
110009
- oldestKey = key;
110010
- }
110011
- }
110012
- if (oldestKey !== null) {
110013
- this.cache.delete(oldestKey);
110014
- this.stats.evictions++;
110015
- if (this.debug) {
110016
- const timeSinceAccess = Date.now() - oldestAccess;
110017
- console.log(
110018
- `\u267B\uFE0F [${this.name}] Cache EVICT (LRU): ${String(oldestKey)} (last accessed: ${timeSinceAccess}ms ago)`
110019
- );
109814
+ cleaned++;
110020
109815
  }
110021
109816
  }
109817
+ return cleaned;
110022
109818
  }
110023
109819
  /**
110024
- * Get or compute value
110025
- *
110026
- * If key exists in cache, returns cached value.
110027
- * Otherwise, computes value using provided function and caches it.
110028
- *
110029
- * @param key - Cache key
110030
- * @param compute - Function to compute value if not in cache
110031
- * @param ttl - Optional custom TTL for this entry
110032
- * @returns Cached or computed value
110033
- */
110034
- async getOrCompute(key, compute, ttl) {
110035
- const cached = this.get(key);
110036
- if (cached !== null) {
110037
- return cached;
110038
- }
110039
- const existing = this.inflight.get(key);
110040
- if (existing) {
110041
- return existing;
110042
- }
110043
- const computePromise = (async () => {
110044
- try {
110045
- const value = await compute();
110046
- this.set(key, value, ttl);
110047
- return value;
110048
- } finally {
110049
- this.inflight.delete(key);
110050
- }
110051
- })();
110052
- this.inflight.set(key, computePromise);
110053
- return computePromise;
110054
- }
110055
- /**
110056
- * Get or compute value with Result wrapper
109820
+ * Get cache statistics
110057
109821
  */
110058
- async getOrComputeResult(key, compute, ttl) {
110059
- const cached = this.get(key);
110060
- if (cached !== null) {
110061
- return success(cached);
110062
- }
110063
- const existing = this.inflightResult.get(key);
110064
- if (existing) {
110065
- return existing;
110066
- }
110067
- const computePromise = (async () => {
110068
- try {
110069
- return await compute();
110070
- } finally {
110071
- this.inflightResult.delete(key);
110072
- }
110073
- })();
110074
- this.inflightResult.set(key, computePromise);
110075
- const result = await computePromise;
110076
- if (result.success) {
110077
- this.set(key, result.value, ttl);
110078
- }
110079
- return result;
109822
+ getStats() {
109823
+ return {
109824
+ size: this.cache.size,
109825
+ maxSize: this.maxSize,
109826
+ ttlMs: this.ttlMs
109827
+ };
110080
109828
  }
110081
109829
  };
110082
109830
  var CacheManager = class {
110083
109831
  caches = /* @__PURE__ */ new Map();
110084
- globalConfig;
110085
- constructor(globalConfig = {}) {
110086
- this.globalConfig = globalConfig;
109832
+ debug;
109833
+ constructor(config = {}) {
109834
+ this.debug = config.debug || false;
110087
109835
  }
110088
109836
  /**
110089
- * Create or get a named cache
110090
- *
110091
- * @param name - Unique cache name
110092
- * @param config - Optional cache-specific configuration
110093
- * @returns LRU cache instance
109837
+ * Get or create a cache instance
110094
109838
  */
110095
109839
  getCache(name, config) {
110096
- const existingCache = this.caches.get(name);
110097
- if (existingCache) {
110098
- return existingCache;
109840
+ if (this.caches.has(name)) {
109841
+ return this.caches.get(name);
110099
109842
  }
110100
- const mergedConfig = {
110101
- ...this.globalConfig,
110102
- ...config,
110103
- name
110104
- };
110105
- const cache = new LRUCache(mergedConfig);
109843
+ const cache = new Cache(config);
110106
109844
  this.caches.set(name, cache);
109845
+ if (this.debug) {
109846
+ console.log(`[CacheManager] Created cache: ${name}`, config);
109847
+ }
110107
109848
  return cache;
110108
109849
  }
110109
109850
  /**
@@ -110118,11 +109859,11 @@ var CacheManager = class {
110118
109859
  * Clean expired entries from all caches
110119
109860
  */
110120
109861
  cleanAllExpired() {
110121
- let totalCleaned = 0;
109862
+ let total = 0;
110122
109863
  for (const cache of this.caches.values()) {
110123
- totalCleaned += cache.cleanExpired();
109864
+ total += cache.cleanExpired();
110124
109865
  }
110125
- return totalCleaned;
109866
+ return total;
110126
109867
  }
110127
109868
  /**
110128
109869
  * Get statistics for all caches
@@ -110135,16 +109876,11 @@ var CacheManager = class {
110135
109876
  return stats;
110136
109877
  }
110137
109878
  /**
110138
- * Get list of all cache names
109879
+ * Destroy cache manager
110139
109880
  */
110140
- getCacheNames() {
110141
- return Array.from(this.caches.keys());
110142
- }
110143
- /**
110144
- * Delete a named cache
110145
- */
110146
- deleteCache(name) {
110147
- return this.caches.delete(name);
109881
+ destroy() {
109882
+ this.clearAll();
109883
+ this.caches.clear();
110148
109884
  }
110149
109885
  };
110150
109886
  function createCacheManager(config) {
@@ -124713,7 +124449,7 @@ export {
124713
124449
  ErrorSeverity,
124714
124450
  EventHelpers,
124715
124451
  LOCALHOST_CONTRACTS,
124716
- LRUCache,
124452
+ Cache as LRUCache,
124717
124453
  LoanCreator,
124718
124454
  LoanQuery,
124719
124455
  LoanStatus,
@@ -185,11 +185,19 @@ export declare class BitcoinOperations {
185
185
  /**
186
186
  * Get balance cache statistics
187
187
  */
188
- getBalanceCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
188
+ getBalanceCacheStats(): {
189
+ size: number;
190
+ maxSize: number;
191
+ ttlMs: number;
192
+ } | null;
189
193
  /**
190
194
  * Get address cache statistics
191
195
  */
192
- getAddressCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
196
+ getAddressCacheStats(): {
197
+ size: number;
198
+ maxSize: number;
199
+ ttlMs: number;
200
+ } | null;
193
201
  /**
194
202
  * Get current network configuration
195
203
  */