@gvnrdao/dh-sdk 0.0.288 → 0.0.289

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.
Files changed (76) hide show
  1. package/browser/dist/833.browser.js +1 -1
  2. package/browser/dist/browser.js +1 -1
  3. package/browser/dist/browser.js.LICENSE.txt +5 -10
  4. package/dist/constants/chunks/contract-abis.d.ts +20 -0
  5. package/dist/constants/chunks/deployment-addresses.d.ts +79 -0
  6. package/dist/constants/chunks/encrypted-provider-params.d.ts +21 -0
  7. package/dist/constants/chunks/environment.browser.d.ts +44 -0
  8. package/dist/constants/chunks/environment.d.ts +57 -0
  9. package/dist/constants/chunks/network-configs.d.ts +72 -0
  10. package/dist/constants/chunks/sdk-config.d.ts +33 -0
  11. package/dist/constants/chunks/sdk-limits.d.ts +66 -0
  12. package/dist/constants/index.d.ts +15 -0
  13. package/dist/contracts/typechain-contracts/common.d.ts +50 -0
  14. package/dist/contracts/typechain-contracts/factories/src/psm/SimplePSMV2__factory.d.ts +1996 -0
  15. package/dist/contracts/typechain-contracts/src/psm/SimplePSMV2.d.ts +1198 -0
  16. package/dist/deployments.js +21 -45
  17. package/dist/deployments.mjs +21 -45
  18. package/dist/graphs/client.d.ts +22 -0
  19. package/dist/graphs/diamond-hands.d.ts +259 -0
  20. package/dist/index.d.ts +56 -0
  21. package/dist/index.js +1123 -628
  22. package/dist/index.mjs +1123 -628
  23. package/dist/interfaces/chunks/btc.i.d.ts +36 -0
  24. package/dist/interfaces/chunks/config.i.d.ts +270 -0
  25. package/dist/interfaces/chunks/contract-interactions.i.d.ts +64 -0
  26. package/dist/interfaces/chunks/contract-types.i.d.ts +171 -0
  27. package/dist/interfaces/chunks/lit-actions-results.i.d.ts +165 -0
  28. package/dist/interfaces/chunks/lit-actions.i.d.ts +98 -0
  29. package/dist/interfaces/chunks/loan-operations.i.d.ts +331 -0
  30. package/dist/interfaces/chunks/pkp-integration.i.d.ts +87 -0
  31. package/dist/interfaces/chunks/position-query.i.d.ts +76 -0
  32. package/dist/interfaces/chunks/requests.i.d.ts +55 -0
  33. package/dist/interfaces/chunks/ucd-minting.i.d.ts +34 -0
  34. package/dist/interfaces/chunks/utility.i.d.ts +64 -0
  35. package/dist/interfaces/index.d.ts +17 -0
  36. package/dist/modules/bitcoin/bitcoin-operations.module.d.ts +254 -0
  37. package/dist/modules/cache/cache-manager.module.d.ts +259 -0
  38. package/dist/modules/contract/contract-manager.module.d.ts +152 -0
  39. package/dist/modules/diamond-hands-sdk.d.ts +969 -0
  40. package/dist/modules/loan/loan-creator.module.d.ts +132 -0
  41. package/dist/modules/loan/loan-query.module.d.ts +204 -0
  42. package/dist/modules/mock/mock-token-manager.module.d.ts +83 -0
  43. package/dist/modules/pkp/pkp-manager.module.d.ts +136 -0
  44. package/dist/modules/withdrawal-address/withdrawal-address.module.d.ts +78 -0
  45. package/dist/protocol/protocol-pause.d.ts +19 -0
  46. package/dist/server.d.ts +17 -0
  47. package/dist/types/authorization-params.d.ts +160 -0
  48. package/dist/types/branded/domain-values.d.ts +138 -0
  49. package/dist/types/branded/ids.d.ts +23 -0
  50. package/dist/types/event-types.d.ts +261 -0
  51. package/dist/types/graph-dtos.d.ts +228 -0
  52. package/dist/types/loanStatus.d.ts +10 -0
  53. package/dist/types/protocol-event-types.d.ts +99 -0
  54. package/dist/types/result.d.ts +120 -0
  55. package/dist/utils/address-conversion.utils.d.ts +51 -0
  56. package/dist/utils/bitcoin-address-cache.utils.d.ts +87 -0
  57. package/dist/utils/bitcoin-provider.utils.d.ts +84 -0
  58. package/dist/utils/btc-withdrawal-message.d.ts +60 -0
  59. package/dist/utils/chunks/bitcoin-utils.d.ts +85 -0
  60. package/dist/utils/chunks/eip1559-broadcast.utils.d.ts +33 -0
  61. package/dist/utils/eip712-login.d.ts +34 -0
  62. package/dist/utils/error-handler.d.ts +106 -0
  63. package/dist/utils/ethers-interop.utils.d.ts +146 -0
  64. package/dist/utils/extend-authorization.utils.d.ts +61 -0
  65. package/dist/utils/lit-signature.utils.d.ts +6 -0
  66. package/dist/utils/logger.utils.d.ts +142 -0
  67. package/dist/utils/mint-authorization.utils.d.ts +248 -0
  68. package/dist/utils/position-delegate.utils.d.ts +41 -0
  69. package/dist/utils/quantum-timing.d.ts +75 -0
  70. package/dist/utils/server-session.d.ts +50 -0
  71. package/dist/utils/service-endpoint-policy.d.ts +16 -0
  72. package/dist/utils/signature-tempering.utils.d.ts +34 -0
  73. package/dist/utils/telegram-messaging.utils.d.ts +188 -0
  74. package/package.json +1 -1
  75. package/browser/dist/397.browser.js +0 -2
  76. package/browser/dist/397.browser.js.LICENSE.txt +0 -1
