@gvnrdao/dh-sdk 0.0.157 → 0.0.158

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.js CHANGED
@@ -12745,47 +12745,45 @@ var init_deployment_addresses = __esm({
12745
12745
  };
12746
12746
  LOCALHOST_DEPLOYMENT = {
12747
12747
  network: "localhost",
12748
- chainId: 31337,
12749
- timestamp: "2026-02-16T15:23:50.854Z",
12750
- deployer: "",
12748
+ chainId: 1337,
12749
+ timestamp: "2026-02-09T10:20:16.663Z",
12750
+ deployer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
12751
12751
  contracts: {
12752
- UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
12752
+ UpgradeValidator: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
12753
12753
  UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
12754
12754
  UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
12755
- PriceFeedConsumer: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
12756
- UCDMintingRewards: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
12757
- PositionManagerCoreModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
12758
- TermManagerModule: "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
12759
- LoanOperationsManagerModule: "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
12760
- CollateralManagerModule: "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
12761
- LiquidationManagerModule: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
12762
- CircuitBreakerModule: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
12763
- CommunityManagerModule: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
12764
- AdminModule: "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
12765
- PositionManagerViews: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
12766
- PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
12767
- OperationAuthorizationRegistry: "0x9d4454B023096f34B160D6B654540c56A1F81688",
12768
- PKPValidation: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
12755
+ PriceFeedConsumer: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
12756
+ UCDMintingRewards: "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
12757
+ PositionManagerCoreModule: "0x9A676e781A523b5d0C0e43731313A708CB607508",
12758
+ TermManagerModule: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
12759
+ LoanOperationsManagerModule: "0x59b670e9fA9D0A427751Af201D676719a970857b",
12760
+ CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
12761
+ LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
12762
+ CircuitBreakerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
12763
+ CommunityManagerModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
12764
+ AdminModule: "0x67d269191c92Caf3cD7723F116c85e6E9bf55933",
12765
+ PositionManagerViews: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
12766
+ PositionManager: "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
12767
+ OperationAuthorizationRegistry: "0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf"
12769
12768
  }
12770
12769
  };
12771
12770
  LOCALHOST_CONTRACTS = {
12772
- UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
12771
+ UpgradeValidator: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
12773
12772
  UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
12774
12773
  UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
12775
- PriceFeedConsumer: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
12776
- UCDMintingRewards: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
12777
- PositionManagerCoreModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
12778
- TermManagerModule: "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
12779
- LoanOperationsManagerModule: "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
12780
- CollateralManagerModule: "0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f",
12781
- LiquidationManagerModule: "0x7a2088a1bFc9d81c55368AE168C2C02570cB814F",
12782
- CircuitBreakerModule: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
12783
- CommunityManagerModule: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
12784
- AdminModule: "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
12785
- PositionManagerViews: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
12786
- PositionManager: "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
12787
- OperationAuthorizationRegistry: "0x9d4454B023096f34B160D6B654540c56A1F81688",
12788
- PKPValidation: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029"
12774
+ PriceFeedConsumer: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
12775
+ UCDMintingRewards: "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
12776
+ PositionManagerCoreModule: "0x9A676e781A523b5d0C0e43731313A708CB607508",
12777
+ TermManagerModule: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
12778
+ LoanOperationsManagerModule: "0x59b670e9fA9D0A427751Af201D676719a970857b",
12779
+ CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
12780
+ LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
12781
+ CircuitBreakerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
12782
+ CommunityManagerModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
12783
+ AdminModule: "0x67d269191c92Caf3cD7723F116c85e6E9bf55933",
12784
+ PositionManagerViews: "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c",
12785
+ PositionManager: "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
12786
+ OperationAuthorizationRegistry: "0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf"
12789
12787
  };
12790
12788
  ALL_DEPLOYMENTS = {
12791
12789
  sepolia: SEPOLIA_DEPLOYMENT,
@@ -13121,7 +13119,7 @@ __export(src_exports, {
13121
13119
  ErrorCategory: () => ErrorCategory,
13122
13120
  ErrorSeverity: () => ErrorSeverity,
13123
13121
  EventHelpers: () => EventHelpers,
13124
- LRUCache: () => Cache,
13122
+ LRUCache: () => LRUCache,
13125
13123
  LoanCreator: () => LoanCreator,
13126
13124
  LoanQuery: () => LoanQuery,
13127
13125
  LoanStatus: () => LoanStatus,
@@ -29632,7 +29630,8 @@ var PRICE_FEED_ABI = [
29632
29630
  "function getLatestPrice() external view returns (int256)"
29633
29631
  ];
29634
29632
  var TERM_MANAGER_ABI = [
29635
- "function getAvailableTerms() external view returns (uint256[] memory termIds, uint256[] memory durationDays, uint256[] memory interestRateBps)"
29633
+ "function getAvailableTerms() external view returns (uint256[] memory termIds, uint256[] memory durationDays, uint256[] memory interestRateBps)",
29634
+ "function getValidTermsWithFees() external view returns (uint256[] terms, uint88[] originationFees, uint88[] extensionFees)"
29636
29635
  ];
29637
29636
  var CIRCUIT_BREAKER_ABI = [
29638
29637
  "function isPaused() external view returns (bool)"
@@ -29944,106 +29943,333 @@ function createContractManager(config) {
29944
29943
  }
29945
29944
 
29946
29945
  // src/modules/cache/cache-manager.module.ts
29947
- var Cache = class {
29948
- cache = /* @__PURE__ */ new Map();
29946
+ var LRUCache = class {
29947
+ cache;
29949
29948
  maxSize;
29950
29949
  ttlMs;
29951
- constructor(config) {
29952
- this.maxSize = config.maxSize;
29953
- this.ttlMs = config.ttlMs;
29950
+ debug;
29951
+ name;
29952
+ // Statistics
29953
+ stats = {
29954
+ hits: 0,
29955
+ misses: 0,
29956
+ evictions: 0
29957
+ };
29958
+ constructor(config = {}) {
29959
+ this.cache = /* @__PURE__ */ new Map();
29960
+ this.maxSize = config.maxSize || 1e3;
29961
+ this.ttlMs = config.ttlMs || 6e4;
29962
+ this.debug = config.debug || false;
29963
+ this.name = config.name || "Cache";
29964
+ if (this.debug) {
29965
+ console.log(
29966
+ `\u{1F4BE} [${this.name}] Initialized: maxSize=${this.maxSize}, ttl=${this.ttlMs}ms`
29967
+ );
29968
+ }
29954
29969
  }
29955
29970
  /**
29956
29971
  * Get value from cache
29972
+ *
29973
+ * Returns null if:
29974
+ * - Key not found
29975
+ * - Entry has expired
29976
+ *
29977
+ * @param key - Cache key
29978
+ * @returns Cached value or null
29957
29979
  */
29958
29980
  get(key2) {
29959
29981
  const entry = this.cache.get(key2);
29960
29982
  if (!entry) {
29961
- return void 0;
29983
+ this.stats.misses++;
29984
+ if (this.debug) {
29985
+ console.log(`\u274C [${this.name}] Cache MISS: ${String(key2)}`);
29986
+ }
29987
+ return null;
29962
29988
  }
29963
- const now2 = Date.now();
29964
- if (now2 - entry.timestamp > entry.ttl) {
29989
+ if (this.isExpired(entry)) {
29965
29990
  this.cache.delete(key2);
29966
- return void 0;
29991
+ this.stats.misses++;
29992
+ if (this.debug) {
29993
+ const age = Date.now() - entry.timestamp;
29994
+ console.log(`\u23F0 [${this.name}] Cache EXPIRED: ${String(key2)} (age: ${age}ms)`);
29995
+ }
29996
+ return null;
29997
+ }
29998
+ entry.hits++;
29999
+ entry.lastAccessed = Date.now();
30000
+ this.cache.set(key2, entry);
30001
+ this.stats.hits++;
30002
+ if (this.debug) {
30003
+ const age = Date.now() - entry.timestamp;
30004
+ console.log(
30005
+ `\u2705 [${this.name}] Cache HIT: ${String(key2)} (age: ${age}ms, hits: ${entry.hits})`
30006
+ );
29967
30007
  }
29968
30008
  return entry.value;
29969
30009
  }
30010
+ /**
30011
+ * Get value from cache with Result wrapper
30012
+ *
30013
+ * Useful when you want to distinguish between "not found" and "expired"
30014
+ */
30015
+ getResult(key2) {
30016
+ const value = this.get(key2);
30017
+ if (value === null) {
30018
+ return failure(
30019
+ new SDKError({
30020
+ message: `Cache miss for key: ${String(key2)}`,
30021
+ category: "CACHE" /* CACHE */,
30022
+ severity: "LOW" /* LOW */,
30023
+ originalError: new Error("Cache miss")
30024
+ })
30025
+ );
30026
+ }
30027
+ return success(value);
30028
+ }
29970
30029
  /**
29971
30030
  * Set value in cache
30031
+ *
30032
+ * If cache is full, evicts the least recently used entry
30033
+ *
30034
+ * @param key - Cache key
30035
+ * @param value - Value to cache
30036
+ * @param ttl - Optional custom TTL for this entry (ms)
29972
30037
  */
29973
30038
  set(key2, value, ttl) {
29974
30039
  if (this.cache.size >= this.maxSize && !this.cache.has(key2)) {
29975
- const firstKey = this.cache.keys().next().value;
29976
- if (firstKey) {
29977
- this.cache.delete(firstKey);
29978
- }
30040
+ this.evictLRU();
29979
30041
  }
29980
- this.cache.set(key2, {
30042
+ const entry = {
29981
30043
  value,
29982
30044
  timestamp: Date.now(),
29983
- ttl: ttl || this.ttlMs
29984
- });
30045
+ hits: 0,
30046
+ lastAccessed: Date.now()
30047
+ };
30048
+ this.cache.set(key2, entry);
30049
+ if (this.debug) {
30050
+ const effectiveTtl = ttl || this.ttlMs;
30051
+ console.log(
30052
+ `\u{1F4BE} [${this.name}] Cache SET: ${String(key2)} (ttl: ${effectiveTtl}ms, size: ${this.cache.size}/${this.maxSize})`
30053
+ );
30054
+ }
29985
30055
  }
29986
30056
  /**
29987
- * Check if key exists in cache
30057
+ * Set value in cache with Result wrapper
30058
+ */
30059
+ setResult(key2, value, ttl) {
30060
+ try {
30061
+ this.set(key2, value, ttl);
30062
+ return success(void 0);
30063
+ } catch (error) {
30064
+ return failure(
30065
+ new SDKError({
30066
+ message: `Failed to set cache value for key: ${String(key2)}`,
30067
+ category: "CACHE" /* CACHE */,
30068
+ severity: "MEDIUM" /* MEDIUM */,
30069
+ originalError: error instanceof Error ? error : new Error(String(error))
30070
+ })
30071
+ );
30072
+ }
30073
+ }
30074
+ /**
30075
+ * Check if key exists in cache (without affecting stats)
29988
30076
  */
29989
30077
  has(key2) {
29990
- return this.get(key2) !== void 0;
30078
+ const entry = this.cache.get(key2);
30079
+ return entry !== void 0 && !this.isExpired(entry);
29991
30080
  }
29992
30081
  /**
29993
- * Delete key from cache
30082
+ * Delete specific key from cache
29994
30083
  */
29995
30084
  delete(key2) {
29996
- return this.cache.delete(key2);
30085
+ const deleted = this.cache.delete(key2);
30086
+ if (deleted && this.debug) {
30087
+ console.log(`\u{1F5D1}\uFE0F [${this.name}] Cache DELETE: ${String(key2)}`);
30088
+ }
30089
+ return deleted;
29997
30090
  }
29998
30091
  /**
29999
- * Clear all cache entries
30092
+ * Clear entire cache
30000
30093
  */
30001
30094
  clear() {
30095
+ const previousSize = this.cache.size;
30002
30096
  this.cache.clear();
30097
+ this.stats = {
30098
+ hits: 0,
30099
+ misses: 0,
30100
+ evictions: 0
30101
+ };
30102
+ if (this.debug) {
30103
+ console.log(`\u{1F9F9} [${this.name}] Cache CLEARED: removed ${previousSize} entries`);
30104
+ }
30105
+ }
30106
+ /**
30107
+ * Get current cache size
30108
+ */
30109
+ size() {
30110
+ return this.cache.size;
30003
30111
  }
30004
30112
  /**
30005
- * Clean expired entries
30113
+ * Get cache statistics
30114
+ */
30115
+ getStats() {
30116
+ const entries = Array.from(this.cache.values());
30117
+ const timestamps = entries.map((e) => e.timestamp);
30118
+ const total = this.stats.hits + this.stats.misses;
30119
+ const hitRate = total === 0 ? 0 : this.stats.hits / total * 100;
30120
+ return {
30121
+ size: this.cache.size,
30122
+ hits: this.stats.hits,
30123
+ misses: this.stats.misses,
30124
+ evictions: this.stats.evictions,
30125
+ oldestEntry: timestamps.length > 0 ? Math.min(...timestamps) : 0,
30126
+ newestEntry: timestamps.length > 0 ? Math.max(...timestamps) : 0,
30127
+ hitRate
30128
+ };
30129
+ }
30130
+ /**
30131
+ * Get hit rate percentage
30132
+ */
30133
+ getHitRate() {
30134
+ const total = this.stats.hits + this.stats.misses;
30135
+ return total === 0 ? 0 : this.stats.hits / total * 100;
30136
+ }
30137
+ /**
30138
+ * Get all cached keys (for debugging)
30139
+ */
30140
+ getKeys() {
30141
+ return Array.from(this.cache.keys());
30142
+ }
30143
+ /**
30144
+ * Get all cached values (for debugging)
30145
+ */
30146
+ getValues() {
30147
+ return Array.from(this.cache.values()).map((entry) => entry.value);
30148
+ }
30149
+ /**
30150
+ * Get all cache entries with metadata (for debugging)
30151
+ */
30152
+ getEntries() {
30153
+ return Array.from(this.cache.entries()).map(([key2, entry]) => ({
30154
+ key: key2,
30155
+ value: entry.value,
30156
+ metadata: {
30157
+ timestamp: entry.timestamp,
30158
+ hits: entry.hits,
30159
+ lastAccessed: entry.lastAccessed
30160
+ }
30161
+ }));
30162
+ }
30163
+ /**
30164
+ * Clean up expired entries
30165
+ *
30166
+ * Useful for periodic maintenance
30167
+ *
30168
+ * @returns Number of entries cleaned
30006
30169
  */
30007
30170
  cleanExpired() {
30008
30171
  const now2 = Date.now();
30009
- let cleaned = 0;
30172
+ let cleanedCount = 0;
30010
30173
  for (const [key2, entry] of this.cache.entries()) {
30011
- if (now2 - entry.timestamp > entry.ttl) {
30174
+ if (now2 - entry.timestamp > this.ttlMs) {
30012
30175
  this.cache.delete(key2);
30013
- cleaned++;
30176
+ cleanedCount++;
30014
30177
  }
30015
30178
  }
30016
- return cleaned;
30179
+ if (cleanedCount > 0 && this.debug) {
30180
+ console.log(`\u{1F9F9} [${this.name}] Cleaned ${cleanedCount} expired entries`);
30181
+ }
30182
+ return cleanedCount;
30017
30183
  }
30018
30184
  /**
30019
- * Get cache statistics
30185
+ * Check if cache entry is expired
30020
30186
  */
30021
- getStats() {
30022
- return {
30023
- size: this.cache.size,
30024
- maxSize: this.maxSize,
30025
- ttlMs: this.ttlMs
30026
- };
30187
+ isExpired(entry) {
30188
+ return Date.now() - entry.timestamp > this.ttlMs;
30189
+ }
30190
+ /**
30191
+ * Evict least recently used entry
30192
+ */
30193
+ evictLRU() {
30194
+ let oldestKey = null;
30195
+ let oldestAccess = Infinity;
30196
+ for (const [key2, entry] of this.cache.entries()) {
30197
+ if (entry.lastAccessed < oldestAccess) {
30198
+ oldestAccess = entry.lastAccessed;
30199
+ oldestKey = key2;
30200
+ }
30201
+ }
30202
+ if (oldestKey !== null) {
30203
+ this.cache.delete(oldestKey);
30204
+ this.stats.evictions++;
30205
+ if (this.debug) {
30206
+ const timeSinceAccess = Date.now() - oldestAccess;
30207
+ console.log(
30208
+ `\u267B\uFE0F [${this.name}] Cache EVICT (LRU): ${String(oldestKey)} (last accessed: ${timeSinceAccess}ms ago)`
30209
+ );
30210
+ }
30211
+ }
30212
+ }
30213
+ /**
30214
+ * Get or compute value
30215
+ *
30216
+ * If key exists in cache, returns cached value.
30217
+ * Otherwise, computes value using provided function and caches it.
30218
+ *
30219
+ * @param key - Cache key
30220
+ * @param compute - Function to compute value if not in cache
30221
+ * @param ttl - Optional custom TTL for this entry
30222
+ * @returns Cached or computed value
30223
+ */
30224
+ async getOrCompute(key2, compute, ttl) {
30225
+ const cached = this.get(key2);
30226
+ if (cached !== null) {
30227
+ return cached;
30228
+ }
30229
+ const value = await compute();
30230
+ this.set(key2, value, ttl);
30231
+ return value;
30232
+ }
30233
+ /**
30234
+ * Get or compute value with Result wrapper
30235
+ */
30236
+ async getOrComputeResult(key2, compute, ttl) {
30237
+ const cached = this.get(key2);
30238
+ if (cached !== null) {
30239
+ return success(cached);
30240
+ }
30241
+ const result = await compute();
30242
+ if (result.success) {
30243
+ this.set(key2, result.value, ttl);
30244
+ }
30245
+ return result;
30027
30246
  }
30028
30247
  };
30029
30248
  var CacheManager = class {
30030
30249
  caches = /* @__PURE__ */ new Map();
30031
- debug;
30032
- constructor(config = {}) {
30033
- this.debug = config.debug || false;
30250
+ globalConfig;
30251
+ constructor(globalConfig = {}) {
30252
+ this.globalConfig = globalConfig;
30034
30253
  }
30035
30254
  /**
30036
- * Get or create a cache instance
30255
+ * Create or get a named cache
30256
+ *
30257
+ * @param name - Unique cache name
30258
+ * @param config - Optional cache-specific configuration
30259
+ * @returns LRU cache instance
30037
30260
  */
30038
30261
  getCache(name, config) {
30039
- if (this.caches.has(name)) {
30040
- return this.caches.get(name);
30262
+ const existingCache = this.caches.get(name);
30263
+ if (existingCache) {
30264
+ return existingCache;
30041
30265
  }
30042
- const cache = new Cache(config);
30266
+ const mergedConfig = {
30267
+ ...this.globalConfig,
30268
+ ...config,
30269
+ name
30270
+ };
30271
+ const cache = new LRUCache(mergedConfig);
30043
30272
  this.caches.set(name, cache);
30044
- if (this.debug) {
30045
- console.log(`[CacheManager] Created cache: ${name}`, config);
30046
- }
30047
30273
  return cache;
30048
30274
  }
30049
30275
  /**
@@ -30058,11 +30284,11 @@ var CacheManager = class {
30058
30284
  * Clean expired entries from all caches
30059
30285
  */
30060
30286
  cleanAllExpired() {
30061
- let total = 0;
30287
+ let totalCleaned = 0;
30062
30288
  for (const cache of this.caches.values()) {
30063
- total += cache.cleanExpired();
30289
+ totalCleaned += cache.cleanExpired();
30064
30290
  }
30065
- return total;
30291
+ return totalCleaned;
30066
30292
  }
30067
30293
  /**
30068
30294
  * Get statistics for all caches
@@ -30075,11 +30301,16 @@ var CacheManager = class {
30075
30301
  return stats;
30076
30302
  }
30077
30303
  /**
30078
- * Destroy cache manager
30304
+ * Get list of all cache names
30079
30305
  */
30080
- destroy() {
30081
- this.clearAll();
30082
- this.caches.clear();
30306
+ getCacheNames() {
30307
+ return Array.from(this.caches.keys());
30308
+ }
30309
+ /**
30310
+ * Delete a named cache
30311
+ */
30312
+ deleteCache(name) {
30313
+ return this.caches.delete(name);
30083
30314
  }
30084
30315
  };
30085
30316
  function createCacheManager(config) {