@gvnrdao/dh-mcp 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -6,19 +6,33 @@ lending on a user's behalf, with a human approving every fund-moving step.
6
6
 
7
7
  ## Install
8
8
 
9
- Claude Code:
9
+ Pick the row that matches your machine — the first two paths carry their own runtime,
10
+ so there is **nothing to install first** (no Node, no npm):
10
11
 
11
- ```bash
12
- claude mcp add diamond-hands -- npx -y @gvnrdao/dh-mcp
13
- ```
14
-
15
- Claude Desktop / Cursor / any MCP host (JSON config):
16
-
17
- ```json
18
- { "mcpServers": { "diamond-hands": { "command": "npx", "args": ["-y", "@gvnrdao/dh-mcp"] } } }
19
- ```
20
-
21
- That is the whole install. **Zero configuration boots the real protocol on SEPOLIA**
12
+ | You are on | Install path |
13
+ |---|---|
14
+ | **Claude Desktop (macOS / Windows)** | Download the bundle and open it (double-click / drag into Settings → Extensions): `https://assets.gvnr.xyz/dh-mcp/v0.2.1/dh-mcp-0.2.1.mcpb` — Claude Desktop runs it on its own embedded runtime; network and optional keystore are configured in the extension's settings UI (the password is held by the OS credential store, never written to a config file). |
15
+ | **Linux — including Claude Desktop builds on Linux — or any other MCP host** | One line, no sudo: `curl -fsSL https://assets.gvnr.xyz/dh-mcp/install.sh \| sh` — installs a self-contained binary (its own Node runtime inside) to `~/.dh-mcp/bin/dh-mcp`, verifies its SHA-256, and prints the exact `mcpServers` snippet with an absolute path. Pin a version: `curl -fsSL https://assets.gvnr.xyz/dh-mcp/install.sh \| DH_VERSION=0.2.1 sh` |
16
+ | **Developers** (requires **Node ≥ 18 on PATH** — this path does NOT work on a bare machine) | Claude Code: `claude mcp add diamond-hands -- npx -y @gvnrdao/dh-mcp` · any host JSON: `{ "mcpServers": { "diamond-hands": { "command": "npx", "args": ["-y", "@gvnrdao/dh-mcp"] } } }` |
17
+
18
+ Downloads landing page (which file is for which system, checksums, security notes):
19
+ **https://assets.gvnr.xyz/dh-mcp/** — all artifacts and `SHA256SUMS` live under it
20
+ (`latest/` and `v<version>/` — e.g. `v0.2.1/`).
21
+
22
+ Unsigned-binary honesty: the macOS and Windows binaries are **not yet code-signed** —
23
+ macOS Gatekeeper may quarantine the download (right-click → Open, or
24
+ `xattr -d com.apple.quarantine <file>`) and Windows SmartScreen will warn. Verify the
25
+ `SHA256SUMS` file from the same release if in doubt. On macOS/Windows the `.mcpb` path
26
+ avoids this entirely.
27
+
28
+ **Troubleshooting `spawn npx ENOENT`:** your MCP host searched the system PATH and found
29
+ no `npx` — the machine has no Node.js (or the host, e.g. an Electron app, cannot see
30
+ your shell's version manager). That is the npx path's stated precondition, not a bug in
31
+ the server. Remedies: use the one-line installer above (the printed snippet uses an
32
+ absolute path to a binary that carries its own runtime), or on macOS/Windows Claude
33
+ Desktop install the `.mcpb`.
34
+
35
+ **Zero configuration boots the real protocol on SEPOLIA**
22
36
  (the test network — real contracts, test funds) with public endpoints. Everything is
23
37
  overridable by environment variables:
24
38
 
@@ -82,6 +96,14 @@ misrepresent upstream state, always answer with legible, typed results.
82
96
  | `loan_extend` | Renew the position term (pro-rata fee) |
83
97
  | `loan_withdraw` | Withdraw BTC from the vault (unrecoverable — strictest gate) |
84
98
  | `loan_recover_stale_spend` | Clear a stale BTC withdrawal reservation (permissionless) |
99
+ | `loan_allowlist_destination` | Register a BTC withdrawal destination in the registry (delay-gated on live networks) |
100
+ | `psm_swap` | Swap USDC ↔ UCD through the PSM (quotes via the `psm_quote` read; mainnet PSM writes always refuse) |
101
+ | `loan_delegation_setup` / `loan_delegation_grant` | Safe delegation plane — practice (mock) only today; real refuses with that true reason |
102
+
103
+ **Authorization by conversation:** `signer_setup` — the user picks external wallet
104
+ (MetaMask popup / WalletConnect QR), local encrypted keystore, or the Safe modes by
105
+ TALKING; secrets never travel through chat. `guide` serves the walkthroughs
106
+ (`first-setup`, `connect-wallet`, `safe`, `delegation`, `troubleshooting`, …).
85
107
 
86
108
  **Observability** (read tools + resources, no signer needed): position status, listings,
87
109
  event history, pending withdrawals (`position_*`, `position://{id}`), protocol health and
package/dist/boundary.js CHANGED
@@ -61761,7 +61761,7 @@ var init_deployment_addresses = __esm2({
61761
61761
  LiquidationManagerModule: "0x74B28695352E7bf736D6c9F76ccb7B4439477De9",
61762
61762
  CircuitBreakerModule: "0xF7b545d3a4Ee056D06909AB367E2F7bFFE3cB1BC",
61763
61763
  AdminModule: "0x0023B71B586795eE5fa4E83E384345C1EC8Bb946",
61764
- PositionManagerViews: "0x9225647a30bbACA4Acc0491B786869036914242e",
61764
+ PositionManagerViews: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
61765
61765
  PositionManager: "0x12A1836e56139ccaD8722B89519d84233efc224B",
61766
61766
  OperationAuthorizationRegistry: "0xD4505645b724754f5170a2027804a4265e860d44",
61767
61767
  ContractVersionRegistry: "0x5e18f77d01940dA5B1D986D373D9A6ad0767008d",
@@ -61839,13 +61839,13 @@ var init_deployment_addresses = __esm2({
61839
61839
  block: 25472957
61840
61840
  },
61841
61841
  PositionManager: {
61842
- previousImplementation: "0x9f52BaBB40FbFC5863e45B1A4014cB433950c684",
61843
- newImplementation: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
61844
- upgradedAt: "2026-07-06T08:42:47.000Z",
61845
- upgradedBy: "AdminModule/Safe audit-batch upgradeToAndCall; executed by 0x2002827d34A781883Ec4c83c36ECC140c3911F2B in tx 0xa1fbe31cb71736514a868e681573dff22c9fab91d69cec157a24a30e29eadbe6 (block 25472368)",
61846
- reason: "Reconciled from chain \u2014 mainnet audit rollout batch (cross-ref onchain-auth/.safe-batches/mainnet-audit-execute.json)",
61847
- executeTx: "0xa1fbe31cb71736514a868e681573dff22c9fab91d69cec157a24a30e29eadbe6",
61848
- block: 25472368
61842
+ previousImplementation: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
61843
+ newImplementation: "0x2e7170d6Fb15A876dB726732e72e63109bcB916d",
61844
+ upgradedAt: "2026-08-03T08:34:23.000Z",
61845
+ upgradedBy: "AdminModule generic-op 0x69b79a906ed2 (3-of-3 signatures, 24h timelock; proposed by 0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f, executed in the release batch onchain-auth/.safe-batches/mainnet-release-execute-B.json, submitted by EOA 0x2002827d34A781883Ec4c83c36ECC140c3911F2B, tx 0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6, block 25673200)",
61846
+ reason: "2026-08 agent-stack release, Execute B: agent-delegation digest rebind. makePayment/mintUCD/extendPosition now bind their EIP-712 digest to the STORED borrower rather than msg.sender, so a scoped AgentDelegationRegistry grant can submit; withdrawBTC still binds msg.sender and stays non-delegable. Also adds setViews(address), which the same batch used to repoint PM at the replacement PositionManagerViews. NOTE: VERSION reads 1.5.4 on BOTH sides of this upgrade \u2014 verify by implementation ADDRESS, never by VERSION(). NOTE: not the July audit rollout batch \u2014 reconcile-deployment-record.ts --write templates every row with that text; this hand-authored provenance is the accurate one, restore it if --write flattens it again.",
61847
+ executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
61848
+ block: 25673200
61849
61849
  },
61850
61850
  LoanOperationsManagerModule: {
61851
61851
  previousImplementation: "0x56671D671e492Dae625413d463D47605Cf54edf6",
@@ -61889,6 +61889,16 @@ var init_deployment_addresses = __esm2({
61889
61889
  reason: "2026-08 agent-stack release: PositionDelegateRegistry VERSION 1.1.0 -> 2.0.0 via upgradeToAndCall + initializeV2(AdminModule, registrar 0x5D54E0BE\u2026, pauser 0xC205Ae99\u2026) \u2014 kill-switch, deny-only registrar, permanent delegate burn. NOTE: not the July audit rollout batch \u2014 reconcile-deployment-record.ts --write templates every row with that text; this hand-authored provenance is the accurate one, restore it if --write flattens it again.",
61890
61890
  executeTx: "0xf0f237f6c4e958c37de556571908283c59c3fba6ebf9fa3cefb956f37e315a10",
61891
61891
  block: 25669024
61892
+ },
61893
+ PositionManagerViews: {
61894
+ previousImplementation: "0x9225647a30bbACA4Acc0491B786869036914242e",
61895
+ newImplementation: "0xE68DC096A65Ecddbc6A9b5c6e5f878e2CE143Bfe",
61896
+ proxy: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
61897
+ upgradedAt: "2026-08-03T08:34:23.000Z",
61898
+ upgradedBy: "REPLACED, not upgraded. Fresh ERC1967Proxy (atomically initialized) + AdminModule generic-op 0x848a97186f0d PositionManager.setViews(proxy) \u2014 3-of-3, 24h timelock, executed in onchain-auth/.safe-batches/mainnet-release-execute-B.json",
61899
+ 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.",
61900
+ executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
61901
+ block: 25673200
61892
61902
  }
61893
61903
  },
61894
61904
  latestEnv: {
@@ -61922,10 +61932,10 @@ var init_deployment_addresses = __esm2({
61922
61932
  ADMIN_MODULE_IMPL: "0xb4C5C7E051A1e672F014B25CB5D55B225Aa0D512",
61923
61933
  BTC_SPEND_AUTHORIZER: "0xfBbF108486fa07F1B06a811C5b66ed68DD9c508a",
61924
61934
  BTC_SPEND_AUTHORIZER_IMPL: "0x40c9e8C46C65E0A57BB63da5368868A9E8Df81A5",
61925
- POSITION_MANAGER_VIEWS: "0x9225647a30bbACA4Acc0491B786869036914242e",
61926
- POSITION_MANAGER_VIEWS_IMPL: "0x9225647a30bbACA4Acc0491B786869036914242e",
61935
+ POSITION_MANAGER_VIEWS: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
61936
+ POSITION_MANAGER_VIEWS_IMPL: "0xE68DC096A65Ecddbc6A9b5c6e5f878e2CE143Bfe",
61927
61937
  POSITION_MANAGER: "0x12A1836e56139ccaD8722B89519d84233efc224B",
61928
- POSITION_MANAGER_IMPL: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
61938
+ POSITION_MANAGER_IMPL: "0x2e7170d6Fb15A876dB726732e72e63109bcB916d",
61929
61939
  LOAN_OPERATIONS_MANAGER_MODULE: "0x2561974A40F1AEed1251d0A090A83cF8536FB9E9",
61930
61940
  LOAN_OPERATIONS_MANAGER_MODULE_IMPL: "0x7d90aAB4466f59BA9aC9C7a9BF14dC53734336e7",
61931
61941
  UPGRADE_VALIDATOR: "0xC46Ae71F22e3741A6CF46E399aE914C4868fEbed",
@@ -61951,7 +61961,7 @@ var init_deployment_addresses = __esm2({
61951
61961
  LiquidationManagerModule: "0x74B28695352E7bf736D6c9F76ccb7B4439477De9",
61952
61962
  CircuitBreakerModule: "0xF7b545d3a4Ee056D06909AB367E2F7bFFE3cB1BC",
61953
61963
  AdminModule: "0x0023B71B586795eE5fa4E83E384345C1EC8Bb946",
61954
- PositionManagerViews: "0x9225647a30bbACA4Acc0491B786869036914242e",
61964
+ PositionManagerViews: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
61955
61965
  PositionManager: "0x12A1836e56139ccaD8722B89519d84233efc224B",
61956
61966
  OperationAuthorizationRegistry: "0xD4505645b724754f5170a2027804a4265e860d44",
61957
61967
  ContractVersionRegistry: "0x5e18f77d01940dA5B1D986D373D9A6ad0767008d",
@@ -67775,6 +67785,7 @@ function sessionStoreKey(address, chainId, endpoint) {
67775
67785
  return STORE_PREFIX + `${address.trim().toLowerCase()}:${chainId}:${endpoint.replace(/\/+$/, "")}`;
67776
67786
  }
67777
67787
  var PENDING_ENVELOPE_TTL_SECONDS = 8 * 60;
67788
+ var EOA_PENDING_ENVELOPE_TTL_SECONDS = 60;
67778
67789
  function pendingEnvelopeKey(sessionKey) {
67779
67790
  return sessionKey + ":pending";
67780
67791
  }
@@ -67822,7 +67833,7 @@ var LocalStorageSessionStore = class {
67822
67833
  } catch {
67823
67834
  }
67824
67835
  }
67825
- loadPending(key) {
67836
+ loadPending(key, maxAgeSeconds = PENDING_ENVELOPE_TTL_SECONDS) {
67826
67837
  let raw;
67827
67838
  try {
67828
67839
  raw = window.localStorage.getItem(pendingEnvelopeKey(key));
@@ -67839,7 +67850,7 @@ var LocalStorageSessionStore = class {
67839
67850
  return null;
67840
67851
  }
67841
67852
  const nowSec = Math.floor(Date.now() / 1e3);
67842
- if (!isPendingEnvelopeShape(parsed) || nowSec >= parsed.issuedAt + PENDING_ENVELOPE_TTL_SECONDS) {
67853
+ if (!isPendingEnvelopeShape(parsed) || nowSec >= parsed.issuedAt + maxAgeSeconds) {
67843
67854
  this.clearPending(key);
67844
67855
  return null;
67845
67856
  }
@@ -67873,12 +67884,12 @@ var MemorySessionStore = class {
67873
67884
  clear(key) {
67874
67885
  this.entries.delete(key);
67875
67886
  }
67876
- loadPending(key) {
67887
+ loadPending(key, maxAgeSeconds = PENDING_ENVELOPE_TTL_SECONDS) {
67877
67888
  const envelope = this.pending.get(key);
67878
67889
  if (!envelope)
67879
67890
  return null;
67880
67891
  const nowSec = Math.floor(Date.now() / 1e3);
67881
- if (nowSec >= envelope.issuedAt + PENDING_ENVELOPE_TTL_SECONDS) {
67892
+ if (nowSec >= envelope.issuedAt + maxAgeSeconds) {
67882
67893
  this.pending.delete(key);
67883
67894
  return null;
67884
67895
  }
@@ -67910,15 +67921,23 @@ var REFRESH_LEEWAY_SECONDS = 30;
67910
67921
  var LOGIN_RETRY_BASE_MS = 3e4;
67911
67922
  var LOGIN_RETRY_MAX_MS = 5 * 6e4;
67912
67923
  var ServerLoginError = class extends Error {
67913
- constructor(message, status) {
67924
+ constructor(message, status, reason) {
67914
67925
  super(message);
67915
67926
  this.status = status;
67927
+ this.reason = reason;
67916
67928
  this.name = "ServerLoginError";
67917
67929
  }
67918
67930
  };
67919
67931
  function isLoginRejection(error) {
67920
67932
  return error instanceof ServerLoginError && error.status >= 400 && error.status < 500 && error.status !== 429;
67921
67933
  }
67934
+ var SPENT_ENVELOPE_REASONS = /* @__PURE__ */ new Set(["replayed_nonce", "expired_issuedAt"]);
67935
+ function isSpentEnvelope(error) {
67936
+ if (!isLoginRejection(error))
67937
+ return false;
67938
+ const { reason, status } = error;
67939
+ return reason ? SPENT_ENVELOPE_REASONS.has(reason) : status === 409;
67940
+ }
67922
67941
  var ServerSession = class {
67923
67942
  signer;
67924
67943
  serviceEndpoint;
@@ -67949,6 +67968,12 @@ var ServerSession = class {
67949
67968
  * `clear()` can drop the persisted token without an async address lookup.
67950
67969
  */
67951
67970
  lastStoreKey = null;
67971
+ /**
67972
+ * Whether the signer is a smart-contract wallet, memoized after the first
67973
+ * `eth_getCode`. Decides which of the server's two first-use windows bounds
67974
+ * envelope reuse; a signer cannot change kind for the life of the session.
67975
+ */
67976
+ contractSigner = null;
67952
67977
  constructor(opts) {
67953
67978
  assertSafeServiceEndpoint(opts.serviceEndpoint);
67954
67979
  this.signer = opts.signer;
@@ -68147,6 +68172,34 @@ var ServerSession = class {
68147
68172
  return null;
68148
68173
  }
68149
68174
  }
68175
+ /**
68176
+ * How long a pending envelope for THIS signer may be reused, in seconds.
68177
+ *
68178
+ * The server grants an EOA 120s to make an envelope's first use and a contract
68179
+ * wallet 600s, so one local TTL is necessarily wrong for one of them. Deployed
68180
+ * code has bytecode; an EOA does not — one `eth_getCode`, memoized, settles it.
68181
+ *
68182
+ * Reports the CONTRACT window when it cannot tell, which is the behavior that
68183
+ * shipped before the split. The asymmetry is intended: guessing "EOA" for a
68184
+ * Safe hands it a new message and orphans the owner signatures already
68185
+ * collected, while guessing "contract" for an EOA now costs one rejected
68186
+ * attempt, because a rejection clears the envelope.
68187
+ */
68188
+ async pendingEnvelopeTtl() {
68189
+ if (this.contractSigner === null) {
68190
+ try {
68191
+ const provider = this.signer.provider;
68192
+ if (!provider)
68193
+ return PENDING_ENVELOPE_TTL_SECONDS;
68194
+ const address = await this.signer.getAddress();
68195
+ const code = await provider.getCode(address);
68196
+ this.contractSigner = typeof code === "string" && code !== "0x";
68197
+ } catch {
68198
+ return PENDING_ENVELOPE_TTL_SECONDS;
68199
+ }
68200
+ }
68201
+ return this.contractSigner ? PENDING_ENVELOPE_TTL_SECONDS : EOA_PENDING_ENVELOPE_TTL_SECONDS;
68202
+ }
68150
68203
  async getOrRefresh() {
68151
68204
  const nowSec = this.now();
68152
68205
  if (this.cached && this.cached.expiresAt - REFRESH_LEEWAY_SECONDS > nowSec) {
@@ -68168,10 +68221,10 @@ var ServerSession = class {
68168
68221
  }
68169
68222
  this.onSignaturePrompt?.();
68170
68223
  let session;
68224
+ const store = this.store;
68225
+ const storeKey = store ? this.lastStoreKey : null;
68171
68226
  try {
68172
- const store = this.store;
68173
- const storeKey = store ? this.lastStoreKey : null;
68174
- const reuse = storeKey ? store.loadPending?.(storeKey) ?? void 0 : void 0;
68227
+ const reuse = storeKey ? store.loadPending?.(storeKey, await this.pendingEnvelopeTtl()) ?? void 0 : void 0;
68175
68228
  const payload = await buildSignedLoginPayload(
68176
68229
  this.signer,
68177
68230
  this.chainId,
@@ -68194,6 +68247,9 @@ var ServerSession = class {
68194
68247
  this.onSignatureResolved?.(true);
68195
68248
  } catch (error) {
68196
68249
  this.onSignatureResolved?.(false);
68250
+ if (storeKey && isSpentEnvelope(error)) {
68251
+ store.clearPending?.(storeKey);
68252
+ }
68197
68253
  const failures = (this.promptBackoff?.failures ?? 0) + 1;
68198
68254
  this.promptBackoff = {
68199
68255
  failures,
@@ -68222,9 +68278,17 @@ var ServerSession = class {
68222
68278
  });
68223
68279
  if (!res.ok) {
68224
68280
  const detail = await res.text().catch(() => "");
68281
+ let reason;
68282
+ try {
68283
+ const parsed = JSON.parse(detail);
68284
+ if (typeof parsed?.reason === "string")
68285
+ reason = parsed.reason;
68286
+ } catch {
68287
+ }
68225
68288
  throw new ServerLoginError(
68226
68289
  `lit-ops-server login failed: HTTP ${res.status} ${detail.slice(0, 200)}`,
68227
- res.status
68290
+ res.status,
68291
+ reason
68228
68292
  );
68229
68293
  }
68230
68294
  const body = await res.json();
@@ -73798,7 +73862,7 @@ var DiamondHandsGraph = class {
73798
73862
  async getPSMConfiguration() {
73799
73863
  const query = `
73800
73864
  query GetPSMConfiguration {
73801
- psmConfiguration(id: "psm") {
73865
+ psmConfiguration: psmconfiguration(id: "psm") {
73802
73866
  id
73803
73867
  version
73804
73868
  redeemEnabled
@@ -73920,7 +73984,7 @@ var DiamondHandsGraph = class {
73920
73984
  const whereClause = whereConditions.length > 0 ? `where: { ${whereConditions.join(", ")} }` : "";
73921
73985
  const query = `
73922
73986
  query GetPSMTransactions($first: Int!, $skip: Int!) {
73923
- psmTransactions(${whereClause}, first: $first, skip: $skip, orderBy: timestamp, orderDirection: desc) {
73987
+ psmTransactions: psmtransactions(${whereClause}, first: $first, skip: $skip, orderBy: timestamp, orderDirection: desc) {
73924
73988
  id
73925
73989
  type
73926
73990
  user
@@ -73955,7 +74019,7 @@ var DiamondHandsGraph = class {
73955
74019
  const whereClause = whereConditions.length > 0 ? `where: { ${whereConditions.join(", ")} }` : "";
73956
74020
  const query = `
73957
74021
  query GetPSMDailyMetrics($first: Int!) {
73958
- psmDailyMetrics(${whereClause}, first: $first, orderBy: date, orderDirection: desc) {
74022
+ psmDailyMetrics: psmdailyMetrics(${whereClause}, first: $first, orderBy: date, orderDirection: desc) {
73959
74023
  id
73960
74024
  date
73961
74025
  totalSwapVolume
@@ -74679,7 +74743,7 @@ var DiamondHandsGraph = class {
74679
74743
  }` : ""}
74680
74744
 
74681
74745
  ${includeKind("psm") ? `
74682
- psmTransactions(
74746
+ psmTransactions: psmtransactions(
74683
74747
  ${buildTimeWhereClause()}
74684
74748
  first: $limit, orderBy: timestamp, orderDirection: $orderDirection
74685
74749
  ) {
@@ -85700,23 +85764,28 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
85700
85764
  * @throws if timeout is reached before subgraph catches up
85701
85765
  */
85702
85766
  // ============================================================================
85703
- // HIGH-LEVEL API - Agent Delegation (auto-renew) — SEPOLIA ONLY
85767
+ // HIGH-LEVEL API - Agent Delegation (auto-renew)
85704
85768
  // ============================================================================
85705
- /** Guard: the AgentDelegationRegistry MVP is deployed on Sepolia only. */
85706
- async assertAgentDelegationSepolia() {
85707
- const chainId = Number((await this.getProviderOrThrow().getNetwork()).chainId);
85708
- if (chainId !== 11155111) {
85709
- throw new SDKError({
85710
- message: `Agent auto-renew delegation is Sepolia-only (chainId 11155111); got ${chainId}`,
85711
- category: "NETWORK",
85712
- severity: "HIGH"
85713
- /* HIGH */
85714
- });
85715
- }
85769
+ /**
85770
+ * Guard: resolve the AgentDelegationRegistry for the configured network.
85771
+ *
85772
+ * Deployment presence IS the availability test — there is deliberately no chainId
85773
+ * allow-list here. The registry is deployed per network (Sepolia 2026-07, mainnet
85774
+ * 2026-08 agent-stack release) and `getNetworkConfig` populates the address from the
85775
+ * generated deployment table, so a chain without a deployment resolves to `""` and
85776
+ * fails closed below. Adding a chain therefore needs no SDK code change — which is
85777
+ * exactly how the previous hardcoded `chainId !== 11155111` gate went stale and kept
85778
+ * the mainnet toggle dark after the registry shipped.
85779
+ *
85780
+ * Callers that need the availability answer WITHOUT throwing (e.g. to decide whether to
85781
+ * render a toggle at all) should ask the deployment table directly rather than calling this
85782
+ * and catching — `ALL_DEPLOYMENTS` is published on the `@gvnrdao/dh-sdk/deployments` subpath.
85783
+ */
85784
+ agentDelegationRegistryOrThrow() {
85716
85785
  const addr = this.config.contractAddresses?.agentDelegationRegistry;
85717
85786
  if (!addr) {
85718
85787
  throw new SDKError({
85719
- message: "AgentDelegationRegistry address not configured \u2014 provide contractAddresses.agentDelegationRegistry",
85788
+ message: "AgentDelegationRegistry is not available on this network \u2014 no deployment address is configured (contractAddresses.agentDelegationRegistry)",
85720
85789
  category: "CONFIGURATION",
85721
85790
  severity: "HIGH"
85722
85791
  /* HIGH */
@@ -85729,7 +85798,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
85729
85798
  * Pure view — no signer required.
85730
85799
  */
85731
85800
  async getAutoRenewStatus(positionId, user) {
85732
- const addr = await this.assertAgentDelegationSepolia();
85801
+ const addr = this.agentDelegationRegistryOrThrow();
85733
85802
  const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
85734
85803
  const pid = this.toBytes32(positionId);
85735
85804
  const grant = await registry.getLoanGrant(pid);
@@ -85749,7 +85818,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
85749
85818
  * registers it, then records the position's renew grant. Borrower-signed.
85750
85819
  */
85751
85820
  async enableAutoRenew(positionId, options) {
85752
- const addr = await this.assertAgentDelegationSepolia();
85821
+ const addr = this.agentDelegationRegistryOrThrow();
85753
85822
  const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
85754
85823
  if (!pdrAddr) {
85755
85824
  throw new SDKError({
@@ -85790,7 +85859,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
85790
85859
  }
85791
85860
  /** Disable auto-renew delegation for a position (clears the grant). Borrower-signed. */
85792
85861
  async disableAutoRenew(positionId) {
85793
- const addr = await this.assertAgentDelegationSepolia();
85862
+ const addr = this.agentDelegationRegistryOrThrow();
85794
85863
  const signer = this.getSignerOrThrow();
85795
85864
  const user = await signer.getAddress();
85796
85865
  const registry = AgentDelegationRegistry__factory.connect(addr, signer);
package/dist/index.js CHANGED
@@ -61973,7 +61973,7 @@ var init_deployment_addresses = __esm2({
61973
61973
  LiquidationManagerModule: "0x74B28695352E7bf736D6c9F76ccb7B4439477De9",
61974
61974
  CircuitBreakerModule: "0xF7b545d3a4Ee056D06909AB367E2F7bFFE3cB1BC",
61975
61975
  AdminModule: "0x0023B71B586795eE5fa4E83E384345C1EC8Bb946",
61976
- PositionManagerViews: "0x9225647a30bbACA4Acc0491B786869036914242e",
61976
+ PositionManagerViews: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
61977
61977
  PositionManager: "0x12A1836e56139ccaD8722B89519d84233efc224B",
61978
61978
  OperationAuthorizationRegistry: "0xD4505645b724754f5170a2027804a4265e860d44",
61979
61979
  ContractVersionRegistry: "0x5e18f77d01940dA5B1D986D373D9A6ad0767008d",
@@ -62051,13 +62051,13 @@ var init_deployment_addresses = __esm2({
62051
62051
  block: 25472957
62052
62052
  },
62053
62053
  PositionManager: {
62054
- previousImplementation: "0x9f52BaBB40FbFC5863e45B1A4014cB433950c684",
62055
- newImplementation: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
62056
- upgradedAt: "2026-07-06T08:42:47.000Z",
62057
- upgradedBy: "AdminModule/Safe audit-batch upgradeToAndCall; executed by 0x2002827d34A781883Ec4c83c36ECC140c3911F2B in tx 0xa1fbe31cb71736514a868e681573dff22c9fab91d69cec157a24a30e29eadbe6 (block 25472368)",
62058
- reason: "Reconciled from chain \u2014 mainnet audit rollout batch (cross-ref onchain-auth/.safe-batches/mainnet-audit-execute.json)",
62059
- executeTx: "0xa1fbe31cb71736514a868e681573dff22c9fab91d69cec157a24a30e29eadbe6",
62060
- block: 25472368
62054
+ previousImplementation: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
62055
+ newImplementation: "0x2e7170d6Fb15A876dB726732e72e63109bcB916d",
62056
+ upgradedAt: "2026-08-03T08:34:23.000Z",
62057
+ upgradedBy: "AdminModule generic-op 0x69b79a906ed2 (3-of-3 signatures, 24h timelock; proposed by 0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f, executed in the release batch onchain-auth/.safe-batches/mainnet-release-execute-B.json, submitted by EOA 0x2002827d34A781883Ec4c83c36ECC140c3911F2B, tx 0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6, block 25673200)",
62058
+ reason: "2026-08 agent-stack release, Execute B: agent-delegation digest rebind. makePayment/mintUCD/extendPosition now bind their EIP-712 digest to the STORED borrower rather than msg.sender, so a scoped AgentDelegationRegistry grant can submit; withdrawBTC still binds msg.sender and stays non-delegable. Also adds setViews(address), which the same batch used to repoint PM at the replacement PositionManagerViews. NOTE: VERSION reads 1.5.4 on BOTH sides of this upgrade \u2014 verify by implementation ADDRESS, never by VERSION(). NOTE: not the July audit rollout batch \u2014 reconcile-deployment-record.ts --write templates every row with that text; this hand-authored provenance is the accurate one, restore it if --write flattens it again.",
62059
+ executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
62060
+ block: 25673200
62061
62061
  },
62062
62062
  LoanOperationsManagerModule: {
62063
62063
  previousImplementation: "0x56671D671e492Dae625413d463D47605Cf54edf6",
@@ -62101,6 +62101,16 @@ var init_deployment_addresses = __esm2({
62101
62101
  reason: "2026-08 agent-stack release: PositionDelegateRegistry VERSION 1.1.0 -> 2.0.0 via upgradeToAndCall + initializeV2(AdminModule, registrar 0x5D54E0BE\u2026, pauser 0xC205Ae99\u2026) \u2014 kill-switch, deny-only registrar, permanent delegate burn. NOTE: not the July audit rollout batch \u2014 reconcile-deployment-record.ts --write templates every row with that text; this hand-authored provenance is the accurate one, restore it if --write flattens it again.",
62102
62102
  executeTx: "0xf0f237f6c4e958c37de556571908283c59c3fba6ebf9fa3cefb956f37e315a10",
62103
62103
  block: 25669024
62104
+ },
62105
+ PositionManagerViews: {
62106
+ previousImplementation: "0x9225647a30bbACA4Acc0491B786869036914242e",
62107
+ newImplementation: "0xE68DC096A65Ecddbc6A9b5c6e5f878e2CE143Bfe",
62108
+ proxy: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
62109
+ upgradedAt: "2026-08-03T08:34:23.000Z",
62110
+ upgradedBy: "REPLACED, not upgraded. Fresh ERC1967Proxy (atomically initialized) + AdminModule generic-op 0x848a97186f0d PositionManager.setViews(proxy) \u2014 3-of-3, 24h timelock, executed in onchain-auth/.safe-batches/mainnet-release-execute-B.json",
62111
+ 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.",
62112
+ executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
62113
+ block: 25673200
62104
62114
  }
62105
62115
  },
62106
62116
  latestEnv: {
@@ -62134,10 +62144,10 @@ var init_deployment_addresses = __esm2({
62134
62144
  ADMIN_MODULE_IMPL: "0xb4C5C7E051A1e672F014B25CB5D55B225Aa0D512",
62135
62145
  BTC_SPEND_AUTHORIZER: "0xfBbF108486fa07F1B06a811C5b66ed68DD9c508a",
62136
62146
  BTC_SPEND_AUTHORIZER_IMPL: "0x40c9e8C46C65E0A57BB63da5368868A9E8Df81A5",
62137
- POSITION_MANAGER_VIEWS: "0x9225647a30bbACA4Acc0491B786869036914242e",
62138
- POSITION_MANAGER_VIEWS_IMPL: "0x9225647a30bbACA4Acc0491B786869036914242e",
62147
+ POSITION_MANAGER_VIEWS: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
62148
+ POSITION_MANAGER_VIEWS_IMPL: "0xE68DC096A65Ecddbc6A9b5c6e5f878e2CE143Bfe",
62139
62149
  POSITION_MANAGER: "0x12A1836e56139ccaD8722B89519d84233efc224B",
62140
- POSITION_MANAGER_IMPL: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
62150
+ POSITION_MANAGER_IMPL: "0x2e7170d6Fb15A876dB726732e72e63109bcB916d",
62141
62151
  LOAN_OPERATIONS_MANAGER_MODULE: "0x2561974A40F1AEed1251d0A090A83cF8536FB9E9",
62142
62152
  LOAN_OPERATIONS_MANAGER_MODULE_IMPL: "0x7d90aAB4466f59BA9aC9C7a9BF14dC53734336e7",
62143
62153
  UPGRADE_VALIDATOR: "0xC46Ae71F22e3741A6CF46E399aE914C4868fEbed",
@@ -62163,7 +62173,7 @@ var init_deployment_addresses = __esm2({
62163
62173
  LiquidationManagerModule: "0x74B28695352E7bf736D6c9F76ccb7B4439477De9",
62164
62174
  CircuitBreakerModule: "0xF7b545d3a4Ee056D06909AB367E2F7bFFE3cB1BC",
62165
62175
  AdminModule: "0x0023B71B586795eE5fa4E83E384345C1EC8Bb946",
62166
- PositionManagerViews: "0x9225647a30bbACA4Acc0491B786869036914242e",
62176
+ PositionManagerViews: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
62167
62177
  PositionManager: "0x12A1836e56139ccaD8722B89519d84233efc224B",
62168
62178
  OperationAuthorizationRegistry: "0xD4505645b724754f5170a2027804a4265e860d44",
62169
62179
  ContractVersionRegistry: "0x5e18f77d01940dA5B1D986D373D9A6ad0767008d",
@@ -67987,6 +67997,7 @@ function sessionStoreKey(address, chainId, endpoint) {
67987
67997
  return STORE_PREFIX + `${address.trim().toLowerCase()}:${chainId}:${endpoint.replace(/\/+$/, "")}`;
67988
67998
  }
67989
67999
  var PENDING_ENVELOPE_TTL_SECONDS = 8 * 60;
68000
+ var EOA_PENDING_ENVELOPE_TTL_SECONDS = 60;
67990
68001
  function pendingEnvelopeKey(sessionKey) {
67991
68002
  return sessionKey + ":pending";
67992
68003
  }
@@ -68034,7 +68045,7 @@ var LocalStorageSessionStore = class {
68034
68045
  } catch {
68035
68046
  }
68036
68047
  }
68037
- loadPending(key) {
68048
+ loadPending(key, maxAgeSeconds = PENDING_ENVELOPE_TTL_SECONDS) {
68038
68049
  let raw;
68039
68050
  try {
68040
68051
  raw = window.localStorage.getItem(pendingEnvelopeKey(key));
@@ -68051,7 +68062,7 @@ var LocalStorageSessionStore = class {
68051
68062
  return null;
68052
68063
  }
68053
68064
  const nowSec = Math.floor(Date.now() / 1e3);
68054
- if (!isPendingEnvelopeShape(parsed) || nowSec >= parsed.issuedAt + PENDING_ENVELOPE_TTL_SECONDS) {
68065
+ if (!isPendingEnvelopeShape(parsed) || nowSec >= parsed.issuedAt + maxAgeSeconds) {
68055
68066
  this.clearPending(key);
68056
68067
  return null;
68057
68068
  }
@@ -68085,12 +68096,12 @@ var MemorySessionStore = class {
68085
68096
  clear(key) {
68086
68097
  this.entries.delete(key);
68087
68098
  }
68088
- loadPending(key) {
68099
+ loadPending(key, maxAgeSeconds = PENDING_ENVELOPE_TTL_SECONDS) {
68089
68100
  const envelope = this.pending.get(key);
68090
68101
  if (!envelope)
68091
68102
  return null;
68092
68103
  const nowSec = Math.floor(Date.now() / 1e3);
68093
- if (nowSec >= envelope.issuedAt + PENDING_ENVELOPE_TTL_SECONDS) {
68104
+ if (nowSec >= envelope.issuedAt + maxAgeSeconds) {
68094
68105
  this.pending.delete(key);
68095
68106
  return null;
68096
68107
  }
@@ -68122,15 +68133,23 @@ var REFRESH_LEEWAY_SECONDS = 30;
68122
68133
  var LOGIN_RETRY_BASE_MS = 3e4;
68123
68134
  var LOGIN_RETRY_MAX_MS = 5 * 6e4;
68124
68135
  var ServerLoginError = class extends Error {
68125
- constructor(message, status) {
68136
+ constructor(message, status, reason) {
68126
68137
  super(message);
68127
68138
  this.status = status;
68139
+ this.reason = reason;
68128
68140
  this.name = "ServerLoginError";
68129
68141
  }
68130
68142
  };
68131
68143
  function isLoginRejection(error) {
68132
68144
  return error instanceof ServerLoginError && error.status >= 400 && error.status < 500 && error.status !== 429;
68133
68145
  }
68146
+ var SPENT_ENVELOPE_REASONS = /* @__PURE__ */ new Set(["replayed_nonce", "expired_issuedAt"]);
68147
+ function isSpentEnvelope(error) {
68148
+ if (!isLoginRejection(error))
68149
+ return false;
68150
+ const { reason, status } = error;
68151
+ return reason ? SPENT_ENVELOPE_REASONS.has(reason) : status === 409;
68152
+ }
68134
68153
  var ServerSession = class {
68135
68154
  signer;
68136
68155
  serviceEndpoint;
@@ -68161,6 +68180,12 @@ var ServerSession = class {
68161
68180
  * `clear()` can drop the persisted token without an async address lookup.
68162
68181
  */
68163
68182
  lastStoreKey = null;
68183
+ /**
68184
+ * Whether the signer is a smart-contract wallet, memoized after the first
68185
+ * `eth_getCode`. Decides which of the server's two first-use windows bounds
68186
+ * envelope reuse; a signer cannot change kind for the life of the session.
68187
+ */
68188
+ contractSigner = null;
68164
68189
  constructor(opts) {
68165
68190
  assertSafeServiceEndpoint(opts.serviceEndpoint);
68166
68191
  this.signer = opts.signer;
@@ -68359,6 +68384,34 @@ var ServerSession = class {
68359
68384
  return null;
68360
68385
  }
68361
68386
  }
68387
+ /**
68388
+ * How long a pending envelope for THIS signer may be reused, in seconds.
68389
+ *
68390
+ * The server grants an EOA 120s to make an envelope's first use and a contract
68391
+ * wallet 600s, so one local TTL is necessarily wrong for one of them. Deployed
68392
+ * code has bytecode; an EOA does not — one `eth_getCode`, memoized, settles it.
68393
+ *
68394
+ * Reports the CONTRACT window when it cannot tell, which is the behavior that
68395
+ * shipped before the split. The asymmetry is intended: guessing "EOA" for a
68396
+ * Safe hands it a new message and orphans the owner signatures already
68397
+ * collected, while guessing "contract" for an EOA now costs one rejected
68398
+ * attempt, because a rejection clears the envelope.
68399
+ */
68400
+ async pendingEnvelopeTtl() {
68401
+ if (this.contractSigner === null) {
68402
+ try {
68403
+ const provider = this.signer.provider;
68404
+ if (!provider)
68405
+ return PENDING_ENVELOPE_TTL_SECONDS;
68406
+ const address = await this.signer.getAddress();
68407
+ const code = await provider.getCode(address);
68408
+ this.contractSigner = typeof code === "string" && code !== "0x";
68409
+ } catch {
68410
+ return PENDING_ENVELOPE_TTL_SECONDS;
68411
+ }
68412
+ }
68413
+ return this.contractSigner ? PENDING_ENVELOPE_TTL_SECONDS : EOA_PENDING_ENVELOPE_TTL_SECONDS;
68414
+ }
68362
68415
  async getOrRefresh() {
68363
68416
  const nowSec = this.now();
68364
68417
  if (this.cached && this.cached.expiresAt - REFRESH_LEEWAY_SECONDS > nowSec) {
@@ -68380,10 +68433,10 @@ var ServerSession = class {
68380
68433
  }
68381
68434
  this.onSignaturePrompt?.();
68382
68435
  let session;
68436
+ const store = this.store;
68437
+ const storeKey = store ? this.lastStoreKey : null;
68383
68438
  try {
68384
- const store = this.store;
68385
- const storeKey = store ? this.lastStoreKey : null;
68386
- const reuse = storeKey ? store.loadPending?.(storeKey) ?? void 0 : void 0;
68439
+ const reuse = storeKey ? store.loadPending?.(storeKey, await this.pendingEnvelopeTtl()) ?? void 0 : void 0;
68387
68440
  const payload = await buildSignedLoginPayload(
68388
68441
  this.signer,
68389
68442
  this.chainId,
@@ -68406,6 +68459,9 @@ var ServerSession = class {
68406
68459
  this.onSignatureResolved?.(true);
68407
68460
  } catch (error) {
68408
68461
  this.onSignatureResolved?.(false);
68462
+ if (storeKey && isSpentEnvelope(error)) {
68463
+ store.clearPending?.(storeKey);
68464
+ }
68409
68465
  const failures = (this.promptBackoff?.failures ?? 0) + 1;
68410
68466
  this.promptBackoff = {
68411
68467
  failures,
@@ -68434,9 +68490,17 @@ var ServerSession = class {
68434
68490
  });
68435
68491
  if (!res.ok) {
68436
68492
  const detail = await res.text().catch(() => "");
68493
+ let reason;
68494
+ try {
68495
+ const parsed = JSON.parse(detail);
68496
+ if (typeof parsed?.reason === "string")
68497
+ reason = parsed.reason;
68498
+ } catch {
68499
+ }
68437
68500
  throw new ServerLoginError(
68438
68501
  `lit-ops-server login failed: HTTP ${res.status} ${detail.slice(0, 200)}`,
68439
- res.status
68502
+ res.status,
68503
+ reason
68440
68504
  );
68441
68505
  }
68442
68506
  const body = await res.json();
@@ -74010,7 +74074,7 @@ var DiamondHandsGraph = class {
74010
74074
  async getPSMConfiguration() {
74011
74075
  const query = `
74012
74076
  query GetPSMConfiguration {
74013
- psmConfiguration(id: "psm") {
74077
+ psmConfiguration: psmconfiguration(id: "psm") {
74014
74078
  id
74015
74079
  version
74016
74080
  redeemEnabled
@@ -74132,7 +74196,7 @@ var DiamondHandsGraph = class {
74132
74196
  const whereClause = whereConditions.length > 0 ? `where: { ${whereConditions.join(", ")} }` : "";
74133
74197
  const query = `
74134
74198
  query GetPSMTransactions($first: Int!, $skip: Int!) {
74135
- psmTransactions(${whereClause}, first: $first, skip: $skip, orderBy: timestamp, orderDirection: desc) {
74199
+ psmTransactions: psmtransactions(${whereClause}, first: $first, skip: $skip, orderBy: timestamp, orderDirection: desc) {
74136
74200
  id
74137
74201
  type
74138
74202
  user
@@ -74167,7 +74231,7 @@ var DiamondHandsGraph = class {
74167
74231
  const whereClause = whereConditions.length > 0 ? `where: { ${whereConditions.join(", ")} }` : "";
74168
74232
  const query = `
74169
74233
  query GetPSMDailyMetrics($first: Int!) {
74170
- psmDailyMetrics(${whereClause}, first: $first, orderBy: date, orderDirection: desc) {
74234
+ psmDailyMetrics: psmdailyMetrics(${whereClause}, first: $first, orderBy: date, orderDirection: desc) {
74171
74235
  id
74172
74236
  date
74173
74237
  totalSwapVolume
@@ -74891,7 +74955,7 @@ var DiamondHandsGraph = class {
74891
74955
  }` : ""}
74892
74956
 
74893
74957
  ${includeKind("psm") ? `
74894
- psmTransactions(
74958
+ psmTransactions: psmtransactions(
74895
74959
  ${buildTimeWhereClause()}
74896
74960
  first: $limit, orderBy: timestamp, orderDirection: $orderDirection
74897
74961
  ) {
@@ -85912,23 +85976,28 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
85912
85976
  * @throws if timeout is reached before subgraph catches up
85913
85977
  */
85914
85978
  // ============================================================================
85915
- // HIGH-LEVEL API - Agent Delegation (auto-renew) — SEPOLIA ONLY
85979
+ // HIGH-LEVEL API - Agent Delegation (auto-renew)
85916
85980
  // ============================================================================
85917
- /** Guard: the AgentDelegationRegistry MVP is deployed on Sepolia only. */
85918
- async assertAgentDelegationSepolia() {
85919
- const chainId = Number((await this.getProviderOrThrow().getNetwork()).chainId);
85920
- if (chainId !== 11155111) {
85921
- throw new SDKError({
85922
- message: `Agent auto-renew delegation is Sepolia-only (chainId 11155111); got ${chainId}`,
85923
- category: "NETWORK",
85924
- severity: "HIGH"
85925
- /* HIGH */
85926
- });
85927
- }
85981
+ /**
85982
+ * Guard: resolve the AgentDelegationRegistry for the configured network.
85983
+ *
85984
+ * Deployment presence IS the availability test — there is deliberately no chainId
85985
+ * allow-list here. The registry is deployed per network (Sepolia 2026-07, mainnet
85986
+ * 2026-08 agent-stack release) and `getNetworkConfig` populates the address from the
85987
+ * generated deployment table, so a chain without a deployment resolves to `""` and
85988
+ * fails closed below. Adding a chain therefore needs no SDK code change — which is
85989
+ * exactly how the previous hardcoded `chainId !== 11155111` gate went stale and kept
85990
+ * the mainnet toggle dark after the registry shipped.
85991
+ *
85992
+ * Callers that need the availability answer WITHOUT throwing (e.g. to decide whether to
85993
+ * render a toggle at all) should ask the deployment table directly rather than calling this
85994
+ * and catching — `ALL_DEPLOYMENTS` is published on the `@gvnrdao/dh-sdk/deployments` subpath.
85995
+ */
85996
+ agentDelegationRegistryOrThrow() {
85928
85997
  const addr = this.config.contractAddresses?.agentDelegationRegistry;
85929
85998
  if (!addr) {
85930
85999
  throw new SDKError({
85931
- message: "AgentDelegationRegistry address not configured \u2014 provide contractAddresses.agentDelegationRegistry",
86000
+ message: "AgentDelegationRegistry is not available on this network \u2014 no deployment address is configured (contractAddresses.agentDelegationRegistry)",
85932
86001
  category: "CONFIGURATION",
85933
86002
  severity: "HIGH"
85934
86003
  /* HIGH */
@@ -85941,7 +86010,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
85941
86010
  * Pure view — no signer required.
85942
86011
  */
85943
86012
  async getAutoRenewStatus(positionId, user) {
85944
- const addr = await this.assertAgentDelegationSepolia();
86013
+ const addr = this.agentDelegationRegistryOrThrow();
85945
86014
  const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
85946
86015
  const pid = this.toBytes32(positionId);
85947
86016
  const grant = await registry.getLoanGrant(pid);
@@ -85961,7 +86030,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
85961
86030
  * registers it, then records the position's renew grant. Borrower-signed.
85962
86031
  */
85963
86032
  async enableAutoRenew(positionId, options) {
85964
- const addr = await this.assertAgentDelegationSepolia();
86033
+ const addr = this.agentDelegationRegistryOrThrow();
85965
86034
  const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
85966
86035
  if (!pdrAddr) {
85967
86036
  throw new SDKError({
@@ -86002,7 +86071,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
86002
86071
  }
86003
86072
  /** Disable auto-renew delegation for a position (clears the grant). Borrower-signed. */
86004
86073
  async disableAutoRenew(positionId) {
86005
- const addr = await this.assertAgentDelegationSepolia();
86074
+ const addr = this.agentDelegationRegistryOrThrow();
86006
86075
  const signer = this.getSignerOrThrow();
86007
86076
  const user = await signer.getAddress();
86008
86077
  const registry = AgentDelegationRegistry__factory.connect(addr, signer);
@@ -91321,6 +91390,12 @@ calls. Every operation that moves funds requires the user's explicit confirmatio
91321
91390
  (\`confirmed: true\`) \u2014 nothing is ever silent.`,
91322
91391
  "first-setup": `# First setup \u2014 from zero to ready, by conversation only
91323
91392
 
91393
+ Installing on another machine? Three paths, by machine: Claude Desktop on macOS/Windows
91394
+ \u2192 the \`.mcpb\` bundle from the releases page (no Node needed); Linux or any other MCP
91395
+ host \u2192 the one-line installer (self-contained binary, prints the exact config snippet);
91396
+ developers with Node \u2265 18 on PATH \u2192 \`npx -y @gvnrdao/dh-mcp\`. Details: the README
91397
+ install matrix.
91398
+
91324
91399
  Nothing needs a config file. Three steps:
91325
91400
 
91326
91401
  **1. Know your world.** Read \`boundary://info\` (its \`capabilities\` block) and
@@ -91646,7 +91721,12 @@ owners sign at leisure (\`psm_swap\` builds the pair) \u2014 that is the only Sa
91646
91721
  - **STATE_DIVERGENCE / STALE_DATA warnings** \u2014 sources disagree or lag; the envelope says
91647
91722
  which source and when from. Prefer chain-sourced values; re-read before acting.
91648
91723
  - Approval popup never appeared? \`signer_setup status\` \u2192 reopen the approval page URL.
91649
- Wallet on the wrong network? The page offers the switch \u2014 approve it in the wallet.`,
91724
+ Wallet on the wrong network? The page offers the switch \u2014 approve it in the wallet.
91725
+ - **\`spawn npx ENOENT\` at server start (another machine/host)** \u2014 the MCP host searched
91726
+ the system PATH and found no \`npx\`: that machine has no Node.js, or the host (e.g. an
91727
+ Electron app) cannot see a shell-managed Node. Not a server bug \u2014 the npx path requires
91728
+ Node \u2265 18 on PATH. Remedies: the one-line installer (self-contained binary, absolute
91729
+ path in the printed snippet), or the \`.mcpb\` bundle on macOS/Windows Claude Desktop.`,
91650
91730
  glossary: `# Glossary \u2014 map the user's words to the protocol's
91651
91731
 
91652
91732
  Synonym sets (treat these as the SAME intent):
@@ -91885,7 +91965,7 @@ function registerBoundaryInfoResource(server, getB) {
91885
91965
  }
91886
91966
 
91887
91967
  // src/server.ts
91888
- var SERVER_VERSION = "0.2.0";
91968
+ var SERVER_VERSION = "0.2.1";
91889
91969
  var SERVER_INSTRUCTIONS = "Diamond Hands MCP \u2014 Bitcoin-collateralized borrowing. Before promising ANY flow, read the boundary://info resource and honor its `capabilities` block: it states which network this server is on, whether money is real (practiceWorld), whether writes are enabled (and the true reason when they are not), and which signer modes this build actually offers \u2014 never describe a flow outside it. State the network and whether funds are real when the user first acts. Authorization is chosen by conversation via the signer_setup tool (when listed); writes always require confirmed:true after showing the human-readable card. For walkthroughs consult the guide tool / guide:// resources instead of inventing steps; when a tool refuses, relay its stated reason and remedy \u2014 do not improvise alternatives.";
91890
91970
  function createServer2(deps) {
91891
91971
  const server = new import_mcp2.McpServer(
@@ -91917,6 +91997,11 @@ function createServer2(deps) {
91917
91997
  }
91918
91998
 
91919
91999
  // src/index.ts
92000
+ if (process.argv.includes("--version")) {
92001
+ process.stdout.write(`${SERVER_VERSION}
92002
+ `);
92003
+ process.exit(0);
92004
+ }
91920
92005
  async function main() {
91921
92006
  const configResult = resolveBoundaryConfig(process.env);
91922
92007
  const boot = await buildBoundary(configResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "MCP server for the Diamond Hands protocol — Bitcoin-collateralized UCD lending with human-approved signing (sepolia by default; mainnet read-only)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -16,7 +16,10 @@
16
16
  "dist/boundary.js"
17
17
  ],
18
18
  "scripts": {
19
- "build": "tsup && node scripts/postbuild-stub-telegram.mjs",
19
+ "build": "tsup && node scripts/postbuild-stub-telegram.mjs && node scripts/postbuild-standalone-require.mjs",
20
+ "build:mcpb": "npm run build && node scripts/build-mcpb.mjs && node scripts/assert-mcpb.mjs",
21
+ "build:binaries": "npm run build && node scripts/build-binaries.mjs",
22
+ "assert:install": "node scripts/assert-install.mjs",
20
23
  "prepack": "npm run typecheck && npm run build",
21
24
  "dev": "tsup --watch",
22
25
  "typecheck": "node --max-old-space-size=8192 ./node_modules/typescript/bin/tsc --noEmit",
@@ -37,13 +40,16 @@
37
40
  "zod": "3.25.76"
38
41
  },
39
42
  "devDependencies": {
40
- "@gvnrdao/dh-sdk": "0.0.318",
43
+ "@anthropic-ai/mcpb": "2.1.2",
44
+ "@gvnrdao/dh-sdk": "0.0.320",
41
45
  "@types/jest": "29.5.12",
42
46
  "@types/node": "20.14.10",
47
+ "@yao-pkg/pkg": "6.22.0",
48
+ "fflate": "0.8.3",
43
49
  "jest": "29.7.0",
44
50
  "ts-jest": "29.2.5",
45
51
  "tsup": "8.4.0",
46
52
  "typescript": "5.9.3"
47
53
  },
48
- "x-dh-sdk-provenance": "0.0.318 @ c4a2c37cf (bundled into dist at build time)"
54
+ "x-dh-sdk-provenance": "0.0.320 @ 7b86c0d25 (bundled into dist at build time)"
49
55
  }