@gvnrdao/dh-sdk 0.0.210 → 0.0.212

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.d.ts CHANGED
@@ -41,7 +41,7 @@ export type { DiamondHandsSDKConfig, SDKMode, ContractAddresses, BitcoinProvider
41
41
  export type { PKPData, PKPCreationRequest, PKPCreationResult, PKPValidationResult, } from './interfaces/chunks/pkp-integration.i';
42
42
  export type { AuthorizationRequest, AuthorizationResult, BTCDepositRequest, BTCDepositResult, } from './interfaces/chunks/requests.i';
43
43
  export { LoanStatus } from './types/loanStatus';
44
- export type { LoanEvents, LoanEventsFilter, PaymentEvent, StatusUpdateEvent, LiquidationEvent, UCDMintEvent, FeeDistributionEvent, } from './types/event-types';
44
+ export type { LoanEvents, LoanEventsFilter, PaymentEvent, StatusUpdateEvent, LiquidationEvent, UCDMintEvent, FeeDistributionEvent, WithdrawalEvent, RenewalEvent, OperationFailureEvent, MintRequestEvent, BurnRequestEvent, CollateralContractEvent, CircuitBreakerProtocolEvent, TermFeeUpdateEvent, } from './types/event-types';
45
45
  export { PaymentType, PositionStatus, isValidPositionStatus, isValidPaymentType, numericToPositionStatus, EventHelpers, } from './types/event-types';
46
46
  export { fetchProtocolPauseStatus, assertProtocolNotPaused, } from './protocol/protocol-pause';
47
47
  export type { ProtocolPauseStatus, ProtocolPauseKey, } from './protocol/protocol-pause';
package/dist/index.js CHANGED
@@ -36245,7 +36245,21 @@ var DiamondHandsGraph = class {
36245
36245
  limit = 1e3,
36246
36246
  orderDirection = "desc"
36247
36247
  } = filter || {};
36248
- const buildWhereClause = () => {
36248
+ const shouldQuery = {
36249
+ payment: !eventTypes || eventTypes.includes("payment"),
36250
+ status: !eventTypes || eventTypes.includes("status"),
36251
+ liquidation: !eventTypes || eventTypes.includes("liquidation"),
36252
+ mint: !eventTypes || eventTypes.includes("mint"),
36253
+ withdrawal: !eventTypes || eventTypes.includes("withdrawal"),
36254
+ renewal: !eventTypes || eventTypes.includes("renewal"),
36255
+ operationFailure: !eventTypes || eventTypes.includes("operationFailure"),
36256
+ mintRequest: !eventTypes || eventTypes.includes("mintRequest"),
36257
+ burnRequest: !eventTypes || eventTypes.includes("burnRequest"),
36258
+ collateralEvent: !eventTypes || eventTypes.includes("collateralEvent"),
36259
+ circuitBreaker: !eventTypes || eventTypes.includes("circuitBreaker"),
36260
+ termFeeUpdate: !eventTypes || eventTypes.includes("termFeeUpdate")
36261
+ };
36262
+ const buildPositionWhereClause = () => {
36249
36263
  const conditions = [`position: "${positionId.toLowerCase()}"`];
36250
36264
  if (fromTimestamp)
36251
36265
  conditions.push(`timestamp_gte: "${fromTimestamp}"`);
@@ -36255,14 +36269,19 @@ var DiamondHandsGraph = class {
36255
36269
  conditions.push(`blockNumber_gte: "${fromBlock}"`);
36256
36270
  if (toBlock)
36257
36271
  conditions.push(`blockNumber_lte: "${toBlock}"`);
36258
- return conditions.length > 0 ? `where: { ${conditions.join(", ")} }` : "";
36272
+ return `where: { ${conditions.join(", ")} }`;
36259
36273
  };
36260
- const shouldQuery = {
36261
- payment: !eventTypes || eventTypes.includes("payment"),
36262
- status: !eventTypes || eventTypes.includes("status"),
36263
- liquidation: !eventTypes || eventTypes.includes("liquidation"),
36264
- mint: !eventTypes || eventTypes.includes("mint"),
36265
- fee: !eventTypes || eventTypes.includes("fee")
36274
+ const buildProtocolWhereClause = () => {
36275
+ const conditions = [];
36276
+ if (fromTimestamp)
36277
+ conditions.push(`timestamp_gte: "${fromTimestamp}"`);
36278
+ if (toTimestamp)
36279
+ conditions.push(`timestamp_lte: "${toTimestamp}"`);
36280
+ if (fromBlock)
36281
+ conditions.push(`blockNumber_gte: "${fromBlock}"`);
36282
+ if (toBlock)
36283
+ conditions.push(`blockNumber_lte: "${toBlock}"`);
36284
+ return conditions.length > 0 ? `where: { ${conditions.join(", ")} }` : "";
36266
36285
  };
36267
36286
  const query = `
36268
36287
  query GetLoanEvents($positionId: Bytes!, $limit: Int!, $orderDirection: OrderDirection!) {
@@ -36273,7 +36292,7 @@ var DiamondHandsGraph = class {
36273
36292
  first: $limit,
36274
36293
  orderBy: timestamp,
36275
36294
  orderDirection: $orderDirection
36276
- ${buildWhereClause()}
36295
+ ${buildProtocolWhereClause()}
36277
36296
  ) {
36278
36297
  id
36279
36298
  payer { id }
@@ -36293,7 +36312,7 @@ var DiamondHandsGraph = class {
36293
36312
  first: $limit,
36294
36313
  orderBy: timestamp,
36295
36314
  orderDirection: $orderDirection
36296
- ${buildWhereClause()}
36315
+ ${buildProtocolWhereClause()}
36297
36316
  ) {
36298
36317
  id
36299
36318
  oldStatus
@@ -36319,23 +36338,170 @@ var DiamondHandsGraph = class {
36319
36338
  revealDelay
36320
36339
  }
36321
36340
  ` : ""}
36322
- }
36323
36341
 
36342
+ ${shouldQuery.withdrawal ? `
36343
+ withdrawals(
36344
+ first: $limit,
36345
+ orderBy: timestamp,
36346
+ orderDirection: $orderDirection
36347
+ ) {
36348
+ id
36349
+ withdrawalAmount
36350
+ withdrawalAddress
36351
+ networkFee
36352
+ timestamp
36353
+ blockNumber
36354
+ transactionHash
36355
+ logIndex
36356
+ }
36357
+ ` : ""}
36358
+
36359
+ ${shouldQuery.renewal ? `
36360
+ renewals(
36361
+ first: $limit,
36362
+ orderBy: timestamp,
36363
+ orderDirection: $orderDirection
36364
+ ) {
36365
+ id
36366
+ extensionTerm
36367
+ extensionFee
36368
+ newExpiryDate
36369
+ timestamp
36370
+ blockNumber
36371
+ transactionHash
36372
+ logIndex
36373
+ }
36374
+ ` : ""}
36324
36375
 
36325
- # TODO: Re-enable ucdMintEvents query when subgraph schema is updated
36326
- # ${shouldQuery.mint ? `ucdMintEvents(...)` : ""}
36376
+ ${shouldQuery.operationFailure ? `
36377
+ operationFailures(
36378
+ first: $limit,
36379
+ orderBy: timestamp,
36380
+ orderDirection: $orderDirection
36381
+ ) {
36382
+ id
36383
+ operationType
36384
+ reason
36385
+ errorCode
36386
+ amount
36387
+ timestamp
36388
+ blockNumber
36389
+ transactionHash
36390
+ logIndex
36391
+ }
36392
+ ` : ""}
36327
36393
 
36328
- ${shouldQuery.fee ? `
36329
- communityFeeDistributions(
36330
- ${buildWhereClause()}
36394
+ ${shouldQuery.mintRequest ? `
36395
+ mintRequests(
36396
+ first: $limit,
36397
+ orderBy: timestamp,
36398
+ orderDirection: $orderDirection
36399
+ ) {
36400
+ id
36401
+ pkpId
36402
+ borrower { id }
36403
+ mintAmount
36404
+ originationFee
36405
+ newDebt
36406
+ newCollateralRatio
36407
+ btcPrice
36408
+ quantumTimestamp
36409
+ opId
36410
+ timestamp
36411
+ blockNumber
36412
+ transactionHash
36413
+ logIndex
36414
+ }
36415
+ ` : ""}
36416
+
36417
+ ${shouldQuery.burnRequest ? `
36418
+ burnRequests(
36419
+ first: $limit,
36420
+ orderBy: timestamp,
36421
+ orderDirection: $orderDirection
36422
+ ) {
36423
+ id
36424
+ pkpId
36425
+ borrower { id }
36426
+ burnAmount
36427
+ remainingDebt
36428
+ newCollateralRatio
36429
+ opId
36430
+ timestamp
36431
+ blockNumber
36432
+ transactionHash
36433
+ logIndex
36434
+ }
36435
+ ` : ""}
36436
+ }
36437
+
36438
+ ${shouldQuery.mint ? `
36439
+ ucdMintEvents(
36440
+ ${buildPositionWhereClause()}
36331
36441
  first: $limit,
36332
36442
  orderBy: timestamp,
36333
36443
  orderDirection: $orderDirection
36334
36444
  ) {
36335
36445
  id
36336
- recipient { id }
36337
36446
  amount
36338
- feeType
36447
+ proof
36448
+ minter { id }
36449
+ isCommunityMint
36450
+ timestamp
36451
+ blockNumber
36452
+ transactionHash
36453
+ }
36454
+ ` : ""}
36455
+
36456
+ ${shouldQuery.collateralEvent ? `
36457
+ collateralEvents(
36458
+ ${buildPositionWhereClause()}
36459
+ first: $limit,
36460
+ orderBy: timestamp,
36461
+ orderDirection: $orderDirection
36462
+ ) {
36463
+ id
36464
+ eventType
36465
+ networkFee
36466
+ remainingCollateral
36467
+ collateralRatio
36468
+ timestamp
36469
+ blockNumber
36470
+ transactionHash
36471
+ logIndex
36472
+ }
36473
+ ` : ""}
36474
+
36475
+ ${shouldQuery.circuitBreaker ? `
36476
+ circuitBreakerEvents(
36477
+ ${buildProtocolWhereClause()}
36478
+ first: $limit,
36479
+ orderBy: timestamp,
36480
+ orderDirection: $orderDirection
36481
+ ) {
36482
+ id
36483
+ isActivated
36484
+ admin
36485
+ reason
36486
+ timestamp
36487
+ blockNumber
36488
+ transactionHash
36489
+ }
36490
+ ` : ""}
36491
+
36492
+ ${shouldQuery.termFeeUpdate ? `
36493
+ termFeeUpdates(
36494
+ ${buildProtocolWhereClause()}
36495
+ first: $limit,
36496
+ orderBy: timestamp,
36497
+ orderDirection: $orderDirection
36498
+ ) {
36499
+ id
36500
+ term { id }
36501
+ oldOriginationFee
36502
+ newOriginationFee
36503
+ oldExtensionFee
36504
+ newExtensionFee
36339
36505
  timestamp
36340
36506
  blockNumber
36341
36507
  transactionHash
@@ -36398,24 +36564,119 @@ var DiamondHandsGraph = class {
36398
36564
  blockNumber: m.blockNumber,
36399
36565
  transactionHash: m.transactionHash
36400
36566
  }));
36401
- const feeDistributions = (result.communityFeeDistributions || []).map((f) => ({
36402
- id: f.id,
36567
+ const withdrawals = (result.position?.withdrawals || []).map((w) => ({
36568
+ id: w.id,
36569
+ positionId,
36570
+ withdrawalAmount: w.withdrawalAmount,
36571
+ withdrawalAddress: w.withdrawalAddress,
36572
+ networkFee: w.networkFee,
36573
+ timestamp: w.timestamp,
36574
+ blockNumber: w.blockNumber,
36575
+ transactionHash: w.transactionHash,
36576
+ logIndex: w.logIndex
36577
+ }));
36578
+ const renewals = (result.position?.renewals || []).map((r2) => ({
36579
+ id: r2.id,
36580
+ positionId,
36581
+ extensionTerm: r2.extensionTerm,
36582
+ extensionFee: r2.extensionFee,
36583
+ newExpiryDate: r2.newExpiryDate,
36584
+ timestamp: r2.timestamp,
36585
+ blockNumber: r2.blockNumber,
36586
+ transactionHash: r2.transactionHash,
36587
+ logIndex: r2.logIndex
36588
+ }));
36589
+ const operationFailures = (result.position?.operationFailures || []).map((o) => ({
36590
+ id: o.id,
36591
+ positionId,
36592
+ operationType: o.operationType,
36593
+ reason: o.reason,
36594
+ errorCode: o.errorCode,
36595
+ amount: o.amount,
36596
+ timestamp: o.timestamp,
36597
+ blockNumber: o.blockNumber,
36598
+ transactionHash: o.transactionHash,
36599
+ logIndex: o.logIndex
36600
+ }));
36601
+ const mintRequests = (result.position?.mintRequests || []).map((m) => ({
36602
+ id: m.id,
36403
36603
  positionId,
36404
- recipient: f.recipient.id,
36405
- amount: f.amount,
36406
- feeType: f.feeType,
36407
- timestamp: f.timestamp,
36408
- blockNumber: f.blockNumber,
36409
- transactionHash: f.transactionHash
36604
+ pkpId: m.pkpId,
36605
+ borrower: m.borrower.id,
36606
+ mintAmount: m.mintAmount,
36607
+ originationFee: m.originationFee,
36608
+ newDebt: m.newDebt,
36609
+ newCollateralRatio: m.newCollateralRatio,
36610
+ btcPrice: m.btcPrice,
36611
+ quantumTimestamp: m.quantumTimestamp,
36612
+ opId: m.opId,
36613
+ timestamp: m.timestamp,
36614
+ blockNumber: m.blockNumber,
36615
+ transactionHash: m.transactionHash,
36616
+ logIndex: m.logIndex
36617
+ }));
36618
+ const burnRequests = (result.position?.burnRequests || []).map((b) => ({
36619
+ id: b.id,
36620
+ positionId,
36621
+ pkpId: b.pkpId,
36622
+ borrower: b.borrower.id,
36623
+ burnAmount: b.burnAmount,
36624
+ remainingDebt: b.remainingDebt,
36625
+ newCollateralRatio: b.newCollateralRatio,
36626
+ opId: b.opId,
36627
+ timestamp: b.timestamp,
36628
+ blockNumber: b.blockNumber,
36629
+ transactionHash: b.transactionHash,
36630
+ logIndex: b.logIndex
36631
+ }));
36632
+ const collateralEvents = (result.collateralEvents || []).map((c) => ({
36633
+ id: c.id,
36634
+ positionId,
36635
+ eventType: c.eventType,
36636
+ networkFee: c.networkFee,
36637
+ remainingCollateral: c.remainingCollateral,
36638
+ collateralRatio: c.collateralRatio,
36639
+ timestamp: c.timestamp,
36640
+ blockNumber: c.blockNumber,
36641
+ transactionHash: c.transactionHash,
36642
+ logIndex: c.logIndex
36643
+ }));
36644
+ const circuitBreakerEvents = (result.circuitBreakerEvents || []).map((cb) => ({
36645
+ id: cb.id,
36646
+ isActivated: cb.isActivated,
36647
+ admin: cb.admin,
36648
+ reason: cb.reason,
36649
+ timestamp: cb.timestamp,
36650
+ blockNumber: cb.blockNumber,
36651
+ transactionHash: cb.transactionHash
36652
+ }));
36653
+ const termFeeUpdates = (result.termFeeUpdates || []).map((t) => ({
36654
+ id: t.id,
36655
+ termMonths: t.term.id,
36656
+ oldOriginationFee: t.oldOriginationFee,
36657
+ newOriginationFee: t.newOriginationFee,
36658
+ oldExtensionFee: t.oldExtensionFee,
36659
+ newExtensionFee: t.newExtensionFee,
36660
+ timestamp: t.timestamp,
36661
+ blockNumber: t.blockNumber,
36662
+ transactionHash: t.transactionHash
36410
36663
  }));
36411
- const totalEvents = payments.length + statusUpdates.length + (liquidation ? 1 : 0) + mints.length + feeDistributions.length;
36664
+ const totalEvents = payments.length + statusUpdates.length + (liquidation ? 1 : 0) + mints.length + withdrawals.length + renewals.length + operationFailures.length + mintRequests.length + burnRequests.length + collateralEvents.length + circuitBreakerEvents.length + termFeeUpdates.length;
36412
36665
  return {
36413
36666
  positionId,
36414
36667
  payments,
36415
36668
  statusUpdates,
36416
36669
  liquidation,
36417
36670
  mints,
36418
- feeDistributions,
36671
+ withdrawals,
36672
+ renewals,
36673
+ operationFailures,
36674
+ mintRequests,
36675
+ burnRequests,
36676
+ collateralEvents,
36677
+ circuitBreakerEvents,
36678
+ termFeeUpdates,
36679
+ feeDistributions: [],
36419
36680
  totalEvents
36420
36681
  };
36421
36682
  }
@@ -43175,7 +43436,7 @@ var EventHelpers = {
43175
43436
  * Get total count of all events
43176
43437
  */
43177
43438
  getTotalCount(events) {
43178
- return events.payments.length + events.statusUpdates.length + (events.liquidation ? 1 : 0) + events.mints.length + events.feeDistributions.length;
43439
+ return events.payments.length + events.statusUpdates.length + (events.liquidation ? 1 : 0) + events.mints.length + events.withdrawals.length + events.renewals.length + events.operationFailures.length + events.mintRequests.length + events.burnRequests.length + events.collateralEvents.length + events.circuitBreakerEvents.length + events.termFeeUpdates.length;
43179
43440
  },
43180
43441
  /**
43181
43442
  * Merge and sort all events by timestamp
@@ -43186,7 +43447,14 @@ var EventHelpers = {
43186
43447
  ...events.statusUpdates.map((e) => ({ ...e, eventType: "status" })),
43187
43448
  ...events.liquidation ? [{ ...events.liquidation, eventType: "liquidation" }] : [],
43188
43449
  ...events.mints.map((e) => ({ ...e, eventType: "mint" })),
43189
- ...events.feeDistributions.map((e) => ({ ...e, eventType: "fee" }))
43450
+ ...events.withdrawals.map((e) => ({ ...e, eventType: "withdrawal" })),
43451
+ ...events.renewals.map((e) => ({ ...e, eventType: "renewal" })),
43452
+ ...events.operationFailures.map((e) => ({ ...e, eventType: "operationFailure" })),
43453
+ ...events.mintRequests.map((e) => ({ ...e, eventType: "mintRequest" })),
43454
+ ...events.burnRequests.map((e) => ({ ...e, eventType: "burnRequest" })),
43455
+ ...events.collateralEvents.map((e) => ({ ...e, eventType: "collateralEvent" })),
43456
+ ...events.circuitBreakerEvents.map((e) => ({ ...e, eventType: "circuitBreaker" })),
43457
+ ...events.termFeeUpdates.map((e) => ({ ...e, eventType: "termFeeUpdate" }))
43190
43458
  ];
43191
43459
  return allEvents.sort((a, b) => {
43192
43460
  const diff = BigInt(a.timestamp) - BigInt(b.timestamp);
package/dist/index.mjs CHANGED
@@ -36173,7 +36173,21 @@ var DiamondHandsGraph = class {
36173
36173
  limit = 1e3,
36174
36174
  orderDirection = "desc"
36175
36175
  } = filter || {};
36176
- const buildWhereClause = () => {
36176
+ const shouldQuery = {
36177
+ payment: !eventTypes || eventTypes.includes("payment"),
36178
+ status: !eventTypes || eventTypes.includes("status"),
36179
+ liquidation: !eventTypes || eventTypes.includes("liquidation"),
36180
+ mint: !eventTypes || eventTypes.includes("mint"),
36181
+ withdrawal: !eventTypes || eventTypes.includes("withdrawal"),
36182
+ renewal: !eventTypes || eventTypes.includes("renewal"),
36183
+ operationFailure: !eventTypes || eventTypes.includes("operationFailure"),
36184
+ mintRequest: !eventTypes || eventTypes.includes("mintRequest"),
36185
+ burnRequest: !eventTypes || eventTypes.includes("burnRequest"),
36186
+ collateralEvent: !eventTypes || eventTypes.includes("collateralEvent"),
36187
+ circuitBreaker: !eventTypes || eventTypes.includes("circuitBreaker"),
36188
+ termFeeUpdate: !eventTypes || eventTypes.includes("termFeeUpdate")
36189
+ };
36190
+ const buildPositionWhereClause = () => {
36177
36191
  const conditions = [`position: "${positionId.toLowerCase()}"`];
36178
36192
  if (fromTimestamp)
36179
36193
  conditions.push(`timestamp_gte: "${fromTimestamp}"`);
@@ -36183,14 +36197,19 @@ var DiamondHandsGraph = class {
36183
36197
  conditions.push(`blockNumber_gte: "${fromBlock}"`);
36184
36198
  if (toBlock)
36185
36199
  conditions.push(`blockNumber_lte: "${toBlock}"`);
36186
- return conditions.length > 0 ? `where: { ${conditions.join(", ")} }` : "";
36200
+ return `where: { ${conditions.join(", ")} }`;
36187
36201
  };
36188
- const shouldQuery = {
36189
- payment: !eventTypes || eventTypes.includes("payment"),
36190
- status: !eventTypes || eventTypes.includes("status"),
36191
- liquidation: !eventTypes || eventTypes.includes("liquidation"),
36192
- mint: !eventTypes || eventTypes.includes("mint"),
36193
- fee: !eventTypes || eventTypes.includes("fee")
36202
+ const buildProtocolWhereClause = () => {
36203
+ const conditions = [];
36204
+ if (fromTimestamp)
36205
+ conditions.push(`timestamp_gte: "${fromTimestamp}"`);
36206
+ if (toTimestamp)
36207
+ conditions.push(`timestamp_lte: "${toTimestamp}"`);
36208
+ if (fromBlock)
36209
+ conditions.push(`blockNumber_gte: "${fromBlock}"`);
36210
+ if (toBlock)
36211
+ conditions.push(`blockNumber_lte: "${toBlock}"`);
36212
+ return conditions.length > 0 ? `where: { ${conditions.join(", ")} }` : "";
36194
36213
  };
36195
36214
  const query = `
36196
36215
  query GetLoanEvents($positionId: Bytes!, $limit: Int!, $orderDirection: OrderDirection!) {
@@ -36201,7 +36220,7 @@ var DiamondHandsGraph = class {
36201
36220
  first: $limit,
36202
36221
  orderBy: timestamp,
36203
36222
  orderDirection: $orderDirection
36204
- ${buildWhereClause()}
36223
+ ${buildProtocolWhereClause()}
36205
36224
  ) {
36206
36225
  id
36207
36226
  payer { id }
@@ -36221,7 +36240,7 @@ var DiamondHandsGraph = class {
36221
36240
  first: $limit,
36222
36241
  orderBy: timestamp,
36223
36242
  orderDirection: $orderDirection
36224
- ${buildWhereClause()}
36243
+ ${buildProtocolWhereClause()}
36225
36244
  ) {
36226
36245
  id
36227
36246
  oldStatus
@@ -36247,23 +36266,170 @@ var DiamondHandsGraph = class {
36247
36266
  revealDelay
36248
36267
  }
36249
36268
  ` : ""}
36250
- }
36251
36269
 
36270
+ ${shouldQuery.withdrawal ? `
36271
+ withdrawals(
36272
+ first: $limit,
36273
+ orderBy: timestamp,
36274
+ orderDirection: $orderDirection
36275
+ ) {
36276
+ id
36277
+ withdrawalAmount
36278
+ withdrawalAddress
36279
+ networkFee
36280
+ timestamp
36281
+ blockNumber
36282
+ transactionHash
36283
+ logIndex
36284
+ }
36285
+ ` : ""}
36286
+
36287
+ ${shouldQuery.renewal ? `
36288
+ renewals(
36289
+ first: $limit,
36290
+ orderBy: timestamp,
36291
+ orderDirection: $orderDirection
36292
+ ) {
36293
+ id
36294
+ extensionTerm
36295
+ extensionFee
36296
+ newExpiryDate
36297
+ timestamp
36298
+ blockNumber
36299
+ transactionHash
36300
+ logIndex
36301
+ }
36302
+ ` : ""}
36252
36303
 
36253
- # TODO: Re-enable ucdMintEvents query when subgraph schema is updated
36254
- # ${shouldQuery.mint ? `ucdMintEvents(...)` : ""}
36304
+ ${shouldQuery.operationFailure ? `
36305
+ operationFailures(
36306
+ first: $limit,
36307
+ orderBy: timestamp,
36308
+ orderDirection: $orderDirection
36309
+ ) {
36310
+ id
36311
+ operationType
36312
+ reason
36313
+ errorCode
36314
+ amount
36315
+ timestamp
36316
+ blockNumber
36317
+ transactionHash
36318
+ logIndex
36319
+ }
36320
+ ` : ""}
36255
36321
 
36256
- ${shouldQuery.fee ? `
36257
- communityFeeDistributions(
36258
- ${buildWhereClause()}
36322
+ ${shouldQuery.mintRequest ? `
36323
+ mintRequests(
36324
+ first: $limit,
36325
+ orderBy: timestamp,
36326
+ orderDirection: $orderDirection
36327
+ ) {
36328
+ id
36329
+ pkpId
36330
+ borrower { id }
36331
+ mintAmount
36332
+ originationFee
36333
+ newDebt
36334
+ newCollateralRatio
36335
+ btcPrice
36336
+ quantumTimestamp
36337
+ opId
36338
+ timestamp
36339
+ blockNumber
36340
+ transactionHash
36341
+ logIndex
36342
+ }
36343
+ ` : ""}
36344
+
36345
+ ${shouldQuery.burnRequest ? `
36346
+ burnRequests(
36347
+ first: $limit,
36348
+ orderBy: timestamp,
36349
+ orderDirection: $orderDirection
36350
+ ) {
36351
+ id
36352
+ pkpId
36353
+ borrower { id }
36354
+ burnAmount
36355
+ remainingDebt
36356
+ newCollateralRatio
36357
+ opId
36358
+ timestamp
36359
+ blockNumber
36360
+ transactionHash
36361
+ logIndex
36362
+ }
36363
+ ` : ""}
36364
+ }
36365
+
36366
+ ${shouldQuery.mint ? `
36367
+ ucdMintEvents(
36368
+ ${buildPositionWhereClause()}
36259
36369
  first: $limit,
36260
36370
  orderBy: timestamp,
36261
36371
  orderDirection: $orderDirection
36262
36372
  ) {
36263
36373
  id
36264
- recipient { id }
36265
36374
  amount
36266
- feeType
36375
+ proof
36376
+ minter { id }
36377
+ isCommunityMint
36378
+ timestamp
36379
+ blockNumber
36380
+ transactionHash
36381
+ }
36382
+ ` : ""}
36383
+
36384
+ ${shouldQuery.collateralEvent ? `
36385
+ collateralEvents(
36386
+ ${buildPositionWhereClause()}
36387
+ first: $limit,
36388
+ orderBy: timestamp,
36389
+ orderDirection: $orderDirection
36390
+ ) {
36391
+ id
36392
+ eventType
36393
+ networkFee
36394
+ remainingCollateral
36395
+ collateralRatio
36396
+ timestamp
36397
+ blockNumber
36398
+ transactionHash
36399
+ logIndex
36400
+ }
36401
+ ` : ""}
36402
+
36403
+ ${shouldQuery.circuitBreaker ? `
36404
+ circuitBreakerEvents(
36405
+ ${buildProtocolWhereClause()}
36406
+ first: $limit,
36407
+ orderBy: timestamp,
36408
+ orderDirection: $orderDirection
36409
+ ) {
36410
+ id
36411
+ isActivated
36412
+ admin
36413
+ reason
36414
+ timestamp
36415
+ blockNumber
36416
+ transactionHash
36417
+ }
36418
+ ` : ""}
36419
+
36420
+ ${shouldQuery.termFeeUpdate ? `
36421
+ termFeeUpdates(
36422
+ ${buildProtocolWhereClause()}
36423
+ first: $limit,
36424
+ orderBy: timestamp,
36425
+ orderDirection: $orderDirection
36426
+ ) {
36427
+ id
36428
+ term { id }
36429
+ oldOriginationFee
36430
+ newOriginationFee
36431
+ oldExtensionFee
36432
+ newExtensionFee
36267
36433
  timestamp
36268
36434
  blockNumber
36269
36435
  transactionHash
@@ -36326,24 +36492,119 @@ var DiamondHandsGraph = class {
36326
36492
  blockNumber: m.blockNumber,
36327
36493
  transactionHash: m.transactionHash
36328
36494
  }));
36329
- const feeDistributions = (result.communityFeeDistributions || []).map((f) => ({
36330
- id: f.id,
36495
+ const withdrawals = (result.position?.withdrawals || []).map((w) => ({
36496
+ id: w.id,
36497
+ positionId,
36498
+ withdrawalAmount: w.withdrawalAmount,
36499
+ withdrawalAddress: w.withdrawalAddress,
36500
+ networkFee: w.networkFee,
36501
+ timestamp: w.timestamp,
36502
+ blockNumber: w.blockNumber,
36503
+ transactionHash: w.transactionHash,
36504
+ logIndex: w.logIndex
36505
+ }));
36506
+ const renewals = (result.position?.renewals || []).map((r2) => ({
36507
+ id: r2.id,
36508
+ positionId,
36509
+ extensionTerm: r2.extensionTerm,
36510
+ extensionFee: r2.extensionFee,
36511
+ newExpiryDate: r2.newExpiryDate,
36512
+ timestamp: r2.timestamp,
36513
+ blockNumber: r2.blockNumber,
36514
+ transactionHash: r2.transactionHash,
36515
+ logIndex: r2.logIndex
36516
+ }));
36517
+ const operationFailures = (result.position?.operationFailures || []).map((o) => ({
36518
+ id: o.id,
36519
+ positionId,
36520
+ operationType: o.operationType,
36521
+ reason: o.reason,
36522
+ errorCode: o.errorCode,
36523
+ amount: o.amount,
36524
+ timestamp: o.timestamp,
36525
+ blockNumber: o.blockNumber,
36526
+ transactionHash: o.transactionHash,
36527
+ logIndex: o.logIndex
36528
+ }));
36529
+ const mintRequests = (result.position?.mintRequests || []).map((m) => ({
36530
+ id: m.id,
36331
36531
  positionId,
36332
- recipient: f.recipient.id,
36333
- amount: f.amount,
36334
- feeType: f.feeType,
36335
- timestamp: f.timestamp,
36336
- blockNumber: f.blockNumber,
36337
- transactionHash: f.transactionHash
36532
+ pkpId: m.pkpId,
36533
+ borrower: m.borrower.id,
36534
+ mintAmount: m.mintAmount,
36535
+ originationFee: m.originationFee,
36536
+ newDebt: m.newDebt,
36537
+ newCollateralRatio: m.newCollateralRatio,
36538
+ btcPrice: m.btcPrice,
36539
+ quantumTimestamp: m.quantumTimestamp,
36540
+ opId: m.opId,
36541
+ timestamp: m.timestamp,
36542
+ blockNumber: m.blockNumber,
36543
+ transactionHash: m.transactionHash,
36544
+ logIndex: m.logIndex
36545
+ }));
36546
+ const burnRequests = (result.position?.burnRequests || []).map((b) => ({
36547
+ id: b.id,
36548
+ positionId,
36549
+ pkpId: b.pkpId,
36550
+ borrower: b.borrower.id,
36551
+ burnAmount: b.burnAmount,
36552
+ remainingDebt: b.remainingDebt,
36553
+ newCollateralRatio: b.newCollateralRatio,
36554
+ opId: b.opId,
36555
+ timestamp: b.timestamp,
36556
+ blockNumber: b.blockNumber,
36557
+ transactionHash: b.transactionHash,
36558
+ logIndex: b.logIndex
36559
+ }));
36560
+ const collateralEvents = (result.collateralEvents || []).map((c) => ({
36561
+ id: c.id,
36562
+ positionId,
36563
+ eventType: c.eventType,
36564
+ networkFee: c.networkFee,
36565
+ remainingCollateral: c.remainingCollateral,
36566
+ collateralRatio: c.collateralRatio,
36567
+ timestamp: c.timestamp,
36568
+ blockNumber: c.blockNumber,
36569
+ transactionHash: c.transactionHash,
36570
+ logIndex: c.logIndex
36571
+ }));
36572
+ const circuitBreakerEvents = (result.circuitBreakerEvents || []).map((cb) => ({
36573
+ id: cb.id,
36574
+ isActivated: cb.isActivated,
36575
+ admin: cb.admin,
36576
+ reason: cb.reason,
36577
+ timestamp: cb.timestamp,
36578
+ blockNumber: cb.blockNumber,
36579
+ transactionHash: cb.transactionHash
36580
+ }));
36581
+ const termFeeUpdates = (result.termFeeUpdates || []).map((t) => ({
36582
+ id: t.id,
36583
+ termMonths: t.term.id,
36584
+ oldOriginationFee: t.oldOriginationFee,
36585
+ newOriginationFee: t.newOriginationFee,
36586
+ oldExtensionFee: t.oldExtensionFee,
36587
+ newExtensionFee: t.newExtensionFee,
36588
+ timestamp: t.timestamp,
36589
+ blockNumber: t.blockNumber,
36590
+ transactionHash: t.transactionHash
36338
36591
  }));
36339
- const totalEvents = payments.length + statusUpdates.length + (liquidation ? 1 : 0) + mints.length + feeDistributions.length;
36592
+ const totalEvents = payments.length + statusUpdates.length + (liquidation ? 1 : 0) + mints.length + withdrawals.length + renewals.length + operationFailures.length + mintRequests.length + burnRequests.length + collateralEvents.length + circuitBreakerEvents.length + termFeeUpdates.length;
36340
36593
  return {
36341
36594
  positionId,
36342
36595
  payments,
36343
36596
  statusUpdates,
36344
36597
  liquidation,
36345
36598
  mints,
36346
- feeDistributions,
36599
+ withdrawals,
36600
+ renewals,
36601
+ operationFailures,
36602
+ mintRequests,
36603
+ burnRequests,
36604
+ collateralEvents,
36605
+ circuitBreakerEvents,
36606
+ termFeeUpdates,
36607
+ feeDistributions: [],
36347
36608
  totalEvents
36348
36609
  };
36349
36610
  }
@@ -43103,7 +43364,7 @@ var EventHelpers = {
43103
43364
  * Get total count of all events
43104
43365
  */
43105
43366
  getTotalCount(events) {
43106
- return events.payments.length + events.statusUpdates.length + (events.liquidation ? 1 : 0) + events.mints.length + events.feeDistributions.length;
43367
+ return events.payments.length + events.statusUpdates.length + (events.liquidation ? 1 : 0) + events.mints.length + events.withdrawals.length + events.renewals.length + events.operationFailures.length + events.mintRequests.length + events.burnRequests.length + events.collateralEvents.length + events.circuitBreakerEvents.length + events.termFeeUpdates.length;
43107
43368
  },
43108
43369
  /**
43109
43370
  * Merge and sort all events by timestamp
@@ -43114,7 +43375,14 @@ var EventHelpers = {
43114
43375
  ...events.statusUpdates.map((e) => ({ ...e, eventType: "status" })),
43115
43376
  ...events.liquidation ? [{ ...events.liquidation, eventType: "liquidation" }] : [],
43116
43377
  ...events.mints.map((e) => ({ ...e, eventType: "mint" })),
43117
- ...events.feeDistributions.map((e) => ({ ...e, eventType: "fee" }))
43378
+ ...events.withdrawals.map((e) => ({ ...e, eventType: "withdrawal" })),
43379
+ ...events.renewals.map((e) => ({ ...e, eventType: "renewal" })),
43380
+ ...events.operationFailures.map((e) => ({ ...e, eventType: "operationFailure" })),
43381
+ ...events.mintRequests.map((e) => ({ ...e, eventType: "mintRequest" })),
43382
+ ...events.burnRequests.map((e) => ({ ...e, eventType: "burnRequest" })),
43383
+ ...events.collateralEvents.map((e) => ({ ...e, eventType: "collateralEvent" })),
43384
+ ...events.circuitBreakerEvents.map((e) => ({ ...e, eventType: "circuitBreaker" })),
43385
+ ...events.termFeeUpdates.map((e) => ({ ...e, eventType: "termFeeUpdate" }))
43118
43386
  ];
43119
43387
  return allEvents.sort((a, b) => {
43120
43388
  const diff = BigInt(a.timestamp) - BigInt(b.timestamp);
@@ -121,6 +121,146 @@ export interface UCDMintEvent {
121
121
  /** Transaction hash */
122
122
  transactionHash: string;
123
123
  }
124
+ /**
125
+ * BTC withdrawal event - tracks collateral withdrawals
126
+ */
127
+ export interface WithdrawalEvent {
128
+ /** Unique event ID (transaction hash + log index) */
129
+ id: string;
130
+ /** Position ID */
131
+ positionId: string;
132
+ /** Amount withdrawn in satoshis */
133
+ withdrawalAmount: string;
134
+ /** Bitcoin destination address */
135
+ withdrawalAddress: string;
136
+ /** Network fee deducted (satoshis, optional) */
137
+ networkFee?: string;
138
+ /** Block timestamp */
139
+ timestamp: string;
140
+ /** Block number */
141
+ blockNumber: string;
142
+ /** Transaction hash */
143
+ transactionHash: string;
144
+ /** Log index in the transaction */
145
+ logIndex: string;
146
+ }
147
+ /**
148
+ * Position renewal/extension event
149
+ */
150
+ export interface RenewalEvent {
151
+ /** Unique event ID (transaction hash + log index) */
152
+ id: string;
153
+ /** Position ID */
154
+ positionId: string;
155
+ /** Additional term in months */
156
+ extensionTerm: string;
157
+ /** Extension fee paid (UCD wei) */
158
+ extensionFee: string;
159
+ /** New expiry timestamp after extension */
160
+ newExpiryDate: string;
161
+ /** Block timestamp */
162
+ timestamp: string;
163
+ /** Block number */
164
+ blockNumber: string;
165
+ /** Transaction hash */
166
+ transactionHash: string;
167
+ /** Log index in the transaction */
168
+ logIndex: string;
169
+ }
170
+ /**
171
+ * Failed operation event - tracks mint/burn/repay/renew/withdraw failures
172
+ */
173
+ export interface OperationFailureEvent {
174
+ id: string;
175
+ positionId: string;
176
+ operationType: string;
177
+ reason: string;
178
+ errorCode?: string;
179
+ amount?: string;
180
+ timestamp: string;
181
+ blockNumber: string;
182
+ transactionHash: string;
183
+ logIndex: string;
184
+ }
185
+ /**
186
+ * UCD mint request - records a successful mintUCD call with all parameters
187
+ */
188
+ export interface MintRequestEvent {
189
+ id: string;
190
+ positionId: string;
191
+ pkpId: string;
192
+ borrower: string;
193
+ mintAmount: string;
194
+ originationFee: string;
195
+ newDebt: string;
196
+ newCollateralRatio: string;
197
+ btcPrice: string;
198
+ quantumTimestamp: string;
199
+ opId: string;
200
+ timestamp: string;
201
+ blockNumber: string;
202
+ transactionHash: string;
203
+ logIndex: string;
204
+ }
205
+ /**
206
+ * Burn request - records a successful makePayment/repay call
207
+ */
208
+ export interface BurnRequestEvent {
209
+ id: string;
210
+ positionId: string;
211
+ pkpId: string;
212
+ borrower: string;
213
+ burnAmount: string;
214
+ remainingDebt: string;
215
+ newCollateralRatio: string;
216
+ opId: string;
217
+ timestamp: string;
218
+ blockNumber: string;
219
+ transactionHash: string;
220
+ logIndex: string;
221
+ }
222
+ /**
223
+ * Collateral contract event - position-level collateral manager outcomes
224
+ * (POSITION_CLOSED, NETWORK_FEE_DEDUCTED, VALIDATION_FAILED, EXCESSIVE_FEE_REJECTED)
225
+ */
226
+ export interface CollateralContractEvent {
227
+ id: string;
228
+ positionId: string;
229
+ eventType: string;
230
+ networkFee?: string;
231
+ remainingCollateral?: string;
232
+ collateralRatio?: string;
233
+ timestamp: string;
234
+ blockNumber: string;
235
+ transactionHash: string;
236
+ logIndex: string;
237
+ }
238
+ /**
239
+ * Protocol-level circuit breaker event (activation, deactivation, limit updates)
240
+ */
241
+ export interface CircuitBreakerProtocolEvent {
242
+ id: string;
243
+ isActivated: boolean;
244
+ admin: string;
245
+ reason?: string;
246
+ timestamp: string;
247
+ blockNumber: string;
248
+ transactionHash: string;
249
+ }
250
+ /**
251
+ * Protocol-level term fee update event
252
+ */
253
+ export interface TermFeeUpdateEvent {
254
+ id: string;
255
+ termMonths: string;
256
+ oldOriginationFee: string;
257
+ newOriginationFee: string;
258
+ oldExtensionFee: string;
259
+ newExtensionFee: string;
260
+ timestamp: string;
261
+ blockNumber: string;
262
+ transactionHash: string;
263
+ }
124
264
  /**
125
265
  * Community fee distribution event
126
266
  */
@@ -156,6 +296,22 @@ export interface LoanEvents {
156
296
  liquidation?: LiquidationEvent;
157
297
  /** All UCD mint events */
158
298
  mints: UCDMintEvent[];
299
+ /** All BTC withdrawal events */
300
+ withdrawals: WithdrawalEvent[];
301
+ /** All position renewal/extension events */
302
+ renewals: RenewalEvent[];
303
+ /** All failed operation events */
304
+ operationFailures: OperationFailureEvent[];
305
+ /** All mint request events (successful mintUCD calls) */
306
+ mintRequests: MintRequestEvent[];
307
+ /** All burn request events (successful repay/payment calls) */
308
+ burnRequests: BurnRequestEvent[];
309
+ /** All collateral contract events (close, fee deduction, validation failures) */
310
+ collateralEvents: CollateralContractEvent[];
311
+ /** Protocol-level circuit breaker events */
312
+ circuitBreakerEvents: CircuitBreakerProtocolEvent[];
313
+ /** Protocol-level term fee update events */
314
+ termFeeUpdates: TermFeeUpdateEvent[];
159
315
  /** All community fee distribution events */
160
316
  feeDistributions: FeeDistributionEvent[];
161
317
  /** Total number of events */
@@ -166,7 +322,7 @@ export interface LoanEvents {
166
322
  */
167
323
  export interface LoanEventsFilter {
168
324
  /** Filter by event types */
169
- eventTypes?: Array<'payment' | 'status' | 'liquidation' | 'mint' | 'fee'>;
325
+ eventTypes?: Array<'payment' | 'status' | 'liquidation' | 'mint' | 'withdrawal' | 'renewal' | 'operationFailure' | 'mintRequest' | 'burnRequest' | 'collateralEvent' | 'circuitBreaker' | 'termFeeUpdate'>;
170
326
  /** Filter by minimum timestamp */
171
327
  fromTimestamp?: string;
172
328
  /** Filter by maximum timestamp */
@@ -229,7 +385,21 @@ export declare const EventHelpers: {
229
385
  eventType: "liquidation";
230
386
  }) | (UCDMintEvent & {
231
387
  eventType: "mint";
232
- }) | (FeeDistributionEvent & {
233
- eventType: "fee";
388
+ }) | (WithdrawalEvent & {
389
+ eventType: "withdrawal";
390
+ }) | (RenewalEvent & {
391
+ eventType: "renewal";
392
+ }) | (OperationFailureEvent & {
393
+ eventType: "operationFailure";
394
+ }) | (MintRequestEvent & {
395
+ eventType: "mintRequest";
396
+ }) | (BurnRequestEvent & {
397
+ eventType: "burnRequest";
398
+ }) | (CollateralContractEvent & {
399
+ eventType: "collateralEvent";
400
+ }) | (CircuitBreakerProtocolEvent & {
401
+ eventType: "circuitBreaker";
402
+ }) | (TermFeeUpdateEvent & {
403
+ eventType: "termFeeUpdate";
234
404
  })>;
235
405
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.210",
3
+ "version": "0.0.212",
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/sdk/src/index.d.ts",