@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/connector.js CHANGED
@@ -23565,6 +23565,7 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23565
23565
  exports2.fetchLitActionCodeFromIpfs = fetchLitActionCodeFromIpfs;
23566
23566
  var axios_1 = __importDefault(require_axios());
23567
23567
  var ipfsCodeCache = /* @__PURE__ */ new Map();
23568
+ var GATEWAY_TIMEOUT_MS = 2e4;
23568
23569
  var buildGatewayList = (cid, pinataJwt) => {
23569
23570
  const gateways = [];
23570
23571
  if (pinataJwt) {
@@ -23573,7 +23574,7 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23573
23574
  headers: { Authorization: `Bearer ${pinataJwt}` }
23574
23575
  });
23575
23576
  }
23576
- 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}` });
23577
+ 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}` });
23577
23578
  return gateways;
23578
23579
  };
23579
23580
  async function fetchLitActionCodeFromIpfs(cid, options = {}) {
@@ -23587,13 +23588,14 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23587
23588
  const pinataJwt = options.pinataJwt ?? process.env.PINATA_JWT;
23588
23589
  const extraGateways = options.extraGateways?.map((t) => ({ url: t.replace("{cid}", cid) })) ?? [];
23589
23590
  const gateways = [...extraGateways, ...buildGatewayList(cid, pinataJwt)];
23591
+ const failures = [];
23590
23592
  for (const gateway of gateways) {
23591
23593
  try {
23592
23594
  if (options.debug) {
23593
23595
  console.log(`\u{1F4E1} [fetchLitActionCodeFromIpfs] Trying ${gateway.url}...`);
23594
23596
  }
23595
23597
  const response = await axios_1.default.get(gateway.url, {
23596
- timeout: 1e4,
23598
+ timeout: GATEWAY_TIMEOUT_MS,
23597
23599
  headers: {
23598
23600
  Accept: "text/plain, application/javascript, text/javascript",
23599
23601
  ...gateway.headers
@@ -23606,13 +23608,17 @@ var require_fetch_lit_action_from_ipfs = __commonJS({
23606
23608
  ipfsCodeCache.set(cid, response.data);
23607
23609
  return response.data;
23608
23610
  }
23611
+ failures.push(`${gateway.url}: HTTP ${response.status} returned ${typeof response.data}, expected string`);
23609
23612
  } catch (error) {
23613
+ const message = error instanceof Error ? error.message : String(error);
23614
+ failures.push(`${gateway.url}: ${message}`);
23610
23615
  if (options.debug) {
23611
- console.log(`\u274C [fetchLitActionCodeFromIpfs] ${gateway.url}:`, error instanceof Error ? error.message : error);
23616
+ console.log(`\u274C [fetchLitActionCodeFromIpfs] ${gateway.url}:`, message);
23612
23617
  }
23613
23618
  }
23614
23619
  }
23615
- throw new Error(`Failed to fetch LIT Action from IPFS CID: ${cid}`);
23620
+ throw new Error(`Failed to fetch LIT Action from IPFS CID: ${cid} \u2014 all ${gateways.length} gateway(s) failed:
23621
+ ` + failures.map((f) => ` - ${f}`).join("\n"));
23616
23622
  }
23617
23623
  }
23618
23624
  });
@@ -51431,6 +51437,14 @@ var init_deployment_addresses = __esm2({
51431
51437
  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.",
51432
51438
  executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
51433
51439
  block: 25673200
51440
+ },
51441
+ AgentDelegationRegistry: {
51442
+ newImplementation: "0xa9fF405Edd4329fc3159a64F56B37EBD253e4928",
51443
+ upgradedAt: "2026-07-31T22:03:35.000Z",
51444
+ upgradedBy: "AdminModule/Safe audit-batch upgradeToAndCall; executed by 0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f in tx 0x8fed0ab7eee3aaaa3792a35b40b0ef74bd09cfb1a175934afd846bee546048d4 (block 25655710)",
51445
+ reason: "Reconciled from chain \u2014 mainnet audit rollout batch (cross-ref onchain-auth/.safe-batches/mainnet-audit-execute.json)",
51446
+ executeTx: "0x8fed0ab7eee3aaaa3792a35b40b0ef74bd09cfb1a175934afd846bee546048d4",
51447
+ block: 25655710
51434
51448
  }
51435
51449
  },
51436
51450
  latestEnv: {
@@ -62710,6 +62724,169 @@ function normalizePkpId2(pkpId) {
62710
62724
  }
62711
62725
  return pkpId;
62712
62726
  }
62727
+ function hasLoanEventsFilter(filter2) {
62728
+ if (!filter2)
62729
+ return false;
62730
+ 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;
62731
+ }
62732
+ var WALLET_LOAN_EVENTS_QUERY = `
62733
+ query GetWalletLoanEvents($borrower: Bytes!, $first: Int!, $limit: Int!, $orderDirection: OrderDirection!) {
62734
+ positions(where: { borrower: $borrower }, first: $first, orderBy: id) {
62735
+ id
62736
+ payments(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62737
+ id
62738
+ payer { id }
62739
+ amount
62740
+ type
62741
+ transactionHash
62742
+ timestamp
62743
+ blockNumber
62744
+ logIndex
62745
+ newDebt
62746
+ newCollateralRatio
62747
+ }
62748
+ statusUpdates(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62749
+ id
62750
+ oldStatus
62751
+ newStatus
62752
+ reason
62753
+ timestamp
62754
+ blockNumber
62755
+ transactionHash
62756
+ }
62757
+ liquidation {
62758
+ id
62759
+ liquidator
62760
+ liquidatedAmount
62761
+ collateralSeized
62762
+ transactionHash
62763
+ timestamp
62764
+ blockNumber
62765
+ commitHash
62766
+ commitTimestamp
62767
+ revealDelay
62768
+ }
62769
+ withdrawals(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62770
+ id
62771
+ withdrawalAmount
62772
+ withdrawalAddress
62773
+ networkFee
62774
+ timestamp
62775
+ blockNumber
62776
+ transactionHash
62777
+ logIndex
62778
+ }
62779
+ renewals(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62780
+ id
62781
+ extensionTerm
62782
+ extensionFee
62783
+ newExpiryDate
62784
+ timestamp
62785
+ blockNumber
62786
+ transactionHash
62787
+ logIndex
62788
+ }
62789
+ operationFailures(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62790
+ id
62791
+ operationType
62792
+ reason
62793
+ errorCode
62794
+ amount
62795
+ timestamp
62796
+ blockNumber
62797
+ transactionHash
62798
+ logIndex
62799
+ }
62800
+ mintRequests(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62801
+ id
62802
+ pkpId
62803
+ borrower { id }
62804
+ mintAmount
62805
+ originationFee
62806
+ newDebt
62807
+ newCollateralRatio
62808
+ btcPrice
62809
+ quantumTimestamp
62810
+ opId
62811
+ timestamp
62812
+ blockNumber
62813
+ transactionHash
62814
+ logIndex
62815
+ }
62816
+ burnRequests(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62817
+ id
62818
+ pkpId
62819
+ borrower { id }
62820
+ burnAmount
62821
+ remainingDebt
62822
+ newCollateralRatio
62823
+ opId
62824
+ timestamp
62825
+ blockNumber
62826
+ transactionHash
62827
+ logIndex
62828
+ }
62829
+ mintingFees(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62830
+ id
62831
+ borrower { id }
62832
+ feeAmount
62833
+ mintAmount
62834
+ newDebt
62835
+ btcPrice
62836
+ quantumTimestamp
62837
+ timestamp
62838
+ blockNumber
62839
+ transactionHash
62840
+ logIndex
62841
+ }
62842
+ renewalFees(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62843
+ id
62844
+ borrower { id }
62845
+ feeAmount
62846
+ extensionTerm
62847
+ newExpiryDate
62848
+ timestamp
62849
+ blockNumber
62850
+ transactionHash
62851
+ logIndex
62852
+ }
62853
+ positionCreatedEvents(first: 1, orderBy: timestamp, orderDirection: asc) {
62854
+ id
62855
+ pkpId
62856
+ borrower { id }
62857
+ requestedCollateralRatio
62858
+ selectedTerm
62859
+ expiryAt
62860
+ timestamp
62861
+ blockNumber
62862
+ transactionHash
62863
+ }
62864
+ }
62865
+ ucdmintEvents(where: { position_: { borrower: $borrower } }, first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62866
+ id
62867
+ position { id }
62868
+ amount
62869
+ proof
62870
+ minter { id }
62871
+ isCommunityMint
62872
+ timestamp
62873
+ blockNumber
62874
+ transactionHash
62875
+ }
62876
+ collateralEvents(where: { position_: { borrower: $borrower } }, first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62877
+ id
62878
+ position { id }
62879
+ eventType
62880
+ networkFee
62881
+ remainingCollateral
62882
+ collateralRatio
62883
+ timestamp
62884
+ blockNumber
62885
+ transactionHash
62886
+ logIndex
62887
+ }
62888
+ }
62889
+ `;
62713
62890
  var DiamondHandsGraph = class {
62714
62891
  client;
62715
62892
  defaultPageSize;
@@ -62815,7 +62992,7 @@ var DiamondHandsGraph = class {
62815
62992
  /**
62816
62993
  * Get user positions from subgraph
62817
62994
  */
62818
- async getUserPositions(userAddress, first, skip, orderBy, orderDirection) {
62995
+ async getUserPositionsOnly(userAddress, first, skip, orderBy, orderDirection) {
62819
62996
  const query = `
62820
62997
  query GetUserPositions($borrower: Bytes!, $first: Int, $skip: Int, $orderBy: Position_orderBy, $orderDirection: OrderDirection) {
62821
62998
  user(id: $borrower) {
@@ -62856,17 +63033,28 @@ var DiamondHandsGraph = class {
62856
63033
  query,
62857
63034
  variables
62858
63035
  );
62859
- const total = await this.getTotalCountPaginated("{ borrower: $borrower }", {
62860
- borrower: userAddress.toLowerCase()
62861
- });
62862
63036
  let positions = [];
62863
63037
  if (result && result.user && Array.isArray(result.user.positions)) {
62864
63038
  positions = result.user.positions.filter((p) => p != null).map((p) => this.transformGraphPositionToLoanData(p));
62865
63039
  }
62866
- return {
62867
- positions,
62868
- total
62869
- };
63040
+ return positions;
63041
+ }
63042
+ /**
63043
+ * Get user positions, plus an accurate total count.
63044
+ *
63045
+ * The count is a SECOND round trip (`getTotalCountPaginated`, which pages to handle
63046
+ * >1000 items). Callers that only need the rows should use `getUserPositionsOnly` and
63047
+ * skip it — the event paths did not, and paid for a count they immediately discarded on
63048
+ * every activity refresh.
63049
+ */
63050
+ async getUserPositions(userAddress, first, skip, orderBy, orderDirection) {
63051
+ const [positions, total] = await Promise.all([
63052
+ this.getUserPositionsOnly(userAddress, first, skip, orderBy, orderDirection),
63053
+ this.getTotalCountPaginated("{ borrower: $borrower }", {
63054
+ borrower: userAddress.toLowerCase()
63055
+ })
63056
+ ]);
63057
+ return { positions, total };
62870
63058
  }
62871
63059
  /**
62872
63060
  * Get user positions with enriched Bitcoin balance data
@@ -63957,6 +64145,16 @@ var DiamondHandsGraph = class {
63957
64145
  orderDirection
63958
64146
  };
63959
64147
  const result = await this.client.execute(query, variables);
64148
+ return this.assembleLoanEvents(positionId, result);
64149
+ }
64150
+ /**
64151
+ * Map one position's raw event payload into `LoanEvents`.
64152
+ *
64153
+ * Extracted verbatim from getLoanEvents so the wallet-collapsed path produces
64154
+ * byte-identical objects by construction rather than by a second implementation
64155
+ * that has to be kept in step by hand.
64156
+ */
64157
+ assembleLoanEvents(positionId, result) {
63960
64158
  const rawCreated = result.positionCreatedEvents?.[0];
63961
64159
  const positionCreated = rawCreated ? {
63962
64160
  id: rawCreated.id,
@@ -64161,7 +64359,22 @@ var DiamondHandsGraph = class {
64161
64359
  * @returns One LoanEvents object per position; empty array if the wallet has none.
64162
64360
  */
64163
64361
  async getWalletLoanEvents(userAddress, filter2) {
64164
- const { positions } = await this.getUserPositions(userAddress);
64362
+ if (!hasLoanEventsFilter(filter2)) {
64363
+ return this.getWalletLoanEventsCollapsed(userAddress);
64364
+ }
64365
+ return this.getWalletLoanEventsFanout(userAddress, filter2);
64366
+ }
64367
+ /**
64368
+ * The per-position path: enumerate the wallet's positions, then one `GetLoanEvents` each.
64369
+ *
64370
+ * Used for filtered calls, and as the completeness fallback when the collapsed document
64371
+ * hits a page limit. Costs `1 + N` requests, which is exactly why it is not the default.
64372
+ */
64373
+ async getWalletLoanEventsFanout(userAddress, filter2) {
64374
+ const positions = await this.getUserPositionsOnly(
64375
+ userAddress,
64376
+ THE_GRAPH_MAX_BATCH_SIZE
64377
+ );
64165
64378
  const positionIds = positions.map((p) => p?.id != null ? String(p.id) : "").filter((id) => id.length > 0);
64166
64379
  if (positionIds.length === 0)
64167
64380
  return [];
@@ -64176,6 +64389,81 @@ var DiamondHandsGraph = class {
64176
64389
  }
64177
64390
  return results;
64178
64391
  }
64392
+ /**
64393
+ * The whole wallet's event history in ONE request.
64394
+ *
64395
+ * Replaces `1 + N` round trips (one position enumeration plus one per position) with a
64396
+ * single document. Measured on Sepolia: a wallet holding 44 positions cost 46 requests
64397
+ * per activity refresh against a per-wallet budget of 30/min — this makes it 1.
64398
+ *
64399
+ * Three subgraph facts make it possible, all verified against the deployed schema rather
64400
+ * than assumed:
64401
+ * - ten event collections are `@derivedFrom` on Position, so they nest under a
64402
+ * borrower-filtered `positions(...)`;
64403
+ * - `positionCreatedEvents` is ALSO derived on Position — `getLoanEvents` queries it
64404
+ * top-level, which it never needed to;
64405
+ * - `ucdmintEvents` / `collateralEvents` are not derived and carry no `borrower`
64406
+ * field, but graph-node's nested `position_: { borrower }` filter reaches them.
64407
+ * Without that last one this would be two requests, not one.
64408
+ */
64409
+ async getWalletLoanEventsCollapsed(userAddress) {
64410
+ const borrower = userAddress.toLowerCase();
64411
+ const pageSize = THE_GRAPH_MAX_BATCH_SIZE;
64412
+ const result = await this.client.execute(
64413
+ WALLET_LOAN_EVENTS_QUERY,
64414
+ {
64415
+ borrower,
64416
+ first: pageSize,
64417
+ limit: pageSize,
64418
+ orderDirection: "desc"
64419
+ }
64420
+ );
64421
+ const positions = result.positions || [];
64422
+ const ucdmintEvents = result.ucdmintEvents || [];
64423
+ const collateralEvents = result.collateralEvents || [];
64424
+ const truncated = positions.length >= pageSize || ucdmintEvents.length >= pageSize || collateralEvents.length >= pageSize;
64425
+ if (truncated) {
64426
+ log.warn(
64427
+ "[DiamondHandsGraph] wallet event page limit reached \u2014 falling back to the per-position path to avoid returning a partial history",
64428
+ {
64429
+ borrower,
64430
+ pageSize,
64431
+ positions: positions.length,
64432
+ ucdmintEvents: ucdmintEvents.length,
64433
+ collateralEvents: collateralEvents.length
64434
+ }
64435
+ );
64436
+ return this.getWalletLoanEventsFanout(userAddress);
64437
+ }
64438
+ if (positions.length === 0)
64439
+ return [];
64440
+ const mintsByPosition = /* @__PURE__ */ new Map();
64441
+ for (const m of result.ucdmintEvents || []) {
64442
+ const key = m.position?.id;
64443
+ if (!key)
64444
+ continue;
64445
+ const bucket = mintsByPosition.get(key) || [];
64446
+ bucket.push(m);
64447
+ mintsByPosition.set(key, bucket);
64448
+ }
64449
+ const collateralByPosition = /* @__PURE__ */ new Map();
64450
+ for (const c of result.collateralEvents || []) {
64451
+ const key = c.position?.id;
64452
+ if (!key)
64453
+ continue;
64454
+ const bucket = collateralByPosition.get(key) || [];
64455
+ bucket.push(c);
64456
+ collateralByPosition.set(key, bucket);
64457
+ }
64458
+ return positions.map(
64459
+ (p) => this.assembleLoanEvents(p.id, {
64460
+ position: p,
64461
+ positionCreatedEvents: p.positionCreatedEvents || [],
64462
+ ucdmintEvents: mintsByPosition.get(p.id) || [],
64463
+ collateralEvents: collateralByPosition.get(p.id) || []
64464
+ })
64465
+ );
64466
+ }
64179
64467
  // ============================================================================
64180
64468
  // Protocol-wide Events
64181
64469
  // ============================================================================
@@ -69035,16 +69323,6 @@ function createMockTokenManager(config) {
69035
69323
  }
69036
69324
  }
69037
69325
  var import_dh_lit_actions2 = __toESM2(require_pkg_src2());
69038
- var TelegramBot = null;
69039
- try {
69040
- if (typeof window === "undefined" && typeof global !== "undefined") {
69041
- TelegramBot = null /* stubbed post-build: dh-mcp never uses telegram (F-PUB-2) */;
69042
- }
69043
- } catch (error) {
69044
- log.warn("Telegram bot API not available", {
69045
- error: error instanceof Error ? error.message : String(error)
69046
- });
69047
- }
69048
69326
  function formatMintMessage(mintAmount, loanId, txHash) {
69049
69327
  return `\u2705 DH SDK: ${mintAmount} UCD was minted for loan id: ${loanId} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
69050
69328
  }