@gvnrdao/dh-sdk 0.0.248 → 0.0.251

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.
@@ -19,6 +19,7 @@ import type { DiamondHandsSDKConfig } from "../interfaces/chunks/config.i";
19
19
  import type { PKPData } from "../interfaces/chunks/pkp-integration.i";
20
20
  import { ContractManager } from "./contract/contract-manager.module";
21
21
  import { BitcoinOperations } from "./bitcoin/bitcoin-operations.module";
22
+ import type { SupportedStablecoinData } from "../graphs/diamond-hands";
22
23
  type PositionDetailsView = {
23
24
  positionId: string;
24
25
  pkpId: string;
@@ -572,6 +573,26 @@ export declare class DiamondHandsSDK {
572
573
  * Get all events for a loan position from the subgraph
573
574
  */
574
575
  getLoanEvents(positionId: string, filter?: import("../types/event-types").LoanEventsFilter): Promise<Result<import("../types/event-types").LoanEvents, SDKError>>;
576
+ /**
577
+ * Get protocol-wide events across all indexed entity types.
578
+ * Returns a merged, sorted discriminated-union timeline.
579
+ * Narrow to a position with filter.positionId, or restrict event kinds with filter.kinds.
580
+ */
581
+ getAllEvents(filter?: import("../types/protocol-event-types").ProtocolEventsFilter): Promise<import("../types/protocol-event-types").ProtocolEventsResult>;
582
+ /**
583
+ * Return PSM-supported stablecoins from the subgraph, including indexed reserves,
584
+ * fees, exchange rate, and volume stats.
585
+ *
586
+ * @param onlySupported - When true (default) filters to currently-supported coins only.
587
+ */
588
+ getPSMStablecoins(onlySupported?: boolean): Promise<SupportedStablecoinData[]>;
589
+ /**
590
+ * Return the live on-chain available reserve balance for a single stablecoin in the PSM.
591
+ * Prefer this over the subgraph `reserves` field when freshness matters (e.g. pre-swap validation).
592
+ *
593
+ * @param stablecoinAddress - EVM address of the stablecoin to query.
594
+ */
595
+ getPSMAvailableReserves(stablecoinAddress: string): Promise<bigint>;
575
596
  /**
576
597
  * Wait for the subgraph to index up to (and including) the given block number.
577
598
  * Call after on-chain actions (createLoan, mintUCD, etc.) before querying the subgraph.
@@ -4,172 +4,102 @@
4
4
  * Type definitions for all loan-related events tracked by the Diamond Hands Protocol.
5
5
  * These events are indexed by The Graph subgraph and can be queried via the SDK.
6
6
  */
7
- /**
8
- * Payment event type enum
9
- */
10
7
  export declare enum PaymentType {
11
8
  FULL_REPAYMENT = "FULL_REPAYMENT",
12
9
  PARTIAL_PAYMENT = "PARTIAL_PAYMENT",
13
10
  EXTENSION_FEE = "EXTENSION_FEE"
14
11
  }
15
- /**
16
- * Position status enum
17
- */
18
12
  export declare enum PositionStatus {
19
13
  PENDING_DEPOSIT = "PENDING_DEPOSIT",
14
+ PENDING_MINT = "PENDING_MINT",
20
15
  ACTIVE = "ACTIVE",
21
16
  EXPIRED = "EXPIRED",
17
+ LIQUIDATABLE = "LIQUIDATABLE",
22
18
  LIQUIDATED = "LIQUIDATED",
23
19
  REPAID = "REPAID",
24
20
  CLOSED = "CLOSED"
25
21
  }
26
- /**
27
- * Payment event - tracks all payment activities for a position
28
- */
22
+ export interface PositionCreatedEvent {
23
+ id: string;
24
+ positionId: string;
25
+ pkpId: string;
26
+ borrower: string;
27
+ requestedCollateralRatio: string;
28
+ selectedTerm: string;
29
+ expiryAt: string;
30
+ timestamp: string;
31
+ blockNumber: string;
32
+ transactionHash: string;
33
+ }
29
34
  export interface PaymentEvent {
30
- /** Unique event ID (transaction hash + log index) */
31
35
  id: string;
32
- /** Position ID this payment belongs to */
33
36
  positionId: string;
34
- /** Address of the payer */
35
37
  payer: string;
36
- /** Payment amount in UCD (wei) */
37
38
  amount: string;
38
- /** Type of payment */
39
39
  type: PaymentType;
40
- /** Transaction hash */
41
40
  transactionHash: string;
42
- /** Block timestamp */
43
41
  timestamp: string;
44
- /** Block number */
45
42
  blockNumber: string;
46
- /** Log index in the transaction */
47
43
  logIndex: string;
48
- /** Position debt after payment */
49
44
  newDebt: string;
50
- /** Position collateral ratio after payment (basis points) */
51
45
  newCollateralRatio: string;
52
46
  }
53
- /**
54
- * Status update event - tracks position status changes
55
- */
56
47
  export interface StatusUpdateEvent {
57
- /** Unique event ID (transaction hash + log index) */
58
48
  id: string;
59
- /** Position ID */
60
49
  positionId: string;
61
- /** Previous status */
62
50
  oldStatus: PositionStatus;
63
- /** New status */
64
51
  newStatus: PositionStatus;
65
- /** Reason for status change (optional) */
66
52
  reason?: string;
67
- /** Block timestamp */
68
53
  timestamp: string;
69
- /** Block number */
70
54
  blockNumber: string;
71
- /** Transaction hash */
72
55
  transactionHash: string;
73
56
  }
74
- /**
75
- * Liquidation event - tracks position liquidations
76
- */
77
57
  export interface LiquidationEvent {
78
- /** Unique event ID (transaction hash) */
79
58
  id: string;
80
- /** Position ID that was liquidated */
81
59
  positionId: string;
82
- /** Address of the liquidator */
83
60
  liquidator: string;
84
- /** Amount of debt liquidated (UCD wei) */
85
61
  liquidatedAmount: string;
86
- /** Amount of collateral seized (satoshis) */
87
62
  collateralSeized: string;
88
- /** Transaction hash */
89
63
  transactionHash: string;
90
- /** Block timestamp */
91
64
  timestamp: string;
92
- /** Block number */
93
65
  blockNumber: string;
94
- /** MEV protection: commit hash (if used) */
95
66
  commitHash?: string;
96
- /** MEV protection: commit timestamp (if used) */
97
67
  commitTimestamp?: string;
98
- /** MEV protection: reveal delay in seconds (if used) */
99
68
  revealDelay?: string;
100
69
  }
101
- /**
102
- * UCD mint event - tracks UCD minting for positions
103
- */
104
70
  export interface UCDMintEvent {
105
- /** Unique event ID (transaction hash + log index) */
106
71
  id: string;
107
- /** Position ID */
108
72
  positionId: string;
109
- /** Amount of UCD minted (wei) */
110
73
  amount: string;
111
- /** Proof bytes (for verification) */
112
74
  proof: string;
113
- /** Address that performed the mint */
114
75
  minter: string;
115
- /** Whether this was a community mint */
116
76
  isCommunityMint: boolean;
117
- /** Block timestamp */
118
77
  timestamp: string;
119
- /** Block number */
120
78
  blockNumber: string;
121
- /** Transaction hash */
122
79
  transactionHash: string;
123
80
  }
124
- /**
125
- * BTC withdrawal event - tracks collateral withdrawals
126
- */
127
81
  export interface WithdrawalEvent {
128
- /** Unique event ID (transaction hash + log index) */
129
82
  id: string;
130
- /** Position ID */
131
83
  positionId: string;
132
- /** Amount withdrawn in satoshis */
133
84
  withdrawalAmount: string;
134
- /** Bitcoin destination address */
135
85
  withdrawalAddress: string;
136
- /** Network fee deducted (satoshis, optional) */
137
86
  networkFee?: string;
138
- /** Block timestamp */
139
87
  timestamp: string;
140
- /** Block number */
141
88
  blockNumber: string;
142
- /** Transaction hash */
143
89
  transactionHash: string;
144
- /** Log index in the transaction */
145
90
  logIndex: string;
146
91
  }
147
- /**
148
- * Position renewal/extension event
149
- */
150
92
  export interface RenewalEvent {
151
- /** Unique event ID (transaction hash + log index) */
152
93
  id: string;
153
- /** Position ID */
154
94
  positionId: string;
155
- /** Additional term in months */
156
95
  extensionTerm: string;
157
- /** Extension fee paid (UCD wei) */
158
96
  extensionFee: string;
159
- /** New expiry timestamp after extension */
160
97
  newExpiryDate: string;
161
- /** Block timestamp */
162
98
  timestamp: string;
163
- /** Block number */
164
99
  blockNumber: string;
165
- /** Transaction hash */
166
100
  transactionHash: string;
167
- /** Log index in the transaction */
168
101
  logIndex: string;
169
102
  }
170
- /**
171
- * Failed operation event - tracks mint/burn/repay/renew/withdraw failures
172
- */
173
103
  export interface OperationFailureEvent {
174
104
  id: string;
175
105
  positionId: string;
@@ -182,9 +112,6 @@ export interface OperationFailureEvent {
182
112
  transactionHash: string;
183
113
  logIndex: string;
184
114
  }
185
- /**
186
- * UCD mint request - records a successful mintUCD call with all parameters
187
- */
188
115
  export interface MintRequestEvent {
189
116
  id: string;
190
117
  positionId: string;
@@ -202,9 +129,6 @@ export interface MintRequestEvent {
202
129
  transactionHash: string;
203
130
  logIndex: string;
204
131
  }
205
- /**
206
- * Burn request - records a successful makePayment/repay call
207
- */
208
132
  export interface BurnRequestEvent {
209
133
  id: string;
210
134
  positionId: string;
@@ -219,10 +143,7 @@ export interface BurnRequestEvent {
219
143
  transactionHash: string;
220
144
  logIndex: string;
221
145
  }
222
- /**
223
- * Collateral contract event - position-level collateral manager outcomes
224
- * (POSITION_CLOSED, NETWORK_FEE_DEDUCTED, VALIDATION_FAILED, EXCESSIVE_FEE_REJECTED)
225
- */
146
+ /** Position-level collateral manager outcomes (POSITION_CLOSED, NETWORK_FEE_DEDUCTED) */
226
147
  export interface CollateralContractEvent {
227
148
  id: string;
228
149
  positionId: string;
@@ -236,208 +157,51 @@ export interface CollateralContractEvent {
236
157
  logIndex: string;
237
158
  }
238
159
  /**
239
- * Protocol param update emitted by updateProtocolParameters() on LoanOperationsManager
240
- */
241
- export interface LoanProtocolParamUpdateEvent {
242
- id: string;
243
- oldLiquidationThreshold: string;
244
- newLiquidationThreshold: string;
245
- oldMinimumLoanValueUcd: string;
246
- newMinimumLoanValueUcd: string;
247
- caller: string;
248
- timestamp: string;
249
- blockNumber: string;
250
- transactionHash: string;
251
- }
252
- /**
253
- * Maximum loan value update — emitted alongside updateProtocolParameters() when max changes
254
- */
255
- export interface MaxLoanValueUpdateEvent {
256
- id: string;
257
- oldValueUcd: string;
258
- newValueUcd: string;
259
- caller: string;
260
- timestamp: string;
261
- blockNumber: string;
262
- transactionHash: string;
263
- }
264
- /**
265
- * BTC price bounds update — emitted by updateBtcPriceBounds()
266
- */
267
- export interface BtcPriceBoundsUpdateEvent {
268
- id: string;
269
- oldMinBound: string;
270
- newMinBound: string;
271
- oldMaxBound: string;
272
- newMaxBound: string;
273
- caller: string;
274
- timestamp: string;
275
- blockNumber: string;
276
- transactionHash: string;
277
- }
278
- /**
279
- * Per-user daily mint limit update — emitted by setPerUserDailyMintLimit()
280
- */
281
- export interface PerUserDailyMintLimitUpdateEvent {
282
- id: string;
283
- oldLimit: string;
284
- newLimit: string;
285
- updatedBy: string;
286
- timestamp: string;
287
- blockNumber: string;
288
- transactionHash: string;
289
- }
290
- /**
291
- * Protocol-level circuit breaker event (activation, deactivation, limit updates)
292
- */
293
- export interface CircuitBreakerProtocolEvent {
294
- id: string;
295
- isActivated: boolean;
296
- admin: string;
297
- reason?: string;
298
- timestamp: string;
299
- blockNumber: string;
300
- transactionHash: string;
301
- }
302
- /**
303
- * Protocol-level term fee update event
304
- */
305
- export interface TermFeeUpdateEvent {
306
- id: string;
307
- termMonths: string;
308
- oldOriginationFee: string;
309
- newOriginationFee: string;
310
- oldExtensionFee: string;
311
- newExtensionFee: string;
312
- timestamp: string;
313
- blockNumber: string;
314
- transactionHash: string;
315
- }
316
- /**
317
- * Community fee distribution event
318
- */
319
- export interface FeeDistributionEvent {
320
- /** Unique event ID (transaction hash + log index) */
321
- id: string;
322
- /** Position ID */
323
- positionId: string;
324
- /** Recipient address */
325
- recipient: string;
326
- /** Fee amount (UCD wei) */
327
- amount: string;
328
- /** Type of fee (e.g., "community", "extension") */
329
- feeType: string;
330
- /** Block timestamp */
331
- timestamp: string;
332
- /** Block number */
333
- blockNumber: string;
334
- /** Transaction hash */
335
- transactionHash: string;
336
- }
337
- /**
338
- * Aggregate container for all loan events
160
+ * Aggregate container for all position-scoped loan events.
161
+ * Protocol-global admin events (circuit breaker, term fees, price bounds, etc.)
162
+ * are available via sdk.getAllEvents({ kinds: ['admin'] }).
339
163
  */
340
164
  export interface LoanEvents {
341
- /** Position ID these events belong to */
342
165
  positionId: string;
343
- /** All payment events */
166
+ positionCreated?: PositionCreatedEvent;
344
167
  payments: PaymentEvent[];
345
- /** All status update events */
346
168
  statusUpdates: StatusUpdateEvent[];
347
- /** Liquidation event (if position was liquidated) */
348
169
  liquidation?: LiquidationEvent;
349
- /** All UCD mint events */
350
170
  mints: UCDMintEvent[];
351
- /** All BTC withdrawal events */
352
171
  withdrawals: WithdrawalEvent[];
353
- /** All position renewal/extension events */
354
172
  renewals: RenewalEvent[];
355
- /** All failed operation events */
356
173
  operationFailures: OperationFailureEvent[];
357
- /** All mint request events (successful mintUCD calls) */
358
174
  mintRequests: MintRequestEvent[];
359
- /** All burn request events (successful repay/payment calls) */
360
175
  burnRequests: BurnRequestEvent[];
361
- /** All collateral contract events (close, fee deduction, validation failures) */
362
176
  collateralEvents: CollateralContractEvent[];
363
- /** Protocol-level circuit breaker events */
364
- circuitBreakerEvents: CircuitBreakerProtocolEvent[];
365
- /** Protocol-level term fee update events */
366
- termFeeUpdates: TermFeeUpdateEvent[];
367
- /** LoanOps protocol param updates (liquidationThreshold + minimumLoanValueUcd) */
368
- loanProtocolParamUpdates: LoanProtocolParamUpdateEvent[];
369
- /** LoanOps maximum loan value updates */
370
- maxLoanValueUpdates: MaxLoanValueUpdateEvent[];
371
- /** BTC price bounds updates */
372
- btcPriceBoundsUpdates: BtcPriceBoundsUpdateEvent[];
373
- /** Per-user daily mint limit updates */
374
- perUserMintLimitUpdates: PerUserDailyMintLimitUpdateEvent[];
375
- /** All community fee distribution events */
376
- feeDistributions: FeeDistributionEvent[];
377
- /** Total number of events */
378
177
  totalEvents: number;
379
178
  }
380
- /**
381
- * Options for filtering loan events
382
- */
383
179
  export interface LoanEventsFilter {
384
- /** Filter by event types */
385
- eventTypes?: Array<'payment' | 'status' | 'liquidation' | 'mint' | 'withdrawal' | 'renewal' | 'operationFailure' | 'mintRequest' | 'burnRequest' | 'collateralEvent' | 'circuitBreaker' | 'termFeeUpdate' | 'loanProtocolParamUpdate' | 'maxLoanValueUpdate' | 'btcPriceBoundsUpdate' | 'perUserMintLimitUpdate'>;
386
- /** Filter by minimum timestamp */
180
+ eventTypes?: Array<'positionCreated' | 'payment' | 'status' | 'liquidation' | 'mint' | 'withdrawal' | 'renewal' | 'operationFailure' | 'mintRequest' | 'burnRequest' | 'collateralEvent'>;
387
181
  fromTimestamp?: string;
388
- /** Filter by maximum timestamp */
389
182
  toTimestamp?: string;
390
- /** Filter by minimum block number */
391
183
  fromBlock?: string;
392
- /** Filter by maximum block number */
393
184
  toBlock?: string;
394
- /** Limit number of events per type */
395
185
  limit?: number;
396
- /** Order direction */
397
186
  orderDirection?: 'asc' | 'desc';
398
187
  }
399
- /**
400
- * Type guard to check if status is valid
401
- */
402
188
  export declare function isValidPositionStatus(status: string): status is PositionStatus;
403
- /**
404
- * Type guard to check if payment type is valid
405
- */
406
189
  export declare function isValidPaymentType(type: string): type is PaymentType;
407
- /**
408
- * Convert numeric status to enum
409
- */
410
190
  export declare function numericToPositionStatus(status: number): PositionStatus;
411
- /**
412
- * Event helper functions
413
- */
414
191
  export declare const EventHelpers: {
415
- /**
416
- * Sort events by timestamp (descending by default)
417
- */
418
192
  sortByTimestamp<T extends {
419
193
  timestamp: string;
420
194
  }>(events: T[], direction?: "asc" | "desc"): T[];
421
- /**
422
- * Filter events by timestamp range
423
- */
424
195
  filterByTimestamp<T extends {
425
196
  timestamp: string;
426
197
  }>(events: T[], fromTimestamp?: string, toTimestamp?: string): T[];
427
- /**
428
- * Filter events by block range
429
- */
430
198
  filterByBlock<T extends {
431
199
  blockNumber: string;
432
200
  }>(events: T[], fromBlock?: string, toBlock?: string): T[];
433
- /**
434
- * Get total count of all events
435
- */
436
201
  getTotalCount(events: LoanEvents): number;
437
- /**
438
- * Merge and sort all events by timestamp
439
- */
440
- getAllEventsSorted(events: LoanEvents, direction?: "asc" | "desc"): Array<(PaymentEvent & {
202
+ getAllEventsSorted(events: LoanEvents, direction?: "asc" | "desc"): Array<(PositionCreatedEvent & {
203
+ eventType: "positionCreated";
204
+ }) | (PaymentEvent & {
441
205
  eventType: "payment";
442
206
  }) | (StatusUpdateEvent & {
443
207
  eventType: "status";
@@ -457,17 +221,5 @@ export declare const EventHelpers: {
457
221
  eventType: "burnRequest";
458
222
  }) | (CollateralContractEvent & {
459
223
  eventType: "collateralEvent";
460
- }) | (CircuitBreakerProtocolEvent & {
461
- eventType: "circuitBreaker";
462
- }) | (TermFeeUpdateEvent & {
463
- eventType: "termFeeUpdate";
464
- }) | (LoanProtocolParamUpdateEvent & {
465
- eventType: "loanProtocolParamUpdate";
466
- }) | (MaxLoanValueUpdateEvent & {
467
- eventType: "maxLoanValueUpdate";
468
- }) | (BtcPriceBoundsUpdateEvent & {
469
- eventType: "btcPriceBoundsUpdate";
470
- }) | (PerUserDailyMintLimitUpdateEvent & {
471
- eventType: "perUserMintLimitUpdate";
472
224
  })>;
473
225
  };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Protocol-wide event types for getAllEvents.
3
+ * Position-scoped events are also available via getLoanEvents.
4
+ */
5
+ export type ProtocolEvent = {
6
+ kind: 'position';
7
+ subkind: 'created' | 'status' | 'renewed' | 'closed';
8
+ positionId: string;
9
+ timestamp: string;
10
+ blockNumber: string;
11
+ transactionHash: string;
12
+ [k: string]: unknown;
13
+ } | {
14
+ kind: 'payment';
15
+ positionId: string;
16
+ timestamp: string;
17
+ blockNumber: string;
18
+ transactionHash: string;
19
+ [k: string]: unknown;
20
+ } | {
21
+ kind: 'liquidation';
22
+ positionId: string;
23
+ timestamp: string;
24
+ blockNumber: string;
25
+ transactionHash: string;
26
+ [k: string]: unknown;
27
+ } | {
28
+ kind: 'collateral';
29
+ positionId: string;
30
+ timestamp: string;
31
+ blockNumber: string;
32
+ transactionHash: string;
33
+ [k: string]: unknown;
34
+ } | {
35
+ kind: 'mint';
36
+ positionId: string;
37
+ timestamp: string;
38
+ blockNumber: string;
39
+ transactionHash: string;
40
+ [k: string]: unknown;
41
+ } | {
42
+ kind: 'withdrawal';
43
+ positionId: string;
44
+ timestamp: string;
45
+ blockNumber: string;
46
+ transactionHash: string;
47
+ [k: string]: unknown;
48
+ } | {
49
+ kind: 'psm';
50
+ subkind: 'swap' | 'redeem';
51
+ timestamp: string;
52
+ blockNumber: string;
53
+ transactionHash: string;
54
+ [k: string]: unknown;
55
+ } | {
56
+ kind: 'admin';
57
+ subkind: 'circuitBreaker' | 'termFee' | 'loanParams' | 'maxLoanValue' | 'btcBounds' | 'mintLimit';
58
+ timestamp: string;
59
+ blockNumber: string;
60
+ transactionHash: string;
61
+ [k: string]: unknown;
62
+ };
63
+ export interface ProtocolEventsFilter {
64
+ /** Narrow all position-linked events to a single position */
65
+ positionId?: string;
66
+ /** Include only these event kinds (omit to include all) */
67
+ kinds?: ProtocolEvent['kind'][];
68
+ fromTimestamp?: string;
69
+ toTimestamp?: string;
70
+ fromBlock?: string;
71
+ toBlock?: string;
72
+ /** Per-entity query limit (default 1000) */
73
+ limit?: number;
74
+ orderDirection?: 'asc' | 'desc';
75
+ }
76
+ export interface ProtocolEventsResult {
77
+ events: ProtocolEvent[];
78
+ totalEvents: number;
79
+ /** Count of events per kind for UI filter badges */
80
+ byKind: Record<string, number>;
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.248",
3
+ "version": "0.0.251",
4
4
  "description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",