@gvnrdao/dh-mcp 0.5.5 → 0.5.6

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/boundary.js CHANGED
@@ -23446,6 +23446,7 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23446
23446
  exports2.fetchLitActionCodeFromIpfs = fetchLitActionCodeFromIpfs;
23447
23447
  var axios_1 = __importDefault(require_axios());
23448
23448
  var ipfsCodeCache = /* @__PURE__ */ new Map();
23449
+ var GATEWAY_TIMEOUT_MS = 2e4;
23449
23450
  var buildGatewayList = (cid, pinataJwt) => {
23450
23451
  const gateways = [];
23451
23452
  if (pinataJwt) {
@@ -23454,7 +23455,7 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23454
23455
  headers: { Authorization: `Bearer ${pinataJwt}` }
23455
23456
  });
23456
23457
  }
23457
- gateways.push({ url: `https://${cid}.ipfs.dweb.link/` }, { url: `https://dweb.link/ipfs/${cid}` }, { url: `https://ipfs.io/ipfs/${cid}` }, { url: `https://gateway.pinata.cloud/ipfs/${cid}` }, { url: `https://cloudflare-ipfs.com/ipfs/${cid}` });
23458
+ gateways.push({ url: `https://${cid}.ipfs.dweb.link/` }, { url: `https://dweb.link/ipfs/${cid}` }, { url: `https://ipfs.io/ipfs/${cid}` }, { url: `https://gateway.pinata.cloud/ipfs/${cid}` });
23458
23459
  return gateways;
23459
23460
  };
23460
23461
  async function fetchLitActionCodeFromIpfs(cid, options = {}) {
@@ -23468,13 +23469,14 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23468
23469
  const pinataJwt = options.pinataJwt ?? process.env.PINATA_JWT;
23469
23470
  const extraGateways = options.extraGateways?.map((t) => ({ url: t.replace("{cid}", cid) })) ?? [];
23470
23471
  const gateways = [...extraGateways, ...buildGatewayList(cid, pinataJwt)];
23472
+ const failures = [];
23471
23473
  for (const gateway of gateways) {
23472
23474
  try {
23473
23475
  if (options.debug) {
23474
23476
  console.log(`\u{1F4E1} [fetchLitActionCodeFromIpfs] Trying ${gateway.url}...`);
23475
23477
  }
23476
23478
  const response = await axios_1.default.get(gateway.url, {
23477
- timeout: 1e4,
23479
+ timeout: GATEWAY_TIMEOUT_MS,
23478
23480
  headers: {
23479
23481
  Accept: "text/plain, application/javascript, text/javascript",
23480
23482
  ...gateway.headers
@@ -23487,13 +23489,17 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23487
23489
  ipfsCodeCache.set(cid, response.data);
23488
23490
  return response.data;
23489
23491
  }
23492
+ failures.push(`${gateway.url}: HTTP ${response.status} returned ${typeof response.data}, expected string`);
23490
23493
  } catch (error) {
23494
+ const message = error instanceof Error ? error.message : String(error);
23495
+ failures.push(`${gateway.url}: ${message}`);
23491
23496
  if (options.debug) {
23492
- console.log(`\u274C [fetchLitActionCodeFromIpfs] ${gateway.url}:`, error instanceof Error ? error.message : error);
23497
+ console.log(`\u274C [fetchLitActionCodeFromIpfs] ${gateway.url}:`, message);
23493
23498
  }
23494
23499
  }
23495
23500
  }
23496
- throw new Error(`Failed to fetch LIT Action from IPFS CID: ${cid}`);
23501
+ throw new Error(`Failed to fetch LIT Action from IPFS CID: ${cid} \u2014 all ${gateways.length} gateway(s) failed:
23502
+ ` + failures.map((f) => ` - ${f}`).join("\n"));
23497
23503
  }
23498
23504
  }
23499
23505
  });
