@gvnrdao/dh-sdk 0.0.287 → 0.0.288

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/397.browser.js +2 -0
  2. package/browser/dist/397.browser.js.LICENSE.txt +1 -0
  3. package/browser/dist/833.browser.js +1 -1
  4. package/browser/dist/browser.js +1 -1
  5. package/browser/dist/browser.js.LICENSE.txt +10 -5
  6. package/dist/deployments.js +45 -21
  7. package/dist/deployments.mjs +45 -21
  8. package/dist/index.js +615 -1100
  9. package/dist/index.mjs +615 -1100
  10. package/package.json +1 -1
  11. package/dist/constants/chunks/contract-abis.d.ts +0 -20
  12. package/dist/constants/chunks/deployment-addresses.d.ts +0 -79
  13. package/dist/constants/chunks/encrypted-provider-params.d.ts +0 -21
  14. package/dist/constants/chunks/environment.browser.d.ts +0 -44
  15. package/dist/constants/chunks/environment.d.ts +0 -57
  16. package/dist/constants/chunks/network-configs.d.ts +0 -72
  17. package/dist/constants/chunks/sdk-config.d.ts +0 -33
  18. package/dist/constants/chunks/sdk-limits.d.ts +0 -66
  19. package/dist/constants/index.d.ts +0 -15
  20. package/dist/contracts/typechain-contracts/common.d.ts +0 -50
  21. package/dist/contracts/typechain-contracts/factories/src/psm/SimplePSMV2__factory.d.ts +0 -1996
  22. package/dist/contracts/typechain-contracts/src/psm/SimplePSMV2.d.ts +0 -1198
  23. package/dist/graphs/client.d.ts +0 -22
  24. package/dist/graphs/diamond-hands.d.ts +0 -259
  25. package/dist/index.d.ts +0 -56
  26. package/dist/interfaces/chunks/btc.i.d.ts +0 -36
  27. package/dist/interfaces/chunks/config.i.d.ts +0 -270
  28. package/dist/interfaces/chunks/contract-interactions.i.d.ts +0 -64
  29. package/dist/interfaces/chunks/contract-types.i.d.ts +0 -171
  30. package/dist/interfaces/chunks/lit-actions-results.i.d.ts +0 -165
  31. package/dist/interfaces/chunks/lit-actions.i.d.ts +0 -98
  32. package/dist/interfaces/chunks/loan-operations.i.d.ts +0 -331
  33. package/dist/interfaces/chunks/pkp-integration.i.d.ts +0 -87
  34. package/dist/interfaces/chunks/position-query.i.d.ts +0 -76
  35. package/dist/interfaces/chunks/requests.i.d.ts +0 -55
  36. package/dist/interfaces/chunks/ucd-minting.i.d.ts +0 -34
  37. package/dist/interfaces/chunks/utility.i.d.ts +0 -64
  38. package/dist/interfaces/index.d.ts +0 -17
  39. package/dist/modules/bitcoin/bitcoin-operations.module.d.ts +0 -254
  40. package/dist/modules/cache/cache-manager.module.d.ts +0 -259
  41. package/dist/modules/contract/contract-manager.module.d.ts +0 -152
  42. package/dist/modules/diamond-hands-sdk.d.ts +0 -969
  43. package/dist/modules/loan/loan-creator.module.d.ts +0 -132
  44. package/dist/modules/loan/loan-query.module.d.ts +0 -204
  45. package/dist/modules/mock/mock-token-manager.module.d.ts +0 -83
  46. package/dist/modules/pkp/pkp-manager.module.d.ts +0 -136
  47. package/dist/modules/withdrawal-address/withdrawal-address.module.d.ts +0 -78
  48. package/dist/protocol/protocol-pause.d.ts +0 -19
  49. package/dist/server.d.ts +0 -17
  50. package/dist/types/authorization-params.d.ts +0 -160
  51. package/dist/types/branded/domain-values.d.ts +0 -138
  52. package/dist/types/branded/ids.d.ts +0 -23
  53. package/dist/types/event-types.d.ts +0 -261
  54. package/dist/types/graph-dtos.d.ts +0 -228
  55. package/dist/types/loanStatus.d.ts +0 -10
  56. package/dist/types/protocol-event-types.d.ts +0 -99
  57. package/dist/types/result.d.ts +0 -120
  58. package/dist/utils/address-conversion.utils.d.ts +0 -51
  59. package/dist/utils/bitcoin-address-cache.utils.d.ts +0 -87
  60. package/dist/utils/bitcoin-provider.utils.d.ts +0 -84
  61. package/dist/utils/btc-withdrawal-message.d.ts +0 -60
  62. package/dist/utils/chunks/bitcoin-utils.d.ts +0 -85
  63. package/dist/utils/chunks/eip1559-broadcast.utils.d.ts +0 -33
  64. package/dist/utils/eip712-login.d.ts +0 -34
  65. package/dist/utils/error-handler.d.ts +0 -106
  66. package/dist/utils/ethers-interop.utils.d.ts +0 -146
  67. package/dist/utils/extend-authorization.utils.d.ts +0 -61
  68. package/dist/utils/lit-signature.utils.d.ts +0 -6
  69. package/dist/utils/logger.utils.d.ts +0 -142
  70. package/dist/utils/mint-authorization.utils.d.ts +0 -248
  71. package/dist/utils/position-delegate.utils.d.ts +0 -41
  72. package/dist/utils/quantum-timing.d.ts +0 -75
  73. package/dist/utils/server-session.d.ts +0 -50
  74. package/dist/utils/service-endpoint-policy.d.ts +0 -16
  75. package/dist/utils/signature-tempering.utils.d.ts +0 -34
  76. package/dist/utils/telegram-messaging.utils.d.ts +0 -188
