@gvnrdao/dh-lit-actions 0.0.26 → 0.0.28

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.
@@ -1 +1 @@
1
- 67b3e25a63ce9b806d451025ee95ddfb0e3104c29602fab79b4fb986ff88ce9b
1
+ 5cf86424936e8691f73e6ff8b9a905da15de40ef883495b9cfe79becaaee2c95
@@ -135,22 +135,42 @@ var _LIT_ACTION_ = (() => {
135
135
  }
136
136
 
137
137
  // src/constants/chunks/bitcoin-network-config.ts
138
- var EVMChain = /* @__PURE__ */ ((EVMChain2) => {
139
- EVMChain2["SEPOLIA"] = "sepolia";
140
- EVMChain2["ETHEREUM"] = "ethereum";
141
- return EVMChain2;
138
+ var EVMChain = /* @__PURE__ */ ((EVMChain3) => {
139
+ EVMChain3["SEPOLIA"] = "sepolia";
140
+ EVMChain3["ETHEREUM"] = "ethereum";
141
+ return EVMChain3;
142
142
  })(EVMChain || {});
143
143
  var CHAIN_TO_BITCOIN_NETWORK = {
144
- ["sepolia" /* SEPOLIA */]: "testnet" /* TESTNET */,
144
+ ["sepolia" /* SEPOLIA */]: "regtest" /* REGTEST */,
145
145
  ["ethereum" /* ETHEREUM */]: "mainnet" /* MAINNET */
146
146
  };
147
147
  var APPROVED_BITCOIN_PROVIDERS = {
148
+ ["regtest" /* REGTEST */]: [
149
+ {
150
+ url: "https://diamond-hands-btc-faucet-6b39a1072059.herokuapp.com/api",
151
+ network: "regtest" /* REGTEST */,
152
+ minConfirmations: 1,
153
+ name: "Diamond Hands"
154
+ },
155
+ {
156
+ url: "http://diamond-hands-btc-faucet-6b39a1072059.herokuapp.com/api",
157
+ network: "regtest" /* REGTEST */,
158
+ minConfirmations: 1,
159
+ name: "Diamond Hands"
160
+ }
161
+ ],
148
162
  ["testnet" /* TESTNET */]: [
149
163
  {
150
164
  url: "https://diamond-hands-btc-faucet-6b39a1072059.herokuapp.com/api",
151
165
  network: "testnet" /* TESTNET */,
152
166
  minConfirmations: 1,
153
- name: "Diamond Hands Faucet"
167
+ name: "Diamond Hands"
168
+ },
169
+ {
170
+ url: "http://diamond-hands-btc-faucet-6b39a1072059.herokuapp.com/api",
171
+ network: "testnet" /* TESTNET */,
172
+ minConfirmations: 1,
173
+ name: "Diamond Hands"
154
174
  }
155
175
  ],
156
176
  ["mainnet" /* MAINNET */]: [
@@ -455,13 +475,14 @@ var _LIT_ACTION_ = (() => {
455
475
  * @returns Array of UTXOs
456
476
  */
457
477
  async getUTXOs(address) {
478
+ const cleanAddress = this.stripNetworkPrefix(address);
458
479
  if (this.config.rpcHelper) {
459
- return await this.fetchUTXOsFromRPC(address);
480
+ return await this.fetchUTXOsFromRPC(cleanAddress);
460
481
  }
461
482
  try {
462
483
  return await this.fetchUTXOsFromProvider(
463
484
  this.config.providerUrl,
464
- address
485
+ cleanAddress
465
486
  );
466
487
  } catch (error) {
467
488
  console.warn(`[Bitcoin Data] Primary provider failed: ${error.message}`);
@@ -474,7 +495,7 @@ var _LIT_ACTION_ = (() => {
474
495
  console.log(
475
496
  `[Bitcoin Data] Trying fallback: ${fallback.name} (${fallback.url})`
476
497
  );
477
- return await this.fetchUTXOsFromProvider(fallback.url, address);
498
+ return await this.fetchUTXOsFromProvider(fallback.url, cleanAddress);
478
499
  } catch (fallbackError) {
479
500
  console.warn(
480
501
  `[Bitcoin Data] Fallback ${fallback.name} failed: ${fallbackError.message}`
@@ -486,6 +507,19 @@ var _LIT_ACTION_ = (() => {
486
507
  throw new Error(`Failed to fetch UTXOs: ${error.message}`);
487
508
  }
488
509
  }
510
+ /**
511
+ * Strip network prefix from Bitcoin address
512
+ *
513
+ * Addresses may be stored with network prefix (e.g., "REGTEST_address")
514
+ * but APIs expect clean addresses without prefix.
515
+ *
516
+ * @param address - Address with optional prefix
517
+ * @returns Clean address without prefix
518
+ */
519
+ stripNetworkPrefix(address) {
520
+ const prefixPattern = /^(REGTEST_|TESTNET_|MAINNET_)/;
521
+ return address.replace(prefixPattern, "");
522
+ }
489
523
  /**
490
524
  * Fetch UTXOs using Bitcoin RPC (for regtest/testing)
491
525
  */
@@ -507,20 +541,6 @@ var _LIT_ACTION_ = (() => {
507
541
  }));
508
542
  return utxos;
509
543
  }
510
- /**
511
- * Detect provider format from URL
512
- *
513
- * Determines which API format a provider uses based on its URL.
514
- *
515
- * @param providerUrl Provider base URL
516
- * @returns Provider format type
517
- */
518
- detectProviderFormat(providerUrl) {
519
- if (providerUrl.includes("diamond-hands-btc-faucet")) {
520
- return "diamond-hands-faucet" /* DIAMOND_HANDS_FAUCET */;
521
- }
522
- return "blockstream" /* BLOCKSTREAM */;
523
- }
524
544
  /**
525
545
  * Parse Diamond Hands Faucet UTXO response
526
546
  *
@@ -586,13 +606,16 @@ var _LIT_ACTION_ = (() => {
586
606
  * - Diamond Hands Faucet: /api/faucet/utxos/{address}
587
607
  */
588
608
  async fetchUTXOsFromProvider(providerUrl, address) {
589
- const format = this.detectProviderFormat(providerUrl);
609
+ const allProviders = Object.values(APPROVED_BITCOIN_PROVIDERS).flat();
610
+ const matched = allProviders.find((p) => p.url === providerUrl);
611
+ const providerName = matched?.name || providerUrl;
590
612
  let endpoint;
591
- if (format === "diamond-hands-faucet" /* DIAMOND_HANDS_FAUCET */) {
592
- endpoint = `${providerUrl}/faucet/utxos/${address}`;
613
+ if (providerName === "Diamond Hands") {
614
+ endpoint = `${providerUrl}/faucet/balance/${address}/utxos`;
593
615
  } else {
594
616
  endpoint = `${providerUrl}/address/${address}/utxos`;
595
617
  }
618
+ console.log(`Fetching UTXOs from ${endpoint}`);
596
619
  const controller = new AbortController();
597
620
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
598
621
  try {
@@ -604,7 +627,7 @@ var _LIT_ACTION_ = (() => {
604
627
  );
605
628
  }
606
629
  const data = await response.json();
607
- if (format === "diamond-hands-faucet" /* DIAMOND_HANDS_FAUCET */) {
630
+ if (providerName === "Diamond Hands") {
608
631
  return this.parseDiamondHandsFaucetUTXOs(data);
609
632
  } else {
610
633
  return this.parseBlockstreamUTXOs(data);
@@ -1477,7 +1500,10 @@ var _LIT_ACTION_ = (() => {
1477
1500
  positionId: position.positionId,
1478
1501
  pkpId: position.pkpId,
1479
1502
  borrower: position.borrower,
1480
- vaultAddress: position.vaultAddress,
1503
+ vaultAddress: this.parseVaultAddress(
1504
+ position.vaultAddress,
1505
+ validateChain(this.config.chain)
1506
+ ),
1481
1507
  ucdDebt: BigInt(position.ucdDebt.toString()),
1482
1508
  termStartTimestamp,
1483
1509
  selectedTerm: selectedTermMonths,
@@ -1486,6 +1512,36 @@ var _LIT_ACTION_ = (() => {
1486
1512
  // Extract loan status enum value (0-7)
1487
1513
  };
1488
1514
  }
1515
+ /**
1516
+ * Parse vault address based on format and network
1517
+ *
1518
+ * Supports two formats:
1519
+ * 1. Single string: "mqM3ZR2N6DzZkafSdFqxEAkWovAU3uYTAN"
1520
+ * 2. JSON object: {"mainnet":"bc1q...","testnet":"mqM3ZR2N6DzZkafSdFqxEAkWovAU3uYTAN"}
1521
+ *
1522
+ * @param rawVaultAddress Raw vault address from contract
1523
+ * @param chain EVM chain (sepolia, ethereum)
1524
+ * @returns Parsed Bitcoin address for the appropriate network
1525
+ */
1526
+ parseVaultAddress(rawVaultAddress, chain) {
1527
+ try {
1528
+ const parsed = JSON.parse(rawVaultAddress);
1529
+ if (typeof parsed === "object" && parsed !== null) {
1530
+ const chainLower = chain.toLowerCase();
1531
+ if (chainLower === "sepolia") {
1532
+ return parsed.regtest || parsed.testnet || parsed.mainnet;
1533
+ }
1534
+ const bitcoinNetwork = getBitcoinNetworkForChain(chain);
1535
+ if (bitcoinNetwork === "testnet" /* TESTNET */) {
1536
+ return parsed.testnet || parsed.regtest || parsed.mainnet;
1537
+ } else {
1538
+ return parsed.mainnet;
1539
+ }
1540
+ }
1541
+ } catch (e) {
1542
+ }
1543
+ return rawVaultAddress;
1544
+ }
1489
1545
  /**
1490
1546
  * Quick check if position is liquidatable
1491
1547
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-lit-actions",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "type": "module",
5
5
  "description": "Diamond Hands Protocol LIT Actions - Deterministic, Auditable Builds",
6
6
  "main": "./pkg-dist/index.cjs",
@@ -17,7 +17,7 @@ exports.DH_LIT_ACTIONS_DATIL = {
17
17
  description: "Production authorization LIT Action for Milestone 1 testing and PKP authorization",
18
18
  version: "0.1.0",
19
19
  deployed: true,
20
- deployedAt: 1761413462458,
20
+ deployedAt: 1761427363916,
21
21
  size: 1016,
22
22
  hash: "c732ef30e50a5013a6c1cbac6dc011d3638875237d21097e3aff722b323d174b",
23
23
  },
@@ -28,7 +28,7 @@ exports.DH_LIT_ACTIONS_DATIL = {
28
28
  description: "Production second dummy authorization LIT Action for testing failed authorization scenarios",
29
29
  version: "0.1.0",
30
30
  deployed: true,
31
- deployedAt: 1761413462458,
31
+ deployedAt: 1761427363915,
32
32
  size: 723,
33
33
  hash: "6262c9467961c661d212b8c60806e499ed5e7d0fe8456e2455e536d40eb4c672",
34
34
  },
@@ -43,7 +43,7 @@ exports.DH_LIT_ACTIONS_DATIL = {
43
43
  size: 12322,
44
44
  hash: "ac5d1dbc1ae8b678f435ac568320887e69e662d93d5f92e11f69e3a322f2e1ef",
45
45
  pkp: {
46
- tokenId: "999461970",
46
+ tokenId: "999363399",
47
47
  publicKey: "0x0411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
48
48
  ethAddress: "0x1111111111111111111111111111111111111111",
49
49
  mintTxHash: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@@ -51,19 +51,19 @@ exports.DH_LIT_ACTIONS_DATIL = {
51
51
  burnTxHash: "0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
52
52
  immutable: true,
53
53
  authorizedCidHex: "0x1220cd432b9afffbf6595071b32888cfe7dd49b571c0afc0c1bea290cdf02e2b66c5",
54
- createdAt: 1761413461970,
54
+ createdAt: 1761427363400,
55
55
  },
56
56
  },
57
57
  ucdMintValidator: {
58
- cid: "QmTmvtVDVVac31CDjJJtQJKUoehE3iCDw6fUUFfsoneiDq", // Placeholder - needs IPFS deployment
58
+ cid: "QmSZQoeajkKiwNrtccpaPBRehxX5hQtnusJPDnGAKcbVSk", // Placeholder - needs IPFS deployment
59
59
  authorizedCidHex: (0, cid_utils_1.cidToHex)("QmNLei78zWmzUdbeRB3CiUfAizWUrbeeZh5K1rhAQKCh51"),
60
60
  name: "UCD Mint Validator",
61
61
  description: "Production UCD mint validator LIT Action for validating mint operations with comprehensive on-chain checks",
62
62
  version: "0.1.0",
63
63
  deployed: true, // Not yet deployed to IPFS
64
- deployedAt: 1761413462459,
65
- size: 34828,
66
- hash: "6c842ec61916b48d7a77ad2ecf7a3567e0c33fd20c3870f8ce97f296f3e4a1a9",
64
+ deployedAt: 1761427363917,
65
+ size: 35512,
66
+ hash: "873cdfb66ff07727655c6066bbea5b8b20a9c336f6d28901caa9dfc9fd14baa2",
67
67
  pkp: {
68
68
  tokenId: "0",
69
69
  publicKey: "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
@@ -86,7 +86,7 @@ exports.DH_LIT_ACTIONS_DATIL_TEST = {
86
86
  description: "Development authorization LIT Action for Milestone 1 testing and PKP authorization on datil-test",
87
87
  version: "0.1.0",
88
88
  deployed: true,
89
- deployedAt: 1761413462458, // Earlier deployment
89
+ deployedAt: 1761427363916, // Earlier deployment
90
90
  size: 1016,
91
91
  hash: "c732ef30e50a5013a6c1cbac6dc011d3638875237d21097e3aff722b323d174b",
92
92
  },
@@ -97,7 +97,7 @@ exports.DH_LIT_ACTIONS_DATIL_TEST = {
97
97
  description: "Development second dummy authorization LIT Action for testing failed authorization scenarios on datil-test",
98
98
  version: "0.1.0",
99
99
  deployed: true, // Not yet deployed to test network
100
- deployedAt: 1761413462458,
100
+ deployedAt: 1761427363915,
101
101
  size: 723,
102
102
  hash: "6262c9467961c661d212b8c60806e499ed5e7d0fe8456e2455e536d40eb4c672",
103
103
  },
@@ -112,7 +112,7 @@ exports.DH_LIT_ACTIONS_DATIL_TEST = {
112
112
  size: 12322,
113
113
  hash: "ac5d1dbc1ae8b678f435ac568320887e69e662d93d5f92e11f69e3a322f2e1ef",
114
114
  pkp: {
115
- tokenId: "999461970",
115
+ tokenId: "999363399",
116
116
  publicKey: "0x0411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
117
117
  ethAddress: "0x1111111111111111111111111111111111111111",
118
118
  mintTxHash: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@@ -120,19 +120,19 @@ exports.DH_LIT_ACTIONS_DATIL_TEST = {
120
120
  burnTxHash: "0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
121
121
  immutable: true,
122
122
  authorizedCidHex: "0x1220cd432b9afffbf6595071b32888cfe7dd49b571c0afc0c1bea290cdf02e2b66c5",
123
- createdAt: 1761413461970,
123
+ createdAt: 1761427363400,
124
124
  },
125
125
  },
126
126
  ucdMintValidator: {
127
- cid: "QmTmvtVDVVac31CDjJJtQJKUoehE3iCDw6fUUFfsoneiDq", // Placeholder - needs IPFS deployment
127
+ cid: "QmSZQoeajkKiwNrtccpaPBRehxX5hQtnusJPDnGAKcbVSk", // Placeholder - needs IPFS deployment
128
128
  authorizedCidHex: (0, cid_utils_1.cidToHex)("QmNLei78zWmzUdbeRB3CiUfAizWUrbeeZh5K1rhAQKCh51"),
129
129
  name: "UCD Mint Validator (Test)",
130
130
  description: "Development UCD mint validator LIT Action for validating mint operations with comprehensive on-chain checks on datil-test",
131
131
  version: "0.1.0",
132
132
  deployed: true, // Not yet deployed to IPFS
133
- deployedAt: 1761413462459,
134
- size: 34828,
135
- hash: "6c842ec61916b48d7a77ad2ecf7a3567e0c33fd20c3870f8ce97f296f3e4a1a9",
133
+ deployedAt: 1761427363917,
134
+ size: 35512,
135
+ hash: "873cdfb66ff07727655c6066bbea5b8b20a9c336f6d28901caa9dfc9fd14baa2",
136
136
  pkp: {
137
137
  tokenId: "0",
138
138
  publicKey: "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",