@@ -50788,6 +50794,14 @@ var init_deployment_addresses = __esm2({
50788
50794
  reason: "2026-08 agent-stack release. The mainnet PositionManagerViews at 0x9225647a was deployed as a BARE implementation (EIP-1967 slot 0x00), so upgradeToAndCall reverts UUPSUnauthorizedCallContext \u2014 it could never be upgraded. PositionManager.setViews (added in the same Execute B batch) removed the repoint blocker, so Views was replaced behind a new proxy rather than upgraded. This makes the Pashov F3 renewal debt-ceiling check REACHABLE for the first time: ExceedsMaxLoan (0x499e7985) is present in 0xE68DC096 and absent from 0x9225647a. Views holds no protocol state (8 wiring slots + roles + pause), which is what made replacement safe. The old contract is ABANDONED, not decommissioned \u2014 it stays live and callable as the rollback target for setViews. NOTE: VERSION reads 1.1.1 on both sides; verify by address.",
50789
50795
  executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
50790
50796
  block: 25673200
50797
+ },
50798
+ AgentDelegationRegistry: {
50799
+ newImplementation: "0xa9fF405Edd4329fc3159a64F56B37EBD253e4928",
50800
+ upgradedAt: "2026-07-31T22:03:35.000Z",
50801
+ upgradedBy: "AdminModule/Safe audit-batch upgradeToAndCall; executed by 0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f in tx 0x8fed0ab7eee3aaaa3792a35b40b0ef74bd09cfb1a175934afd846bee546048d4 (block 25655710)",
50802
+ reason: "Reconciled from chain \u2014 mainnet audit rollout batch (cross-ref onchain-auth/.safe-batches/mainnet-audit-execute.json)",
50803
+ executeTx: "0x8fed0ab7eee3aaaa3792a35b40b0ef74bd09cfb1a175934afd846bee546048d4",
50804
+ block: 25655710
50791
50805
  }
50792
50806
  },
50793
50807
  latestEnv: {
@@ -62067,6 +62081,169 @@ function normalizePkpId2(pkpId) {
62067
62081
  }
62068
62082
  return pkpId;
62069
62083
  }
