@gvnrdao/dh-sdk 0.0.96 → 0.0.98

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.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ethers, DeferredTopicFilter, EventFragment, EventLog as EventLog$1, ContractTransactionResponse, FunctionFragment, ContractTransaction, LogDescription, Typed, TransactionRequest, BaseContract, ContractRunner, Listener, BigNumberish, BytesLike, AddressLike, ContractMethod, Interface, Result as Result$2, Wallet } from 'ethers';
1
+ import { ethers, DeferredTopicFilter, EventFragment, EventLog as EventLog$1, ContractTransactionResponse, FunctionFragment, ContractTransaction, LogDescription, Typed, TransactionRequest, BaseContract, ContractRunner, Listener, BigNumberish, BytesLike, AddressLike, ContractMethod, Interface, Result as Result$2, Wallet, providers } from 'ethers';
2
2
  import { LitNetwork, LitOps } from '@gvnrdao/dh-lit-ops';
3
3
 
4
4
  /**
@@ -6279,6 +6279,11 @@ declare class DiamondHandsGraph {
6279
6279
  private client;
6280
6280
  private defaultPageSize;
6281
6281
  constructor(config: DiamondHandsGraphConfig);
6282
+ /**
6283
+ * Transform graph position data to LoanData interface
6284
+ * Converts flat graph structure to nested LoanData structure
6285
+ */
6286
+ private transformGraphPositionToLoanData;
6282
6287
  /**
6283
6288
  * Helper: Get total count by paginating through all results
6284
6289
  * The Graph has a hard limit of 1000 items per query, so we need to paginate
@@ -6456,6 +6461,8 @@ interface LoanQueryConfig {
6456
6461
  graphClient: DiamondHandsGraphClient;
6457
6462
  /** Bitcoin operations for balance enrichment */
6458
6463
  bitcoinOperations: BitcoinOperations;
6464
+ /** Ethereum provider for PKP public key retrieval */
6465
+ provider?: providers.Provider;
6459
6466
  /** Cache for loan query results */
6460
6467
  cache?: LRUCache<string, LoanData>;
6461
6468
  /** Enable debug logging */
@@ -6496,6 +6503,13 @@ declare class LoanQuery {
6496
6503
  * @returns Paginated loans response
6497
6504
  */
6498
6505
  getLoans(filters?: LoanQueryFilters, pagination?: PaginationParams): Promise<Result$1<PaginatedLoansResponse, SDKError>>;
6506
+ /**
6507
+ * Enrich loans with vault addresses derived from PKP public keys
6508
+ *
6509
+ * @param loans - Array of loans to enrich
6510
+ * @returns Enriched loans with vault addresses for all networks
6511
+ */
6512
+ private enrichLoansWithVaultAddresses;
6499
6513
  /**
6500
6514
  * Map numeric status to string for subgraph queries
6501
6515
  */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ethers, DeferredTopicFilter, EventFragment, EventLog as EventLog$1, ContractTransactionResponse, FunctionFragment, ContractTransaction, LogDescription, Typed, TransactionRequest, BaseContract, ContractRunner, Listener, BigNumberish, BytesLike, AddressLike, ContractMethod, Interface, Result as Result$2, Wallet } from 'ethers';
1
+ import { ethers, DeferredTopicFilter, EventFragment, EventLog as EventLog$1, ContractTransactionResponse, FunctionFragment, ContractTransaction, LogDescription, Typed, TransactionRequest, BaseContract, ContractRunner, Listener, BigNumberish, BytesLike, AddressLike, ContractMethod, Interface, Result as Result$2, Wallet, providers } from 'ethers';
2
2
  import { LitNetwork, LitOps } from '@gvnrdao/dh-lit-ops';
3
3
 
4
4
  /**
@@ -6279,6 +6279,11 @@ declare class DiamondHandsGraph {
6279
6279
  private client;
6280
6280
  private defaultPageSize;
6281
6281
  constructor(config: DiamondHandsGraphConfig);
6282
+ /**
6283
+ * Transform graph position data to LoanData interface
6284
+ * Converts flat graph structure to nested LoanData structure
6285
+ */
6286
+ private transformGraphPositionToLoanData;
6282
6287
  /**
6283
6288
  * Helper: Get total count by paginating through all results
6284
6289
  * The Graph has a hard limit of 1000 items per query, so we need to paginate
@@ -6456,6 +6461,8 @@ interface LoanQueryConfig {
6456
6461
  graphClient: DiamondHandsGraphClient;
6457
6462
  /** Bitcoin operations for balance enrichment */
