@gvnrdao/dh-mcp 0.5.10 → 0.5.12
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 +5 -3
- package/connector-embed.d.ts +23 -0
- package/dist/boundary.js +81 -28
- package/dist/connector-embed.js +2337 -1387
- package/dist/connector.js +2348 -1381
- package/dist/index.js +1383 -1043
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -498,7 +498,7 @@ var require_utils = __commonJS({
|
|
|
498
498
|
exports2.createHasher = createHasher2;
|
|
499
499
|
exports2.createOptHasher = createOptHasher;
|
|
500
500
|
exports2.createXOFer = createXOFer;
|
|
501
|
-
exports2.randomBytes =
|
|
501
|
+
exports2.randomBytes = randomBytes4;
|
|
502
502
|
var crypto_1 = require_cryptoNode();
|
|
503
503
|
function isBytes2(a) {
|
|
504
504
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
@@ -696,7 +696,7 @@ var require_utils = __commonJS({
|
|
|
696
696
|
exports2.wrapConstructor = createHasher2;
|
|
697
697
|
exports2.wrapConstructorWithOpts = createOptHasher;
|
|
698
698
|
exports2.wrapXOFConstructorWithOpts = createXOFer;
|
|
699
|
-
function
|
|
699
|
+
function randomBytes4(bytesLength = 32) {
|
|
700
700
|
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
|
|
701
701
|
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
702
702
|
}
|
|
@@ -40638,7 +40638,11 @@ var NETWORK_DEFAULTS = {
|
|
|
40638
40638
|
},
|
|
40639
40639
|
mainnet: {
|
|
40640
40640
|
rpcUrl: "https://ethereum-rpc.publicnode.com",
|
|
40641
|
-
|
|
40641
|
+
// Cutover 2026-09-08 — see sdk/src/constants/chunks/network-configs.ts for the full
|
|
40642
|
+
// reasoning. Widening, not a rename: ops.gvnr.xyz serves the same broker and cannot be
|
|
40643
|
+
// retired while installed copies call it. The sepolia entry above deliberately stays on
|
|
40644
|
+
// ops-test.gvnr.xyz — there is no ops-test.diamondhands.credit twin (open decision 2).
|
|
40645
|
+
serviceEndpoint: "https://ops.diamondhands.credit",
|
|
40642
40646
|
litNetwork: "chipotle",
|
|
40643
40647
|
// On-chain PKPValidation generation, mainnet (validatorForVersion(3) is the ONLY
|
|
40644
40648
|
// registered validator — verified live 2026-08-05). Without this the SDK defaults
|
|
@@ -40829,7 +40833,7 @@ var fs6 = __toESM(require("fs"));
|
|
|
40829
40833
|
var import_ethers39 = require("ethers");
|
|
40830
40834
|
|
|
40831
40835
|
// src/boundary/index.ts
|
|
40832
|
-
var
|
|
40836
|
+
var import_node_crypto8 = require("crypto");
|
|
40833
40837
|
var fs5 = __toESM(require("fs"));
|
|
40834
40838
|
var os2 = __toESM(require("os"));
|
|
40835
40839
|
var path4 = __toESM(require("path"));
|
|
@@ -56902,7 +56906,17 @@ function getSepoliaConfig() {
|
|
|
56902
56906
|
function getMainnetConfig() {
|
|
56903
56907
|
return {
|
|
56904
56908
|
mode: "service",
|
|
56905
|
-
|
|
56909
|
+
// Cutover 2026-09-08: the product's own domain. `ops.gvnr.xyz` still serves the same
|
|
56910
|
+
// broker and always will — every already-installed copy of this package calls it, so
|
|
56911
|
+
// it can never be retired. This changes what NEW installs default to, nothing else.
|
|
56912
|
+
//
|
|
56913
|
+
// Safe only because the server accepts the new audience ALREADY: the SDK derives the
|
|
56914
|
+
// login audience from this endpoint (`server-session.ts` — `loginAudience ??
|
|
56915
|
+
// serviceEndpoint`) and lit-ops-server FAILS CLOSED on an unknown one. Verified live
|
|
56916
|
+
// before this edit: DH_ACCEPTED_LOGIN_AUDIENCES on the deployed revision lists
|
|
56917
|
+
// https://ops.diamondhands.credit. Publishing this ahead of that would lock out every
|
|
56918
|
+
// client that installed it.
|
|
56919
|
+
serviceEndpoint: "https://ops.diamondhands.credit",
|
|
56906
56920
|
chainId: 1,
|
|
56907
56921
|
name: "mainnet",
|
|
56908
56922
|
// No default RPC: mainnet runs in service mode (serviceEndpoint above), so
|
|
@@ -79740,13 +79754,20 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers37.ether
|
|
|
79740
79754
|
const outcome = await this.deps.bridge.requestSignature({
|
|
79741
79755
|
id: (0, import_node_crypto5.randomUUID)(),
|
|
79742
79756
|
kind: "personal-sign",
|
|
79743
|
-
action: "btc-withdrawal
|
|
79757
|
+
action: "btc-withdrawal EXECUTE step (blind hash)",
|
|
79744
79758
|
card: [
|
|
79745
|
-
"BLIND SIGNATURE \u2014 BTC withdrawal
|
|
79759
|
+
"BLIND SIGNATURE \u2014 BTC withdrawal, EXECUTE step",
|
|
79746
79760
|
`hash: ${hashHex}`,
|
|
79747
79761
|
"This hash is built inside the SDK and its contents CANNOT be decoded or verified by this page",
|
|
79748
79762
|
"(identical to how diamondhands.credit signs withdrawals).",
|
|
79749
|
-
"Approve ONLY if you initiated this exact BTC withdrawal in the conversation."
|
|
79763
|
+
"Approve ONLY if you initiated this exact BTC withdrawal in the conversation.",
|
|
79764
|
+
"",
|
|
79765
|
+
"SIGN NOW \u2014 this one is on a clock. The payload was stamped before this card was",
|
|
79766
|
+
`raised and is only valid inside a single ${QUANTUM_WINDOW_SECONDS}-second window, so the time left is`,
|
|
79767
|
+
"under a minute and often nearer twenty seconds \u2014 far less than the approval page",
|
|
79768
|
+
"itself allows. If it expires the signature is refused, the withdrawal does not",
|
|
79769
|
+
"complete, and the reserved coins stay reserved until that is cleared. Decline and",
|
|
79770
|
+
"start again rather than signing something you have not finished reading."
|
|
79750
79771
|
],
|
|
79751
79772
|
expectedSigner: this.deps.borrower,
|
|
79752
79773
|
chainId: this.deps.chainId,
|
|
@@ -80679,10 +80700,10 @@ var RealUpstreamPlugin = class {
|
|
|
80679
80700
|
// src/boundary/upstream/shared/external-bridge/bridge.ts
|
|
80680
80701
|
var fs4 = __toESM(require("fs"));
|
|
80681
80702
|
var http3 = __toESM(require("http"));
|
|
80682
|
-
var
|
|
80703
|
+
var import_node_crypto7 = require("crypto");
|
|
80683
80704
|
|
|
80684
80705
|
// src/boundary/upstream/shared/external-bridge/approval-page.ts
|
|
80685
|
-
function renderApprovalPage(sessionId) {
|
|
80706
|
+
function renderApprovalPage(sessionId, nonce) {
|
|
80686
80707
|
return `<!doctype html>
|
|
80687
80708
|
<html lang="en">
|
|
80688
80709
|
<head>
|
|
@@ -80732,15 +80753,17 @@ function renderApprovalPage(sessionId) {
|
|
|
80732
80753
|
</div>
|
|
80733
80754
|
</div>
|
|
80734
80755
|
</main>
|
|
80735
|
-
<script>
|
|
80756
|
+
<script nonce="${nonce}">
|
|
80736
80757
|
${PAGE_CRYPTO_JS}
|
|
80737
80758
|
</script>
|
|
80738
|
-
<script>
|
|
80759
|
+
<script nonce="${nonce}">
|
|
80739
80760
|
"use strict";
|
|
80740
80761
|
const SESSION = ${JSON.stringify(sessionId)};
|
|
80741
80762
|
// One-time token leaves the address bar (and history) immediately.
|
|
80742
80763
|
// Plan 12 C1: endpoints resolve relative to the page DIRECTORY, so the same page works
|
|
80743
80764
|
// at loopback root ("/") and under a hosted tenant mount ("/approval/<id>/").
|
|
80765
|
+
// EVERY endpoint reference goes through BASE \u2014 an origin-absolute "/x" resolves to the
|
|
80766
|
+
// ORIGIN root, which on a mount is the host, not the bridge, and 404s silently.
|
|
80744
80767
|
const BASE = location.pathname.replace(/[^/]*$/, "");
|
|
80745
80768
|
history.replaceState(null, "", location.pathname);
|
|
80746
80769
|
|
|
@@ -80812,14 +80835,14 @@ async function connect() {
|
|
|
80812
80835
|
// wallet's own state transition and can report the stale value.
|
|
80813
80836
|
async function onAccountsChanged(accounts) {
|
|
80814
80837
|
account = (accounts && accounts[0]) || null;
|
|
80815
|
-
await post("
|
|
80838
|
+
await post(BASE + "wallet-event", { account: account, chainId: chainId });
|
|
80816
80839
|
showWallet();
|
|
80817
80840
|
clearRequest("Wallet changed \u2014 pending request invalidated.");
|
|
80818
80841
|
}
|
|
80819
80842
|
|
|
80820
80843
|
async function onChainChanged(cid) {
|
|
80821
80844
|
chainId = typeof cid === "string" ? parseInt(cid, 16) : Number(cid);
|
|
80822
|
-
await post("
|
|
80845
|
+
await post(BASE + "wallet-event", { account: account, chainId: chainId });
|
|
80823
80846
|
showWallet();
|
|
80824
80847
|
clearRequest("Network changed \u2014 pending request invalidated.");
|
|
80825
80848
|
}
|
|
@@ -80927,7 +80950,7 @@ connect();
|
|
|
80927
80950
|
</body>
|
|
80928
80951
|
</html>`;
|
|
80929
80952
|
}
|
|
80930
|
-
function renderUnlockPage(sessionId) {
|
|
80953
|
+
function renderUnlockPage(sessionId, nonce) {
|
|
80931
80954
|
return `<!doctype html>
|
|
80932
80955
|
<html lang="en">
|
|
80933
80956
|
<head>
|
|
@@ -80969,7 +80992,7 @@ function renderUnlockPage(sessionId) {
|
|
|
80969
80992
|
<div id="status" class="status"></div>
|
|
80970
80993
|
</div>
|
|
80971
80994
|
</main>
|
|
80972
|
-
<script>
|
|
80995
|
+
<script nonce="${nonce}">
|
|
80973
80996
|
"use strict";
|
|
80974
80997
|
const SESSION = ${JSON.stringify(sessionId)};
|
|
80975
80998
|
// Plan 12 C1: endpoints resolve relative to the page DIRECTORY, so the same page works
|
|
@@ -81000,6 +81023,34 @@ document.getElementById("generate").onclick = () => submit(true);
|
|
|
81000
81023
|
</html>`;
|
|
81001
81024
|
}
|
|
81002
81025
|
|
|
81026
|
+
// src/util/page-headers.ts
|
|
81027
|
+
var import_node_crypto6 = require("crypto");
|
|
81028
|
+
function htmlPageSecurityHeaders(extra) {
|
|
81029
|
+
const nonce = (0, import_node_crypto6.randomBytes)(16).toString("base64");
|
|
81030
|
+
const base = [
|
|
81031
|
+
`default-src 'none'`,
|
|
81032
|
+
`script-src 'nonce-${nonce}'`,
|
|
81033
|
+
`style-src 'unsafe-inline'`,
|
|
81034
|
+
`connect-src 'self'`,
|
|
81035
|
+
`base-uri 'none'`,
|
|
81036
|
+
`form-action 'none'`,
|
|
81037
|
+
`frame-ancestors 'none'`
|
|
81038
|
+
];
|
|
81039
|
+
for (const [directive, sources] of Object.entries(extra ?? {})) {
|
|
81040
|
+
if (sources.length === 0) continue;
|
|
81041
|
+
base.push(`${directive} ${sources.join(" ")}`);
|
|
81042
|
+
}
|
|
81043
|
+
return {
|
|
81044
|
+
nonce,
|
|
81045
|
+
headers: {
|
|
81046
|
+
"Content-Security-Policy": base.join("; "),
|
|
81047
|
+
"X-Frame-Options": "DENY",
|
|
81048
|
+
"Referrer-Policy": "no-referrer",
|
|
81049
|
+
"X-Content-Type-Options": "nosniff"
|
|
81050
|
+
}
|
|
81051
|
+
};
|
|
81052
|
+
}
|
|
81053
|
+
|
|
81003
81054
|
// src/boundary/upstream/shared/external-bridge/bridge.ts
|
|
81004
81055
|
var MAX_SESSIONS = 16;
|
|
81005
81056
|
var DEFAULT_EXPIRY_MS = 5 * 60 * 1e3;
|
|
@@ -81027,7 +81078,7 @@ var SignatureBridge = class {
|
|
|
81027
81078
|
/** Started state independent of the transport binding (mounted bridges own no server). */
|
|
81028
81079
|
started = false;
|
|
81029
81080
|
mount;
|
|
81030
|
-
token = (0,
|
|
81081
|
+
token = (0, import_node_crypto7.randomBytes)(24).toString("hex");
|
|
81031
81082
|
/** Hosted mounts: when the current page token was minted (rotation basis). */
|
|
81032
81083
|
tokenMintedAt = 0;
|
|
81033
81084
|
/** Ceremony-scoped link (plan 06 §1.5): the SAME URL is multi-visit and multi-owner —
|
|
@@ -81064,7 +81115,7 @@ var SignatureBridge = class {
|
|
|
81064
81115
|
unlockUrl() {
|
|
81065
81116
|
if (!this.started) throw new Error("bridge is not started");
|
|
81066
81117
|
if (!this.keystoreUnlock) throw new Error("keystore unlock is not wired on this bridge");
|
|
81067
|
-
this.unlockToken = (0,
|
|
81118
|
+
this.unlockToken = (0, import_node_crypto7.randomBytes)(24).toString("hex");
|
|
81068
81119
|
return this.mount ? `${this.mount.baseUrl}/unlock?t=${this.unlockToken}` : `http://127.0.0.1:${this.port}/unlock?t=${this.unlockToken}`;
|
|
81069
81120
|
}
|
|
81070
81121
|
/** Idempotent — the bridge spawns on the first write that needs it (plan 04 §2).
|
|
@@ -81105,7 +81156,7 @@ var SignatureBridge = class {
|
|
|
81105
81156
|
if (this.mount) {
|
|
81106
81157
|
const now = this.clock();
|
|
81107
81158
|
if (this.tokenMintedAt === 0 || now - this.tokenMintedAt > HOSTED_PAGE_TOKEN_TTL_MS) {
|
|
81108
|
-
this.token = (0,
|
|
81159
|
+
this.token = (0, import_node_crypto7.randomBytes)(24).toString("hex");
|
|
81109
81160
|
this.tokenMintedAt = now;
|
|
81110
81161
|
}
|
|
81111
81162
|
return `${this.mount.baseUrl}/?t=${this.token}`;
|
|
@@ -81321,7 +81372,7 @@ var SignatureBridge = class {
|
|
|
81321
81372
|
this.server = null;
|
|
81322
81373
|
this.started = false;
|
|
81323
81374
|
this.wallet = null;
|
|
81324
|
-
this.token = (0,
|
|
81375
|
+
this.token = (0, import_node_crypto7.randomBytes)(24).toString("hex");
|
|
81325
81376
|
this.tokenMintedAt = 0;
|
|
81326
81377
|
if (this.urlFile) fs4.rmSync(this.urlFile, { force: true });
|
|
81327
81378
|
void this.wcTransport?.close().catch(() => void 0);
|
|
@@ -81391,10 +81442,11 @@ var SignatureBridge = class {
|
|
|
81391
81442
|
this.deny(res, 429, `too many open approval pages (${MAX_SESSIONS}) \u2014 close one and retry`);
|
|
81392
81443
|
return;
|
|
81393
81444
|
}
|
|
81394
|
-
const sessionId = (0,
|
|
81445
|
+
const sessionId = (0, import_node_crypto7.randomBytes)(24).toString("hex");
|
|
81395
81446
|
this.sessions.set(sessionId, { wallet: null, sse: null });
|
|
81396
|
-
|
|
81397
|
-
res.
|
|
81447
|
+
const page = htmlPageSecurityHeaders();
|
|
81448
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", ...page.headers });
|
|
81449
|
+
res.end(renderApprovalPage(sessionId, page.nonce));
|
|
81398
81450
|
}
|
|
81399
81451
|
/** Target-network hints for the page's chain self-heal (session-gated). */
|
|
81400
81452
|
serveConfig(url2, res) {
|
|
@@ -81454,9 +81506,10 @@ var SignatureBridge = class {
|
|
|
81454
81506
|
return;
|
|
81455
81507
|
}
|
|
81456
81508
|
this.unlockToken = null;
|
|
81457
|
-
this.unlockSession = (0,
|
|
81458
|
-
|
|
81459
|
-
res.
|
|
81509
|
+
this.unlockSession = (0, import_node_crypto7.randomBytes)(24).toString("hex");
|
|
81510
|
+
const page = htmlPageSecurityHeaders();
|
|
81511
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store", ...page.headers });
|
|
81512
|
+
res.end(renderUnlockPage(this.unlockSession, page.nonce));
|
|
81460
81513
|
}
|
|
81461
81514
|
async onUnlockSubmit(body, res) {
|
|
81462
81515
|
if (!this.keystoreUnlock) {
|
|
@@ -81702,7 +81755,7 @@ function createBoundary(config, opts) {
|
|
|
81702
81755
|
"createBoundary(real) is async \u2014 use createRealBoundary() so the write SDK can be built."
|
|
81703
81756
|
);
|
|
81704
81757
|
}
|
|
81705
|
-
const configFingerprint = (0,
|
|
81758
|
+
const configFingerprint = (0, import_node_crypto8.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, latency: config.latency, db: config.mockDb, signer: config.signer ?? "auto" })).digest("hex").slice(0, 12);
|
|
81706
81759
|
if (opts?.ceremony) {
|
|
81707
81760
|
const plugin2 = new MockUpstreamPlugin(config, { ceremony: opts.ceremony });
|
|
81708
81761
|
const boundary2 = new BoundaryCore({
|
|
@@ -81871,7 +81924,7 @@ async function createRealBoundary(config, wallet, overrides) {
|
|
|
81871
81924
|
}
|
|
81872
81925
|
const plugin = new RealUpstreamPlugin(config, wallet, { manager, bridge, keystore });
|
|
81873
81926
|
await plugin.initWriteSdk();
|
|
81874
|
-
const configFingerprint = (0,
|
|
81927
|
+
const configFingerprint = (0, import_node_crypto8.createHash)("sha256").update(JSON.stringify({ adapter: config.adapter, network: config.network, ops: config.serviceEndpoint })).digest("hex").slice(0, 12);
|
|
81875
81928
|
const capabilities = () => ({
|
|
81876
81929
|
reads: {
|
|
81877
81930
|
public: true,
|
|
@@ -81971,469 +82024,6 @@ async function buildBoundary(configResult, overrides) {
|
|
|
81971
82024
|
return { boundaryResult: { ok: true, boundary }, signer, dispose };
|
|
81972
82025
|
}
|
|
81973
82026
|
|
|
81974
|
-
// src/network-switch.ts
|
|
81975
|
-
var SWITCHABLE_NETWORKS = ["sepolia", "mainnet"];
|
|
81976
|
-
function createNetworkSwitchRuntime(opts) {
|
|
81977
|
-
return {
|
|
81978
|
-
current() {
|
|
81979
|
-
const b = opts.getBoot().boundaryResult;
|
|
81980
|
-
if (!b.ok) return null;
|
|
81981
|
-
const w = b.boundary.world();
|
|
81982
|
-
return { network: w.network, chainId: w.chainId, practiceWorld: w.practiceWorld };
|
|
81983
|
-
},
|
|
81984
|
-
async switchTo(network) {
|
|
81985
|
-
const allowed = opts.overrides?.allowedNetworks;
|
|
81986
|
-
if (allowed && !allowed.includes(network)) {
|
|
81987
|
-
return {
|
|
81988
|
-
ok: false,
|
|
81989
|
-
error: boundaryError(
|
|
81990
|
-
"VALIDATION_FAILED",
|
|
81991
|
-
`this deployment serves ${allowed.join(", ")} \u2014 '${network}' is not enabled on this service. Mainnet service enablement is a rollout step of the deployment, not a session setting.`
|
|
81992
|
-
)
|
|
81993
|
-
};
|
|
81994
|
-
}
|
|
81995
|
-
const targetEnv = { ...opts.env, DH_NETWORK: network };
|
|
81996
|
-
const configResult = resolveBoundaryConfig(targetEnv);
|
|
81997
|
-
if (!configResult.ok) return { ok: false, error: configResult.error };
|
|
81998
|
-
const next = await buildBoundary(configResult, opts.overrides);
|
|
81999
|
-
if (!next.boundaryResult.ok) {
|
|
82000
|
-
next.dispose();
|
|
82001
|
-
return { ok: false, error: next.boundaryResult.error };
|
|
82002
|
-
}
|
|
82003
|
-
opts.swap(next);
|
|
82004
|
-
return { ok: true };
|
|
82005
|
-
}
|
|
82006
|
-
};
|
|
82007
|
-
}
|
|
82008
|
-
function assembleWorld(opts) {
|
|
82009
|
-
let boot = opts.boot;
|
|
82010
|
-
const deps = {
|
|
82011
|
-
boundaryResult: boot.boundaryResult,
|
|
82012
|
-
...boot.mockControl ? { mockControl: boot.mockControl } : {},
|
|
82013
|
-
...boot.signer ? { signer: boot.signer } : {},
|
|
82014
|
-
...opts.overrides?.externalOnly ? { externalOnly: true } : {},
|
|
82015
|
-
...opts.configResult.ok && opts.configResult.config.adapter === "mock" && opts.configResult.config.chainId ? { chainId: opts.configResult.config.chainId } : {}
|
|
82016
|
-
};
|
|
82017
|
-
if ((opts.env["DH_ADAPTER"] ?? "real") !== "mock") {
|
|
82018
|
-
deps.networkSwitch = createNetworkSwitchRuntime({
|
|
82019
|
-
env: opts.env,
|
|
82020
|
-
getBoot: () => boot,
|
|
82021
|
-
...opts.overrides ? { overrides: opts.overrides } : {},
|
|
82022
|
-
swap: (next) => {
|
|
82023
|
-
const old = boot;
|
|
82024
|
-
boot = next;
|
|
82025
|
-
deps.boundaryResult = next.boundaryResult;
|
|
82026
|
-
if (next.signer) deps.signer = next.signer;
|
|
82027
|
-
else delete deps.signer;
|
|
82028
|
-
old.dispose();
|
|
82029
|
-
const w = next.boundaryResult.ok ? next.boundaryResult.boundary.world() : null;
|
|
82030
|
-
opts.log?.(`network switched \u2014 now ${w ? `${w.network} (chainId ${w.chainId})` : "unavailable"}.`);
|
|
82031
|
-
}
|
|
82032
|
-
});
|
|
82033
|
-
}
|
|
82034
|
-
return { deps, dispose: () => boot.dispose() };
|
|
82035
|
-
}
|
|
82036
|
-
|
|
82037
|
-
// src/server.ts
|
|
82038
|
-
var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
82039
|
-
|
|
82040
|
-
// src/tools/loan.ts
|
|
82041
|
-
var import_zod = require("zod");
|
|
82042
|
-
var import_ethers40 = require("ethers");
|
|
82043
|
-
|
|
82044
|
-
// src/util/format.ts
|
|
82045
|
-
function bigintReplacer(_key, value) {
|
|
82046
|
-
if (typeof value === "bigint") return value.toString();
|
|
82047
|
-
return value;
|
|
82048
|
-
}
|
|
82049
|
-
function serialize(data) {
|
|
82050
|
-
return JSON.stringify(data, bigintReplacer, 2);
|
|
82051
|
-
}
|
|
82052
|
-
|
|
82053
|
-
// src/tools/_helpers.ts
|
|
82054
|
-
function registerBoundaryTool(server, name, config, handler) {
|
|
82055
|
-
server.registerTool(name, config, handler);
|
|
82056
|
-
}
|
|
82057
|
-
function renderError(error) {
|
|
82058
|
-
const lines = [`ERROR [${error.code}]: ${error.message}`];
|
|
82059
|
-
if (error.source) lines.push(`source: ${error.source}`);
|
|
82060
|
-
return { content: [{ type: "text", text: lines.join("\n") }], isError: true };
|
|
82061
|
-
}
|
|
82062
|
-
function renderEnvelope(env) {
|
|
82063
|
-
if (!env.ok) return renderError(env.error);
|
|
82064
|
-
const parts = [serialize(env.data)];
|
|
82065
|
-
if (env.warnings.length > 0) {
|
|
82066
|
-
parts.push(
|
|
82067
|
-
"WARNINGS:\n" + env.warnings.map((w) => `- [${w.code}] ${w.message} (sources: ${w.sources.join(", ")})`).join("\n")
|
|
82068
|
-
);
|
|
82069
|
-
}
|
|
82070
|
-
parts.push(`source: ${env.source.id} (${env.source.kind}) @ ${env.source.fetchedAt}`);
|
|
82071
|
-
return { content: [{ type: "text", text: parts.join("\n\n") }] };
|
|
82072
|
-
}
|
|
82073
|
-
function validationFailed(problem) {
|
|
82074
|
-
return renderError(boundaryError("VALIDATION_FAILED", problem));
|
|
82075
|
-
}
|
|
82076
|
-
function resourceJson(env) {
|
|
82077
|
-
if (!env.ok) return serialize({ error: env.error });
|
|
82078
|
-
return serialize({ data: env.data, warnings: env.warnings, source: env.source });
|
|
82079
|
-
}
|
|
82080
|
-
function resourceErrorJson(error) {
|
|
82081
|
-
return serialize({ error });
|
|
82082
|
-
}
|
|
82083
|
-
function requireConfirmation(confirmed, actionLabel) {
|
|
82084
|
-
if (confirmed === true) return null;
|
|
82085
|
-
return {
|
|
82086
|
-
content: [
|
|
82087
|
-
{
|
|
82088
|
-
type: "text",
|
|
82089
|
-
text: `CONFIRMATION REQUIRED \u2014 refusing to run "${actionLabel}".
|
|
82090
|
-
This is an irreversible, fund-moving action. A human must explicitly authorize it.
|
|
82091
|
-
Re-invoke with confirmed: true ONLY after a human has approved this exact operation. Do not set confirmed on your own.`
|
|
82092
|
-
}
|
|
82093
|
-
],
|
|
82094
|
-
isError: true
|
|
82095
|
-
};
|
|
82096
|
-
}
|
|
82097
|
-
function envStamp(b) {
|
|
82098
|
-
if (!b.ok) return "environment: UNKNOWN \u2014 boundary unavailable";
|
|
82099
|
-
const w = b.boundary.world();
|
|
82100
|
-
const money = w.network === "mainnet" ? "REAL MONEY" : w.network === "mock" ? "PRACTICE SANDBOX (no real money)" : "PRACTICE FUNDS (test network)";
|
|
82101
|
-
return `environment: ${w.network} \u2014 ${money}`;
|
|
82102
|
-
}
|
|
82103
|
-
async function guardedWrite(getB, fn) {
|
|
82104
|
-
const result = await guarded(fn);
|
|
82105
|
-
const stamp = envStamp(getB());
|
|
82106
|
-
const content = result.content.map(
|
|
82107
|
-
(c, i) => i === result.content.length - 1 ? { ...c, text: `${c.text}
|
|
82108
|
-
|
|
82109
|
-
${stamp}` } : c
|
|
82110
|
-
);
|
|
82111
|
-
return { ...result, content };
|
|
82112
|
-
}
|
|
82113
|
-
async function guarded(fn) {
|
|
82114
|
-
try {
|
|
82115
|
-
return await fn();
|
|
82116
|
-
} catch (e) {
|
|
82117
|
-
return renderError(
|
|
82118
|
-
boundaryError("INTERNAL", `Internal boundary fault: ${e.message}`, {
|
|
82119
|
-
details: { stack: e.stack }
|
|
82120
|
-
})
|
|
82121
|
-
);
|
|
82122
|
-
}
|
|
82123
|
-
}
|
|
82124
|
-
|
|
82125
|
-
// src/util/validate.ts
|
|
82126
|
-
var POSITION_ID_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
82127
|
-
var SATS_SANITY_CAP = 1e10;
|
|
82128
|
-
var UCD_SANITY_CAP = 1e9;
|
|
82129
|
-
function checkPositionIdHex(id, label = "Position ID") {
|
|
82130
|
-
if (!POSITION_ID_RE.test(id)) {
|
|
82131
|
-
return `${label} must be 0x-prefixed 32-byte hex (got '${id}').`;
|
|
82132
|
-
}
|
|
82133
|
-
return null;
|
|
82134
|
-
}
|
|
82135
|
-
function checkUcdAmount(amount, label = "Amount") {
|
|
82136
|
-
if (!Number.isFinite(amount) || amount <= 0) {
|
|
82137
|
-
return `${label} must be a positive finite number (got ${amount}).`;
|
|
82138
|
-
}
|
|
82139
|
-
if (amount > UCD_SANITY_CAP) {
|
|
82140
|
-
return `${label} ${amount} exceeds the ${UCD_SANITY_CAP.toLocaleString()} UCD sanity cap.`;
|
|
82141
|
-
}
|
|
82142
|
-
if (amount > 0 && amount < 1e-6) {
|
|
82143
|
-
return `${label} ${amount} has more than 6 decimals of precision \u2014 likely a typo.`;
|
|
82144
|
-
}
|
|
82145
|
-
const decimals = amount.toString().split(".")[1];
|
|
82146
|
-
if (decimals && decimals.length > 6) {
|
|
82147
|
-
return `${label} ${amount} has more than 6 decimals of precision \u2014 likely a typo.`;
|
|
82148
|
-
}
|
|
82149
|
-
return null;
|
|
82150
|
-
}
|
|
82151
|
-
function checkSatsAmount(sats, label = "Amount") {
|
|
82152
|
-
if (!Number.isInteger(sats) || sats <= 0) {
|
|
82153
|
-
return `${label} must be a positive integer (satoshis), got ${sats}.`;
|
|
82154
|
-
}
|
|
82155
|
-
if (sats > SATS_SANITY_CAP) {
|
|
82156
|
-
return `${label} ${sats} sats exceeds the 100 BTC sanity cap.`;
|
|
82157
|
-
}
|
|
82158
|
-
return null;
|
|
82159
|
-
}
|
|
82160
|
-
function checkSelectedTerm(months, label = "Term") {
|
|
82161
|
-
if (!Number.isInteger(months) || months <= 0) {
|
|
82162
|
-
return `${label} must be a positive integer (months), got ${months}.`;
|
|
82163
|
-
}
|
|
82164
|
-
if (months > 120) {
|
|
82165
|
-
return `${label} ${months} months exceeds the 10-year sanity cap.`;
|
|
82166
|
-
}
|
|
82167
|
-
return null;
|
|
82168
|
-
}
|
|
82169
|
-
|
|
82170
|
-
// src/tools/loan.ts
|
|
82171
|
-
var LATENCY_NOTES = {
|
|
82172
|
-
mock: "Instant in this practice world.",
|
|
82173
|
-
real: "May take 60\u201390 seconds against the live protocol (LIT Action invocation)."
|
|
82174
|
-
};
|
|
82175
|
-
var positionIdSchema = import_zod.z.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be 0x-prefixed 32-byte hex");
|
|
82176
|
-
var confirmedSchema = import_zod.z.boolean().optional().describe(
|
|
82177
|
-
"Human authorization gate \u2014 must be set to true by a HUMAN (not the model) to execute this irreversible action."
|
|
82178
|
-
);
|
|
82179
|
-
var DESTRUCTIVE_WRITE_ANNOTATIONS = {
|
|
82180
|
-
readOnlyHint: false,
|
|
82181
|
-
destructiveHint: true,
|
|
82182
|
-
idempotentHint: false,
|
|
82183
|
-
openWorldHint: true
|
|
82184
|
-
};
|
|
82185
|
-
function registerLoanTools(server, getB, adapter2 = "real") {
|
|
82186
|
-
const LATENCY_NOTE = LATENCY_NOTES[adapter2];
|
|
82187
|
-
registerBoundaryTool(
|
|
82188
|
-
server,
|
|
82189
|
-
"loan_create",
|
|
82190
|
-
{
|
|
82191
|
-
title: "Create a new lending position",
|
|
82192
|
-
description: `Mint a new PKP, create a Bitcoin custody vault, and register a new lending position with the given term. ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
82193
|
-
inputSchema: {
|
|
82194
|
-
selectedTerm: import_zod.z.number().int().positive().describe("Loan term in months (e.g. 3, 6, 12, 24)"),
|
|
82195
|
-
confirmed: confirmedSchema
|
|
82196
|
-
},
|
|
82197
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82198
|
-
},
|
|
82199
|
-
async ({ selectedTerm, confirmed }) => guardedWrite(getB, async () => {
|
|
82200
|
-
const gate = requireConfirmation(confirmed, `create a ${selectedTerm}-month lending position`);
|
|
82201
|
-
if (gate) return gate;
|
|
82202
|
-
const problem = checkSelectedTerm(selectedTerm);
|
|
82203
|
-
if (problem) return validationFailed(problem);
|
|
82204
|
-
const b = getB();
|
|
82205
|
-
if (!b.ok) return renderError(b.error);
|
|
82206
|
-
return renderEnvelope(await b.boundary.createPosition({ selectedTerm }));
|
|
82207
|
-
})
|
|
82208
|
-
);
|
|
82209
|
-
registerBoundaryTool(
|
|
82210
|
-
server,
|
|
82211
|
-
"loan_mint",
|
|
82212
|
-
{
|
|
82213
|
-
title: "Mint UCD against a position",
|
|
82214
|
-
description: `Mint (borrow) UCD against an existing lending position's BTC collateral. The origination fee is ADDED TO YOUR DEBT \u2014 you receive the full amount, you owe amount + fee. Ceiling: position_status \u2192 valuation.maxMintableUcd (directly usable as amountUcd). ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
82215
|
-
inputSchema: {
|
|
82216
|
-
positionId: positionIdSchema,
|
|
82217
|
-
amountUcd: import_zod.z.number().positive().describe("Amount of UCD to mint"),
|
|
82218
|
-
confirmed: confirmedSchema
|
|
82219
|
-
},
|
|
82220
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82221
|
-
},
|
|
82222
|
-
async ({ positionId, amountUcd, confirmed }) => guardedWrite(getB, async () => {
|
|
82223
|
-
const gate = requireConfirmation(confirmed, `mint ${amountUcd} UCD against position ${positionId}`);
|
|
82224
|
-
if (gate) return gate;
|
|
82225
|
-
const problem = checkPositionIdHex(positionId) ?? checkUcdAmount(amountUcd);
|
|
82226
|
-
if (problem) return validationFailed(problem);
|
|
82227
|
-
const b = getB();
|
|
82228
|
-
if (!b.ok) return renderError(b.error);
|
|
82229
|
-
return renderEnvelope(
|
|
82230
|
-
await b.boundary.mintUcd({ positionId, amountUcdWei: (0, import_ethers40.parseEther)(amountUcd.toString()).toString() })
|
|
82231
|
-
);
|
|
82232
|
-
})
|
|
82233
|
-
);
|
|
82234
|
-
registerBoundaryTool(
|
|
82235
|
-
server,
|
|
82236
|
-
"loan_pay",
|
|
82237
|
-
{
|
|
82238
|
-
title: "Make a UCD payment toward a position's debt",
|
|
82239
|
-
description: `Repay (partial or full) a position's UCD debt. Moves UCD out of your wallet (irreversible). To pay off EVERYTHING exactly \u2014 including dust smaller than the 6-decimal input allows \u2014 pass repayAll: true instead of amountUcd (fleet finding: debt can carry more precision than amountUcd accepts). ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
82240
|
-
inputSchema: {
|
|
82241
|
-
positionId: positionIdSchema,
|
|
82242
|
-
amountUcd: import_zod.z.number().positive().optional().describe("Amount of UCD to repay (max 6 decimals; omit when repayAll)"),
|
|
82243
|
-
repayAll: import_zod.z.boolean().optional().describe("true = repay the position's EXACT outstanding debt (wei-precise)"),
|
|
82244
|
-
confirmed: confirmedSchema
|
|
82245
|
-
},
|
|
82246
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82247
|
-
},
|
|
82248
|
-
async ({ positionId, amountUcd, repayAll, confirmed }) => guardedWrite(getB, async () => {
|
|
82249
|
-
if (repayAll === true === (amountUcd !== void 0)) {
|
|
82250
|
-
return validationFailed("provide exactly one of amountUcd or repayAll: true");
|
|
82251
|
-
}
|
|
82252
|
-
const gate = requireConfirmation(
|
|
82253
|
-
confirmed,
|
|
82254
|
-
repayAll ? `repay the ENTIRE outstanding debt of position ${positionId}` : `repay ${amountUcd} UCD toward position ${positionId}`
|
|
82255
|
-
);
|
|
82256
|
-
if (gate) return gate;
|
|
82257
|
-
const problem = checkPositionIdHex(positionId) ?? (repayAll ? null : checkUcdAmount(amountUcd, "Payment amount"));
|
|
82258
|
-
if (problem) return validationFailed(problem);
|
|
82259
|
-
const b = getB();
|
|
82260
|
-
if (!b.ok) return renderError(b.error);
|
|
82261
|
-
let amountUcdWei;
|
|
82262
|
-
if (repayAll) {
|
|
82263
|
-
const detail = await b.boundary.getPosition(positionId);
|
|
82264
|
-
if (!detail.ok) return renderError(detail.error);
|
|
82265
|
-
if (BigInt(detail.data.debtUcdWei) === 0n) return validationFailed("the position has no outstanding debt");
|
|
82266
|
-
amountUcdWei = detail.data.debtUcdWei;
|
|
82267
|
-
} else {
|
|
82268
|
-
amountUcdWei = (0, import_ethers40.parseEther)(amountUcd.toString()).toString();
|
|
82269
|
-
}
|
|
82270
|
-
return renderEnvelope(await b.boundary.repayUcd({ positionId, amountUcdWei }));
|
|
82271
|
-
})
|
|
82272
|
-
);
|
|
82273
|
-
registerBoundaryTool(
|
|
82274
|
-
server,
|
|
82275
|
-
"loan_extend",
|
|
82276
|
-
{
|
|
82277
|
-
title: "Extend / renew a position's term",
|
|
82278
|
-
description: `ADDS selectedTerm onto the position's CURRENT expiry (12 months = exactly 365 days; any other term = N \xD7 30-day months) \u2014 never replaces or shortens it. Only available in the FINAL 30 DAYS of the current term, and refused if the remaining runway would exceed 2\xD7 the new term. (Per-network caveat: some DEPLOYED contracts predate this window/runway rule \u2014 a live extend may execute from now rather than refuse; the MCP reports the on-chain result truthfully.) Fee: ADDED TO YOUR DEBT (your wallet is not charged), at most the term's extension fee rate \xD7 your current debt (see protocol_terms; a flat rate per renewal, not per month), reduced by origination fees already paid this term. Only an ACTIVE position can be renewed. Irreversible on-chain write. ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
82279
|
-
inputSchema: {
|
|
82280
|
-
positionId: positionIdSchema,
|
|
82281
|
-
selectedTerm: import_zod.z.number().int().positive().describe("Months to ADD to the current expiry (must be an offered term: see protocol_terms)"),
|
|
82282
|
-
confirmed: confirmedSchema
|
|
82283
|
-
},
|
|
82284
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82285
|
-
},
|
|
82286
|
-
async ({ positionId, selectedTerm, confirmed }) => guardedWrite(getB, async () => {
|
|
82287
|
-
const gate = requireConfirmation(confirmed, `renew position ${positionId} for a ${selectedTerm}-month term`);
|
|
82288
|
-
if (gate) return gate;
|
|
82289
|
-
const problem = checkPositionIdHex(positionId) ?? checkSelectedTerm(selectedTerm);
|
|
82290
|
-
if (problem) return validationFailed(problem);
|
|
82291
|
-
const b = getB();
|
|
82292
|
-
if (!b.ok) return renderError(b.error);
|
|
82293
|
-
return renderEnvelope(await b.boundary.extendPosition({ positionId, selectedTerm }));
|
|
82294
|
-
})
|
|
82295
|
-
);
|
|
82296
|
-
registerBoundaryTool(
|
|
82297
|
-
server,
|
|
82298
|
-
"loan_withdraw",
|
|
82299
|
-
{
|
|
82300
|
-
title: "Withdraw BTC from a position vault",
|
|
82301
|
-
description: `Withdraw BTC from a position's custody vault to an external BTC address. BTC sends are UNRECOVERABLE \u2014 verify the destination address carefully. Result identifiers: txid (and txRef.id) is the Bitcoin transaction of the withdrawal reservation; authorization.digest is the borrower wallet's signature over the approval \u2014 they are different things. ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
82302
|
-
inputSchema: {
|
|
82303
|
-
positionId: positionIdSchema,
|
|
82304
|
-
btcAddress: import_zod.z.string().min(1).describe("Destination BTC address (must match the configured BTC network)"),
|
|
82305
|
-
amountSats: import_zod.z.number().int().positive().describe(
|
|
82306
|
-
"GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. amountSats may be up to the whole available balance (a full sweep leaves 0 sats; anything above available reverts TargetExceedsInputValue). position_status.maxWithdrawableSats is a ready-to-use value that already leaves the default fee aside."
|
|
82307
|
-
),
|
|
82308
|
-
networkFeeSats: import_zod.z.number().int().positive().default(1e3).describe("BTC network fee in sats (declared default 1000); deducted FROM amountSats, not added on top"),
|
|
82309
|
-
confirmed: confirmedSchema
|
|
82310
|
-
},
|
|
82311
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82312
|
-
},
|
|
82313
|
-
async ({ positionId, btcAddress: btcAddress2, amountSats, networkFeeSats, confirmed }) => guardedWrite(getB, async () => {
|
|
82314
|
-
const gate = requireConfirmation(
|
|
82315
|
-
confirmed,
|
|
82316
|
-
`withdraw ${amountSats} sats from position ${positionId} to ${btcAddress2} (UNRECOVERABLE)`
|
|
82317
|
-
);
|
|
82318
|
-
if (gate) return gate;
|
|
82319
|
-
const problem = checkPositionIdHex(positionId) ?? checkSatsAmount(amountSats) ?? checkSatsAmount(networkFeeSats, "Network fee");
|
|
82320
|
-
if (problem) return validationFailed(problem);
|
|
82321
|
-
const b = getB();
|
|
82322
|
-
if (!b.ok) return renderError(b.error);
|
|
82323
|
-
return renderEnvelope(await b.boundary.withdrawBtc({ positionId, btcAddress: btcAddress2, amountSats, networkFeeSats }));
|
|
82324
|
-
})
|
|
82325
|
-
);
|
|
82326
|
-
registerBoundaryTool(
|
|
82327
|
-
server,
|
|
82328
|
-
"loan_allowlist_destination",
|
|
82329
|
-
{
|
|
82330
|
-
title: "Allowlist a BTC withdrawal destination",
|
|
82331
|
-
description: `Add a BTC address to the borrower's withdrawal allowlist (BitcoinWithdrawalAddressRegistry). The protocol refuses withdrawBTC to any destination not on the borrower's own allowlist. For a SAFE borrower this is itself a Safe transaction \u2014 owner signatures are collected, and owners can sign at their leisure (no expiry on this ceremony). The destination becomes usable after the registry's address delay, read LIVE from the contract at execution \u2014 the result's usableAtSec is the chain-derived moment it becomes usable (never assume a fixed delay). Requires human confirmation (confirmed: true).`,
|
|
82332
|
-
inputSchema: {
|
|
82333
|
-
btcAddress: import_zod.z.string().min(1).describe("Destination BTC address to allowlist (must match the configured BTC network)"),
|
|
82334
|
-
confirmed: confirmedSchema
|
|
82335
|
-
},
|
|
82336
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82337
|
-
},
|
|
82338
|
-
async ({ btcAddress: btcAddress2, confirmed }) => guardedWrite(getB, async () => {
|
|
82339
|
-
const gate = requireConfirmation(confirmed, `allowlist ${btcAddress2} as a BTC withdrawal destination`);
|
|
82340
|
-
if (gate) return gate;
|
|
82341
|
-
const b = getB();
|
|
82342
|
-
if (!b.ok) return renderError(b.error);
|
|
82343
|
-
return renderEnvelope(await b.boundary.allowlistWithdrawalAddress({ btcAddress: btcAddress2 }));
|
|
82344
|
-
})
|
|
82345
|
-
);
|
|
82346
|
-
registerBoundaryTool(
|
|
82347
|
-
server,
|
|
82348
|
-
"loan_delegation_setup",
|
|
82349
|
-
{
|
|
82350
|
-
title: "Install delegation on the Safe (one owner ceremony)",
|
|
82351
|
-
description: `The ONE-TIME Safe delegation batch (signer mode 'safe-module'): your owners sign a single durable Safe transaction \u2014 at their leisure, no time window \u2014 that enables the Safe's AgentModule, binds the agent key, registers it in the delegation registry, and pre-approves the given BTC withdrawal destinations. After it, day-to-day operations (create/mint/pay/extend) run agent-solo; withdrawals always still need the owners' short signing burst, and only to destinations approved here (or later via loan_allowlist_destination \u2014 also owners-only). A revoked agent address burns FOREVER (AR-1) \u2014 rotation means a fresh key. Requires human confirmation (confirmed: true).`,
|
|
82352
|
-
inputSchema: {
|
|
82353
|
-
btcAddresses: import_zod.z.array(import_zod.z.string().min(1)).describe("BTC withdrawal destinations to pre-approve in the same ceremony (avoids a second owner gathering before the first withdrawal)"),
|
|
82354
|
-
confirmed: confirmedSchema
|
|
82355
|
-
},
|
|
82356
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82357
|
-
},
|
|
82358
|
-
async ({ btcAddresses, confirmed }) => guardedWrite(getB, async () => {
|
|
82359
|
-
const gate = requireConfirmation(confirmed, `install delegation (module + agent + ${btcAddresses.length} destination(s))`);
|
|
82360
|
-
if (gate) return gate;
|
|
82361
|
-
const b = getB();
|
|
82362
|
-
if (!b.ok) return renderError(b.error);
|
|
82363
|
-
return renderEnvelope(await b.boundary.delegationSetup({ btcAddresses }));
|
|
82364
|
-
})
|
|
82365
|
-
);
|
|
82366
|
-
registerBoundaryTool(
|
|
82367
|
-
server,
|
|
82368
|
-
"loan_delegation_grant",
|
|
82369
|
-
{
|
|
82370
|
-
title: "Grant the agent per-position scopes (owners sign)",
|
|
82371
|
-
description: `Set what the delegated agent may do on ONE position \u2014 RENEW (extend), REPAY (pay down), MINT (borrow, only while the post-mint collateral ratio stays at or above mintFloorBps \u2014 required for MINT, it is the owners' risk bound). Grants are user-only expansion: for a Safe this is a QUORUM signature (durable Safe transaction, owners sign at leisure) \u2014 the agent can never widen its own powers. Omitting a scope leaves it un-granted; a grant with no scopes clears the position's grant. Requires human confirmation (confirmed: true).`,
|
|
82372
|
-
inputSchema: {
|
|
82373
|
-
positionId: positionIdSchema,
|
|
82374
|
-
renew: import_zod.z.boolean().optional().describe("Allow the agent to extend/renew this position"),
|
|
82375
|
-
repay: import_zod.z.boolean().optional().describe("Allow the agent to pay down this position's debt"),
|
|
82376
|
-
mintFloorBps: import_zod.z.number().int().positive().optional().describe("Allow MINT while post-mint CR \u2265 this floor (bps, e.g. 15000 = 150%) \u2014 required for the MINT scope"),
|
|
82377
|
-
confirmed: confirmedSchema
|
|
82378
|
-
},
|
|
82379
|
-
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
82380
|
-
},
|
|
82381
|
-
async ({ positionId, renew, repay, mintFloorBps, confirmed }) => guardedWrite(getB, async () => {
|
|
82382
|
-
const gate = requireConfirmation(confirmed, `grant agent scopes on ${positionId}`);
|
|
82383
|
-
if (gate) return gate;
|
|
82384
|
-
const b = getB();
|
|
82385
|
-
if (!b.ok) return renderError(b.error);
|
|
82386
|
-
return renderEnvelope(
|
|
82387
|
-
await b.boundary.delegationGrant({
|
|
82388
|
-
positionId,
|
|
82389
|
-
renew: renew ?? false,
|
|
82390
|
-
repay: repay ?? false,
|
|
82391
|
-
mintFloorBps: mintFloorBps ?? null
|
|
82392
|
-
})
|
|
82393
|
-
);
|
|
82394
|
-
})
|
|
82395
|
-
);
|
|
82396
|
-
registerBoundaryTool(
|
|
82397
|
-
server,
|
|
82398
|
-
"loan_recover_stale_spend",
|
|
82399
|
-
{
|
|
82400
|
-
title: "Recover a stale BTC reservation via LIT-attested proof",
|
|
82401
|
-
description: "Clear a stale authorized BTC spend on BTCSpendAuthorizer using a LIT-attested StaleSpendRecovery attestation. The original UTXO must already be consumed on Bitcoin with \u22656 confirmations. `invalidatorTxid` is either the borrower's authorized broadcast (after confirmations) or a PKP self-spend that invalidated the reservation. Permissionless on-chain.",
|
|
82402
|
-
inputSchema: {
|
|
82403
|
-
positionId: positionIdSchema,
|
|
82404
|
-
utxoTxid: import_zod.z.string().describe("The original authorized UTXO's txid"),
|
|
82405
|
-
utxoVout: import_zod.z.number().int().nonnegative().describe("The original authorized UTXO's vout"),
|
|
82406
|
-
invalidatorTxid: import_zod.z.string().describe("Txid of the BTC transaction that consumed the original UTXO (\u22656 confirmations)"),
|
|
82407
|
-
minConfirmations: import_zod.z.number().int().positive().optional().describe("Override minimum confirmations (default 6)")
|
|
82408
|
-
},
|
|
82409
|
-
annotations: {
|
|
82410
|
-
readOnlyHint: false,
|
|
82411
|
-
destructiveHint: false,
|
|
82412
|
-
idempotentHint: true,
|
|
82413
|
-
openWorldHint: true
|
|
82414
|
-
}
|
|
82415
|
-
},
|
|
82416
|
-
async ({ positionId, utxoTxid, utxoVout, invalidatorTxid, minConfirmations }) => guardedWrite(getB, async () => {
|
|
82417
|
-
const problem = checkPositionIdHex(positionId);
|
|
82418
|
-
if (problem) return validationFailed(problem);
|
|
82419
|
-
const b = getB();
|
|
82420
|
-
if (!b.ok) return renderError(b.error);
|
|
82421
|
-
return renderEnvelope(
|
|
82422
|
-
await b.boundary.recoverStaleSpend({
|
|
82423
|
-
positionId,
|
|
82424
|
-
utxoTxid,
|
|
82425
|
-
utxoVout,
|
|
82426
|
-
invalidatorTxid,
|
|
82427
|
-
...minConfirmations !== void 0 ? { minConfirmations } : {}
|
|
82428
|
-
})
|
|
82429
|
-
);
|
|
82430
|
-
})
|
|
82431
|
-
);
|
|
82432
|
-
}
|
|
82433
|
-
|
|
82434
|
-
// src/tools/position.ts
|
|
82435
|
-
var import_zod2 = require("zod");
|
|
82436
|
-
|
|
82437
82027
|
// src/boundary/field-glossary.ts
|
|
82438
82028
|
var FIELD_GLOSSARY = {
|
|
82439
82029
|
// ---- identity / envelope structure ----
|
|
@@ -82559,7 +82149,1288 @@ response \u2014 follow them over any prior assumption.
|
|
|
82559
82149
|
${lines.join("\n")}`;
|
|
82560
82150
|
}
|
|
82561
82151
|
|
|
82152
|
+
// src/guide/content.ts
|
|
82153
|
+
var GUIDE_TOPICS = [
|
|
82154
|
+
"getting-started",
|
|
82155
|
+
"first-setup",
|
|
82156
|
+
"connect-wallet",
|
|
82157
|
+
"lifecycle",
|
|
82158
|
+
"fees",
|
|
82159
|
+
"psm",
|
|
82160
|
+
"authorization",
|
|
82161
|
+
"safe",
|
|
82162
|
+
"delegation",
|
|
82163
|
+
"safety",
|
|
82164
|
+
"switch-network",
|
|
82165
|
+
"connector",
|
|
82166
|
+
"troubleshooting",
|
|
82167
|
+
"glossary",
|
|
82168
|
+
"reading-data"
|
|
82169
|
+
];
|
|
82170
|
+
var GUIDE_SIGNER_MODES = ["external", "keystore", "safe", "safe-module", "mock-simulated"];
|
|
82171
|
+
var EXTERNAL_ONLY_SIGNER_MODES = ["external"];
|
|
82172
|
+
function offers(d, mode) {
|
|
82173
|
+
return d.signerModes.includes(mode);
|
|
82174
|
+
}
|
|
82175
|
+
function signerModeSourceClause(d) {
|
|
82176
|
+
return offers(d, "keystore") ? "the set `signer_setup` offers. `boundary://info` reports the NARROWER set the active adapter actually constructs under `capabilities.writes.signerModes` (the real adapter builds `external` + `keystore`; the practice ceremonies are mock-adapter only) \u2014 when the two differ, `boundary://info` is authoritative" : "the same set `signer_setup` offers and `boundary://info` reports under `capabilities.writes.signerModes`";
|
|
82177
|
+
}
|
|
82178
|
+
var LOCAL_GUIDE_DEPLOYMENT = {
|
|
82179
|
+
tier: "local",
|
|
82180
|
+
networks: ["sepolia", "mainnet"],
|
|
82181
|
+
// A local install constructs the whole signer runtime: the real adapter offers
|
|
82182
|
+
// external+keystore and the mock sandbox adds the practice ceremonies, so the guide may
|
|
82183
|
+
// speak the full vocabulary and let the existing adapter prose ("PRACTICE-ONLY today —
|
|
82184
|
+
// on the real adapter these modes refuse") carry the narrower adapter axis.
|
|
82185
|
+
signerModes: GUIDE_SIGNER_MODES
|
|
82186
|
+
};
|
|
82187
|
+
function servedNetworks(d) {
|
|
82188
|
+
if (d.networks.length === 0) throw new Error("guide: a deployment must serve at least one network");
|
|
82189
|
+
const mainnet = d.networks.includes("mainnet");
|
|
82190
|
+
const sepolia = d.networks.includes("sepolia");
|
|
82191
|
+
if (mainnet && sepolia) {
|
|
82192
|
+
return "sepolia (PRACTICE money) and mainnet (REAL MONEY) \u2014 `network_switch` moves between them, and every switch states which is live";
|
|
82193
|
+
}
|
|
82194
|
+
if (mainnet) {
|
|
82195
|
+
return "mainnet ONLY \u2014 every fund-moving operation this deployment enables spends REAL MONEY (reads move nothing, and PSM swaps are refused on mainnet), and there is no practice network on this deployment to fall back to";
|
|
82196
|
+
}
|
|
82197
|
+
return "sepolia only \u2014 the real contracts on the test network, so the ceremonies are real and the money is PRACTICE";
|
|
82198
|
+
}
|
|
82199
|
+
function connectorStatusTruth(d) {
|
|
82200
|
+
if (d.tier === "hosted") {
|
|
82201
|
+
return `**STATUS TRUTH (say this first when asked):** this session IS the hosted
|
|
82202
|
+
connector \u2014 the user is already on it, so there is nothing to install and no URL to hand
|
|
82203
|
+
out. It serves ${servedNetworks(d)}. State that money reality unprompted, and never
|
|
82204
|
+
promise a network, a tier or a timing this deployment does not already serve.`;
|
|
82205
|
+
}
|
|
82206
|
+
return `**STATUS TRUTH (say this first when asked):** this session is a LOCAL install,
|
|
82207
|
+
not the hosted connector. Whether a public connector URL is being served today is the
|
|
82208
|
+
operator's rollout decision and this build cannot see it \u2014 so never assert that one is
|
|
82209
|
+
available, and never assert that one is not. If the user already has a URL, everything
|
|
82210
|
+
below describes what they get; otherwise the local install paths (\`first-setup\`) are the
|
|
82211
|
+
way in. Never promise availability or timing.`;
|
|
82212
|
+
}
|
|
82213
|
+
function connectorNetworkTruth(d) {
|
|
82214
|
+
if (d.tier === "hosted") {
|
|
82215
|
+
return `And it serves only the networks its deployment is rolled out to \u2014 this one
|
|
82216
|
+
serves ${servedNetworks(d)}. Which networks a deployment is rolled out to is the
|
|
82217
|
+
operator's deploy decision, never a hidden knob \u2014 and it is not a field of
|
|
82218
|
+
\`boundary://info\`, whose capabilities block reports the world THIS session is on right
|
|
82219
|
+
now (network, chainId, practiceWorld) plus the read/write/signer planes. \`network_switch\`
|
|
82220
|
+
is what states the rollout: asked for a network this deployment is not rolled out to, it
|
|
82221
|
+
refuses and names the ones it is.`;
|
|
82222
|
+
}
|
|
82223
|
+
return `And any connector deployment serves only the networks it is rolled out to \u2014
|
|
82224
|
+
which ones is the operator's deploy decision, never a hidden knob. Do not go looking for
|
|
82225
|
+
that list in \`boundary://info\`: its capabilities block reports the world THIS session is
|
|
82226
|
+
on (network, chainId, practiceWorld) plus the read/write/signer planes, never another
|
|
82227
|
+
deployment's rollout. \`network_switch\` is what states it \u2014 asked for a network a
|
|
82228
|
+
deployment is not rolled out to, it refuses and names the ones it is. This local build
|
|
82229
|
+
cannot see another deployment's rollout at all: ask that server, never assume.`;
|
|
82230
|
+
}
|
|
82231
|
+
function connectorInstallNote(d) {
|
|
82232
|
+
if (d.tier === "hosted") {
|
|
82233
|
+
return `(The user is ALREADY on the fourth, zero-install path \u2014 the claude.ai
|
|
82234
|
+
connector \u2014 so none of the above is needed HERE; those paths are for other machines.
|
|
82235
|
+
Truth and trust model: \`guide connector\`.)`;
|
|
82236
|
+
}
|
|
82237
|
+
return `(A fourth, zero-install path \u2014 the claude.ai connector \u2014 is implemented in this
|
|
82238
|
+
build. Whether it is publicly served today is the operator's rollout decision and this
|
|
82239
|
+
session cannot see it: do not assert either way. Truth and trust model:
|
|
82240
|
+
\`guide connector\`.)`;
|
|
82241
|
+
}
|
|
82242
|
+
function connectorTroubleshootingRow(d) {
|
|
82243
|
+
if (d.tier === "hosted") {
|
|
82244
|
+
return `- **Asked for the claude.ai connector / remote / hosted tier** \u2014 that is THIS
|
|
82245
|
+
session. Nothing to install, no URL to look up; it serves ${servedNetworks(d)}. Full
|
|
82246
|
+
truth: \`guide connector\`.`;
|
|
82247
|
+
}
|
|
82248
|
+
return `- **Asked for the claude.ai connector / remote / hosted tier** \u2014 this session is
|
|
82249
|
+
a local install, not that tier. Whether a public URL is being served today is the
|
|
82250
|
+
operator's rollout decision and this build cannot see it: do not assert either way. The
|
|
82251
|
+
local install paths work regardless. Full truth: \`guide connector\`.`;
|
|
82252
|
+
}
|
|
82253
|
+
function approvalPageLocation(d) {
|
|
82254
|
+
if (d.tier === "hosted") {
|
|
82255
|
+
return `its URL is ALSO in the tool result. On this hosted tier the page is served by
|
|
82256
|
+
the connector itself over HTTPS on its own public origin, so ANY browser reaches it,
|
|
82257
|
+
including a phone's. The link carries a one-time session token \u2014 treat it as a secret,
|
|
82258
|
+
never forward it, and check the address bar shows that same origin before connecting a
|
|
82259
|
+
wallet.`;
|
|
82260
|
+
}
|
|
82261
|
+
return `its URL is ALSO in the tool result. On this local install the page is served by
|
|
82262
|
+
the server's own loopback listener (127.0.0.1): it exists only on the machine the
|
|
82263
|
+
server runs on, so open it there \u2014 no other device can reach it.`;
|
|
82264
|
+
}
|
|
82265
|
+
function switchNetworkHeadline(d) {
|
|
82266
|
+
return d.networks.length > 1 ? "sepolia \u2194 mainnet by conversation (real adapter)" : `${d.networks[0]} ONLY on this deployment (real adapter)`;
|
|
82267
|
+
}
|
|
82268
|
+
function switchNetworkRules(d) {
|
|
82269
|
+
if (d.networks.length > 1) {
|
|
82270
|
+
return `- \`network_switch switch { network, confirmed: true }\` \u2014 the switch runs only after
|
|
82271
|
+
the human approves the card. sepolia = practice funds; mainnet = REAL MONEY.
|
|
82272
|
+
- NOTHING carries across: positions, vaults, signer bindings, logins are per-network.
|
|
82273
|
+
A sepolia position does not exist on mainnet and vice versa.
|
|
82274
|
+
- Fund-moving loan operations work on BOTH networks \u2014 on mainnet they move REAL money,
|
|
82275
|
+
and every one still requires the user's explicit confirmation plus the signer
|
|
82276
|
+
ceremony. The exception is PSM swaps: sepolia-only, refused on mainnet.`;
|
|
82277
|
+
}
|
|
82278
|
+
const only = d.networks[0];
|
|
82279
|
+
const money = d.networks.includes("mainnet") ? "REAL MONEY" : "PRACTICE funds";
|
|
82280
|
+
const psm = d.networks.includes("mainnet") ? "The exception is PSM swaps \u2014 the write port refuses them here." : "PSM swaps run here, and are refused on every other network.";
|
|
82281
|
+
return `- \`network_switch switch { network, confirmed: true }\` exists, but ${only} is the ONLY
|
|
82282
|
+
network this deployment is rolled out to \u2014 every other target is REFUSED with that
|
|
82283
|
+
rollout truth. There is nothing to switch TO here; never offer the user another world.
|
|
82284
|
+
Money reality: ${money}.
|
|
82285
|
+
- State is per-network by construction: positions, vaults, signer bindings and logins
|
|
82286
|
+
belong to ${only} and would not exist anywhere else.
|
|
82287
|
+
- Fund-moving loan operations run on ${only}, each still requiring the user's explicit
|
|
82288
|
+
confirmation plus the signer ceremony.
|
|
82289
|
+
- ${psm}`;
|
|
82290
|
+
}
|
|
82291
|
+
function wrongNetworkTroubleshootingRow(d) {
|
|
82292
|
+
if (d.networks.length > 1) {
|
|
82293
|
+
return `- **"Wrong network" / wants mainnet or sepolia** \u2014 real adapter: \`network_switch\`
|
|
82294
|
+
(human-confirmed card; nothing carries across networks). Mock: the world is pinned by
|
|
82295
|
+
config \u2014 no switch exists there.`;
|
|
82296
|
+
}
|
|
82297
|
+
return `- **Wrong network / asks for another one** \u2014 this deployment is rolled out to
|
|
82298
|
+
${d.networks[0]} alone, so \`network_switch\` refuses every other target with that
|
|
82299
|
+
rollout truth. Relay the refusal; do not suggest a world this service does not serve.`;
|
|
82300
|
+
}
|
|
82301
|
+
function switchNetworkIndexLine(d) {
|
|
82302
|
+
if (d.networks.length > 1) {
|
|
82303
|
+
return "- switch-network \u2014 moving this session between sepolia (practice) and mainnet (REAL MONEY): the card, what carries across (nothing), what stays gated";
|
|
82304
|
+
}
|
|
82305
|
+
const only = d.networks[0];
|
|
82306
|
+
const money = d.networks.includes("mainnet") ? "REAL MONEY" : "PRACTICE funds";
|
|
82307
|
+
return `- switch-network \u2014 this deployment is rolled out to ${only} alone (${money}): \`network_switch status\` states the live world, and every other target is refused with that rollout truth`;
|
|
82308
|
+
}
|
|
82309
|
+
function psmAvailabilityNote(d) {
|
|
82310
|
+
if (d.networks.includes("sepolia")) return "";
|
|
82311
|
+
return `**Not executable on this deployment.** The PSM write port refuses on every network
|
|
82312
|
+
but sepolia, which this deployment is not rolled out to \u2014 quotes (\`psm_quote\`) and
|
|
82313
|
+
\`protocol://psm\` reads still answer, but no swap can execute here. Everything below is
|
|
82314
|
+
the mechanism, not an offer: say so before a user plans around it.
|
|
82315
|
+
|
|
82316
|
+
`;
|
|
82317
|
+
}
|
|
82318
|
+
function authorizationModeBullets(d) {
|
|
82319
|
+
const bullets = [];
|
|
82320
|
+
if (offers(d, "external")) {
|
|
82321
|
+
bullets.push(` - \`external\` \u2014 the user approves in their OWN wallet (browser popup, or WalletConnect
|
|
82322
|
+
mobile via QR/paste-code). Real adapter and mock. For TRANSACTIONS the approval card
|
|
82323
|
+
is decoded from the exact bytes being signed \u2014 what the user reads IS what executes.
|
|
82324
|
+
The ONE exception is the BTC withdrawal's EXECUTE phase: an opaque 32-byte hash the
|
|
82325
|
+
approval page states plainly it CANNOT decode. Never extend the card promise over
|
|
82326
|
+
that one \u2014 say it before the popup. Walkthrough: \`guide connect-wallet\`.`);
|
|
82327
|
+
}
|
|
82328
|
+
if (offers(d, "keystore")) {
|
|
82329
|
+
bullets.push(` - \`keystore\` \u2014 a local encrypted keystore signs automatically after each confirmation.
|
|
82330
|
+
Real adapter and mock.`);
|
|
82331
|
+
}
|
|
82332
|
+
if (offers(d, "safe") || offers(d, "safe-module")) {
|
|
82333
|
+
bullets.push(` - \`safe\` / \`safe-module\` \u2014 PRACTICE-ONLY today: on the real adapter these modes
|
|
82334
|
+
refuse with that true reason (their planes ship in their own deliveries).`);
|
|
82335
|
+
}
|
|
82336
|
+
if (offers(d, "mock-simulated")) {
|
|
82337
|
+
bullets.push(` - \`mock-simulated\` \u2014 practice-world stand-in ceremony (no cryptography; mock only).`);
|
|
82338
|
+
}
|
|
82339
|
+
return bullets.join("\n");
|
|
82340
|
+
}
|
|
82341
|
+
function keystoreAbsenceParagraph(d) {
|
|
82342
|
+
if (offers(d, "keystore")) return "";
|
|
82343
|
+
return `
|
|
82344
|
+
**There is no keystore mode on this build.** It is ABSENT, not disabled: the provider
|
|
82345
|
+
is never constructed, so no key material can exist server-side and there is nothing to
|
|
82346
|
+
unlock. "Sign automatically, without popups" is impossible here \u2014 say that true reason
|
|
82347
|
+
instead of describing a keystore, and never ask for a password.
|
|
82348
|
+
`;
|
|
82349
|
+
}
|
|
82350
|
+
function keystoreAbsenceBullet() {
|
|
82351
|
+
return `- **"Sign automatically / no popups" cannot happen here** \u2014 there is no keystore mode
|
|
82352
|
+
on this build. It is ABSENT, not disabled: the provider is never constructed, so no key
|
|
82353
|
+
material can exist server-side and nothing can be unlocked. Give that true reason, and
|
|
82354
|
+
never ask for a password.`;
|
|
82355
|
+
}
|
|
82356
|
+
var GUIDE_TOPIC_SOURCES = {
|
|
82357
|
+
"getting-started": `# Diamond Hands \u2014 what this is
|
|
82358
|
+
|
|
82359
|
+
Diamond Hands lets you BORROW a dollar-pegged token (UCD) against your own BITCOIN,
|
|
82360
|
+
without selling it. Your BTC sits in a custody vault tied to your position; you mint UCD
|
|
82361
|
+
against it, pay it back whenever you like, and take your BTC out again.
|
|
82362
|
+
|
|
82363
|
+
**Agent instructions:** answer in the USER'S language, map their words via the \`glossary\`
|
|
82364
|
+
topic, and always say plainly whether this session is PRACTICE or REAL MONEY. Read the
|
|
82365
|
+
\`capabilities\` block in \`boundary://info\` FIRST \u2014 it states the network, whether writes
|
|
82366
|
+
are enabled (and the true reason when not), and which signer modes this build offers;
|
|
82367
|
+
never promise a capability it does not list. The money truth has THREE cases:
|
|
82368
|
+
- Adapter \`mock\` \u2014 a PRACTICE sandbox. No real money anywhere.
|
|
82369
|
+
- Adapter \`real\` on SEPOLIA (the zero-config default) \u2014 the REAL protocol contracts on
|
|
82370
|
+
the test network: real ceremonies and signatures, PRACTICE money (test funds).
|
|
82371
|
+
- Adapter \`real\` on MAINNET \u2014 REAL MONEY. Writes are disabled unless the operator
|
|
82372
|
+
explicitly arms them; the capabilities block states which applies.
|
|
82373
|
+
SAY THIS EARLY AND UNPROMPTED \u2014 users must never wonder whether money is real.
|
|
82374
|
+
|
|
82375
|
+
A first conversation usually goes: explain this page \u2192 \`guide first-setup\` (choose how to
|
|
82376
|
+
authorize) \u2192 create a position \u2192 deposit BTC \u2192 mint. The \`lifecycle\` topic has the exact
|
|
82377
|
+
calls. Every operation that moves funds requires the user's explicit confirmation
|
|
82378
|
+
(\`confirmed: true\`) \u2014 nothing is ever silent.`,
|
|
82379
|
+
"first-setup": (d) => `# First setup \u2014 from zero to ready, by conversation only
|
|
82380
|
+
|
|
82381
|
+
Installing on another machine? Three paths, by machine: Claude Desktop on macOS/Windows
|
|
82382
|
+
\u2192 the \`.mcpb\` bundle from the releases page (no Node needed); Linux or any other MCP
|
|
82383
|
+
host \u2192 the one-line installer (self-contained binary, prints the exact config snippet);
|
|
82384
|
+
developers with Node \u2265 18 on PATH \u2192 \`npx -y @gvnrdao/dh-mcp\`. Details: the README
|
|
82385
|
+
install matrix. ${connectorInstallNote(d)}
|
|
82386
|
+
|
|
82387
|
+
Nothing needs a config file. Three steps:
|
|
82388
|
+
|
|
82389
|
+
**1. Know your world.** Read \`boundary://info\` (its \`capabilities\` block) and
|
|
82390
|
+
\`protocol_status\`, then tell the user: practice (mock) or real adapter; sepolia
|
|
82391
|
+
(practice money) or mainnet (real money); whether writes are enabled here and which
|
|
82392
|
+
signer modes exist; current terms (\`protocol_terms\`).
|
|
82393
|
+
|
|
82394
|
+
**2. Choose HOW to authorize operations** (the user's choice, made by talking):
|
|
82395
|
+
- **"Use my own wallet"** \u2192 call \`signer_setup\` action \`use\`, mode \`external\` \u2014 works
|
|
82396
|
+
on the real adapter and the mock. The approval page auto-opens in the browser (its URL
|
|
82397
|
+
is ALSO in the tool result); the user connects MetaMask \u2014 or scans the WalletConnect QR
|
|
82398
|
+
/ pastes the pairing code for a mobile wallet \u2014 and then APPROVES EACH OPERATION in
|
|
82399
|
+
their own wallet. The first verified signature binds their wallet address as the
|
|
82400
|
+
borrower. Full walkthrough: \`guide connect-wallet\`.
|
|
82401
|
+
${offers(d, "keystore") ? `- **"Sign automatically / no popups"** \u2192 mode \`keystore\`. A local encrypted keystore
|
|
82402
|
+
signs after each confirmation. Provision it via the env pair (\`DH_KEYSTORE_PATH\` +
|
|
82403
|
+
\`DH_KEYSTORE_PASSWORD\`), or call \`signer_setup\` action \`unlock-keystore\`: a SECURE
|
|
82404
|
+
LOCAL PAGE opens where the user types the password or generates a fresh keystore.
|
|
82405
|
+
NEVER ask for or accept a password in the conversation \u2014 if a user pastes one, tell
|
|
82406
|
+
them to use the unlock page instead.` : keystoreAbsenceBullet()}
|
|
82407
|
+
${offers(d, "safe") || offers(d, "safe-module") ? `- **Safe / delegation modes (\`safe\`, \`safe-module\`) are PRACTICE-ONLY today** \u2014 on the
|
|
82408
|
+
real adapter they refuse with that true reason. Try them in a mock world.` : `- **Safe / delegation borrowing is not offered by this build** \u2014 its authorization
|
|
82409
|
+
surface is the wallet ceremony and nothing else; \`signer_setup\` lists no other mode.
|
|
82410
|
+
\`guide safe\` and \`guide delegation\` state what exists elsewhere.`}
|
|
82411
|
+
- Not sure? \`signer_setup\` action \`status\` explains what is active and what is missing.
|
|
82412
|
+
- **No signer is also a valid start:** every public read works without one \u2014
|
|
82413
|
+
\`position_list {borrower}\` with the user's address needs no signer and no login.
|
|
82414
|
+
${d.networks.length > 1 ? `- **Wrong network?** On the real adapter the user can switch sepolia \u2194 mainnet by
|
|
82415
|
+
talking (\`network_switch\`, human-confirmed) \u2014 see \`guide switch-network\`. State
|
|
82416
|
+
the money reality after any switch.` : `- **Wrong network?** This deployment is rolled out to ${d.networks[0]} alone \u2014
|
|
82417
|
+
\`network_switch\` refuses every other target with that rollout truth. See
|
|
82418
|
+
\`guide switch-network\`; never offer a world this service does not serve.`}
|
|
82419
|
+
|
|
82420
|
+
**3. First position.** \`loan_create\` with a term from \`protocol_terms\` (needs
|
|
82421
|
+
\`confirmed: true\` from the user). Then deposit BTC to the vault address
|
|
82422
|
+
(practice worlds: simulate it with \`mock_control\` \`submit-deposit\` + \`confirm-deposit\`),
|
|
82423
|
+
and mint with \`loan_mint\`.
|
|
82424
|
+
|
|
82425
|
+
The user can switch authorization modes at ANY time by saying so \u2014 repeat step 2.`,
|
|
82426
|
+
"connect-wallet": (d) => `# Connect your wallet \u2014 the external-signer walkthrough
|
|
82427
|
+
|
|
82428
|
+
External mode means the user approves every operation in their OWN wallet \u2014 a browser
|
|
82429
|
+
extension (MetaMask) or a WalletConnect mobile wallet. It works on the real adapter and
|
|
82430
|
+
the mock.
|
|
82431
|
+
|
|
82432
|
+
**The walkthrough:**
|
|
82433
|
+
1. \`signer_setup\` action \`use\`, mode \`external\`. The approval page auto-opens in the
|
|
82434
|
+
desktop browser; ${approvalPageLocation(d)}
|
|
82435
|
+
2. On the page: connect the browser extension, or \u2014 for a mobile wallet \u2014 scan the
|
|
82436
|
+
WalletConnect QR code or paste the pairing code.
|
|
82437
|
+
3. For authenticated reads before any write: \`signer_setup\` action \`connect\` runs the
|
|
82438
|
+
login ceremony explicitly (one typed-data signature in the wallet).
|
|
82439
|
+
4. The FIRST verified signature binds that wallet address as the borrower \u2014 it persists
|
|
82440
|
+
across sessions (\`signer_setup reset-borrower\` unbinds it).
|
|
82441
|
+
5. From then on, every fund-moving operation shows an approval card in the wallet. For
|
|
82442
|
+
TRANSACTIONS that card is decoded from the exact bytes being signed \u2014 what you read
|
|
82443
|
+
IS what executes. The ONE exception is the BTC withdrawal, which signs an opaque
|
|
82444
|
+
32-byte hash the page states plainly it CANNOT decode (honesty note below); say so
|
|
82445
|
+
before those popups, never "what you read is what executes". Declining always safely
|
|
82446
|
+
cancels.
|
|
82447
|
+
|
|
82448
|
+
**Popup cadence \u2014 exactly this many wallet interactions per operation:**
|
|
82449
|
+
|
|
82450
|
+
| Operation | Wallet interactions (external mode) |
|
|
82451
|
+
|---|---|
|
|
82452
|
+
| login (per login-session lifetime) | 1 typed-data |
|
|
82453
|
+
| create position | 1 tx (plus 1 login typed-data the first time \u2014 the protocol SDK keeps its own session) |
|
|
82454
|
+
| mint | 1 personal-sign + 1 tx |
|
|
82455
|
+
| repay | 1 personal-sign + 1-2 tx (UCD approve leg when the server returns one) |
|
|
82456
|
+
| extend | 1 personal-sign + 1 tx |
|
|
82457
|
+
| allowlist destination | 1 tx (plus 1 login typed-data the first time \u2014 same SDK session) |
|
|
82458
|
+
| withdraw BTC | 1\u20133 typed-data (decodable) + 1 personal-sign \u2014 a BLIND hash the page cannot decode (see the honesty note below) |
|
|
82459
|
+
| PSM swap/redeem | 2 tx (exact-amount approve + swap/redeem) |
|
|
82460
|
+
|
|
82461
|
+
**Honesty notes (say these plainly):**
|
|
82462
|
+
- **Reads never pop the wallet.** If a read needs a login the user does not have, the
|
|
82463
|
+
tool refuses legibly and the user says "connect my wallet" (\`signer_setup\` action
|
|
82464
|
+
\`connect\`). The wallet never appears unrequested.
|
|
82465
|
+
- **Logins expire.** When the session token dies mid-conversation, the next
|
|
82466
|
+
authenticated call refuses with the same remedy \u2014 an explicit reconnect, never a
|
|
82467
|
+
surprise popup. On mainnet the broker also throttles logins per address \u2014 a throttled
|
|
82468
|
+
login means "wait and retry", not a wallet failure.
|
|
82469
|
+
- **Withdraw-BTC under external mode has ONE blind signature, not two.** The
|
|
82470
|
+
authorization phase is EIP-712 typed data \u2014 the wallet renders position, amount and
|
|
82471
|
+
destination and the user can read it. Only the EXECUTE phase signs an opaque 32-byte
|
|
82472
|
+
hash the SDK builds internally, which the approval page shows bare and says plainly it
|
|
82473
|
+
cannot decode (the production web app signs the same way). Tell the user before that
|
|
82474
|
+
ONE popup. Do not describe the typed phase as blind: overstating it teaches them to
|
|
82475
|
+
expect an unreadable card and click through the readable one.
|
|
82476
|
+
- **The READABLE phase can be asked for up to THREE times.** Its authorization is only
|
|
82477
|
+
valid inside a short protocol timing window, and the SDK re-signs on a miss \u2014 up to 3
|
|
82478
|
+
attempts, each a FRESH typed-data card. So a slow approval does not fail; it comes
|
|
82479
|
+
back. Warn the user: a second or third identical card is the retry, NOT a duplicate
|
|
82480
|
+
charge and NOT an attack \u2014 but they should still read it, and each attempt is a new
|
|
82481
|
+
signature. The blind execute popup happens once.
|
|
82482
|
+
- **The allowlist delay is read LIVE from the chain.** A new BTC withdrawal destination
|
|
82483
|
+
(\`loan_allowlist_destination\`) becomes usable only after the chain's own delay \u2014 24
|
|
82484
|
+
hours on mainnet, so allowlisting and withdrawing happen on DIFFERENT DAYS there. The
|
|
82485
|
+
card states the live figure.
|
|
82486
|
+
- **Mainnet:** every fund-moving operation spends REAL money, and the minimum mint is
|
|
82487
|
+
10 UCD.
|
|
82488
|
+
|
|
82489
|
+
**Disconnecting \u2014 "log out / sign out / forget my wallet" (\`signer_setup\` action
|
|
82490
|
+
\`disconnect\`):** the FULL wallet flush. It ends every approval-page session and any
|
|
82491
|
+
WalletConnect session (pending approvals are cancelled loudly), discards the login
|
|
82492
|
+
token from server memory AND revokes it at the service, and unbinds the borrower
|
|
82493
|
+
identity. Reconnecting afterwards ALWAYS requires opening the approval page again and
|
|
82494
|
+
a fresh wallet signature \u2014 a disconnect can never silently reconnect. Two truths to
|
|
82495
|
+
state: (1) \`reset-borrower\` is NOT a disconnect \u2014 it only swaps identity and leaves
|
|
82496
|
+
the connection and login alive; (2) no server can revoke the wallet's own site
|
|
82497
|
+
permission for the approval page \u2014 remove that inside the wallet (MetaMask: Settings \u2192
|
|
82498
|
+
Connections / Connected sites).`,
|
|
82499
|
+
lifecycle: `# The full lifecycle \u2014 exact calls
|
|
82500
|
+
|
|
82501
|
+
1. **Create** \u2014 \`loan_create {selectedTerm, confirmed:true}\` \u2192 position id, vault address.
|
|
82502
|
+
2. **Deposit BTC** \u2014 send BTC to the vault address; it becomes usable after the
|
|
82503
|
+
confirmation threshold (\`protocol_status.minConfirmations\`). Practice worlds:
|
|
82504
|
+
\`mock_control {action:"submit-deposit", positionId, sats}\` then
|
|
82505
|
+
\`{action:"confirm-deposit", txid, confirmations}\`.
|
|
82506
|
+
3. **Borrow (mint)** \u2014 \`loan_mint {positionId, amountUcd, confirmed:true}\`. Ceiling:
|
|
82507
|
+
\`position_status\` \u2192 \`valuation.maxMintableUcd\`. The origination fee is ADDED to debt.
|
|
82508
|
+
4. **Repay** \u2014 \`loan_pay {positionId, amountUcd, confirmed:true}\`. Fee-free, partial or
|
|
82509
|
+
full; full repayment moves the position to REPAID.
|
|
82510
|
+
5. **Extend (renew)** \u2014 \`loan_extend {positionId, selectedTerm, confirmed:true}\`, only
|
|
82511
|
+
within the FINAL 30 DAYS of the current term. The extension fee is ADDED TO YOUR DEBT
|
|
82512
|
+
(your wallet is not charged); it is at most the term's rate \xD7 your current debt,
|
|
82513
|
+
reduced by unused origination-fee credit from the current term.
|
|
82514
|
+
6. **Withdraw BTC** \u2014 \`loan_withdraw {positionId, btcAddress, amountSats, confirmed:true}\`.
|
|
82515
|
+
BTC sends are IRREVERSIBLE \u2014 read the address back to the user before confirming.
|
|
82516
|
+
amountSats is gross (fee comes out of it) and may be the whole available balance.
|
|
82517
|
+
7. **Watch it** \u2014 \`position_status\` (one), \`position_list\` (all),
|
|
82518
|
+
\`position_events\` (history), \`btc_price\`, \`protocol_status\`.
|
|
82519
|
+
|
|
82520
|
+
State flow: ${STATE_FLOW_LINE} \u2014 see \`safety\`.`,
|
|
82521
|
+
fees: `# Fees \u2014 the two models, stated plainly
|
|
82522
|
+
|
|
82523
|
+
- **Origination fee (minting):** a percentage of what you borrow
|
|
82524
|
+
(\`protocol_terms.originationFeeBps\`, e.g. 200 = 2%). It is ADDED TO YOUR DEBT: borrow
|
|
82525
|
+
100 UCD \u2192 you receive 100, you owe 102. It is never taken out of what you receive.
|
|
82526
|
+
- **Extension fee (renewing):** ADDED TO YOUR DEBT, like the origination fee \u2014 your
|
|
82527
|
+
wallet is not charged. The CEILING is \`extensionFeeRateBps\` \xD7 your CURRENT DEBT (a
|
|
82528
|
+
flat rate per renewal, not per month); origination fees you already paid this term are
|
|
82529
|
+
CREDITED against it, so the charged fee lands between (ceiling \u2212 that credit) and the
|
|
82530
|
+
ceiling.
|
|
82531
|
+
- **Repayment:** no fee, any amount up to the debt.
|
|
82532
|
+
- **BTC network fee (withdrawals):** deducted FROM the amount you withdraw (default
|
|
82533
|
+
1000 sats) \u2014 the destination receives amountSats \u2212 fee.
|
|
82534
|
+
|
|
82535
|
+
Every fund-moving result carries an \`authorization.card\` \u2014 the exact text that was
|
|
82536
|
+
signed, amounts included. Read it back when the user asks what happened.`,
|
|
82537
|
+
psm: (d) => `# PSM \u2014 exchanging UCD \u2194 USDC (the peg-stability module)
|
|
82538
|
+
|
|
82539
|
+
${psmAvailabilityNote(d)}The PSM is the protocol's exchange window between UCD and USDC, near the peg. Two
|
|
82540
|
+
directions, in user words:
|
|
82541
|
+
|
|
82542
|
+
- **"Get UCD for my USDC"** (\`psm_quote\` direction \`to-ucd\`): you pay USDC, the PSM
|
|
82543
|
+
mints UCD **to you** (output always goes to the caller \u2014 there is no recipient field).
|
|
82544
|
+
The **entry fee is charged IN UCD**: a percentage (basis points) of the gross converted
|
|
82545
|
+
UCD, taken before it reaches you \u2014 e.g. at a 1% fee, 100 USDC converts to 100 UCD gross
|
|
82546
|
+
and you receive 99 UCD.
|
|
82547
|
+
- **"Get USDC back"** (\`psm_quote\` direction \`to-usdc\`): you return UCD (it is burned)
|
|
82548
|
+
and the PSM pays you USDC **from its live reserves**. The **exit fee is charged IN
|
|
82549
|
+
USDC**, deducted from what you receive; the contract caps it at 10%. A redemption is
|
|
82550
|
+
only possible while reserves cover the payout \u2014 the quote shows live reserves, and a
|
|
82551
|
+
shortfall refuses with both figures (available vs required).
|
|
82552
|
+
|
|
82553
|
+
The two fees are independent and live in DIFFERENT tokens \u2014 always say which token a fee
|
|
82554
|
+
is in. Rates and fees are configuration (\`protocol://psm\` shows them; exchange rate
|
|
82555
|
+
1e18 = 1:1) and can be changed by protocol governance.
|
|
82556
|
+
|
|
82557
|
+
**Limits and switches** (all visible in \`protocol://psm\`):
|
|
82558
|
+
- Each direction has a min and max PER OPERATION. Unit trap: to-ucd limits are in USDC
|
|
82559
|
+
units, to-usdc limits are in UCD. A max of 0 means that direction is DISABLED.
|
|
82560
|
+
- \`paused\` kills BOTH directions; \`redeemEnabled = false\` kills ONLY the to-usdc
|
|
82561
|
+
direction (swaps to UCD keep working). These are different switches \u2014 name the right one.
|
|
82562
|
+
- Per-block volume caps may exist per direction ("uncapped" when none is set).
|
|
82563
|
+
|
|
82564
|
+
**Why a slippage floor exists:** executing an exchange on-chain REQUIRES a minimum-out
|
|
82565
|
+
floor \u2014 submitting with a zero floor is refused by the contract. Fees or the rate can
|
|
82566
|
+
change between your quote and execution; the floor makes a drifted execution REFUSE
|
|
82567
|
+
rather than silently deliver less than quoted.
|
|
82568
|
+
|
|
82569
|
+
**Practice funding (sepolia):** the sepolia stablecoin is a MOCK USDC with a public
|
|
82570
|
+
\`mint\` \u2014 you can create practice USDC for yourself, self-serve. \`protocol://psm\` states
|
|
82571
|
+
the token's kind (\`mock\` vs \`circle\`) and address so you never have to guess whether
|
|
82572
|
+
the money is real. On mainnet the stablecoin is real Circle USDC.
|
|
82573
|
+
|
|
82574
|
+
**Executing (\`psm_swap\`):** an exchange is TWO on-chain ceremonies, both shown in the
|
|
82575
|
+
result. (1) An **exact-amount approval** of the input token \u2014 never unlimited. The spender
|
|
82576
|
+
differs by direction, and that is contract truth, not a quirk: for **to-ucd** you approve
|
|
82577
|
+
USDC to the **PSM contract** (it pulls the USDC it converts); for **to-usdc** you approve
|
|
82578
|
+
UCD to the **UCDController** (the PSM burns your UCD through the controller). (2) The
|
|
82579
|
+
swap/redeem itself, carrying a minimum-out floor = the live quote minus a 100 bps
|
|
82580
|
+
tolerance; if fees or the rate drifted beyond that between quote and execution, the
|
|
82581
|
+
contract refuses \u2014 you never silently receive less. Output always lands at the signer's
|
|
82582
|
+
own address. If you approve step 1 but decline step 2, the exact-amount allowance remains
|
|
82583
|
+
standing \u2014 it authorizes only that amount and nothing else; the result says so plainly.
|
|
82584
|
+
On the real protocol, PSM writes run on sepolia ONLY \u2014 mainnet PSM writes are refused
|
|
82585
|
+
(the PSM-specific sepolia-only anchor; loan operations are not affected).`,
|
|
82586
|
+
authorization: (d) => `# Authorization \u2014 who signs, and what a signature means
|
|
82587
|
+
|
|
82588
|
+
Every fund-moving operation needs TWO things, always in this order:
|
|
82589
|
+
1. **The user's explicit confirmation** in conversation (\`confirmed: true\`) \u2014 the agent
|
|
82590
|
+
must ask, never assume.
|
|
82591
|
+
2. **A cryptographic authorization** by the chosen signer mode. This build offers
|
|
82592
|
+
exactly ${d.signerModes.map((m) => `\`${m}\``).join(", ")} \u2014 ${signerModeSourceClause(d)}. Never
|
|
82593
|
+
describe a mode outside it:
|
|
82594
|
+
${authorizationModeBullets(d)}
|
|
82595
|
+
${keystoreAbsenceParagraph(d)}
|
|
82596
|
+
**Reads never summon the wallet.** Public reads need no signer at all. Authenticated
|
|
82597
|
+
reads need a login \u2014 ${offers(d, "keystore") ? "the keystore env pair, or " : ""}an explicit "connect my wallet"
|
|
82598
|
+
(\`signer_setup\` action \`connect\`). Without one they refuse legibly; a wallet popup is
|
|
82599
|
+
only ever caused by a write ceremony or that explicit connect. The login (one typed-data
|
|
82600
|
+
signature) lasts a JWT lifetime; when it expires, the next call refuses the same legible
|
|
82601
|
+
way \u2014 reconnect on the user's word.
|
|
82602
|
+
|
|
82603
|
+
Results carry \`authorization\`: \`scheme\` (external-wallet | eip712-eoa | mock-signature),
|
|
82604
|
+
\`signer\` (who signed), \`card\` (what was signed, human-readable), \`digest\` (the signature
|
|
82605
|
+
or transaction hash). Declining in the wallet ALWAYS safely cancels the operation.
|
|
82606
|
+
|
|
82607
|
+
\`signer_setup status\` vocabulary: a **candidate** is a wallet that is CONNECTED to the
|
|
82608
|
+
approval page but has not yet proven itself by signing; the **borrower** is the identity
|
|
82609
|
+
BOUND by the first verified signature (it persists across sessions). Connected \u2260 chosen:
|
|
82610
|
+
picking external mode is a preference \u2014 a wallet still has to connect on the approval
|
|
82611
|
+
page, and the page link comes from \`signer_setup status\`.
|
|
82612
|
+
|
|
82613
|
+
Switching modes: \`signer_setup\` \u2014 see \`first-setup\`. Secrets NEVER travel through chat${offers(d, "keystore") ? ";\nkeystore passwords go only into the secure unlock page." : " \u2014\nand this build has no password to ask for in the first place."}`,
|
|
82614
|
+
// Rendered on the capability axis: a build that constructs no Safe-shaped mode must not
|
|
82615
|
+
// hand a user a setup walkthrough its `signer_setup` cannot accept (the F1/F2 class,
|
|
82616
|
+
// one topic over). The concepts a Safe owner still needs stay; the instructions go.
|
|
82617
|
+
safe: (d) => !offers(d, "safe") ? `# Safe accounts \u2014 not offered by this build
|
|
82618
|
+
|
|
82619
|
+
A **Safe** is a smart-contract account owned by one or more wallets ("owners") with a
|
|
82620
|
+
signature **threshold** (e.g. 2-of-3: any 2 of the 3 owners must sign). Diamond Hands can
|
|
82621
|
+
treat a Safe AS THE BORROWER \u2014 but not from here. This build's authorization surface is
|
|
82622
|
+
the wallet ceremony alone; \`signer_setup\` lists no Safe-shaped option, so there is
|
|
82623
|
+
nothing to set up. Say that plainly instead of walking a user through a ceremony this
|
|
82624
|
+
service cannot run.
|
|
82625
|
+
|
|
82626
|
+
**What still holds for a Safe's position anywhere:** its BTC withdrawal destination must
|
|
82627
|
+
be ALLOWLISTED first, and the allowlist delay is READ LIVE from the chain \u2014 24 hours on
|
|
82628
|
+
mainnet, so allowlisting and withdrawing happen on DIFFERENT DAYS. Owner authorizations
|
|
82629
|
+
for mint/pay/renew expire in minutes and withdrawal authorizations within the minute, so
|
|
82630
|
+
a multi-owner signing session happens TOGETHER, live.
|
|
82631
|
+
|
|
82632
|
+
**Where it does exist:** the local install's practice worlds run the Safe borrower plane
|
|
82633
|
+
end to end, and the web app (diamondhands.credit) speaks to the same chain state. A user
|
|
82634
|
+
who needs it is not blocked \u2014 they are on the wrong surface for it.` : `# Safe accounts \u2014 borrowing as a smart-account (single or multi-owner)
|
|
82635
|
+
|
|
82636
|
+
A **Safe** is a smart-contract account owned by one or more wallets ("owners") with a
|
|
82637
|
+
signature **threshold** (e.g. 2-of-3: any 2 of the 3 owners must sign). Companies and
|
|
82638
|
+
teams use Safes so no single key controls the funds. Diamond Hands supports a Safe AS THE
|
|
82639
|
+
BORROWER: the position belongs to the Safe, and operations are authorized by its owners.
|
|
82640
|
+
|
|
82641
|
+
**Adapter truth:** the Safe borrower plane is PRACTICE-ONLY today \u2014 on the real adapter,
|
|
82642
|
+
\`signer_setup use safe\` refuses with exactly that reason. Everything below runs in mock
|
|
82643
|
+
worlds until the Safe plane's own delivery; never present it as available on real.
|
|
82644
|
+
|
|
82645
|
+
**Setup:** \`signer_setup\` action \`use\`, mode \`safe\`, with \`safeAddress\`. Owners and
|
|
82646
|
+
threshold are DISCOVERED from the Safe itself \u2014 never typed in. (Practice worlds: create
|
|
82647
|
+
a test Safe first with \`mock_control deploy-safe\`.) If keystore material is already
|
|
82648
|
+
configured (\`signer_setup status\` \u2192 keystoreConfigured), \`use safe\` unlocks it
|
|
82649
|
+
AUTOMATICALLY \u2014 do not send the user to the unlock page in that case.
|
|
82650
|
+
|
|
82651
|
+
**Who signs what (say this plainly):**
|
|
82652
|
+
- Every operation still needs the user's \`confirmed: true\` first \u2014 nothing changed there.
|
|
82653
|
+
- Owner signatures then authorize the operation. In the current phase the local keystore
|
|
82654
|
+
is the owner-signer (a 1-of-1 Safe); external owner wallets join in a later phase.
|
|
82655
|
+
- Creating a position and withdrawing BTC are executed BY the Safe itself (a Safe
|
|
82656
|
+
transaction \u2014 you may see a "Safe nonce" on the card). Minting, paying and renewing
|
|
82657
|
+
are authorized by the owners and submitted by an executor \u2014 the result card names it.
|
|
82658
|
+
|
|
82659
|
+
**Withdrawals have one extra rule:** the destination BTC address must be ALLOWLISTED for
|
|
82660
|
+
the Safe first \u2014 \`loan_allowlist_destination\` (its own owner-signed ceremony; the address
|
|
82661
|
+
becomes usable after a delay READ LIVE from the chain \u2014 immediate in practice worlds,
|
|
82662
|
+
24 hours on mainnet, where allowlisting and withdrawing happen on different days). A
|
|
82663
|
+
withdrawal to an unlisted address refuses with exactly this instruction.
|
|
82664
|
+
|
|
82665
|
+
**Timing honesty (multi-owner Safes, later phases):** authorizations for mint/pay/renew
|
|
82666
|
+
expire after ~3 minutes, and withdrawal authorizations within the minute \u2014 so a multi-
|
|
82667
|
+
owner signing session happens TOGETHER, live ("gather first, sign in one burst").
|
|
82668
|
+
Creating a position and allowlisting a destination have NO expiry \u2014 owners can sign
|
|
82669
|
+
those at their own pace. The ceremony guides this; never widen a window.`,
|
|
82670
|
+
delegation: (d) => !offers(d, "safe-module") ? `# Delegation \u2014 not offered by this build
|
|
82671
|
+
|
|
82672
|
+
Delegation is the protocol's answer to multi-owner Safes: the owners sign ONCE to install
|
|
82673
|
+
a tightly-caged AGENT key, and day-to-day work then runs without disturbing them. It is a
|
|
82674
|
+
Safe-shaped authorization plane, and this build constructs none \u2014 \`signer_setup\` lists
|
|
82675
|
+
no such option and \`loan_delegation_setup\` has no plane to install into here. Say that
|
|
82676
|
+
plainly rather than describing a ceremony this service cannot run.
|
|
82677
|
+
|
|
82678
|
+
**The cage, for a user who asks what it would mean:** an agent may create a position and
|
|
82679
|
+
\u2014 only after the owners grant it, per position \u2014 repay, renew, and mint while the
|
|
82680
|
+
post-mint collateral ratio stays at or above the floor the owners set. It can NEVER
|
|
82681
|
+
withdraw Bitcoin alone, never add or change withdrawal destinations, never touch the
|
|
82682
|
+
module or the registry, never move ETH. A stolen agent key can shuffle money WITHIN a
|
|
82683
|
+
position \u2014 never out. Revoking an agent BURNS its address forever, which is why
|
|
82684
|
+
revocation is always safe.
|
|
82685
|
+
|
|
82686
|
+
**Where it does exist:** the local install's practice worlds, pending the plane's own
|
|
82687
|
+
delivery on the real adapter. The web app and the SDK reach the same chain state.` : `# Delegation \u2014 one owner ceremony, then day-to-day solo
|
|
82688
|
+
|
|
82689
|
+
Multi-owner Safes cannot practically sign every operation inside the protocol's short
|
|
82690
|
+
signature window. Delegation is the protocol's answer: the owners sign ONCE to install a
|
|
82691
|
+
tightly-caged AGENT key; afterwards daily work runs without disturbing them.
|
|
82692
|
+
|
|
82693
|
+
**Adapter truth:** delegation (mode \`safe-module\`) is PRACTICE-ONLY today \u2014 on the real
|
|
82694
|
+
adapter it refuses with exactly that reason, pending its own delivery. Everything below
|
|
82695
|
+
runs in mock worlds; never present it as available on real.
|
|
82696
|
+
|
|
82697
|
+
**Setup (mode \`safe-module\`):** \`signer_setup use safe-module\` with your Safe's address,
|
|
82698
|
+
then \`loan_delegation_setup\` \u2014 ONE durable Safe transaction the owners sign at their
|
|
82699
|
+
leisure (no time window). It enables the Safe's AgentModule, binds the agent key, registers
|
|
82700
|
+
it in the delegation registry, and pre-approves your BTC withdrawal destinations (so your
|
|
82701
|
+
first withdrawal never needs a second gathering).
|
|
82702
|
+
|
|
82703
|
+
**What the agent CAN do alone** (an unchangeable, contract-hardcoded list): create a
|
|
82704
|
+
position; and \u2014 per position, only after the owners grant it (\`loan_delegation_grant\`,
|
|
82705
|
+
a quorum signature; the agent can NEVER widen its own powers) \u2014 pay down debt (REPAY),
|
|
82706
|
+
extend the term (RENEW), and borrow (MINT, only while the post-mint collateral ratio
|
|
82707
|
+
stays at or above the floor the owners granted \u2014 their risk bound).
|
|
82708
|
+
|
|
82709
|
+
**What the agent can NEVER do, ever:** withdraw Bitcoin alone (withdrawal signatures are
|
|
82710
|
+
owners-only, permanently \u2014 the verifier has no delegate arm); add or change withdrawal
|
|
82711
|
+
destinations (owners-only, forever); touch the module, the registry, or any other
|
|
82712
|
+
contract; move ETH. A stolen agent key can shuffle money WITHIN your position \u2014 never out.
|
|
82713
|
+
|
|
82714
|
+
**Withdrawals stay a short owners' moment:** the agent prepares and submits, but the
|
|
82715
|
+
owners sign together inside the short window, and only to destinations they pre-approved.
|
|
82716
|
+
Where the destination registry is wired on-chain this bound is enforced by the contract;
|
|
82717
|
+
verify the wiring on your network before relying on it (test networks: wired and verified;
|
|
82718
|
+
mainnet wiring is confirmed at deployment review).
|
|
82719
|
+
|
|
82720
|
+
**Rotation and revocation:** revoking the agent BURNS its address forever (AR-1) \u2014 that
|
|
82721
|
+
is deliberate, so revocation is always safe to use. Rotation = mint a FRESH key and run a
|
|
82722
|
+
new setup ceremony; never reuse keys, never bind a personal or owner key as agent.
|
|
82723
|
+
|
|
82724
|
+
**Currency exchange (PSM):** the module cannot reach the PSM at all \u2014 its allowlist stops
|
|
82725
|
+
at the loan contracts. A Safe's UCD\u2194USDC swaps are TWO durable Safe transactions the
|
|
82726
|
+
owners sign at leisure (\`psm_swap\` builds the pair) \u2014 that is the only Safe PSM path.`,
|
|
82727
|
+
safety: `# Safety \u2014 what protects the user
|
|
82728
|
+
|
|
82729
|
+
- **Nothing moves without you.** Every write needs \`confirmed: true\` AND the signer
|
|
82730
|
+
ceremony. A decline anywhere cleanly cancels \u2014 declining is always safe.
|
|
82731
|
+
- **The card is the truth \u2014 with one named exception.** In external mode the wallet card
|
|
82732
|
+
is decoded from the exact TRANSACTION bytes being signed: what you read IS what
|
|
82733
|
+
executes. The exception is the BTC-withdraw blind signature \u2014 an opaque 32-byte hash
|
|
82734
|
+
the approval page says plainly it cannot decode (\`guide connect-wallet\`). Never
|
|
82735
|
+
extend the "what you read is what executes" promise over that one.
|
|
82736
|
+
- **Liquidation:** if collateral value falls so the collateral ratio drops under the
|
|
82737
|
+
liquidation threshold (\`protocol_status.liquidationThresholdBps\`, e.g. 110%), the
|
|
82738
|
+
position can be liquidated. Watch \`position_status.valuation\` \u2014 \`currentLtvBps\` vs the
|
|
82739
|
+
threshold. Repaying debt or adding collateral restores safety.
|
|
82740
|
+
- **Expiry:** positions have terms; extend BEFORE expiry (\`loan_extend\`). An EXPIRED
|
|
82741
|
+
position cannot mint or extend.
|
|
82742
|
+
- **Withdrawals are irreversible.** Bitcoin sent to a wrong address is gone. Read the
|
|
82743
|
+
address back to the user before confirming.
|
|
82744
|
+
- **Can you lose your bitcoin?** Only through liquidation (undercollateralized debt) or
|
|
82745
|
+
withdrawing to a wrong address. Repaid-in-full positions release all collateral.
|
|
82746
|
+
- **Practice vs real:** mock worlds are stated as such (\`boundary://info\`). Never let a
|
|
82747
|
+
user believe practice gains/losses are real, or vice versa.`,
|
|
82748
|
+
"switch-network": (d) => `# Switch network \u2014 ${switchNetworkHeadline(d)}
|
|
82749
|
+
|
|
82750
|
+
The \`network_switch\` tool moves THIS SESSION between worlds. Check
|
|
82751
|
+
\`boundary://info\` capabilities first: \`networkSwitch: true\` means it is available
|
|
82752
|
+
(real adapter); in a practice sandbox (mock) the world is pinned by config \u2014 there is
|
|
82753
|
+
no switch, and that is by design.
|
|
82754
|
+
|
|
82755
|
+
**Served here:** ${servedNetworks(d)}. A network this deployment does not serve is
|
|
82756
|
+
refused with that reason \u2014 the tool existing is not a promise that both worlds are
|
|
82757
|
+
reachable, so never offer the user a network this deployment does not serve.
|
|
82758
|
+
|
|
82759
|
+
**The rules, plainly:**
|
|
82760
|
+
- \`network_switch status\` \u2014 which network is active and whether money is real. Say
|
|
82761
|
+
this to the user BEFORE and AFTER any switch, always.
|
|
82762
|
+
${switchNetworkRules(d)}
|
|
82763
|
+
- A pending signing ceremony blocks the switch (finish or decline it first).
|
|
82764
|
+
- The switch is session-scoped: when the server restarts, the configured default
|
|
82765
|
+
network returns.
|
|
82766
|
+
|
|
82767
|
+
After any switch: re-read \`boundary://info\`, then STATE the new network and money
|
|
82768
|
+
reality in your next message. The user must never have to ask which world they are in.`,
|
|
82769
|
+
// Plan 17 B1 — the hosted tier's truth, in user language. The trust ledger below is
|
|
82770
|
+
// the plan-12 Part 0 ledger (BINDING, archive/12-remote-connector.md) — all six
|
|
82771
|
+
// entries, verbatim-equivalent; G-CONN pins anchor phrases from every entry.
|
|
82772
|
+
connector: (d) => `# The claude.ai connector \u2014 Diamond Hands with zero install (hosted tier)
|
|
82773
|
+
|
|
82774
|
+
${connectorStatusTruth(d)}
|
|
82775
|
+
|
|
82776
|
+
**What it is:** instead of installing anything, the user adds Diamond Hands to
|
|
82777
|
+
claude.ai as a connector (paste a URL \u2014 zero install, zero Node, zero config files).
|
|
82778
|
+
Sign-in IS the wallet: one Sign-In-with-Ethereum signature proves address ownership \u2014
|
|
82779
|
+
no password, no email, no account beyond the wallet address. The sign-in page offers a
|
|
82780
|
+
WalletConnect QR too, so a phone wallet works without any browser extension.
|
|
82781
|
+
|
|
82782
|
+
**Signature cadence, plainly:** the FIRST connect costs one SIWE signature (sign-in)
|
|
82783
|
+
plus one lit-ops login signature (read access). After that, every operation that moves
|
|
82784
|
+
funds asks for its OWN approval in the user's wallet, every time \u2014 and reads never pop
|
|
82785
|
+
the wallet. The login session lives ONLY in the server's memory: a server restart, or
|
|
82786
|
+
an idle spell long enough that the tenant's world is evicted, means signing in again.
|
|
82787
|
+
That is the flip side of "nothing stored at rest" \u2014 a re-login is normal, not a fault.
|
|
82788
|
+
|
|
82789
|
+
**What the hosted server IS trusted with** (the six residual trusts \u2014 state them
|
|
82790
|
+
honestly when asked "is this safe"):
|
|
82791
|
+
1. **The approval page it serves.** Same security baseline as the diamondhands.credit
|
|
82792
|
+
web app (you already trust the pages gvnr serves over HTTPS). The wallet's own
|
|
82793
|
+
display is the independent backstop for transactions; personal-sign envelopes are
|
|
82794
|
+
action-pinned and expire in minutes; BTC destinations are defended by the on-chain
|
|
82795
|
+
allowlist delay, which no server can shorten.
|
|
82796
|
+
2. **The read credential.** Your lit-ops login token is held in memory for the active
|
|
82797
|
+
session ONLY \u2014 it grants reads and advisory broadcast, it can sign NOTHING, and it
|
|
82798
|
+
is never written to disk. A breach here is privacy-class, never money-class.
|
|
82799
|
+
3. **What the assistant narrates.** Tool results shape what the assistant tells you \u2014
|
|
82800
|
+
a security concern is filed and audited for exactly this channel.
|
|
82801
|
+
4. **Tenant separation \u2014 and the one binding it does NOT make.** Each signed-in wallet
|
|
82802
|
+
gets its own world: its own boundary, its own signer state, its own approval-page
|
|
82803
|
+
mount, keyed by that address. What is NOT bound is the mount to that address \u2014 the
|
|
82804
|
+
world's borrower is whichever wallet CONNECTS at the mount, so a leaked mount link
|
|
82805
|
+
plus an earlier connection would make a different wallet this session's signer. That
|
|
82806
|
+
is signing-class, not merely privacy-class; do not tell a user it cannot be. What
|
|
82807
|
+
contains it: the mount id is freshly random per world and travels only in the user's
|
|
82808
|
+
own tool result (treat the link as a secret), and EVERY fund movement verifies the
|
|
82809
|
+
signature against that bound borrower \u2014 no key material exists server-side, so
|
|
82810
|
+
whoever reaches the page still cannot sign for anyone else. The gap is filed and
|
|
82811
|
+
audited; state it this way rather than claiming a binding that isn't there.
|
|
82812
|
+
5. **Availability and deploy honesty.** Hosted code changes under you: deploys are
|
|
82813
|
+
version-pinned, the page bundle is open-source, and \`boundary://info\` capabilities
|
|
82814
|
+
reports the exact server version.
|
|
82815
|
+
6. **The BTC-withdraw blind sign.** Withdrawal serves an OPAQUE 32-byte hash \u2014 the
|
|
82816
|
+
card says plainly that its contents are NOT decodable on the page (site parity:
|
|
82817
|
+
diamondhands.credit serves the identical blind sign). Defenses stated with it:
|
|
82818
|
+
server-side borrower verification, the minutes-narrow signing window, and the
|
|
82819
|
+
on-chain allowlist delay.
|
|
82820
|
+
|
|
82821
|
+
**What it structurally CANNOT do:** hold keys or custody \u2014 keystore mode is ABSENT
|
|
82822
|
+
from the connector build (not disabled: never constructed), so every fund-moving
|
|
82823
|
+
action needs a fresh signature from the user's own wallet. ${connectorNetworkTruth(d)}
|
|
82824
|
+
|
|
82825
|
+
**Independent exits:** the web app (diamondhands.credit) and the SDK speak to the SAME
|
|
82826
|
+
chain state. The connector going down strands nothing and gates nothing.`,
|
|
82827
|
+
troubleshooting: (d) => `# Troubleshooting \u2014 what error codes mean, in plain words
|
|
82828
|
+
|
|
82829
|
+
${offers(d, "keystore") ? `- **SIGNER_UNAVAILABLE** \u2014 no authorization mode chosen/ready. Two real remedies: the
|
|
82830
|
+
keystore env pair (\`DH_KEYSTORE_PATH\` + \`DH_KEYSTORE_PASSWORD\`), or the user says
|
|
82831
|
+
"connect my wallet" \u2192 \`signer_setup\` action \`connect\` (external mode). \`signer_setup
|
|
82832
|
+
status\` explains what is active; \`first-setup\` step 2 has the full choice.
|
|
82833
|
+
- **"Not logged in" on a read** \u2014 authenticated reads NEVER pop the wallet; the remedy is
|
|
82834
|
+
the same pair: keystore env pair, or "connect my wallet" (\`signer_setup connect\`). An
|
|
82835
|
+
EXPIRED login refuses the same way \u2014 reconnect on the user's word.` : `- **SIGNER_UNAVAILABLE** \u2014 no authorization mode chosen/ready. This build has exactly
|
|
82836
|
+
ONE remedy: the user says "connect my wallet" \u2192 \`signer_setup\` action \`connect\`
|
|
82837
|
+
(external mode). There is no keystore here to configure and no password to supply \u2014
|
|
82838
|
+
saying otherwise sends the user hunting for a setting that does not exist.
|
|
82839
|
+
\`signer_setup status\` explains what is active; \`first-setup\` step 2 has the choice.
|
|
82840
|
+
- **"Not logged in" on a read** \u2014 authenticated reads NEVER pop the wallet; the remedy is
|
|
82841
|
+
the same one: "connect my wallet" (\`signer_setup connect\`). An EXPIRED login refuses
|
|
82842
|
+
the same way \u2014 reconnect on the user's word.`}
|
|
82843
|
+
${d.networks.includes("mainnet") ? `- **PSM write refused on mainnet** \u2014 PSM swaps are sepolia-only (a deliberate anchor,
|
|
82844
|
+
not a bug); loan operations work on mainnet. Reads keep working everywhere.` : `- **PSM write refused** \u2014 the PSM write port answers on sepolia alone (a deliberate
|
|
82845
|
+
anchor, not a bug); loan operations are unaffected. Reads keep working everywhere.`}
|
|
82846
|
+
${wrongNetworkTroubleshootingRow(d)}
|
|
82847
|
+
- **External-mode withdraw shows a bare hash** \u2014 that is by design (site parity): the
|
|
82848
|
+
SDK builds the execute-phase hash internally, so the page cannot decode it. ONE blind
|
|
82849
|
+
signature per withdrawal, not two: the authorization phase is EIP-712 typed data
|
|
82850
|
+
(\`WithdrawRequest\` \u2014 the wallet renders position, amount and destination), and only
|
|
82851
|
+
the execute phase is opaque. Warn the user before that one popup, and do not describe
|
|
82852
|
+
the typed one as blind \u2014 overstating it teaches them to expect an unreadable card and
|
|
82853
|
+
click through the readable one.
|
|
82854
|
+
- **Login throttled (mainnet)** \u2014 the broker limits logins per address; wait and retry.
|
|
82855
|
+
That is the broker throttle, not a wallet failure.
|
|
82856
|
+
- **VALIDATION_FAILED** \u2014 the input itself is off (bad address format, too many decimals,
|
|
82857
|
+
unknown field). The message names the exact problem; fix the input, don't retry blindly.
|
|
82858
|
+
- **UPSTREAM_REJECTED** \u2014 the protocol said no: over the mint ceiling, repaying more than
|
|
82859
|
+
owed, wrong position state, or the USER DECLINED in the wallet. The message says which.
|
|
82860
|
+
A decline is not an error to fix \u2014 it is the user's decision.
|
|
82861
|
+
- **UPSTREAM_UNAVAILABLE** \u2014 a data source or the signature bridge is unreachable/expired.
|
|
82862
|
+
Usually transient; re-check with \`protocol_status\` and retry once.
|
|
82863
|
+
- **NOT_FOUND** \u2014 the position id doesn't exist in this world (check \`position_list\`).
|
|
82864
|
+
- **STATE_DIVERGENCE / STALE_DATA warnings** \u2014 sources disagree or lag; the envelope says
|
|
82865
|
+
which source and when from. Prefer chain-sourced values; re-read before acting.
|
|
82866
|
+
- Approval popup never appeared? \`signer_setup status\` \u2192 reopen the approval page URL.
|
|
82867
|
+
Wallet on the wrong network? The page offers the switch \u2014 approve it in the wallet.
|
|
82868
|
+
${connectorTroubleshootingRow(d)}
|
|
82869
|
+
- **\`spawn npx ENOENT\` at server start (another machine/host)** \u2014 the MCP host searched
|
|
82870
|
+
the system PATH and found no \`npx\`: that machine has no Node.js, or the host (e.g. an
|
|
82871
|
+
Electron app) cannot see a shell-managed Node. Not a server bug \u2014 the npx path requires
|
|
82872
|
+
Node \u2265 18 on PATH. Remedies: the one-line installer (self-contained binary, absolute
|
|
82873
|
+
path in the printed snippet), or the \`.mcpb\` bundle on macOS/Windows Claude Desktop.`,
|
|
82874
|
+
glossary: `# Glossary \u2014 map the user's words to the protocol's
|
|
82875
|
+
|
|
82876
|
+
Synonym sets (treat these as the SAME intent):
|
|
82877
|
+
- **mint** = borrow = take a loan = draw = "get UCD" \u2192 \`loan_mint\`
|
|
82878
|
+
- **pay** = repay = pay back = pay down = settle \u2192 \`loan_pay\`
|
|
82879
|
+
- **extend** = renew = roll over = prolong \u2192 \`loan_extend\`
|
|
82880
|
+
- **withdraw** = take out my bitcoin = cash out = get my BTC back \u2192 \`loan_withdraw\`
|
|
82881
|
+
- **position** = loan = account (the borrowing arrangement) \u2192 \`position_status\`
|
|
82882
|
+
- **disconnect** = log out = sign out = forget my wallet = remove my wallet \u2192
|
|
82883
|
+
\`signer_setup\` action \`disconnect\` (the FULL flush \u2014 never map these to
|
|
82884
|
+
\`reset-borrower\`, which only swaps identity)
|
|
82885
|
+
- **UCD** = the dollar-pegged token you borrow ("the dollars")
|
|
82886
|
+
- **sats** = satoshis, 1 BTC = 100,000,000 sats
|
|
82887
|
+
- **connector** = remote = hosted tier = "claude.ai integration" = "use it without
|
|
82888
|
+
installing" \u2192 \`guide connector\` (it states which tier THIS session is, and the
|
|
82889
|
+
trust model that comes with it)
|
|
82890
|
+
|
|
82891
|
+
Context-dependent terms \u2014 DISAMBIGUATE, never flatten:
|
|
82892
|
+
- **vault** \u2014 the position's BTC custody address. Its balance is your COLLATERAL, not
|
|
82893
|
+
your loan. "How much is in my vault?" \u2192 collateral; "how much do I owe?" \u2192 debt.
|
|
82894
|
+
- **balance** \u2014 ask which: vault BTC (collateral) or UCD debt? They move independently.
|
|
82895
|
+
- **health** \u2014 collateral-value vs debt (\`indexedHealth\`, \`currentLtvBps\`): a SAFETY
|
|
82896
|
+
measure against liquidation, not an account balance.
|
|
82897
|
+
- **interest** \u2014 Diamond Hands charges FEES (origination/extension), not running
|
|
82898
|
+
interest; see \`fees\`.
|
|
82899
|
+
|
|
82900
|
+
Language: answer in the user's language, whatever it is. These mappings apply to meaning,
|
|
82901
|
+
not to English words only \u2014 "pagar" \u2192 \`loan_pay\`, "retirar meu bitcoin" \u2192 \`loan_withdraw\`,
|
|
82902
|
+
"emprestar/pedir emprestado" \u2192 \`loan_mint\`, and so on.`,
|
|
82903
|
+
// Plan 16 C3: rendered from the ONE glossary source (boundary/field-glossary.ts) —
|
|
82904
|
+
// the same entries the anchor test pins against the actually-serialized fields.
|
|
82905
|
+
"reading-data": renderFieldGlossaryTopic()
|
|
82906
|
+
};
|
|
82907
|
+
function renderGuideContent(deployment) {
|
|
82908
|
+
const content = {};
|
|
82909
|
+
for (const topic of GUIDE_TOPICS) {
|
|
82910
|
+
const source = GUIDE_TOPIC_SOURCES[topic];
|
|
82911
|
+
content[topic] = typeof source === "string" ? source : source(deployment);
|
|
82912
|
+
}
|
|
82913
|
+
return content;
|
|
82914
|
+
}
|
|
82915
|
+
function renderGuideIndex(deployment) {
|
|
82916
|
+
const connectorLine = deployment.tier === "hosted" ? `- connector \u2014 the hosted claude.ai tier THIS session is running on (zero install, wallet = account): its six-trust ledger, signature cadence, what it can never do. Serves ${servedNetworks(deployment)}` : "- connector \u2014 the hosted claude.ai tier (zero install, wallet = account): its six-trust ledger, signature cadence, what it can never do. THIS session is a local install, not that tier";
|
|
82917
|
+
return `# Diamond Hands guide \u2014 topics
|
|
82918
|
+
|
|
82919
|
+
- getting-started \u2014 what this product is, practice-vs-real-money honesty (three cases)
|
|
82920
|
+
- first-setup \u2014 zero to ready by conversation (authorization choice included)
|
|
82921
|
+
- connect-wallet \u2014 external-wallet walkthrough: approval page, extension or WalletConnect QR, popup cadence, login honesty, disconnect/log-out
|
|
82922
|
+
- lifecycle \u2014 the exact calls, create \u2192 deposit \u2192 mint \u2192 pay \u2192 extend \u2192 withdraw
|
|
82923
|
+
- fees \u2014 the two fee models, plainly
|
|
82924
|
+
- psm \u2014 exchanging UCD \u2194 USDC: both directions, the two fees WITH their tokens, limits, why a floor exists
|
|
82925
|
+
- authorization \u2014 confirmation + signature: what protects every operation, which modes exist where
|
|
82926
|
+
${offers(deployment, "safe") ? "- safe \u2014 borrowing as a Safe smart-account (single or multi-owner), allowlisting, timing \u2014 PRACTICE-ONLY today" : "- safe \u2014 borrowing as a Safe smart-account: NOT offered by this build (no Safe-shaped mode exists here), and what still holds wherever it is"}
|
|
82927
|
+
${offers(deployment, "safe-module") ? "- delegation \u2014 one owner ceremony, then day-to-day solo: the agent, its cage, and what always stays with the owners \u2014 PRACTICE-ONLY today" : "- delegation \u2014 the caged agent key for multi-owner Safes: NOT offered by this build, and what the cage would mean where it is"}
|
|
82928
|
+
- safety \u2014 liquidation, expiry, irreversible sends, decline-is-safe
|
|
82929
|
+
${switchNetworkIndexLine(deployment)}
|
|
82930
|
+
${connectorLine}
|
|
82931
|
+
- troubleshooting \u2014 error codes in plain words, with the real remedies
|
|
82932
|
+
- glossary \u2014 synonym map + disambiguations (use it to understand ANY user's vocabulary)
|
|
82933
|
+
- reading-data \u2014 every payload field's exact meaning (consult before interpreting any number you are unsure of)
|
|
82934
|
+
|
|
82935
|
+
Orientation: Diamond Hands = borrow UCD (dollar-pegged) against your own Bitcoin without
|
|
82936
|
+
selling it. Everything fund-moving needs the user's confirmed:true AND their chosen
|
|
82937
|
+
signature ceremony. Read boundary://info capabilities FIRST; state the money truth early
|
|
82938
|
+
and always: mock = practice; real adapter on sepolia = real protocol, PRACTICE money;
|
|
82939
|
+
only mainnet is real money.`;
|
|
82940
|
+
}
|
|
82941
|
+
var deploymentKey = (d) => `${d.tier}|${d.networks.join(",")}|${d.signerModes.join(",")}`;
|
|
82942
|
+
var RENDERED = /* @__PURE__ */ new Map();
|
|
82943
|
+
function renderedGuide(deployment) {
|
|
82944
|
+
const key = deploymentKey(deployment);
|
|
82945
|
+
let rendered = RENDERED.get(key);
|
|
82946
|
+
if (!rendered) {
|
|
82947
|
+
rendered = Object.freeze({
|
|
82948
|
+
content: Object.freeze(renderGuideContent(deployment)),
|
|
82949
|
+
index: renderGuideIndex(deployment)
|
|
82950
|
+
});
|
|
82951
|
+
RENDERED.set(key, rendered);
|
|
82952
|
+
}
|
|
82953
|
+
return rendered;
|
|
82954
|
+
}
|
|
82955
|
+
function buildGuideContent(deployment) {
|
|
82956
|
+
return renderedGuide(deployment).content;
|
|
82957
|
+
}
|
|
82958
|
+
function buildGuideIndex(deployment) {
|
|
82959
|
+
return renderedGuide(deployment).index;
|
|
82960
|
+
}
|
|
82961
|
+
var GUIDE_CONTENT = buildGuideContent(LOCAL_GUIDE_DEPLOYMENT);
|
|
82962
|
+
var GUIDE_INDEX = buildGuideIndex(LOCAL_GUIDE_DEPLOYMENT);
|
|
82963
|
+
|
|
82964
|
+
// src/network-switch.ts
|
|
82965
|
+
var SWITCHABLE_NETWORKS = ["sepolia", "mainnet"];
|
|
82966
|
+
function createNetworkSwitchRuntime(opts) {
|
|
82967
|
+
return {
|
|
82968
|
+
current() {
|
|
82969
|
+
const b = opts.getBoot().boundaryResult;
|
|
82970
|
+
if (!b.ok) return null;
|
|
82971
|
+
const w = b.boundary.world();
|
|
82972
|
+
return { network: w.network, chainId: w.chainId, practiceWorld: w.practiceWorld };
|
|
82973
|
+
},
|
|
82974
|
+
async switchTo(network) {
|
|
82975
|
+
const allowed = opts.overrides?.allowedNetworks;
|
|
82976
|
+
if (allowed && !allowed.includes(network)) {
|
|
82977
|
+
return {
|
|
82978
|
+
ok: false,
|
|
82979
|
+
error: boundaryError(
|
|
82980
|
+
"VALIDATION_FAILED",
|
|
82981
|
+
`this deployment serves ${allowed.join(", ")} \u2014 '${network}' is not enabled on this service. Mainnet service enablement is a rollout step of the deployment, not a session setting.`
|
|
82982
|
+
)
|
|
82983
|
+
};
|
|
82984
|
+
}
|
|
82985
|
+
const targetEnv = { ...opts.env, DH_NETWORK: network };
|
|
82986
|
+
const configResult = resolveBoundaryConfig(targetEnv);
|
|
82987
|
+
if (!configResult.ok) return { ok: false, error: configResult.error };
|
|
82988
|
+
const next = await buildBoundary(configResult, opts.overrides);
|
|
82989
|
+
if (!next.boundaryResult.ok) {
|
|
82990
|
+
next.dispose();
|
|
82991
|
+
return { ok: false, error: next.boundaryResult.error };
|
|
82992
|
+
}
|
|
82993
|
+
opts.swap(next);
|
|
82994
|
+
return { ok: true };
|
|
82995
|
+
}
|
|
82996
|
+
};
|
|
82997
|
+
}
|
|
82998
|
+
function guideDeployment(overrides) {
|
|
82999
|
+
return {
|
|
83000
|
+
tier: overrides?.bridgeMount ? "hosted" : "local",
|
|
83001
|
+
networks: overrides?.allowedNetworks ?? LOCAL_GUIDE_DEPLOYMENT.networks,
|
|
83002
|
+
signerModes: overrides?.externalOnly ? EXTERNAL_ONLY_SIGNER_MODES : LOCAL_GUIDE_DEPLOYMENT.signerModes
|
|
83003
|
+
};
|
|
83004
|
+
}
|
|
83005
|
+
function assembleWorld(opts) {
|
|
83006
|
+
let boot = opts.boot;
|
|
83007
|
+
const deps = {
|
|
83008
|
+
boundaryResult: boot.boundaryResult,
|
|
83009
|
+
...boot.mockControl ? { mockControl: boot.mockControl } : {},
|
|
83010
|
+
...boot.signer ? { signer: boot.signer } : {},
|
|
83011
|
+
...opts.overrides?.externalOnly ? { externalOnly: true } : {},
|
|
83012
|
+
deployment: guideDeployment(opts.overrides),
|
|
83013
|
+
...opts.configResult.ok && opts.configResult.config.adapter === "mock" && opts.configResult.config.chainId ? { chainId: opts.configResult.config.chainId } : {}
|
|
83014
|
+
};
|
|
83015
|
+
if ((opts.env["DH_ADAPTER"] ?? "real") !== "mock") {
|
|
83016
|
+
deps.networkSwitch = createNetworkSwitchRuntime({
|
|
83017
|
+
env: opts.env,
|
|
83018
|
+
getBoot: () => boot,
|
|
83019
|
+
...opts.overrides ? { overrides: opts.overrides } : {},
|
|
83020
|
+
swap: (next) => {
|
|
83021
|
+
const old = boot;
|
|
83022
|
+
boot = next;
|
|
83023
|
+
deps.boundaryResult = next.boundaryResult;
|
|
83024
|
+
if (next.signer) deps.signer = next.signer;
|
|
83025
|
+
else delete deps.signer;
|
|
83026
|
+
old.dispose();
|
|
83027
|
+
const w = next.boundaryResult.ok ? next.boundaryResult.boundary.world() : null;
|
|
83028
|
+
opts.log?.(`network switched \u2014 now ${w ? `${w.network} (chainId ${w.chainId})` : "unavailable"}.`);
|
|
83029
|
+
}
|
|
83030
|
+
});
|
|
83031
|
+
}
|
|
83032
|
+
return { deps, dispose: () => boot.dispose() };
|
|
83033
|
+
}
|
|
83034
|
+
|
|
83035
|
+
// src/server.ts
|
|
83036
|
+
var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
83037
|
+
|
|
83038
|
+
// src/tools/loan.ts
|
|
83039
|
+
var import_zod = require("zod");
|
|
83040
|
+
var import_ethers40 = require("ethers");
|
|
83041
|
+
|
|
83042
|
+
// src/util/format.ts
|
|
83043
|
+
function bigintReplacer(_key, value) {
|
|
83044
|
+
if (typeof value === "bigint") return value.toString();
|
|
83045
|
+
return value;
|
|
83046
|
+
}
|
|
83047
|
+
function serialize(data) {
|
|
83048
|
+
return JSON.stringify(data, bigintReplacer, 2);
|
|
83049
|
+
}
|
|
83050
|
+
|
|
83051
|
+
// src/tools/_helpers.ts
|
|
83052
|
+
function registerBoundaryTool(server, name, config, handler) {
|
|
83053
|
+
server.registerTool(name, config, handler);
|
|
83054
|
+
}
|
|
83055
|
+
function renderError(error) {
|
|
83056
|
+
const lines = [`ERROR [${error.code}]: ${error.message}`];
|
|
83057
|
+
if (error.source) lines.push(`source: ${error.source}`);
|
|
83058
|
+
return { content: [{ type: "text", text: lines.join("\n") }], isError: true };
|
|
83059
|
+
}
|
|
83060
|
+
function renderEnvelope(env) {
|
|
83061
|
+
if (!env.ok) return renderError(env.error);
|
|
83062
|
+
const parts = [serialize(env.data)];
|
|
83063
|
+
if (env.warnings.length > 0) {
|
|
83064
|
+
parts.push(
|
|
83065
|
+
"WARNINGS:\n" + env.warnings.map((w) => `- [${w.code}] ${w.message} (sources: ${w.sources.join(", ")})`).join("\n")
|
|
83066
|
+
);
|
|
83067
|
+
}
|
|
83068
|
+
parts.push(`source: ${env.source.id} (${env.source.kind}) @ ${env.source.fetchedAt}`);
|
|
83069
|
+
return { content: [{ type: "text", text: parts.join("\n\n") }] };
|
|
83070
|
+
}
|
|
83071
|
+
function validationFailed(problem) {
|
|
83072
|
+
return renderError(boundaryError("VALIDATION_FAILED", problem));
|
|
83073
|
+
}
|
|
83074
|
+
function resourceJson(env) {
|
|
83075
|
+
if (!env.ok) return serialize({ error: env.error });
|
|
83076
|
+
return serialize({ data: env.data, warnings: env.warnings, source: env.source });
|
|
83077
|
+
}
|
|
83078
|
+
function resourceErrorJson(error) {
|
|
83079
|
+
return serialize({ error });
|
|
83080
|
+
}
|
|
83081
|
+
function requireConfirmation(confirmed, actionLabel) {
|
|
83082
|
+
if (confirmed === true) return null;
|
|
83083
|
+
return {
|
|
83084
|
+
content: [
|
|
83085
|
+
{
|
|
83086
|
+
type: "text",
|
|
83087
|
+
text: `CONFIRMATION REQUIRED \u2014 refusing to run "${actionLabel}".
|
|
83088
|
+
This is an irreversible, fund-moving action. A human must explicitly authorize it.
|
|
83089
|
+
Re-invoke with confirmed: true ONLY after a human has approved this exact operation. Do not set confirmed on your own.`
|
|
83090
|
+
}
|
|
83091
|
+
],
|
|
83092
|
+
isError: true
|
|
83093
|
+
};
|
|
83094
|
+
}
|
|
83095
|
+
function envStamp(b) {
|
|
83096
|
+
if (!b.ok) return "environment: UNKNOWN \u2014 boundary unavailable";
|
|
83097
|
+
const w = b.boundary.world();
|
|
83098
|
+
const money = w.network === "mainnet" ? "REAL MONEY" : w.network === "mock" ? "PRACTICE SANDBOX (no real money)" : "PRACTICE FUNDS (test network)";
|
|
83099
|
+
return `environment: ${w.network} \u2014 ${money}`;
|
|
83100
|
+
}
|
|
83101
|
+
async function guardedWrite(getB, fn) {
|
|
83102
|
+
const result = await guarded(fn);
|
|
83103
|
+
const stamp = envStamp(getB());
|
|
83104
|
+
const content = result.content.map(
|
|
83105
|
+
(c, i) => i === result.content.length - 1 ? { ...c, text: `${c.text}
|
|
83106
|
+
|
|
83107
|
+
${stamp}` } : c
|
|
83108
|
+
);
|
|
83109
|
+
return { ...result, content };
|
|
83110
|
+
}
|
|
83111
|
+
async function guarded(fn) {
|
|
83112
|
+
try {
|
|
83113
|
+
return await fn();
|
|
83114
|
+
} catch (e) {
|
|
83115
|
+
return renderError(
|
|
83116
|
+
boundaryError("INTERNAL", `Internal boundary fault: ${e.message}`, {
|
|
83117
|
+
details: { stack: e.stack }
|
|
83118
|
+
})
|
|
83119
|
+
);
|
|
83120
|
+
}
|
|
83121
|
+
}
|
|
83122
|
+
|
|
83123
|
+
// src/util/validate.ts
|
|
83124
|
+
var POSITION_ID_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
83125
|
+
var SATS_SANITY_CAP = 1e10;
|
|
83126
|
+
var UCD_SANITY_CAP = 1e9;
|
|
83127
|
+
function checkPositionIdHex(id, label = "Position ID") {
|
|
83128
|
+
if (!POSITION_ID_RE.test(id)) {
|
|
83129
|
+
return `${label} must be 0x-prefixed 32-byte hex (got '${id}').`;
|
|
83130
|
+
}
|
|
83131
|
+
return null;
|
|
83132
|
+
}
|
|
83133
|
+
function checkUcdAmount(amount, label = "Amount") {
|
|
83134
|
+
if (!Number.isFinite(amount) || amount <= 0) {
|
|
83135
|
+
return `${label} must be a positive finite number (got ${amount}).`;
|
|
83136
|
+
}
|
|
83137
|
+
if (amount > UCD_SANITY_CAP) {
|
|
83138
|
+
return `${label} ${amount} exceeds the ${UCD_SANITY_CAP.toLocaleString()} UCD sanity cap.`;
|
|
83139
|
+
}
|
|
83140
|
+
if (amount > 0 && amount < 1e-6) {
|
|
83141
|
+
return `${label} ${amount} has more than 6 decimals of precision \u2014 likely a typo.`;
|
|
83142
|
+
}
|
|
83143
|
+
const decimals = amount.toString().split(".")[1];
|
|
83144
|
+
if (decimals && decimals.length > 6) {
|
|
83145
|
+
return `${label} ${amount} has more than 6 decimals of precision \u2014 likely a typo.`;
|
|
83146
|
+
}
|
|
83147
|
+
return null;
|
|
83148
|
+
}
|
|
83149
|
+
function checkSatsAmount(sats, label = "Amount") {
|
|
83150
|
+
if (!Number.isInteger(sats) || sats <= 0) {
|
|
83151
|
+
return `${label} must be a positive integer (satoshis), got ${sats}.`;
|
|
83152
|
+
}
|
|
83153
|
+
if (sats > SATS_SANITY_CAP) {
|
|
83154
|
+
return `${label} ${sats} sats exceeds the 100 BTC sanity cap.`;
|
|
83155
|
+
}
|
|
83156
|
+
return null;
|
|
83157
|
+
}
|
|
83158
|
+
function checkSelectedTerm(months, label = "Term") {
|
|
83159
|
+
if (!Number.isInteger(months) || months <= 0) {
|
|
83160
|
+
return `${label} must be a positive integer (months), got ${months}.`;
|
|
83161
|
+
}
|
|
83162
|
+
if (months > 120) {
|
|
83163
|
+
return `${label} ${months} months exceeds the 10-year sanity cap.`;
|
|
83164
|
+
}
|
|
83165
|
+
return null;
|
|
83166
|
+
}
|
|
83167
|
+
|
|
83168
|
+
// src/tools/loan.ts
|
|
83169
|
+
var LATENCY_NOTES = {
|
|
83170
|
+
mock: "Instant in this practice world.",
|
|
83171
|
+
real: "May take 60\u201390 seconds against the live protocol (LIT Action invocation)."
|
|
83172
|
+
};
|
|
83173
|
+
var positionIdSchema = import_zod.z.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be 0x-prefixed 32-byte hex");
|
|
83174
|
+
var confirmedSchema = import_zod.z.boolean().optional().describe(
|
|
83175
|
+
"Human authorization gate \u2014 must be set to true by a HUMAN (not the model) to execute this irreversible action."
|
|
83176
|
+
);
|
|
83177
|
+
var DESTRUCTIVE_WRITE_ANNOTATIONS = {
|
|
83178
|
+
readOnlyHint: false,
|
|
83179
|
+
destructiveHint: true,
|
|
83180
|
+
idempotentHint: false,
|
|
83181
|
+
openWorldHint: true
|
|
83182
|
+
};
|
|
83183
|
+
function registerLoanTools(server, getB, adapter2 = "real") {
|
|
83184
|
+
const LATENCY_NOTE = LATENCY_NOTES[adapter2];
|
|
83185
|
+
registerBoundaryTool(
|
|
83186
|
+
server,
|
|
83187
|
+
"loan_create",
|
|
83188
|
+
{
|
|
83189
|
+
title: "Create a new lending position",
|
|
83190
|
+
description: `Mint a new PKP, create a Bitcoin custody vault, and register a new lending position with the given term. ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
83191
|
+
inputSchema: {
|
|
83192
|
+
selectedTerm: import_zod.z.number().int().positive().describe("Loan term in months (e.g. 3, 6, 12, 24)"),
|
|
83193
|
+
confirmed: confirmedSchema
|
|
83194
|
+
},
|
|
83195
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83196
|
+
},
|
|
83197
|
+
async ({ selectedTerm, confirmed }) => guardedWrite(getB, async () => {
|
|
83198
|
+
const gate = requireConfirmation(confirmed, `create a ${selectedTerm}-month lending position`);
|
|
83199
|
+
if (gate) return gate;
|
|
83200
|
+
const problem = checkSelectedTerm(selectedTerm);
|
|
83201
|
+
if (problem) return validationFailed(problem);
|
|
83202
|
+
const b = getB();
|
|
83203
|
+
if (!b.ok) return renderError(b.error);
|
|
83204
|
+
return renderEnvelope(await b.boundary.createPosition({ selectedTerm }));
|
|
83205
|
+
})
|
|
83206
|
+
);
|
|
83207
|
+
registerBoundaryTool(
|
|
83208
|
+
server,
|
|
83209
|
+
"loan_mint",
|
|
83210
|
+
{
|
|
83211
|
+
title: "Mint UCD against a position",
|
|
83212
|
+
description: `Mint (borrow) UCD against an existing lending position's BTC collateral. The origination fee is ADDED TO YOUR DEBT \u2014 you receive the full amount, you owe amount + fee. Ceiling: position_status \u2192 valuation.maxMintableUcd (directly usable as amountUcd). ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
83213
|
+
inputSchema: {
|
|
83214
|
+
positionId: positionIdSchema,
|
|
83215
|
+
amountUcd: import_zod.z.number().positive().describe("Amount of UCD to mint"),
|
|
83216
|
+
confirmed: confirmedSchema
|
|
83217
|
+
},
|
|
83218
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83219
|
+
},
|
|
83220
|
+
async ({ positionId, amountUcd, confirmed }) => guardedWrite(getB, async () => {
|
|
83221
|
+
const gate = requireConfirmation(confirmed, `mint ${amountUcd} UCD against position ${positionId}`);
|
|
83222
|
+
if (gate) return gate;
|
|
83223
|
+
const problem = checkPositionIdHex(positionId) ?? checkUcdAmount(amountUcd);
|
|
83224
|
+
if (problem) return validationFailed(problem);
|
|
83225
|
+
const b = getB();
|
|
83226
|
+
if (!b.ok) return renderError(b.error);
|
|
83227
|
+
return renderEnvelope(
|
|
83228
|
+
await b.boundary.mintUcd({ positionId, amountUcdWei: (0, import_ethers40.parseEther)(amountUcd.toString()).toString() })
|
|
83229
|
+
);
|
|
83230
|
+
})
|
|
83231
|
+
);
|
|
83232
|
+
registerBoundaryTool(
|
|
83233
|
+
server,
|
|
83234
|
+
"loan_pay",
|
|
83235
|
+
{
|
|
83236
|
+
title: "Make a UCD payment toward a position's debt",
|
|
83237
|
+
description: `Repay (partial or full) a position's UCD debt. Moves UCD out of your wallet (irreversible). To pay off EVERYTHING exactly \u2014 including dust smaller than the 6-decimal input allows \u2014 pass repayAll: true instead of amountUcd (fleet finding: debt can carry more precision than amountUcd accepts). ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
83238
|
+
inputSchema: {
|
|
83239
|
+
positionId: positionIdSchema,
|
|
83240
|
+
amountUcd: import_zod.z.number().positive().optional().describe("Amount of UCD to repay (max 6 decimals; omit when repayAll)"),
|
|
83241
|
+
repayAll: import_zod.z.boolean().optional().describe("true = repay the position's EXACT outstanding debt (wei-precise)"),
|
|
83242
|
+
confirmed: confirmedSchema
|
|
83243
|
+
},
|
|
83244
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83245
|
+
},
|
|
83246
|
+
async ({ positionId, amountUcd, repayAll, confirmed }) => guardedWrite(getB, async () => {
|
|
83247
|
+
if (repayAll === true === (amountUcd !== void 0)) {
|
|
83248
|
+
return validationFailed("provide exactly one of amountUcd or repayAll: true");
|
|
83249
|
+
}
|
|
83250
|
+
const gate = requireConfirmation(
|
|
83251
|
+
confirmed,
|
|
83252
|
+
repayAll ? `repay the ENTIRE outstanding debt of position ${positionId}` : `repay ${amountUcd} UCD toward position ${positionId}`
|
|
83253
|
+
);
|
|
83254
|
+
if (gate) return gate;
|
|
83255
|
+
const problem = checkPositionIdHex(positionId) ?? (repayAll ? null : checkUcdAmount(amountUcd, "Payment amount"));
|
|
83256
|
+
if (problem) return validationFailed(problem);
|
|
83257
|
+
const b = getB();
|
|
83258
|
+
if (!b.ok) return renderError(b.error);
|
|
83259
|
+
let amountUcdWei;
|
|
83260
|
+
if (repayAll) {
|
|
83261
|
+
const detail = await b.boundary.getPosition(positionId);
|
|
83262
|
+
if (!detail.ok) return renderError(detail.error);
|
|
83263
|
+
if (BigInt(detail.data.debtUcdWei) === 0n) return validationFailed("the position has no outstanding debt");
|
|
83264
|
+
amountUcdWei = detail.data.debtUcdWei;
|
|
83265
|
+
} else {
|
|
83266
|
+
amountUcdWei = (0, import_ethers40.parseEther)(amountUcd.toString()).toString();
|
|
83267
|
+
}
|
|
83268
|
+
return renderEnvelope(await b.boundary.repayUcd({ positionId, amountUcdWei }));
|
|
83269
|
+
})
|
|
83270
|
+
);
|
|
83271
|
+
registerBoundaryTool(
|
|
83272
|
+
server,
|
|
83273
|
+
"loan_extend",
|
|
83274
|
+
{
|
|
83275
|
+
title: "Extend / renew a position's term",
|
|
83276
|
+
description: `ADDS selectedTerm onto the position's CURRENT expiry (12 months = exactly 365 days; any other term = N \xD7 30-day months) \u2014 never replaces or shortens it. Only available in the FINAL 30 DAYS of the current term, and refused if the remaining runway would exceed 2\xD7 the new term. (Per-network caveat: some DEPLOYED contracts predate this window/runway rule \u2014 a live extend may execute from now rather than refuse; the MCP reports the on-chain result truthfully.) Fee: ADDED TO YOUR DEBT (your wallet is not charged), at most the term's extension fee rate \xD7 your current debt (see protocol_terms; a flat rate per renewal, not per month), reduced by origination fees already paid this term. Only an ACTIVE position can be renewed. Irreversible on-chain write. ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
83277
|
+
inputSchema: {
|
|
83278
|
+
positionId: positionIdSchema,
|
|
83279
|
+
selectedTerm: import_zod.z.number().int().positive().describe("Months to ADD to the current expiry (must be an offered term: see protocol_terms)"),
|
|
83280
|
+
confirmed: confirmedSchema
|
|
83281
|
+
},
|
|
83282
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83283
|
+
},
|
|
83284
|
+
async ({ positionId, selectedTerm, confirmed }) => guardedWrite(getB, async () => {
|
|
83285
|
+
const gate = requireConfirmation(confirmed, `renew position ${positionId} for a ${selectedTerm}-month term`);
|
|
83286
|
+
if (gate) return gate;
|
|
83287
|
+
const problem = checkPositionIdHex(positionId) ?? checkSelectedTerm(selectedTerm);
|
|
83288
|
+
if (problem) return validationFailed(problem);
|
|
83289
|
+
const b = getB();
|
|
83290
|
+
if (!b.ok) return renderError(b.error);
|
|
83291
|
+
return renderEnvelope(await b.boundary.extendPosition({ positionId, selectedTerm }));
|
|
83292
|
+
})
|
|
83293
|
+
);
|
|
83294
|
+
registerBoundaryTool(
|
|
83295
|
+
server,
|
|
83296
|
+
"loan_withdraw",
|
|
83297
|
+
{
|
|
83298
|
+
title: "Withdraw BTC from a position vault",
|
|
83299
|
+
description: `Withdraw BTC from a position's custody vault to an external BTC address. BTC sends are UNRECOVERABLE \u2014 verify the destination address carefully. Result identifiers: txid (and txRef.id) is the Bitcoin transaction of the withdrawal reservation; authorization.digest is the borrower wallet's signature over the approval \u2014 they are different things. ${LATENCY_NOTE} Requires human confirmation (confirmed: true).`,
|
|
83300
|
+
inputSchema: {
|
|
83301
|
+
positionId: positionIdSchema,
|
|
83302
|
+
btcAddress: import_zod.z.string().min(1).describe("Destination BTC address (must match the configured BTC network)"),
|
|
83303
|
+
amountSats: import_zod.z.number().int().positive().describe(
|
|
83304
|
+
"GROSS amount in satoshis committed from the vault (1 BTC = 100,000,000 sats). The destination receives amountSats \u2212 networkFeeSats; the vault's available drops by amountSats. amountSats may be up to the whole available balance (a full sweep leaves 0 sats; anything above available reverts TargetExceedsInputValue). position_status.maxWithdrawableSats is a ready-to-use value that already leaves the default fee aside."
|
|
83305
|
+
),
|
|
83306
|
+
networkFeeSats: import_zod.z.number().int().positive().default(1e3).describe("BTC network fee in sats (declared default 1000); deducted FROM amountSats, not added on top"),
|
|
83307
|
+
confirmed: confirmedSchema
|
|
83308
|
+
},
|
|
83309
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83310
|
+
},
|
|
83311
|
+
async ({ positionId, btcAddress: btcAddress2, amountSats, networkFeeSats, confirmed }) => guardedWrite(getB, async () => {
|
|
83312
|
+
const gate = requireConfirmation(
|
|
83313
|
+
confirmed,
|
|
83314
|
+
`withdraw ${amountSats} sats from position ${positionId} to ${btcAddress2} (UNRECOVERABLE)`
|
|
83315
|
+
);
|
|
83316
|
+
if (gate) return gate;
|
|
83317
|
+
const problem = checkPositionIdHex(positionId) ?? checkSatsAmount(amountSats) ?? checkSatsAmount(networkFeeSats, "Network fee");
|
|
83318
|
+
if (problem) return validationFailed(problem);
|
|
83319
|
+
const b = getB();
|
|
83320
|
+
if (!b.ok) return renderError(b.error);
|
|
83321
|
+
return renderEnvelope(await b.boundary.withdrawBtc({ positionId, btcAddress: btcAddress2, amountSats, networkFeeSats }));
|
|
83322
|
+
})
|
|
83323
|
+
);
|
|
83324
|
+
registerBoundaryTool(
|
|
83325
|
+
server,
|
|
83326
|
+
"loan_allowlist_destination",
|
|
83327
|
+
{
|
|
83328
|
+
title: "Allowlist a BTC withdrawal destination",
|
|
83329
|
+
description: `Add a BTC address to the borrower's withdrawal allowlist (BitcoinWithdrawalAddressRegistry). The protocol refuses withdrawBTC to any destination not on the borrower's own allowlist. For a SAFE borrower this is itself a Safe transaction \u2014 owner signatures are collected, and owners can sign at their leisure (no expiry on this ceremony). The destination becomes usable after the registry's address delay, read LIVE from the contract at execution \u2014 the result's usableAtSec is the chain-derived moment it becomes usable (never assume a fixed delay). Requires human confirmation (confirmed: true).`,
|
|
83330
|
+
inputSchema: {
|
|
83331
|
+
btcAddress: import_zod.z.string().min(1).describe("Destination BTC address to allowlist (must match the configured BTC network)"),
|
|
83332
|
+
confirmed: confirmedSchema
|
|
83333
|
+
},
|
|
83334
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83335
|
+
},
|
|
83336
|
+
async ({ btcAddress: btcAddress2, confirmed }) => guardedWrite(getB, async () => {
|
|
83337
|
+
const gate = requireConfirmation(confirmed, `allowlist ${btcAddress2} as a BTC withdrawal destination`);
|
|
83338
|
+
if (gate) return gate;
|
|
83339
|
+
const b = getB();
|
|
83340
|
+
if (!b.ok) return renderError(b.error);
|
|
83341
|
+
return renderEnvelope(await b.boundary.allowlistWithdrawalAddress({ btcAddress: btcAddress2 }));
|
|
83342
|
+
})
|
|
83343
|
+
);
|
|
83344
|
+
registerBoundaryTool(
|
|
83345
|
+
server,
|
|
83346
|
+
"loan_delegation_setup",
|
|
83347
|
+
{
|
|
83348
|
+
title: "Install delegation on the Safe (one owner ceremony)",
|
|
83349
|
+
description: `The ONE-TIME Safe delegation batch (signer mode 'safe-module'): your owners sign a single durable Safe transaction \u2014 at their leisure, no time window \u2014 that enables the Safe's AgentModule, binds the agent key, registers it in the delegation registry, and pre-approves the given BTC withdrawal destinations. After it, day-to-day operations (create/mint/pay/extend) run agent-solo; withdrawals always still need the owners' short signing burst, and only to destinations approved here (or later via loan_allowlist_destination \u2014 also owners-only). A revoked agent address burns FOREVER (AR-1) \u2014 rotation means a fresh key. Requires human confirmation (confirmed: true).`,
|
|
83350
|
+
inputSchema: {
|
|
83351
|
+
btcAddresses: import_zod.z.array(import_zod.z.string().min(1)).describe("BTC withdrawal destinations to pre-approve in the same ceremony (avoids a second owner gathering before the first withdrawal)"),
|
|
83352
|
+
confirmed: confirmedSchema
|
|
83353
|
+
},
|
|
83354
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83355
|
+
},
|
|
83356
|
+
async ({ btcAddresses, confirmed }) => guardedWrite(getB, async () => {
|
|
83357
|
+
const gate = requireConfirmation(confirmed, `install delegation (module + agent + ${btcAddresses.length} destination(s))`);
|
|
83358
|
+
if (gate) return gate;
|
|
83359
|
+
const b = getB();
|
|
83360
|
+
if (!b.ok) return renderError(b.error);
|
|
83361
|
+
return renderEnvelope(await b.boundary.delegationSetup({ btcAddresses }));
|
|
83362
|
+
})
|
|
83363
|
+
);
|
|
83364
|
+
registerBoundaryTool(
|
|
83365
|
+
server,
|
|
83366
|
+
"loan_delegation_grant",
|
|
83367
|
+
{
|
|
83368
|
+
title: "Grant the agent per-position scopes (owners sign)",
|
|
83369
|
+
description: `Set what the delegated agent may do on ONE position \u2014 RENEW (extend), REPAY (pay down), MINT (borrow, only while the post-mint collateral ratio stays at or above mintFloorBps \u2014 required for MINT, it is the owners' risk bound). Grants are user-only expansion: for a Safe this is a QUORUM signature (durable Safe transaction, owners sign at leisure) \u2014 the agent can never widen its own powers. Omitting a scope leaves it un-granted; a grant with no scopes clears the position's grant. Requires human confirmation (confirmed: true).`,
|
|
83370
|
+
inputSchema: {
|
|
83371
|
+
positionId: positionIdSchema,
|
|
83372
|
+
renew: import_zod.z.boolean().optional().describe("Allow the agent to extend/renew this position"),
|
|
83373
|
+
repay: import_zod.z.boolean().optional().describe("Allow the agent to pay down this position's debt"),
|
|
83374
|
+
mintFloorBps: import_zod.z.number().int().positive().optional().describe("Allow MINT while post-mint CR \u2265 this floor (bps, e.g. 15000 = 150%) \u2014 required for the MINT scope"),
|
|
83375
|
+
confirmed: confirmedSchema
|
|
83376
|
+
},
|
|
83377
|
+
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
83378
|
+
},
|
|
83379
|
+
async ({ positionId, renew, repay, mintFloorBps, confirmed }) => guardedWrite(getB, async () => {
|
|
83380
|
+
const gate = requireConfirmation(confirmed, `grant agent scopes on ${positionId}`);
|
|
83381
|
+
if (gate) return gate;
|
|
83382
|
+
const b = getB();
|
|
83383
|
+
if (!b.ok) return renderError(b.error);
|
|
83384
|
+
return renderEnvelope(
|
|
83385
|
+
await b.boundary.delegationGrant({
|
|
83386
|
+
positionId,
|
|
83387
|
+
renew: renew ?? false,
|
|
83388
|
+
repay: repay ?? false,
|
|
83389
|
+
mintFloorBps: mintFloorBps ?? null
|
|
83390
|
+
})
|
|
83391
|
+
);
|
|
83392
|
+
})
|
|
83393
|
+
);
|
|
83394
|
+
registerBoundaryTool(
|
|
83395
|
+
server,
|
|
83396
|
+
"loan_recover_stale_spend",
|
|
83397
|
+
{
|
|
83398
|
+
title: "Recover a stale BTC reservation via LIT-attested proof",
|
|
83399
|
+
description: "Clear a stale authorized BTC spend on BTCSpendAuthorizer using a LIT-attested StaleSpendRecovery attestation. The original UTXO must already be consumed on Bitcoin with \u22656 confirmations. `invalidatorTxid` is either the borrower's authorized broadcast (after confirmations) or a PKP self-spend that invalidated the reservation. Permissionless on-chain.",
|
|
83400
|
+
inputSchema: {
|
|
83401
|
+
positionId: positionIdSchema,
|
|
83402
|
+
utxoTxid: import_zod.z.string().describe("The original authorized UTXO's txid"),
|
|
83403
|
+
utxoVout: import_zod.z.number().int().nonnegative().describe("The original authorized UTXO's vout"),
|
|
83404
|
+
invalidatorTxid: import_zod.z.string().describe("Txid of the BTC transaction that consumed the original UTXO (\u22656 confirmations)"),
|
|
83405
|
+
minConfirmations: import_zod.z.number().int().positive().optional().describe("Override minimum confirmations (default 6)")
|
|
83406
|
+
},
|
|
83407
|
+
annotations: {
|
|
83408
|
+
readOnlyHint: false,
|
|
83409
|
+
destructiveHint: false,
|
|
83410
|
+
idempotentHint: true,
|
|
83411
|
+
openWorldHint: true
|
|
83412
|
+
}
|
|
83413
|
+
},
|
|
83414
|
+
async ({ positionId, utxoTxid, utxoVout, invalidatorTxid, minConfirmations }) => guardedWrite(getB, async () => {
|
|
83415
|
+
const problem = checkPositionIdHex(positionId);
|
|
83416
|
+
if (problem) return validationFailed(problem);
|
|
83417
|
+
const b = getB();
|
|
83418
|
+
if (!b.ok) return renderError(b.error);
|
|
83419
|
+
return renderEnvelope(
|
|
83420
|
+
await b.boundary.recoverStaleSpend({
|
|
83421
|
+
positionId,
|
|
83422
|
+
utxoTxid,
|
|
83423
|
+
utxoVout,
|
|
83424
|
+
invalidatorTxid,
|
|
83425
|
+
...minConfirmations !== void 0 ? { minConfirmations } : {}
|
|
83426
|
+
})
|
|
83427
|
+
);
|
|
83428
|
+
})
|
|
83429
|
+
);
|
|
83430
|
+
}
|
|
83431
|
+
|
|
82562
83432
|
// src/tools/position.ts
|
|
83433
|
+
var import_zod2 = require("zod");
|
|
82563
83434
|
var positionIdSchema2 = import_zod2.z.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be 0x-prefixed 32-byte hex");
|
|
82564
83435
|
var POSITION_STATES = [
|
|
82565
83436
|
"PENDING_DEPOSIT",
|
|
@@ -83116,547 +83987,9 @@ function ok(data) {
|
|
|
83116
83987
|
|
|
83117
83988
|
// src/tools/guide.ts
|
|
83118
83989
|
var import_zod7 = require("zod");
|
|
83119
|
-
|
|
83120
|
-
|
|
83121
|
-
|
|
83122
|
-
"getting-started",
|
|
83123
|
-
"first-setup",
|
|
83124
|
-
"connect-wallet",
|
|
83125
|
-
"lifecycle",
|
|
83126
|
-
"fees",
|
|
83127
|
-
"psm",
|
|
83128
|
-
"authorization",
|
|
83129
|
-
"safe",
|
|
83130
|
-
"delegation",
|
|
83131
|
-
"safety",
|
|
83132
|
-
"switch-network",
|
|
83133
|
-
"connector",
|
|
83134
|
-
"troubleshooting",
|
|
83135
|
-
"glossary",
|
|
83136
|
-
"reading-data"
|
|
83137
|
-
];
|
|
83138
|
-
var GUIDE_CONTENT = {
|
|
83139
|
-
"getting-started": `# Diamond Hands \u2014 what this is
|
|
83140
|
-
|
|
83141
|
-
Diamond Hands lets you BORROW a dollar-pegged token (UCD) against your own BITCOIN,
|
|
83142
|
-
without selling it. Your BTC sits in a custody vault tied to your position; you mint UCD
|
|
83143
|
-
against it, pay it back whenever you like, and take your BTC out again.
|
|
83144
|
-
|
|
83145
|
-
**Agent instructions:** answer in the USER'S language, map their words via the \`glossary\`
|
|
83146
|
-
topic, and always say plainly whether this session is PRACTICE or REAL MONEY. Read the
|
|
83147
|
-
\`capabilities\` block in \`boundary://info\` FIRST \u2014 it states the network, whether writes
|
|
83148
|
-
are enabled (and the true reason when not), and which signer modes this build offers;
|
|
83149
|
-
never promise a capability it does not list. The money truth has THREE cases:
|
|
83150
|
-
- Adapter \`mock\` \u2014 a PRACTICE sandbox. No real money anywhere.
|
|
83151
|
-
- Adapter \`real\` on SEPOLIA (the zero-config default) \u2014 the REAL protocol contracts on
|
|
83152
|
-
the test network: real ceremonies and signatures, PRACTICE money (test funds).
|
|
83153
|
-
- Adapter \`real\` on MAINNET \u2014 REAL MONEY. Writes are disabled unless the operator
|
|
83154
|
-
explicitly arms them; the capabilities block states which applies.
|
|
83155
|
-
SAY THIS EARLY AND UNPROMPTED \u2014 users must never wonder whether money is real.
|
|
83156
|
-
|
|
83157
|
-
A first conversation usually goes: explain this page \u2192 \`guide first-setup\` (choose how to
|
|
83158
|
-
authorize) \u2192 create a position \u2192 deposit BTC \u2192 mint. The \`lifecycle\` topic has the exact
|
|
83159
|
-
calls. Every operation that moves funds requires the user's explicit confirmation
|
|
83160
|
-
(\`confirmed: true\`) \u2014 nothing is ever silent.`,
|
|
83161
|
-
"first-setup": `# First setup \u2014 from zero to ready, by conversation only
|
|
83162
|
-
|
|
83163
|
-
Installing on another machine? Three paths, by machine: Claude Desktop on macOS/Windows
|
|
83164
|
-
\u2192 the \`.mcpb\` bundle from the releases page (no Node needed); Linux or any other MCP
|
|
83165
|
-
host \u2192 the one-line installer (self-contained binary, prints the exact config snippet);
|
|
83166
|
-
developers with Node \u2265 18 on PATH \u2192 \`npx -y @gvnrdao/dh-mcp\`. Details: the README
|
|
83167
|
-
install matrix. (A fourth, zero-install path \u2014 the claude.ai connector \u2014 is implemented
|
|
83168
|
-
but NOT yet publicly served; its rollout is operator-gated. Truth and trust model:
|
|
83169
|
-
\`guide connector\`.)
|
|
83170
|
-
|
|
83171
|
-
Nothing needs a config file. Three steps:
|
|
83172
|
-
|
|
83173
|
-
**1. Know your world.** Read \`boundary://info\` (its \`capabilities\` block) and
|
|
83174
|
-
\`protocol_status\`, then tell the user: practice (mock) or real adapter; sepolia
|
|
83175
|
-
(practice money) or mainnet (real money); whether writes are enabled here and which
|
|
83176
|
-
signer modes exist; current terms (\`protocol_terms\`).
|
|
83177
|
-
|
|
83178
|
-
**2. Choose HOW to authorize operations** (the user's choice, made by talking):
|
|
83179
|
-
- **"Use my own wallet"** \u2192 call \`signer_setup\` action \`use\`, mode \`external\` \u2014 works
|
|
83180
|
-
on the real adapter and the mock. The approval page auto-opens in the browser (its URL
|
|
83181
|
-
is ALSO in the tool result); the user connects MetaMask \u2014 or scans the WalletConnect QR
|
|
83182
|
-
/ pastes the pairing code for a mobile wallet \u2014 and then APPROVES EACH OPERATION in
|
|
83183
|
-
their own wallet. The first verified signature binds their wallet address as the
|
|
83184
|
-
borrower. Full walkthrough: \`guide connect-wallet\`.
|
|
83185
|
-
- **"Sign automatically / no popups"** \u2192 mode \`keystore\`. A local encrypted keystore
|
|
83186
|
-
signs after each confirmation. Provision it via the env pair (\`DH_KEYSTORE_PATH\` +
|
|
83187
|
-
\`DH_KEYSTORE_PASSWORD\`), or call \`signer_setup\` action \`unlock-keystore\`: a SECURE
|
|
83188
|
-
LOCAL PAGE opens where the user types the password or generates a fresh keystore.
|
|
83189
|
-
NEVER ask for or accept a password in the conversation \u2014 if a user pastes one, tell
|
|
83190
|
-
them to use the unlock page instead.
|
|
83191
|
-
- **Safe / delegation modes (\`safe\`, \`safe-module\`) are PRACTICE-ONLY today** \u2014 on the
|
|
83192
|
-
real adapter they refuse with that true reason. Try them in a mock world.
|
|
83193
|
-
- Not sure? \`signer_setup\` action \`status\` explains what is active and what is missing.
|
|
83194
|
-
- **No signer is also a valid start:** every public read works without one \u2014
|
|
83195
|
-
\`position_list {borrower}\` with the user's address needs no signer and no login.
|
|
83196
|
-
- **Wrong network?** On the real adapter the user can switch sepolia \u2194 mainnet by
|
|
83197
|
-
talking (\`network_switch\`, human-confirmed) \u2014 see \`guide switch-network\`. State
|
|
83198
|
-
the money reality after any switch.
|
|
83199
|
-
|
|
83200
|
-
**3. First position.** \`loan_create\` with a term from \`protocol_terms\` (needs
|
|
83201
|
-
\`confirmed: true\` from the user). Then deposit BTC to the vault address
|
|
83202
|
-
(practice worlds: simulate it with \`mock_control\` \`submit-deposit\` + \`confirm-deposit\`),
|
|
83203
|
-
and mint with \`loan_mint\`.
|
|
83204
|
-
|
|
83205
|
-
The user can switch authorization modes at ANY time by saying so \u2014 repeat step 2.`,
|
|
83206
|
-
"connect-wallet": `# Connect your wallet \u2014 the external-signer walkthrough
|
|
83207
|
-
|
|
83208
|
-
External mode means the user approves every operation in their OWN wallet \u2014 a browser
|
|
83209
|
-
extension (MetaMask) or a WalletConnect mobile wallet. It works on the real adapter and
|
|
83210
|
-
the mock.
|
|
83211
|
-
|
|
83212
|
-
**The walkthrough:**
|
|
83213
|
-
1. \`signer_setup\` action \`use\`, mode \`external\`. The approval page auto-opens in the
|
|
83214
|
-
desktop browser; its URL is ALSO in the tool result (loopback-only \u2014 open it on the
|
|
83215
|
-
same machine the server runs on).
|
|
83216
|
-
2. On the page: connect the browser extension, or \u2014 for a mobile wallet \u2014 scan the
|
|
83217
|
-
WalletConnect QR code or paste the pairing code.
|
|
83218
|
-
3. For authenticated reads before any write: \`signer_setup\` action \`connect\` runs the
|
|
83219
|
-
login ceremony explicitly (one typed-data signature in the wallet).
|
|
83220
|
-
4. The FIRST verified signature binds that wallet address as the borrower \u2014 it persists
|
|
83221
|
-
across sessions (\`signer_setup reset-borrower\` unbinds it).
|
|
83222
|
-
5. From then on, every fund-moving operation shows an approval card in the wallet,
|
|
83223
|
-
decoded from the exact transaction bytes \u2014 what you read IS what executes. Declining
|
|
83224
|
-
always safely cancels.
|
|
83225
|
-
|
|
83226
|
-
**Popup cadence \u2014 exactly this many wallet interactions per operation:**
|
|
83227
|
-
|
|
83228
|
-
| Operation | Wallet interactions (external mode) |
|
|
83229
|
-
|---|---|
|
|
83230
|
-
| login (per login-session lifetime) | 1 typed-data |
|
|
83231
|
-
| create position | 1 tx (plus 1 login typed-data the first time \u2014 the protocol SDK keeps its own session) |
|
|
83232
|
-
| mint | 1 personal-sign + 1 tx |
|
|
83233
|
-
| repay | 1 personal-sign + 1-2 tx (UCD approve leg when the server returns one) |
|
|
83234
|
-
| extend | 1 personal-sign + 1 tx |
|
|
83235
|
-
| allowlist destination | 1 tx (plus 1 login typed-data the first time \u2014 same SDK session) |
|
|
83236
|
-
| withdraw BTC | not available in external mode yet (refuses with that reason); keystore mode works, no popups |
|
|
83237
|
-
| PSM swap/redeem | 2 tx (exact-amount approve + swap/redeem) |
|
|
83238
|
-
|
|
83239
|
-
**Honesty notes (say these plainly):**
|
|
83240
|
-
- **Reads never pop the wallet.** If a read needs a login the user does not have, the
|
|
83241
|
-
tool refuses legibly and the user says "connect my wallet" (\`signer_setup\` action
|
|
83242
|
-
\`connect\`). The wallet never appears unrequested.
|
|
83243
|
-
- **Logins expire.** When the session token dies mid-conversation, the next
|
|
83244
|
-
authenticated call refuses with the same remedy \u2014 an explicit reconnect, never a
|
|
83245
|
-
surprise popup. On mainnet the broker also throttles logins per address \u2014 a throttled
|
|
83246
|
-
login means "wait and retry", not a wallet failure.
|
|
83247
|
-
- **Withdraw-BTC under external mode is a BLIND signature** \u2014 the SDK builds the two
|
|
83248
|
-
withdrawal auth hashes internally, so the approval page shows the bare hash and says
|
|
83249
|
-
plainly it cannot decode the contents (the production web app signs the same way).
|
|
83250
|
-
Tell the user this before the popups: two hash signatures, then the BTC moves.
|
|
83251
|
-
- **The allowlist delay is read LIVE from the chain.** A new BTC withdrawal destination
|
|
83252
|
-
(\`loan_allowlist_destination\`) becomes usable only after the chain's own delay \u2014 24
|
|
83253
|
-
hours on mainnet, so allowlisting and withdrawing happen on DIFFERENT DAYS there. The
|
|
83254
|
-
card states the live figure.
|
|
83255
|
-
- **Mainnet:** every fund-moving operation spends REAL money, and the minimum mint is
|
|
83256
|
-
10 UCD.
|
|
83257
|
-
|
|
83258
|
-
**Disconnecting \u2014 "log out / sign out / forget my wallet" (\`signer_setup\` action
|
|
83259
|
-
\`disconnect\`):** the FULL wallet flush. It ends every approval-page session and any
|
|
83260
|
-
WalletConnect session (pending approvals are cancelled loudly), discards the login
|
|
83261
|
-
token from server memory AND revokes it at the service, and unbinds the borrower
|
|
83262
|
-
identity. Reconnecting afterwards ALWAYS requires opening the approval page again and
|
|
83263
|
-
a fresh wallet signature \u2014 a disconnect can never silently reconnect. Two truths to
|
|
83264
|
-
state: (1) \`reset-borrower\` is NOT a disconnect \u2014 it only swaps identity and leaves
|
|
83265
|
-
the connection and login alive; (2) no server can revoke the wallet's own site
|
|
83266
|
-
permission for the approval page \u2014 remove that inside the wallet (MetaMask: Settings \u2192
|
|
83267
|
-
Connections / Connected sites).`,
|
|
83268
|
-
lifecycle: `# The full lifecycle \u2014 exact calls
|
|
83269
|
-
|
|
83270
|
-
1. **Create** \u2014 \`loan_create {selectedTerm, confirmed:true}\` \u2192 position id, vault address.
|
|
83271
|
-
2. **Deposit BTC** \u2014 send BTC to the vault address; it becomes usable after the
|
|
83272
|
-
confirmation threshold (\`protocol_status.minConfirmations\`). Practice worlds:
|
|
83273
|
-
\`mock_control {action:"submit-deposit", positionId, sats}\` then
|
|
83274
|
-
\`{action:"confirm-deposit", txid, confirmations}\`.
|
|
83275
|
-
3. **Borrow (mint)** \u2014 \`loan_mint {positionId, amountUcd, confirmed:true}\`. Ceiling:
|
|
83276
|
-
\`position_status\` \u2192 \`valuation.maxMintableUcd\`. The origination fee is ADDED to debt.
|
|
83277
|
-
4. **Repay** \u2014 \`loan_pay {positionId, amountUcd, confirmed:true}\`. Fee-free, partial or
|
|
83278
|
-
full; full repayment moves the position to REPAID.
|
|
83279
|
-
5. **Extend (renew)** \u2014 \`loan_extend {positionId, selectedTerm, confirmed:true}\`, only
|
|
83280
|
-
within the FINAL 30 DAYS of the current term. The extension fee is ADDED TO YOUR DEBT
|
|
83281
|
-
(your wallet is not charged); it is at most the term's rate \xD7 your current debt,
|
|
83282
|
-
reduced by unused origination-fee credit from the current term.
|
|
83283
|
-
6. **Withdraw BTC** \u2014 \`loan_withdraw {positionId, btcAddress, amountSats, confirmed:true}\`.
|
|
83284
|
-
BTC sends are IRREVERSIBLE \u2014 read the address back to the user before confirming.
|
|
83285
|
-
amountSats is gross (fee comes out of it) and may be the whole available balance.
|
|
83286
|
-
7. **Watch it** \u2014 \`position_status\` (one), \`position_list\` (all),
|
|
83287
|
-
\`position_events\` (history), \`btc_price\`, \`protocol_status\`.
|
|
83288
|
-
|
|
83289
|
-
State flow: ${STATE_FLOW_LINE} \u2014 see \`safety\`.`,
|
|
83290
|
-
fees: `# Fees \u2014 the two models, stated plainly
|
|
83291
|
-
|
|
83292
|
-
- **Origination fee (minting):** a percentage of what you borrow
|
|
83293
|
-
(\`protocol_terms.originationFeeBps\`, e.g. 200 = 2%). It is ADDED TO YOUR DEBT: borrow
|
|
83294
|
-
100 UCD \u2192 you receive 100, you owe 102. It is never taken out of what you receive.
|
|
83295
|
-
- **Extension fee (renewing):** ADDED TO YOUR DEBT, like the origination fee \u2014 your
|
|
83296
|
-
wallet is not charged. The CEILING is \`extensionFeeRateBps\` \xD7 your CURRENT DEBT (a
|
|
83297
|
-
flat rate per renewal, not per month); origination fees you already paid this term are
|
|
83298
|
-
CREDITED against it, so the charged fee lands between (ceiling \u2212 that credit) and the
|
|
83299
|
-
ceiling.
|
|
83300
|
-
- **Repayment:** no fee, any amount up to the debt.
|
|
83301
|
-
- **BTC network fee (withdrawals):** deducted FROM the amount you withdraw (default
|
|
83302
|
-
1000 sats) \u2014 the destination receives amountSats \u2212 fee.
|
|
83303
|
-
|
|
83304
|
-
Every fund-moving result carries an \`authorization.card\` \u2014 the exact text that was
|
|
83305
|
-
signed, amounts included. Read it back when the user asks what happened.`,
|
|
83306
|
-
psm: `# PSM \u2014 exchanging UCD \u2194 USDC (the peg-stability module)
|
|
83307
|
-
|
|
83308
|
-
The PSM is the protocol's exchange window between UCD and USDC, near the peg. Two
|
|
83309
|
-
directions, in user words:
|
|
83310
|
-
|
|
83311
|
-
- **"Get UCD for my USDC"** (\`psm_quote\` direction \`to-ucd\`): you pay USDC, the PSM
|
|
83312
|
-
mints UCD **to you** (output always goes to the caller \u2014 there is no recipient field).
|
|
83313
|
-
The **entry fee is charged IN UCD**: a percentage (basis points) of the gross converted
|
|
83314
|
-
UCD, taken before it reaches you \u2014 e.g. at a 1% fee, 100 USDC converts to 100 UCD gross
|
|
83315
|
-
and you receive 99 UCD.
|
|
83316
|
-
- **"Get USDC back"** (\`psm_quote\` direction \`to-usdc\`): you return UCD (it is burned)
|
|
83317
|
-
and the PSM pays you USDC **from its live reserves**. The **exit fee is charged IN
|
|
83318
|
-
USDC**, deducted from what you receive; the contract caps it at 10%. A redemption is
|
|
83319
|
-
only possible while reserves cover the payout \u2014 the quote shows live reserves, and a
|
|
83320
|
-
shortfall refuses with both figures (available vs required).
|
|
83321
|
-
|
|
83322
|
-
The two fees are independent and live in DIFFERENT tokens \u2014 always say which token a fee
|
|
83323
|
-
is in. Rates and fees are configuration (\`protocol://psm\` shows them; exchange rate
|
|
83324
|
-
1e18 = 1:1) and can be changed by protocol governance.
|
|
83325
|
-
|
|
83326
|
-
**Limits and switches** (all visible in \`protocol://psm\`):
|
|
83327
|
-
- Each direction has a min and max PER OPERATION. Unit trap: to-ucd limits are in USDC
|
|
83328
|
-
units, to-usdc limits are in UCD. A max of 0 means that direction is DISABLED.
|
|
83329
|
-
- \`paused\` kills BOTH directions; \`redeemEnabled = false\` kills ONLY the to-usdc
|
|
83330
|
-
direction (swaps to UCD keep working). These are different switches \u2014 name the right one.
|
|
83331
|
-
- Per-block volume caps may exist per direction ("uncapped" when none is set).
|
|
83332
|
-
|
|
83333
|
-
**Why a slippage floor exists:** executing an exchange on-chain REQUIRES a minimum-out
|
|
83334
|
-
floor \u2014 submitting with a zero floor is refused by the contract. Fees or the rate can
|
|
83335
|
-
change between your quote and execution; the floor makes a drifted execution REFUSE
|
|
83336
|
-
rather than silently deliver less than quoted.
|
|
83337
|
-
|
|
83338
|
-
**Practice funding (sepolia):** the sepolia stablecoin is a MOCK USDC with a public
|
|
83339
|
-
\`mint\` \u2014 you can create practice USDC for yourself, self-serve. \`protocol://psm\` states
|
|
83340
|
-
the token's kind (\`mock\` vs \`circle\`) and address so you never have to guess whether
|
|
83341
|
-
the money is real. On mainnet the stablecoin is real Circle USDC.
|
|
83342
|
-
|
|
83343
|
-
**Executing (\`psm_swap\`):** an exchange is TWO on-chain ceremonies, both shown in the
|
|
83344
|
-
result. (1) An **exact-amount approval** of the input token \u2014 never unlimited. The spender
|
|
83345
|
-
differs by direction, and that is contract truth, not a quirk: for **to-ucd** you approve
|
|
83346
|
-
USDC to the **PSM contract** (it pulls the USDC it converts); for **to-usdc** you approve
|
|
83347
|
-
UCD to the **UCDController** (the PSM burns your UCD through the controller). (2) The
|
|
83348
|
-
swap/redeem itself, carrying a minimum-out floor = the live quote minus a 100 bps
|
|
83349
|
-
tolerance; if fees or the rate drifted beyond that between quote and execution, the
|
|
83350
|
-
contract refuses \u2014 you never silently receive less. Output always lands at the signer's
|
|
83351
|
-
own address. If you approve step 1 but decline step 2, the exact-amount allowance remains
|
|
83352
|
-
standing \u2014 it authorizes only that amount and nothing else; the result says so plainly.
|
|
83353
|
-
On the real protocol, PSM writes run on sepolia ONLY \u2014 mainnet PSM writes are refused
|
|
83354
|
-
(the PSM-specific sepolia-only anchor; loan operations are not affected).`,
|
|
83355
|
-
authorization: `# Authorization \u2014 who signs, and what a signature means
|
|
83356
|
-
|
|
83357
|
-
Every fund-moving operation needs TWO things, always in this order:
|
|
83358
|
-
1. **The user's explicit confirmation** in conversation (\`confirmed: true\`) \u2014 the agent
|
|
83359
|
-
must ask, never assume.
|
|
83360
|
-
2. **A cryptographic authorization** by the chosen signer mode:
|
|
83361
|
-
- \`external\` \u2014 the user approves in their OWN wallet (browser popup, or WalletConnect
|
|
83362
|
-
mobile via QR/paste-code). Real adapter and mock. The approval card in the wallet
|
|
83363
|
-
shows EXACTLY what executes \u2014 amounts are decoded from the transaction itself, never
|
|
83364
|
-
re-formatted. Walkthrough: \`guide connect-wallet\`.
|
|
83365
|
-
- \`keystore\` \u2014 a local encrypted keystore signs automatically after each confirmation.
|
|
83366
|
-
Real adapter and mock.
|
|
83367
|
-
- \`safe\` / \`safe-module\` \u2014 PRACTICE-ONLY today: on the real adapter these modes
|
|
83368
|
-
refuse with that true reason (their planes ship in their own deliveries).
|
|
83369
|
-
- \`mock-simulated\` \u2014 practice-world stand-in ceremony (no cryptography; mock only).
|
|
83370
|
-
|
|
83371
|
-
**Reads never summon the wallet.** Public reads need no signer at all. Authenticated
|
|
83372
|
-
reads need a login \u2014 the keystore env pair, or an explicit "connect my wallet"
|
|
83373
|
-
(\`signer_setup\` action \`connect\`). Without one they refuse legibly; a wallet popup is
|
|
83374
|
-
only ever caused by a write ceremony or that explicit connect. The login (one typed-data
|
|
83375
|
-
signature) lasts a JWT lifetime; when it expires, the next call refuses the same legible
|
|
83376
|
-
way \u2014 reconnect on the user's word.
|
|
83377
|
-
|
|
83378
|
-
Results carry \`authorization\`: \`scheme\` (external-wallet | eip712-eoa | mock-signature),
|
|
83379
|
-
\`signer\` (who signed), \`card\` (what was signed, human-readable), \`digest\` (the signature
|
|
83380
|
-
or transaction hash). Declining in the wallet ALWAYS safely cancels the operation.
|
|
83381
|
-
|
|
83382
|
-
\`signer_setup status\` vocabulary: a **candidate** is a wallet that is CONNECTED to the
|
|
83383
|
-
approval page but has not yet proven itself by signing; the **borrower** is the identity
|
|
83384
|
-
BOUND by the first verified signature (it persists across sessions). Connected \u2260 chosen:
|
|
83385
|
-
picking external mode is a preference \u2014 a wallet still has to connect on the approval
|
|
83386
|
-
page, and the page link comes from \`signer_setup status\`.
|
|
83387
|
-
|
|
83388
|
-
Switching modes: \`signer_setup\` \u2014 see \`first-setup\`. Secrets NEVER travel through chat;
|
|
83389
|
-
keystore passwords go only into the secure unlock page.`,
|
|
83390
|
-
safe: `# Safe accounts \u2014 borrowing as a smart-account (single or multi-owner)
|
|
83391
|
-
|
|
83392
|
-
A **Safe** is a smart-contract account owned by one or more wallets ("owners") with a
|
|
83393
|
-
signature **threshold** (e.g. 2-of-3: any 2 of the 3 owners must sign). Companies and
|
|
83394
|
-
teams use Safes so no single key controls the funds. Diamond Hands supports a Safe AS THE
|
|
83395
|
-
BORROWER: the position belongs to the Safe, and operations are authorized by its owners.
|
|
83396
|
-
|
|
83397
|
-
**Adapter truth:** the Safe borrower plane is PRACTICE-ONLY today \u2014 on the real adapter,
|
|
83398
|
-
\`signer_setup use safe\` refuses with exactly that reason. Everything below runs in mock
|
|
83399
|
-
worlds until the Safe plane's own delivery; never present it as available on real.
|
|
83400
|
-
|
|
83401
|
-
**Setup:** \`signer_setup\` action \`use\`, mode \`safe\`, with \`safeAddress\`. Owners and
|
|
83402
|
-
threshold are DISCOVERED from the Safe itself \u2014 never typed in. (Practice worlds: create
|
|
83403
|
-
a test Safe first with \`mock_control deploy-safe\`.) If keystore material is already
|
|
83404
|
-
configured (\`signer_setup status\` \u2192 keystoreConfigured), \`use safe\` unlocks it
|
|
83405
|
-
AUTOMATICALLY \u2014 do not send the user to the unlock page in that case.
|
|
83406
|
-
|
|
83407
|
-
**Who signs what (say this plainly):**
|
|
83408
|
-
- Every operation still needs the user's \`confirmed: true\` first \u2014 nothing changed there.
|
|
83409
|
-
- Owner signatures then authorize the operation. In the current phase the local keystore
|
|
83410
|
-
is the owner-signer (a 1-of-1 Safe); external owner wallets join in a later phase.
|
|
83411
|
-
- Creating a position and withdrawing BTC are executed BY the Safe itself (a Safe
|
|
83412
|
-
transaction \u2014 you may see a "Safe nonce" on the card). Minting, paying and renewing
|
|
83413
|
-
are authorized by the owners and submitted by an executor \u2014 the result card names it.
|
|
83414
|
-
|
|
83415
|
-
**Withdrawals have one extra rule:** the destination BTC address must be ALLOWLISTED for
|
|
83416
|
-
the Safe first \u2014 \`loan_allowlist_destination\` (its own owner-signed ceremony; the address
|
|
83417
|
-
becomes usable after a delay READ LIVE from the chain \u2014 immediate in practice worlds,
|
|
83418
|
-
24 hours on mainnet, where allowlisting and withdrawing happen on different days). A
|
|
83419
|
-
withdrawal to an unlisted address refuses with exactly this instruction.
|
|
83420
|
-
|
|
83421
|
-
**Timing honesty (multi-owner Safes, later phases):** authorizations for mint/pay/renew
|
|
83422
|
-
expire after ~3 minutes, and withdrawal authorizations within the minute \u2014 so a multi-
|
|
83423
|
-
owner signing session happens TOGETHER, live ("gather first, sign in one burst").
|
|
83424
|
-
Creating a position and allowlisting a destination have NO expiry \u2014 owners can sign
|
|
83425
|
-
those at their own pace. The ceremony guides this; never widen a window.`,
|
|
83426
|
-
delegation: `# Delegation \u2014 one owner ceremony, then day-to-day solo
|
|
83427
|
-
|
|
83428
|
-
Multi-owner Safes cannot practically sign every operation inside the protocol's short
|
|
83429
|
-
signature window. Delegation is the protocol's answer: the owners sign ONCE to install a
|
|
83430
|
-
tightly-caged AGENT key; afterwards daily work runs without disturbing them.
|
|
83431
|
-
|
|
83432
|
-
**Adapter truth:** delegation (mode \`safe-module\`) is PRACTICE-ONLY today \u2014 on the real
|
|
83433
|
-
adapter it refuses with exactly that reason, pending its own delivery. Everything below
|
|
83434
|
-
runs in mock worlds; never present it as available on real.
|
|
83435
|
-
|
|
83436
|
-
**Setup (mode \`safe-module\`):** \`signer_setup use safe-module\` with your Safe's address,
|
|
83437
|
-
then \`loan_delegation_setup\` \u2014 ONE durable Safe transaction the owners sign at their
|
|
83438
|
-
leisure (no time window). It enables the Safe's AgentModule, binds the agent key, registers
|
|
83439
|
-
it in the delegation registry, and pre-approves your BTC withdrawal destinations (so your
|
|
83440
|
-
first withdrawal never needs a second gathering).
|
|
83441
|
-
|
|
83442
|
-
**What the agent CAN do alone** (an unchangeable, contract-hardcoded list): create a
|
|
83443
|
-
position; and \u2014 per position, only after the owners grant it (\`loan_delegation_grant\`,
|
|
83444
|
-
a quorum signature; the agent can NEVER widen its own powers) \u2014 pay down debt (REPAY),
|
|
83445
|
-
extend the term (RENEW), and borrow (MINT, only while the post-mint collateral ratio
|
|
83446
|
-
stays at or above the floor the owners granted \u2014 their risk bound).
|
|
83447
|
-
|
|
83448
|
-
**What the agent can NEVER do, ever:** withdraw Bitcoin alone (withdrawal signatures are
|
|
83449
|
-
owners-only, permanently \u2014 the verifier has no delegate arm); add or change withdrawal
|
|
83450
|
-
destinations (owners-only, forever); touch the module, the registry, or any other
|
|
83451
|
-
contract; move ETH. A stolen agent key can shuffle money WITHIN your position \u2014 never out.
|
|
83452
|
-
|
|
83453
|
-
**Withdrawals stay a short owners' moment:** the agent prepares and submits, but the
|
|
83454
|
-
owners sign together inside the short window, and only to destinations they pre-approved.
|
|
83455
|
-
Where the destination registry is wired on-chain this bound is enforced by the contract;
|
|
83456
|
-
verify the wiring on your network before relying on it (test networks: wired and verified;
|
|
83457
|
-
mainnet wiring is confirmed at deployment review).
|
|
83458
|
-
|
|
83459
|
-
**Rotation and revocation:** revoking the agent BURNS its address forever (AR-1) \u2014 that
|
|
83460
|
-
is deliberate, so revocation is always safe to use. Rotation = mint a FRESH key and run a
|
|
83461
|
-
new setup ceremony; never reuse keys, never bind a personal or owner key as agent.
|
|
83462
|
-
|
|
83463
|
-
**Currency exchange (PSM):** the module cannot reach the PSM at all \u2014 its allowlist stops
|
|
83464
|
-
at the loan contracts. A Safe's UCD\u2194USDC swaps are TWO durable Safe transactions the
|
|
83465
|
-
owners sign at leisure (\`psm_swap\` builds the pair) \u2014 that is the only Safe PSM path.`,
|
|
83466
|
-
safety: `# Safety \u2014 what protects the user
|
|
83467
|
-
|
|
83468
|
-
- **Nothing moves without you.** Every write needs \`confirmed: true\` AND the signer
|
|
83469
|
-
ceremony. A decline anywhere cleanly cancels \u2014 declining is always safe.
|
|
83470
|
-
- **The card is the truth.** In external mode the wallet card is decoded from the exact
|
|
83471
|
-
transaction bytes being signed \u2014 what you read IS what executes.
|
|
83472
|
-
- **Liquidation:** if collateral value falls so the collateral ratio drops under the
|
|
83473
|
-
liquidation threshold (\`protocol_status.liquidationThresholdBps\`, e.g. 110%), the
|
|
83474
|
-
position can be liquidated. Watch \`position_status.valuation\` \u2014 \`currentLtvBps\` vs the
|
|
83475
|
-
threshold. Repaying debt or adding collateral restores safety.
|
|
83476
|
-
- **Expiry:** positions have terms; extend BEFORE expiry (\`loan_extend\`). An EXPIRED
|
|
83477
|
-
position cannot mint or extend.
|
|
83478
|
-
- **Withdrawals are irreversible.** Bitcoin sent to a wrong address is gone. Read the
|
|
83479
|
-
address back to the user before confirming.
|
|
83480
|
-
- **Can you lose your bitcoin?** Only through liquidation (undercollateralized debt) or
|
|
83481
|
-
withdrawing to a wrong address. Repaid-in-full positions release all collateral.
|
|
83482
|
-
- **Practice vs real:** mock worlds are stated as such (\`boundary://info\`). Never let a
|
|
83483
|
-
user believe practice gains/losses are real, or vice versa.`,
|
|
83484
|
-
"switch-network": `# Switch network \u2014 sepolia \u2194 mainnet by conversation (real adapter)
|
|
83485
|
-
|
|
83486
|
-
The \`network_switch\` tool moves THIS SESSION between worlds. Check
|
|
83487
|
-
\`boundary://info\` capabilities first: \`networkSwitch: true\` means it is available
|
|
83488
|
-
(real adapter); in a practice sandbox (mock) the world is pinned by config \u2014 there is
|
|
83489
|
-
no switch, and that is by design.
|
|
83490
|
-
|
|
83491
|
-
**The rules, plainly:**
|
|
83492
|
-
- \`network_switch status\` \u2014 which network is active and whether money is real. Say
|
|
83493
|
-
this to the user BEFORE and AFTER any switch, always.
|
|
83494
|
-
- \`network_switch switch { network, confirmed: true }\` \u2014 the switch runs only after
|
|
83495
|
-
the human approves the card. sepolia = practice funds; mainnet = REAL MONEY.
|
|
83496
|
-
- NOTHING carries across: positions, vaults, signer bindings, logins are per-network.
|
|
83497
|
-
A sepolia position does not exist on mainnet and vice versa.
|
|
83498
|
-
- Fund-moving loan operations work on BOTH networks \u2014 on mainnet they move REAL money,
|
|
83499
|
-
and every one still requires the user's explicit confirmation plus the signer
|
|
83500
|
-
ceremony. The exception is PSM swaps: sepolia-only, refused on mainnet.
|
|
83501
|
-
- A pending signing ceremony blocks the switch (finish or decline it first).
|
|
83502
|
-
- The switch is session-scoped: when the server restarts, the configured default
|
|
83503
|
-
network returns.
|
|
83504
|
-
|
|
83505
|
-
After any switch: re-read \`boundary://info\`, then STATE the new network and money
|
|
83506
|
-
reality in your next message. The user must never have to ask which world they are in.`,
|
|
83507
|
-
// Plan 17 B1 — the hosted tier's truth, in user language. The trust ledger below is
|
|
83508
|
-
// the plan-12 Part 0 ledger (BINDING, archive/12-remote-connector.md) — all six
|
|
83509
|
-
// entries, verbatim-equivalent; G-CONN pins anchor phrases from every entry.
|
|
83510
|
-
connector: `# The claude.ai connector \u2014 Diamond Hands with zero install (hosted tier)
|
|
83511
|
-
|
|
83512
|
-
**STATUS TRUTH (say this first when asked):** the connector is IMPLEMENTED but NOT yet
|
|
83513
|
-
publicly served \u2014 the operator's rollout gates (a security audit, then a URL) come
|
|
83514
|
-
first. Until then there is no URL to give out, and the local install paths
|
|
83515
|
-
(\`first-setup\`) are the way in. Never promise availability or timing.
|
|
83516
|
-
|
|
83517
|
-
**What it is:** instead of installing anything, the user adds Diamond Hands to
|
|
83518
|
-
claude.ai as a connector (paste a URL \u2014 zero install, zero Node, zero config files).
|
|
83519
|
-
Sign-in IS the wallet: one Sign-In-with-Ethereum signature proves address ownership \u2014
|
|
83520
|
-
no password, no email, no account beyond the wallet address. The sign-in page offers a
|
|
83521
|
-
WalletConnect QR too, so a phone wallet works without any browser extension.
|
|
83522
|
-
|
|
83523
|
-
**Signature cadence, plainly:** the FIRST connect costs one SIWE signature (sign-in)
|
|
83524
|
-
plus one lit-ops login signature (read access). After that, every operation that moves
|
|
83525
|
-
funds asks for its OWN approval in the user's wallet, every time \u2014 and reads never pop
|
|
83526
|
-
the wallet. The login session lives ONLY in the server's memory: a server restart, or
|
|
83527
|
-
an idle spell long enough that the tenant's world is evicted, means signing in again.
|
|
83528
|
-
That is the flip side of "nothing stored at rest" \u2014 a re-login is normal, not a fault.
|
|
83529
|
-
|
|
83530
|
-
**What the hosted server IS trusted with** (the six residual trusts \u2014 state them
|
|
83531
|
-
honestly when asked "is this safe"):
|
|
83532
|
-
1. **The approval page it serves.** Same security baseline as the diamondhands.credit
|
|
83533
|
-
web app (you already trust the pages gvnr serves over HTTPS). The wallet's own
|
|
83534
|
-
display is the independent backstop for transactions; personal-sign envelopes are
|
|
83535
|
-
action-pinned and expire in minutes; BTC destinations are defended by the on-chain
|
|
83536
|
-
allowlist delay, which no server can shorten.
|
|
83537
|
-
2. **The read credential.** Your lit-ops login token is held in memory for the active
|
|
83538
|
-
session ONLY \u2014 it grants reads and advisory broadcast, it can sign NOTHING, and it
|
|
83539
|
-
is never written to disk. A breach here is privacy-class, never money-class.
|
|
83540
|
-
3. **What the assistant narrates.** Tool results shape what the assistant tells you \u2014
|
|
83541
|
-
a security concern is filed and audited for exactly this channel.
|
|
83542
|
-
4. **Tenant separation.** Your identity \u2194 wallet \u2194 session binding is isolated from
|
|
83543
|
-
every other user's; a failure here would be privacy-class, never signing-class,
|
|
83544
|
-
because no key material exists server-side to leak.
|
|
83545
|
-
5. **Availability and deploy honesty.** Hosted code changes under you: deploys are
|
|
83546
|
-
version-pinned, the page bundle is open-source, and \`boundary://info\` capabilities
|
|
83547
|
-
reports the exact server version.
|
|
83548
|
-
6. **The BTC-withdraw blind sign.** Withdrawal serves an OPAQUE 32-byte hash \u2014 the
|
|
83549
|
-
card says plainly that its contents are NOT decodable on the page (site parity:
|
|
83550
|
-
diamondhands.credit serves the identical blind sign). Defenses stated with it:
|
|
83551
|
-
server-side borrower verification, the minutes-narrow signing window, and the
|
|
83552
|
-
on-chain allowlist delay.
|
|
83553
|
-
|
|
83554
|
-
**What it structurally CANNOT do:** hold keys or custody \u2014 keystore mode is ABSENT
|
|
83555
|
-
from the connector build (not disabled: never constructed), so every fund-moving
|
|
83556
|
-
action needs a fresh signature from the user's own wallet. And it serves only the
|
|
83557
|
-
networks its deployment is rolled out to \u2014 this deployment serves sepolia during
|
|
83558
|
-
rollout; mainnet enablement is the operator's deploy decision, stated in capabilities
|
|
83559
|
-
by reason, never a hidden knob.
|
|
83560
|
-
|
|
83561
|
-
**Independent exits:** the web app (diamondhands.credit) and the SDK speak to the SAME
|
|
83562
|
-
chain state. The connector going down strands nothing and gates nothing.`,
|
|
83563
|
-
troubleshooting: `# Troubleshooting \u2014 what error codes mean, in plain words
|
|
83564
|
-
|
|
83565
|
-
- **SIGNER_UNAVAILABLE** \u2014 no authorization mode chosen/ready. Two real remedies: the
|
|
83566
|
-
keystore env pair (\`DH_KEYSTORE_PATH\` + \`DH_KEYSTORE_PASSWORD\`), or the user says
|
|
83567
|
-
"connect my wallet" \u2192 \`signer_setup\` action \`connect\` (external mode). \`signer_setup
|
|
83568
|
-
status\` explains what is active; \`first-setup\` step 2 has the full choice.
|
|
83569
|
-
- **"Not logged in" on a read** \u2014 authenticated reads NEVER pop the wallet; the remedy is
|
|
83570
|
-
the same pair: keystore env pair, or "connect my wallet" (\`signer_setup connect\`). An
|
|
83571
|
-
EXPIRED login refuses the same way \u2014 reconnect on the user's word.
|
|
83572
|
-
- **PSM write refused on mainnet** \u2014 PSM swaps are sepolia-only (a deliberate anchor,
|
|
83573
|
-
not a bug); loan operations work on mainnet. Reads keep working everywhere.
|
|
83574
|
-
- **"Wrong network" / wants mainnet or sepolia** \u2014 real adapter: \`network_switch\`
|
|
83575
|
-
(human-confirmed card; nothing carries across networks). Mock: the world is pinned by
|
|
83576
|
-
config \u2014 no switch exists there.
|
|
83577
|
-
- **External-mode withdraw shows a bare hash** \u2014 that is by design (site parity): the
|
|
83578
|
-
SDK builds the withdrawal auth hashes internally, so the page cannot decode them.
|
|
83579
|
-
Two blind hash signatures per withdrawal; warn the user before triggering them.
|
|
83580
|
-
- **Login throttled (mainnet)** \u2014 the broker limits logins per address; wait and retry.
|
|
83581
|
-
That is the broker throttle, not a wallet failure.
|
|
83582
|
-
- **VALIDATION_FAILED** \u2014 the input itself is off (bad address format, too many decimals,
|
|
83583
|
-
unknown field). The message names the exact problem; fix the input, don't retry blindly.
|
|
83584
|
-
- **UPSTREAM_REJECTED** \u2014 the protocol said no: over the mint ceiling, repaying more than
|
|
83585
|
-
owed, wrong position state, or the USER DECLINED in the wallet. The message says which.
|
|
83586
|
-
A decline is not an error to fix \u2014 it is the user's decision.
|
|
83587
|
-
- **UPSTREAM_UNAVAILABLE** \u2014 a data source or the signature bridge is unreachable/expired.
|
|
83588
|
-
Usually transient; re-check with \`protocol_status\` and retry once.
|
|
83589
|
-
- **NOT_FOUND** \u2014 the position id doesn't exist in this world (check \`position_list\`).
|
|
83590
|
-
- **STATE_DIVERGENCE / STALE_DATA warnings** \u2014 sources disagree or lag; the envelope says
|
|
83591
|
-
which source and when from. Prefer chain-sourced values; re-read before acting.
|
|
83592
|
-
- Approval popup never appeared? \`signer_setup status\` \u2192 reopen the approval page URL.
|
|
83593
|
-
Wallet on the wrong network? The page offers the switch \u2014 approve it in the wallet.
|
|
83594
|
-
- **Asked for the claude.ai connector / remote / hosted tier** \u2014 implemented, NOT yet
|
|
83595
|
-
publicly served (the operator's audit + rollout gates come first). There is no URL to
|
|
83596
|
-
give out; the local install paths work today. Full truth: \`guide connector\`.
|
|
83597
|
-
- **\`spawn npx ENOENT\` at server start (another machine/host)** \u2014 the MCP host searched
|
|
83598
|
-
the system PATH and found no \`npx\`: that machine has no Node.js, or the host (e.g. an
|
|
83599
|
-
Electron app) cannot see a shell-managed Node. Not a server bug \u2014 the npx path requires
|
|
83600
|
-
Node \u2265 18 on PATH. Remedies: the one-line installer (self-contained binary, absolute
|
|
83601
|
-
path in the printed snippet), or the \`.mcpb\` bundle on macOS/Windows Claude Desktop.`,
|
|
83602
|
-
glossary: `# Glossary \u2014 map the user's words to the protocol's
|
|
83603
|
-
|
|
83604
|
-
Synonym sets (treat these as the SAME intent):
|
|
83605
|
-
- **mint** = borrow = take a loan = draw = "get UCD" \u2192 \`loan_mint\`
|
|
83606
|
-
- **pay** = repay = pay back = pay down = settle \u2192 \`loan_pay\`
|
|
83607
|
-
- **extend** = renew = roll over = prolong \u2192 \`loan_extend\`
|
|
83608
|
-
- **withdraw** = take out my bitcoin = cash out = get my BTC back \u2192 \`loan_withdraw\`
|
|
83609
|
-
- **position** = loan = account (the borrowing arrangement) \u2192 \`position_status\`
|
|
83610
|
-
- **disconnect** = log out = sign out = forget my wallet = remove my wallet \u2192
|
|
83611
|
-
\`signer_setup\` action \`disconnect\` (the FULL flush \u2014 never map these to
|
|
83612
|
-
\`reset-borrower\`, which only swaps identity)
|
|
83613
|
-
- **UCD** = the dollar-pegged token you borrow ("the dollars")
|
|
83614
|
-
- **sats** = satoshis, 1 BTC = 100,000,000 sats
|
|
83615
|
-
- **connector** = remote = hosted tier = "claude.ai integration" = "use it without
|
|
83616
|
-
installing" \u2192 \`guide connector\` (status: implemented, not yet publicly served)
|
|
83617
|
-
|
|
83618
|
-
Context-dependent terms \u2014 DISAMBIGUATE, never flatten:
|
|
83619
|
-
- **vault** \u2014 the position's BTC custody address. Its balance is your COLLATERAL, not
|
|
83620
|
-
your loan. "How much is in my vault?" \u2192 collateral; "how much do I owe?" \u2192 debt.
|
|
83621
|
-
- **balance** \u2014 ask which: vault BTC (collateral) or UCD debt? They move independently.
|
|
83622
|
-
- **health** \u2014 collateral-value vs debt (\`indexedHealth\`, \`currentLtvBps\`): a SAFETY
|
|
83623
|
-
measure against liquidation, not an account balance.
|
|
83624
|
-
- **interest** \u2014 Diamond Hands charges FEES (origination/extension), not running
|
|
83625
|
-
interest; see \`fees\`.
|
|
83626
|
-
|
|
83627
|
-
Language: answer in the user's language, whatever it is. These mappings apply to meaning,
|
|
83628
|
-
not to English words only \u2014 "pagar" \u2192 \`loan_pay\`, "retirar meu bitcoin" \u2192 \`loan_withdraw\`,
|
|
83629
|
-
"emprestar/pedir emprestado" \u2192 \`loan_mint\`, and so on.`,
|
|
83630
|
-
// Plan 16 C3: rendered from the ONE glossary source (boundary/field-glossary.ts) —
|
|
83631
|
-
// the same entries the anchor test pins against the actually-serialized fields.
|
|
83632
|
-
"reading-data": renderFieldGlossaryTopic()
|
|
83633
|
-
};
|
|
83634
|
-
var GUIDE_INDEX = `# Diamond Hands guide \u2014 topics
|
|
83635
|
-
|
|
83636
|
-
- getting-started \u2014 what this product is, practice-vs-real-money honesty (three cases)
|
|
83637
|
-
- first-setup \u2014 zero to ready by conversation (authorization choice included)
|
|
83638
|
-
- connect-wallet \u2014 external-wallet walkthrough: approval page, extension or WalletConnect QR, popup cadence, login honesty, disconnect/log-out
|
|
83639
|
-
- lifecycle \u2014 the exact calls, create \u2192 deposit \u2192 mint \u2192 pay \u2192 extend \u2192 withdraw
|
|
83640
|
-
- fees \u2014 the two fee models, plainly
|
|
83641
|
-
- psm \u2014 exchanging UCD \u2194 USDC: both directions, the two fees WITH their tokens, limits, why a floor exists
|
|
83642
|
-
- authorization \u2014 confirmation + signature: what protects every operation, which modes exist where
|
|
83643
|
-
- safe \u2014 borrowing as a Safe smart-account (single or multi-owner), allowlisting, timing \u2014 PRACTICE-ONLY today
|
|
83644
|
-
- delegation \u2014 one owner ceremony, then day-to-day solo: the agent, its cage, and what always stays with the owners \u2014 PRACTICE-ONLY today
|
|
83645
|
-
- safety \u2014 liquidation, expiry, irreversible sends, decline-is-safe
|
|
83646
|
-
- switch-network \u2014 moving this session between sepolia (practice) and mainnet (REAL MONEY): the card, what carries across (nothing), what stays gated
|
|
83647
|
-
- connector \u2014 the hosted claude.ai tier (zero install, wallet = account): its six-trust ledger, signature cadence, what it can never do. Status: implemented, NOT yet publicly served
|
|
83648
|
-
- troubleshooting \u2014 error codes in plain words, with the real remedies
|
|
83649
|
-
- glossary \u2014 synonym map + disambiguations (use it to understand ANY user's vocabulary)
|
|
83650
|
-
- reading-data \u2014 every payload field's exact meaning (consult before interpreting any number you are unsure of)
|
|
83651
|
-
|
|
83652
|
-
Orientation: Diamond Hands = borrow UCD (dollar-pegged) against your own Bitcoin without
|
|
83653
|
-
selling it. Everything fund-moving needs the user's confirmed:true AND their chosen
|
|
83654
|
-
signature ceremony. Read boundary://info capabilities FIRST; state the money truth early
|
|
83655
|
-
and always: mock = practice; real adapter on sepolia = real protocol, PRACTICE money;
|
|
83656
|
-
only mainnet is real money.`;
|
|
83657
|
-
|
|
83658
|
-
// src/tools/guide.ts
|
|
83659
|
-
function registerGuideTool(server) {
|
|
83990
|
+
function registerGuideTool(server, deployment = LOCAL_GUIDE_DEPLOYMENT) {
|
|
83991
|
+
const content = buildGuideContent(deployment);
|
|
83992
|
+
const index = buildGuideIndex(deployment);
|
|
83660
83993
|
registerBoundaryTool(
|
|
83661
83994
|
server,
|
|
83662
83995
|
"guide",
|
|
@@ -83670,26 +84003,31 @@ function registerGuideTool(server) {
|
|
|
83670
84003
|
},
|
|
83671
84004
|
async ({ topic }) => guarded(async () => {
|
|
83672
84005
|
if (topic === void 0 || topic === "") {
|
|
83673
|
-
return { content: [{ type: "text", text:
|
|
84006
|
+
return { content: [{ type: "text", text: index }] };
|
|
83674
84007
|
}
|
|
83675
84008
|
if (!GUIDE_TOPICS.includes(topic)) {
|
|
83676
84009
|
return validationFailed(`unknown guide topic '${topic}' \u2014 available: ${GUIDE_TOPICS.join(" | ")}`);
|
|
83677
84010
|
}
|
|
83678
|
-
return { content: [{ type: "text", text:
|
|
84011
|
+
return { content: [{ type: "text", text: content[topic] }] };
|
|
83679
84012
|
})
|
|
83680
84013
|
);
|
|
83681
84014
|
}
|
|
83682
|
-
function registerGuideResources(server) {
|
|
84015
|
+
function registerGuideResources(server, deployment = LOCAL_GUIDE_DEPLOYMENT) {
|
|
84016
|
+
const content = buildGuideContent(deployment);
|
|
84017
|
+
const index = buildGuideIndex(deployment);
|
|
83683
84018
|
for (const topic of GUIDE_TOPICS) {
|
|
83684
84019
|
server.resource(`guide-${topic}`, `guide://${topic}`, async () => ({
|
|
83685
|
-
contents: [{ uri: `guide://${topic}`, mimeType: "text/markdown", text:
|
|
84020
|
+
contents: [{ uri: `guide://${topic}`, mimeType: "text/markdown", text: content[topic] }]
|
|
83686
84021
|
}));
|
|
83687
84022
|
}
|
|
83688
84023
|
server.resource("guide-index", "guide://index", async () => ({
|
|
83689
|
-
contents: [{ uri: "guide://index", mimeType: "text/markdown", text:
|
|
84024
|
+
contents: [{ uri: "guide://index", mimeType: "text/markdown", text: index }]
|
|
83690
84025
|
}));
|
|
83691
84026
|
}
|
|
83692
|
-
function
|
|
84027
|
+
function onboardAuthorizationLine(deployment) {
|
|
84028
|
+
return deployment.signerModes.includes("keystore") ? "if external mode is available, offer the wallet walkthrough (guide 'connect-wallet') alongside the automatic keystore \u2014 my choice \u2014 and then help me open my first position. " : "this build authorizes with MY OWN WALLET and nothing else, so offer the wallet walkthrough (guide 'connect-wallet') \u2014 never an automatic-signing alternative it does not have \u2014 and then help me open my first position. ";
|
|
84029
|
+
}
|
|
84030
|
+
function registerGuidePrompts(server, deployment = LOCAL_GUIDE_DEPLOYMENT) {
|
|
83693
84031
|
server.prompt(
|
|
83694
84032
|
"onboard-me",
|
|
83695
84033
|
"Walk a brand-new user through Diamond Hands: what it is, practice-vs-real-money, choosing how to authorize, and their first position.",
|
|
@@ -83699,7 +84037,7 @@ function registerGuidePrompts(server) {
|
|
|
83699
84037
|
role: "user",
|
|
83700
84038
|
content: {
|
|
83701
84039
|
type: "text",
|
|
83702
|
-
text: "I'm new to Diamond Hands. FIRST read boundary://info and its capabilities block \u2014 it is the truth about this session: the network, practice vs real money, whether writes are enabled (and the true reason when not), and which signer modes exist here. Never promise anything it does not list. Then read the guide topics 'getting-started' and 'first-setup' (guide tool), check protocol_status, and walk me through setup step by step IN MY LANGUAGE: tell me plainly whether this is practice or real money. BRANCH on capabilities: if no signer mode is available or writes are disabled, keep me on the read-only path (position_list with my address needs no signer) and say the true reason;
|
|
84040
|
+
text: "I'm new to Diamond Hands. FIRST read boundary://info and its capabilities block \u2014 it is the truth about this session: the network, practice vs real money, whether writes are enabled (and the true reason when not), and which signer modes exist here. Never promise anything it does not list. Then read the guide topics 'getting-started' and 'first-setup' (guide tool), check protocol_status, and walk me through setup step by step IN MY LANGUAGE: tell me plainly whether this is practice or real money. BRANCH on capabilities: if no signer mode is available or writes are disabled, keep me on the read-only path (position_list with my address needs no signer) and say the true reason; " + onboardAuthorizationLine(deployment) + "Ask before every operation; never assume confirmation."
|
|
83703
84041
|
}
|
|
83704
84042
|
}
|
|
83705
84043
|
]
|
|
@@ -83935,8 +84273,10 @@ function registerBoundaryInfoResource(server, getB) {
|
|
|
83935
84273
|
);
|
|
83936
84274
|
}
|
|
83937
84275
|
|
|
84276
|
+
// src/version.ts
|
|
84277
|
+
var SERVER_VERSION = "0.5.12";
|
|
84278
|
+
|
|
83938
84279
|
// src/server.ts
|
|
83939
|
-
var SERVER_VERSION = "0.5.9";
|
|
83940
84280
|
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. When a network_switch tool is listed, the network can change mid-session \u2014 after ANY switch, re-read boundary://info and state the new network and money reality to the user before doing anything else. When the user asks to disconnect / log out / sign out / forget or remove their wallet, call signer_setup action 'disconnect' (the full flush) \u2014 never treat 'reset-borrower' as a disconnect; it only swaps identity. READING DATA: a payload's fields and notes are authoritative \u2014 state what they say, never speculate past them, and when the data does not carry something, say 'the data does not carry X'. Field meanings live in guide topic 'reading-data'; `reading` notes inside a result are interpretation instructions for that exact payload \u2014 follow them over any prior assumption.";
|
|
83941
84281
|
var CONNECTOR_INSTRUCTIONS = SERVER_INSTRUCTIONS + " HOSTED CONNECTOR TIER: this server is the hosted claude.ai connector. Signer modes are external-wallet ONLY \u2014 keystore mode is ABSENT from this build (structurally, not disabled); the server never holds a key, and every fund-moving action needs a fresh signature from the user's own wallet. Each tenant's world is isolated by wallet identity; network_switch moves ONLY this tenant, within the networks this deployment serves (the refusal states the rollout truth). The login session lives in server memory only \u2014 a server restart or idle eviction means signing in again; that is the no-data-at-rest property, not a fault. Trust ledger and cadence: guide topic 'connector'.";
|
|
83942
84282
|
function createServer2(deps, instructions = SERVER_INSTRUCTIONS) {
|
|
@@ -83956,9 +84296,9 @@ function createServer2(deps, instructions = SERVER_INSTRUCTIONS) {
|
|
|
83956
84296
|
registerPositionResource(server, getB);
|
|
83957
84297
|
registerProtocolResources(server, getB);
|
|
83958
84298
|
registerBoundaryInfoResource(server, getB);
|
|
83959
|
-
registerGuideTool(server);
|
|
83960
|
-
registerGuideResources(server);
|
|
83961
|
-
registerGuidePrompts(server);
|
|
84299
|
+
registerGuideTool(server, deps.deployment);
|
|
84300
|
+
registerGuideResources(server, deps.deployment);
|
|
84301
|
+
registerGuidePrompts(server, deps.deployment);
|
|
83962
84302
|
if (deps.mockControl) {
|
|
83963
84303
|
registerMockControlTool(server, deps.mockControl, deps.chainId);
|
|
83964
84304
|
}
|