@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.
@@ -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
  });
@@ -51437,6 +51443,14 @@ var init_deployment_addresses = __esm2({
51437
51443
  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.",
51438
51444
  executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
51439
51445
  block: 25673200
51446
+ },
51447
+ AgentDelegationRegistry: {
51448
+ newImplementation: "0xa9fF405Edd4329fc3159a64F56B37EBD253e4928",
51449
+ upgradedAt: "2026-07-31T22:03:35.000Z",
51450
+ upgradedBy: "AdminModule/Safe audit-batch upgradeToAndCall; executed by 0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f in tx 0x8fed0ab7eee3aaaa3792a35b40b0ef74bd09cfb1a175934afd846bee546048d4 (block 25655710)",
51451
+ reason: "Reconciled from chain \u2014 mainnet audit rollout batch (cross-ref onchain-auth/.safe-batches/mainnet-audit-execute.json)",
51452
+ executeTx: "0x8fed0ab7eee3aaaa3792a35b40b0ef74bd09cfb1a175934afd846bee546048d4",
51453
+ block: 25655710
51440
51454
  }
51441
51455
  },
51442
51456
  latestEnv: {
@@ -62716,6 +62730,169 @@ function normalizePkpId2(pkpId) {
62716
62730
  }
62717
62731
  return pkpId;
62718
62732
  }
