@gvnrdao/dh-mcp 0.2.0 → 0.3.0
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 +37 -12
- package/dist/boundary.js +126 -44
- package/dist/index.js +443 -143
- package/package.json +10 -4
package/dist/index.js
CHANGED
|
@@ -297,9 +297,9 @@ var require_dist = __commonJS({
|
|
|
297
297
|
exports2.bech32m = exports2.bech32 = void 0;
|
|
298
298
|
var ALPHABET2 = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
299
299
|
var ALPHABET_MAP = {};
|
|
300
|
-
for (let
|
|
301
|
-
const x = ALPHABET2.charAt(
|
|
302
|
-
ALPHABET_MAP[x] =
|
|
300
|
+
for (let z9 = 0; z9 < ALPHABET2.length; z9++) {
|
|
301
|
+
const x = ALPHABET2.charAt(z9);
|
|
302
|
+
ALPHABET_MAP[x] = z9;
|
|
303
303
|
}
|
|
304
304
|
function polymodStep(pre) {
|
|
305
305
|
const b = pre >> 25;
|
|
@@ -43143,12 +43143,12 @@ var require_bn = __commonJS({
|
|
|
43143
43143
|
var one = new BN(1).toRed(this);
|
|
43144
43144
|
var nOne = one.redNeg();
|
|
43145
43145
|
var lpow = this.m.subn(1).iushrn(1);
|
|
43146
|
-
var
|
|
43147
|
-
|
|
43148
|
-
while (this.pow(
|
|
43149
|
-
|
|
43146
|
+
var z9 = this.m.bitLength();
|
|
43147
|
+
z9 = new BN(2 * z9 * z9).toRed(this);
|
|
43148
|
+
while (this.pow(z9, lpow).cmp(nOne) !== 0) {
|
|
43149
|
+
z9.redIAdd(nOne);
|
|
43150
43150
|
}
|
|
43151
|
-
var c = this.pow(
|
|
43151
|
+
var c = this.pow(z9, q);
|
|
43152
43152
|
var r = this.pow(a, q.addn(1).iushrn(1));
|
|
43153
43153
|
var t = this.pow(a, q);
|
|
43154
43154
|
var m = s;
|
|
@@ -46026,12 +46026,12 @@ var require_bn2 = __commonJS({
|
|
|
46026
46026
|
var one = new BN(1).toRed(this);
|
|
46027
46027
|
var nOne = one.redNeg();
|
|
46028
46028
|
var lpow = this.m.subn(1).iushrn(1);
|
|
46029
|
-
var
|
|
46030
|
-
|
|
46031
|
-
while (this.pow(
|
|
46032
|
-
|
|
46029
|
+
var z9 = this.m.bitLength();
|
|
46030
|
+
z9 = new BN(2 * z9 * z9).toRed(this);
|
|
46031
|
+
while (this.pow(z9, lpow).cmp(nOne) !== 0) {
|
|
46032
|
+
z9.redIAdd(nOne);
|
|
46033
46033
|
}
|
|
46034
|
-
var c = this.pow(
|
|
46034
|
+
var c = this.pow(z9, q);
|
|
46035
46035
|
var r = this.pow(a, q.addn(1).iushrn(1));
|
|
46036
46036
|
var t = this.pow(a, q);
|
|
46037
46037
|
var m = s;
|
|
@@ -46267,18 +46267,18 @@ var require_utils3 = __commonJS({
|
|
|
46267
46267
|
var ws = 1 << w + 1;
|
|
46268
46268
|
var k = num.clone();
|
|
46269
46269
|
for (i = 0; i < naf.length; i++) {
|
|
46270
|
-
var
|
|
46270
|
+
var z9;
|
|
46271
46271
|
var mod = k.andln(ws - 1);
|
|
46272
46272
|
if (k.isOdd()) {
|
|
46273
46273
|
if (mod > (ws >> 1) - 1)
|
|
46274
|
-
|
|
46274
|
+
z9 = (ws >> 1) - mod;
|
|
46275
46275
|
else
|
|
46276
|
-
|
|
46277
|
-
k.isubn(
|
|
46276
|
+
z9 = mod;
|
|
46277
|
+
k.isubn(z9);
|
|
46278
46278
|
} else {
|
|
46279
|
-
|
|
46279
|
+
z9 = 0;
|
|
46280
46280
|
}
|
|
46281
|
-
naf[i] =
|
|
46281
|
+
naf[i] = z9;
|
|
46282
46282
|
k.iushrn(1);
|
|
46283
46283
|
}
|
|
46284
46284
|
return naf;
|
|
@@ -46491,18 +46491,18 @@ var require_base2 = __commonJS({
|
|
|
46491
46491
|
acc = acc.dblp(l);
|
|
46492
46492
|
if (i < 0)
|
|
46493
46493
|
break;
|
|
46494
|
-
var
|
|
46495
|
-
assert(
|
|
46494
|
+
var z9 = naf[i];
|
|
46495
|
+
assert(z9 !== 0);
|
|
46496
46496
|
if (p.type === "affine") {
|
|
46497
|
-
if (
|
|
46498
|
-
acc = acc.mixedAdd(wnd[
|
|
46497
|
+
if (z9 > 0)
|
|
46498
|
+
acc = acc.mixedAdd(wnd[z9 - 1 >> 1]);
|
|
46499
46499
|
else
|
|
46500
|
-
acc = acc.mixedAdd(wnd[-
|
|
46500
|
+
acc = acc.mixedAdd(wnd[-z9 - 1 >> 1].neg());
|
|
46501
46501
|
} else {
|
|
46502
|
-
if (
|
|
46503
|
-
acc = acc.add(wnd[
|
|
46502
|
+
if (z9 > 0)
|
|
46503
|
+
acc = acc.add(wnd[z9 - 1 >> 1]);
|
|
46504
46504
|
else
|
|
46505
|
-
acc = acc.add(wnd[-
|
|
46505
|
+
acc = acc.add(wnd[-z9 - 1 >> 1].neg());
|
|
46506
46506
|
}
|
|
46507
46507
|
}
|
|
46508
46508
|
return p.type === "affine" ? acc.toP() : acc;
|
|
@@ -46605,14 +46605,14 @@ var require_base2 = __commonJS({
|
|
|
46605
46605
|
if (i < 0)
|
|
46606
46606
|
break;
|
|
46607
46607
|
for (j = 0; j < len; j++) {
|
|
46608
|
-
var
|
|
46608
|
+
var z9 = tmp[j];
|
|
46609
46609
|
p;
|
|
46610
|
-
if (
|
|
46610
|
+
if (z9 === 0)
|
|
46611
46611
|
continue;
|
|
46612
|
-
else if (
|
|
46613
|
-
p = wnd[j][
|
|
46614
|
-
else if (
|
|
46615
|
-
p = wnd[j][-
|
|
46612
|
+
else if (z9 > 0)
|
|
46613
|
+
p = wnd[j][z9 - 1 >> 1];
|
|
46614
|
+
else if (z9 < 0)
|
|
46615
|
+
p = wnd[j][-z9 - 1 >> 1].neg();
|
|
46616
46616
|
if (p.type === "affine")
|
|
46617
46617
|
acc = acc.mixedAdd(p);
|
|
46618
46618
|
else
|
|
@@ -47168,16 +47168,16 @@ var require_short = __commonJS({
|
|
|
47168
47168
|
var res = this.curve.jpoint(this.x, this.y, this.curve.one);
|
|
47169
47169
|
return res;
|
|
47170
47170
|
};
|
|
47171
|
-
function JPoint(curve, x, y,
|
|
47171
|
+
function JPoint(curve, x, y, z9) {
|
|
47172
47172
|
Base.BasePoint.call(this, curve, "jacobian");
|
|
47173
|
-
if (x === null && y === null &&
|
|
47173
|
+
if (x === null && y === null && z9 === null) {
|
|
47174
47174
|
this.x = this.curve.one;
|
|
47175
47175
|
this.y = this.curve.one;
|
|
47176
47176
|
this.z = new BN(0);
|
|
47177
47177
|
} else {
|
|
47178
47178
|
this.x = new BN(x, 16);
|
|
47179
47179
|
this.y = new BN(y, 16);
|
|
47180
|
-
this.z = new BN(
|
|
47180
|
+
this.z = new BN(z9, 16);
|
|
47181
47181
|
}
|
|
47182
47182
|
if (!this.x.red)
|
|
47183
47183
|
this.x = this.x.toRed(this.curve.red);
|
|
@@ -47188,8 +47188,8 @@ var require_short = __commonJS({
|
|
|
47188
47188
|
this.zOne = this.z === this.curve.one;
|
|
47189
47189
|
}
|
|
47190
47190
|
inherits2(JPoint, Base.BasePoint);
|
|
47191
|
-
ShortCurve.prototype.jpoint = function jpoint(x, y,
|
|
47192
|
-
return new JPoint(this, x, y,
|
|
47191
|
+
ShortCurve.prototype.jpoint = function jpoint(x, y, z9) {
|
|
47192
|
+
return new JPoint(this, x, y, z9);
|
|
47193
47193
|
};
|
|
47194
47194
|
JPoint.prototype.toP = function toP() {
|
|
47195
47195
|
if (this.isInfinity())
|
|
@@ -47502,14 +47502,14 @@ var require_mont = __commonJS({
|
|
|
47502
47502
|
var y = rhs.redSqrt();
|
|
47503
47503
|
return y.redSqr().cmp(rhs) === 0;
|
|
47504
47504
|
};
|
|
47505
|
-
function Point(curve, x,
|
|
47505
|
+
function Point(curve, x, z9) {
|
|
47506
47506
|
Base.BasePoint.call(this, curve, "projective");
|
|
47507
|
-
if (x === null &&
|
|
47507
|
+
if (x === null && z9 === null) {
|
|
47508
47508
|
this.x = this.curve.one;
|
|
47509
47509
|
this.z = this.curve.zero;
|
|
47510
47510
|
} else {
|
|
47511
47511
|
this.x = new BN(x, 16);
|
|
47512
|
-
this.z = new BN(
|
|
47512
|
+
this.z = new BN(z9, 16);
|
|
47513
47513
|
if (!this.x.red)
|
|
47514
47514
|
this.x = this.x.toRed(this.curve.red);
|
|
47515
47515
|
if (!this.z.red)
|
|
@@ -47520,8 +47520,8 @@ var require_mont = __commonJS({
|
|
|
47520
47520
|
MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
|
|
47521
47521
|
return this.point(utils.toArray(bytes, enc), 1);
|
|
47522
47522
|
};
|
|
47523
|
-
MontCurve.prototype.point = function point(x,
|
|
47524
|
-
return new Point(this, x,
|
|
47523
|
+
MontCurve.prototype.point = function point(x, z9) {
|
|
47524
|
+
return new Point(this, x, z9);
|
|
47525
47525
|
};
|
|
47526
47526
|
MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
|
|
47527
47527
|
return Point.fromJSON(this, obj);
|
|
@@ -47642,8 +47642,8 @@ var require_edwards = __commonJS({
|
|
|
47642
47642
|
else
|
|
47643
47643
|
return this.c.redMul(num);
|
|
47644
47644
|
};
|
|
47645
|
-
EdwardsCurve.prototype.jpoint = function jpoint(x, y,
|
|
47646
|
-
return this.point(x, y,
|
|
47645
|
+
EdwardsCurve.prototype.jpoint = function jpoint(x, y, z9, t) {
|
|
47646
|
+
return this.point(x, y, z9, t);
|
|
47647
47647
|
};
|
|
47648
47648
|
EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
|
|
47649
47649
|
x = new BN(x, 16);
|
|
@@ -47692,9 +47692,9 @@ var require_edwards = __commonJS({
|
|
|
47692
47692
|
var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
|
|
47693
47693
|
return lhs.cmp(rhs) === 0;
|
|
47694
47694
|
};
|
|
47695
|
-
function Point(curve, x, y,
|
|
47695
|
+
function Point(curve, x, y, z9, t) {
|
|
47696
47696
|
Base.BasePoint.call(this, curve, "projective");
|
|
47697
|
-
if (x === null && y === null &&
|
|
47697
|
+
if (x === null && y === null && z9 === null) {
|
|
47698
47698
|
this.x = this.curve.zero;
|
|
47699
47699
|
this.y = this.curve.one;
|
|
47700
47700
|
this.z = this.curve.one;
|
|
@@ -47703,7 +47703,7 @@ var require_edwards = __commonJS({
|
|
|
47703
47703
|
} else {
|
|
47704
47704
|
this.x = new BN(x, 16);
|
|
47705
47705
|
this.y = new BN(y, 16);
|
|
47706
|
-
this.z =
|
|
47706
|
+
this.z = z9 ? new BN(z9, 16) : this.curve.one;
|
|
47707
47707
|
this.t = t && new BN(t, 16);
|
|
47708
47708
|
if (!this.x.red)
|
|
47709
47709
|
this.x = this.x.toRed(this.curve.red);
|
|
@@ -47725,8 +47725,8 @@ var require_edwards = __commonJS({
|
|
|
47725
47725
|
EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
|
|
47726
47726
|
return Point.fromJSON(this, obj);
|
|
47727
47727
|
};
|
|
47728
|
-
EdwardsCurve.prototype.point = function point(x, y,
|
|
47729
|
-
return new Point(this, x, y,
|
|
47728
|
+
EdwardsCurve.prototype.point = function point(x, y, z9, t) {
|
|
47729
|
+
return new Point(this, x, y, z9, t);
|
|
47730
47730
|
};
|
|
47731
47731
|
Point.fromJSON = function fromJSON(curve, obj) {
|
|
47732
47732
|
return new Point(curve, obj[0], obj[1], obj[2]);
|
|
@@ -48248,25 +48248,25 @@ var require_common4 = __commonJS({
|
|
|
48248
48248
|
"use strict";
|
|
48249
48249
|
var utils = require_utils4();
|
|
48250
48250
|
var rotr32 = utils.rotr32;
|
|
48251
|
-
function ft_1(s, x, y,
|
|
48251
|
+
function ft_1(s, x, y, z9) {
|
|
48252
48252
|
if (s === 0)
|
|
48253
|
-
return ch32(x, y,
|
|
48253
|
+
return ch32(x, y, z9);
|
|
48254
48254
|
if (s === 1 || s === 3)
|
|
48255
|
-
return p32(x, y,
|
|
48255
|
+
return p32(x, y, z9);
|
|
48256
48256
|
if (s === 2)
|
|
48257
|
-
return maj32(x, y,
|
|
48257
|
+
return maj32(x, y, z9);
|
|
48258
48258
|
}
|
|
48259
48259
|
exports2.ft_1 = ft_1;
|
|
48260
|
-
function ch32(x, y,
|
|
48261
|
-
return x & y ^ ~x &
|
|
48260
|
+
function ch32(x, y, z9) {
|
|
48261
|
+
return x & y ^ ~x & z9;
|
|
48262
48262
|
}
|
|
48263
48263
|
exports2.ch32 = ch32;
|
|
48264
|
-
function maj32(x, y,
|
|
48265
|
-
return x & y ^ x &
|
|
48264
|
+
function maj32(x, y, z9) {
|
|
48265
|
+
return x & y ^ x & z9 ^ y & z9;
|
|
48266
48266
|
}
|
|
48267
48267
|
exports2.maj32 = maj32;
|
|
48268
|
-
function p32(x, y,
|
|
48269
|
-
return x ^ y ^
|
|
48268
|
+
function p32(x, y, z9) {
|
|
48269
|
+
return x ^ y ^ z9;
|
|
48270
48270
|
}
|
|
48271
48271
|
exports2.p32 = p32;
|
|
48272
48272
|
function s0_256(x) {
|
|
@@ -49117,17 +49117,17 @@ var require_ripemd = __commonJS({
|
|
|
49117
49117
|
else
|
|
49118
49118
|
return utils.split32(this.h, "little");
|
|
49119
49119
|
};
|
|
49120
|
-
function f(j, x, y,
|
|
49120
|
+
function f(j, x, y, z9) {
|
|
49121
49121
|
if (j <= 15)
|
|
49122
|
-
return x ^ y ^
|
|
49122
|
+
return x ^ y ^ z9;
|
|
49123
49123
|
else if (j <= 31)
|
|
49124
|
-
return x & y | ~x &
|
|
49124
|
+
return x & y | ~x & z9;
|
|
49125
49125
|
else if (j <= 47)
|
|
49126
|
-
return (x | ~y) ^
|
|
49126
|
+
return (x | ~y) ^ z9;
|
|
49127
49127
|
else if (j <= 63)
|
|
49128
|
-
return x &
|
|
49128
|
+
return x & z9 | y & ~z9;
|
|
49129
49129
|
else
|
|
49130
|
-
return x ^ (y | ~
|
|
49130
|
+
return x ^ (y | ~z9);
|
|
49131
49131
|
}
|
|
49132
49132
|
function K(j) {
|
|
49133
49133
|
if (j <= 15)
|
|
@@ -51477,9 +51477,9 @@ var require_dist4 = __commonJS({
|
|
|
51477
51477
|
exports2.bech32m = exports2.bech32 = void 0;
|
|
51478
51478
|
var ALPHABET2 = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
51479
51479
|
var ALPHABET_MAP = {};
|
|
51480
|
-
for (let
|
|
51481
|
-
const x = ALPHABET2.charAt(
|
|
51482
|
-
ALPHABET_MAP[x] =
|
|
51480
|
+
for (let z9 = 0; z9 < ALPHABET2.length; z9++) {
|
|
51481
|
+
const x = ALPHABET2.charAt(z9);
|
|
51482
|
+
ALPHABET_MAP[x] = z9;
|
|
51483
51483
|
}
|
|
51484
51484
|
function polymodStep(pre) {
|
|
51485
51485
|
const b = pre >> 25;
|
|
@@ -52968,6 +52968,14 @@ var BoundaryCore = class {
|
|
|
52968
52968
|
return okEnvelope({ releasedSats: r.value.releasedSats }, r.source);
|
|
52969
52969
|
}
|
|
52970
52970
|
// ---- meta ----
|
|
52971
|
+
world() {
|
|
52972
|
+
return {
|
|
52973
|
+
adapter: this.deps.adapter,
|
|
52974
|
+
network: this.deps.network,
|
|
52975
|
+
chainId: this.deps.chainId,
|
|
52976
|
+
practiceWorld: this.deps.network !== "mainnet"
|
|
52977
|
+
};
|
|
52978
|
+
}
|
|
52971
52979
|
async describeBoundary() {
|
|
52972
52980
|
const info = this.deps.plugin.describe();
|
|
52973
52981
|
const source = { id: "boundary-core", kind: "core", fetchedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -56969,16 +56977,16 @@ var Kr160 = /* @__PURE__ */ Uint32Array.from([
|
|
|
56969
56977
|
2053994217,
|
|
56970
56978
|
0
|
|
56971
56979
|
]);
|
|
56972
|
-
function ripemd_f(group, x, y,
|
|
56980
|
+
function ripemd_f(group, x, y, z9) {
|
|
56973
56981
|
if (group === 0)
|
|
56974
|
-
return x ^ y ^
|
|
56982
|
+
return x ^ y ^ z9;
|
|
56975
56983
|
if (group === 1)
|
|
56976
|
-
return x & y | ~x &
|
|
56984
|
+
return x & y | ~x & z9;
|
|
56977
56985
|
if (group === 2)
|
|
56978
|
-
return (x | ~y) ^
|
|
56986
|
+
return (x | ~y) ^ z9;
|
|
56979
56987
|
if (group === 3)
|
|
56980
|
-
return x &
|
|
56981
|
-
return x ^ (y | ~
|
|
56988
|
+
return x & z9 | y & ~z9;
|
|
56989
|
+
return x ^ (y | ~z9);
|
|
56982
56990
|
}
|
|
56983
56991
|
var BUF_160 = /* @__PURE__ */ new Uint32Array(16);
|
|
56984
56992
|
var RIPEMD160 = class extends HashMD {
|
|
@@ -61973,7 +61981,7 @@ var init_deployment_addresses = __esm2({
|
|
|
61973
61981
|
LiquidationManagerModule: "0x74B28695352E7bf736D6c9F76ccb7B4439477De9",
|
|
61974
61982
|
CircuitBreakerModule: "0xF7b545d3a4Ee056D06909AB367E2F7bFFE3cB1BC",
|
|
61975
61983
|
AdminModule: "0x0023B71B586795eE5fa4E83E384345C1EC8Bb946",
|
|
61976
|
-
PositionManagerViews: "
|
|
61984
|
+
PositionManagerViews: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
|
|
61977
61985
|
PositionManager: "0x12A1836e56139ccaD8722B89519d84233efc224B",
|
|
61978
61986
|
OperationAuthorizationRegistry: "0xD4505645b724754f5170a2027804a4265e860d44",
|
|
61979
61987
|
ContractVersionRegistry: "0x5e18f77d01940dA5B1D986D373D9A6ad0767008d",
|
|
@@ -62051,13 +62059,13 @@ var init_deployment_addresses = __esm2({
|
|
|
62051
62059
|
block: 25472957
|
|
62052
62060
|
},
|
|
62053
62061
|
PositionManager: {
|
|
62054
|
-
previousImplementation: "
|
|
62055
|
-
newImplementation: "
|
|
62056
|
-
upgradedAt: "2026-
|
|
62057
|
-
upgradedBy: "AdminModule
|
|
62058
|
-
reason: "
|
|
62059
|
-
executeTx: "
|
|
62060
|
-
block:
|
|
62062
|
+
previousImplementation: "0x600Dc0D1C2c0F94882B6Bc09172f8650047Ad5B1",
|
|
62063
|
+
newImplementation: "0x2e7170d6Fb15A876dB726732e72e63109bcB916d",
|
|
62064
|
+
upgradedAt: "2026-08-03T08:34:23.000Z",
|
|
62065
|
+
upgradedBy: "AdminModule generic-op 0x69b79a906ed2 (3-of-3 signatures, 24h timelock; proposed by 0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f, executed in the release batch onchain-auth/.safe-batches/mainnet-release-execute-B.json, submitted by EOA 0x2002827d34A781883Ec4c83c36ECC140c3911F2B, tx 0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6, block 25673200)",
|
|
62066
|
+
reason: "2026-08 agent-stack release, Execute B: agent-delegation digest rebind. makePayment/mintUCD/extendPosition now bind their EIP-712 digest to the STORED borrower rather than msg.sender, so a scoped AgentDelegationRegistry grant can submit; withdrawBTC still binds msg.sender and stays non-delegable. Also adds setViews(address), which the same batch used to repoint PM at the replacement PositionManagerViews. NOTE: VERSION reads 1.5.4 on BOTH sides of this upgrade \u2014 verify by implementation ADDRESS, never by VERSION(). NOTE: not the July audit rollout batch \u2014 reconcile-deployment-record.ts --write templates every row with that text; this hand-authored provenance is the accurate one, restore it if --write flattens it again.",
|
|
62067
|
+
executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
|
|
62068
|
+
block: 25673200
|
|
62061
62069
|
},
|
|
62062
62070
|
LoanOperationsManagerModule: {
|
|
62063
62071
|
previousImplementation: "0x56671D671e492Dae625413d463D47605Cf54edf6",
|
|
@@ -62101,6 +62109,16 @@ var init_deployment_addresses = __esm2({
|
|
|
62101
62109
|
reason: "2026-08 agent-stack release: PositionDelegateRegistry VERSION 1.1.0 -> 2.0.0 via upgradeToAndCall + initializeV2(AdminModule, registrar 0x5D54E0BE\u2026, pauser 0xC205Ae99\u2026) \u2014 kill-switch, deny-only registrar, permanent delegate burn. NOTE: not the July audit rollout batch \u2014 reconcile-deployment-record.ts --write templates every row with that text; this hand-authored provenance is the accurate one, restore it if --write flattens it again.",
|
|
62102
62110
|
executeTx: "0xf0f237f6c4e958c37de556571908283c59c3fba6ebf9fa3cefb956f37e315a10",
|
|
62103
62111
|
block: 25669024
|
|
62112
|
+
},
|
|
62113
|
+
PositionManagerViews: {
|
|
62114
|
+
previousImplementation: "0x9225647a30bbACA4Acc0491B786869036914242e",
|
|
62115
|
+
newImplementation: "0xE68DC096A65Ecddbc6A9b5c6e5f878e2CE143Bfe",
|
|
62116
|
+
proxy: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
|
|
62117
|
+
upgradedAt: "2026-08-03T08:34:23.000Z",
|
|
62118
|
+
upgradedBy: "REPLACED, not upgraded. Fresh ERC1967Proxy (atomically initialized) + AdminModule generic-op 0x848a97186f0d PositionManager.setViews(proxy) \u2014 3-of-3, 24h timelock, executed in onchain-auth/.safe-batches/mainnet-release-execute-B.json",
|
|
62119
|
+
reason: "2026-08 agent-stack release. The mainnet PositionManagerViews at 0x9225647a was deployed as a BARE implementation (EIP-1967 slot 0x00), so upgradeToAndCall reverts UUPSUnauthorizedCallContext \u2014 it could never be upgraded. PositionManager.setViews (added in the same Execute B batch) removed the repoint blocker, so Views was replaced behind a new proxy rather than upgraded. This makes the Pashov F3 renewal debt-ceiling check REACHABLE for the first time: ExceedsMaxLoan (0x499e7985) is present in 0xE68DC096 and absent from 0x9225647a. Views holds no protocol state (8 wiring slots + roles + pause), which is what made replacement safe. The old contract is ABANDONED, not decommissioned \u2014 it stays live and callable as the rollback target for setViews. NOTE: VERSION reads 1.1.1 on both sides; verify by address.",
|
|
62120
|
+
executeTx: "0xf1f8d5fc13f45d7a3f932bf1a2d6e29381fdd41cd31298ad785bf7688df07fe6",
|
|
62121
|
+
block: 25673200
|
|
62104
62122
|
}
|
|
62105
62123
|
},
|
|
62106
62124
|
latestEnv: {
|
|
@@ -62134,10 +62152,10 @@ var init_deployment_addresses = __esm2({
|
|
|
62134
62152
|
ADMIN_MODULE_IMPL: "0xb4C5C7E051A1e672F014B25CB5D55B225Aa0D512",
|
|
62135
62153
|
BTC_SPEND_AUTHORIZER: "0xfBbF108486fa07F1B06a811C5b66ed68DD9c508a",
|
|
62136
62154
|
BTC_SPEND_AUTHORIZER_IMPL: "0x40c9e8C46C65E0A57BB63da5368868A9E8Df81A5",
|
|
62137
|
-
POSITION_MANAGER_VIEWS: "
|
|
62138
|
-
POSITION_MANAGER_VIEWS_IMPL: "
|
|
62155
|
+
POSITION_MANAGER_VIEWS: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
|
|
62156
|
+
POSITION_MANAGER_VIEWS_IMPL: "0xE68DC096A65Ecddbc6A9b5c6e5f878e2CE143Bfe",
|
|
62139
62157
|
POSITION_MANAGER: "0x12A1836e56139ccaD8722B89519d84233efc224B",
|
|
62140
|
-
POSITION_MANAGER_IMPL: "
|
|
62158
|
+
POSITION_MANAGER_IMPL: "0x2e7170d6Fb15A876dB726732e72e63109bcB916d",
|
|
62141
62159
|
LOAN_OPERATIONS_MANAGER_MODULE: "0x2561974A40F1AEed1251d0A090A83cF8536FB9E9",
|
|
62142
62160
|
LOAN_OPERATIONS_MANAGER_MODULE_IMPL: "0x7d90aAB4466f59BA9aC9C7a9BF14dC53734336e7",
|
|
62143
62161
|
UPGRADE_VALIDATOR: "0xC46Ae71F22e3741A6CF46E399aE914C4868fEbed",
|
|
@@ -62163,7 +62181,7 @@ var init_deployment_addresses = __esm2({
|
|
|
62163
62181
|
LiquidationManagerModule: "0x74B28695352E7bf736D6c9F76ccb7B4439477De9",
|
|
62164
62182
|
CircuitBreakerModule: "0xF7b545d3a4Ee056D06909AB367E2F7bFFE3cB1BC",
|
|
62165
62183
|
AdminModule: "0x0023B71B586795eE5fa4E83E384345C1EC8Bb946",
|
|
62166
|
-
PositionManagerViews: "
|
|
62184
|
+
PositionManagerViews: "0x8B57954eA338c6A6bfF1457f71080e25baFF3937",
|
|
62167
62185
|
PositionManager: "0x12A1836e56139ccaD8722B89519d84233efc224B",
|
|
62168
62186
|
OperationAuthorizationRegistry: "0xD4505645b724754f5170a2027804a4265e860d44",
|
|
62169
62187
|
ContractVersionRegistry: "0x5e18f77d01940dA5B1D986D373D9A6ad0767008d",
|
|
@@ -67987,6 +68005,7 @@ function sessionStoreKey(address, chainId, endpoint) {
|
|
|
67987
68005
|
return STORE_PREFIX + `${address.trim().toLowerCase()}:${chainId}:${endpoint.replace(/\/+$/, "")}`;
|
|
67988
68006
|
}
|
|
67989
68007
|
var PENDING_ENVELOPE_TTL_SECONDS = 8 * 60;
|
|
68008
|
+
var EOA_PENDING_ENVELOPE_TTL_SECONDS = 60;
|
|
67990
68009
|
function pendingEnvelopeKey(sessionKey) {
|
|
67991
68010
|
return sessionKey + ":pending";
|
|
67992
68011
|
}
|
|
@@ -68034,7 +68053,7 @@ var LocalStorageSessionStore = class {
|
|
|
68034
68053
|
} catch {
|
|
68035
68054
|
}
|
|
68036
68055
|
}
|
|
68037
|
-
loadPending(key) {
|
|
68056
|
+
loadPending(key, maxAgeSeconds = PENDING_ENVELOPE_TTL_SECONDS) {
|
|
68038
68057
|
let raw;
|
|
68039
68058
|
try {
|
|
68040
68059
|
raw = window.localStorage.getItem(pendingEnvelopeKey(key));
|
|
@@ -68051,7 +68070,7 @@ var LocalStorageSessionStore = class {
|
|
|
68051
68070
|
return null;
|
|
68052
68071
|
}
|
|
68053
68072
|
const nowSec = Math.floor(Date.now() / 1e3);
|
|
68054
|
-
if (!isPendingEnvelopeShape(parsed) || nowSec >= parsed.issuedAt +
|
|
68073
|
+
if (!isPendingEnvelopeShape(parsed) || nowSec >= parsed.issuedAt + maxAgeSeconds) {
|
|
68055
68074
|
this.clearPending(key);
|
|
68056
68075
|
return null;
|
|
68057
68076
|
}
|
|
@@ -68085,12 +68104,12 @@ var MemorySessionStore = class {
|
|
|
68085
68104
|
clear(key) {
|
|
68086
68105
|
this.entries.delete(key);
|
|
68087
68106
|
}
|
|
68088
|
-
loadPending(key) {
|
|
68107
|
+
loadPending(key, maxAgeSeconds = PENDING_ENVELOPE_TTL_SECONDS) {
|
|
68089
68108
|
const envelope = this.pending.get(key);
|
|
68090
68109
|
if (!envelope)
|
|
68091
68110
|
return null;
|
|
68092
68111
|
const nowSec = Math.floor(Date.now() / 1e3);
|
|
68093
|
-
if (nowSec >= envelope.issuedAt +
|
|
68112
|
+
if (nowSec >= envelope.issuedAt + maxAgeSeconds) {
|
|
68094
68113
|
this.pending.delete(key);
|
|
68095
68114
|
return null;
|
|
68096
68115
|
}
|
|
@@ -68122,15 +68141,23 @@ var REFRESH_LEEWAY_SECONDS = 30;
|
|
|
68122
68141
|
var LOGIN_RETRY_BASE_MS = 3e4;
|
|
68123
68142
|
var LOGIN_RETRY_MAX_MS = 5 * 6e4;
|
|
68124
68143
|
var ServerLoginError = class extends Error {
|
|
68125
|
-
constructor(message, status) {
|
|
68144
|
+
constructor(message, status, reason) {
|
|
68126
68145
|
super(message);
|
|
68127
68146
|
this.status = status;
|
|
68147
|
+
this.reason = reason;
|
|
68128
68148
|
this.name = "ServerLoginError";
|
|
68129
68149
|
}
|
|
68130
68150
|
};
|
|
68131
68151
|
function isLoginRejection(error) {
|
|
68132
68152
|
return error instanceof ServerLoginError && error.status >= 400 && error.status < 500 && error.status !== 429;
|
|
68133
68153
|
}
|
|
68154
|
+
var SPENT_ENVELOPE_REASONS = /* @__PURE__ */ new Set(["replayed_nonce", "expired_issuedAt"]);
|
|
68155
|
+
function isSpentEnvelope(error) {
|
|
68156
|
+
if (!isLoginRejection(error))
|
|
68157
|
+
return false;
|
|
68158
|
+
const { reason, status } = error;
|
|
68159
|
+
return reason ? SPENT_ENVELOPE_REASONS.has(reason) : status === 409;
|
|
68160
|
+
}
|
|
68134
68161
|
var ServerSession = class {
|
|
68135
68162
|
signer;
|
|
68136
68163
|
serviceEndpoint;
|
|
@@ -68161,6 +68188,12 @@ var ServerSession = class {
|
|
|
68161
68188
|
* `clear()` can drop the persisted token without an async address lookup.
|
|
68162
68189
|
*/
|
|
68163
68190
|
lastStoreKey = null;
|
|
68191
|
+
/**
|
|
68192
|
+
* Whether the signer is a smart-contract wallet, memoized after the first
|
|
68193
|
+
* `eth_getCode`. Decides which of the server's two first-use windows bounds
|
|
68194
|
+
* envelope reuse; a signer cannot change kind for the life of the session.
|
|
68195
|
+
*/
|
|
68196
|
+
contractSigner = null;
|
|
68164
68197
|
constructor(opts) {
|
|
68165
68198
|
assertSafeServiceEndpoint(opts.serviceEndpoint);
|
|
68166
68199
|
this.signer = opts.signer;
|
|
@@ -68359,6 +68392,34 @@ var ServerSession = class {
|
|
|
68359
68392
|
return null;
|
|
68360
68393
|
}
|
|
68361
68394
|
}
|
|
68395
|
+
/**
|
|
68396
|
+
* How long a pending envelope for THIS signer may be reused, in seconds.
|
|
68397
|
+
*
|
|
68398
|
+
* The server grants an EOA 120s to make an envelope's first use and a contract
|
|
68399
|
+
* wallet 600s, so one local TTL is necessarily wrong for one of them. Deployed
|
|
68400
|
+
* code has bytecode; an EOA does not — one `eth_getCode`, memoized, settles it.
|
|
68401
|
+
*
|
|
68402
|
+
* Reports the CONTRACT window when it cannot tell, which is the behavior that
|
|
68403
|
+
* shipped before the split. The asymmetry is intended: guessing "EOA" for a
|
|
68404
|
+
* Safe hands it a new message and orphans the owner signatures already
|
|
68405
|
+
* collected, while guessing "contract" for an EOA now costs one rejected
|
|
68406
|
+
* attempt, because a rejection clears the envelope.
|
|
68407
|
+
*/
|
|
68408
|
+
async pendingEnvelopeTtl() {
|
|
68409
|
+
if (this.contractSigner === null) {
|
|
68410
|
+
try {
|
|
68411
|
+
const provider = this.signer.provider;
|
|
68412
|
+
if (!provider)
|
|
68413
|
+
return PENDING_ENVELOPE_TTL_SECONDS;
|
|
68414
|
+
const address = await this.signer.getAddress();
|
|
68415
|
+
const code = await provider.getCode(address);
|
|
68416
|
+
this.contractSigner = typeof code === "string" && code !== "0x";
|
|
68417
|
+
} catch {
|
|
68418
|
+
return PENDING_ENVELOPE_TTL_SECONDS;
|
|
68419
|
+
}
|
|
68420
|
+
}
|
|
68421
|
+
return this.contractSigner ? PENDING_ENVELOPE_TTL_SECONDS : EOA_PENDING_ENVELOPE_TTL_SECONDS;
|
|
68422
|
+
}
|
|
68362
68423
|
async getOrRefresh() {
|
|
68363
68424
|
const nowSec = this.now();
|
|
68364
68425
|
if (this.cached && this.cached.expiresAt - REFRESH_LEEWAY_SECONDS > nowSec) {
|
|
@@ -68380,10 +68441,10 @@ var ServerSession = class {
|
|
|
68380
68441
|
}
|
|
68381
68442
|
this.onSignaturePrompt?.();
|
|
68382
68443
|
let session;
|
|
68444
|
+
const store = this.store;
|
|
68445
|
+
const storeKey = store ? this.lastStoreKey : null;
|
|
68383
68446
|
try {
|
|
68384
|
-
const
|
|
68385
|
-
const storeKey = store ? this.lastStoreKey : null;
|
|
68386
|
-
const reuse = storeKey ? store.loadPending?.(storeKey) ?? void 0 : void 0;
|
|
68447
|
+
const reuse = storeKey ? store.loadPending?.(storeKey, await this.pendingEnvelopeTtl()) ?? void 0 : void 0;
|
|
68387
68448
|
const payload = await buildSignedLoginPayload(
|
|
68388
68449
|
this.signer,
|
|
68389
68450
|
this.chainId,
|
|
@@ -68406,6 +68467,9 @@ var ServerSession = class {
|
|
|
68406
68467
|
this.onSignatureResolved?.(true);
|
|
68407
68468
|
} catch (error) {
|
|
68408
68469
|
this.onSignatureResolved?.(false);
|
|
68470
|
+
if (storeKey && isSpentEnvelope(error)) {
|
|
68471
|
+
store.clearPending?.(storeKey);
|
|
68472
|
+
}
|
|
68409
68473
|
const failures = (this.promptBackoff?.failures ?? 0) + 1;
|
|
68410
68474
|
this.promptBackoff = {
|
|
68411
68475
|
failures,
|
|
@@ -68434,9 +68498,17 @@ var ServerSession = class {
|
|
|
68434
68498
|
});
|
|
68435
68499
|
if (!res.ok) {
|
|
68436
68500
|
const detail = await res.text().catch(() => "");
|
|
68501
|
+
let reason;
|
|
68502
|
+
try {
|
|
68503
|
+
const parsed = JSON.parse(detail);
|
|
68504
|
+
if (typeof parsed?.reason === "string")
|
|
68505
|
+
reason = parsed.reason;
|
|
68506
|
+
} catch {
|
|
68507
|
+
}
|
|
68437
68508
|
throw new ServerLoginError(
|
|
68438
68509
|
`lit-ops-server login failed: HTTP ${res.status} ${detail.slice(0, 200)}`,
|
|
68439
|
-
res.status
|
|
68510
|
+
res.status,
|
|
68511
|
+
reason
|
|
68440
68512
|
);
|
|
68441
68513
|
}
|
|
68442
68514
|
const body = await res.json();
|
|
@@ -74010,7 +74082,7 @@ var DiamondHandsGraph = class {
|
|
|
74010
74082
|
async getPSMConfiguration() {
|
|
74011
74083
|
const query = `
|
|
74012
74084
|
query GetPSMConfiguration {
|
|
74013
|
-
psmConfiguration(id: "psm") {
|
|
74085
|
+
psmConfiguration: psmconfiguration(id: "psm") {
|
|
74014
74086
|
id
|
|
74015
74087
|
version
|
|
74016
74088
|
redeemEnabled
|
|
@@ -74132,7 +74204,7 @@ var DiamondHandsGraph = class {
|
|
|
74132
74204
|
const whereClause = whereConditions.length > 0 ? `where: { ${whereConditions.join(", ")} }` : "";
|
|
74133
74205
|
const query = `
|
|
74134
74206
|
query GetPSMTransactions($first: Int!, $skip: Int!) {
|
|
74135
|
-
psmTransactions(${whereClause}, first: $first, skip: $skip, orderBy: timestamp, orderDirection: desc) {
|
|
74207
|
+
psmTransactions: psmtransactions(${whereClause}, first: $first, skip: $skip, orderBy: timestamp, orderDirection: desc) {
|
|
74136
74208
|
id
|
|
74137
74209
|
type
|
|
74138
74210
|
user
|
|
@@ -74167,7 +74239,7 @@ var DiamondHandsGraph = class {
|
|
|
74167
74239
|
const whereClause = whereConditions.length > 0 ? `where: { ${whereConditions.join(", ")} }` : "";
|
|
74168
74240
|
const query = `
|
|
74169
74241
|
query GetPSMDailyMetrics($first: Int!) {
|
|
74170
|
-
psmDailyMetrics(${whereClause}, first: $first, orderBy: date, orderDirection: desc) {
|
|
74242
|
+
psmDailyMetrics: psmdailyMetrics(${whereClause}, first: $first, orderBy: date, orderDirection: desc) {
|
|
74171
74243
|
id
|
|
74172
74244
|
date
|
|
74173
74245
|
totalSwapVolume
|
|
@@ -74891,7 +74963,7 @@ var DiamondHandsGraph = class {
|
|
|
74891
74963
|
}` : ""}
|
|
74892
74964
|
|
|
74893
74965
|
${includeKind("psm") ? `
|
|
74894
|
-
psmTransactions(
|
|
74966
|
+
psmTransactions: psmtransactions(
|
|
74895
74967
|
${buildTimeWhereClause()}
|
|
74896
74968
|
first: $limit, orderBy: timestamp, orderDirection: $orderDirection
|
|
74897
74969
|
) {
|
|
@@ -85912,23 +85984,28 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
85912
85984
|
* @throws if timeout is reached before subgraph catches up
|
|
85913
85985
|
*/
|
|
85914
85986
|
// ============================================================================
|
|
85915
|
-
// HIGH-LEVEL API - Agent Delegation (auto-renew)
|
|
85987
|
+
// HIGH-LEVEL API - Agent Delegation (auto-renew)
|
|
85916
85988
|
// ============================================================================
|
|
85917
|
-
/**
|
|
85918
|
-
|
|
85919
|
-
|
|
85920
|
-
|
|
85921
|
-
|
|
85922
|
-
|
|
85923
|
-
|
|
85924
|
-
|
|
85925
|
-
|
|
85926
|
-
|
|
85927
|
-
|
|
85989
|
+
/**
|
|
85990
|
+
* Guard: resolve the AgentDelegationRegistry for the configured network.
|
|
85991
|
+
*
|
|
85992
|
+
* Deployment presence IS the availability test — there is deliberately no chainId
|
|
85993
|
+
* allow-list here. The registry is deployed per network (Sepolia 2026-07, mainnet
|
|
85994
|
+
* 2026-08 agent-stack release) and `getNetworkConfig` populates the address from the
|
|
85995
|
+
* generated deployment table, so a chain without a deployment resolves to `""` and
|
|
85996
|
+
* fails closed below. Adding a chain therefore needs no SDK code change — which is
|
|
85997
|
+
* exactly how the previous hardcoded `chainId !== 11155111` gate went stale and kept
|
|
85998
|
+
* the mainnet toggle dark after the registry shipped.
|
|
85999
|
+
*
|
|
86000
|
+
* Callers that need the availability answer WITHOUT throwing (e.g. to decide whether to
|
|
86001
|
+
* render a toggle at all) should ask the deployment table directly rather than calling this
|
|
86002
|
+
* and catching — `ALL_DEPLOYMENTS` is published on the `@gvnrdao/dh-sdk/deployments` subpath.
|
|
86003
|
+
*/
|
|
86004
|
+
agentDelegationRegistryOrThrow() {
|
|
85928
86005
|
const addr = this.config.contractAddresses?.agentDelegationRegistry;
|
|
85929
86006
|
if (!addr) {
|
|
85930
86007
|
throw new SDKError({
|
|
85931
|
-
message: "AgentDelegationRegistry
|
|
86008
|
+
message: "AgentDelegationRegistry is not available on this network \u2014 no deployment address is configured (contractAddresses.agentDelegationRegistry)",
|
|
85932
86009
|
category: "CONFIGURATION",
|
|
85933
86010
|
severity: "HIGH"
|
|
85934
86011
|
/* HIGH */
|
|
@@ -85941,7 +86018,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
85941
86018
|
* Pure view — no signer required.
|
|
85942
86019
|
*/
|
|
85943
86020
|
async getAutoRenewStatus(positionId, user) {
|
|
85944
|
-
const addr =
|
|
86021
|
+
const addr = this.agentDelegationRegistryOrThrow();
|
|
85945
86022
|
const registry = AgentDelegationRegistry__factory.connect(addr, this.getProviderOrThrow());
|
|
85946
86023
|
const pid = this.toBytes32(positionId);
|
|
85947
86024
|
const grant = await registry.getLoanGrant(pid);
|
|
@@ -85961,7 +86038,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
85961
86038
|
* registers it, then records the position's renew grant. Borrower-signed.
|
|
85962
86039
|
*/
|
|
85963
86040
|
async enableAutoRenew(positionId, options) {
|
|
85964
|
-
const addr =
|
|
86041
|
+
const addr = this.agentDelegationRegistryOrThrow();
|
|
85965
86042
|
const pdrAddr = this.config.contractAddresses?.positionDelegateRegistry;
|
|
85966
86043
|
if (!pdrAddr) {
|
|
85967
86044
|
throw new SDKError({
|
|
@@ -86002,7 +86079,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
86002
86079
|
}
|
|
86003
86080
|
/** Disable auto-renew delegation for a position (clears the grant). Borrower-signed. */
|
|
86004
86081
|
async disableAutoRenew(positionId) {
|
|
86005
|
-
const addr =
|
|
86082
|
+
const addr = this.agentDelegationRegistryOrThrow();
|
|
86006
86083
|
const signer = this.getSignerOrThrow();
|
|
86007
86084
|
const user = await signer.getAddress();
|
|
86008
86085
|
const registry = AgentDelegationRegistry__factory.connect(addr, signer);
|
|
@@ -90171,7 +90248,8 @@ function createBoundary(config, opts) {
|
|
|
90171
90248
|
capabilities: () => ({
|
|
90172
90249
|
reads: { public: true, authenticated: "available" },
|
|
90173
90250
|
writes: { enabled: true, signerModes: ["external"], activeMode: "external" },
|
|
90174
|
-
signerSetupTool: false
|
|
90251
|
+
signerSetupTool: false,
|
|
90252
|
+
networkSwitch: false
|
|
90175
90253
|
}),
|
|
90176
90254
|
configFingerprint
|
|
90177
90255
|
});
|
|
@@ -90251,6 +90329,7 @@ function createBoundary(config, opts) {
|
|
|
90251
90329
|
...config.borrower ? { borrowerAddress: config.borrower } : {},
|
|
90252
90330
|
signer: manager,
|
|
90253
90331
|
// B3: the mock sandbox runs every ceremony class; reads have no login gate.
|
|
90332
|
+
// Plan 13 M13-5: no network_switch on mock — its world is pinned by the config.
|
|
90254
90333
|
capabilities: () => ({
|
|
90255
90334
|
reads: { public: true, authenticated: "available" },
|
|
90256
90335
|
writes: {
|
|
@@ -90258,7 +90337,8 @@ function createBoundary(config, opts) {
|
|
|
90258
90337
|
signerModes: ["external", "keystore", "mock-simulated", "safe", "safe-module"],
|
|
90259
90338
|
activeMode: manager.mode()
|
|
90260
90339
|
},
|
|
90261
|
-
signerSetupTool: true
|
|
90340
|
+
signerSetupTool: true,
|
|
90341
|
+
networkSwitch: false
|
|
90262
90342
|
}),
|
|
90263
90343
|
configFingerprint
|
|
90264
90344
|
});
|
|
@@ -90319,7 +90399,9 @@ async function createRealBoundary(config, wallet) {
|
|
|
90319
90399
|
signerModes: [],
|
|
90320
90400
|
activeMode: manager.mode()
|
|
90321
90401
|
},
|
|
90322
|
-
signerSetupTool: true
|
|
90402
|
+
signerSetupTool: true,
|
|
90403
|
+
// Plan 13: the real adapter switches networks by conversation (network_switch tool).
|
|
90404
|
+
networkSwitch: true
|
|
90323
90405
|
});
|
|
90324
90406
|
const boundary = new BoundaryCore({
|
|
90325
90407
|
plugin,
|
|
@@ -90393,6 +90475,58 @@ async function buildBoundary(configResult) {
|
|
|
90393
90475
|
return { boundaryResult: { ok: true, boundary }, signer, dispose };
|
|
90394
90476
|
}
|
|
90395
90477
|
|
|
90478
|
+
// src/network-switch.ts
|
|
90479
|
+
var SWITCHABLE_NETWORKS = ["sepolia", "mainnet"];
|
|
90480
|
+
function createNetworkSwitchRuntime(opts) {
|
|
90481
|
+
return {
|
|
90482
|
+
current() {
|
|
90483
|
+
const b = opts.getBoot().boundaryResult;
|
|
90484
|
+
if (!b.ok) return null;
|
|
90485
|
+
const w = b.boundary.world();
|
|
90486
|
+
return { network: w.network, chainId: w.chainId, practiceWorld: w.practiceWorld };
|
|
90487
|
+
},
|
|
90488
|
+
async switchTo(network) {
|
|
90489
|
+
const targetEnv = { ...opts.env, DH_NETWORK: network };
|
|
90490
|
+
delete targetEnv["DH_MAINNET_WRITES_ACK"];
|
|
90491
|
+
const configResult = resolveBoundaryConfig(targetEnv);
|
|
90492
|
+
if (!configResult.ok) return { ok: false, error: configResult.error };
|
|
90493
|
+
const next = await buildBoundary(configResult);
|
|
90494
|
+
if (!next.boundaryResult.ok) {
|
|
90495
|
+
next.dispose();
|
|
90496
|
+
return { ok: false, error: next.boundaryResult.error };
|
|
90497
|
+
}
|
|
90498
|
+
opts.swap(next);
|
|
90499
|
+
return { ok: true };
|
|
90500
|
+
}
|
|
90501
|
+
};
|
|
90502
|
+
}
|
|
90503
|
+
function assembleWorld(opts) {
|
|
90504
|
+
let boot = opts.boot;
|
|
90505
|
+
const deps = {
|
|
90506
|
+
boundaryResult: boot.boundaryResult,
|
|
90507
|
+
...boot.mockControl ? { mockControl: boot.mockControl } : {},
|
|
90508
|
+
...boot.signer ? { signer: boot.signer } : {},
|
|
90509
|
+
...opts.configResult.ok && opts.configResult.config.adapter === "mock" && opts.configResult.config.chainId ? { chainId: opts.configResult.config.chainId } : {}
|
|
90510
|
+
};
|
|
90511
|
+
if ((opts.env["DH_ADAPTER"] ?? "real") !== "mock") {
|
|
90512
|
+
deps.networkSwitch = createNetworkSwitchRuntime({
|
|
90513
|
+
env: opts.env,
|
|
90514
|
+
getBoot: () => boot,
|
|
90515
|
+
swap: (next) => {
|
|
90516
|
+
const old = boot;
|
|
90517
|
+
boot = next;
|
|
90518
|
+
deps.boundaryResult = next.boundaryResult;
|
|
90519
|
+
if (next.signer) deps.signer = next.signer;
|
|
90520
|
+
else delete deps.signer;
|
|
90521
|
+
old.dispose();
|
|
90522
|
+
const w = next.boundaryResult.ok ? next.boundaryResult.boundary.world() : null;
|
|
90523
|
+
opts.log?.(`network switched \u2014 now ${w ? `${w.network} (chainId ${w.chainId})` : "unavailable"}.`);
|
|
90524
|
+
}
|
|
90525
|
+
});
|
|
90526
|
+
}
|
|
90527
|
+
return { deps, dispose: () => boot.dispose() };
|
|
90528
|
+
}
|
|
90529
|
+
|
|
90396
90530
|
// src/server.ts
|
|
90397
90531
|
var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
90398
90532
|
|
|
@@ -90453,6 +90587,22 @@ Re-invoke with confirmed: true ONLY after a human has approved this exact operat
|
|
|
90453
90587
|
isError: true
|
|
90454
90588
|
};
|
|
90455
90589
|
}
|
|
90590
|
+
function envStamp(b) {
|
|
90591
|
+
if (!b.ok) return "environment: UNKNOWN \u2014 boundary unavailable";
|
|
90592
|
+
const w = b.boundary.world();
|
|
90593
|
+
const money = w.network === "mainnet" ? "REAL MONEY" : w.network === "mock" ? "PRACTICE SANDBOX (no real money)" : "PRACTICE FUNDS (test network)";
|
|
90594
|
+
return `environment: ${w.network} \u2014 ${money}`;
|
|
90595
|
+
}
|
|
90596
|
+
async function guardedWrite(getB, fn) {
|
|
90597
|
+
const result = await guarded(fn);
|
|
90598
|
+
const stamp = envStamp(getB());
|
|
90599
|
+
const content = result.content.map(
|
|
90600
|
+
(c, i) => i === result.content.length - 1 ? { ...c, text: `${c.text}
|
|
90601
|
+
|
|
90602
|
+
${stamp}` } : c
|
|
90603
|
+
);
|
|
90604
|
+
return { ...result, content };
|
|
90605
|
+
}
|
|
90456
90606
|
async function guarded(fn) {
|
|
90457
90607
|
try {
|
|
90458
90608
|
return await fn();
|
|
@@ -90539,7 +90689,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90539
90689
|
},
|
|
90540
90690
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90541
90691
|
},
|
|
90542
|
-
async ({ selectedTerm, confirmed }) =>
|
|
90692
|
+
async ({ selectedTerm, confirmed }) => guardedWrite(getB, async () => {
|
|
90543
90693
|
const gate = requireConfirmation(confirmed, `create a ${selectedTerm}-month lending position`);
|
|
90544
90694
|
if (gate) return gate;
|
|
90545
90695
|
const problem = checkSelectedTerm(selectedTerm);
|
|
@@ -90562,7 +90712,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90562
90712
|
},
|
|
90563
90713
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90564
90714
|
},
|
|
90565
|
-
async ({ positionId, amountUcd, confirmed }) =>
|
|
90715
|
+
async ({ positionId, amountUcd, confirmed }) => guardedWrite(getB, async () => {
|
|
90566
90716
|
const gate = requireConfirmation(confirmed, `mint ${amountUcd} UCD against position ${positionId}`);
|
|
90567
90717
|
if (gate) return gate;
|
|
90568
90718
|
const problem = checkPositionIdHex(positionId) ?? checkUcdAmount(amountUcd);
|
|
@@ -90588,7 +90738,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90588
90738
|
},
|
|
90589
90739
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90590
90740
|
},
|
|
90591
|
-
async ({ positionId, amountUcd, repayAll, confirmed }) =>
|
|
90741
|
+
async ({ positionId, amountUcd, repayAll, confirmed }) => guardedWrite(getB, async () => {
|
|
90592
90742
|
if (repayAll === true === (amountUcd !== void 0)) {
|
|
90593
90743
|
return validationFailed("provide exactly one of amountUcd or repayAll: true");
|
|
90594
90744
|
}
|
|
@@ -90626,7 +90776,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90626
90776
|
},
|
|
90627
90777
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90628
90778
|
},
|
|
90629
|
-
async ({ positionId, selectedTerm, confirmed }) =>
|
|
90779
|
+
async ({ positionId, selectedTerm, confirmed }) => guardedWrite(getB, async () => {
|
|
90630
90780
|
const gate = requireConfirmation(confirmed, `renew position ${positionId} for a ${selectedTerm}-month term`);
|
|
90631
90781
|
if (gate) return gate;
|
|
90632
90782
|
const problem = checkPositionIdHex(positionId) ?? checkSelectedTerm(selectedTerm);
|
|
@@ -90653,7 +90803,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90653
90803
|
},
|
|
90654
90804
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90655
90805
|
},
|
|
90656
|
-
async ({ positionId, btcAddress: btcAddress2, amountSats, networkFeeSats, confirmed }) =>
|
|
90806
|
+
async ({ positionId, btcAddress: btcAddress2, amountSats, networkFeeSats, confirmed }) => guardedWrite(getB, async () => {
|
|
90657
90807
|
const gate = requireConfirmation(
|
|
90658
90808
|
confirmed,
|
|
90659
90809
|
`withdraw ${amountSats} sats from position ${positionId} to ${btcAddress2} (UNRECOVERABLE)`
|
|
@@ -90678,7 +90828,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90678
90828
|
},
|
|
90679
90829
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90680
90830
|
},
|
|
90681
|
-
async ({ btcAddress: btcAddress2, confirmed }) =>
|
|
90831
|
+
async ({ btcAddress: btcAddress2, confirmed }) => guardedWrite(getB, async () => {
|
|
90682
90832
|
const gate = requireConfirmation(confirmed, `allowlist ${btcAddress2} as a BTC withdrawal destination`);
|
|
90683
90833
|
if (gate) return gate;
|
|
90684
90834
|
const b = getB();
|
|
@@ -90698,7 +90848,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90698
90848
|
},
|
|
90699
90849
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90700
90850
|
},
|
|
90701
|
-
async ({ btcAddresses, confirmed }) =>
|
|
90851
|
+
async ({ btcAddresses, confirmed }) => guardedWrite(getB, async () => {
|
|
90702
90852
|
const gate = requireConfirmation(confirmed, `install delegation (module + agent + ${btcAddresses.length} destination(s))`);
|
|
90703
90853
|
if (gate) return gate;
|
|
90704
90854
|
const b = getB();
|
|
@@ -90721,7 +90871,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90721
90871
|
},
|
|
90722
90872
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS
|
|
90723
90873
|
},
|
|
90724
|
-
async ({ positionId, renew, repay, mintFloorBps, confirmed }) =>
|
|
90874
|
+
async ({ positionId, renew, repay, mintFloorBps, confirmed }) => guardedWrite(getB, async () => {
|
|
90725
90875
|
const gate = requireConfirmation(confirmed, `grant agent scopes on ${positionId}`);
|
|
90726
90876
|
if (gate) return gate;
|
|
90727
90877
|
const b = getB();
|
|
@@ -90756,7 +90906,7 @@ function registerLoanTools(server, getB, adapter2 = "real") {
|
|
|
90756
90906
|
openWorldHint: true
|
|
90757
90907
|
}
|
|
90758
90908
|
},
|
|
90759
|
-
async ({ positionId, utxoTxid, utxoVout, invalidatorTxid, minConfirmations }) =>
|
|
90909
|
+
async ({ positionId, utxoTxid, utxoVout, invalidatorTxid, minConfirmations }) => guardedWrite(getB, async () => {
|
|
90760
90910
|
const problem = checkPositionIdHex(positionId);
|
|
90761
90911
|
if (problem) return validationFailed(problem);
|
|
90762
90912
|
const b = getB();
|
|
@@ -90988,7 +91138,7 @@ function registerPsmTools(server, getB) {
|
|
|
90988
91138
|
},
|
|
90989
91139
|
annotations: DESTRUCTIVE_WRITE_ANNOTATIONS2
|
|
90990
91140
|
},
|
|
90991
|
-
async ({ direction, amount, confirmed }) =>
|
|
91141
|
+
async ({ direction, amount, confirmed }) => guardedWrite(getB, async () => {
|
|
90992
91142
|
const inputToken = direction === "to-ucd" ? "USDC" : "UCD";
|
|
90993
91143
|
const outputToken = direction === "to-ucd" ? "UCD" : "USDC";
|
|
90994
91144
|
const gate = requireConfirmation(
|
|
@@ -91185,7 +91335,7 @@ function looksSecretShaped(value) {
|
|
|
91185
91335
|
return /^0x[0-9a-fA-F]{32,}$/.test(value) || value.length >= 16 && !/\s/.test(value) && /[0-9]/.test(value) && /[a-zA-Z]/.test(value);
|
|
91186
91336
|
}
|
|
91187
91337
|
var SECRET_REFUSAL = "That value looks like a password or key. NEVER paste secrets into the conversation \u2014 they would enter the model context and transcripts. To provide keystore material, say 'unlock my keystore' (a secure local page opens and the password goes directly to the server), or set DH_KEYSTORE_PATH/DH_KEYSTORE_PASSWORD in the server environment.";
|
|
91188
|
-
function registerSignerTool(server,
|
|
91338
|
+
function registerSignerTool(server, getRuntime) {
|
|
91189
91339
|
registerBoundaryTool(
|
|
91190
91340
|
server,
|
|
91191
91341
|
"signer_setup",
|
|
@@ -91200,6 +91350,15 @@ function registerSignerTool(server, runtime) {
|
|
|
91200
91350
|
annotations: { destructiveHint: false, idempotentHint: false, openWorldHint: false, readOnlyHint: false }
|
|
91201
91351
|
},
|
|
91202
91352
|
async ({ action, mode, safeAddress }) => guarded(async () => {
|
|
91353
|
+
const runtime = getRuntime();
|
|
91354
|
+
if (!runtime) {
|
|
91355
|
+
return renderError(
|
|
91356
|
+
boundaryError(
|
|
91357
|
+
"SIGNER_UNAVAILABLE",
|
|
91358
|
+
"no signer runtime is live \u2014 the boundary failed to boot. Fix the configuration (or recover by switching networks via network_switch), then retry."
|
|
91359
|
+
)
|
|
91360
|
+
);
|
|
91361
|
+
}
|
|
91203
91362
|
const { manager, bridge } = runtime;
|
|
91204
91363
|
if (mode !== void 0 && !MODES.includes(mode)) {
|
|
91205
91364
|
return validationFailed(looksSecretShaped(mode) ? SECRET_REFUSAL : `mode '${mode}' is not one of: ${MODES.join(" | ")}`);
|
|
@@ -91293,6 +91452,7 @@ var GUIDE_TOPICS = [
|
|
|
91293
91452
|
"safe",
|
|
91294
91453
|
"delegation",
|
|
91295
91454
|
"safety",
|
|
91455
|
+
"switch-network",
|
|
91296
91456
|
"troubleshooting",
|
|
91297
91457
|
"glossary"
|
|
91298
91458
|
];
|
|
@@ -91321,6 +91481,12 @@ calls. Every operation that moves funds requires the user's explicit confirmatio
|
|
|
91321
91481
|
(\`confirmed: true\`) \u2014 nothing is ever silent.`,
|
|
91322
91482
|
"first-setup": `# First setup \u2014 from zero to ready, by conversation only
|
|
91323
91483
|
|
|
91484
|
+
Installing on another machine? Three paths, by machine: Claude Desktop on macOS/Windows
|
|
91485
|
+
\u2192 the \`.mcpb\` bundle from the releases page (no Node needed); Linux or any other MCP
|
|
91486
|
+
host \u2192 the one-line installer (self-contained binary, prints the exact config snippet);
|
|
91487
|
+
developers with Node \u2265 18 on PATH \u2192 \`npx -y @gvnrdao/dh-mcp\`. Details: the README
|
|
91488
|
+
install matrix.
|
|
91489
|
+
|
|
91324
91490
|
Nothing needs a config file. Three steps:
|
|
91325
91491
|
|
|
91326
91492
|
**1. Know your world.** Read \`boundary://info\` (its \`capabilities\` block) and
|
|
@@ -91346,6 +91512,9 @@ signer modes exist; current terms (\`protocol_terms\`).
|
|
|
91346
91512
|
- Not sure? \`signer_setup\` action \`status\` explains what is active and what is missing.
|
|
91347
91513
|
- **No signer is also a valid start:** every public read works without one \u2014
|
|
91348
91514
|
\`position_list {borrower}\` with the user's address needs no signer and no login.
|
|
91515
|
+
- **Wrong network?** On the real adapter the user can switch sepolia \u2194 mainnet by
|
|
91516
|
+
talking (\`network_switch\`, human-confirmed) \u2014 see \`guide switch-network\`. State
|
|
91517
|
+
the money reality after any switch.
|
|
91349
91518
|
|
|
91350
91519
|
**3. First position.** \`loan_create\` with a term from \`protocol_terms\` (needs
|
|
91351
91520
|
\`confirmed: true\` from the user). Then deposit BTC to the vault address
|
|
@@ -91620,6 +91789,29 @@ owners sign at leisure (\`psm_swap\` builds the pair) \u2014 that is the only Sa
|
|
|
91620
91789
|
withdrawing to a wrong address. Repaid-in-full positions release all collateral.
|
|
91621
91790
|
- **Practice vs real:** mock worlds are stated as such (\`boundary://info\`). Never let a
|
|
91622
91791
|
user believe practice gains/losses are real, or vice versa.`,
|
|
91792
|
+
"switch-network": `# Switch network \u2014 sepolia \u2194 mainnet by conversation (real adapter)
|
|
91793
|
+
|
|
91794
|
+
The \`network_switch\` tool moves THIS SESSION between worlds. Check
|
|
91795
|
+
\`boundary://info\` capabilities first: \`networkSwitch: true\` means it is available
|
|
91796
|
+
(real adapter); in a practice sandbox (mock) the world is pinned by config \u2014 there is
|
|
91797
|
+
no switch, and that is by design.
|
|
91798
|
+
|
|
91799
|
+
**The rules, plainly:**
|
|
91800
|
+
- \`network_switch status\` \u2014 which network is active and whether money is real. Say
|
|
91801
|
+
this to the user BEFORE and AFTER any switch, always.
|
|
91802
|
+
- \`network_switch switch { network, confirmed: true }\` \u2014 the switch runs only after
|
|
91803
|
+
the human approves the card. sepolia = practice funds; mainnet = REAL MONEY.
|
|
91804
|
+
- NOTHING carries across: positions, vaults, signer bindings, logins are per-network.
|
|
91805
|
+
A sepolia position does not exist on mainnet and vice versa.
|
|
91806
|
+
- Switching to mainnet does NOT enable fund-moving operations: mainnet writes are
|
|
91807
|
+
operator-gated \u2014 reads work, write tools refuse with the true reason. Never imply
|
|
91808
|
+
otherwise.
|
|
91809
|
+
- A pending signing ceremony blocks the switch (finish or decline it first).
|
|
91810
|
+
- The switch is session-scoped: when the server restarts, the configured default
|
|
91811
|
+
network returns.
|
|
91812
|
+
|
|
91813
|
+
After any switch: re-read \`boundary://info\`, then STATE the new network and money
|
|
91814
|
+
reality in your next message. The user must never have to ask which world they are in.`,
|
|
91623
91815
|
troubleshooting: `# Troubleshooting \u2014 what error codes mean, in plain words
|
|
91624
91816
|
|
|
91625
91817
|
- **SIGNER_UNAVAILABLE** \u2014 no authorization mode chosen/ready. Two real remedies: the
|
|
@@ -91630,7 +91822,11 @@ owners sign at leisure (\`psm_swap\` builds the pair) \u2014 that is the only Sa
|
|
|
91630
91822
|
the same pair: keystore env pair, or "connect my wallet" (\`signer_setup connect\`). An
|
|
91631
91823
|
EXPIRED login refuses the same way \u2014 reconnect on the user's word.
|
|
91632
91824
|
- **Mainnet write refused** \u2014 mainnet writes are disabled unless the operator explicitly
|
|
91633
|
-
arms them; the refusal is the standing gate, not a bug. Reads keep working.
|
|
91825
|
+
arms them; the refusal is the standing gate, not a bug. Reads keep working. This is
|
|
91826
|
+
TRUE after a conversational network switch too \u2014 switching never arms writes.
|
|
91827
|
+
- **"Wrong network" / wants mainnet or sepolia** \u2014 real adapter: \`network_switch\`
|
|
91828
|
+
(human-confirmed card; nothing carries across networks). Mock: the world is pinned by
|
|
91829
|
+
config \u2014 no switch exists there.
|
|
91634
91830
|
- **External-mode withdraw refused** \u2014 withdraw-BTC under external mode is not shipped
|
|
91635
91831
|
yet (the SDK signing-context seam is pending); keystore-mode withdraw works.
|
|
91636
91832
|
- **Login throttled (mainnet)** \u2014 the broker limits logins per address; wait and retry.
|
|
@@ -91646,7 +91842,12 @@ owners sign at leisure (\`psm_swap\` builds the pair) \u2014 that is the only Sa
|
|
|
91646
91842
|
- **STATE_DIVERGENCE / STALE_DATA warnings** \u2014 sources disagree or lag; the envelope says
|
|
91647
91843
|
which source and when from. Prefer chain-sourced values; re-read before acting.
|
|
91648
91844
|
- Approval popup never appeared? \`signer_setup status\` \u2192 reopen the approval page URL.
|
|
91649
|
-
Wallet on the wrong network? The page offers the switch \u2014 approve it in the wallet
|
|
91845
|
+
Wallet on the wrong network? The page offers the switch \u2014 approve it in the wallet.
|
|
91846
|
+
- **\`spawn npx ENOENT\` at server start (another machine/host)** \u2014 the MCP host searched
|
|
91847
|
+
the system PATH and found no \`npx\`: that machine has no Node.js, or the host (e.g. an
|
|
91848
|
+
Electron app) cannot see a shell-managed Node. Not a server bug \u2014 the npx path requires
|
|
91849
|
+
Node \u2265 18 on PATH. Remedies: the one-line installer (self-contained binary, absolute
|
|
91850
|
+
path in the printed snippet), or the \`.mcpb\` bundle on macOS/Windows Claude Desktop.`,
|
|
91650
91851
|
glossary: `# Glossary \u2014 map the user's words to the protocol's
|
|
91651
91852
|
|
|
91652
91853
|
Synonym sets (treat these as the SAME intent):
|
|
@@ -91683,6 +91884,7 @@ var GUIDE_INDEX = `# Diamond Hands guide \u2014 topics
|
|
|
91683
91884
|
- safe \u2014 borrowing as a Safe smart-account (single or multi-owner), allowlisting, timing \u2014 PRACTICE-ONLY today
|
|
91684
91885
|
- 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
|
|
91685
91886
|
- safety \u2014 liquidation, expiry, irreversible sends, decline-is-safe
|
|
91887
|
+
- switch-network \u2014 moving this session between sepolia (practice) and mainnet (REAL MONEY): the card, what carries across (nothing), what stays gated
|
|
91686
91888
|
- troubleshooting \u2014 error codes in plain words, with the real remedies
|
|
91687
91889
|
- glossary \u2014 synonym map + disambiguations (use it to understand ANY user's vocabulary)
|
|
91688
91890
|
|
|
@@ -91789,6 +91991,94 @@ function registerGuidePrompts(server) {
|
|
|
91789
91991
|
);
|
|
91790
91992
|
}
|
|
91791
91993
|
|
|
91994
|
+
// src/tools/network-switch.ts
|
|
91995
|
+
var import_zod8 = require("zod");
|
|
91996
|
+
function moneyLine(network) {
|
|
91997
|
+
return network === "mainnet" ? "mainnet \u2014 REAL MONEY: fund-moving operations spend real funds once enabled" : `${network} \u2014 PRACTICE FUNDS (test network: real contracts, no real money)`;
|
|
91998
|
+
}
|
|
91999
|
+
function registerNetworkSwitchTool(server, getB, runtime, getSigner) {
|
|
92000
|
+
registerBoundaryTool(
|
|
92001
|
+
server,
|
|
92002
|
+
"network_switch",
|
|
92003
|
+
{
|
|
92004
|
+
title: "Show or switch the active network",
|
|
92005
|
+
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. Mainnet writes stay operator-gated after a switch \u2014 reads work, fund-moving tools refuse with the true reason. 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.",
|
|
92006
|
+
inputSchema: {
|
|
92007
|
+
action: import_zod8.z.enum(["status", "switch"]).describe("status = current world; switch = change network (needs confirmed:true)"),
|
|
92008
|
+
network: import_zod8.z.string().optional().describe("switch target: sepolia | mainnet"),
|
|
92009
|
+
confirmed: import_zod8.z.boolean().optional().describe("HUMAN approval of this exact switch \u2014 never auto-set")
|
|
92010
|
+
},
|
|
92011
|
+
annotations: { destructiveHint: true }
|
|
92012
|
+
},
|
|
92013
|
+
async ({ action, network, confirmed }) => guarded(async () => {
|
|
92014
|
+
const current = runtime.current();
|
|
92015
|
+
if (action === "status") {
|
|
92016
|
+
const lines = current ? [
|
|
92017
|
+
`Active network: ${current.network} (chainId ${current.chainId})`,
|
|
92018
|
+
`Money reality: ${current.practiceWorld ? "PRACTICE \u2014 no real money" : "REAL MONEY"}`
|
|
92019
|
+
] : ["Active network: NONE \u2014 the boundary failed to boot (see any tool's error for the config cause)."];
|
|
92020
|
+
lines.push(
|
|
92021
|
+
`Switchable networks: ${SWITCHABLE_NETWORKS.join(", ")} (action 'switch', confirmed:true after human approval).`,
|
|
92022
|
+
"A switch changes worlds entirely: positions, vaults, and signer bindings are per-network.",
|
|
92023
|
+
"Mainnet writes are operator-gated regardless of switching \u2014 reads work, fund-moving tools refuse.",
|
|
92024
|
+
"Session-scoped: the configured default network returns when the server restarts."
|
|
92025
|
+
);
|
|
92026
|
+
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
92027
|
+
}
|
|
92028
|
+
const target = (network ?? "").toLowerCase();
|
|
92029
|
+
if (!SWITCHABLE_NETWORKS.includes(target)) {
|
|
92030
|
+
return validationFailed(`network must be one of: ${SWITCHABLE_NETWORKS.join(", ")} (got '${network ?? ""}').`);
|
|
92031
|
+
}
|
|
92032
|
+
if (current && current.network === target) {
|
|
92033
|
+
return validationFailed(`already on ${target} \u2014 nothing to switch.`);
|
|
92034
|
+
}
|
|
92035
|
+
const pending = getSigner()?.bridge.pendingCount() ?? 0;
|
|
92036
|
+
if (pending > 0) {
|
|
92037
|
+
return renderError(
|
|
92038
|
+
boundaryError(
|
|
92039
|
+
"UPSTREAM_REJECTED",
|
|
92040
|
+
`network switch refused: ${pending} signing ceremony(ies) still pending. Finish or decline them in the wallet/approval page (or let them expire), then switch.`
|
|
92041
|
+
)
|
|
92042
|
+
);
|
|
92043
|
+
}
|
|
92044
|
+
if (confirmed !== true) {
|
|
92045
|
+
const from = current ? moneyLine(current.network) : "no live network (boot error)";
|
|
92046
|
+
return {
|
|
92047
|
+
content: [
|
|
92048
|
+
{
|
|
92049
|
+
type: "text",
|
|
92050
|
+
text: `CONFIRMATION REQUIRED \u2014 network switch.
|
|
92051
|
+
FROM: ${from}
|
|
92052
|
+
TO: ${moneyLine(target)}
|
|
92053
|
+
- Positions, vaults, and signer bindings are PER-NETWORK: nothing carries across.
|
|
92054
|
+
- Mainnet fund-moving operations remain operator-gated after the switch \u2014 reads work, writes refuse.
|
|
92055
|
+
- Session-scoped: the configured default network returns on server restart.
|
|
92056
|
+
Re-invoke with confirmed: true ONLY after a human has approved this exact switch. Do not set it on your own.`
|
|
92057
|
+
}
|
|
92058
|
+
],
|
|
92059
|
+
isError: true
|
|
92060
|
+
};
|
|
92061
|
+
}
|
|
92062
|
+
const result = await runtime.switchTo(target);
|
|
92063
|
+
if (!result.ok) return renderError(result.error);
|
|
92064
|
+
const b = getB();
|
|
92065
|
+
const world = b.ok ? b.boundary.world() : null;
|
|
92066
|
+
return {
|
|
92067
|
+
content: [
|
|
92068
|
+
{
|
|
92069
|
+
type: "text",
|
|
92070
|
+
text: `SWITCHED. Active network is now: ${world ? moneyLine(world.network) : target}.
|
|
92071
|
+
` + (world ? `chainId: ${world.chainId}
|
|
92072
|
+
` : "") + `Signer bindings for ${target} (if any) were loaded from this network's own state; re-authorize via signer_setup if needed.
|
|
92073
|
+
Session-scoped: the configured default returns on restart.
|
|
92074
|
+
NOW: re-read boundary://info and STATE the new environment and money reality to the user before any action.`
|
|
92075
|
+
}
|
|
92076
|
+
]
|
|
92077
|
+
};
|
|
92078
|
+
})
|
|
92079
|
+
);
|
|
92080
|
+
}
|
|
92081
|
+
|
|
91792
92082
|
// src/resources/position.ts
|
|
91793
92083
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
91794
92084
|
function registerPositionResource(server, getB) {
|
|
@@ -91885,8 +92175,8 @@ function registerBoundaryInfoResource(server, getB) {
|
|
|
91885
92175
|
}
|
|
91886
92176
|
|
|
91887
92177
|
// src/server.ts
|
|
91888
|
-
var SERVER_VERSION = "0.
|
|
91889
|
-
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.";
|
|
92178
|
+
var SERVER_VERSION = "0.3.0";
|
|
92179
|
+
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.";
|
|
91890
92180
|
function createServer2(deps) {
|
|
91891
92181
|
const server = new import_mcp2.McpServer(
|
|
91892
92182
|
{
|
|
@@ -91910,29 +92200,39 @@ function createServer2(deps) {
|
|
|
91910
92200
|
if (deps.mockControl) {
|
|
91911
92201
|
registerMockControlTool(server, deps.mockControl, deps.chainId);
|
|
91912
92202
|
}
|
|
91913
|
-
if (deps.signer) {
|
|
91914
|
-
registerSignerTool(server, deps.signer);
|
|
92203
|
+
if (deps.signer || deps.networkSwitch) {
|
|
92204
|
+
registerSignerTool(server, () => deps.signer);
|
|
92205
|
+
}
|
|
92206
|
+
if (deps.networkSwitch) {
|
|
92207
|
+
registerNetworkSwitchTool(server, getB, deps.networkSwitch, () => deps.signer);
|
|
91915
92208
|
}
|
|
91916
92209
|
return server;
|
|
91917
92210
|
}
|
|
91918
92211
|
|
|
91919
92212
|
// src/index.ts
|
|
92213
|
+
if (process.argv.includes("--version")) {
|
|
92214
|
+
process.stdout.write(`${SERVER_VERSION}
|
|
92215
|
+
`);
|
|
92216
|
+
process.exit(0);
|
|
92217
|
+
}
|
|
91920
92218
|
async function main() {
|
|
91921
92219
|
const configResult = resolveBoundaryConfig(process.env);
|
|
91922
|
-
|
|
92220
|
+
let boot = await buildBoundary(configResult);
|
|
91923
92221
|
if (!boot.boundaryResult.ok) {
|
|
91924
92222
|
process.stderr.write(`[dh-mcp] boundary not available: ${boot.boundaryResult.error.message}
|
|
91925
92223
|
`);
|
|
91926
92224
|
}
|
|
91927
|
-
const
|
|
91928
|
-
|
|
91929
|
-
|
|
91930
|
-
|
|
91931
|
-
|
|
92225
|
+
const world = assembleWorld({
|
|
92226
|
+
env: process.env,
|
|
92227
|
+
configResult,
|
|
92228
|
+
boot,
|
|
92229
|
+
log: (line) => process.stderr.write(`[dh-mcp] ${line}
|
|
92230
|
+
`)
|
|
91932
92231
|
});
|
|
92232
|
+
const server = createServer2(world.deps);
|
|
91933
92233
|
const transport = new import_stdio.StdioServerTransport();
|
|
91934
92234
|
const cleanup = () => {
|
|
91935
|
-
|
|
92235
|
+
world.dispose();
|
|
91936
92236
|
process.exit(0);
|
|
91937
92237
|
};
|
|
91938
92238
|
process.on("SIGINT", cleanup);
|