6458
6463
  bitcoinOperations: BitcoinOperations;
6464
+ /** Ethereum provider for PKP public key retrieval */
6465
+ provider?: providers.Provider;
6459
6466
  /** Cache for loan query results */
6460
6467
  cache?: LRUCache<string, LoanData>;
6461
6468
  /** Enable debug logging */
@@ -6496,6 +6503,13 @@ declare class LoanQuery {
6496
6503
  * @returns Paginated loans response
6497
6504
  */
6498
6505
  getLoans(filters?: LoanQueryFilters, pagination?: PaginationParams): Promise<Result$1<PaginatedLoansResponse, SDKError>>;
6506
+ /**
6507
+ * Enrich loans with vault addresses derived from PKP public keys
6508
+ *
6509
+ * @param loans - Array of loans to enrich
6510
+ * @returns Enriched loans with vault addresses for all networks
6511
+ */
6512
+ private enrichLoansWithVaultAddresses;
6499
6513
  /**
6500
6514
  * Map numeric status to string for subgraph queries
6501
6515
  */
package/dist/index.js CHANGED
@@ -44413,6 +44413,7 @@ function createLoanCreator(config) {
44413
44413
  }
44414
44414
 
44415
44415
  // src/modules/loan/loan-query.module.ts
44416
+ init_mint_authorization_utils();
44416
44417
  var LoanQuery = class {
44417
44418
  config;
44418
44419
  defaultPageSize;
@@ -44540,8 +44541,9 @@ var LoanQuery = class {
44540
44541
  skip
44541
44542
  );
44542
44543
  }
44544
+ const enrichedLoans = await this.enrichLoansWithVaultAddresses(result.positions);
44543
44545
  return {
44544
- loans: result.positions,
44546
+ loans: enrichedLoans,
44545
44547
  page,
44546
44548
  maxRows: pageSize,
44547
44549
  totalLoans: result.total
@@ -44556,6 +44558,63 @@ var LoanQuery = class {
44556
44558
  })
44557
44559
  );
44558
44560
  }
44561
+ /**
44562
+ * Enrich loans with vault addresses derived from PKP public keys
44563
+ *
44564
+ * @param loans - Array of loans to enrich
44565
+ * @returns Enriched loans with vault addresses for all networks
44566
+ */
44567
+ async enrichLoansWithVaultAddresses(loans) {
44568
+ if (!loans || loans.length === 0) {
44569
+ return loans;
44570
+ }
44571
+ if (this.config.debug) {
44572
+ log.info(`\u{1F511} Enriching ${loans.length} loans with vault addresses...`);
44573
+ }
44574
+ const BATCH_SIZE = 15;
44575
+ for (let i = 0; i < loans.length; i += BATCH_SIZE) {
44576
+ const batch = loans.slice(i, i + BATCH_SIZE);
44577
+ await Promise.all(
44578
+ batch.map(async (loan) => {
44579
+ try {
44580
+ const pkpPublicKey = await getPKPPublicKeyFromTokenId(
44581
+ loan.pkpId,
44582
+ this.config.provider
44583
+ );
44584
+ const addressesResult = await this.config.bitcoinOperations.deriveAddresses(
44585
+ pkpPublicKey
44586
+ );
44587
+ if (addressesResult.success) {
44588
+ loan.collateral.vaultAddress = addressesResult.value;
44589
+ if (this.config.debug) {
44590
+ log.info(`\u2705 Derived vault addresses for loan ${loan.id}`, {
44591
+ mainnet: addressesResult.value.mainnet,
44592
+ testnet: addressesResult.value.testnet,
44593
+ regtest: addressesResult.value.regtest
44594
+ });
44595
+ }
44596
+ } else {
44597
+ if (this.config.debug) {
44598
+ log.warn(`\u26A0\uFE0F Failed to derive vault addresses for loan ${loan.id}`, {
44599
+ error: addressesResult.error.message
44600
+ });
44601
+ }
44602
+ }
44603
+ } catch (error) {
44604
+ if (this.config.debug) {
44605
+ log.warn(`\u26A0\uFE0F Vault address derivation error for loan ${loan.id}`, {
44606
+ error: error instanceof Error ? error.message : String(error)
44607
+ });
44608
+ }
44609
+ }
44610
+ })
44611
+ );
44612
+ }
44613
+ if (this.config.debug) {
44614
+ log.info(`\u2705 Completed vault address enrichment for ${loans.length} loans`);
44615
+ }
44616
+ return loans;
44617
+ }
44559
44618
  /**
44560
44619
  * Map numeric status to string for subgraph queries
44561
44620
  */