@@ -1,254 +0,0 @@
1
- /**
2
- * Bitcoin Operations Module
3
- *
4
- * Responsible for:
5
- * - Deriving Bitcoin addresses from PKP public keys
6
- * - Querying Bitcoin balances (with multi-provider consensus)
7
- * - Validating Bitcoin transactions
8
- * - Caching Bitcoin data for performance
9
- *
10
- * Uses branded types (Satoshis) for type-safe Bitcoin amounts
11
- */
12
- import { Result } from "../../types/result";
13
- import { Satoshis } from "../../types/branded/domain-values";
14
- import { SDKError } from "../../utils/error-handler";
15
- import type { Cache } from "../cache/cache-manager.module";
16
- import type { BitcoinAddresses } from "../../interfaces/chunks/loan-operations.i";
17
- import type { BitcoinBalanceResult, BitcoinUTXO } from "../../interfaces/chunks/position-query.i";
18
- import type { BitcoinProviderConfig, PriceProviderConfig } from "../../interfaces/chunks/config.i";
19
- /**
20
- * Bitcoin network type
21
- */
22
- export type BitcoinNetwork = "mainnet" | "testnet" | "regtest";
23
- /**
24
- * Bitcoin Operations configuration
25
- */
26
- export interface BitcoinOperationsConfig {
27
- /** Bitcoin network to use */
28
- network: BitcoinNetwork;
29
- /** Bitcoin provider configurations (supports 1-3 for consensus) */
30
- providers: BitcoinProviderConfig[];
31
- /** Consensus mode: single or majority */
32
- consensusMode?: "single" | "majority";
33
- /** Cache for balance results (keyed by address) */
34
- balanceCache?: Cache<BitcoinBalanceResult>;
35
- /** Cache for address derivations (keyed by PKP public key) */
36
- addressCache?: Cache<BitcoinAddresses>;
37
- /** LitOps instance for price oracle queries (optional) */
38
- litOps?: any;
39
- /** Signer for LIT Protocol operations (required for getBTCPrice) */
40
- signer?: any;
41
- /** Optional PKP Ethereum address for signed price oracle (Lit jsParams pkpId) */
42
- priceOraclePkpId?: string;
43
- /** Price feed API credentials passed to the price-oracle Lit Action. Must be exactly
44
- * 3 entries from the locked set: cryptocompare, coinmarketcap, coingecko. */
45
- priceProviders?: PriceProviderConfig[];
46
- /** Enable debug logging */
47
- debug?: boolean;
48
- }
49
- /**
50
- * Bitcoin balance with enhanced metadata
51
- */
52
- export interface EnrichedBitcoinBalance {
53
- /** Bitcoin address */
54
- address: string;
55
- /** Balance in satoshis (branded type) */
56
- balance: Satoshis;
57
- /** UTXOs for this address */
58
- utxos: BitcoinUTXO[];
59
- /** Minimum confirmations across UTXOs */
60
- confirmations: number;
61
- /** Provider name that returned this data */
62
- provider: string;
63
- /** Timestamp when fetched */
64
- timestamp: number;
65
- /** Whether this data came from cache */
66
- cached: boolean;
67
- }
68
- /**
69
- * Bitcoin price result from LIT Protocol price oracle
70
- */
71
- export interface BTCPriceResult {
72
- /** Price with 8 decimals (e.g., "10679200000000" for $106,792) */
73
- priceE8: string;
74
- /** Price in USD as a number */
75
- price: number;
76
- /** Unix timestamp when price was fetched */
77
- timestamp: number;
78
- /** Source: "fast" (single source), "consensus" (multiple sources), or "fast-fallback" */
79
- source: string;
80
- /** Optional PKP signature on the price data */
81
- signature?: string;
82
- /** Optional signer address */
83
- signer?: string;
84
- }
85
- /**
86
- * Bitcoin Operations Module
87
- *
88
- * Handles all Bitcoin-related operations with type safety and caching
89
- */
90
- export declare class BitcoinOperations {
91
- private readonly config;
92
- private readonly provider;
93
- private readonly litOps?;
94
- constructor(config: BitcoinOperationsConfig);
95
- /**
96
- * Derive Bitcoin addresses from PKP public key
97
- *
98
- * Generates addresses for all networks (mainnet, testnet, regtest)
99
- * and caches the result.
100
- *
101
- * @param publicKey - PKP public key (hex string)
102
- * @returns Bitcoin addresses for all networks
103
- */
104
- deriveAddresses(publicKey: string): Promise<Result<BitcoinAddresses, SDKError>>;
105
- /**
106
- * Get Bitcoin address for current network
107
- *
108
- * Convenience method that returns only the address for the configured network.
109
- *
110
- * @param publicKey - PKP public key
111
- * @returns Bitcoin address for current network
112
- */
113
- getAddressForNetwork(publicKey: string): Promise<Result<string, SDKError>>;
114
- /**
115
- * Get Bitcoin balance for an address
116
- *
117
- * Queries balance using configured providers with consensus if enabled.
118
- * Results are cached for performance.
119
- *
120
- * @param address - Bitcoin address
121
- * @param skipCache - Skip cache and force fresh query
122
- * @returns Enriched balance information
123
- */
124
- getBalance(address: string, skipCache?: boolean): Promise<Result<EnrichedBitcoinBalance, SDKError>>;
125
- /**
126
- * Get balance with consensus across multiple providers
127
- *
128
- * Only available if multiple providers are configured.
129
- *
130
- * @param address - Bitcoin address
131
- * @returns Consensus balance result
132
- */
133
- getBalanceWithConsensus(address: string): Promise<Result<EnrichedBitcoinBalance, SDKError>>;
134
- /**
135
- * Get balances for multiple addresses
136
- *
137
- * Efficiently queries balances for multiple addresses in parallel.
138
- *
139
- * @param addresses - Array of Bitcoin addresses
140
- * @returns Array of balance results
141
- */
142
- getBalances(addresses: string[]): Promise<Result<EnrichedBitcoinBalance[], SDKError>>;
143
- /**
144
- * Get balance for a PKP public key
145
- *
146
- * Convenience method that derives address and queries balance.
147
- *
148
- * @param publicKey - PKP public key
149
- * @returns Balance for the PKP's Bitcoin address
150
- */
151
- getBalanceForPKP(publicKey: string): Promise<Result<EnrichedBitcoinBalance, SDKError>>;
152
- /**
153
- * Validate a Bitcoin address
154
- *
155
- * Checks if an address has a valid format.
156
- *
157
- * @param address - Bitcoin address
158
- * @returns Whether address is valid
159
- */
160
- validateAddress(address: string): boolean;
161
- /**
162
- * Clear balance cache for an address
163
- *
164
- * Forces next balance query to fetch fresh data.
165
- *
166
- * @param address - Bitcoin address
167
- */
168
- clearBalanceCache(address: string): void;
169
- /**
170
- * Clear all balance cache
171
- */
172
- clearAllBalanceCache(): void;
173
- /**
174
- * Clear address cache for a public key
175
- *
176
- * Forces next address derivation to compute fresh.
177
- *
178
- * @param publicKey - PKP public key
179
- */
180
- clearAddressCache(publicKey: string): void;
181
- /**
182
- * Clear all address cache
183
- */
184
- clearAllAddressCache(): void;
185
- /**
186
- * Get balance cache statistics
187
- */
188
- getBalanceCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
189
- /**
190
- * Get address cache statistics
191
- */
192
- getAddressCacheStats(): import("../cache/cache-manager.module").CacheStats | null;
193
- /**
194
- * Get current network configuration
195
- */
196
- getNetwork(): BitcoinNetwork;
197
- /**
198
- * Check if consensus mode is enabled
199
- */
200
- isConsensusEnabled(): boolean;
201
- /**
202
- * Audit CRIT-2: verify a Phase-2 BTC withdrawal that the lit-ops-server
203
- * claimed broadcast actually exists on chain and matches the user's
204
- * authorization.
205
- *
206
- * Behavior:
207
- * - If we successfully fetch the tx AND it disagrees with what the user
208
- * authorized → throws (hard fail; server lied).
209
- * - If we fetch the tx and it matches → returns `{ verified: true }`.
210
- * - If no provider has the tx after `maxAttempts` retries → returns
211
- * `{ verified: false, reason: "not yet visible" }`. The caller decides
212
- * whether to log a warning and proceed (e.g., regtest without an
213
- * Esplora indexer, or extreme propagation delay) or to escalate.
214
- * - If no Bitcoin providers are configured → returns `{ verified: false,
215
- * reason: "no providers" }` immediately.
216
- *
217
- * The expected `value` is `targetAmount - networkFee` (what reaches the
218
- * recipient after the fee), matching the Lit Action's
219
- * `userReceivesAmount` computation.
220
- */
221
- verifyBroadcastTx(args: {
222
- txid: string;
223
- expectedInput: {
224
- txid: string;
225
- vout: number;
226
- };
227
- expectedOutput: {
228
- address: string;
229
- value: number;
230
- };
231
- maxAttempts?: number;
232
- delayMs?: number;
233
- }): Promise<{
234
- verified: boolean;
235
- reason?: string;
236
- confirmed?: boolean;
237
- }>;
238
- /**
239
- * Get current BTC price using LIT Protocol price oracle.
240
- *
241
- * Strict 3-of-3: all three configured providers must respond within 1% of
242
- * each other, and the median is returned. The previous `mode: "fast" | "full"`
243
- * parameter (with single-source and lenient-consensus variants) was removed
244
- * in the H-2 audit fix — there is only one strict path now.
245
- *
246
- * @param sign - Whether to request PKP signature on the price
247
- * @returns BTC price result with timestamp and source
248
- */
249
- getPrice(sign?: boolean): Promise<Result<BTCPriceResult, SDKError>>;
250
- }
251
- /**
252
- * Factory function to create a BitcoinOperations instance
253
- */
254
- export declare function createBitcoinOperations(config: BitcoinOperationsConfig): Result<BitcoinOperations, SDKError>;
@@ -1,259 +0,0 @@
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 {};
@@ -1,152 +0,0 @@
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>;