@gvnrdao/dh-mcp 0.5.14 → 0.5.15
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 +8 -4
- package/dist/boundary.js +423 -96
- package/dist/connector-embed.js +574 -174
- package/dist/connector.js +574 -174
- package/dist/index.js +559 -168
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15440,9 +15440,9 @@ ${errorReport}`);
|
|
|
15440
15440
|
var MAX_BTC_AMOUNT = 25e6 * 1e8;
|
|
15441
15441
|
var UTXO_QUERY_MAX_RETRIES = 3;
|
|
15442
15442
|
var UTXO_QUERY_RETRY_DELAY_MS = 500;
|
|
15443
|
-
var
|
|
15443
|
+
var QUANTUM_WINDOW_SECONDS4 = 60;
|
|
15444
15444
|
var DEAD_ZONE_SECONDS2 = 16;
|
|
15445
|
-
var SAFE_EXECUTION_WINDOW_SECONDS =
|
|
15445
|
+
var SAFE_EXECUTION_WINDOW_SECONDS = QUANTUM_WINDOW_SECONDS4 - DEAD_ZONE_SECONDS2;
|
|
15446
15446
|
var SECONDS_PER_DAY = 86400;
|
|
15447
15447
|
var DAYS_PER_MONTH = 30;
|
|
15448
15448
|
var LIT_ACTION_ETH_RPC_TIMEOUT_MS = 8e3;
|
|
@@ -40498,6 +40498,7 @@ var require_dist3 = __commonJS({
|
|
|
40498
40498
|
// src/boundary/upstream/shared/external-bridge/wc-transport.ts
|
|
40499
40499
|
var wc_transport_exports = {};
|
|
40500
40500
|
__export(wc_transport_exports, {
|
|
40501
|
+
WC_DAPP_METADATA: () => WC_DAPP_METADATA,
|
|
40501
40502
|
WC_SESSION_METHODS: () => WC_SESSION_METHODS,
|
|
40502
40503
|
WcTransport: () => WcTransport,
|
|
40503
40504
|
newIsolatedCore: () => newIsolatedCore,
|
|
@@ -40533,7 +40534,7 @@ function newIsolatedCore(cfg, label) {
|
|
|
40533
40534
|
});
|
|
40534
40535
|
return { core, scratch };
|
|
40535
40536
|
}
|
|
40536
|
-
var import_core, import_sign_client, os, path3, import_node_fs, WC_SESSION_METHODS, EVENTS, WcTransport;
|
|
40537
|
+
var import_core, import_sign_client, os, path3, import_node_fs, WC_SESSION_METHODS, WC_DAPP_METADATA, EVENTS, WcTransport;
|
|
40537
40538
|
var init_wc_transport = __esm({
|
|
40538
40539
|
"src/boundary/upstream/shared/external-bridge/wc-transport.ts"() {
|
|
40539
40540
|
"use strict";
|
|
@@ -40543,6 +40544,12 @@ var init_wc_transport = __esm({
|
|
|
40543
40544
|
path3 = __toESM(require("path"));
|
|
40544
40545
|
import_node_fs = require("fs");
|
|
40545
40546
|
WC_SESSION_METHODS = ["personal_sign", "eth_signTypedData_v4", "eth_sendTransaction"];
|
|
40547
|
+
WC_DAPP_METADATA = {
|
|
40548
|
+
name: "Diamond Hands MCP",
|
|
40549
|
+
description: "Approve Diamond Hands loan operations \u2014 real funds move on your confirmation",
|
|
40550
|
+
url: "https://app.diamondhands.credit",
|
|
40551
|
+
icons: []
|
|
40552
|
+
};
|
|
40546
40553
|
EVENTS = ["accountsChanged", "chainChanged"];
|
|
40547
40554
|
WcTransport = class _WcTransport {
|
|
40548
40555
|
constructor(client, cfg, scratch) {
|
|
@@ -40561,12 +40568,7 @@ var init_wc_transport = __esm({
|
|
|
40561
40568
|
const client = await import_sign_client.default.init({
|
|
40562
40569
|
core,
|
|
40563
40570
|
projectId: cfg.projectId,
|
|
40564
|
-
metadata:
|
|
40565
|
-
name: "Diamond Hands MCP",
|
|
40566
|
-
description: "Human approval for Diamond Hands operations",
|
|
40567
|
-
url: "https://gvnr.xyz",
|
|
40568
|
-
icons: []
|
|
40569
|
-
}
|
|
40571
|
+
metadata: WC_DAPP_METADATA
|
|
40570
40572
|
});
|
|
40571
40573
|
return new _WcTransport(client, cfg, scratch);
|
|
40572
40574
|
}
|
|
@@ -40628,6 +40630,27 @@ var NETWORKS = { sepolia: 11155111, mainnet: 1 };
|
|
|
40628
40630
|
var ADAPTERS = ["mock", "real"];
|
|
40629
40631
|
var LATENCIES = ["zero", "realistic"];
|
|
40630
40632
|
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
40633
|
+
var DEFAULT_WC_PROJECT_ID = "f93d3047a55f38275553a49b32ed5372";
|
|
40634
|
+
var WC_DISABLED = "off";
|
|
40635
|
+
function withLocalWcDefault(env) {
|
|
40636
|
+
const raw = env["DH_WC_PROJECT_ID"];
|
|
40637
|
+
if (raw !== void 0 && raw !== "") return env;
|
|
40638
|
+
return { ...env, DH_WC_PROJECT_ID: DEFAULT_WC_PROJECT_ID };
|
|
40639
|
+
}
|
|
40640
|
+
function wcEnabled(env) {
|
|
40641
|
+
return resolvedWcProjectId(env) !== void 0;
|
|
40642
|
+
}
|
|
40643
|
+
function resolvedWcProjectId(env) {
|
|
40644
|
+
return resolveWcProjectId(env?.["DH_WC_PROJECT_ID"], []);
|
|
40645
|
+
}
|
|
40646
|
+
function resolveWcProjectId(raw, problems) {
|
|
40647
|
+
if (raw === void 0 || raw === "" || raw === WC_DISABLED) return void 0;
|
|
40648
|
+
if (!/^[0-9a-f]{32}$/.test(raw)) {
|
|
40649
|
+
problems.push(`DH_WC_PROJECT_ID must be a 32-char hex WalletConnect project id, or '${WC_DISABLED}' to disable WalletConnect.`);
|
|
40650
|
+
return void 0;
|
|
40651
|
+
}
|
|
40652
|
+
return raw;
|
|
40653
|
+
}
|
|
40631
40654
|
var NETWORK_DEFAULTS = {
|
|
40632
40655
|
sepolia: {
|
|
40633
40656
|
rpcUrl: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
@@ -40702,10 +40725,7 @@ function resolveBoundaryConfig(env) {
|
|
|
40702
40725
|
}
|
|
40703
40726
|
const bridgeUrlFile = env["DH_BRIDGE_URL_FILE"];
|
|
40704
40727
|
const bridgeOpenRaw = env["DH_BRIDGE_OPEN"];
|
|
40705
|
-
const wcProjectId = env["DH_WC_PROJECT_ID"];
|
|
40706
|
-
if (wcProjectId !== void 0 && wcProjectId !== "" && !/^[0-9a-f]{32}$/.test(wcProjectId)) {
|
|
40707
|
-
problems.push("DH_WC_PROJECT_ID must be a 32-char hex WalletConnect project id.");
|
|
40708
|
-
}
|
|
40728
|
+
const wcProjectId = resolveWcProjectId(env["DH_WC_PROJECT_ID"], problems);
|
|
40709
40729
|
let bridgeOpenBrowser;
|
|
40710
40730
|
if (bridgeOpenRaw !== void 0 && bridgeOpenRaw !== "") {
|
|
40711
40731
|
if (bridgeOpenRaw !== "0" && bridgeOpenRaw !== "1") {
|
|
@@ -40777,10 +40797,7 @@ function resolveRealConfig(env) {
|
|
|
40777
40797
|
const stateDir = env["DH_STATE_DIR"];
|
|
40778
40798
|
const bridgeUrlFile = env["DH_BRIDGE_URL_FILE"];
|
|
40779
40799
|
const bridgeOpenRaw = env["DH_BRIDGE_OPEN"];
|
|
40780
|
-
const wcProjectId = env["DH_WC_PROJECT_ID"];
|
|
40781
|
-
if (wcProjectId !== void 0 && wcProjectId !== "" && !/^[0-9a-f]{32}$/.test(wcProjectId)) {
|
|
40782
|
-
problems.push("DH_WC_PROJECT_ID must be a 32-char hex WalletConnect project id.");
|
|
40783
|
-
}
|
|
40800
|
+
const wcProjectId = resolveWcProjectId(env["DH_WC_PROJECT_ID"], problems);
|
|
40784
40801
|
let bridgeOpenBrowser;
|
|
40785
40802
|
if (bridgeOpenRaw !== void 0 && bridgeOpenRaw !== "") {
|
|
40786
40803
|
if (bridgeOpenRaw !== "0" && bridgeOpenRaw !== "1") {
|
|
@@ -41220,8 +41237,15 @@ var BoundaryCore = class {
|
|
|
41220
41237
|
return r.ok ? okEnvelope({ terms: r.value }, r.source) : errEnvelope(failureToError(r.failure));
|
|
41221
41238
|
}
|
|
41222
41239
|
// ---- PSM reads (plan 08 Part B Phase R) ----
|
|
41223
|
-
|
|
41224
|
-
|
|
41240
|
+
/** Which stablecoins this PSM supports. There is deliberately NO default: the caller
|
|
41241
|
+
* names the coin, and this is how they learn what they may name. */
|
|
41242
|
+
async listPsmStablecoins() {
|
|
41243
|
+
const r = await this.deps.plugin.chain.listPsmStablecoins();
|
|
41244
|
+
if (!r.ok) return errEnvelope(failureToError(r.failure));
|
|
41245
|
+
return okEnvelope(r.value, r.source);
|
|
41246
|
+
}
|
|
41247
|
+
async getPsmStatus(p) {
|
|
41248
|
+
const r = await this.deps.plugin.chain.getPsmStatus(p);
|
|
41225
41249
|
if (!r.ok) return errEnvelope(failureToError(r.failure));
|
|
41226
41250
|
return okEnvelope(this.psmStatusData(r.value), r.source);
|
|
41227
41251
|
}
|
|
@@ -41232,7 +41256,7 @@ var BoundaryCore = class {
|
|
|
41232
41256
|
* refusal taxonomy and the decimals/fee identity for its cards). `status` is non-null
|
|
41233
41257
|
* whenever `env.ok`. */
|
|
41234
41258
|
async psmQuoteWithStatus(p) {
|
|
41235
|
-
const statusR = await this.deps.plugin.chain.getPsmStatus();
|
|
41259
|
+
const statusR = await this.deps.plugin.chain.getPsmStatus({ stablecoin: p.stablecoin });
|
|
41236
41260
|
if (!statusR.ok) return { env: errEnvelope(failureToError(statusR.failure)), status: null };
|
|
41237
41261
|
const s = statusR.value;
|
|
41238
41262
|
const toUcd = p.direction === "to-ucd";
|
|
@@ -41288,6 +41312,7 @@ var BoundaryCore = class {
|
|
|
41288
41312
|
);
|
|
41289
41313
|
}
|
|
41290
41314
|
const quoteR = await this.deps.plugin.chain.getPsmQuote({
|
|
41315
|
+
stablecoin: p.stablecoin,
|
|
41291
41316
|
direction: toUcd ? "swap" : "redeem",
|
|
41292
41317
|
amountIn: amountIn.toString()
|
|
41293
41318
|
});
|
|
@@ -41354,6 +41379,7 @@ var BoundaryCore = class {
|
|
|
41354
41379
|
let floor = amountOut - amountOut * BigInt(PSM_FLOOR_TOLERANCE_BPS) / 10000n;
|
|
41355
41380
|
if (floor === 0n) floor = 1n;
|
|
41356
41381
|
const r = await this.deps.plugin.ops.psmSwap({
|
|
41382
|
+
stablecoin: p.stablecoin,
|
|
41357
41383
|
direction: q.contractCall,
|
|
41358
41384
|
amountIn: q.amountIn,
|
|
41359
41385
|
minOut: floor.toString(),
|
|
@@ -41453,7 +41479,7 @@ var BoundaryCore = class {
|
|
|
41453
41479
|
feeToken: "UCD",
|
|
41454
41480
|
perBlockCap: s.maxSwapVolumePerBlock
|
|
41455
41481
|
}),
|
|
41456
|
-
|
|
41482
|
+
fromUcd: direction({
|
|
41457
41483
|
minAmount: s.minRedeemAmount,
|
|
41458
41484
|
maxAmount: s.maxRedeemAmount,
|
|
41459
41485
|
amountUnit: ucdUnit,
|
|
@@ -43278,7 +43304,7 @@ var SINK_CONTRACTS = {
|
|
|
43278
43304
|
PositionManager: sinkAddress("PositionManager"),
|
|
43279
43305
|
UCDToken: sinkAddress("UCDToken"),
|
|
43280
43306
|
// PSM pair (plan 08 W1): the exchange's asymmetric approval targets/spenders —
|
|
43281
|
-
// to-ucd approves UsdcToken → SimplePSMV2;
|
|
43307
|
+
// to-ucd approves UsdcToken → SimplePSMV2; from-ucd approves UCDToken → UCDController.
|
|
43282
43308
|
SimplePSMV2: sinkAddress("SimplePSMV2"),
|
|
43283
43309
|
UsdcToken: sinkAddress("UsdcToken"),
|
|
43284
43310
|
UCDController: sinkAddress("UCDController")
|
|
@@ -43574,7 +43600,18 @@ var MockUpstreamPlugin = class {
|
|
|
43574
43600
|
getHead: () => this.read("mock-chain", () => upOk({ height: this.world.state.events.length }, this.src("mock-chain"))),
|
|
43575
43601
|
// PSM sim (plan 08 Part B Phase R): seeded from the sepolia fixture snapshot; the
|
|
43576
43602
|
// mock's addresses are honest labels — the mock never fabricates chain-looking values.
|
|
43577
|
-
|
|
43603
|
+
// The practice world models ONE stablecoin, and says so rather than implying a
|
|
43604
|
+
// choice it cannot honour: the caller must still NAME a coin (no default anywhere),
|
|
43605
|
+
// and naming anything but this one is refused the same way the real adapter refuses
|
|
43606
|
+
// an unsupported address — a mock that accepted any name would teach a habit the
|
|
43607
|
+
// real protocol punishes.
|
|
43608
|
+
listPsmStablecoins: () => this.read(
|
|
43609
|
+
"mock-chain",
|
|
43610
|
+
() => upOk([{ address: "mock-usdc", symbol: "USDC", decimals: this.world.psmSeed().stablecoinDecimals }], this.src("mock-chain"))
|
|
43611
|
+
),
|
|
43612
|
+
getPsmStatus: (p) => this.read("mock-chain", () => {
|
|
43613
|
+
const known = this.mockStablecoinRefusal(p.stablecoin);
|
|
43614
|
+
if (known) return known;
|
|
43578
43615
|
const psm = this.world.psmSeed();
|
|
43579
43616
|
return upOk(
|
|
43580
43617
|
{
|
|
@@ -43599,6 +43636,8 @@ var MockUpstreamPlugin = class {
|
|
|
43599
43636
|
);
|
|
43600
43637
|
}),
|
|
43601
43638
|
getPsmQuote: (p) => this.read("mock-chain", () => {
|
|
43639
|
+
const known = this.mockStablecoinRefusal(p.stablecoin);
|
|
43640
|
+
if (known) return known;
|
|
43602
43641
|
const q = p.direction === "swap" ? this.world.psmSwapQuote(BigInt(p.amountIn)) : this.world.psmRedeemQuote(BigInt(p.amountIn));
|
|
43603
43642
|
return upOk({ amountOut: q.out.toString(), feeAmount: q.fee.toString() }, this.src("mock-chain"));
|
|
43604
43643
|
})
|
|
@@ -43723,6 +43762,19 @@ var MockUpstreamPlugin = class {
|
|
|
43723
43762
|
return apply();
|
|
43724
43763
|
}
|
|
43725
43764
|
/** Mode `none`: every write answers with the conversational setup invitation. */
|
|
43765
|
+
/** The practice world supports exactly one PSM stablecoin. A name that is not it is
|
|
43766
|
+
* refused with the same shape the real adapter uses for an address the chain does not
|
|
43767
|
+
* list — so practising the choose-a-coin habit here fails the same way it would there,
|
|
43768
|
+
* instead of silently succeeding and teaching that any name works. */
|
|
43769
|
+
mockStablecoinRefusal(stablecoin) {
|
|
43770
|
+
const chosen = stablecoin.trim().toLowerCase();
|
|
43771
|
+
if (chosen === "mock-usdc" || chosen === "usdc") return null;
|
|
43772
|
+
return upFail({
|
|
43773
|
+
kind: "rejected",
|
|
43774
|
+
source: "mock-chain",
|
|
43775
|
+
message: `'${stablecoin}' is not a PSM-supported stablecoin in this practice world \u2014 it supports 'USDC' only. Read protocol://psm for the coins a deployment actually supports; there is no default coin on any tier.`
|
|
43776
|
+
});
|
|
43777
|
+
}
|
|
43726
43778
|
noneRefusal() {
|
|
43727
43779
|
if (this.signer && this.signer.manager.mode() === "none") {
|
|
43728
43780
|
return upFail({ kind: "signer-missing", source: "signer-setup", message: this.signer.manager.invitation() });
|
|
@@ -78606,6 +78658,19 @@ function listPositionsQuery(f) {
|
|
|
78606
78658
|
}
|
|
78607
78659
|
return { document: LIST_POSITIONS, variables: { first, skip } };
|
|
78608
78660
|
}
|
|
78661
|
+
var SUPPORTED_STABLECOINS = `
|
|
78662
|
+
query SupportedStablecoins {
|
|
78663
|
+
supportedStablecoins(where: { isSupported: true }, orderBy: addedAt, orderDirection: desc) {
|
|
78664
|
+
id
|
|
78665
|
+
address
|
|
78666
|
+
isSupported
|
|
78667
|
+
decimals
|
|
78668
|
+
entryFee
|
|
78669
|
+
exitFee
|
|
78670
|
+
reserves
|
|
78671
|
+
}
|
|
78672
|
+
}
|
|
78673
|
+
`;
|
|
78609
78674
|
|
|
78610
78675
|
// src/boundary/upstream/real/psm-calls.ts
|
|
78611
78676
|
var import_ethers31 = require("ethers");
|
|
@@ -78745,6 +78810,11 @@ var PsmCalls = class {
|
|
|
78745
78810
|
return { ucdWei: ucdWei.toString(), stablecoinUnits: stablecoinUnits.toString() };
|
|
78746
78811
|
});
|
|
78747
78812
|
}
|
|
78813
|
+
/** The token's own symbol, read at construction. The caller names the coin by this word,
|
|
78814
|
+
* so it must come from the token rather than from a per-network assumption. */
|
|
78815
|
+
symbol() {
|
|
78816
|
+
return this.deps.stablecoinSymbol;
|
|
78817
|
+
}
|
|
78748
78818
|
async status() {
|
|
78749
78819
|
return this.call(async () => {
|
|
78750
78820
|
const s = this.deps.stablecoinAddress;
|
|
@@ -79204,13 +79274,6 @@ function buildValidationContext(network, chainId) {
|
|
|
79204
79274
|
}
|
|
79205
79275
|
|
|
79206
79276
|
// src/boundary/upstream/real/write-ops.ts
|
|
79207
|
-
function psmMainnetWriteRefusal(network, chainId) {
|
|
79208
|
-
return {
|
|
79209
|
-
kind: "rejected",
|
|
79210
|
-
source: SOURCE5,
|
|
79211
|
-
message: `psmSwap is refused (MAINNET_WRITES_DISABLED): PSM writes are enabled on sepolia ONLY, and this process is configured for network '${network}' (chainId ${chainId}) \u2014 the PSM-specific sepolia-only anchor; mainnet PSM operations await their dedicated security review. No ceremony was started and no signer was touched. PSM reads (psm_quote, protocol://psm) remain available. Loan operations are NOT affected by this gate.`
|
|
79212
|
-
};
|
|
79213
|
-
}
|
|
79214
79277
|
var SOURCE5 = "real-ops";
|
|
79215
79278
|
var OP_LAYOUT = "dh-op-envelope-v1";
|
|
79216
79279
|
function randomNonceHex() {
|
|
@@ -79558,8 +79621,7 @@ function buildWriteOps(deps) {
|
|
|
79558
79621
|
* keystore-signed and broadcast through `/api/lit/broadcast` (the existing sepolia
|
|
79559
79622
|
* write pattern). NOT live-run in this delivery — Phase S is Master-gated. */
|
|
79560
79623
|
psmSwap: async (p) => {
|
|
79561
|
-
|
|
79562
|
-
const pr = deps.psm();
|
|
79624
|
+
const pr = await deps.psm(p.stablecoin);
|
|
79563
79625
|
if (!pr.ok) return upFail(pr.failure);
|
|
79564
79626
|
const calls = pr.calls;
|
|
79565
79627
|
const addr = calls.addresses();
|
|
@@ -79940,6 +80002,9 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers37.ether
|
|
|
79940
80002
|
);
|
|
79941
80003
|
}
|
|
79942
80004
|
const hashHex = import_ethers37.ethers.hexlify(bytes).toLowerCase();
|
|
80005
|
+
const nowMs = (this.deps.clock ?? Date.now)();
|
|
80006
|
+
const expiresAtSec = nextQuantumTimestamp(nowMs);
|
|
80007
|
+
const secondsLeft = Math.max(0, expiresAtSec - Math.floor(nowMs / 1e3));
|
|
79943
80008
|
const outcome = await this.deps.bridge.requestSignature({
|
|
79944
80009
|
id: (0, import_node_crypto5.randomUUID)(),
|
|
79945
80010
|
kind: "personal-sign",
|
|
@@ -79951,15 +80016,16 @@ var BridgeEthersSigner = class _BridgeEthersSigner extends import_ethers37.ether
|
|
|
79951
80016
|
"(identical to how diamondhands.credit signs withdrawals).",
|
|
79952
80017
|
"Approve ONLY if you initiated this exact BTC withdrawal in the conversation.",
|
|
79953
80018
|
"",
|
|
79954
|
-
"SIGN NOW \u2014 this one is on a clock
|
|
79955
|
-
`
|
|
79956
|
-
"
|
|
79957
|
-
"
|
|
79958
|
-
"
|
|
79959
|
-
"start again rather than signing something you have not finished reading."
|
|
80019
|
+
"SIGN NOW \u2014 this one is on a clock, and here is the actual deadline:",
|
|
80020
|
+
` expires at ${new Date(expiresAtSec * 1e3).toISOString().slice(11, 19)} UTC \u2014 ${secondsLeft} second${secondsLeft === 1 ? "" : "s"} from when this card was raised`,
|
|
80021
|
+
"The approval page allows far longer than this; the PAYLOAD does not. If it expires",
|
|
80022
|
+
"the signature is refused, the withdrawal does not complete, and the reserved coins",
|
|
80023
|
+
"stay reserved until that is cleared. If the number above is already small, decline",
|
|
80024
|
+
"and start again rather than signing something you have not finished reading."
|
|
79960
80025
|
],
|
|
79961
80026
|
expectedSigner: this.deps.borrower,
|
|
79962
80027
|
chainId: this.deps.chainId,
|
|
80028
|
+
expiresAtSec,
|
|
79963
80029
|
personalSign: { layout: RAW_HASH_LAYOUT, fields: { hash: hashHex }, hashHex }
|
|
79964
80030
|
});
|
|
79965
80031
|
if (outcome.status !== "approved" || !outcome.signature) {
|
|
@@ -80163,13 +80229,27 @@ var RealUpstreamPlugin = class {
|
|
|
80163
80229
|
getHead: () => this.chainRead(async () => ({ height: await this.provider.getBlockNumber() })),
|
|
80164
80230
|
// PSM reads (plan 08 Part B Phase R): on-chain views ONLY, through the dedicated
|
|
80165
80231
|
// wrapper (NOT chainRead) so custom-error refusals decode WITH their figures.
|
|
80166
|
-
|
|
80167
|
-
const
|
|
80168
|
-
|
|
80232
|
+
listPsmStablecoins: async () => {
|
|
80233
|
+
const listed = await this.listSupportedStablecoins();
|
|
80234
|
+
if (!listed.ok) return listed;
|
|
80235
|
+
const rows = await Promise.all(
|
|
80236
|
+
listed.rows.map(async (row) => {
|
|
80237
|
+
const built = await this.psmCallsFor(row.address);
|
|
80238
|
+
return built.ok ? { address: row.address, symbol: built.calls.symbol(), decimals: row.decimals } : null;
|
|
80239
|
+
})
|
|
80240
|
+
);
|
|
80241
|
+
return upOk(
|
|
80242
|
+
rows.filter((r) => r !== null),
|
|
80243
|
+
this.src("subgraph")
|
|
80244
|
+
);
|
|
80169
80245
|
},
|
|
80170
|
-
|
|
80171
|
-
const r = this.
|
|
80172
|
-
|
|
80246
|
+
getPsmStatus: async (p) => {
|
|
80247
|
+
const r = await this.psmCallsFor(p.stablecoin);
|
|
80248
|
+
return r.ok ? r.calls.status() : upFail(r.failure);
|
|
80249
|
+
},
|
|
80250
|
+
getPsmQuote: async (p) => {
|
|
80251
|
+
const r = await this.psmCallsFor(p.stablecoin);
|
|
80252
|
+
if (!r.ok) return upFail(r.failure);
|
|
80173
80253
|
return p.direction === "swap" ? r.calls.swapQuote(p.amountIn) : r.calls.redemptionQuote(p.amountIn);
|
|
80174
80254
|
}
|
|
80175
80255
|
};
|
|
@@ -80237,12 +80317,13 @@ var RealUpstreamPlugin = class {
|
|
|
80237
80317
|
allowlistWithdrawalAddress: () => readOnly("allowlistWithdrawalAddress"),
|
|
80238
80318
|
delegationSetup: () => readOnly("delegationSetup"),
|
|
80239
80319
|
delegationGrant: () => readOnly("delegationGrant"),
|
|
80240
|
-
//
|
|
80241
|
-
//
|
|
80242
|
-
//
|
|
80243
|
-
//
|
|
80320
|
+
// The plan-08 M8-7/M8-14 mainnet standing block was anchored here too, and is
|
|
80321
|
+
// removed with its twin in write-ops.ts (2026-09-10, Master's instruction). On a
|
|
80322
|
+
// signerless boot the honest refusal was always the missing signer; the network
|
|
80323
|
+
// gate sat in front of it and answered first. Now there is one reason left, and it
|
|
80324
|
+
// is the true one on this path.
|
|
80244
80325
|
psmSwap: () => Promise.resolve(
|
|
80245
|
-
|
|
80326
|
+
upFail({
|
|
80246
80327
|
kind: "signer-missing",
|
|
80247
80328
|
source: "real-ops",
|
|
80248
80329
|
message: "no signer configured \u2014 psmSwap signs two on-chain transactions (exact-amount approve, then swap/redeem) with the keystore signer. Set DH_KEYSTORE_PATH and DH_KEYSTORE_PASSWORD to enable it."
|
|
@@ -80359,7 +80440,7 @@ var RealUpstreamPlugin = class {
|
|
|
80359
80440
|
session,
|
|
80360
80441
|
getWriteSdk: () => this.sdkCache.get(key) ?? null,
|
|
80361
80442
|
readDetails: (id) => this.readPositionDetails(id),
|
|
80362
|
-
psm: () => this.
|
|
80443
|
+
psm: (stablecoin) => this.psmCallsFor(stablecoin),
|
|
80363
80444
|
assertValidatorConfigured: () => this.assertValidatorConfigured()
|
|
80364
80445
|
});
|
|
80365
80446
|
}
|
|
@@ -80493,7 +80574,7 @@ var RealUpstreamPlugin = class {
|
|
|
80493
80574
|
session,
|
|
80494
80575
|
getWriteSdk: () => this.sdkCache.get(key) ?? null,
|
|
80495
80576
|
readDetails: (id) => this.readPositionDetails(id),
|
|
80496
|
-
psm: () => this.
|
|
80577
|
+
psm: (stablecoin) => this.psmCallsFor(stablecoin),
|
|
80497
80578
|
assertValidatorConfigured: () => this.assertValidatorConfigured()
|
|
80498
80579
|
});
|
|
80499
80580
|
this.opsGatewayCache.set(key, gateway);
|
|
@@ -80639,35 +80720,91 @@ var RealUpstreamPlugin = class {
|
|
|
80639
80720
|
* (never invented): sepolia runs the self-mintable mock USDC; the MAINNET table carries
|
|
80640
80721
|
* SimplePSMV2 but NO stablecoin address — mainnet PSM reads refuse typed rather than
|
|
80641
80722
|
* guess the Circle USDC address (reads-verify only, and only once the table names it). */
|
|
80642
|
-
|
|
80643
|
-
|
|
80644
|
-
|
|
80723
|
+
/** One wrapper per stablecoin — the PSM supports several and each has its own decimals,
|
|
80724
|
+
* fees and reserves, so a single cached wrapper would answer for the wrong coin. */
|
|
80725
|
+
psmWrappers = /* @__PURE__ */ new Map();
|
|
80726
|
+
/**
|
|
80727
|
+
* The PSM's supported stablecoins, from the indexer (2026-09-10, mainnet PSM enablement).
|
|
80728
|
+
*
|
|
80729
|
+
* This replaced a deployment-table lookup that hardcoded ONE coin per network — sepolia's
|
|
80730
|
+
* mock USDC, and on mainnet an address the table did not carry at all, so mainnet PSM
|
|
80731
|
+
* refused before it ever reached the write gate. Which coins the PSM supports is on-chain
|
|
80732
|
+
* STATE that governance changes, not a constant a package can ship: the SDK's own
|
|
80733
|
+
* `getPSMStablecoins` reads the index for the same reason.
|
|
80734
|
+
*/
|
|
80735
|
+
async listSupportedStablecoins() {
|
|
80736
|
+
const r = await this.graphProxy(
|
|
80737
|
+
SUPPORTED_STABLECOINS,
|
|
80738
|
+
{}
|
|
80739
|
+
);
|
|
80740
|
+
if (!r.ok) return r;
|
|
80741
|
+
const rows = (r.value.data.supportedStablecoins ?? []).map((x) => ({
|
|
80742
|
+
address: String(x.address).toLowerCase(),
|
|
80743
|
+
decimals: Number(x.decimals)
|
|
80744
|
+
}));
|
|
80745
|
+
return { ok: true, rows };
|
|
80746
|
+
}
|
|
80747
|
+
/**
|
|
80748
|
+
* Build the PSM wrapper for ONE caller-chosen stablecoin.
|
|
80749
|
+
*
|
|
80750
|
+
* The choice is re-checked against `supportedStablecoins(address)` on-chain first. The
|
|
80751
|
+
* indexer is how the list is discovered and is not authority over it: it can lag a
|
|
80752
|
+
* governance removal, and acting on a stale list would build a swap the contract reverts
|
|
80753
|
+
* — after the user has approved it in their wallet. List from the index, verify on the
|
|
80754
|
+
* chain, then sign.
|
|
80755
|
+
*/
|
|
80756
|
+
async psmCallsFor(stablecoinAddress) {
|
|
80757
|
+
const key = stablecoinAddress.toLowerCase();
|
|
80758
|
+
const cached = this.psmWrappers.get(key);
|
|
80759
|
+
if (cached) return { ok: true, calls: cached };
|
|
80645
80760
|
const psmAddress = this.contracts["SimplePSMV2"];
|
|
80646
|
-
|
|
80647
|
-
if (!psmAddress || !stablecoinAddress) {
|
|
80648
|
-
const missing = [!psmAddress ? "SimplePSMV2" : null, !stablecoinAddress ? "the PSM stablecoin (USDC)" : null].filter((x) => x !== null).join(" and ");
|
|
80761
|
+
if (!psmAddress) {
|
|
80649
80762
|
return {
|
|
80650
80763
|
ok: false,
|
|
80651
80764
|
failure: {
|
|
80652
80765
|
kind: "unavailable",
|
|
80653
80766
|
source: "chain-rpc",
|
|
80654
|
-
message: `the bundled deployment table has no address
|
|
80767
|
+
message: `the bundled deployment table has no SimplePSMV2 address on ${this.config.network} \u2014 PSM refuses rather than guess an address.`
|
|
80655
80768
|
}
|
|
80656
80769
|
};
|
|
80657
80770
|
}
|
|
80771
|
+
let supported;
|
|
80772
|
+
let symbol;
|
|
80773
|
+
try {
|
|
80774
|
+
const psm = new import_ethers38.ethers.Contract(psmAddress, ["function supportedStablecoins(address) view returns (bool)"], this.provider);
|
|
80775
|
+
supported = await psm["supportedStablecoins"](key);
|
|
80776
|
+
const erc20 = new import_ethers38.ethers.Contract(key, ["function symbol() view returns (string)"], this.provider);
|
|
80777
|
+
symbol = await erc20["symbol"]();
|
|
80778
|
+
} catch (e) {
|
|
80779
|
+
return { ok: false, failure: { kind: "unavailable", source: "chain-rpc", message: `PSM stablecoin check failed for ${key}: ${e.message}` } };
|
|
80780
|
+
}
|
|
80781
|
+
if (!supported) {
|
|
80782
|
+
return {
|
|
80783
|
+
ok: false,
|
|
80784
|
+
failure: {
|
|
80785
|
+
kind: "rejected",
|
|
80786
|
+
source: "chain-rpc",
|
|
80787
|
+
message: `${key} is not a PSM-supported stablecoin on ${this.config.network} (checked on-chain against SimplePSMV2.supportedStablecoins). Read protocol://psm for the coins this deployment actually supports.`
|
|
80788
|
+
}
|
|
80789
|
+
};
|
|
80790
|
+
}
|
|
80791
|
+
const stablecoinAddress2 = key;
|
|
80658
80792
|
const ucdTokenAddress = this.contracts["UCDToken"];
|
|
80659
80793
|
const ucdControllerAddress = this.contracts["UCDController"];
|
|
80660
|
-
|
|
80794
|
+
const built = new PsmCalls({
|
|
80661
80795
|
provider: this.provider,
|
|
80662
80796
|
psmAddress,
|
|
80663
|
-
stablecoinAddress,
|
|
80664
|
-
|
|
80797
|
+
stablecoinAddress: stablecoinAddress2,
|
|
80798
|
+
// Read from the token, never assumed. The old value was the literal "USDC", which
|
|
80799
|
+
// stops being true the moment a second coin is supported.
|
|
80800
|
+
stablecoinSymbol: symbol,
|
|
80665
80801
|
// Write plane (plan 08 W1): the redeem approve leg's spender is the UCDController
|
|
80666
80802
|
// (the PSM burns via controller.burnFromPsm) — table-sourced, never invented.
|
|
80667
80803
|
...ucdTokenAddress ? { ucdTokenAddress } : {},
|
|
80668
80804
|
...ucdControllerAddress ? { ucdControllerAddress } : {}
|
|
80669
80805
|
});
|
|
80670
|
-
|
|
80806
|
+
this.psmWrappers.set(key, built);
|
|
80807
|
+
return { ok: true, calls: built };
|
|
80671
80808
|
}
|
|
80672
80809
|
src(id) {
|
|
80673
80810
|
const kind = id === "subgraph" ? "subgraph" : id === "chain-rpc" ? "chain" : "lit-ops";
|
|
@@ -80930,6 +81067,7 @@ function renderApprovalPage(sessionId, nonce) {
|
|
|
80930
81067
|
<div id="request" class="hidden">
|
|
80931
81068
|
<div id="action" class="action"></div>
|
|
80932
81069
|
<div id="card" class="card"></div>
|
|
81070
|
+
<div id="deadline" class="status hidden"></div>
|
|
80933
81071
|
<button id="approve">Approve in wallet</button>
|
|
80934
81072
|
<button id="reject">Reject</button>
|
|
80935
81073
|
</div>
|
|
@@ -80962,10 +81100,19 @@ const statusEl = document.getElementById("status");
|
|
|
80962
81100
|
const requestEl = document.getElementById("request");
|
|
80963
81101
|
const actionEl = document.getElementById("action");
|
|
80964
81102
|
const cardEl = document.getElementById("card");
|
|
81103
|
+
const approveEl = document.getElementById("approve");
|
|
81104
|
+
const rejectEl = document.getElementById("reject");
|
|
81105
|
+
const deadlineEl = document.getElementById("deadline");
|
|
81106
|
+
let deadlineTimer = null;
|
|
80965
81107
|
const walletEl = document.getElementById("wallet");
|
|
80966
81108
|
let account = null;
|
|
80967
81109
|
let chainId = null;
|
|
80968
81110
|
let current = null;
|
|
81111
|
+
// EVERY pending ceremony, by id \u2014 not just the displayed one. A loopback bridge caps
|
|
81112
|
+
// nothing, so a k-of-n collection and a WalletConnect request can be live at once and
|
|
81113
|
+
// "events" replays both on attach; with a single slot the loser was gone for good, and a
|
|
81114
|
+
// card the page never renders is one the human can neither read nor reject.
|
|
81115
|
+
const pending = new Map();
|
|
80969
81116
|
|
|
80970
81117
|
function post(path, body) {
|
|
80971
81118
|
return fetch(path, {
|
|
@@ -81028,43 +81175,135 @@ async function onAccountsChanged(accounts) {
|
|
|
81028
81175
|
account = (accounts && accounts[0]) || null;
|
|
81029
81176
|
await post(BASE + "wallet-event", { account: account, chainId: chainId });
|
|
81030
81177
|
showWallet();
|
|
81031
|
-
|
|
81178
|
+
invalidatePageRequests("Wallet changed \u2014 pending request invalidated.");
|
|
81032
81179
|
}
|
|
81033
81180
|
|
|
81034
81181
|
async function onChainChanged(cid) {
|
|
81035
81182
|
chainId = typeof cid === "string" ? parseInt(cid, 16) : Number(cid);
|
|
81036
81183
|
await post(BASE + "wallet-event", { account: account, chainId: chainId });
|
|
81037
81184
|
showWallet();
|
|
81038
|
-
|
|
81185
|
+
invalidatePageRequests("Network changed \u2014 pending request invalidated.");
|
|
81039
81186
|
}
|
|
81040
81187
|
|
|
81041
81188
|
function listen() {
|
|
81042
81189
|
const es = new EventSource(BASE + "events?s=" + SESSION);
|
|
81043
|
-
es.onmessage = (ev) => {
|
|
81190
|
+
es.onmessage = (ev) => {
|
|
81191
|
+
const next = JSON.parse(ev.data);
|
|
81192
|
+
// A later frame for an id REPLACES the earlier one: driveWc re-stamps a personal-sign
|
|
81193
|
+
// payload in place and re-pushes it, so the older frame carries a dead hash.
|
|
81194
|
+
pending.set(next.id, next);
|
|
81195
|
+
showPending();
|
|
81196
|
+
};
|
|
81044
81197
|
es.onerror = () => showStatus("Bridge connection lost \u2014 the MCP process may have exited.");
|
|
81045
81198
|
}
|
|
81046
81199
|
|
|
81200
|
+
// A read-only mirror must never displace a card this page can actually decide \u2014 but it
|
|
81201
|
+
// must not be thrown away either, so it waits its turn instead. Among equals the card
|
|
81202
|
+
// already on screen keeps it: reshuffling under a moving cursor is how the wrong thing
|
|
81203
|
+
// gets approved.
|
|
81204
|
+
function pickPending() {
|
|
81205
|
+
const held = current ? pending.get(current.id) : undefined;
|
|
81206
|
+
if (held && held.mirror !== true) return held;
|
|
81207
|
+
let best = held || null;
|
|
81208
|
+
pending.forEach((frame) => {
|
|
81209
|
+
if (!best || (best.mirror === true && frame.mirror !== true)) best = frame;
|
|
81210
|
+
});
|
|
81211
|
+
return best;
|
|
81212
|
+
}
|
|
81213
|
+
|
|
81214
|
+
// "current" stays the DISPLAYED frame \u2014 renderRequest and both click handlers read it.
|
|
81215
|
+
function showPending(emptyText) {
|
|
81216
|
+
const next = pickPending();
|
|
81217
|
+
if (!next) {
|
|
81218
|
+
// The queue drained, so no card owns the clock \u2014 leaving it running would tick down
|
|
81219
|
+
// an expiry for a ceremony that is already decided.
|
|
81220
|
+
stopDeadline();
|
|
81221
|
+
current = null;
|
|
81222
|
+
requestEl.classList.add("hidden");
|
|
81223
|
+
if (emptyText) showStatus(emptyText);
|
|
81224
|
+
return;
|
|
81225
|
+
}
|
|
81226
|
+
current = next;
|
|
81227
|
+
renderRequest();
|
|
81228
|
+
}
|
|
81229
|
+
|
|
81047
81230
|
function renderRequest() {
|
|
81048
81231
|
actionEl.textContent = current.action;
|
|
81049
81232
|
cardEl.textContent = current.card.join("\\n");
|
|
81233
|
+
// Visibility is set on BOTH branches, always. A hidden button is still in the DOM and
|
|
81234
|
+
// still wired, so this is presentation only \u2014 the bridge refuses a mirrored approval
|
|
81235
|
+
// server-side, which is the actual boundary.
|
|
81236
|
+
const mirrored = current.mirror === true;
|
|
81237
|
+
approveEl.classList.toggle("hidden", mirrored);
|
|
81238
|
+
rejectEl.classList.remove("hidden");
|
|
81050
81239
|
requestEl.classList.remove("hidden");
|
|
81051
|
-
showStatus(
|
|
81240
|
+
showStatus(mirrored
|
|
81241
|
+
? "Your mobile wallet is holding this one \u2014 read it here, then approve or decline in the wallet. Reject cancels it from this page."
|
|
81242
|
+
: "Review the operation below. Nothing signs without your approval.");
|
|
81243
|
+
// The countdown belongs to the DISPLAYED card, so it restarts on every render \u2014 a queued
|
|
81244
|
+
// card promoted after another settles gets its own clock, not the previous one's.
|
|
81245
|
+
startDeadline();
|
|
81246
|
+
}
|
|
81247
|
+
|
|
81248
|
+
// C-46: the card's deadline is computed when the card is RAISED, so by the time a human
|
|
81249
|
+
// has read it the number is already wrong. On the BTC-withdraw execute leg the whole
|
|
81250
|
+
// window is under a minute, which makes a stale figure worse than none \u2014 it implies time
|
|
81251
|
+
// the payload does not have. Counting down from the server-supplied instant keeps the page
|
|
81252
|
+
// honest without it needing to know anything about quantum windows.
|
|
81253
|
+
function stopDeadline() {
|
|
81254
|
+
if (deadlineTimer !== null) { clearInterval(deadlineTimer); deadlineTimer = null; }
|
|
81255
|
+
deadlineEl.classList.add("hidden");
|
|
81052
81256
|
}
|
|
81053
81257
|
|
|
81258
|
+
function startDeadline() {
|
|
81259
|
+
stopDeadline();
|
|
81260
|
+
if (!current || typeof current.expiresAtSec !== "number") return;
|
|
81261
|
+
const tick = () => {
|
|
81262
|
+
const left = current.expiresAtSec - Math.floor(Date.now() / 1000);
|
|
81263
|
+
if (left > 0) {
|
|
81264
|
+
deadlineEl.textContent = "This payload expires in " + left + " second" + (left === 1 ? "" : "s") +
|
|
81265
|
+
" \u2014 after that the signature is refused and the withdrawal does not complete.";
|
|
81266
|
+
} else {
|
|
81267
|
+
// Say EXPIRED rather than hiding the line: a user who signs now gets a refusal from
|
|
81268
|
+
// the protocol, and the honest thing is to tell them before the wallet opens, not
|
|
81269
|
+
// after. The button is deliberately left enabled \u2014 declining is still the right
|
|
81270
|
+
// action and the page must not trap them.
|
|
81271
|
+
deadlineEl.textContent = "EXPIRED \u2014 this payload is past its window. Decline and start the withdrawal again.";
|
|
81272
|
+
if (deadlineTimer !== null) { clearInterval(deadlineTimer); deadlineTimer = null; }
|
|
81273
|
+
}
|
|
81274
|
+
deadlineEl.classList.remove("hidden");
|
|
81275
|
+
};
|
|
81276
|
+
tick();
|
|
81277
|
+
deadlineTimer = setInterval(tick, 1000);
|
|
81278
|
+
}
|
|
81279
|
+
|
|
81280
|
+
// Only the ceremony this page just decided leaves the queue. The bridge never announces a
|
|
81281
|
+
// settlement, so anything else it pushed is still live as far as the page can know \u2014 and
|
|
81282
|
+
// blanking the panel over it stranded a phone ceremony with no card and no Reject.
|
|
81054
81283
|
function clearRequest(text) {
|
|
81055
|
-
current
|
|
81056
|
-
|
|
81057
|
-
showStatus(text);
|
|
81284
|
+
if (current) pending.delete(current.id);
|
|
81285
|
+
showPending(text);
|
|
81058
81286
|
}
|
|
81059
81287
|
|
|
81060
|
-
|
|
81288
|
+
// A wallet or network change settles every ceremony THIS page could decide, and the bridge
|
|
81289
|
+
// deliberately spares the ones a phone is holding. Drop what died; the mirror that survived
|
|
81290
|
+
// stays readable and rejectable.
|
|
81291
|
+
function invalidatePageRequests(text) {
|
|
81292
|
+
pending.forEach((frame, id) => { if (frame.mirror !== true) pending.delete(id); });
|
|
81293
|
+
showPending(text); // NOT clearRequest \u2014 that would drop a displayed mirror the bridge kept
|
|
81294
|
+
}
|
|
81295
|
+
|
|
81296
|
+
rejectEl.onclick = async () => {
|
|
81061
81297
|
if (!current) return;
|
|
81062
81298
|
await post(BASE + "result", { requestId: current.id, approved: false, reason: "user declined on the approval page" });
|
|
81063
81299
|
clearRequest("Rejected. Waiting for the next request\u2026");
|
|
81064
81300
|
};
|
|
81065
81301
|
|
|
81066
|
-
|
|
81302
|
+
approveEl.onclick = async () => {
|
|
81067
81303
|
if (!current) return;
|
|
81304
|
+
// Re-checked at the click, not just at render: hiding a button is CSS, and a stale
|
|
81305
|
+
// request or a DOM poke must not open a wallet for a ceremony the phone owns.
|
|
81306
|
+
if (current.mirror === true) { showStatus("This approval belongs to your mobile wallet \u2014 approve it there."); return; }
|
|
81068
81307
|
const req = current;
|
|
81069
81308
|
try {
|
|
81070
81309
|
if (req.kind === "transaction") {
|
|
@@ -81081,7 +81320,10 @@ document.getElementById("approve").onclick = async () => {
|
|
|
81081
81320
|
const fbody = await fr.json();
|
|
81082
81321
|
if (!fr.ok) { showStatus("Cannot prepare the signature right now: " + (fbody.error || "finalize failed") + " \u2014 retry the operation."); return; }
|
|
81083
81322
|
const fresh = fbody.request;
|
|
81084
|
-
// \u2026re-render what will actually sign
|
|
81323
|
+
// \u2026re-render what will actually sign, and put the re-stamped frame in the queue too:
|
|
81324
|
+
// another card arriving while the wallet popup is open re-picks from there, and the
|
|
81325
|
+
// pre-finalize frame would put the OLD hash's card back under an open wallet.
|
|
81326
|
+
pending.set(fresh.id, fresh);
|
|
81085
81327
|
current = fresh; renderRequest();
|
|
81086
81328
|
// \u2026and A0.4: recompute the hash from the DISPLAYED fields. No match, no button.
|
|
81087
81329
|
const recomputed = dhPageCrypto.packAndHash(fresh.personalSign.layout, fresh.personalSign.fields);
|
|
@@ -81264,9 +81506,6 @@ var SignatureBridge = class {
|
|
|
81264
81506
|
/** Plan 17 E2: single-decision concurrency cap (null = unbounded, the loopback tier). */
|
|
81265
81507
|
maxPending;
|
|
81266
81508
|
attachGraceMs;
|
|
81267
|
-
/** Last sweep tick that saw a live attachment — the unattended grace measures from
|
|
81268
|
-
* max(enqueue, this), so a page closed mid-wait gets the same grace as never-opened. */
|
|
81269
|
-
lastAttachedMs = 0;
|
|
81270
81509
|
server = null;
|
|
81271
81510
|
port = 0;
|
|
81272
81511
|
/** Started state independent of the transport binding (mounted bridges own no server). */
|
|
@@ -81417,13 +81656,16 @@ var SignatureBridge = class {
|
|
|
81417
81656
|
enqueuedMs: now,
|
|
81418
81657
|
resolve,
|
|
81419
81658
|
settled: false,
|
|
81420
|
-
...handlers?.finalize ? { finalize: handlers.finalize } : {}
|
|
81659
|
+
...handlers?.finalize ? { finalize: handlers.finalize } : {},
|
|
81660
|
+
owner: this.wcActive ? "wc" : "page",
|
|
81661
|
+
dispatched: false,
|
|
81662
|
+
lastAttachedMs: now
|
|
81421
81663
|
};
|
|
81422
81664
|
this.pending.set(request.id, entry);
|
|
81423
|
-
if (
|
|
81665
|
+
if (entry.owner === "wc") {
|
|
81424
81666
|
void this.driveWc(entry);
|
|
81425
81667
|
} else {
|
|
81426
|
-
this.
|
|
81668
|
+
this.pushEntry(entry);
|
|
81427
81669
|
}
|
|
81428
81670
|
});
|
|
81429
81671
|
}
|
|
@@ -81444,10 +81686,16 @@ var SignatureBridge = class {
|
|
|
81444
81686
|
enqueuedMs: now,
|
|
81445
81687
|
resolve,
|
|
81446
81688
|
settled: false,
|
|
81447
|
-
collect
|
|
81689
|
+
collect,
|
|
81690
|
+
// A collection asks the page AND (below) WalletConnect at once, so it is owned by
|
|
81691
|
+
// BOTH: the read-only card and the `/result` gate must never fire here, or a k-of-n
|
|
81692
|
+
// ceremony could not reach quorum through the very pages it is broadcast to.
|
|
81693
|
+
owner: "both",
|
|
81694
|
+
dispatched: false,
|
|
81695
|
+
lastAttachedMs: now
|
|
81448
81696
|
};
|
|
81449
81697
|
this.pending.set(request.id, entry);
|
|
81450
|
-
this.
|
|
81698
|
+
this.pushEntry(entry);
|
|
81451
81699
|
if (this.wcActive) void this.driveWcCollection(entry);
|
|
81452
81700
|
});
|
|
81453
81701
|
}
|
|
@@ -81486,7 +81734,9 @@ var SignatureBridge = class {
|
|
|
81486
81734
|
}
|
|
81487
81735
|
try {
|
|
81488
81736
|
if (req.kind === "transaction") {
|
|
81737
|
+
this.pushEntry(entry);
|
|
81489
81738
|
const tx2 = req.tx;
|
|
81739
|
+
entry.dispatched = true;
|
|
81490
81740
|
const txHash = await transport.request("eth_sendTransaction", [
|
|
81491
81741
|
{ from: account, to: tx2.to, data: tx2.data, value: tx2.value, ...tx2.gas ? { gas: tx2.gas } : {} }
|
|
81492
81742
|
]);
|
|
@@ -81498,11 +81748,22 @@ var SignatureBridge = class {
|
|
|
81498
81748
|
req.card = fresh.card;
|
|
81499
81749
|
}
|
|
81500
81750
|
const ps = req.personalSign;
|
|
81751
|
+
if (ps.layout === RAW_HASH_LAYOUT && !this.pageAttached()) {
|
|
81752
|
+
this.settle(entry, {
|
|
81753
|
+
status: "invalidated",
|
|
81754
|
+
reason: `this step signs a 32-byte hash your wallet cannot decode, and no approval page is open to show you what it authorizes \u2014 open ${this.url()} and re-run the withdrawal with loan_withdraw_retry (it re-signs with a fresh stamp; your coins stay in the vault meanwhile)`
|
|
81755
|
+
});
|
|
81756
|
+
return;
|
|
81757
|
+
}
|
|
81758
|
+
this.pushEntry(entry);
|
|
81759
|
+
entry.dispatched = true;
|
|
81501
81760
|
const signature = await transport.request("personal_sign", [ps.hashHex, account]);
|
|
81502
81761
|
if (!entry.settled) this.settle(entry, { status: "approved", account, signature });
|
|
81503
81762
|
} else {
|
|
81763
|
+
this.pushEntry(entry);
|
|
81504
81764
|
const { withEip712DomainType: withEip712DomainType2 } = await Promise.resolve().then(() => (init_wc_transport(), wc_transport_exports));
|
|
81505
81765
|
const payload = withEip712DomainType2(req.typedData);
|
|
81766
|
+
entry.dispatched = true;
|
|
81506
81767
|
const signature = await transport.request("eth_signTypedData_v4", [account, JSON.stringify(payload)]);
|
|
81507
81768
|
if (!entry.settled) this.settle(entry, { status: "approved", account, signature });
|
|
81508
81769
|
}
|
|
@@ -81522,30 +81783,55 @@ var SignatureBridge = class {
|
|
|
81522
81783
|
* with a live attachment is in use and must never be evicted. */
|
|
81523
81784
|
attachedNow() {
|
|
81524
81785
|
if (this.wcActive) return true;
|
|
81525
|
-
|
|
81786
|
+
return this.pageAttached();
|
|
81787
|
+
}
|
|
81788
|
+
/** A live approval PAGE specifically — the only surface that can render a card. Excludes
|
|
81789
|
+
* quarantined sessions, which `push` already refuses to write to (C-47): a page that
|
|
81790
|
+
* receives nothing cannot show anything. Distinct from `attachedNow()`, which counts
|
|
81791
|
+
* WalletConnect and must stay global for the connector's eviction predicate. */
|
|
81792
|
+
pageAttached() {
|
|
81793
|
+
for (const s of this.sessions.values()) if (!s.refused && s.sse) return true;
|
|
81526
81794
|
return false;
|
|
81527
81795
|
}
|
|
81796
|
+
/** Attachment for ONE entry — the wallet that entry is actually waiting on. The global
|
|
81797
|
+
* predicate said "a WC session is attached", which is true but irrelevant to a
|
|
81798
|
+
* page-owned request, and vice versa: an entry whose own wallet has gone silently sat
|
|
81799
|
+
* out the full expiry instead of failing fast at the grace. */
|
|
81800
|
+
attachedFor(entry) {
|
|
81801
|
+
if (entry.owner === "wc") return this.wcActive;
|
|
81802
|
+
if (entry.owner === "both") return this.wcActive || this.pageAttached();
|
|
81803
|
+
return this.pageAttached();
|
|
81804
|
+
}
|
|
81528
81805
|
/** Expire overdue requests; fail UNATTENDED requests fast. Runs on a real-time
|
|
81529
81806
|
* interval; tests call it directly with the injected clock advanced. Order matters:
|
|
81530
81807
|
* the deadline is checked first so expiry semantics stay pinned (T-EXT-03). */
|
|
81531
81808
|
sweep() {
|
|
81532
81809
|
const now = this.clock();
|
|
81533
|
-
const attached = this.attachedNow();
|
|
81534
|
-
if (attached) this.lastAttachedMs = now;
|
|
81535
81810
|
for (const entry of this.pending.values()) {
|
|
81536
81811
|
if (entry.settled) continue;
|
|
81537
81812
|
if (now >= entry.deadlineMs) {
|
|
81538
81813
|
this.settle(entry, { status: "expired" });
|
|
81539
81814
|
continue;
|
|
81540
81815
|
}
|
|
81541
|
-
if (
|
|
81542
|
-
|
|
81543
|
-
|
|
81544
|
-
reason: `no wallet approval page is attached to this bridge (it may have been closed) \u2014 open ${this.url()} in the browser, connect the wallet, and retry the operation`
|
|
81545
|
-
});
|
|
81816
|
+
if (this.attachedFor(entry)) {
|
|
81817
|
+
entry.lastAttachedMs = now;
|
|
81818
|
+
continue;
|
|
81546
81819
|
}
|
|
81820
|
+
if (now - Math.max(entry.enqueuedMs, entry.lastAttachedMs) < this.attachGraceMs) continue;
|
|
81821
|
+
this.settle(entry, { status: "invalidated", reason: this.unattendedReason(entry) });
|
|
81547
81822
|
}
|
|
81548
81823
|
}
|
|
81824
|
+
/** Why an unattended ceremony was cut loose — and, for a transaction already sitting on
|
|
81825
|
+
* a phone, the warning that giving up here is not the same as nothing having happened. */
|
|
81826
|
+
unattendedReason(entry) {
|
|
81827
|
+
if (entry.dispatched && entry.request.kind === "transaction") {
|
|
81828
|
+
return "the mobile wallet holding this transaction went away before answering, but it was already asked to send it \u2014 it may have broadcast. Check the chain (or your wallet's activity) before retrying, or you may pay twice.";
|
|
81829
|
+
}
|
|
81830
|
+
if (entry.owner === "wc") {
|
|
81831
|
+
return "the mobile wallet holding this approval went away before answering \u2014 reconnect it, or use the approval page, and retry the operation";
|
|
81832
|
+
}
|
|
81833
|
+
return `no wallet approval page is attached to this bridge (it may have been closed) \u2014 open ${this.url()} in the browser, connect the wallet, and retry the operation`;
|
|
81834
|
+
}
|
|
81549
81835
|
/** A live WalletConnect session exists right now (disconnect reports it truthfully). */
|
|
81550
81836
|
walletConnectActive() {
|
|
81551
81837
|
return this.wcActive;
|
|
@@ -81669,6 +81955,7 @@ var SignatureBridge = class {
|
|
|
81669
81955
|
if (info && refusal) {
|
|
81670
81956
|
this.wcActive = false;
|
|
81671
81957
|
this.rebuildSharedWallet();
|
|
81958
|
+
this.demoteWcEntries();
|
|
81672
81959
|
process.stderr.write(`[bridge] WalletConnect session refused \u2014 ${refusal}
|
|
81673
81960
|
`);
|
|
81674
81961
|
return;
|
|
@@ -81678,7 +81965,10 @@ var SignatureBridge = class {
|
|
|
81678
81965
|
if (info === null) {
|
|
81679
81966
|
for (const entry of this.pending.values()) {
|
|
81680
81967
|
if (!entry.settled && !entry.collect) {
|
|
81681
|
-
this.settle(entry, {
|
|
81968
|
+
this.settle(entry, {
|
|
81969
|
+
status: "invalidated",
|
|
81970
|
+
reason: entry.dispatched && entry.request.kind === "transaction" ? "the WalletConnect session disconnected after being asked to send this transaction \u2014 it may have broadcast. Check the chain (or your wallet's activity) before retrying, or you may pay twice." : "the WalletConnect session disconnected"
|
|
81971
|
+
});
|
|
81682
81972
|
}
|
|
81683
81973
|
}
|
|
81684
81974
|
}
|
|
@@ -81750,9 +82040,7 @@ var SignatureBridge = class {
|
|
|
81750
82040
|
session.sse?.end();
|
|
81751
82041
|
session.sse = res;
|
|
81752
82042
|
for (const entry of this.pending.values()) {
|
|
81753
|
-
if (!entry.settled) res.write(
|
|
81754
|
-
|
|
81755
|
-
`);
|
|
82043
|
+
if (!entry.settled) res.write(this.wireFor(entry));
|
|
81756
82044
|
}
|
|
81757
82045
|
const keepAlive = setInterval(() => res.write(":ka\n\n"), 2e4);
|
|
81758
82046
|
keepAlive.unref();
|
|
@@ -81828,10 +82116,36 @@ var SignatureBridge = class {
|
|
|
81828
82116
|
}
|
|
81829
82117
|
const reason = refusedSwitch ? "the wallet switched to an account this session is not signed in as" : prev && session.wallet && prev.account.toLowerCase() !== session.wallet.account.toLowerCase() ? "the wallet account changed while approval was pending" : prev && session.wallet && prev.chainId !== session.wallet.chainId ? "the wallet network changed while approval was pending" : "the wallet disconnected while approval was pending";
|
|
81830
82118
|
for (const entry of this.pending.values()) {
|
|
81831
|
-
if (
|
|
82119
|
+
if (entry.settled || entry.collect) continue;
|
|
82120
|
+
if (this.ownedByWc(entry)) continue;
|
|
82121
|
+
this.settle(entry, { status: "invalidated", reason });
|
|
81832
82122
|
}
|
|
81833
82123
|
this.ok(res);
|
|
81834
82124
|
}
|
|
82125
|
+
/** Is this ceremony the PHONE's to decide? False once the WC leg is gone, so a dropped
|
|
82126
|
+
* session hands the request back to the page rather than stranding it. */
|
|
82127
|
+
ownedByWc(entry) {
|
|
82128
|
+
if (entry.owner !== "wc") return false;
|
|
82129
|
+
return this.wcActive || entry.dispatched;
|
|
82130
|
+
}
|
|
82131
|
+
/** Give the approval page back the ceremonies a departed WC leg was holding, and re-push
|
|
82132
|
+
* them so the card stops rendering read-only. Collections are already `both`.
|
|
82133
|
+
*
|
|
82134
|
+
* DISPATCHED entries are deliberately left where they are. Handing back a ceremony the
|
|
82135
|
+
* phone is still holding does not replace one wallet with another, it adds a second: the
|
|
82136
|
+
* outstanding `transport.request` is not cancelled by a refused pairing (the refusal path
|
|
82137
|
+
* keeps the transport alive on purpose), so an actionable page card alongside it means
|
|
82138
|
+
* both can approve — and for a transaction that is two broadcasts of the same operation.
|
|
82139
|
+
* Those entries instead fail fast at the per-entry grace, since `attachedFor` now reads
|
|
82140
|
+
* false for them, and `unattendedReason` says plainly that the phone may already have
|
|
82141
|
+
* acted. */
|
|
82142
|
+
demoteWcEntries() {
|
|
82143
|
+
for (const entry of this.pending.values()) {
|
|
82144
|
+
if (entry.settled || entry.owner !== "wc" || entry.dispatched) continue;
|
|
82145
|
+
entry.owner = "page";
|
|
82146
|
+
this.pushEntry(entry);
|
|
82147
|
+
}
|
|
82148
|
+
}
|
|
81835
82149
|
/** Click-time re-stamp (A0.9): returns the FRESH personal-sign payload for a pending
|
|
81836
82150
|
* request. Idempotent for requests without a finalize handler (payload as enqueued). */
|
|
81837
82151
|
async onFinalize(body, res) {
|
|
@@ -81845,6 +82159,10 @@ var SignatureBridge = class {
|
|
|
81845
82159
|
this.deny(res, 400, "finalize applies only to personal-sign requests");
|
|
81846
82160
|
return;
|
|
81847
82161
|
}
|
|
82162
|
+
if (this.ownedByWc(entry)) {
|
|
82163
|
+
this.deny(res, 409, "a mobile wallet is holding this approval \u2014 it is read-only here; approve or decline it in the wallet");
|
|
82164
|
+
return;
|
|
82165
|
+
}
|
|
81848
82166
|
if (entry.finalize) {
|
|
81849
82167
|
let fresh;
|
|
81850
82168
|
try {
|
|
@@ -81871,10 +82189,22 @@ var SignatureBridge = class {
|
|
|
81871
82189
|
return;
|
|
81872
82190
|
}
|
|
81873
82191
|
if (body["approved"] !== true) {
|
|
82192
|
+
if (this.ownedByWc(entry) && entry.request.kind === "transaction") {
|
|
82193
|
+
this.settle(entry, {
|
|
82194
|
+
status: "invalidated",
|
|
82195
|
+
reason: "cancelled on the approval page, but a mobile wallet was already asked to send this transaction \u2014 it may have broadcast already. Check the chain (or your wallet's activity) before retrying, or you may pay twice."
|
|
82196
|
+
});
|
|
82197
|
+
this.ok(res);
|
|
82198
|
+
return;
|
|
82199
|
+
}
|
|
81874
82200
|
this.settle(entry, { status: "rejected", reason: String(body["reason"] ?? "user declined in wallet") });
|
|
81875
82201
|
this.ok(res);
|
|
81876
82202
|
return;
|
|
81877
82203
|
}
|
|
82204
|
+
if (this.ownedByWc(entry)) {
|
|
82205
|
+
this.deny(res, 409, "a mobile wallet is holding this approval \u2014 approve it there; this page is read-only for it");
|
|
82206
|
+
return;
|
|
82207
|
+
}
|
|
81878
82208
|
const account = String(body["account"] ?? "");
|
|
81879
82209
|
if (!/^0x[0-9a-fA-F]{40}$/.test(account)) {
|
|
81880
82210
|
this.deny(res, 400, "approved result requires the signing account");
|
|
@@ -81911,11 +82241,20 @@ var SignatureBridge = class {
|
|
|
81911
82241
|
this.pending.delete(entry.request.id);
|
|
81912
82242
|
entry.resolve(outcome);
|
|
81913
82243
|
}
|
|
81914
|
-
/**
|
|
81915
|
-
|
|
81916
|
-
|
|
82244
|
+
/** The wire form of a pending entry. `mirror` is DERIVED here, every time, and never
|
|
82245
|
+
* written back onto `entry.request`: ownership is mutable (a WC drop demotes to `page`),
|
|
82246
|
+
* `onFinalize` echoes the request object back to the caller, and `driveWc` mutates that
|
|
82247
|
+
* same object in place — a stored flag would leak into all three and go sticky, leaving
|
|
82248
|
+
* a permanently read-only card that nobody is allowed to decide. */
|
|
82249
|
+
wireFor(entry) {
|
|
82250
|
+
const payload = entry.owner === "wc" ? { ...entry.request, mirror: true } : entry.request;
|
|
82251
|
+
return `data: ${JSON.stringify(payload)}
|
|
81917
82252
|
|
|
81918
82253
|
`;
|
|
82254
|
+
}
|
|
82255
|
+
/** Broadcast a pending entry to EVERY open page (multi-owner links — plan 06 §1.5). */
|
|
82256
|
+
pushEntry(entry) {
|
|
82257
|
+
const data = this.wireFor(entry);
|
|
81919
82258
|
for (const s of this.sessions.values()) if (!s.refused) s.sse?.write(data);
|
|
81920
82259
|
}
|
|
81921
82260
|
/** Progress goes out as a NAMED event so `es.onmessage` request handling never sees it. */
|
|
@@ -82398,7 +82737,7 @@ var FIELD_GLOSSARY = {
|
|
|
82398
82737
|
originationFeeBps: "mint fee in basis points of the borrowed amount \u2014 ADDED TO DEBT (200 = 2%)",
|
|
82399
82738
|
extensionFeeRateBps: "extension-fee CEILING in bps of current debt per renewal (unused origination credit reduces it)",
|
|
82400
82739
|
// ---- psm quote ----
|
|
82401
|
-
direction: "'to-ucd' = pay stablecoin, receive UCD; '
|
|
82740
|
+
direction: "'to-ucd' = pay stablecoin, receive UCD; 'from-ucd' = pay UCD, receive stablecoin",
|
|
82402
82741
|
contractCall: "the on-chain function this direction maps to (swap | redeem) \u2014 vocabulary honesty",
|
|
82403
82742
|
amountIn: "what you pay, in amountInUnit of amountInToken (smallest units)",
|
|
82404
82743
|
amountInToken: "the token you pay with",
|
|
@@ -82496,11 +82835,14 @@ var LOCAL_GUIDE_DEPLOYMENT = {
|
|
|
82496
82835
|
// speak the full vocabulary and let the existing adapter prose ("PRACTICE-ONLY today —
|
|
82497
82836
|
// on the real adapter these modes refuse") carry the narrower adapter axis.
|
|
82498
82837
|
signerModes: GUIDE_SIGNER_MODES,
|
|
82499
|
-
// FALSE,
|
|
82500
|
-
//
|
|
82501
|
-
//
|
|
82502
|
-
//
|
|
82503
|
-
//
|
|
82838
|
+
// FALSE as the FALLBACK, which is no longer the same statement as "a default install has
|
|
82839
|
+
// no WalletConnect". Since 2026-09-10 a local install ships a default project id
|
|
82840
|
+
// (`config.ts` DEFAULT_WC_PROJECT_ID), so the real answer for a real local boot is now
|
|
82841
|
+
// usually `true` — and a live boot derives exactly that, from the same resolution the
|
|
82842
|
+
// bridge uses (`network-switch.ts` → `wcEnabled`). This constant is only reached when
|
|
82843
|
+
// nobody supplied a deployment at all, and understating a capability there is the safe
|
|
82844
|
+
// direction: the first draft said `true` "to keep the walkthrough complete", which is the
|
|
82845
|
+
// overclaim C-44 is about — promising a QR the build cannot show.
|
|
82504
82846
|
walletConnect: false
|
|
82505
82847
|
};
|
|
82506
82848
|
function servedNetworks(d) {
|
|
@@ -82511,7 +82853,7 @@ function servedNetworks(d) {
|
|
|
82511
82853
|
return "sepolia (PRACTICE money) and mainnet (REAL MONEY) \u2014 `network_switch` moves between them, and every switch states which is live";
|
|
82512
82854
|
}
|
|
82513
82855
|
if (mainnet) {
|
|
82514
|
-
return "mainnet ONLY \u2014 every fund-moving operation this deployment enables spends REAL MONEY (reads move nothing
|
|
82856
|
+
return "mainnet ONLY \u2014 every fund-moving operation this deployment enables spends REAL MONEY (reads move nothing; PSM swaps are NOT an exception \u2014 they execute here and move real funds), and there is no practice network on this deployment to fall back to";
|
|
82515
82857
|
}
|
|
82516
82858
|
return "sepolia only \u2014 the real contracts on the test network, so the ceremonies are real and the money is PRACTICE";
|
|
82517
82859
|
}
|
|
@@ -82590,13 +82932,14 @@ function switchNetworkRules(d) {
|
|
|
82590
82932
|
the human approves the card. sepolia = practice funds; mainnet = REAL MONEY.
|
|
82591
82933
|
- NOTHING carries across: positions, vaults, signer bindings, logins are per-network.
|
|
82592
82934
|
A sepolia position does not exist on mainnet and vice versa.
|
|
82593
|
-
- Fund-moving
|
|
82594
|
-
and every one still requires the user's explicit
|
|
82595
|
-
ceremony.
|
|
82935
|
+
- Fund-moving operations work on BOTH networks \u2014 loan operations AND PSM swaps alike. On
|
|
82936
|
+
mainnet they move REAL money, and every one still requires the user's explicit
|
|
82937
|
+
confirmation plus the signer ceremony. A PSM swap also requires the caller to NAME the
|
|
82938
|
+
stablecoin; that name is checked against the PSM's on-chain set before anything is
|
|
82939
|
+
signed.`;
|
|
82596
82940
|
}
|
|
82597
82941
|
const only = d.networks[0];
|
|
82598
82942
|
const money = d.networks.includes("mainnet") ? "REAL MONEY" : "PRACTICE funds";
|
|
82599
|
-
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.";
|
|
82600
82943
|
return `- \`network_switch switch { network, confirmed: true }\` exists, but ${only} is the ONLY
|
|
82601
82944
|
network this deployment is rolled out to \u2014 every other target is REFUSED with that
|
|
82602
82945
|
rollout truth. There is nothing to switch TO here; never offer the user another world.
|
|
@@ -82605,7 +82948,9 @@ function switchNetworkRules(d) {
|
|
|
82605
82948
|
belong to ${only} and would not exist anywhere else.
|
|
82606
82949
|
- Fund-moving loan operations run on ${only}, each still requiring the user's explicit
|
|
82607
82950
|
confirmation plus the signer ceremony.
|
|
82608
|
-
- ${
|
|
82951
|
+
- PSM swaps run on ${only} too, under that same confirmation and signer ceremony \u2014 and
|
|
82952
|
+
the caller must NAME the stablecoin, checked against the PSM's on-chain set before
|
|
82953
|
+
anything is signed.`;
|
|
82609
82954
|
}
|
|
82610
82955
|
function wrongNetworkTroubleshootingRow(d) {
|
|
82611
82956
|
if (d.networks.length > 1) {
|
|
@@ -82625,14 +82970,18 @@ function switchNetworkIndexLine(d) {
|
|
|
82625
82970
|
const money = d.networks.includes("mainnet") ? "REAL MONEY" : "PRACTICE funds";
|
|
82626
82971
|
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`;
|
|
82627
82972
|
}
|
|
82628
|
-
function
|
|
82629
|
-
if (d.networks.includes("sepolia"))
|
|
82630
|
-
|
|
82631
|
-
|
|
82632
|
-
\`
|
|
82633
|
-
the
|
|
82634
|
-
|
|
82635
|
-
|
|
82973
|
+
function psmStablecoinRealityNote(d) {
|
|
82974
|
+
if (d.networks.includes("sepolia")) {
|
|
82975
|
+
return `**Practice funding (sepolia):** the sepolia stablecoin is a MOCK USDC with a public
|
|
82976
|
+
\`mint\` \u2014 you can create practice USDC for yourself, self-serve. \`protocol://psm\` states
|
|
82977
|
+
the token's kind (\`mock\` vs \`circle\`) and address so you never have to guess whether
|
|
82978
|
+
the money is real. On mainnet the stablecoin is real Circle USDC.`;
|
|
82979
|
+
}
|
|
82980
|
+
return `**Real money, and no practice path from here.** This deployment is not rolled out to
|
|
82981
|
+
sepolia, so the self-mintable MOCK USDC that funds practice swaps there is out of reach \u2014
|
|
82982
|
+
every swap executed on this deployment moves real Circle USDC and real UCD.
|
|
82983
|
+
\`protocol://psm\` states the token's kind (\`mock\` vs \`circle\`) and address, so you never
|
|
82984
|
+
have to guess whether the money is real.`;
|
|
82636
82985
|
}
|
|
82637
82986
|
function authorizationModeBullets(d) {
|
|
82638
82987
|
const bullets = [];
|
|
@@ -82746,7 +83095,7 @@ on the real adapter and the mock.
|
|
|
82746
83095
|
**The walkthrough:**
|
|
82747
83096
|
1. \`signer_setup\` action \`use\`, mode \`external\`. The approval page auto-opens in the
|
|
82748
83097
|
desktop browser; ${approvalPageLocation(d)}
|
|
82749
|
-
2. On the page: connect the browser extension${d.walletConnect ? ", or \u2014 for a mobile wallet \u2014 scan the\n WalletConnect QR code or paste the pairing code." : ". " + phoneWalletOffer(d) + "."}
|
|
83098
|
+
2. On the page: connect the browser extension${d.walletConnect ? ", or \u2014 for a mobile wallet \u2014 scan the\n WalletConnect QR code or paste the pairing code. KEEP THE APPROVAL PAGE OPEN: while a\n phone wallet is connected the page becomes the READ-ONLY reader for every ceremony \u2014\n it shows the full card, the phone shows only what a wallet can render, and you approve\n or decline in the phone. (Cancel still works from the page.)" : ". " + phoneWalletOffer(d) + "."}
|
|
82750
83099
|
3. For authenticated reads before any write: \`signer_setup\` action \`connect\` runs the
|
|
82751
83100
|
login ceremony explicitly (one typed-data signature in the wallet).
|
|
82752
83101
|
4. The FIRST verified signature binds that wallet address as the borrower \u2014 it persists
|
|
@@ -82785,7 +83134,14 @@ on the real adapter and the mock.
|
|
|
82785
83134
|
hash the SDK builds internally, which the approval page shows bare and says plainly it
|
|
82786
83135
|
cannot decode (the production web app signs the same way). Tell the user before that
|
|
82787
83136
|
ONE popup. Do not describe the typed phase as blind: overstating it teaches them to
|
|
82788
|
-
expect an unreadable card and click through the readable one.
|
|
83137
|
+
expect an unreadable card and click through the readable one.${d.walletConnect ? `
|
|
83138
|
+
- **On a PHONE wallet that EXECUTE step needs the approval page open, and refuses without
|
|
83139
|
+
it.** The phone can only render the bare 32 bytes; everything that makes them meaningful
|
|
83140
|
+
\u2014 which operation, that they cannot be decoded, that the window is under a minute \u2014 lives
|
|
83141
|
+
on the card, and the page is the only surface that shows it. With no page attached the
|
|
83142
|
+
step fails with that reason rather than asking anyone to sign blind. Nothing is lost: the
|
|
83143
|
+
coins stay in the vault and \`loan_withdraw_retry\` re-runs it with a fresh stamp. Tell a
|
|
83144
|
+
mobile user to keep the page open BEFORE they start a withdrawal, not after it refuses.` : ""}
|
|
82789
83145
|
- **The READABLE phase can be asked for up to THREE times.** Its authorization is only
|
|
82790
83146
|
valid inside a short protocol timing window, and the SDK re-signs on a miss \u2014 up to 3
|
|
82791
83147
|
attempts, each a FRESH typed-data card. So a slow approval does not fail; it comes
|
|
@@ -82866,9 +83222,9 @@ State flow: ${STATE_FLOW_LINE} \u2014 see \`safety\`.`,
|
|
|
82866
83222
|
|
|
82867
83223
|
Every fund-moving result carries an \`authorization.card\` \u2014 the exact text that was
|
|
82868
83224
|
signed, amounts included. Read it back when the user asks what happened.`,
|
|
82869
|
-
psm: (d) => `# PSM \u2014 exchanging UCD \u2194
|
|
83225
|
+
psm: (d) => `# PSM \u2014 exchanging UCD \u2194 a stablecoin (the peg-stability module)
|
|
82870
83226
|
|
|
82871
|
-
|
|
83227
|
+
The PSM is the protocol's exchange window between UCD and USDC, near the peg. Two
|
|
82872
83228
|
directions, in user words:
|
|
82873
83229
|
|
|
82874
83230
|
- **"Get UCD for my USDC"** (\`psm_quote\` direction \`to-ucd\`): you pay USDC, the PSM
|
|
@@ -82876,20 +83232,27 @@ directions, in user words:
|
|
|
82876
83232
|
The **entry fee is charged IN UCD**: a percentage (basis points) of the gross converted
|
|
82877
83233
|
UCD, taken before it reaches you \u2014 e.g. at a 1% fee, 100 USDC converts to 100 UCD gross
|
|
82878
83234
|
and you receive 99 UCD.
|
|
82879
|
-
- **"Get
|
|
82880
|
-
and the PSM pays you
|
|
82881
|
-
|
|
82882
|
-
only possible while reserves cover the payout \u2014 the quote shows live
|
|
82883
|
-
shortfall refuses with both figures (available vs required).
|
|
83235
|
+
- **"Get my stablecoin back"** (\`psm_quote\` direction \`from-ucd\`): you return UCD (it is
|
|
83236
|
+
burned) and the PSM pays you that stablecoin **from its live reserves**. The **exit fee
|
|
83237
|
+
is charged IN the stablecoin**, deducted from what you receive; the contract caps it at
|
|
83238
|
+
10%. A redemption is only possible while reserves cover the payout \u2014 the quote shows live
|
|
83239
|
+
reserves, and a shortfall refuses with both figures (available vs required).
|
|
83240
|
+
|
|
83241
|
+
**Both tools REQUIRE a \`stablecoin\`** (symbol like \`USDC\`, or a 0x address). There is no
|
|
83242
|
+
default and that is deliberate: the PSM can carry several coins, each with its own
|
|
83243
|
+
reserves, fees and limits, so picking one silently would move someone's money through a
|
|
83244
|
+
token they never chose. \`protocol://psm\` lists every supported coin \u2014 read the names from
|
|
83245
|
+
there rather than guessing one.
|
|
82884
83246
|
|
|
82885
83247
|
The two fees are independent and live in DIFFERENT tokens \u2014 always say which token a fee
|
|
82886
83248
|
is in. Rates and fees are configuration (\`protocol://psm\` shows them; exchange rate
|
|
82887
83249
|
1e18 = 1:1) and can be changed by protocol governance.
|
|
82888
83250
|
|
|
82889
83251
|
**Limits and switches** (all visible in \`protocol://psm\`):
|
|
82890
|
-
- Each direction has a min and max PER OPERATION
|
|
82891
|
-
units,
|
|
82892
|
-
|
|
83252
|
+
- Each direction has a min and max PER OPERATION, **per coin**. Unit trap: to-ucd limits
|
|
83253
|
+
are in the stablecoin's units, from-ucd limits are in UCD. A max of 0 means that
|
|
83254
|
+
direction is DISABLED.
|
|
83255
|
+
- \`paused\` kills BOTH directions; \`redeemEnabled = false\` kills ONLY the from-ucd
|
|
82893
83256
|
direction (swaps to UCD keep working). These are different switches \u2014 name the right one.
|
|
82894
83257
|
- Per-block volume caps may exist per direction ("uncapped" when none is set).
|
|
82895
83258
|
|
|
@@ -82898,23 +83261,26 @@ floor \u2014 submitting with a zero floor is refused by the contract. Fees or th
|
|
|
82898
83261
|
change between your quote and execution; the floor makes a drifted execution REFUSE
|
|
82899
83262
|
rather than silently deliver less than quoted.
|
|
82900
83263
|
|
|
82901
|
-
|
|
82902
|
-
\`mint\` \u2014 you can create practice USDC for yourself, self-serve. \`protocol://psm\` states
|
|
82903
|
-
the token's kind (\`mock\` vs \`circle\`) and address so you never have to guess whether
|
|
82904
|
-
the money is real. On mainnet the stablecoin is real Circle USDC.
|
|
83264
|
+
${psmStablecoinRealityNote(d)}
|
|
82905
83265
|
|
|
82906
83266
|
**Executing (\`psm_swap\`):** an exchange is TWO on-chain ceremonies, both shown in the
|
|
82907
83267
|
result. (1) An **exact-amount approval** of the input token \u2014 never unlimited. The spender
|
|
82908
83268
|
differs by direction, and that is contract truth, not a quirk: for **to-ucd** you approve
|
|
82909
|
-
|
|
82910
|
-
UCD to the **UCDController** (the PSM burns your UCD through the
|
|
82911
|
-
swap/redeem itself, carrying a minimum-out floor = the live quote minus a 100 bps
|
|
83269
|
+
the stablecoin to the **PSM contract** (it pulls the coin it converts); for **from-ucd**
|
|
83270
|
+
you approve UCD to the **UCDController** (the PSM burns your UCD through the
|
|
83271
|
+
controller). (2) The swap/redeem itself, carrying a minimum-out floor = the live quote minus a 100 bps
|
|
82912
83272
|
tolerance; if fees or the rate drifted beyond that between quote and execution, the
|
|
82913
83273
|
contract refuses \u2014 you never silently receive less. Output always lands at the signer's
|
|
82914
83274
|
own address. If you approve step 1 but decline step 2, the exact-amount allowance remains
|
|
82915
83275
|
standing \u2014 it authorizes only that amount and nothing else; the result says so plainly.
|
|
82916
|
-
|
|
82917
|
-
|
|
83276
|
+
PSM writes are wired on every real network \u2014 mainnet INCLUDED. On mainnet a swap moves
|
|
83277
|
+
REAL money \u2014 real Circle USDC and real UCD. What stands between the user and a
|
|
83278
|
+
wrong move is not a network gate: it is the stablecoin they NAMED (verified against the
|
|
83279
|
+
PSM's supported set on-chain before anything is signed), the explicit confirmation plus
|
|
83280
|
+
signer ceremony every fund-moving operation needs, and the contract's own bounds \u2014 the
|
|
83281
|
+
per-operation and per-block limits,
|
|
83282
|
+
\`paused\` / \`redeemEnabled\`, and live reserves. Say the money reality before the first
|
|
83283
|
+
mainnet swap, not after.`,
|
|
82918
83284
|
authorization: (d) => `# Authorization \u2014 who signs, and what a signature means
|
|
82919
83285
|
|
|
82920
83286
|
Every fund-moving operation needs TWO things, always in this order:
|
|
@@ -83173,9 +83539,11 @@ ${offers(d, "keystore") ? `- **SIGNER_UNAVAILABLE** \u2014 no authorization mode
|
|
|
83173
83539
|
- **"Not logged in" on a read** \u2014 authenticated reads NEVER pop the wallet; the remedy is
|
|
83174
83540
|
the same one: "connect my wallet" (\`signer_setup connect\`). An EXPIRED login refuses
|
|
83175
83541
|
the same way \u2014 reconnect on the user's word.`}
|
|
83176
|
-
|
|
83177
|
-
|
|
83178
|
-
|
|
83542
|
+
- **PSM swap refused** \u2014 never a network gate any more: PSM writes run on every network
|
|
83543
|
+
this build serves. The message names the real cause \u2014 a \`stablecoin\` the PSM does not
|
|
83544
|
+
support (checked on-chain before signing), \`paused\` or \`redeemEnabled = false\`, a
|
|
83545
|
+
per-operation or per-block limit, reserves too thin for the redemption, or no signer.
|
|
83546
|
+
Fix the named cause; reads (\`psm_quote\`, \`protocol://psm\`) keep working regardless.
|
|
83179
83547
|
${wrongNetworkTroubleshootingRow(d)}
|
|
83180
83548
|
- **External-mode withdraw shows a bare hash** \u2014 that is by design (site parity): the
|
|
83181
83549
|
SDK builds the execute-phase hash internally, so the page cannot decode it. ONE blind
|
|
@@ -83333,12 +83701,13 @@ function guideDeployment(overrides, env) {
|
|
|
83333
83701
|
tier: overrides?.bridgeMount ? "hosted" : "local",
|
|
83334
83702
|
networks: overrides?.allowedNetworks ?? LOCAL_GUIDE_DEPLOYMENT.networks,
|
|
83335
83703
|
signerModes: overrides?.externalOnly ? EXTERNAL_ONLY_SIGNER_MODES : LOCAL_GUIDE_DEPLOYMENT.signerModes,
|
|
83336
|
-
// C-44 F8, the fourth derivation.
|
|
83337
|
-
//
|
|
83338
|
-
//
|
|
83339
|
-
//
|
|
83340
|
-
//
|
|
83341
|
-
|
|
83704
|
+
// C-44 F8, the fourth derivation. Resolved through the SAME function the bridge's
|
|
83705
|
+
// config goes through (`wcEnabled` wraps it), so the guide cannot promise a phone-wallet
|
|
83706
|
+
// QR that `/wc-pairing` would answer 404 for. A bare `Boolean(env[...])` was that test
|
|
83707
|
+
// until the leg gained a shipped default and an `off` sentinel — after which absence no
|
|
83708
|
+
// longer means off, and "off" itself is truthy. Deriving rather than hard-coding a tier
|
|
83709
|
+
// default is what keeps the guide and `/auth.md` agreeing about the same server.
|
|
83710
|
+
walletConnect: wcEnabled(env)
|
|
83342
83711
|
};
|
|
83343
83712
|
}
|
|
83344
83713
|
function assembleWorld(opts) {
|
|
@@ -83978,39 +84347,45 @@ function registerPsmTools(server, getB) {
|
|
|
83978
84347
|
server,
|
|
83979
84348
|
"psm_quote",
|
|
83980
84349
|
{
|
|
83981
|
-
title: "Quote a UCD \u2194
|
|
83982
|
-
description: "Quote the PSM exchange (read-only, live on-chain views \u2014 never an indexer). direction 'to-ucd' = pay
|
|
84350
|
+
title: "Quote a UCD \u2194 stablecoin exchange (peg-stability module)",
|
|
84351
|
+
description: "Quote the PSM exchange (read-only, live on-chain views \u2014 never an indexer). direction 'to-ucd' = pay the stablecoin, receive UCD; the ENTRY fee is charged IN UCD on the gross converted amount. direction 'from-ucd' = pay UCD, receive the stablecoin back from the PSM's reserves; the EXIT fee is charged IN that stablecoin and deducted from what you receive. amount is in the INPUT token's user units (to-ucd: the stablecoin; from-ucd: UCD). The result names both amounts, the fee WITH its token, and (from-ucd) the live reserves. Executing an exchange on-chain requires a minimum-out floor \u2014 a zero floor is refused \u2014 so a drifted quote refuses at execution instead of delivering less. Limits and kill-switches: protocol://psm.",
|
|
83983
84352
|
inputSchema: {
|
|
83984
|
-
|
|
83985
|
-
|
|
84353
|
+
stablecoin: import_zod4.z.string().min(1).describe(
|
|
84354
|
+
"The stablecoin to exchange, by SYMBOL (e.g. 'USDC', 'USDT') or by 0x address. REQUIRED and deliberately has NO DEFAULT: the PSM can support several coins, and choosing one for the user would move their money through a token they did not name. Read protocol://psm for the coins this deployment supports. The choice is verified against the PSM contract on-chain before anything signs."
|
|
84355
|
+
),
|
|
84356
|
+
direction: import_zod4.z.enum(["to-ucd", "from-ucd"]).describe("'to-ucd' = pay the stablecoin, get UCD (contract swap); 'from-ucd' = pay UCD, get the stablecoin back (contract redeem)"),
|
|
84357
|
+
amount: import_zod4.z.number().positive().describe("Amount of the INPUT token in user units (to-ucd: the stablecoin; from-ucd: UCD). Max 6 decimals.")
|
|
83986
84358
|
},
|
|
83987
84359
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
83988
84360
|
},
|
|
83989
|
-
async ({ direction, amount }) => guarded(async () => {
|
|
83990
|
-
const label = direction === "to-ucd" ?
|
|
84361
|
+
async ({ stablecoin, direction, amount }) => guarded(async () => {
|
|
84362
|
+
const label = direction === "to-ucd" ? `Amount (${stablecoin})` : "Amount (UCD)";
|
|
83991
84363
|
const problem = checkUcdAmount(amount, label);
|
|
83992
84364
|
if (problem) return validationFailed(problem);
|
|
83993
84365
|
const b = getB();
|
|
83994
84366
|
if (!b.ok) return renderError(b.error);
|
|
83995
|
-
return renderEnvelope(await b.boundary.getPsmQuote({ direction, amount: amount.toString() }));
|
|
84367
|
+
return renderEnvelope(await b.boundary.getPsmQuote({ stablecoin, direction, amount: amount.toString() }));
|
|
83996
84368
|
})
|
|
83997
84369
|
);
|
|
83998
84370
|
registerBoundaryTool(
|
|
83999
84371
|
server,
|
|
84000
84372
|
"psm_swap",
|
|
84001
84373
|
{
|
|
84002
|
-
title: "Exchange UCD \u2194
|
|
84003
|
-
description: "Execute a PSM exchange (irreversible, fund-moving). direction 'to-ucd' = pay
|
|
84374
|
+
title: "Exchange UCD \u2194 a stablecoin through the PSM",
|
|
84375
|
+
description: "Execute a PSM exchange (irreversible, fund-moving). direction 'to-ucd' = pay the stablecoin, receive UCD; 'from-ucd' = pay UCD (burned), receive the stablecoin from the PSM's reserves. Runs as TWO explicit on-chain ceremonies, both signed by the session signer and both reported in the result: (1) an EXACT-AMOUNT approval of the input token \u2014 to-ucd approves the stablecoin to the PSM contract (the PSM pulls the coin it converts); from-ucd approves UCD to the UCDController (the PSM burns UCD through the controller \u2014 a DIFFERENT spender, by design). Never an unlimited approval. (2) the swap/redeem itself, carrying a mandatory minimum-out floor set to the live quote minus a 100 bps tolerance \u2014 a zero floor is refused by the contract, and if the quote drifts beyond the floor the exchange REFUSES rather than delivering less. Output always goes to the signer's own address (the contract pays msg.sender only). Fees: to-ucd charges the entry fee IN UCD on the gross converted amount; from-ucd charges the exit fee IN the stablecoin, deducted from what you receive. amount is in the INPUT token's user units (to-ucd: the stablecoin; from-ucd: UCD). Requires human confirmation (confirmed: true).",
|
|
84004
84376
|
inputSchema: {
|
|
84005
|
-
|
|
84006
|
-
|
|
84377
|
+
stablecoin: import_zod4.z.string().min(1).describe(
|
|
84378
|
+
"The stablecoin to exchange, by SYMBOL (e.g. 'USDC', 'USDT') or by 0x address. REQUIRED and deliberately has NO DEFAULT: the PSM can support several coins, and choosing one for the user would move their money through a token they did not name. Read protocol://psm for the coins this deployment supports. The choice is verified against the PSM contract on-chain before anything signs."
|
|
84379
|
+
),
|
|
84380
|
+
direction: import_zod4.z.enum(["to-ucd", "from-ucd"]).describe("'to-ucd' = pay the stablecoin, get UCD (contract swap); 'from-ucd' = pay UCD, get the stablecoin back (contract redeem)"),
|
|
84381
|
+
amount: import_zod4.z.number().positive().describe("Amount of the INPUT token in user units (to-ucd: the stablecoin; from-ucd: UCD). Max 6 decimals."),
|
|
84007
84382
|
confirmed: confirmedSchema2
|
|
84008
84383
|
},
|
|
84009
84384
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS2
|
|
84010
84385
|
},
|
|
84011
|
-
async ({ direction, amount, confirmed }) => guardedWrite(getB, async () => {
|
|
84012
|
-
const inputToken = direction === "to-ucd" ?
|
|
84013
|
-
const outputToken = direction === "to-ucd" ? "UCD" :
|
|
84386
|
+
async ({ stablecoin, direction, amount, confirmed }) => guardedWrite(getB, async () => {
|
|
84387
|
+
const inputToken = direction === "to-ucd" ? stablecoin : "UCD";
|
|
84388
|
+
const outputToken = direction === "to-ucd" ? "UCD" : stablecoin;
|
|
84014
84389
|
const gate = requireConfirmation(
|
|
84015
84390
|
confirmed,
|
|
84016
84391
|
`exchange ${amount} ${inputToken} for ${outputToken} through the PSM (two ceremonies: exact-amount approve, then ${direction === "to-ucd" ? "swap" : "redeem"})`
|
|
@@ -84020,7 +84395,7 @@ function registerPsmTools(server, getB) {
|
|
|
84020
84395
|
if (problem) return validationFailed(problem);
|
|
84021
84396
|
const b = getB();
|
|
84022
84397
|
if (!b.ok) return renderError(b.error);
|
|
84023
|
-
return renderEnvelope(await b.boundary.psmSwap({ direction, amount: amount.toString() }));
|
|
84398
|
+
return renderEnvelope(await b.boundary.psmSwap({ stablecoin, direction, amount: amount.toString() }));
|
|
84024
84399
|
})
|
|
84025
84400
|
);
|
|
84026
84401
|
}
|
|
@@ -84466,7 +84841,7 @@ function registerNetworkSwitchTool(server, getB, runtime, getSigner) {
|
|
|
84466
84841
|
"network_switch",
|
|
84467
84842
|
{
|
|
84468
84843
|
title: "Show or switch the active network",
|
|
84469
|
-
description: "Which world this server is on \u2014 and switching it by conversation (real adapter). 'status' states the active network and whether money is real. 'switch' moves this session between sepolia (practice funds) and mainnet (REAL MONEY) after an explicit human confirmation; positions, vaults, and signer bindings are per-network and do not carry across. Fund-moving operations work on BOTH networks (on mainnet they move REAL money
|
|
84844
|
+
description: "Which world this server is on \u2014 and switching it by conversation (real adapter). 'status' states the active network and whether money is real. 'switch' moves this session between sepolia (practice funds) and mainnet (REAL MONEY) after an explicit human confirmation; positions, vaults, and signer bindings are per-network and do not carry across. Fund-moving operations work on BOTH networks \u2014 loan operations and PSM swaps alike (on mainnet they move REAL money). The switch lasts for this server session only; the configured default returns on restart. After a switch, re-read boundary://info and STATE the new environment to the user.",
|
|
84470
84845
|
inputSchema: {
|
|
84471
84846
|
action: import_zod8.z.enum(["status", "switch"]).describe("status = current world; switch = change network (needs confirmed:true)"),
|
|
84472
84847
|
network: import_zod8.z.string().optional().describe("switch target: sepolia | mainnet"),
|
|
@@ -84484,7 +84859,7 @@ function registerNetworkSwitchTool(server, getB, runtime, getSigner) {
|
|
|
84484
84859
|
lines.push(
|
|
84485
84860
|
`Switchable networks: ${SWITCHABLE_NETWORKS.join(", ")} (action 'switch', confirmed:true after human approval).`,
|
|
84486
84861
|
"A switch changes worlds entirely: positions, vaults, and signer bindings are per-network.",
|
|
84487
|
-
"Fund-moving operations work on both networks \u2014 on mainnet they move REAL money
|
|
84862
|
+
"Fund-moving operations work on both networks, loan operations and PSM swaps alike \u2014 on mainnet they move REAL money.",
|
|
84488
84863
|
"Session-scoped: the configured default network returns when the server restarts."
|
|
84489
84864
|
);
|
|
84490
84865
|
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
@@ -84590,13 +84965,26 @@ function registerProtocolResources(server, getB) {
|
|
|
84590
84965
|
"protocol://psm",
|
|
84591
84966
|
{
|
|
84592
84967
|
title: "PSM status (UCD \u2194 USDC exchange)",
|
|
84593
|
-
description: "Live SimplePSMV2 state as {data, warnings, source}
|
|
84968
|
+
description: "Live SimplePSMV2 state as {data, warnings, source}. `data` carries network + chainId + psmAddress (the money surface names its chain) and `stablecoins`: EVERY coin this PSM supports, each with its own stablecoinKind (mock = practice token with a public self-serve mint; circle = real USDC), pause + redeemEnabled switches, live reserves, and per-direction fees (WITH their token), min/max (WITH their units \u2014 to-ucd caps in the stablecoin's smallest units, from-ucd caps in UCD wei) and per-block volume caps ('uncapped' when the on-chain cap is 0). This is where a caller learns the coin names that `psm_quote` and `psm_swap` require.",
|
|
84594
84969
|
mimeType: "application/json"
|
|
84595
84970
|
},
|
|
84596
84971
|
async (uri) => {
|
|
84597
84972
|
const b = getB();
|
|
84598
84973
|
if (!b.ok) return { contents: [{ uri: uri.href, mimeType: "application/json", text: resourceErrorJson(b.error) }] };
|
|
84599
|
-
const
|
|
84974
|
+
const listed = await b.boundary.listPsmStablecoins();
|
|
84975
|
+
if (!listed.ok) return { contents: [{ uri: uri.href, mimeType: "application/json", text: resourceJson(listed) }] };
|
|
84976
|
+
const perCoin = await Promise.all(listed.data.map((coin) => b.boundary.getPsmStatus({ stablecoin: coin.address })));
|
|
84977
|
+
const failed = perCoin.find((s) => !s.ok);
|
|
84978
|
+
if (failed && !failed.ok) return { contents: [{ uri: uri.href, mimeType: "application/json", text: resourceErrorJson(failed.error) }] };
|
|
84979
|
+
const coins = perCoin.flatMap((s) => s.ok ? [s.data] : []);
|
|
84980
|
+
const head = coins[0];
|
|
84981
|
+
const env = {
|
|
84982
|
+
...listed,
|
|
84983
|
+
data: {
|
|
84984
|
+
...head ? { network: head.network, chainId: head.chainId, psmAddress: head.psmAddress } : {},
|
|
84985
|
+
stablecoins: coins
|
|
84986
|
+
}
|
|
84987
|
+
};
|
|
84600
84988
|
return { contents: [{ uri: uri.href, mimeType: "application/json", text: resourceJson(env) }] };
|
|
84601
84989
|
}
|
|
84602
84990
|
);
|
|
@@ -84639,7 +85027,7 @@ function registerBoundaryInfoResource(server, getB) {
|
|
|
84639
85027
|
}
|
|
84640
85028
|
|
|
84641
85029
|
// src/version.ts
|
|
84642
|
-
var SERVER_VERSION = "0.5.
|
|
85030
|
+
var SERVER_VERSION = "0.5.15";
|
|
84643
85031
|
|
|
84644
85032
|
// src/server.ts
|
|
84645
85033
|
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.";
|
|
@@ -84684,14 +85072,17 @@ if (process.argv.includes("--version")) {
|
|
|
84684
85072
|
process.exit(0);
|
|
84685
85073
|
}
|
|
84686
85074
|
async function main() {
|
|
84687
|
-
const
|
|
85075
|
+
const localEnv = withLocalWcDefault(process.env);
|
|
85076
|
+
const configResult = resolveBoundaryConfig(localEnv);
|
|
84688
85077
|
let boot = await buildBoundary(configResult);
|
|
84689
85078
|
if (!boot.boundaryResult.ok) {
|
|
84690
85079
|
process.stderr.write(`[dh-mcp] boundary not available: ${boot.boundaryResult.error.message}
|
|
84691
85080
|
`);
|
|
84692
85081
|
}
|
|
84693
85082
|
const world = assembleWorld({
|
|
84694
|
-
env
|
|
85083
|
+
// The SAME resolved env the boundary booted from, so a `network_switch` rebuild does
|
|
85084
|
+
// not silently drop the phone-wallet leg the user started the session with.
|
|
85085
|
+
env: localEnv,
|
|
84695
85086
|
configResult,
|
|
84696
85087
|
boot,
|
|
84697
85088
|
log: (line) => process.stderr.write(`[dh-mcp] ${line}
|