@@ -46539,6 +46598,32 @@ var DiamondHandsGraph = class {
46539
46598
  });
46540
46599
  this.defaultPageSize = config.defaultPageSize ?? 100;
46541
46600
  }
46601
+ /**
46602
+ * Transform graph position data to LoanData interface
46603
+ * Converts flat graph structure to nested LoanData structure
46604
+ */
46605
+ transformGraphPositionToLoanData(graphPosition) {
46606
+ return {
46607
+ id: graphPosition.id,
46608
+ pkpId: graphPosition.pkpId,
46609
+ borrower: {
46610
+ createdAt: graphPosition.borrower?.createdAt ? Number(graphPosition.borrower.createdAt) : 0,
46611
+ id: graphPosition.borrower?.id || graphPosition.borrower
46612
+ },
46613
+ createdAt: graphPosition.createdAt ? Number(graphPosition.createdAt) : 0,
46614
+ lastUpdatedAt: graphPosition.lastUpdated ? Number(graphPosition.lastUpdated) : 0,
46615
+ loan: {
46616
+ ucdMinted: graphPosition.ucdMinted ? Number(graphPosition.ucdMinted) : 0,
46617
+ ucdDebt: graphPosition.ucdDebt ? Number(graphPosition.ucdDebt) : 0,
46618
+ selectedTerm: graphPosition.selectedTerm ? Number(graphPosition.selectedTerm) : 0,
46619
+ status: graphPosition.status,
46620
+ expiryAt: graphPosition.expiryAt ? Number(graphPosition.expiryAt) : 0
46621
+ },
46622
+ collateral: {
46623
+ vaultAddress: graphPosition.vaultAddress || ""
46624
+ }
46625
+ };
46626
+ }
46542
46627
  /**
46543
46628
  * Helper: Get total count by paginating through all results
46544
46629
  * The Graph has a hard limit of 1000 items per query, so we need to paginate
@@ -46607,6 +46692,7 @@ var DiamondHandsGraph = class {
46607
46692
  id
46608
46693
  }
46609
46694
  # btcAmount removed - balance is now queried on-chain via lit-actions with signature validation
46695
+ ucdMinted
46610
46696
  ucdDebt
46611
46697
  collateralRatio
46612
46698
  requestedCollateralRatio
@@ -46615,8 +46701,9 @@ var DiamondHandsGraph = class {
46615
46701
  createdAt
46616
46702
  createdAtBlock
46617
46703
  lastUpdated
46618
- originalTerm
46704
+ originalTerm
46619
46705
  remainingDebt
46706
+ expiryAt
46620
46707
  }
46621
46708
  }
46622
46709
  }
@@ -46638,7 +46725,7 @@ var DiamondHandsGraph = class {
46638
46725
  );
46639
46726
  let positions = [];
46640
46727
  if (result && result.user && Array.isArray(result.user.positions)) {
46641
- positions = result.user.positions.filter((p) => p != null);
46728
+ positions = result.user.positions.filter((p) => p != null).map((p) => this.transformGraphPositionToLoanData(p));
46642
46729
  }
46643
46730
  return {
46644
46731
  positions,
@@ -46874,17 +46961,19 @@ var DiamondHandsGraph = class {
46874
46961
  createdAt
46875
46962
  id
46876
46963
  }
46964
+ ucdMinted
46965
+ ucdDebt
46877
46966
  collateralRatio
46878
46967
  requestedCollateralRatio
46968
+ selectedTerm
46969
+ status
46879
46970
  createdAt
46880
46971
  createdAtBlock
46881
46972
  lastUpdated
46882
46973
  lastUpdatedAtBlock
46883
46974
  originalTerm
46884
46975
  remainingDebt
46885
- selectedTerm
46886
- status
46887
- ucdDebt
46976
+ expiryAt
46888
46977
  totalPaid
46889
46978
  totalExtensions
46890
46979
  extensionFeesPaid
@@ -46897,8 +46986,11 @@ var DiamondHandsGraph = class {
46897
46986
  { first, skip, orderBy, orderDirection }
46898
46987
  );
46899
46988
  const total = await this.getTotalCountPaginated();
46989
+ const transformedPositions = (result.positions || []).map(
46990
+ (p) => this.transformGraphPositionToLoanData(p)
46991
+ );
46900
46992
  return {
46901
- positions: result.positions || [],
46993
+ positions: transformedPositions,
46902
46994
  total
46903
46995
  };
46904
46996
  }
@@ -46918,15 +47010,17 @@ var DiamondHandsGraph = class {
46918
47010
  id
46919
47011
  pkpId
46920
47012
  borrower { createdAt id }
47013
+ ucdMinted
47014
+ ucdDebt
46921
47015
  collateralRatio
47016
+ selectedTerm
47017
+ status
46922
47018
  createdAt
46923
47019
  createdAtBlock
46924
47020
  lastUpdated
46925
47021
  originalTerm
46926
47022
  remainingDebt
46927
- selectedTerm
46928
- status
46929
- ucdDebt
47023
+ expiryAt
46930
47024
  }
46931
47025
  }
46932
47026
  `;
@@ -46938,8 +47032,11 @@ var DiamondHandsGraph = class {
46938
47032
  "{ status_in: $statuses }",
46939
47033
  { statuses }
46940
47034
  );
47035
+ const transformedPositions = (result.positions || []).map(
47036
+ (p) => this.transformGraphPositionToLoanData(p)
47037
+ );
46941
47038
  return {
46942
- positions: result.positions || [],
47039
+ positions: transformedPositions,
46943
47040
  total
46944
47041
  };
46945
47042
  }
@@ -47815,6 +47912,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
47815
47912
  const loanQueryResult = createLoanQuery({
47816
47913
  graphClient: this.graphClient,
47817
47914
  bitcoinOperations: this.bitcoinOperations,
47915
+ provider: config.provider,
47818
47916
  cache: this.cacheManager.getCache("loan-data", {
47819
47917
  maxSize: 200,
47820
47918
  ttlMs: 3e4
package/dist/index.mjs CHANGED
@@ -44319,6 +44319,7 @@ function createLoanCreator(config) {
44319
44319
  }
44320
44320
 
44321
44321
  // src/modules/loan/loan-query.module.ts
44322
+ init_mint_authorization_utils();
44322
44323
  var LoanQuery = class {
44323
44324
  config;
44324
44325
  defaultPageSize;
@@ -44446,8 +44447,9 @@ var LoanQuery = class {
44446
44447
  skip
44447
44448
  );
44448
44449
  }
44450
+ const enrichedLoans = await this.enrichLoansWithVaultAddresses(result.positions);
44449
44451
  return {
44450
- loans: result.positions,
44452
+ loans: enrichedLoans,
44451
44453
  page,
44452
44454
  maxRows: pageSize,
44453
44455
  totalLoans: result.total
@@ -44462,6 +44464,63 @@ var LoanQuery = class {
44462
44464
  })
44463
44465
  );
44464
44466
  }
44467
+ /**
44468
+ * Enrich loans with vault addresses derived from PKP public keys
44469
+ *
44470
+ * @param loans - Array of loans to enrich
44471
+ * @returns Enriched loans with vault addresses for all networks
44472
+ */
44473
+ async enrichLoansWithVaultAddresses(loans) {
44474
+ if (!loans || loans.length === 0) {
44475
+ return loans;
44476
+ }
44477
+ if (this.config.debug) {
44478
+ log.info(`\u{1F511} Enriching ${loans.length} loans with vault addresses...`);
44479
+ }
44480
+ const BATCH_SIZE = 15;
44481
+ for (let i = 0; i < loans.length; i += BATCH_SIZE) {
44482
+ const batch = loans.slice(i, i + BATCH_SIZE);
44483
+ await Promise.all(
44484
+ batch.map(async (loan) => {
44485
+ try {
44486
+ const pkpPublicKey = await getPKPPublicKeyFromTokenId(
44487
+ loan.pkpId,
44488
+ this.config.provider
44489
+ );
44490
+ const addressesResult = await this.config.bitcoinOperations.deriveAddresses(
44491
+ pkpPublicKey
44492
+ );
44493
+ if (addressesResult.success) {
44494
+ loan.collateral.vaultAddress = addressesResult.value;
44495
+ if (this.config.debug) {
44496
+ log.info(`\u2705 Derived vault addresses for loan ${loan.id}`, {
44497
+ mainnet: addressesResult.value.mainnet,
44498
+ testnet: addressesResult.value.testnet,
44499
+ regtest: addressesResult.value.regtest
44500
+ });
44501
+ }
44502
+ } else {
44503
+ if (this.config.debug) {
44504
+ log.warn(`\u26A0\uFE0F Failed to derive vault addresses for loan ${loan.id}`, {
44505
+ error: addressesResult.error.message
44506
+ });
44507
+ }
44508
+ }
44509
+ } catch (error) {
44510
+ if (this.config.debug) {
44511
+ log.warn(`\u26A0\uFE0F Vault address derivation error for loan ${loan.id}`, {
44512
+ error: error instanceof Error ? error.message : String(error)
44513
+ });
44514
+ }
44515
+ }
44516
+ })
44517
+ );
44518
+ }
44519
+ if (this.config.debug) {
44520
+ log.info(`\u2705 Completed vault address enrichment for ${loans.length} loans`);
44521
+ }
44522
+ return loans;
44523
+ }
44465
44524
  /**
44466
44525
  * Map numeric status to string for subgraph queries
44467
44526
  */