62733
+ function hasLoanEventsFilter(filter2) {
62734
+ if (!filter2)
62735
+ return false;
62736
+ 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;
62737
+ }
62738
+ var WALLET_LOAN_EVENTS_QUERY = `
62739
+ query GetWalletLoanEvents($borrower: Bytes!, $first: Int!, $limit: Int!, $orderDirection: OrderDirection!) {
62740
+ positions(where: { borrower: $borrower }, first: $first, orderBy: id) {
62741
+ id
62742
+ payments(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62743
+ id
62744
+ payer { id }
62745
+ amount
62746
+ type
62747
+ transactionHash
62748
+ timestamp
62749
+ blockNumber
62750
+ logIndex
62751
+ newDebt
62752
+ newCollateralRatio
62753
+ }
62754
+ statusUpdates(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62755
+ id
62756
+ oldStatus
62757
+ newStatus
62758
+ reason
62759
+ timestamp
62760
+ blockNumber
62761
+ transactionHash
62762
+ }
62763
+ liquidation {
62764
+ id
62765
+ liquidator
62766
+ liquidatedAmount
62767
+ collateralSeized
62768
+ transactionHash
62769
+ timestamp
62770
+ blockNumber
62771
+ commitHash
62772
+ commitTimestamp
62773
+ revealDelay
62774
+ }
62775
+ withdrawals(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62776
+ id
62777
+ withdrawalAmount
62778
+ withdrawalAddress
62779
+ networkFee
62780
+ timestamp
62781
+ blockNumber
62782
+ transactionHash
62783
+ logIndex
62784
+ }
62785
+ renewals(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62786
+ id
62787
+ extensionTerm
62788
+ extensionFee
62789
+ newExpiryDate
62790
+ timestamp
62791
+ blockNumber
62792
+ transactionHash
62793
+ logIndex
62794
+ }
62795
+ operationFailures(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62796
+ id
62797
+ operationType
62798
+ reason
62799
+ errorCode
62800
+ amount
62801
+ timestamp
62802
+ blockNumber
62803
+ transactionHash
62804
+ logIndex
62805
+ }
62806
+ mintRequests(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62807
+ id
62808
+ pkpId
62809
+ borrower { id }
62810
+ mintAmount
62811
+ originationFee
62812
+ newDebt
62813
+ newCollateralRatio
62814
+ btcPrice
62815
+ quantumTimestamp
62816
+ opId
62817
+ timestamp
62818
+ blockNumber
62819
+ transactionHash
62820
+ logIndex
62821
+ }
62822
+ burnRequests(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62823
+ id
62824
+ pkpId
62825
+ borrower { id }
62826
+ burnAmount
62827
+ remainingDebt
62828
+ newCollateralRatio
62829
+ opId
62830
+ timestamp
62831
+ blockNumber
62832
+ transactionHash
62833
+ logIndex
62834
+ }
62835
+ mintingFees(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62836
+ id
62837
+ borrower { id }
62838
+ feeAmount
62839
+ mintAmount
62840
+ newDebt
62841
+ btcPrice
62842
+ quantumTimestamp
62843
+ timestamp
62844
+ blockNumber
62845
+ transactionHash
62846
+ logIndex
62847
+ }
62848
+ renewalFees(first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62849
+ id
62850
+ borrower { id }
62851
+ feeAmount
62852
+ extensionTerm
62853
+ newExpiryDate
62854
+ timestamp
62855
+ blockNumber
62856
+ transactionHash
62857
+ logIndex
62858
+ }
62859
+ positionCreatedEvents(first: 1, orderBy: timestamp, orderDirection: asc) {
62860
+ id
62861
+ pkpId
62862
+ borrower { id }
62863
+ requestedCollateralRatio
62864
+ selectedTerm
62865
+ expiryAt
62866
+ timestamp
62867
+ blockNumber
62868
+ transactionHash
62869
+ }
62870
+ }
62871
+ ucdmintEvents(where: { position_: { borrower: $borrower } }, first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62872
+ id
62873
+ position { id }
62874
+ amount
62875
+ proof
62876
+ minter { id }
62877
+ isCommunityMint
62878
+ timestamp
62879
+ blockNumber
62880
+ transactionHash
62881
+ }
62882
+ collateralEvents(where: { position_: { borrower: $borrower } }, first: $limit, orderBy: timestamp, orderDirection: $orderDirection) {
62883
+ id
62884
+ position { id }
62885
+ eventType
62886
+ networkFee
62887
+ remainingCollateral
62888
+ collateralRatio
62889
+ timestamp
62890
+ blockNumber
62891
+ transactionHash
62892
+ logIndex
62893
+ }
62894
+ }
62895
+ `;
62719
62896
  var DiamondHandsGraph = class {
62720
62897
  client;
62721
62898
  defaultPageSize;
@@ -62821,7 +62998,7 @@ var DiamondHandsGraph = class {
62821
62998
  /**
62822
62999
  * Get user positions from subgraph
62823
63000
  */
62824
- async getUserPositions(userAddress, first, skip, orderBy, orderDirection) {
63001
+ async getUserPositionsOnly(userAddress, first, skip, orderBy, orderDirection) {
62825
63002
  const query = `
62826
63003
  query GetUserPositions($borrower: Bytes!, $first: Int, $skip: Int, $orderBy: Position_orderBy, $orderDirection: OrderDirection) {
62827
63004
  user(id: $borrower) {
@@ -62862,17 +63039,28 @@ var DiamondHandsGraph = class {
62862
63039
  query,
62863
63040
  variables
62864
63041
  );
62865
- const total = await this.getTotalCountPaginated("{ borrower: $borrower }", {
62866
- borrower: userAddress.toLowerCase()
62867
- });
62868
63042
  let positions = [];
62869
63043
  if (result && result.user && Array.isArray(result.user.positions)) {
62870
63044
  positions = result.user.positions.filter((p) => p != null).map((p) => this.transformGraphPositionToLoanData(p));
62871
63045
  }
62872
- return {
62873
- positions,
62874
- total
62875
- };
63046
+ return positions;
63047
+ }
63048
+ /**
63049
+ * Get user positions, plus an accurate total count.
63050
+ *
63051
+ * The count is a SECOND round trip (`getTotalCountPaginated`, which pages to handle
63052
+ * >1000 items). Callers that only need the rows should use `getUserPositionsOnly` and
63053
+ * skip it — the event paths did not, and paid for a count they immediately discarded on
63054
+ * every activity refresh.
63055
+ */
63056
+ async getUserPositions(userAddress, first, skip, orderBy, orderDirection) {
63057
+ const [positions, total] = await Promise.all([
63058
+ this.getUserPositionsOnly(userAddress, first, skip, orderBy, orderDirection),
63059
+ this.getTotalCountPaginated("{ borrower: $borrower }", {
63060
+ borrower: userAddress.toLowerCase()
63061
+ })
63062
+ ]);
63063
+ return { positions, total };
62876
63064
  }
62877
63065
  /**
62878
63066
  * Get user positions with enriched Bitcoin balance data
@@ -63963,6 +64151,16 @@ var DiamondHandsGraph = class {
63963
64151
  orderDirection
63964
64152
  };
63965
64153
  const result = await this.client.execute(query, variables);
64154
+ return this.assembleLoanEvents(positionId, result);
64155
+ }
64156
+ /**
64157
+ * Map one position's raw event payload into `LoanEvents`.
64158
+ *
64159
+ * Extracted verbatim from getLoanEvents so the wallet-collapsed path produces
64160
+ * byte-identical objects by construction rather than by a second implementation
64161
+ * that has to be kept in step by hand.
64162
+ */
64163
+ assembleLoanEvents(positionId, result) {
63966
64164
  const rawCreated = result.positionCreatedEvents?.[0];
63967
64165
  const positionCreated = rawCreated ? {
63968
64166
  id: rawCreated.id,
@@ -64167,7 +64365,22 @@ var DiamondHandsGraph = class {
64167
64365
  * @returns One LoanEvents object per position; empty array if the wallet has none.
64168
64366
  */
64169
64367
  async getWalletLoanEvents(userAddress, filter2) {
64170
- const { positions } = await this.getUserPositions(userAddress);
64368
+ if (!hasLoanEventsFilter(filter2)) {
64369
+ return this.getWalletLoanEventsCollapsed(userAddress);
64370
+ }
64371
+ return this.getWalletLoanEventsFanout(userAddress, filter2);
64372
+ }
64373
+ /**
64374
+ * The per-position path: enumerate the wallet's positions, then one `GetLoanEvents` each.
64375
+ *
64376
+ * Used for filtered calls, and as the completeness fallback when the collapsed document
64377
+ * hits a page limit. Costs `1 + N` requests, which is exactly why it is not the default.
64378
+ */
64379
+ async getWalletLoanEventsFanout(userAddress, filter2) {
64380
+ const positions = await this.getUserPositionsOnly(
64381
+ userAddress,
64382
+ THE_GRAPH_MAX_BATCH_SIZE
64383
+ );
64171
64384
  const positionIds = positions.map((p) => p?.id != null ? String(p.id) : "").filter((id) => id.length > 0);
64172
64385
  if (positionIds.length === 0)
64173
64386
  return [];
@@ -64182,6 +64395,81 @@ var DiamondHandsGraph = class {
64182
64395
  }
64183
64396
  return results;
64184
64397
  }
64398
+ /**
64399
+ * The whole wallet's event history in ONE request.
64400
+ *
64401
+ * Replaces `1 + N` round trips (one position enumeration plus one per position) with a
64402
+ * single document. Measured on Sepolia: a wallet holding 44 positions cost 46 requests
64403
+ * per activity refresh against a per-wallet budget of 30/min — this makes it 1.
64404
+ *
64405
+ * Three subgraph facts make it possible, all verified against the deployed schema rather
64406
+ * than assumed:
64407
+ * - ten event collections are `@derivedFrom` on Position, so they nest under a
64408
+ * borrower-filtered `positions(...)`;
64409
+ * - `positionCreatedEvents` is ALSO derived on Position — `getLoanEvents` queries it
64410
+ * top-level, which it never needed to;
64411
+ * - `ucdmintEvents` / `collateralEvents` are not derived and carry no `borrower`
64412
+ * field, but graph-node's nested `position_: { borrower }` filter reaches them.
64413
+ * Without that last one this would be two requests, not one.
64414
+ */
64415
+ async getWalletLoanEventsCollapsed(userAddress) {
64416
+ const borrower = userAddress.toLowerCase();
64417
+ const pageSize = THE_GRAPH_MAX_BATCH_SIZE;
64418
+ const result = await this.client.execute(
64419
+ WALLET_LOAN_EVENTS_QUERY,
64420
+ {
64421
+ borrower,
64422
+ first: pageSize,
64423
+ limit: pageSize,
64424
+ orderDirection: "desc"
64425
+ }
64426
+ );
64427
+ const positions = result.positions || [];
64428
+ const ucdmintEvents = result.ucdmintEvents || [];
64429
+ const collateralEvents = result.collateralEvents || [];
64430
+ const truncated = positions.length >= pageSize || ucdmintEvents.length >= pageSize || collateralEvents.length >= pageSize;
64431
+ if (truncated) {
64432
+ log.warn(
64433
+ "[DiamondHandsGraph] wallet event page limit reached \u2014 falling back to the per-position path to avoid returning a partial history",
64434
+ {
64435
+ borrower,
64436
+ pageSize,
64437
+ positions: positions.length,
64438
+ ucdmintEvents: ucdmintEvents.length,
64439
+ collateralEvents: collateralEvents.length
64440
+ }
64441
+ );
64442
+ return this.getWalletLoanEventsFanout(userAddress);
64443
+ }
64444
+ if (positions.length === 0)
64445
+ return [];
64446
+ const mintsByPosition = /* @__PURE__ */ new Map();
64447
+ for (const m of result.ucdmintEvents || []) {
64448
+ const key = m.position?.id;
64449
+ if (!key)
64450
+ continue;
64451
+ const bucket = mintsByPosition.get(key) || [];
64452
+ bucket.push(m);
64453
+ mintsByPosition.set(key, bucket);
64454
+ }
64455
+ const collateralByPosition = /* @__PURE__ */ new Map();
64456
+ for (const c of result.collateralEvents || []) {
64457
+ const key = c.position?.id;
64458
+ if (!key)
64459
+ continue;
64460
+ const bucket = collateralByPosition.get(key) || [];
64461
+ bucket.push(c);
64462
+ collateralByPosition.set(key, bucket);
64463
+ }
64464
+ return positions.map(
64465
+ (p) => this.assembleLoanEvents(p.id, {
64466
+ position: p,
64467
+ positionCreatedEvents: p.positionCreatedEvents || [],
64468
+ ucdmintEvents: mintsByPosition.get(p.id) || [],
64469
+ collateralEvents: collateralByPosition.get(p.id) || []
64470
+ })
64471
+ );
64472
+ }
64185
64473
  // ============================================================================
64186
64474
  // Protocol-wide Events
64187
64475
  // ============================================================================
@@ -69041,16 +69329,6 @@ function createMockTokenManager(config) {
69041
69329
  }
69042
69330
  }
69043
69331
  var import_dh_lit_actions2 = __toESM2(require_pkg_src2());
69044
- var TelegramBot = null;
69045
- try {
69046
- if (typeof window === "undefined" && typeof global !== "undefined") {
69047
- TelegramBot = __require("node-telegram-bot-api");
69048
- }
69049
- } catch (error) {
69050
- log.warn("Telegram bot API not available", {
69051
- error: error instanceof Error ? error.message : String(error)
69052
- });
69053
- }
69054
69332
  function formatMintMessage(mintAmount, loanId, txHash) {
69055
69333
  return `\u2705 DH SDK: ${mintAmount} UCD was minted for loan id: ${loanId} Tx: https://sepolia.etherscan.io/tx/${txHash}`;
69056
69334
  }