@@ -0,0 +1,259 @@
1
+ /**
2
+ * Generic Cache Manager Module
3
+ *
4
+ * Provides a type-safe, generic LRU cache with TTL support.
5
+ * Can be used for any data type (Bitcoin balances, addresses, query results, etc.)
6
+ *
7
+ * Features:
8
+ * - Generic type support
9
+ * - TTL-based expiration
10
+ * - LRU eviction policy
11
+ * - Hit/miss statistics
12
+ * - Memory-efficient
13
+ * - Thread-safe operations
14
+ */
15
+ import { Result } from '../../types/result';
16
+ import { SDKError } from '../../utils/error-handler';
17
+ /**
18
+ * Cache entry with metadata
19
+ */
20
+ interface CacheEntry<T> {
21
+ /** Cached value */
22
+ value: T;
23
+ /** Unix timestamp when entry was created (ms) */
24
+ timestamp: number;
25
+ /** Number of times this entry was accessed */
26
+ hits: number;
27
+ /** Unix timestamp of last access (ms) */
28
+ lastAccessed: number;
29
+ }
30
+ /**
31
+ * Cache statistics
32
+ */
33
+ export interface CacheStats {
34
+ /** Current number of entries in cache */
35
+ size: number;
36
+ /** Total cache hits */
37
+ hits: number;
38
+ /** Total cache misses */
39
+ misses: number;
40
+ /** Total evictions performed */
41
+ evictions: number;
42
+ /** Timestamp of oldest entry (ms) */
43
+ oldestEntry: number;
44
+ /** Timestamp of newest entry (ms) */
45
+ newestEntry: number;
46
+ /** Hit rate as percentage (0-100) */
47
+ hitRate: number;
48
+ }
49
+ /**
50
+ * Cache configuration
51
+ */
52
+ export interface CacheConfig {
53
+ /** Maximum number of entries (default: 1000) */
54
+ maxSize?: number;
55
+ /** Time-to-live in milliseconds (default: 60000 = 1 minute) */
56
+ ttlMs?: number;
57
+ /** Enable debug logging (default: false) */
58
+ debug?: boolean;
59
+ /** Cache name for logging (default: 'Cache') */
60
+ name?: string;
61
+ }
62
+ /**
63
+ * Generic LRU Cache with TTL support
64
+ *
65
+ * @template K - Key type (usually string)
66
+ * @template V - Value type
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * // Create a cache for Bitcoin balances
71
+ * const balanceCache = new LRUCache<string, BitcoinBalance>({
72
+ * maxSize: 500,
73
+ * ttlMs: 60000,
74
+ * name: 'BitcoinBalance'
75
+ * });
76
+ *
77
+ * // Set value
78
+ * balanceCache.set('bc1q...', { balance: Satoshis(50000000n) });
79
+ *
80
+ * // Get value
81
+ * const balance = balanceCache.get('bc1q...');
82
+ * if (balance) {
83
+ * console.log('Cached balance:', balance.balance);
84
+ * }
85
+ * ```
86
+ */
87
+ export declare class LRUCache<K, V> {
88
+ private cache;
89
+ /**
90
+ * Audit M-J: singleflight registry for `getOrCompute` / `getOrComputeResult`.
91
+ * Concurrent cache-miss callers for the same key share one inflight promise
92
+ * instead of each running `compute()` independently — important when the
93
+ * compute spends a paid LIT capacity credit or hits a rate-limited upstream.
94
+ */
95
+ private inflight;
96
+ private inflightResult;
97
+ private readonly maxSize;
98
+ private readonly ttlMs;
99
+ private readonly debug;
100
+ private readonly name;
101
+ private stats;
102
+ constructor(config?: CacheConfig);
103
+ /**
104
+ * Get value from cache
105
+ *
106
+ * Returns null if:
107
+ * - Key not found
108
+ * - Entry has expired
109
+ *
110
+ * @param key - Cache key
111
+ * @returns Cached value or null
112
+ */
113
+ get(key: K): V | null;
114
+ /**
115
+ * Get value from cache with Result wrapper
116
+ *
117
+ * Useful when you want to distinguish between "not found" and "expired"
118
+ */
119
+ getResult(key: K): Result<V, SDKError>;
120
+ /**
121
+ * Set value in cache
122
+ *
123
+ * If cache is full, evicts the least recently used entry
124
+ *
125
+ * @param key - Cache key
126
+ * @param value - Value to cache
127
+ * @param ttl - Optional custom TTL for this entry (ms)
128
+ */
129
+ set(key: K, value: V, ttl?: number): void;
130
+ /**
131
+ * Set value in cache with Result wrapper
132
+ */
133
+ setResult(key: K, value: V, ttl?: number): Result<void, SDKError>;
134
+ /**
135
+ * Check if key exists in cache (without affecting stats)
136
+ */
137
+ has(key: K): boolean;
138
+ /**
139
+ * Delete specific key from cache
140
+ */
141
+ delete(key: K): boolean;
142
+ /**
143
+ * Clear entire cache
144
+ */
145
+ clear(): void;
146
+ /**
147
+ * Get current cache size
148
+ */
149
+ size(): number;
150
+ /**
151
+ * Get cache statistics
152
+ */
153
+ getStats(): CacheStats;
154
+ /**
155
+ * Get hit rate percentage
156
+ */
157
+ getHitRate(): number;
158
+ /**
159
+ * Get all cached keys (for debugging)
160
+ */
161
+ getKeys(): K[];
162
+ /**
163
+ * Get all cached values (for debugging)
164
+ */
165
+ getValues(): V[];
166
+ /**
167
+ * Get all cache entries with metadata (for debugging)
168
+ */
169
+ getEntries(): Array<{
170
+ key: K;
171
+ value: V;
172
+ metadata: Omit<CacheEntry<V>, 'value'>;
173
+ }>;
174
+ /**
175
+ * Clean up expired entries
176
+ *
177
+ * Useful for periodic maintenance
178
+ *
179
+ * @returns Number of entries cleaned
180
+ */
181
+ cleanExpired(): number;
182
+ /**
183
+ * Check if cache entry is expired
184
+ */
185
+ private isExpired;
186
+ /**
187
+ * Evict least recently used entry
188
+ */
189
+ private evictLRU;
190
+ /**
191
+ * Get or compute value
192
+ *
193
+ * If key exists in cache, returns cached value.
194
+ * Otherwise, computes value using provided function and caches it.
195
+ *
196
+ * @param key - Cache key
197
+ * @param compute - Function to compute value if not in cache
198
+ * @param ttl - Optional custom TTL for this entry
199
+ * @returns Cached or computed value
200
+ */
201
+ getOrCompute(key: K, compute: () => Promise<V>, ttl?: number): Promise<V>;
202
+ /**
203
+ * Get or compute value with Result wrapper
204
+ */
205
+ getOrComputeResult(key: K, compute: () => Promise<Result<V, SDKError>>, ttl?: number): Promise<Result<V, SDKError>>;
206
+ }
207
+ /**
208
+ * Generic cache interface for type safety
209
+ */
210
+ export interface Cache<T> {
211
+ get(key: string): T | null | undefined;
212
+ set(key: string, value: T): void;
213
+ delete(key: string): boolean;
214
+ clear(): void;
215
+ has(key: string): boolean;
216
+ size(): number;
217
+ getStats(): CacheStats;
218
+ }
219
+ /**
220
+ * Cache Manager - Factory for creating specialized caches
221
+ */
222
+ export declare class CacheManager {
223
+ private caches;
224
+ private readonly globalConfig;
225
+ constructor(globalConfig?: CacheConfig);
226
+ /**
227
+ * Create or get a named cache
228
+ *
229
+ * @param name - Unique cache name
230
+ * @param config - Optional cache-specific configuration
231
+ * @returns LRU cache instance
232
+ */
233
+ getCache<K, V>(name: string, config?: CacheConfig): LRUCache<K, V>;
234
+ /**
235
+ * Clear all caches
236
+ */
237
+ clearAll(): void;
238
+ /**
239
+ * Clean expired entries from all caches
240
+ */
241
+ cleanAllExpired(): number;
242
+ /**
243
+ * Get statistics for all caches
244
+ */
245
+ getAllStats(): Record<string, CacheStats>;
246
+ /**
247
+ * Get list of all cache names
248
+ */
249
+ getCacheNames(): string[];
250
+ /**
251
+ * Delete a named cache
252
+ */
253
+ deleteCache(name: string): boolean;
254
+ }
255
+ /**
256
+ * Factory function to create a CacheManager instance
257
+ */
258
+ export declare function createCacheManager(config?: CacheConfig): CacheManager;
259
+ export {};
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Contract Manager Module
3
+ *
4
+ * Responsible for:
5
+ * - Managing contract instances and their lifecycle
6
+ * - Providing typed contract interfaces
7
+ * - Handling contract address resolution
8
+ * - Managing provider/signer connections
9
+ *
10
+ * This module centralizes all contract interaction setup and provides
11
+ * a clean interface for other modules to access contracts.
12
+ */
13
+ import { Contract, type Provider, type Signer } from "ethers";
14
+ import type { ContractAddresses } from "../../interfaces/chunks/config.i";
15
+ import { type DeploymentContracts } from "../../constants/chunks/deployment-addresses";
16
+ import { Result } from "../../types/result";
17
+ import { SDKError } from "../../utils/error-handler";
18
+ import type { PositionManager, ILoanOperationsManager, IUCDController, IPriceFeedConsumer, ITermManager, CircuitBreakerModule, ILiquidationManager } from "../../interfaces/chunks/contract-types.i";
19
+ /**
20
+ * Type alias for ethers v6 provider (used throughout SDK)
21
+ */
22
+ export type { Provider };
23
+ /**
24
+ * Type alias for ethers v6 signer
25
+ */
26
+ export type { Signer };
27
+ /**
28
+ * Type alias for contract runner (provider or signer)
29
+ */
30
+ export type ContractRunner = Provider | Signer;
31
+ /**
32
+ * Configuration for Contract Manager
33
+ */
34
+ export interface ContractManagerConfig {
35
+ /** Ethers v5 provider for reading blockchain data */
36
+ provider: Provider;
37
+ /** Ethers v5 signer for writing transactions (optional) */
38
+ signer?: Signer;
39
+ /** Contract addresses for the target network */
40
+ contractAddresses: ContractAddresses;
41
+ /** SDK mode: 'service' or 'standalone' */
42
+ mode?: "service" | "standalone";
43
+ /** Enable debug logging */
44
+ debug?: boolean;
45
+ /** Network name (e.g. "sepolia", "localhost") for deployment address lookup */
46
+ networkName?: string;
47
+ }
48
+ /**
49
+ * Managed contract instances with proper typing
50
+ */
51
+ export interface ManagedContracts {
52
+ positionManager: PositionManager;
53
+ loanOperationsManager: ILoanOperationsManager;
54
+ ucdController: IUCDController;
55
+ priceFeed: IPriceFeedConsumer;
56
+ termManager: ITermManager;
57
+ circuitBreaker: CircuitBreakerModule;
58
+ liquidationManager: ILiquidationManager;
59
+ /** Per-wallet approved-withdrawal-address allowlist. Untyped ethers Contract — methods accessed via WithdrawalAddressModule. */
60
+ bitcoinWithdrawalAddressRegistry: Contract;
61
+ }
62
+ /**
63
+ * Contract Manager Module
64
+ *
65
+ * Centralized contract instance management with proper typing
66
+ */
67
+ export declare class ContractManager {
68
+ private readonly config;
69
+ private contracts;
70
+ constructor(config: ContractManagerConfig);
71
+ /**
72
+ * Initialize all contract instances
73
+ *
74
+ * This is called lazily on first access to any contract
75
+ */
76
+ private initializeContracts;
77
+ /**
78
+ * Validate that all required contract addresses are present and valid
79
+ */
80
+ private validateContractAddresses;
81
+ /**
82
+ * Get all managed contract instances
83
+ */
84
+ getContracts(): Result<ManagedContracts, SDKError>;
85
+ /**
86
+ * Get Position Manager contract
87
+ */
88
+ getPositionManager(): Result<PositionManager, SDKError>;
89
+ /**
90
+ * Get Loan Operations Manager contract
91
+ */
92
+ getLoanOperationsManager(): Result<ILoanOperationsManager, SDKError>;
93
+ /**
94
+ * Get UCD Controller contract
95
+ */
96
+ getUCDController(): Result<IUCDController, SDKError>;
97
+ /**
98
+ * Get Price Feed contract
99
+ */
100
+ getPriceFeed(): Result<IPriceFeedConsumer, SDKError>;
101
+ /**
102
+ * Get Term Manager contract
103
+ */
104
+ getTermManager(): Result<ITermManager, SDKError>;
105
+ /**
106
+ * Get Circuit Breaker contract
107
+ */
108
+ getCircuitBreaker(): Result<CircuitBreakerModule, SDKError>;
109
+ /**
110
+ * Get Liquidation Manager contract
111
+ */
112
+ getLiquidationManager(): Result<ILiquidationManager, SDKError>;
113
+ /**
114
+ * Get the BitcoinWithdrawalAddressRegistry contract (per-wallet approved-address allowlist).
115
+ */
116
+ getBitcoinWithdrawalAddressRegistry(): Result<Contract, SDKError>;
117
+ /**
118
+ * Get the provider instance
119
+ */
120
+ getProvider(): Provider;
121
+ /**
122
+ * Get the signer instance (if available)
123
+ */
124
+ getSigner(): Result<Signer, SDKError>;
125
+ /**
126
+ * Check if a signer is available for write operations
127
+ */
128
+ hasSigner(): boolean;
129
+ /**
130
+ * Get contract addresses
131
+ */
132
+ getContractAddresses(): ContractAddresses;
133
+ /**
134
+ * Get the full deployment map for the configured network.
135
+ * Returns all deployed contracts (including admin-surface ones not needed at runtime),
136
+ * keyed by PascalCase contract name matching the deployment JSON.
137
+ * Returns null if the network name is unknown.
138
+ */
139
+ getDeploymentAddresses(): DeploymentContracts | null;
140
+ /**
141
+ * Get the network chain ID from the provider
142
+ */
143
+ getChainId(): Promise<Result<number, SDKError>>;
144
+ /**
145
+ * Verify that the provider is connected and responsive
146
+ */
147
+ verifyConnection(): Promise<Result<boolean, SDKError>>;
148
+ }
149
+ /**
150
+ * Factory function to create a ContractManager instance
151
+ */
152
+ export declare function createContractManager(config: ContractManagerConfig): Result<ContractManager, SDKError>;