@@ -46445,6 +46504,32 @@ var DiamondHandsGraph = class {
46445
46504
  });
46446
46505
  this.defaultPageSize = config.defaultPageSize ?? 100;
46447
46506
  }
46507
+ /**
46508
+ * Transform graph position data to LoanData interface
46509
+ * Converts flat graph structure to nested LoanData structure
46510
+ */
46511
+ transformGraphPositionToLoanData(graphPosition) {
46512
+ return {
46513
+ id: graphPosition.id,
46514
+ pkpId: graphPosition.pkpId,
46515
+ borrower: {
46516
+ createdAt: graphPosition.borrower?.createdAt ? Number(graphPosition.borrower.createdAt) : 0,
46517
+ id: graphPosition.borrower?.id || graphPosition.borrower
46518
+ },
46519
+ createdAt: graphPosition.createdAt ? Number(graphPosition.createdAt) : 0,
46520
+ lastUpdatedAt: graphPosition.lastUpdated ? Number(graphPosition.lastUpdated) : 0,
46521
+ loan: {
46522
+ ucdMinted: graphPosition.ucdMinted ? Number(graphPosition.ucdMinted) : 0,
46523
+ ucdDebt: graphPosition.ucdDebt ? Number(graphPosition.ucdDebt) : 0,
46524
+ selectedTerm: graphPosition.selectedTerm ? Number(graphPosition.selectedTerm) : 0,
46525
+ status: graphPosition.status,
46526
+ expiryAt: graphPosition.expiryAt ? Number(graphPosition.expiryAt) : 0
46527
+ },
46528
+ collateral: {
46529
+ vaultAddress: graphPosition.vaultAddress || ""
46530
+ }
46531
+ };
46532
+ }
46448
46533
  /**
46449
46534
  * Helper: Get total count by paginating through all results
46450
46535
  * The Graph has a hard limit of 1000 items per query, so we need to paginate
@@ -46513,6 +46598,7 @@ var DiamondHandsGraph = class {
46513
46598
  id
46514
46599
  }
46515
46600
  # btcAmount removed - balance is now queried on-chain via lit-actions with signature validation
46601
+ ucdMinted
46516
46602
  ucdDebt
46517
46603
  collateralRatio
46518
46604
  requestedCollateralRatio
@@ -46521,8 +46607,9 @@ var DiamondHandsGraph = class {
46521
46607
  createdAt
46522
46608
  createdAtBlock
46523
46609
  lastUpdated
46524
- originalTerm
46610
+ originalTerm
46525
46611
  remainingDebt
46612
+ expiryAt
46526
46613
  }
46527
46614
  }
46528
46615
  }
@@ -46544,7 +46631,7 @@ var DiamondHandsGraph = class {
46544
46631
  );
46545
46632
  let positions = [];
46546
46633
  if (result && result.user && Array.isArray(result.user.positions)) {
46547
- positions = result.user.positions.filter((p) => p != null);
46634
+ positions = result.user.positions.filter((p) => p != null).map((p) => this.transformGraphPositionToLoanData(p));
46548
46635
  }
46549
46636
  return {
46550
46637
  positions,
@@ -46780,17 +46867,19 @@ var DiamondHandsGraph = class {
46780
46867
  createdAt
46781
46868
  id
46782
46869
  }
46870
+ ucdMinted
46871
+ ucdDebt
46783
46872
  collateralRatio
46784
46873
  requestedCollateralRatio
46874
+ selectedTerm
46875
+ status
46785
46876
  createdAt
46786
46877
  createdAtBlock
46787
46878
  lastUpdated
46788
46879
  lastUpdatedAtBlock
46789
46880
  originalTerm
46790
46881
  remainingDebt
46791
- selectedTerm
46792
- status
46793
- ucdDebt
46882
+ expiryAt
46794
46883
  totalPaid
46795
46884
  totalExtensions
46796
46885
  extensionFeesPaid
@@ -46803,8 +46892,11 @@ var DiamondHandsGraph = class {
46803
46892
  { first, skip, orderBy, orderDirection }
46804
46893
  );
46805
46894
  const total = await this.getTotalCountPaginated();
46895
+ const transformedPositions = (result.positions || []).map(
46896
+ (p) => this.transformGraphPositionToLoanData(p)
46897
+ );
46806
46898
  return {
46807
- positions: result.positions || [],
46899
+ positions: transformedPositions,
46808
46900
  total
46809
46901
  };
46810
46902
  }
@@ -46824,15 +46916,17 @@ var DiamondHandsGraph = class {
46824
46916
  id
46825
46917
  pkpId
46826
46918
  borrower { createdAt id }
46919
+ ucdMinted
46920
+ ucdDebt
46827
46921
  collateralRatio
46922
+ selectedTerm
46923
+ status
46828
46924
  createdAt
46829
46925
  createdAtBlock
46830
46926
  lastUpdated
46831
46927
  originalTerm
46832
46928
  remainingDebt
46833
- selectedTerm
46834
- status
46835
- ucdDebt
46929
+ expiryAt
46836
46930
  }
46837
46931
  }
46838
46932
  `;
@@ -46844,8 +46938,11 @@ var DiamondHandsGraph = class {
46844
46938
  "{ status_in: $statuses }",
46845
46939
  { statuses }
46846
46940
  );
46941
+ const transformedPositions = (result.positions || []).map(
46942
+ (p) => this.transformGraphPositionToLoanData(p)
46943
+ );
46847
46944
  return {
46848
- positions: result.positions || [],
46945
+ positions: transformedPositions,
46849
46946
  total
46850
46947
  };
46851
46948
  }
@@ -47721,6 +47818,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
47721
47818
  const loanQueryResult = createLoanQuery({
47722
47819
  graphClient: this.graphClient,
47723
47820
  bitcoinOperations: this.bitcoinOperations,
47821
+ provider: config.provider,
47724
47822
  cache: this.cacheManager.getCache("loan-data", {
47725
47823
  maxSize: 200,
47726
47824
  ttlMs: 3e4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.96",
3
+ "version": "0.0.98",
4
4
  "description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.ts",