62084
+ function hasLoanEventsFilter(filter2) {
62085
+ if (!filter2)
62086
+ return false;
62087
+ return filter2.eventTypes !== void 0 || filter2.fromTimestamp !== void 0 || filter2.toTimestamp !== void 0 || filter2.fromBlock !== void 0 || filter2.toBlock !== void 0 || filter2.limit !== void 0 || filter2.orderDirection !== void 0;
62088
+ }
62089
+ var WALLET_LOAN_EVENTS_QUERY = `
62090
+ query GetWalletLoanEvents($borrower: Bytes!, $first: Int!, $limit: Int!, $orderDirection: OrderDirection!) {
62091
+ positions(where: { borrower: $borrower }, first: $first, orderBy: id) {
62092
+ id
62093
+ payments(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62094
+ id
62095
+ payer { id }
62096
+ amount
62097
+ type
62098
+ transactionHash
62099
+ timestamp
62100
+ blockNumber
62101
+ logIndex
62102
+ newDebt
62103
+ newCollateralRatio
62104
+ }
62105
+ statusUpdates(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62106
+ id
62107
+ oldStatus
62108
+ newStatus
62109
+ reason
62110
+ timestamp
62111
+ blockNumber
62112
+ transactionHash
62113
+ }
62114
+ liquidation {
62115
+ id
62116
+ liquidator
62117
+ liquidatedAmount
62118
+ collateralSeized
62119
+ transactionHash
62120
+ timestamp
62121
+ blockNumber
62122
+ commitHash
62123
+ commitTimestamp
62124
+ revealDelay
62125
+ }
62126
+ withdrawals(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62127
+ id
62128
+ withdrawalAmount
62129
+ withdrawalAddress
62130
+ networkFee
62131
+ timestamp
62132
+ blockNumber
62133
+ transactionHash
62134
+ logIndex
62135
+ }
62136
+ renewals(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62137
+ id
62138
+ extensionTerm
62139
+ extensionFee
62140
+ newExpiryDate
62141
+ timestamp
62142
+ blockNumber
62143
+ transactionHash
62144
+ logIndex
62145
+ }
62146
+ operationFailures(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62147
+ id
62148
+ operationType
62149
+ reason
62150
+ errorCode
62151
+ amount
62152
+ timestamp
62153
+ blockNumber
62154
+ transactionHash
62155
+ logIndex
62156
+ }
62157
+ mintRequests(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62158
+ id
62159
+ pkpId
62160
+ borrower { id }
62161
+ mintAmount
62162
+ originationFee
62163
+ newDebt
62164
+ newCollateralRatio
62165
+ btcPrice
62166
+ quantumTimestamp
62167
+ opId
62168
+ timestamp
62169
+ blockNumber
62170
+ transactionHash
62171
+ logIndex
62172
+ }
62173
+ burnRequests(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62174
+ id
62175
+ pkpId
62176
+ borrower { id }
62177
+ burnAmount
62178
+ remainingDebt
62179
+ newCollateralRatio
62180
+ opId
62181
+ timestamp
62182
+ blockNumber
62183
+ transactionHash
62184
+ logIndex
62185
+ }
62186
+ mintingFees(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62187
+ id
62188
+ borrower { id }
62189
+ feeAmount
62190
+ mintAmount
62191
+ newDebt
62192
+ btcPrice
62193
+ quantumTimestamp
62194
+ timestamp
62195
+ blockNumber
62196
+ transactionHash
62197
+ logIndex
62198
+ }
62199
+ renewalFees(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62200
+ id
62201
+ borrower { id }
62202
+ feeAmount
62203
+ extensionTerm
62204
+ newExpiryDate
62205
+ timestamp
62206
+ blockNumber
62207
+ transactionHash
62208
+ logIndex
62209
+ }
62210
+ positionCreatedEvents(first: 1, orderBy: timestamp, orderDirection: asc) {
62211
+ id
62212
+ pkpId
62213
+ borrower { id }
62214
+ requestedCollateralRatio
62215
+ selectedTerm
62216
+ expiryAt
62217
+ timestamp
62218
+ blockNumber
62219
+ transactionHash
62220
+ }
62221
+ }
62222
+ ucdmintEvents(where: { position_: { borrower: $borrower } }, first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62223
+ id
62224
+ position { id }
62225
+ amount
62226
+ proof
62227
+ minter { id }
62228
+ isCommunityMint
62229
+ timestamp
62230
+ blockNumber
62231
+ transactionHash
62232
+ }
62233
+ collateralEvents(where: { position_: { borrower: $borrower } }, first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62234
+ id
62235
+ position { id }
62236
+ eventType
62237
+ networkFee
62238
+ remainingCollateral
62239
+ collateralRatio
62240
+ timestamp
62241
+ blockNumber
62242
+ transactionHash
62243
+ logIndex
62244
+ }
62245
+ }
62246
+ `;
62070
62247
  var DiamondHandsGraph = class {
62071
62248
  client;
62072
62249
  defaultPageSize;
@@ -62172,7 +62349,7 @@ var DiamondHandsGraph = class {
62172
62349
  /**
62173
62350
  * Get user positions from subgraph
62174
62351
  */
62175
- async getUserPositions(userAddress, first, skip, orderBy, orderDirection) {
62352
+ async getUserPositionsOnly(userAddress, first, skip, orderBy, orderDirection) {
62176
62353
  const query = `
62177
62354
  query GetUserPositions($borrower: Bytes!, $first: Int, $skip: Int, $orderBy: Position_orderBy, $orderDirection: OrderDirection) {
62178
62355
  user(id: $borrower) {
@@ -62213,17 +62390,28 @@ var DiamondHandsGraph = class {
62213
62390
  query,
62214
62391
  variables
62215
62392
  );
62216
- const total = await this.getTotalCountPaginated("{ borrower: $borrower }", {
62217
- borrower: userAddress.toLowerCase()
62218
- });
62219
62393
  let positions = [];
62220
62394
  if (result && result.user && Array.isArray(result.user.positions)) {
62221
62395
  positions = result.user.positions.filter((p) => p != null).map((p) => this.transformGraphPositionToLoanData(p));
62222
62396
  }
62223
- return {
62224
- positions,
62225
- total
62226
- };
62397
+ return positions;
62398
+ }
62399
+ /**
62400
+ * Get user positions, plus an accurate total count.
62401
+ *
62402
+ * The count is a SECOND round trip (`getTotalCountPaginated`, which pages to handle
62403
+ * >1000 items). Callers that only need the rows should use `getUserPositionsOnly` and
62404
+ * skip it — the event paths did not, and paid for a count they immediately discarded on
62405
+ * every activity refresh.
62406
+ */
62407
+ async getUserPositions(userAddress, first, skip, orderBy, orderDirection) {
62408
+ const [positions, total] = await Promise.all([
62409
+ this.getUserPositionsOnly(userAddress, first, skip, orderBy, orderDirection),
62410
+ this.getTotalCountPaginated("{ borrower: $borrower }", {
62411
+ borrower: userAddress.toLowerCase()
62412
+ })
62413
+ ]);
62414
+ return { positions, total };
62227
62415
  }
62228
62416
  /**
62229
62417
  * Get user positions with enriched Bitcoin balance data
@@ -63314,6 +63502,16 @@ var DiamondHandsGraph = class {
63314
63502
  orderDirection
63315
63503
  };
63316
63504
  const result = await this.client.execute(query, variables);
63505
+ return this.assembleLoanEvents(positionId, result);
63506
+ }
63507
+ /**
63508
+ * Map one position's raw event payload into `LoanEvents`.
63509
+ *
63510
+ * Extracted verbatim from getLoanEvents so the wallet-collapsed path produces
63511
+ * byte-identical objects by construction rather than by a second implementation
63512
+ * that has to be kept in step by hand.
63513
+ */
63514
+ assembleLoanEvents(positionId, result) {
63317
63515
  const rawCreated = result.positionCreatedEvents?.[0];
63318
63516
  const positionCreated = rawCreated ? {
63319
63517
  id: rawCreated.id,
@@ -63518,7 +63716,22 @@ var DiamondHandsGraph = class {
63518
63716
  * @returns One LoanEvents object per position; empty array if the wallet has none.
63519
63717
  */
63520
63718
  async getWalletLoanEvents(userAddress, filter2) {
63521
- const { positions } = await this.getUserPositions(userAddress);
63719
+ if (!hasLoanEventsFilter(filter2)) {
63720
+ return this.getWalletLoanEventsCollapsed(userAddress);
63721
+ }
63722
+ return this.getWalletLoanEventsFanout(userAddress, filter2);
63723
+ }
63724
+ /**
63725
+ * The per-position path: enumerate the wallet's positions, then one `GetLoanEvents` each.
63726
+ *
63727
+ * Used for filtered calls, and as the completeness fallback when the collapsed document
63728
+ * hits a page limit. Costs `1 + N` requests, which is exactly why it is not the default.
63729
+ */
63730
+ async getWalletLoanEventsFanout(userAddress, filter2) {
63731
+ const positions = await this.getUserPositionsOnly(
63732
+ userAddress,
63733
+ THE_GRAPH_MAX_BATCH_SIZE
63734
+ );
63522
63735
  const positionIds = positions.map((p) => p?.id != null ? String(p.id) : "").filter((id) => id.length > 0);
63523
63736
  if (positionIds.length === 0)
63524
63737
  return [];
@@ -63533,6 +63746,81 @@ var DiamondHandsGraph = class {
63533
63746
  }
63534
63747
  return results;
63535
63748
  }
63749
+ /**
63750
+ * The whole wallet's event history in ONE request.
63751
+ *
63752
+ * Replaces `1 + N` round trips (one position enumeration plus one per position) with a
63753
+ * single document. Measured on Sepolia: a wallet holding 44 positions cost 46 requests
63754
+ * per activity refresh against a per-wallet budget of 30/min — this makes it 1.
63755
+ *
63756
+ * Three subgraph facts make it possible, all verified against the deployed schema rather
63757
+ * than assumed:
63758
+ * - ten event collections are `@derivedFrom` on Position, so they nest under a
63759
+ * borrower-filtered `positions(...)`;
63760
+ * - `positionCreatedEvents` is ALSO derived on Position — `getLoanEvents` queries it
63761
+ * top-level, which it never needed to;
63762
+ * - `ucdmintEvents` / `collateralEvents` are not derived and carry no `borrower`
63763
+ * field, but graph-node's nested `position_: { borrower }` filter reaches them.
63764
+ * Without that last one this would be two requests, not one.
63765
+ */
63766
+ async getWalletLoanEventsCollapsed(userAddress) {
63767
+ const borrower = userAddress.toLowerCase();
63768
+ const pageSize = THE_GRAPH_MAX_BATCH_SIZE;
63769
+ const result = await this.client.execute(
63770
+ WALLET_LOAN_EVENTS_QUERY,
63771
+ {
63772
+ borrower,
63773
+ first: pageSize,
63774
+ limit: pageSize,
63775
+ orderDirection: "desc"
63776
+ }
63777
+ );
63778
+ const positions = result.positions || [];
63779
+ const ucdmintEvents = result.ucdmintEvents || [];
63780
+ const collateralEvents = result.collateralEvents || [];
63781
+ const truncated = positions.length >= pageSize || ucdmintEvents.length >= pageSize || collateralEvents.length >= pageSize;
63782
+ if (truncated) {
63783
+ log.warn(
63784
+ "[DiamondHandsGraph] wallet event page limit reached \u2014 falling back to the per-position path to avoid returning a partial history",
63785
+ {
63786
+ borrower,
63787
+ pageSize,
63788
+ positions: positions.length,
63789
+ ucdmintEvents: ucdmintEvents.length,
63790
+ collateralEvents: collateralEvents.length
63791
+ }
63792
+ );
63793
+ return this.getWalletLoanEventsFanout(userAddress);
63794
+ }
63795
+ if (positions.length === 0)
63796
+ return [];
63797
+ const mintsByPosition = /* @__PURE__ */ new Map();
63798
+ for (const m of result.ucdmintEvents || []) {
63799
+ const key = m.position?.id;
63800
+ if (!key)
63801
+ continue;
63802
+ const bucket = mintsByPosition.get(key) || [];
63803
+ bucket.push(m);
63804
+ mintsByPosition.set(key, bucket);
63805
+ }
63806
+ const collateralByPosition = /* @__PURE__ */ new Map();
63807
+ for (const c of result.collateralEvents || []) {
63808
+ const key = c.position?.id;
63809
+ if (!key)
63810
+ continue;
63811
+ const bucket = collateralByPosition.get(key) || [];
63812
+ bucket.push(c);
63813
+ collateralByPosition.set(key, bucket);
63814
+ }
63815
+ return positions.map(
63816
+ (p) => this.assembleLoanEvents(p.id, {
63817
+ position: p,
63818
+ positionCreatedEvents: p.positionCreatedEvents || [],
63819
+ ucdmintEvents: mintsByPosition.get(p.id) || [],
63820
+ collateralEvents: collateralByPosition.get(p.id) || []
63821
+ })
63822
+ );
63823
+ }
63536
63824
  // ============================================================================
63537
63825
  // Protocol-wide Events
63538
63826
  // ============================================================================
@@ -68392,16 +68680,6 @@ function createMockTokenManager(config) {
68392
68680
  }
68393
68681
  }
68394
68682
  var import_dh_lit_actions2 = __toESM2(require_pkg_src2());
68395
- var TelegramBot = null;
68396
- try {
68397
- if (typeof window === "undefined" && typeof global !== "undefined") {
68398
- TelegramBot = null /* stubbed post-build: dh-mcp never uses telegram (F-PUB-2) */;
68399
- }
68400
- } catch (error) {
68401
- log.warn("Telegram bot API not available", {
68402
- error: error instanceof Error ? error.message : String(error)
68403
- });
68404
- }
68405
68683
  function formatMintMessage(mintAmount, loanId, txHash) {
68406
68684
  return `\u2705 DH SDK: ${mintAmount} UCD was minted for loan id: ${loanId} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
68407
68685
  }