paralith-mcp 0.4.9 → 0.5.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 +17 -7
- package/dist/bridge.mjs +841 -217
- package/dist/chains.json +27 -18
- package/dist/graph.json +113 -66
- package/dist/http.mjs +20304 -993
- package/dist/server.mjs +20530 -1006
- package/package.json +10 -4
- package/dist/client.mjs +0 -12717
- package/dist/wallet-slot.mjs +0 -5
package/dist/bridge.mjs
CHANGED
|
@@ -1,43 +1,146 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res, err) => function __init() {
|
|
4
|
+
if (err) throw err[0];
|
|
5
|
+
try {
|
|
6
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
|
+
} catch (e) {
|
|
8
|
+
throw err = [e], e;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
2
11
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
// ../../backend/native/deploy-target.mjs
|
|
13
|
+
function origin(url) {
|
|
14
|
+
let parsed;
|
|
15
|
+
try {
|
|
16
|
+
parsed = new URL(String(url));
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const host = parsed.hostname === "localhost" ? "127.0.0.1" : parsed.hostname;
|
|
21
|
+
const port = parsed.port || (parsed.protocol === "https:" ? "443" : "80");
|
|
22
|
+
return `${parsed.protocol}//${host}:${port}`;
|
|
23
|
+
}
|
|
24
|
+
function pinnedTargets(env = process.env) {
|
|
25
|
+
const list = parseList(env[TARGET_ENV]).map(origin).filter(Boolean);
|
|
26
|
+
return list.length ? new Set(list) : null;
|
|
27
|
+
}
|
|
28
|
+
function assertDeployTarget(url, env = process.env) {
|
|
29
|
+
const pinned = pinnedTargets(env);
|
|
30
|
+
if (!pinned) return;
|
|
31
|
+
const o = origin(url);
|
|
32
|
+
if (!o || !pinned.has(o)) {
|
|
33
|
+
throw new Error(`refusing to send to ${url}: this deploy is pinned to ${[...pinned].join(", ")}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
var TARGET_ENV, parseList, RECEIPT_FILES;
|
|
37
|
+
var init_deploy_target = __esm({
|
|
38
|
+
"../../backend/native/deploy-target.mjs"() {
|
|
39
|
+
TARGET_ENV = "PARALITH_DEPLOY_TARGET";
|
|
40
|
+
parseList = (value) => String(value || "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
41
|
+
RECEIPT_FILES = Object.freeze([
|
|
42
|
+
"backend/native/deployment-state.json",
|
|
43
|
+
"backend/native/dao-state.json",
|
|
44
|
+
"backend/native/marketplace-state.json",
|
|
45
|
+
"backend/native/venue-state.json",
|
|
46
|
+
"backend/native/sharded-venue-state.json",
|
|
47
|
+
"backend/native/ranking-state.json",
|
|
48
|
+
"backend/native/faucet-state.json",
|
|
49
|
+
"backend/native/wasm-runtime-state.json",
|
|
50
|
+
"live-process.txt",
|
|
51
|
+
"rune-process.txt",
|
|
52
|
+
"hunt-process.txt",
|
|
53
|
+
"products/bridge/deployments/pusd-standin.json"
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
26
57
|
|
|
27
|
-
//
|
|
28
|
-
|
|
58
|
+
// ../rune-ao/src/lib/poll-wait.mjs
|
|
59
|
+
var init_poll_wait = __esm({
|
|
60
|
+
"../rune-ao/src/lib/poll-wait.mjs"() {
|
|
61
|
+
"use strict";
|
|
62
|
+
}
|
|
63
|
+
});
|
|
29
64
|
|
|
30
|
-
// ../rune-ao/src/lib/
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
65
|
+
// ../rune-ao/src/lib/slot-settle.mjs
|
|
66
|
+
var init_slot_settle = __esm({
|
|
67
|
+
"../rune-ao/src/lib/slot-settle.mjs"() {
|
|
68
|
+
"use strict";
|
|
69
|
+
init_poll_wait();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// ../rune-ao/src/lib/gas.mjs
|
|
74
|
+
function isGasRefusal(res) {
|
|
75
|
+
return res?.status === 402;
|
|
76
|
+
}
|
|
34
77
|
function header(headers, name) {
|
|
78
|
+
if (!headers) return null;
|
|
79
|
+
if (typeof headers.get === "function") return headers.get(name);
|
|
80
|
+
return headers[name] ?? headers[name.toLowerCase()] ?? null;
|
|
81
|
+
}
|
|
82
|
+
function gasInt(value) {
|
|
83
|
+
if (typeof value === "number") return Number.isSafeInteger(value) ? value : null;
|
|
84
|
+
if (typeof value === "bigint") {
|
|
85
|
+
return value <= BigInt(Number.MAX_SAFE_INTEGER) && value >= -BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : null;
|
|
86
|
+
}
|
|
87
|
+
const text = String(value ?? "").trim().replace(/^"(.*)"$/, "$1");
|
|
88
|
+
if (!/^-?\d+$/.test(text)) return null;
|
|
89
|
+
const n = Number(text);
|
|
90
|
+
return Number.isSafeInteger(n) ? n : null;
|
|
91
|
+
}
|
|
92
|
+
function parseGasRequired(res, { node = null, account = null, process: process2 = null, body = null } = {}) {
|
|
93
|
+
if (!isGasRefusal(res)) return null;
|
|
94
|
+
let price = gasInt(header(res.headers, "price"));
|
|
95
|
+
let balance = gasInt(header(res.headers, "balance"));
|
|
96
|
+
const text = body === null || body === void 0 ? typeof res.body === "string" || res.body instanceof Uint8Array ? res.body : "" : body;
|
|
97
|
+
const str = typeof text === "string" ? text : new TextDecoder().decode(text);
|
|
98
|
+
if ((price === null || balance === null) && /^\s*\{/.test(str)) {
|
|
99
|
+
try {
|
|
100
|
+
const json = JSON.parse(str);
|
|
101
|
+
if (price === null) price = gasInt(json?.price);
|
|
102
|
+
if (balance === null) balance = gasInt(json?.balance);
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const detail = HTML.test(str) ? "" : str.trim().slice(0, 120);
|
|
107
|
+
return new GasRequiredError({ price, balance, node, account, process: process2, detail: detail === "Insufficient funds" ? "" : detail });
|
|
108
|
+
}
|
|
109
|
+
var GAS_MAX_TAG_BYTES, GAS_MAX_FOR, HTML, GasRequiredError;
|
|
110
|
+
var init_gas = __esm({
|
|
111
|
+
"../rune-ao/src/lib/gas.mjs"() {
|
|
112
|
+
"use strict";
|
|
113
|
+
GAS_MAX_TAG_BYTES = 3072;
|
|
114
|
+
GAS_MAX_FOR = Math.floor((GAS_MAX_TAG_BYTES + 1) / 44);
|
|
115
|
+
HTML = /^\s*(?:<!doctype\s+html|<html|<head|<body)/i;
|
|
116
|
+
GasRequiredError = class extends Error {
|
|
117
|
+
constructor({ price = null, balance = null, node = null, account = null, process: process2 = null, detail = "" } = {}) {
|
|
118
|
+
const need = price === null ? "" : ` It costs ${price}`;
|
|
119
|
+
const have = balance === null ? "" : `${need ? ";" : " The"} balance is ${balance}`;
|
|
120
|
+
super(`Gas required${node ? ` on ${node}` : ""}.${need}${have}${need || have ? " (PUSD base units)." : ""} Nothing was scheduled. Deposit gas, then send it again.` + (detail ? ` (${detail})` : ""));
|
|
121
|
+
this.name = "GasRequiredError";
|
|
122
|
+
this.status = 402;
|
|
123
|
+
this.scheduled = false;
|
|
124
|
+
this.gas = true;
|
|
125
|
+
this.price = price;
|
|
126
|
+
this.balance = balance;
|
|
127
|
+
this.node = node;
|
|
128
|
+
this.account = account;
|
|
129
|
+
this.process = process2;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// ../rune-ao/src/lib/admission.mjs
|
|
136
|
+
function header2(headers, name) {
|
|
35
137
|
if (!headers) return null;
|
|
36
138
|
if (typeof headers.get === "function") return headers.get(name);
|
|
37
139
|
return headers[name] ?? null;
|
|
38
140
|
}
|
|
39
141
|
function isAdmissionRefusal(res) {
|
|
40
|
-
|
|
142
|
+
if (res?.status === 429) return true;
|
|
143
|
+
return res?.status === 503 && String(header2(res.headers, ADMISSION_HEADER) ?? "").trim() === "busy";
|
|
41
144
|
}
|
|
42
145
|
function retryAfterMs(value, now = Date.now()) {
|
|
43
146
|
const text = String(value ?? "").trim();
|
|
@@ -50,21 +153,6 @@ function admissionDelayMs(attempt, retryAfter, random = Math.random) {
|
|
|
50
153
|
const wait = Math.max(retryAfter, exp);
|
|
51
154
|
return Math.round(wait + random() * wait / 2);
|
|
52
155
|
}
|
|
53
|
-
var pause = (ms, signal) => new Promise((resolve, reject) => {
|
|
54
|
-
if (signal?.aborted) {
|
|
55
|
-
reject(signal.reason);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const timer = setTimeout(() => {
|
|
59
|
-
signal?.removeEventListener?.("abort", onAbort);
|
|
60
|
-
resolve();
|
|
61
|
-
}, ms);
|
|
62
|
-
const onAbort = () => {
|
|
63
|
-
clearTimeout(timer);
|
|
64
|
-
reject(signal.reason);
|
|
65
|
-
};
|
|
66
|
-
signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
67
|
-
});
|
|
68
156
|
async function postAdmitted(post, {
|
|
69
157
|
budgetMs = ADMISSION_BUDGET_MS,
|
|
70
158
|
signal,
|
|
@@ -81,7 +169,7 @@ async function postAdmitted(post, {
|
|
|
81
169
|
onRefused?.();
|
|
82
170
|
} catch {
|
|
83
171
|
}
|
|
84
|
-
const wait = admissionDelayMs(attempt, retryAfterMs(
|
|
172
|
+
const wait = admissionDelayMs(attempt, retryAfterMs(header2(res.headers, "retry-after"), now()), random);
|
|
85
173
|
if (now() - started + wait > budgetMs) return res;
|
|
86
174
|
try {
|
|
87
175
|
await res.arrayBuffer?.();
|
|
@@ -94,31 +182,140 @@ async function postAdmitted(post, {
|
|
|
94
182
|
}
|
|
95
183
|
}
|
|
96
184
|
}
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
185
|
+
var ADMISSION_HEADER, ADMISSION_BACKOFF, ADMISSION_BUDGET_MS, pause, AdmissionWaitAborted;
|
|
186
|
+
var init_admission = __esm({
|
|
187
|
+
"../rune-ao/src/lib/admission.mjs"() {
|
|
188
|
+
"use strict";
|
|
189
|
+
init_gas();
|
|
190
|
+
ADMISSION_HEADER = "hb-admission";
|
|
191
|
+
ADMISSION_BACKOFF = Object.freeze({ baseMs: 1e3, capMs: 8e3 });
|
|
192
|
+
ADMISSION_BUDGET_MS = 3e4;
|
|
193
|
+
pause = (ms, signal) => new Promise((resolve, reject) => {
|
|
194
|
+
if (signal?.aborted) {
|
|
195
|
+
reject(signal.reason);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const timer = setTimeout(() => {
|
|
199
|
+
signal?.removeEventListener?.("abort", onAbort);
|
|
200
|
+
resolve();
|
|
201
|
+
}, ms);
|
|
202
|
+
const onAbort = () => {
|
|
203
|
+
clearTimeout(timer);
|
|
204
|
+
reject(signal.reason);
|
|
205
|
+
};
|
|
206
|
+
signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
207
|
+
});
|
|
208
|
+
AdmissionWaitAborted = class extends Error {
|
|
209
|
+
constructor(reason) {
|
|
210
|
+
super("The write was aborted while the node was refusing it; nothing was accepted.");
|
|
211
|
+
this.name = "AbortError";
|
|
212
|
+
this.cause = reason;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
102
215
|
}
|
|
103
|
-
};
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// ../rune-ao/src/lib/transport-timeouts.mjs
|
|
219
|
+
function pushRequestInit() {
|
|
220
|
+
const dispatcher = globalThis[PUSH_DISPATCHER];
|
|
221
|
+
return dispatcher ? { dispatcher } : {};
|
|
222
|
+
}
|
|
223
|
+
var DEFAULT_TRANSPORT_TIMEOUTS, PUSH_SOCKET_CAP_MS, PUSH_DISPATCHER;
|
|
224
|
+
var init_transport_timeouts = __esm({
|
|
225
|
+
"../rune-ao/src/lib/transport-timeouts.mjs"() {
|
|
226
|
+
"use strict";
|
|
227
|
+
DEFAULT_TRANSPORT_TIMEOUTS = Object.freeze({
|
|
228
|
+
publishedReadMs: 3e3,
|
|
229
|
+
computeReadMs: 6e3,
|
|
230
|
+
replyMs: 25e3,
|
|
231
|
+
replyRecoveryMs: 3e4,
|
|
232
|
+
deliveryMs: 9e4
|
|
233
|
+
});
|
|
234
|
+
PUSH_SOCKET_CAP_MS = 10 * 6e4;
|
|
235
|
+
PUSH_DISPATCHER = /* @__PURE__ */ Symbol.for("paralith.push-dispatcher");
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// ../rune-ao/src/lib/slot-result.mjs
|
|
240
|
+
async function nodeDeliversOutboxes(node, {
|
|
241
|
+
fetchImpl = globalThis.fetch,
|
|
242
|
+
timeoutMs = 3e3,
|
|
243
|
+
maxAgeMs = OUTBOX_DELIVERY_RECHECK_MS
|
|
244
|
+
} = {}) {
|
|
245
|
+
const base = String(node ?? "").replace(/\/+$/, "");
|
|
246
|
+
const known = deliveringNodes.get(base);
|
|
247
|
+
if (known !== void 0 && Date.now() - known.at < maxAgeMs) return known.delivers;
|
|
248
|
+
let answer = null;
|
|
249
|
+
try {
|
|
250
|
+
const res = await fetchImpl(`${base}/${OUTBOX_DELIVERY_PATH}`, {
|
|
251
|
+
headers: { accept: "text/plain" },
|
|
252
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
253
|
+
});
|
|
254
|
+
const text = res.status === 200 ? (await res.text()).trim() : "";
|
|
255
|
+
answer = text === OUTBOX_DELIVERY_VALUE ? true : res.status >= 500 ? null : false;
|
|
256
|
+
} catch {
|
|
257
|
+
answer = null;
|
|
258
|
+
}
|
|
259
|
+
if (answer !== null) deliveringNodes.set(base, { delivers: answer, at: Date.now() });
|
|
260
|
+
return answer === true;
|
|
261
|
+
}
|
|
262
|
+
function parsePushReceipts(text) {
|
|
263
|
+
let body;
|
|
264
|
+
try {
|
|
265
|
+
body = JSON.parse(String(text ?? ""));
|
|
266
|
+
} catch {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) return null;
|
|
270
|
+
const outbox = body.outbox ?? body.results?.outbox;
|
|
271
|
+
if (outbox !== void 0 && (outbox === null || typeof outbox !== "object")) return null;
|
|
272
|
+
const keys = nonEmpty(outbox) ? Object.keys(outbox) : [];
|
|
273
|
+
const receipts = {};
|
|
274
|
+
const terminal = [];
|
|
275
|
+
let delivered = true;
|
|
276
|
+
for (const key of keys) {
|
|
277
|
+
const receipt = body[key];
|
|
278
|
+
receipts[key] = receipt ?? null;
|
|
279
|
+
if (receiptTerminal(receipt)) terminal.push(key);
|
|
280
|
+
else if (!receiptSlot(receipt)) delivered = false;
|
|
281
|
+
}
|
|
282
|
+
const output = body.output ?? body.results?.output;
|
|
283
|
+
const data = output !== null && typeof output === "object" ? output.data : void 0;
|
|
284
|
+
return {
|
|
285
|
+
delivered,
|
|
286
|
+
receipts,
|
|
287
|
+
terminal,
|
|
288
|
+
reply: typeof data === "string" && data !== "" ? data : null
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
async function pushVerdict(node, status2, text, delivers, { fetchImpl = globalThis.fetch } = {}) {
|
|
292
|
+
if (notDeliveringAnswer(status2, text) && (delivers || await nodeDeliversOutboxes(node, { fetchImpl, maxAgeMs: 0 }))) {
|
|
293
|
+
return { delivered: false, notDelivering: true };
|
|
294
|
+
}
|
|
295
|
+
if (!delivers) return { delivered: null, notDelivering: false };
|
|
296
|
+
return {
|
|
297
|
+
delivered: status2 >= 200 && status2 < 300 && parsePushReceipts(text)?.delivered === true,
|
|
298
|
+
notDelivering: false
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
var SLOT_RESULT_HEADERS, nonEmpty, OUTBOX_DELIVERY_PATH, OUTBOX_DELIVERY_VALUE, deliveringNodes, OUTBOX_DELIVERY_RECHECK_MS, receiptSlot, receiptTerminal, notDeliveringAnswer;
|
|
302
|
+
var init_slot_result = __esm({
|
|
303
|
+
"../rune-ao/src/lib/slot-result.mjs"() {
|
|
304
|
+
"use strict";
|
|
305
|
+
SLOT_RESULT_HEADERS = Object.freeze({ accept: "application/json", "accept-bundle": "true" });
|
|
306
|
+
nonEmpty = (value) => value !== null && typeof value === "object" && Object.keys(value).length > 0;
|
|
307
|
+
OUTBOX_DELIVERY_PATH = "~meta@1.0/info/outbox-delivery";
|
|
308
|
+
OUTBOX_DELIVERY_VALUE = "durable";
|
|
309
|
+
deliveringNodes = /* @__PURE__ */ new Map();
|
|
310
|
+
OUTBOX_DELIVERY_RECHECK_MS = 5 * 6e4;
|
|
311
|
+
receiptSlot = (r) => r !== null && typeof r === "object" && r.status !== "terminal" && (typeof r.slot === "number" && Number.isSafeInteger(r.slot) && r.slot >= 0 || typeof r.slot === "string" && /^\d+$/.test(r.slot));
|
|
312
|
+
receiptTerminal = (r) => r !== null && typeof r === "object" && r.status === "terminal";
|
|
313
|
+
notDeliveringAnswer = (status2, text) => status2 !== 200 && /does not deliver/i.test(String(text ?? ""));
|
|
314
|
+
}
|
|
315
|
+
});
|
|
104
316
|
|
|
105
317
|
// ../../backend/native/hbclient.mjs
|
|
106
|
-
|
|
107
|
-
var MAX_HEADER_LENGTH = 4096;
|
|
108
|
-
var DERIVED_COMPONENTS = /* @__PURE__ */ new Set([
|
|
109
|
-
"method",
|
|
110
|
-
"target-uri",
|
|
111
|
-
"authority",
|
|
112
|
-
"scheme",
|
|
113
|
-
"request-target",
|
|
114
|
-
"path",
|
|
115
|
-
"query",
|
|
116
|
-
"query-param"
|
|
117
|
-
]);
|
|
118
|
-
var b64url = (buf) => Buffer.from(buf).toString("base64url");
|
|
119
|
-
var b64urlDec = (s) => Buffer.from(s, "base64url");
|
|
120
|
-
var b64std = (buf) => Buffer.from(buf).toString("base64");
|
|
121
|
-
var sha256 = (b) => crypto.createHash("sha256").update(b).digest();
|
|
318
|
+
import crypto2 from "node:crypto";
|
|
122
319
|
function sfString(s) {
|
|
123
320
|
return '"' + String(s).replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
|
|
124
321
|
}
|
|
@@ -129,7 +326,6 @@ function sfBareItem(v) {
|
|
|
129
326
|
if (typeof v === "number") return String(v);
|
|
130
327
|
return sfString(v);
|
|
131
328
|
}
|
|
132
|
-
var sfStr = (s) => ({ __sf: "string", value: s });
|
|
133
329
|
function sfParams(params) {
|
|
134
330
|
return params.map(([k, v]) => ";" + k + "=" + sfBareItem(v)).join("");
|
|
135
331
|
}
|
|
@@ -142,12 +338,10 @@ function sfDict(entries) {
|
|
|
142
338
|
function binCmp(a, b) {
|
|
143
339
|
return Buffer.compare(Buffer.from(a, "binary"), Buffer.from(b, "binary"));
|
|
144
340
|
}
|
|
145
|
-
var sortedKeys = (obj) => Object.keys(obj).sort(binCmp);
|
|
146
341
|
function encodeHeaderValue(v) {
|
|
147
342
|
const s = Buffer.isBuffer(v) ? v.toString("latin1") : String(v);
|
|
148
343
|
return s.replace(/\\/g, "\\\\").replace(/\r/g, "\\r").replace(/\n/g, "\\n");
|
|
149
344
|
}
|
|
150
|
-
var URI_SAFE = /^[a-z0-9.\-_/?&]*$/;
|
|
151
345
|
function escapeKey(k) {
|
|
152
346
|
if (URI_SAFE.test(k)) return k;
|
|
153
347
|
let out = "";
|
|
@@ -158,7 +352,6 @@ function escapeKey(k) {
|
|
|
158
352
|
}
|
|
159
353
|
return out;
|
|
160
354
|
}
|
|
161
|
-
var IS_ID = (k) => /^[a-zA-Z0-9_-]{43}$/.test(k);
|
|
162
355
|
function isPlainObject(v) {
|
|
163
356
|
return v !== null && typeof v === "object" && !Buffer.isBuffer(v) && !Array.isArray(v);
|
|
164
357
|
}
|
|
@@ -205,7 +398,6 @@ function toTabm(value) {
|
|
|
205
398
|
}
|
|
206
399
|
return Buffer.from(String(value), "utf8");
|
|
207
400
|
}
|
|
208
|
-
var byBytes = (a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b));
|
|
209
401
|
function encodeAoTypes(types) {
|
|
210
402
|
const groups = /* @__PURE__ */ new Map();
|
|
211
403
|
for (const key of Object.keys(types).sort(byBytes)) {
|
|
@@ -280,7 +472,6 @@ function encodeFlatMsg(msg) {
|
|
|
280
472
|
if (body.length === 0) return head;
|
|
281
473
|
return Buffer.concat([head, Buffer.from(CRLF + CRLF), body]);
|
|
282
474
|
}
|
|
283
|
-
var asBuf = (v) => Buffer.isBuffer(v) ? v : Buffer.from(String(v));
|
|
284
475
|
function encodeBodyPart(partName, part, inlKey) {
|
|
285
476
|
const disposition = partName === inlKey ? "inline" : `form-data;name="${partName}"`;
|
|
286
477
|
if (isPlainObject(part)) {
|
|
@@ -403,7 +594,7 @@ function keyParams(jwk) {
|
|
|
403
594
|
return { keyid: committerUri(jwkToAddress(jwk)), publicKey: b64url(pubKeyBuf(jwk)) };
|
|
404
595
|
}
|
|
405
596
|
function jwkToPrivateKey(jwk) {
|
|
406
|
-
return
|
|
597
|
+
return crypto2.createPrivateKey({ key: { ...jwk, kty: "RSA" }, format: "jwk" });
|
|
407
598
|
}
|
|
408
599
|
function pubKeyBuf(jwk) {
|
|
409
600
|
return b64urlDec(jwk.n);
|
|
@@ -412,12 +603,12 @@ function ownerToAddress(nB64url) {
|
|
|
412
603
|
return b64url(sha256(b64urlDec(nB64url)));
|
|
413
604
|
}
|
|
414
605
|
function jwkToAddress(jwk) {
|
|
415
|
-
return ownerToAddress(jwk.n);
|
|
606
|
+
return ownerToAddress(jwk.kty === "OKP" ? jwk.x : jwk.n);
|
|
416
607
|
}
|
|
417
608
|
function rsaPssSign(jwk, data) {
|
|
418
|
-
return
|
|
609
|
+
return crypto2.sign("sha512", data, {
|
|
419
610
|
key: jwkToPrivateKey(jwk),
|
|
420
|
-
padding:
|
|
611
|
+
padding: crypto2.constants.RSA_PKCS1_PSS_PADDING,
|
|
421
612
|
saltLength: 64
|
|
422
613
|
// SHA-512 digest length; ar_wallet/rsa_pss uses saltLen == hashLen
|
|
423
614
|
});
|
|
@@ -448,7 +639,7 @@ function hmacCommit(subTabm) {
|
|
|
448
639
|
const wire = sortedKeys(headers).filter((k) => k !== "signature" && k !== "signature-input");
|
|
449
640
|
const params = commitmentParams({ alg: "hmac-sha256", keyid: "constant:ao" });
|
|
450
641
|
const base = signatureBase(headers, wire, params);
|
|
451
|
-
const mac =
|
|
642
|
+
const mac = crypto2.createHmac("sha256", "constant:ao").update(base).digest();
|
|
452
643
|
const id = b64url(mac);
|
|
453
644
|
const rawInputs = sortedKeys(bare);
|
|
454
645
|
const bodyKeys = rawInputs.filter((k) => headers[k] === void 0 && headers[k + "+link"] === void 0);
|
|
@@ -481,7 +672,6 @@ function withNestedHmacs(tabm) {
|
|
|
481
672
|
}
|
|
482
673
|
return out;
|
|
483
674
|
}
|
|
484
|
-
var durMs = (from, to) => Number(to - from) / 1e6;
|
|
485
675
|
function commit(msg, jwk, opts = {}) {
|
|
486
676
|
const { bundle = "true", nestedHmacs = false, ...params0 } = opts;
|
|
487
677
|
const tEncode = process.hrtime.bigint();
|
|
@@ -509,21 +699,25 @@ function commit(msg, jwk, opts = {}) {
|
|
|
509
699
|
committed,
|
|
510
700
|
sigName: name,
|
|
511
701
|
timing: {
|
|
702
|
+
// The message's signed ID, as the node names it: the SHA-256 of the
|
|
703
|
+
// signature. The node's message trace (`/~hyperbuddy@1.0/trace`) carries it.
|
|
704
|
+
mid: b64url(sha256(sig)),
|
|
512
705
|
encodeMs: durMs(tEncode, tSign),
|
|
513
706
|
signMs: durMs(tSign, tSeal),
|
|
514
707
|
sealMs: durMs(tSeal, process.hrtime.bigint())
|
|
515
708
|
}
|
|
516
709
|
};
|
|
517
710
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const url = transportNode(node) + (path2.startsWith("/") ? path2 : "/" + path2);
|
|
711
|
+
async function send(node, path3, method, headers, body, signal, init = {}) {
|
|
712
|
+
const url = transportNode(node) + (path3.startsWith("/") ? path3 : "/" + path3);
|
|
521
713
|
httpRequests += 1;
|
|
522
|
-
|
|
714
|
+
assertDeployTarget(url);
|
|
715
|
+
const res = await fetchWithinTarget(url, {
|
|
716
|
+
...init,
|
|
523
717
|
method,
|
|
524
718
|
headers: { ...headers, "accept-bundle": "true" },
|
|
525
719
|
body: body && body.length ? body : void 0,
|
|
526
|
-
|
|
720
|
+
...signal ? { signal } : {}
|
|
527
721
|
});
|
|
528
722
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
529
723
|
const h = {};
|
|
@@ -532,6 +726,17 @@ async function send(node, path2, method, headers, body) {
|
|
|
532
726
|
});
|
|
533
727
|
return { status: res.status, headers: h, body: buf, url };
|
|
534
728
|
}
|
|
729
|
+
async function fetchWithinTarget(url, init, hops = 0) {
|
|
730
|
+
if (!pinnedTargets()) return fetch(url, { ...init, redirect: "follow" });
|
|
731
|
+
const res = await fetch(url, { ...init, redirect: "manual" });
|
|
732
|
+
const location = res.status >= 300 && res.status < 400 ? res.headers.get("location") : null;
|
|
733
|
+
if (!location) return res;
|
|
734
|
+
if (hops >= 5) throw new Error(`too many redirects from ${url}`);
|
|
735
|
+
const next = new URL(location, url).toString();
|
|
736
|
+
assertDeployTarget(next);
|
|
737
|
+
const keepsBody = res.status === 307 || res.status === 308;
|
|
738
|
+
return fetchWithinTarget(next, keepsBody ? init : { ...init, method: "GET", body: void 0 }, hops + 1);
|
|
739
|
+
}
|
|
535
740
|
function transportNode(node) {
|
|
536
741
|
return (process.env.NODE_TRANSPORT_URL || node).replace(/\/$/, "");
|
|
537
742
|
}
|
|
@@ -542,12 +747,12 @@ function hbError(res) {
|
|
|
542
747
|
if (m) return dec(m[1]).replace(/\s+/g, " ").trim();
|
|
543
748
|
return res.headers["details"] || t.slice(0, 400);
|
|
544
749
|
}
|
|
545
|
-
async function postSigned(node,
|
|
750
|
+
async function postSigned(node, path3, msg, jwk, opts = {}) {
|
|
546
751
|
const { headers, body, signatureBase: base, committed, timing } = commit(msg, jwk, opts);
|
|
547
752
|
const tPost = process.hrtime.bigint();
|
|
548
753
|
let refusals = 0;
|
|
549
754
|
const res = await postAdmitted(
|
|
550
|
-
() => send(node,
|
|
755
|
+
() => send(node, path3, "POST", headers, body),
|
|
551
756
|
{ onRefused: () => {
|
|
552
757
|
refusals += 1;
|
|
553
758
|
} }
|
|
@@ -555,13 +760,13 @@ async function postSigned(node, path2, msg, jwk, opts = {}) {
|
|
|
555
760
|
const postMs = durMs(tPost, process.hrtime.bigint());
|
|
556
761
|
res.request = { headers, body, base, committed };
|
|
557
762
|
res.timing = { ...timing, postMs, bytes: body ? body.length : 0, ...refusals ? { refusals } : {} };
|
|
763
|
+
if (isGasRefusal(res)) {
|
|
764
|
+
const error = parseGasRequired(res, { node, account: jwkToAddress(jwk), process: msg?.target ?? null });
|
|
765
|
+
error.timing = res.timing;
|
|
766
|
+
throw error;
|
|
767
|
+
}
|
|
558
768
|
return res;
|
|
559
769
|
}
|
|
560
|
-
var SCHEDULE_ROUTE = /* @__PURE__ */ new Map();
|
|
561
|
-
var PID_SLOT = "{pid}";
|
|
562
|
-
var sendObserver = null;
|
|
563
|
-
var sendRoles = {};
|
|
564
|
-
var unsettledSends = [];
|
|
565
770
|
function observeSend(timing, observer = sendObserver) {
|
|
566
771
|
if (!observer) return;
|
|
567
772
|
try {
|
|
@@ -573,11 +778,11 @@ async function sendMessage({
|
|
|
573
778
|
node,
|
|
574
779
|
jwk,
|
|
575
780
|
process: pid,
|
|
576
|
-
action,
|
|
781
|
+
action: action2,
|
|
577
782
|
tags = {},
|
|
578
783
|
data,
|
|
579
784
|
body,
|
|
580
|
-
path:
|
|
785
|
+
path: path3,
|
|
581
786
|
push = true
|
|
582
787
|
}) {
|
|
583
788
|
const t0 = Date.now();
|
|
@@ -590,7 +795,7 @@ async function sendMessage({
|
|
|
590
795
|
put("target", pid);
|
|
591
796
|
put("type", "Message");
|
|
592
797
|
put("subject", "self");
|
|
593
|
-
if (
|
|
798
|
+
if (action2) put("action", action2);
|
|
594
799
|
for (const [k, v] of Object.entries(tags)) put(k, v);
|
|
595
800
|
if (data !== void 0) put("data", data);
|
|
596
801
|
put("random-seed", String(Math.floor(Math.random() * 1e9)));
|
|
@@ -610,6 +815,7 @@ async function sendMessage({
|
|
|
610
815
|
t0,
|
|
611
816
|
t1: Date.now(),
|
|
612
817
|
buildMs: t ? t.encodeMs : 0,
|
|
818
|
+
...t?.mid ? { mid: t.mid } : {},
|
|
613
819
|
signMs: t ? t.signMs + t.sealMs : 0,
|
|
614
820
|
postMs: t ? t.postMs : 0,
|
|
615
821
|
sendMs: durMs(started, process.hrtime.bigint()),
|
|
@@ -624,9 +830,9 @@ async function sendMessage({
|
|
|
624
830
|
const report = (outcome, detail) => {
|
|
625
831
|
if (sendObserver) observeSend(timing(outcome, detail));
|
|
626
832
|
};
|
|
627
|
-
const candidates =
|
|
833
|
+
const candidates = path3 ? [path3] : [`/${pid}~process@1.0/schedule`, `/${pid}~scheduler@1.0/schedule`, `/${pid}/schedule`];
|
|
628
834
|
const known = SCHEDULE_ROUTE.get(node)?.replaceAll(PID_SLOT, pid);
|
|
629
|
-
const ordered = known && !
|
|
835
|
+
const ordered = known && !path3 ? [known, ...candidates.filter((p) => p !== known)] : candidates;
|
|
630
836
|
const tried = [];
|
|
631
837
|
let lastResponse = null;
|
|
632
838
|
for (const candidate of ordered) {
|
|
@@ -634,12 +840,12 @@ async function sendMessage({
|
|
|
634
840
|
try {
|
|
635
841
|
res = await postSigned(node, candidate, msg, jwk);
|
|
636
842
|
} catch (error2) {
|
|
637
|
-
report("post-failed", { error: error2 instanceof Error ? `${error2.name}: ${error2.message}` : String(error2) });
|
|
843
|
+
report(error2?.name === "GasRequiredError" ? "gas-required" : "post-failed", { error: error2 instanceof Error ? `${error2.name}: ${error2.message}` : String(error2) });
|
|
638
844
|
throw error2;
|
|
639
845
|
}
|
|
640
846
|
lastResponse = res;
|
|
641
847
|
if (res.status === 200) {
|
|
642
|
-
if (!
|
|
848
|
+
if (!path3) SCHEDULE_ROUTE.set(node, candidate.replaceAll(pid, PID_SLOT));
|
|
643
849
|
const slot = res.headers["slot"];
|
|
644
850
|
if (push && slot !== void 0 && slot !== null) {
|
|
645
851
|
queuePush({ node, process: pid, slot });
|
|
@@ -665,33 +871,431 @@ async function sendMessage({
|
|
|
665
871
|
error.status = lastResponse?.status ?? null;
|
|
666
872
|
error.refused = isAdmissionRefusal(lastResponse);
|
|
667
873
|
report(
|
|
668
|
-
error.
|
|
874
|
+
error.status === 429 ? "rate-limited" : error.refused ? "refused" : error.status === 408 ? "timeout" : "post-failed",
|
|
669
875
|
{ res: lastResponse, error: error.message }
|
|
670
876
|
);
|
|
671
877
|
throw error;
|
|
672
878
|
}
|
|
673
879
|
async function pushSlot({ node, process: pid, slot }) {
|
|
880
|
+
let verdict;
|
|
674
881
|
try {
|
|
675
|
-
const
|
|
676
|
-
|
|
882
|
+
const base = transportNode(node);
|
|
883
|
+
const delivers = await nodeDeliversOutboxes(base);
|
|
884
|
+
const res = await send(
|
|
885
|
+
node,
|
|
886
|
+
`/${pid}~process@1.0/push&slot=${slot}&max-depth=0`,
|
|
887
|
+
"GET",
|
|
888
|
+
delivers ? { accept: SLOT_RESULT_HEADERS.accept } : {},
|
|
889
|
+
void 0,
|
|
890
|
+
AbortSignal.timeout(PUSH_SOCKET_CAP_MS),
|
|
891
|
+
pushRequestInit()
|
|
892
|
+
);
|
|
893
|
+
verdict = { ...await pushVerdict(base, res.status, res.body.toString(), delivers), status: res.status };
|
|
677
894
|
} catch {
|
|
678
895
|
return false;
|
|
679
896
|
}
|
|
897
|
+
if (verdict.notDelivering) throw new NotDeliveringNodeError({ node, process: pid, slot, status: verdict.status });
|
|
898
|
+
return verdict.delivered ?? verdict.status === 200;
|
|
680
899
|
}
|
|
681
|
-
var PUSH_QUEUES = /* @__PURE__ */ new Map();
|
|
682
900
|
function queuePush({ node, process: pid, slot }) {
|
|
683
901
|
const key = `${node}|${pid}`;
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
|
|
902
|
+
const running = PUSHES.get(key) ?? /* @__PURE__ */ new Set();
|
|
903
|
+
PUSHES.set(key, running);
|
|
904
|
+
const push = pushSlot({ node, process: pid, slot }).catch((error) => {
|
|
905
|
+
if (error?.name === "NotDeliveringNodeError" && !NOT_DELIVERING_REPORTED.has(key)) {
|
|
906
|
+
NOT_DELIVERING_REPORTED.add(key);
|
|
907
|
+
console.error(`[hbclient] ${error.message}`);
|
|
908
|
+
}
|
|
909
|
+
return false;
|
|
910
|
+
}).finally(() => {
|
|
911
|
+
running.delete(push);
|
|
912
|
+
if (running.size === 0 && PUSHES.get(key) === running) PUSHES.delete(key);
|
|
913
|
+
});
|
|
914
|
+
running.add(push);
|
|
915
|
+
return push;
|
|
687
916
|
}
|
|
688
917
|
async function pendingPushes({ node, process: pid } = {}) {
|
|
689
|
-
const
|
|
690
|
-
await Promise.all(
|
|
918
|
+
const sets = node && pid ? [PUSHES.get(`${node}|${pid}`)] : [...PUSHES.values()];
|
|
919
|
+
await Promise.all(sets.filter(Boolean).flatMap((running) => [...running]));
|
|
920
|
+
}
|
|
921
|
+
var CRLF, MAX_HEADER_LENGTH, DERIVED_COMPONENTS, b64url, b64urlDec, b64std, sha256, sfStr, sortedKeys, URI_SAFE, IS_ID, byBytes, asBuf, durMs, httpRequests, SCHEDULE_ROUTE, PID_SLOT, sendObserver, sendRoles, unsettledSends, NotDeliveringNodeError, PUSHES, NOT_DELIVERING_REPORTED;
|
|
922
|
+
var init_hbclient = __esm({
|
|
923
|
+
"../../backend/native/hbclient.mjs"() {
|
|
924
|
+
init_deploy_target();
|
|
925
|
+
init_slot_settle();
|
|
926
|
+
init_admission();
|
|
927
|
+
init_gas();
|
|
928
|
+
init_transport_timeouts();
|
|
929
|
+
init_slot_result();
|
|
930
|
+
CRLF = "\r\n";
|
|
931
|
+
MAX_HEADER_LENGTH = 4096;
|
|
932
|
+
DERIVED_COMPONENTS = /* @__PURE__ */ new Set([
|
|
933
|
+
"method",
|
|
934
|
+
"target-uri",
|
|
935
|
+
"authority",
|
|
936
|
+
"scheme",
|
|
937
|
+
"request-target",
|
|
938
|
+
"path",
|
|
939
|
+
"query",
|
|
940
|
+
"query-param"
|
|
941
|
+
]);
|
|
942
|
+
b64url = (buf) => Buffer.from(buf).toString("base64url");
|
|
943
|
+
b64urlDec = (s) => Buffer.from(s, "base64url");
|
|
944
|
+
b64std = (buf) => Buffer.from(buf).toString("base64");
|
|
945
|
+
sha256 = (b) => crypto2.createHash("sha256").update(b).digest();
|
|
946
|
+
sfStr = (s) => ({ __sf: "string", value: s });
|
|
947
|
+
sortedKeys = (obj) => Object.keys(obj).sort(binCmp);
|
|
948
|
+
URI_SAFE = /^[a-z0-9.\-_/?&]*$/;
|
|
949
|
+
IS_ID = (k) => /^[a-zA-Z0-9_-]{43}$/.test(k);
|
|
950
|
+
byBytes = (a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b));
|
|
951
|
+
asBuf = (v) => Buffer.isBuffer(v) ? v : Buffer.from(String(v));
|
|
952
|
+
durMs = (from, to) => Number(to - from) / 1e6;
|
|
953
|
+
httpRequests = 0;
|
|
954
|
+
SCHEDULE_ROUTE = /* @__PURE__ */ new Map();
|
|
955
|
+
PID_SLOT = "{pid}";
|
|
956
|
+
sendObserver = null;
|
|
957
|
+
sendRoles = {};
|
|
958
|
+
unsettledSends = [];
|
|
959
|
+
NotDeliveringNodeError = class extends Error {
|
|
960
|
+
constructor({ node, process: pid, slot, status: status2 }) {
|
|
961
|
+
super(`${transportNode(node)} does not deliver the outbox of ${pid} (push&slot=${slot} answered ${status2}); the node that schedules it delivers it. Push there, or read its published state.`);
|
|
962
|
+
this.name = "NotDeliveringNodeError";
|
|
963
|
+
Object.assign(this, { node, process: pid, slot, status: status2 });
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
PUSHES = /* @__PURE__ */ new Map();
|
|
967
|
+
NOT_DELIVERING_REPORTED = /* @__PURE__ */ new Set();
|
|
968
|
+
process.on("beforeExit", () => {
|
|
969
|
+
void pendingPushes();
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
// ../paralith-bridge/src/cli.mjs
|
|
975
|
+
init_hbclient();
|
|
976
|
+
import crypto3 from "node:crypto";
|
|
977
|
+
import fs2 from "node:fs";
|
|
978
|
+
import os from "node:os";
|
|
979
|
+
import path2 from "node:path";
|
|
980
|
+
import { createPublicClient, createWalletClient, encodeAbiParameters as encodeAbiParameters2, http, keccak256 as keccak2562, parseAbi, recoverMessageAddress, toBytes as toBytes2 } from "viem";
|
|
981
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
982
|
+
import { base as baseChain } from "viem/chains";
|
|
983
|
+
import {
|
|
984
|
+
Connection,
|
|
985
|
+
Ed25519Program,
|
|
986
|
+
Keypair,
|
|
987
|
+
PublicKey,
|
|
988
|
+
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
989
|
+
SystemProgram,
|
|
990
|
+
Transaction,
|
|
991
|
+
TransactionInstruction,
|
|
992
|
+
sendAndConfirmTransaction
|
|
993
|
+
} from "@solana/web3.js";
|
|
994
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
995
|
+
import { Transaction as SuiTransaction } from "@mysten/sui/transactions";
|
|
996
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
997
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
998
|
+
|
|
999
|
+
// ../hypertoken/src/quantity.mjs
|
|
1000
|
+
var MAX_QUANTITY = 2n ** 53n - 1n;
|
|
1001
|
+
var ID = /^[A-Za-z0-9_-]{43}$/;
|
|
1002
|
+
var isId = (value) => typeof value === "string" && ID.test(value);
|
|
1003
|
+
|
|
1004
|
+
// ../hypertoken/src/root-carrier.mjs
|
|
1005
|
+
import { bls12_381 as bls } from "@noble/curves/bls12-381";
|
|
1006
|
+
|
|
1007
|
+
// ../hypertoken/src/read.mjs
|
|
1008
|
+
var HTML2 = /^\s*<(!doctype|html|head|body)/i;
|
|
1009
|
+
var cleanNode = (url) => String(url ?? "").trim().replace(/\/+$/, "").replace(/^(?!https?:\/\/)/, "https://");
|
|
1010
|
+
function unwrap(value) {
|
|
1011
|
+
for (let depth = 0; depth < 3; depth += 1) {
|
|
1012
|
+
if (value && typeof value === "object" && !Array.isArray(value) && value["ao-result"] === "body") value = value.body;
|
|
1013
|
+
else if (typeof value === "string" && /^\s*[[{]/.test(value)) {
|
|
1014
|
+
try {
|
|
1015
|
+
value = JSON.parse(value);
|
|
1016
|
+
} catch {
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
} else break;
|
|
1020
|
+
}
|
|
1021
|
+
return value;
|
|
691
1022
|
}
|
|
692
|
-
|
|
693
|
-
|
|
1023
|
+
async function readPublished(node, pid, key, { fetch: f = globalThis.fetch, timeoutMs = 2e4 } = {}) {
|
|
1024
|
+
const url = `${cleanNode(node)}/${pid}~process@1.0/now/${key}`;
|
|
1025
|
+
let res;
|
|
1026
|
+
try {
|
|
1027
|
+
res = await f(url, {
|
|
1028
|
+
headers: { accept: "application/json", "cache-control": "no-cache" },
|
|
1029
|
+
signal: typeof AbortSignal !== "undefined" && AbortSignal.timeout ? AbortSignal.timeout(timeoutMs) : void 0
|
|
1030
|
+
});
|
|
1031
|
+
} catch (error) {
|
|
1032
|
+
return { present: false, error: `unreachable: ${error?.message ?? error}` };
|
|
1033
|
+
}
|
|
1034
|
+
const text = await res.text();
|
|
1035
|
+
if (HTML2.test(text)) return { present: false, status: res.status, text };
|
|
1036
|
+
if (res.status === 404) return { present: false, status: 404, text };
|
|
1037
|
+
if (!res.ok) return { present: false, status: res.status, error: `HTTP ${res.status}`, text };
|
|
1038
|
+
if (text.trim() === "") return { present: false, status: res.status, text };
|
|
1039
|
+
try {
|
|
1040
|
+
return { present: true, status: res.status, text, value: unwrap(JSON.parse(text)) };
|
|
1041
|
+
} catch {
|
|
1042
|
+
return { present: true, status: res.status, text, value: text.trim().replace(/^"+|"+$/g, "") };
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// ../hypertoken/src/manifest.mjs
|
|
1047
|
+
var SCHEMA = "hypertoken-manifest/v2";
|
|
1048
|
+
var DOMAIN = `${SCHEMA}
|
|
1049
|
+
`;
|
|
1050
|
+
|
|
1051
|
+
// ../hypertoken/src/root-carrier.mjs
|
|
1052
|
+
var utf8 = new TextEncoder();
|
|
1053
|
+
|
|
1054
|
+
// ../hypertoken/src/root-certificate.mjs
|
|
1055
|
+
var fail = (reason) => {
|
|
1056
|
+
throw new Error(`Root certificate: ${reason}`);
|
|
1057
|
+
};
|
|
1058
|
+
var ROOT_ACTIONS = Object.freeze({
|
|
1059
|
+
Transfer: "holder",
|
|
1060
|
+
"Ledger-Enter": "holder",
|
|
1061
|
+
"Bridge-Redeem": "holder",
|
|
1062
|
+
"Ledger-Release": "lane",
|
|
1063
|
+
"Ledger-Register": "lane",
|
|
1064
|
+
"Ledger-Accepts": "lane",
|
|
1065
|
+
"Bridge-Mint": "member",
|
|
1066
|
+
"Ledger-Exit": "member",
|
|
1067
|
+
"Ledger-Move-Root": "member",
|
|
1068
|
+
"Bridge-Released": "member",
|
|
1069
|
+
"Ledger-Credited": "member",
|
|
1070
|
+
"Attestor-Apply": "member"
|
|
694
1071
|
});
|
|
1072
|
+
async function readEndorsement(response) {
|
|
1073
|
+
const limit = 65536;
|
|
1074
|
+
if (Number(response.headers.get("content-length")) > limit || !response.body) fail("oversized or empty endorsement");
|
|
1075
|
+
const reader = response.body.getReader();
|
|
1076
|
+
const chunks = [];
|
|
1077
|
+
let length = 0;
|
|
1078
|
+
try {
|
|
1079
|
+
for (; ; ) {
|
|
1080
|
+
const { done, value } = await reader.read();
|
|
1081
|
+
if (done) break;
|
|
1082
|
+
length += value.length;
|
|
1083
|
+
if (length > limit) {
|
|
1084
|
+
await reader.cancel();
|
|
1085
|
+
fail("oversized endorsement");
|
|
1086
|
+
}
|
|
1087
|
+
if (value.length) chunks.push(value);
|
|
1088
|
+
}
|
|
1089
|
+
} finally {
|
|
1090
|
+
reader.releaseLock();
|
|
1091
|
+
}
|
|
1092
|
+
const bytes = new Uint8Array(length);
|
|
1093
|
+
let offset = 0;
|
|
1094
|
+
for (const chunk of chunks) {
|
|
1095
|
+
bytes.set(chunk, offset);
|
|
1096
|
+
offset += chunk.length;
|
|
1097
|
+
}
|
|
1098
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
1099
|
+
}
|
|
1100
|
+
async function memberNodes(node, aos, nodes, fetcher) {
|
|
1101
|
+
const known = new Map(nodes.filter((n) => isId(n.ao) && n.url).map((n) => [n.ao, cleanNode(n.url)]));
|
|
1102
|
+
return Promise.all(aos.map(async (ao) => {
|
|
1103
|
+
let endpoint = known.get(ao) ?? "";
|
|
1104
|
+
if (!endpoint) {
|
|
1105
|
+
try {
|
|
1106
|
+
const response = await fetcher(
|
|
1107
|
+
`${cleanNode(node)}/~location@1.0/${ao}?variant=ao.N.1`,
|
|
1108
|
+
{ headers: { accept: "application/json" }, signal: AbortSignal.timeout(1e4) }
|
|
1109
|
+
);
|
|
1110
|
+
if (response.ok) {
|
|
1111
|
+
const location = await readEndorsement(response);
|
|
1112
|
+
if (typeof location.url === "string") endpoint = cleanNode(location.url);
|
|
1113
|
+
}
|
|
1114
|
+
} catch {
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return { ao, node: endpoint };
|
|
1118
|
+
}));
|
|
1119
|
+
}
|
|
1120
|
+
async function collectChainSignatures({
|
|
1121
|
+
root,
|
|
1122
|
+
node,
|
|
1123
|
+
withdrawal,
|
|
1124
|
+
proposal: proposal2,
|
|
1125
|
+
nodes = [],
|
|
1126
|
+
fetch: fetcher = globalThis.fetch,
|
|
1127
|
+
timeoutMs = 2e4
|
|
1128
|
+
}) {
|
|
1129
|
+
if (withdrawal === void 0 === (proposal2 === void 0)) fail("name one withdrawal or one proposal");
|
|
1130
|
+
const id = String(withdrawal ?? proposal2);
|
|
1131
|
+
if (!/^[1-9][0-9]*$/.test(id)) fail("invalid record id");
|
|
1132
|
+
const read = await readPublished(node, root, "bridgeinfo", { fetch: fetcher });
|
|
1133
|
+
const info = read.present ? read.value : null;
|
|
1134
|
+
if (!Array.isArray(info?.attestors)) fail("root bridge state is unavailable");
|
|
1135
|
+
let members = info.attestors;
|
|
1136
|
+
if (proposal2 !== void 0) {
|
|
1137
|
+
const p = (info.proposals ?? []).find((x) => String(x.id) === id);
|
|
1138
|
+
if (!p || p.status !== "applied" || !Array.isArray(p.prior)) fail("the proposal is not applied");
|
|
1139
|
+
members = p.prior;
|
|
1140
|
+
}
|
|
1141
|
+
const located = await memberNodes(node, members.map((m) => m.ao), nodes, fetcher);
|
|
1142
|
+
const query = withdrawal !== void 0 ? `withdrawal=${id}` : `proposal=${id}`;
|
|
1143
|
+
const answers = await Promise.all(located.map(async ({ ao, node: url }) => {
|
|
1144
|
+
try {
|
|
1145
|
+
const endpoint = new URL(url);
|
|
1146
|
+
if (!["https:", "http:"].includes(endpoint.protocol) || endpoint.username || endpoint.password) return null;
|
|
1147
|
+
endpoint.pathname = endpoint.pathname.replace(/\/+$/, "") + "/~bridge-attestor@1.0/chain-sig";
|
|
1148
|
+
endpoint.search = query;
|
|
1149
|
+
const response = await fetcher(endpoint.href, {
|
|
1150
|
+
headers: { accept: "application/json" },
|
|
1151
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
1152
|
+
});
|
|
1153
|
+
if (!response.ok) return null;
|
|
1154
|
+
const answer = await readEndorsement(response);
|
|
1155
|
+
return answer?.signer === ao ? [ao, answer] : null;
|
|
1156
|
+
} catch {
|
|
1157
|
+
return null;
|
|
1158
|
+
}
|
|
1159
|
+
}));
|
|
1160
|
+
const ok = answers.filter(Boolean);
|
|
1161
|
+
const isSig = (s) => typeof s === "string" && /^0x[0-9a-fA-F]{2,200}$/.test(s);
|
|
1162
|
+
if (withdrawal !== void 0) {
|
|
1163
|
+
return { sigs: Object.fromEntries(ok.filter(([, a]) => String(a.withdrawal) === id && isSig(a.sig)).map(([ao, a]) => [ao, a.sig])) };
|
|
1164
|
+
}
|
|
1165
|
+
return { votes: Object.fromEntries(ok.filter(([, a]) => String(a.proposal) === id).map(([ao, a]) => [ao, Object.fromEntries(["base", "solana", "sui"].filter((c) => isSig(a[c])).map((c) => [c, a[c]]))])) };
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// ../paralith-bridge/src/rpc.mjs
|
|
1169
|
+
import fs from "node:fs";
|
|
1170
|
+
import path from "node:path";
|
|
1171
|
+
function solanaRpcRefusal(url) {
|
|
1172
|
+
let host;
|
|
1173
|
+
try {
|
|
1174
|
+
host = new URL(url).hostname.toLowerCase();
|
|
1175
|
+
} catch {
|
|
1176
|
+
return "an RPC that is not a URL";
|
|
1177
|
+
}
|
|
1178
|
+
if (host === "api.mainnet-beta.solana.com") return "the public mainnet endpoint";
|
|
1179
|
+
if (host.includes("helius")) return "a Helius endpoint";
|
|
1180
|
+
return null;
|
|
1181
|
+
}
|
|
1182
|
+
var solanaMainnet = (deployment2) => !/devnet|testnet|localnet/.test(String(deployment2?.solana?.cluster ?? deployment2?.network ?? ""));
|
|
1183
|
+
function rpcFor(chain, { flag, env, keysDir, deployment: deployment2 }) {
|
|
1184
|
+
const given = flag ?? env[`PARALITH_${chain.toUpperCase()}_RPC`];
|
|
1185
|
+
if (chain !== "solana") return given || deployment2[chain].rpc;
|
|
1186
|
+
const file = path.join(keysDir, "solana-rpc.txt");
|
|
1187
|
+
const url = given || (fs.existsSync(file) ? fs.readFileSync(file, "utf8").trim() : "");
|
|
1188
|
+
if (!url) throw new Error(`no private Solana RPC: write it to ${file}, or pass --rpc / PARALITH_SOLANA_RPC`);
|
|
1189
|
+
const why = solanaMainnet(deployment2) ? solanaRpcRefusal(url) : null;
|
|
1190
|
+
if (why) throw new Error(`refusing ${why} as the Solana mainnet RPC (${given ? "--rpc / PARALITH_SOLANA_RPC" : file}): use the private RPC`);
|
|
1191
|
+
return url;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// ../paralith-bridge/src/admin-message.mjs
|
|
1195
|
+
import { encodeAbiParameters, keccak256, toBytes } from "viem";
|
|
1196
|
+
var ADMIN_TYPE = "PARALITH_ADMIN_V2";
|
|
1197
|
+
var ALLOW_TOKEN = 1;
|
|
1198
|
+
var UNPAUSE = 2;
|
|
1199
|
+
var ZERO_EVM = "0x0000000000000000000000000000000000000000";
|
|
1200
|
+
function u64(n) {
|
|
1201
|
+
const v = BigInt(n);
|
|
1202
|
+
if (v < 0n || v >= 1n << 64n) throw new Error(`${n} is not a u64`);
|
|
1203
|
+
const b = Buffer.alloc(8);
|
|
1204
|
+
b.writeBigUInt64LE(v);
|
|
1205
|
+
return b;
|
|
1206
|
+
}
|
|
1207
|
+
function bytes32(value, what) {
|
|
1208
|
+
const b = Buffer.from(value);
|
|
1209
|
+
if (b.length !== 32) throw new Error(`${what} must be 32 bytes`);
|
|
1210
|
+
return b;
|
|
1211
|
+
}
|
|
1212
|
+
function action(a) {
|
|
1213
|
+
if (a !== ALLOW_TOKEN && a !== UNPAUSE) throw new Error(`unknown admin action ${a}`);
|
|
1214
|
+
return a;
|
|
1215
|
+
}
|
|
1216
|
+
function rootBytes(id) {
|
|
1217
|
+
return bytes32(Buffer.from(id ?? "", "base64url"), `process id ${id || "<empty>"}`);
|
|
1218
|
+
}
|
|
1219
|
+
function baseAdminInner({ chainId, bridge, root, epoch, nonce, action: a, token, value = true }) {
|
|
1220
|
+
const allow = action(a) === ALLOW_TOKEN;
|
|
1221
|
+
return keccak256(encodeAbiParameters(
|
|
1222
|
+
[
|
|
1223
|
+
{ type: "bytes32" },
|
|
1224
|
+
{ type: "uint256" },
|
|
1225
|
+
{ type: "address" },
|
|
1226
|
+
{ type: "bytes32" },
|
|
1227
|
+
{ type: "uint64" },
|
|
1228
|
+
{ type: "uint64" },
|
|
1229
|
+
{ type: "bytes32" },
|
|
1230
|
+
{ type: "address" },
|
|
1231
|
+
{ type: "bool" }
|
|
1232
|
+
],
|
|
1233
|
+
[
|
|
1234
|
+
keccak256(toBytes(ADMIN_TYPE)),
|
|
1235
|
+
BigInt(chainId),
|
|
1236
|
+
bridge,
|
|
1237
|
+
`0x${rootBytes(root).toString("hex")}`,
|
|
1238
|
+
BigInt(epoch),
|
|
1239
|
+
u64(nonce).readBigUInt64LE(0),
|
|
1240
|
+
keccak256(toBytes(allow ? "ALLOW_TOKEN" : "UNPAUSE")),
|
|
1241
|
+
allow ? token : ZERO_EVM,
|
|
1242
|
+
value
|
|
1243
|
+
]
|
|
1244
|
+
));
|
|
1245
|
+
}
|
|
1246
|
+
function solanaAdminMessage({ program, root, epoch, nonce, action: a, mint, value = true }) {
|
|
1247
|
+
const allow = action(a) === ALLOW_TOKEN;
|
|
1248
|
+
return Buffer.concat([
|
|
1249
|
+
Buffer.from(ADMIN_TYPE),
|
|
1250
|
+
bytes32(program, "program id"),
|
|
1251
|
+
rootBytes(root),
|
|
1252
|
+
u64(epoch),
|
|
1253
|
+
u64(nonce),
|
|
1254
|
+
Buffer.from([a]),
|
|
1255
|
+
allow ? bytes32(mint, "mint") : Buffer.alloc(32),
|
|
1256
|
+
Buffer.from([value ? 1 : 0])
|
|
1257
|
+
]);
|
|
1258
|
+
}
|
|
1259
|
+
var ATTESTORS_TYPE = "PARALITH_ATTESTORS_V2";
|
|
1260
|
+
function setOf(set) {
|
|
1261
|
+
if (!Array.isArray(set) || set.length < 1 || set.length > 16) throw new Error("an attestor set is 1-16 keys");
|
|
1262
|
+
return set;
|
|
1263
|
+
}
|
|
1264
|
+
function baseAttestorsInner({ chainId, bridge, root, epoch, newEpoch, set }) {
|
|
1265
|
+
setOf(set);
|
|
1266
|
+
return keccak256(encodeAbiParameters(
|
|
1267
|
+
[
|
|
1268
|
+
{ type: "bytes32" },
|
|
1269
|
+
{ type: "uint256" },
|
|
1270
|
+
{ type: "address" },
|
|
1271
|
+
{ type: "bytes32" },
|
|
1272
|
+
{ type: "uint64" },
|
|
1273
|
+
{ type: "uint64" },
|
|
1274
|
+
{ type: "address[]" }
|
|
1275
|
+
],
|
|
1276
|
+
[
|
|
1277
|
+
keccak256(toBytes(ATTESTORS_TYPE)),
|
|
1278
|
+
BigInt(chainId),
|
|
1279
|
+
bridge,
|
|
1280
|
+
`0x${rootBytes(root).toString("hex")}`,
|
|
1281
|
+
u64(epoch).readBigUInt64LE(0),
|
|
1282
|
+
u64(newEpoch).readBigUInt64LE(0),
|
|
1283
|
+
set
|
|
1284
|
+
]
|
|
1285
|
+
));
|
|
1286
|
+
}
|
|
1287
|
+
function solanaAttestorsMessage({ program, root, epoch, newEpoch, set }) {
|
|
1288
|
+
const keys = setOf(set).map((k) => bytes32(k, "Solana attestor key"));
|
|
1289
|
+
return Buffer.concat([
|
|
1290
|
+
Buffer.from(ATTESTORS_TYPE),
|
|
1291
|
+
bytes32(program, "program id"),
|
|
1292
|
+
rootBytes(root),
|
|
1293
|
+
u64(epoch),
|
|
1294
|
+
u64(newEpoch),
|
|
1295
|
+
Buffer.from([keys.length]),
|
|
1296
|
+
...keys
|
|
1297
|
+
]);
|
|
1298
|
+
}
|
|
695
1299
|
|
|
696
1300
|
// ../paralith-bridge/src/cli.mjs
|
|
697
1301
|
var MANIFEST = "https://bridge.paralithmarkets.com/bridge.json";
|
|
@@ -702,11 +1306,14 @@ var HELP = `paralith-bridge <command>
|
|
|
702
1306
|
propose-remove <node-ao> propose removing one
|
|
703
1307
|
propose-migrate <new-pusd> propose moving the set to a replacement PUSD; every node follows
|
|
704
1308
|
propose-token <base|solana|sui> ask the current majority to admit the recorded TEST token
|
|
705
|
-
approve <id> approve as operator;
|
|
706
|
-
|
|
1309
|
+
approve <id> approve as operator; once a majority of nodes' operators
|
|
1310
|
+
approve, the nodes apply it at PUSD with one certificate
|
|
1311
|
+
apply <id> collect the prior members' chain signatures from their nodes
|
|
1312
|
+
and carry them to Base, Solana and Sui (pays each chain's gas;
|
|
707
1313
|
--chain base|solana|sui for one)
|
|
708
1314
|
pause stop PUSD minting, redeeming and signing releases (any operator)
|
|
709
|
-
unpause propose
|
|
1315
|
+
unpause propose lifting the owner's pause on every chain (--chain one);
|
|
1316
|
+
binds each chain's current admin nonce; majority approves and signs
|
|
710
1317
|
|
|
711
1318
|
Keys are read from ~/.paralith/bridge/ unless a flag names another file:
|
|
712
1319
|
operator.json the operator's Arweave keyfile (--wallet <file>)
|
|
@@ -715,7 +1322,8 @@ Keys are read from ~/.paralith/bridge/ unless a flag names another file:
|
|
|
715
1322
|
sui.key Sui gas payer, suiprivkey1... (--key <file>)
|
|
716
1323
|
|
|
717
1324
|
--operator <addr> propose-add: the new node's operator (default: --wallet's address)
|
|
718
|
-
--rpc <url> apply's RPC (or PARALITH_BASE_RPC / _SOLANA_RPC / _SUI_RPC)
|
|
1325
|
+
--rpc <url> apply's RPC (or PARALITH_BASE_RPC / _SOLANA_RPC / _SUI_RPC);
|
|
1326
|
+
Solana otherwise needs a private RPC in solana-rpc.txt
|
|
719
1327
|
--pusd <id> act on this PUSD, not the manifest's (approve on a PUSD being replaced)
|
|
720
1328
|
--manifest <url> the deployment description (default ${MANIFEST})`;
|
|
721
1329
|
var CHAINS = ["base", "solana", "sui"];
|
|
@@ -730,10 +1338,10 @@ var die = (msg) => {
|
|
|
730
1338
|
console.error(`error: ${msg}`);
|
|
731
1339
|
process.exit(1);
|
|
732
1340
|
};
|
|
733
|
-
var KEYS =
|
|
1341
|
+
var KEYS = path2.join(os.homedir(), ".paralith", "bridge");
|
|
734
1342
|
var readFile = (file, what) => {
|
|
735
1343
|
try {
|
|
736
|
-
return
|
|
1344
|
+
return fs2.readFileSync(file, "utf8").trim();
|
|
737
1345
|
} catch {
|
|
738
1346
|
die(`no ${what} at ${file}`);
|
|
739
1347
|
}
|
|
@@ -741,9 +1349,9 @@ var readFile = (file, what) => {
|
|
|
741
1349
|
var threshold = (n) => Math.floor(n / 2) + 1;
|
|
742
1350
|
async function getJson(url) {
|
|
743
1351
|
if (!/^https?:\/\//i.test(url)) {
|
|
744
|
-
const file =
|
|
1352
|
+
const file = path2.resolve(url);
|
|
745
1353
|
try {
|
|
746
|
-
return JSON.parse(
|
|
1354
|
+
return JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
747
1355
|
} catch (error) {
|
|
748
1356
|
throw new Error(`${file}: ${error.message}`);
|
|
749
1357
|
}
|
|
@@ -769,7 +1377,7 @@ async function bridgeInfo(pid = PUSD) {
|
|
|
769
1377
|
var proposal = (info, id) => (info.proposals ?? []).find((p) => String(p.id) === String(id)) ?? die(`no proposal #${id}`);
|
|
770
1378
|
function wallet() {
|
|
771
1379
|
const jwk = JSON.parse(readFile(
|
|
772
|
-
opt("wallet") ?? process.env.PARALITH_AO_WALLET ??
|
|
1380
|
+
opt("wallet") ?? process.env.PARALITH_AO_WALLET ?? path2.join(KEYS, "operator.json"),
|
|
773
1381
|
"operator wallet (your operator's Arweave keyfile)"
|
|
774
1382
|
));
|
|
775
1383
|
return { jwk, address: jwkToAddress(jwk) };
|
|
@@ -795,16 +1403,14 @@ async function pusd(tags) {
|
|
|
795
1403
|
}
|
|
796
1404
|
die(`sent (slot ${slot}) but no reply yet; run status before sending again`);
|
|
797
1405
|
}
|
|
798
|
-
var RELEASE_ATTESTORS = "PARALITH_ATTESTORS_V2";
|
|
799
1406
|
var RELEASE_ROOT = "PARALITH_ROOT_V1";
|
|
800
|
-
var
|
|
801
|
-
var
|
|
802
|
-
var u64 = (n) => {
|
|
1407
|
+
var hexBytes = (h) => toBytes2(h);
|
|
1408
|
+
var u642 = (n) => {
|
|
803
1409
|
const b = Buffer.alloc(8);
|
|
804
1410
|
b.writeBigUInt64LE(BigInt(n));
|
|
805
1411
|
return b;
|
|
806
1412
|
};
|
|
807
|
-
var
|
|
1413
|
+
var utf82 = (s) => Buffer.from(s, "utf8");
|
|
808
1414
|
var processBytes = (id) => {
|
|
809
1415
|
const bytes = Buffer.from(id ?? "", "base64url");
|
|
810
1416
|
if (bytes.length !== 32) die(`process id ${id || "<empty>"} does not decode to 32 bytes`);
|
|
@@ -813,31 +1419,32 @@ var processBytes = (id) => {
|
|
|
813
1419
|
var processHex = (id) => `0x${processBytes(id).toString("hex")}`;
|
|
814
1420
|
function voters(p) {
|
|
815
1421
|
const v = p.prior.flatMap((member, at) => p.votes?.[member.ao] ? [{ at, member, vote: p.votes[member.ao] }] : []);
|
|
816
|
-
if (v.length < threshold(p.prior.length)) die(`#${p.id} has ${v.length} of ${threshold(p.prior.length)}
|
|
1422
|
+
if (v.length < threshold(p.prior.length)) die(`#${p.id} has ${v.length} of ${threshold(p.prior.length)} members' chain signatures`);
|
|
817
1423
|
return v;
|
|
818
1424
|
}
|
|
819
|
-
var
|
|
1425
|
+
var rpcFor2 = (chain) => rpcFor(chain, { flag: opt("rpc"), env: process.env, keysDir: KEYS, deployment });
|
|
820
1426
|
var KEY_FILE = { base: "base.key", solana: "solana.json", sui: "sui.key" };
|
|
821
|
-
var keyFor = (chain) => readFile(opt("key") ?? process.env[`PARALITH_${chain.toUpperCase()}_KEY`] ??
|
|
1427
|
+
var keyFor = (chain) => readFile(opt("key") ?? process.env[`PARALITH_${chain.toUpperCase()}_KEY`] ?? path2.join(KEYS, KEY_FILE[chain]), `${chain} gas payer key`);
|
|
822
1428
|
var BASE_ABI = parseAbi([
|
|
823
1429
|
"function setAttestors(address[] set, uint64 newEpoch, bytes[] sigs)",
|
|
824
1430
|
"function setRoot(bytes32 successor, bytes[] sigs)",
|
|
825
|
-
"function setTokenAllowed(address token, bool allowed, bytes[] sigs)",
|
|
826
|
-
"function unpause(bytes[] sigs)",
|
|
1431
|
+
"function setTokenAllowed(address token, bool allowed, uint64 nonce, bytes[] sigs)",
|
|
1432
|
+
"function unpause(uint64 nonce, bytes[] sigs)",
|
|
1433
|
+
"function adminNonce() view returns (uint64)",
|
|
827
1434
|
"function epoch() view returns (uint64)",
|
|
828
1435
|
"function root() view returns (bytes32)"
|
|
829
1436
|
]);
|
|
830
1437
|
function baseClients(withKey) {
|
|
831
1438
|
const cfg = deployment.base;
|
|
832
|
-
const chain = { ...baseChain, id: cfg.chainId, rpcUrls: { default: { http: [
|
|
833
|
-
const pub = createPublicClient({ chain, transport: http(
|
|
1439
|
+
const chain = { ...baseChain, id: cfg.chainId, rpcUrls: { default: { http: [rpcFor2("base")] } } };
|
|
1440
|
+
const pub = createPublicClient({ chain, transport: http(rpcFor2("base")) });
|
|
834
1441
|
if (!withKey) return { pub };
|
|
835
1442
|
const account = privateKeyToAccount(keyFor("base"));
|
|
836
|
-
return { pub, account, wallet: createWalletClient({ account, chain, transport: http(
|
|
1443
|
+
return { pub, account, wallet: createWalletClient({ account, chain, transport: http(rpcFor2("base")) }) };
|
|
837
1444
|
}
|
|
838
1445
|
var solanaProgram = () => new PublicKey(deployment.solana.programId);
|
|
839
|
-
var solanaConfig = () => PublicKey.findProgramAddressSync([
|
|
840
|
-
var anchorIx = (name) =>
|
|
1446
|
+
var solanaConfig = () => PublicKey.findProgramAddressSync([utf82("config")], solanaProgram())[0];
|
|
1447
|
+
var anchorIx = (name) => crypto3.createHash("sha256").update(`global:${name}`).digest().subarray(0, 8);
|
|
841
1448
|
function ed25519Ix(entries, msg) {
|
|
842
1449
|
const head = 2 + 14 * entries.length;
|
|
843
1450
|
const msgOff = head + 96 * entries.length;
|
|
@@ -853,7 +1460,7 @@ function ed25519Ix(entries, msg) {
|
|
|
853
1460
|
data.set(msg, msgOff);
|
|
854
1461
|
return new TransactionInstruction({ programId: Ed25519Program.programId, keys: [], data });
|
|
855
1462
|
}
|
|
856
|
-
var suiClient = () => new SuiGrpcClient({ network: deployment.sui.network, baseUrl:
|
|
1463
|
+
var suiClient = () => new SuiGrpcClient({ network: deployment.sui.network, baseUrl: rpcFor2("sui") });
|
|
857
1464
|
var vecBytes = bcs.vector(bcs.vector(bcs.u8()));
|
|
858
1465
|
var vecU64 = bcs.vector(bcs.u64());
|
|
859
1466
|
var epochOf = {
|
|
@@ -861,7 +1468,7 @@ var epochOf = {
|
|
|
861
1468
|
return Number(await baseClients(false).pub.readContract({ address: deployment.base.bridge, abi: BASE_ABI, functionName: "epoch" }));
|
|
862
1469
|
},
|
|
863
1470
|
async solana() {
|
|
864
|
-
const info = await new Connection(
|
|
1471
|
+
const info = await new Connection(rpcFor2("solana"), "confirmed").getAccountInfo(solanaConfig());
|
|
865
1472
|
if (!info) throw new Error("config not found");
|
|
866
1473
|
const n = info.data.readUInt32LE(40);
|
|
867
1474
|
return Number(info.data.readBigUInt64LE(44 + 32 * n));
|
|
@@ -876,12 +1483,39 @@ var epochOf = {
|
|
|
876
1483
|
return Number(Buffer.from(bytes).readBigUInt64LE(0));
|
|
877
1484
|
}
|
|
878
1485
|
};
|
|
1486
|
+
var adminNonceOf = {
|
|
1487
|
+
async base() {
|
|
1488
|
+
return Number(await baseClients(false).pub.readContract({ address: deployment.base.bridge, abi: BASE_ABI, functionName: "adminNonce" }));
|
|
1489
|
+
},
|
|
1490
|
+
async solana() {
|
|
1491
|
+
const info = await new Connection(rpcFor2("solana"), "confirmed").getAccountInfo(solanaConfig());
|
|
1492
|
+
if (!info) throw new Error("config not found");
|
|
1493
|
+
const n = info.data.readUInt32LE(40);
|
|
1494
|
+
return Number(info.data.readBigUInt64LE(93 + 32 * n));
|
|
1495
|
+
},
|
|
1496
|
+
async sui() {
|
|
1497
|
+
const tx = new SuiTransaction();
|
|
1498
|
+
tx.moveCall({ target: `${deployment.sui.package}::para_bridge::admin_nonce`, arguments: [tx.object(deployment.sui.bridge)] });
|
|
1499
|
+
tx.setSender("0x0");
|
|
1500
|
+
const r = await suiClient().simulateTransaction({ transaction: tx, include: { commandResults: true }, checksEnabled: false });
|
|
1501
|
+
const bytes = r.commandResults?.[0]?.returnValues?.[0]?.bcs;
|
|
1502
|
+
if (!bytes) throw new Error("admin nonce read returned nothing");
|
|
1503
|
+
return Number(Buffer.from(bytes).readBigUInt64LE(0));
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
async function adminNonceFor(p, chain) {
|
|
1507
|
+
const nonce = p.admin?.nonces?.[chain];
|
|
1508
|
+
if (!Number.isSafeInteger(nonce) || nonce < 0) die(`#${p.id} binds no admin nonce for ${chain}`);
|
|
1509
|
+
const now = await adminNonceOf[chain]();
|
|
1510
|
+
if (now !== nonce) die(`#${p.id} is for ${chain} admin nonce ${nonce}, but ${chain} is at ${now}; propose it again`);
|
|
1511
|
+
return nonce;
|
|
1512
|
+
}
|
|
879
1513
|
var rootOf = {
|
|
880
1514
|
async base() {
|
|
881
1515
|
return String(await baseClients(false).pub.readContract({ address: deployment.base.bridge, abi: BASE_ABI, functionName: "root" })).toLowerCase();
|
|
882
1516
|
},
|
|
883
1517
|
async solana() {
|
|
884
|
-
const info = await new Connection(
|
|
1518
|
+
const info = await new Connection(rpcFor2("solana"), "confirmed").getAccountInfo(solanaConfig());
|
|
885
1519
|
if (!info) throw new Error("config not found");
|
|
886
1520
|
const n = info.data.readUInt32LE(40);
|
|
887
1521
|
return `0x${info.data.subarray(52 + 32 * n, 84 + 32 * n).toString("hex")}`;
|
|
@@ -896,31 +1530,25 @@ var rootOf = {
|
|
|
896
1530
|
return `0x${encoded.subarray(1).toString("hex")}`;
|
|
897
1531
|
}
|
|
898
1532
|
};
|
|
1533
|
+
async function requireRoot(chain) {
|
|
1534
|
+
const onChain = await rootOf[chain]();
|
|
1535
|
+
if (onChain !== processHex(PUSD)) die(`${chain} is on root ${onChain}, not ${PUSD} (${processHex(PUSD)}); pass --pusd <its root>`);
|
|
1536
|
+
}
|
|
899
1537
|
var applyOn = {
|
|
900
1538
|
async base(p) {
|
|
901
1539
|
const { pub, wallet: w, account } = baseClients(true);
|
|
902
1540
|
console.log(`paying as ${account.address}`);
|
|
903
1541
|
const set = p.set.map((m) => m.base);
|
|
904
|
-
const currentEpoch = BigInt(p.priorEpoch ?? p.currentEpoch);
|
|
905
1542
|
const epoch = BigInt(p.epoch);
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
[
|
|
916
|
-
keccak256(toBytes(RELEASE_ATTESTORS)),
|
|
917
|
-
BigInt(deployment.base.chainId),
|
|
918
|
-
deployment.base.bridge,
|
|
919
|
-
currentEpoch,
|
|
920
|
-
epoch,
|
|
921
|
-
set
|
|
922
|
-
]
|
|
923
|
-
));
|
|
1543
|
+
await requireRoot("base");
|
|
1544
|
+
const inner = baseAttestorsInner({
|
|
1545
|
+
chainId: deployment.base.chainId,
|
|
1546
|
+
bridge: deployment.base.bridge,
|
|
1547
|
+
root: PUSD,
|
|
1548
|
+
epoch: p.priorEpoch ?? p.currentEpoch,
|
|
1549
|
+
newEpoch: p.epoch,
|
|
1550
|
+
set
|
|
1551
|
+
});
|
|
924
1552
|
const allowed = new Set(p.prior.map((m) => m.base.toLowerCase()));
|
|
925
1553
|
const rows = await Promise.all(voters(p).map(async (v) => ({
|
|
926
1554
|
sig: v.vote.base,
|
|
@@ -937,15 +1565,14 @@ var applyOn = {
|
|
|
937
1565
|
console.log(`paying as ${payer.publicKey.toBase58()}`);
|
|
938
1566
|
const program = solanaProgram();
|
|
939
1567
|
const set = p.set.map((m) => new PublicKey(m.solana));
|
|
940
|
-
|
|
941
|
-
const msg =
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
]);
|
|
1568
|
+
await requireRoot("solana");
|
|
1569
|
+
const msg = solanaAttestorsMessage({
|
|
1570
|
+
program: program.toBuffer(),
|
|
1571
|
+
root: PUSD,
|
|
1572
|
+
epoch: p.priorEpoch ?? p.currentEpoch,
|
|
1573
|
+
newEpoch: p.epoch,
|
|
1574
|
+
set: set.map((k) => k.toBuffer())
|
|
1575
|
+
});
|
|
949
1576
|
const len = Buffer.alloc(4);
|
|
950
1577
|
len.writeUInt32LE(set.length);
|
|
951
1578
|
const tx = new Transaction().add(
|
|
@@ -956,10 +1583,10 @@ var applyOn = {
|
|
|
956
1583
|
{ pubkey: solanaConfig(), isSigner: false, isWritable: true },
|
|
957
1584
|
{ pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false }
|
|
958
1585
|
],
|
|
959
|
-
data: Buffer.concat([anchorIx("set_attestors"), len, ...set.map((k) => k.toBuffer()),
|
|
1586
|
+
data: Buffer.concat([anchorIx("set_attestors"), len, ...set.map((k) => k.toBuffer()), u642(p.epoch)])
|
|
960
1587
|
})
|
|
961
1588
|
);
|
|
962
|
-
return sendAndConfirmTransaction(new Connection(
|
|
1589
|
+
return sendAndConfirmTransaction(new Connection(rpcFor2("solana"), "confirmed"), tx, [payer], { commitment: "confirmed" });
|
|
963
1590
|
},
|
|
964
1591
|
async sui(p) {
|
|
965
1592
|
const signer = Ed25519Keypair.fromSecretKey(keyFor("sui"));
|
|
@@ -990,7 +1617,7 @@ var applyRootOn = {
|
|
|
990
1617
|
console.log(`paying as ${account.address}`);
|
|
991
1618
|
const oldRoot = processHex(PUSD);
|
|
992
1619
|
const successor = processHex(p.successor);
|
|
993
|
-
const inner =
|
|
1620
|
+
const inner = keccak2562(encodeAbiParameters2(
|
|
994
1621
|
[
|
|
995
1622
|
{ type: "bytes32" },
|
|
996
1623
|
{ type: "uint256" },
|
|
@@ -1000,7 +1627,7 @@ var applyRootOn = {
|
|
|
1000
1627
|
{ type: "bytes32" }
|
|
1001
1628
|
],
|
|
1002
1629
|
[
|
|
1003
|
-
|
|
1630
|
+
keccak2562(toBytes2(RELEASE_ROOT)),
|
|
1004
1631
|
BigInt(deployment.base.chainId),
|
|
1005
1632
|
deployment.base.bridge,
|
|
1006
1633
|
BigInt(p.currentEpoch ?? p.priorEpoch),
|
|
@@ -1030,9 +1657,9 @@ var applyRootOn = {
|
|
|
1030
1657
|
const oldRoot = processBytes(PUSD);
|
|
1031
1658
|
const successor = processBytes(p.successor);
|
|
1032
1659
|
const msg = Buffer.concat([
|
|
1033
|
-
|
|
1660
|
+
utf82(RELEASE_ROOT),
|
|
1034
1661
|
program.toBuffer(),
|
|
1035
|
-
|
|
1662
|
+
u642(p.currentEpoch ?? p.priorEpoch),
|
|
1036
1663
|
oldRoot,
|
|
1037
1664
|
successor
|
|
1038
1665
|
]);
|
|
@@ -1047,7 +1674,7 @@ var applyRootOn = {
|
|
|
1047
1674
|
data: Buffer.concat([anchorIx("set_root"), successor])
|
|
1048
1675
|
})
|
|
1049
1676
|
);
|
|
1050
|
-
return sendAndConfirmTransaction(new Connection(
|
|
1677
|
+
return sendAndConfirmTransaction(new Connection(rpcFor2("solana"), "confirmed"), tx, [payer], { commitment: "confirmed" });
|
|
1051
1678
|
},
|
|
1052
1679
|
async sui(p) {
|
|
1053
1680
|
const signer = Ed25519Keypair.fromSecretKey(keyFor("sui"));
|
|
@@ -1076,30 +1703,17 @@ var applyAdminOn = {
|
|
|
1076
1703
|
const { pub, wallet: w, account } = baseClients(true);
|
|
1077
1704
|
console.log(`paying as ${account.address}`);
|
|
1078
1705
|
const allow = p.op === "add-token";
|
|
1079
|
-
const token = allow ? p.admin.token :
|
|
1080
|
-
const
|
|
1081
|
-
const inner =
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
{ type: "bool" }
|
|
1091
|
-
],
|
|
1092
|
-
[
|
|
1093
|
-
keccak256(toBytes(RELEASE_ADMIN)),
|
|
1094
|
-
BigInt(deployment.base.chainId),
|
|
1095
|
-
deployment.base.bridge,
|
|
1096
|
-
processHex(PUSD),
|
|
1097
|
-
BigInt(p.currentEpoch ?? p.priorEpoch),
|
|
1098
|
-
action,
|
|
1099
|
-
token,
|
|
1100
|
-
true
|
|
1101
|
-
]
|
|
1102
|
-
));
|
|
1706
|
+
const token = allow ? p.admin.token : void 0;
|
|
1707
|
+
const nonce = await adminNonceFor(p, "base");
|
|
1708
|
+
const inner = baseAdminInner({
|
|
1709
|
+
chainId: deployment.base.chainId,
|
|
1710
|
+
bridge: deployment.base.bridge,
|
|
1711
|
+
root: PUSD,
|
|
1712
|
+
epoch: p.currentEpoch ?? p.priorEpoch,
|
|
1713
|
+
nonce,
|
|
1714
|
+
action: allow ? ALLOW_TOKEN : UNPAUSE,
|
|
1715
|
+
token
|
|
1716
|
+
});
|
|
1103
1717
|
const allowed = new Set(p.prior.map((m) => m.base.toLowerCase()));
|
|
1104
1718
|
const rows = await Promise.all(adminVoters(p, "base").map(async (v) => ({
|
|
1105
1719
|
sig: v.vote.base,
|
|
@@ -1110,12 +1724,12 @@ var applyAdminOn = {
|
|
|
1110
1724
|
address: deployment.base.bridge,
|
|
1111
1725
|
abi: BASE_ABI,
|
|
1112
1726
|
functionName: "setTokenAllowed",
|
|
1113
|
-
args: [token, true, sigs]
|
|
1727
|
+
args: [token, true, BigInt(nonce), sigs]
|
|
1114
1728
|
}) : await w.writeContract({
|
|
1115
1729
|
address: deployment.base.bridge,
|
|
1116
1730
|
abi: BASE_ABI,
|
|
1117
1731
|
functionName: "unpause",
|
|
1118
|
-
args: [sigs]
|
|
1732
|
+
args: [BigInt(nonce), sigs]
|
|
1119
1733
|
});
|
|
1120
1734
|
const receipt = await pub.waitForTransactionReceipt({ hash });
|
|
1121
1735
|
if (receipt.status !== "success") die(`reverted ${hash}`);
|
|
@@ -1126,16 +1740,15 @@ var applyAdminOn = {
|
|
|
1126
1740
|
const program = solanaProgram();
|
|
1127
1741
|
const allow = p.op === "add-token";
|
|
1128
1742
|
const mint = allow ? new PublicKey(p.admin.token) : new PublicKey(new Uint8Array(32));
|
|
1129
|
-
const
|
|
1130
|
-
const msg =
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
mint.toBuffer()
|
|
1137
|
-
|
|
1138
|
-
]);
|
|
1743
|
+
const nonce = await adminNonceFor(p, "solana");
|
|
1744
|
+
const msg = solanaAdminMessage({
|
|
1745
|
+
program: program.toBuffer(),
|
|
1746
|
+
root: PUSD,
|
|
1747
|
+
epoch: p.currentEpoch ?? p.priorEpoch,
|
|
1748
|
+
nonce,
|
|
1749
|
+
action: allow ? ALLOW_TOKEN : UNPAUSE,
|
|
1750
|
+
mint: mint.toBuffer()
|
|
1751
|
+
});
|
|
1139
1752
|
const precompile = ed25519Ix(adminVoters(p, "solana").map((v) => ({
|
|
1140
1753
|
pubkey: new PublicKey(v.member.solana).toBytes(),
|
|
1141
1754
|
sig: hexBytes(v.vote.solana)
|
|
@@ -1149,14 +1762,14 @@ var applyAdminOn = {
|
|
|
1149
1762
|
programId: program,
|
|
1150
1763
|
keys: [
|
|
1151
1764
|
{ pubkey: payer.publicKey, isSigner: true, isWritable: true },
|
|
1152
|
-
{ pubkey: solanaConfig(), isSigner: false, isWritable:
|
|
1765
|
+
{ pubkey: solanaConfig(), isSigner: false, isWritable: true },
|
|
1153
1766
|
{ pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false },
|
|
1154
1767
|
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
1155
|
-
{ pubkey: PublicKey.findProgramAddressSync([
|
|
1768
|
+
{ pubkey: PublicKey.findProgramAddressSync([utf82("vault"), mint.toBuffer()], program)[0], isSigner: false, isWritable: true },
|
|
1156
1769
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
1157
1770
|
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false }
|
|
1158
1771
|
],
|
|
1159
|
-
data: anchorIx("allow_token")
|
|
1772
|
+
data: Buffer.concat([anchorIx("allow_token"), u642(nonce)])
|
|
1160
1773
|
});
|
|
1161
1774
|
} else {
|
|
1162
1775
|
instruction = new TransactionInstruction({
|
|
@@ -1165,11 +1778,11 @@ var applyAdminOn = {
|
|
|
1165
1778
|
{ pubkey: solanaConfig(), isSigner: false, isWritable: true },
|
|
1166
1779
|
{ pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false }
|
|
1167
1780
|
],
|
|
1168
|
-
data: anchorIx("unpause")
|
|
1781
|
+
data: Buffer.concat([anchorIx("unpause"), u642(nonce)])
|
|
1169
1782
|
});
|
|
1170
1783
|
}
|
|
1171
1784
|
return sendAndConfirmTransaction(
|
|
1172
|
-
new Connection(
|
|
1785
|
+
new Connection(rpcFor2("solana"), "confirmed"),
|
|
1173
1786
|
new Transaction().add(precompile, instruction),
|
|
1174
1787
|
[payer],
|
|
1175
1788
|
{ commitment: "confirmed" }
|
|
@@ -1178,6 +1791,7 @@ var applyAdminOn = {
|
|
|
1178
1791
|
async sui(p) {
|
|
1179
1792
|
const signer = Ed25519Keypair.fromSecretKey(keyFor("sui"));
|
|
1180
1793
|
const rows = adminVoters(p, "sui");
|
|
1794
|
+
const nonce = await adminNonceFor(p, "sui");
|
|
1181
1795
|
const tx = new SuiTransaction();
|
|
1182
1796
|
if (p.op === "add-token") {
|
|
1183
1797
|
tx.moveCall({
|
|
@@ -1185,6 +1799,7 @@ var applyAdminOn = {
|
|
|
1185
1799
|
typeArguments: [p.admin.token],
|
|
1186
1800
|
arguments: [
|
|
1187
1801
|
tx.object(deployment.sui.bridge),
|
|
1802
|
+
tx.pure.u64(nonce),
|
|
1188
1803
|
tx.pure(vecU64.serialize(rows.map((x) => BigInt(x.at)))),
|
|
1189
1804
|
tx.pure(vecBytes.serialize(rows.map((x) => Array.from(hexBytes(x.vote.sui)))))
|
|
1190
1805
|
]
|
|
@@ -1194,6 +1809,7 @@ var applyAdminOn = {
|
|
|
1194
1809
|
target: `${deployment.sui.package}::para_bridge::unpause`,
|
|
1195
1810
|
arguments: [
|
|
1196
1811
|
tx.object(deployment.sui.bridge),
|
|
1812
|
+
tx.pure.u64(nonce),
|
|
1197
1813
|
tx.pure(vecU64.serialize(rows.map((x) => BigInt(x.at)))),
|
|
1198
1814
|
tx.pure(vecBytes.serialize(rows.map((x) => Array.from(hexBytes(x.vote.sui)))))
|
|
1199
1815
|
]
|
|
@@ -1224,7 +1840,7 @@ async function status() {
|
|
|
1224
1840
|
const need = threshold(p.prior.length);
|
|
1225
1841
|
const behind = CHAINS.filter((c, i) => typeof epochs[i] === "number" && epochs[i] < p.epoch);
|
|
1226
1842
|
if (p.status === "applied" && !behind.length) continue;
|
|
1227
|
-
console.log(`#${p.id} ${p.op} ${p.op === "migrate" ? `to ${p.successor}` : `${short(p.member?.ao)} -> epoch ${p.epoch}`}: ${p.status}, approved ${Object.keys(p.approvals ?? {}).length}
|
|
1843
|
+
console.log(`#${p.id} ${p.op} ${p.op === "migrate" ? `to ${p.successor}` : `${short(p.member?.ao)} -> epoch ${p.epoch}`}: ${p.status}, approved ${Object.keys(p.approvals ?? {}).length}/${need}` + (p.status === "applied" ? `, apply on: ${behind.join(" ")}` : ""));
|
|
1228
1844
|
}
|
|
1229
1845
|
}
|
|
1230
1846
|
async function main() {
|
|
@@ -1278,25 +1894,33 @@ operator ${operator}`);
|
|
|
1278
1894
|
const token = rows.find((row) => !row.retired);
|
|
1279
1895
|
const id = target === "base" ? token?.address : target === "solana" ? token?.mint : token?.type;
|
|
1280
1896
|
if (!id) die(`manifest has no active ${target} token`);
|
|
1897
|
+
const nonce = await adminNonceOf[target]();
|
|
1281
1898
|
const r = await pusd({
|
|
1282
1899
|
Action: "Attestor-Propose",
|
|
1283
1900
|
Op: "add-token",
|
|
1284
1901
|
Chain: target,
|
|
1285
1902
|
Token: id,
|
|
1286
1903
|
Symbol: token.symbol,
|
|
1287
|
-
Decimals: String(token.decimals)
|
|
1904
|
+
Decimals: String(token.decimals),
|
|
1905
|
+
AdminNonce: String(nonce)
|
|
1288
1906
|
});
|
|
1289
1907
|
return console.log(`proposed #${r.ProposalId ?? "?"} for ${target} ${id}; next: approve ${r.ProposalId ?? "<id>"}`);
|
|
1290
1908
|
}
|
|
1291
1909
|
if (cmd === "unpause") {
|
|
1292
|
-
const
|
|
1910
|
+
const chain = opt("chain");
|
|
1911
|
+
if (chain && !CHAINS.includes(chain)) die("unpause [--chain base|solana|sui]");
|
|
1912
|
+
const tags = { Action: "Attestor-Propose", Op: "unpause" };
|
|
1913
|
+
const TAG = { base: "BaseAdminNonce", solana: "SolanaAdminNonce", sui: "SuiAdminNonce" };
|
|
1914
|
+
for (const c of chain ? [chain] : CHAINS) tags[TAG[c]] = String(await adminNonceOf[c]());
|
|
1915
|
+
const r = await pusd(tags);
|
|
1293
1916
|
return console.log(`proposed #${r.ProposalId ?? "?"}; next: approve ${r.ProposalId ?? "<id>"}`);
|
|
1294
1917
|
}
|
|
1295
1918
|
if (cmd === "apply") {
|
|
1296
1919
|
const chain = opt("chain");
|
|
1297
1920
|
if (!target || chain && !CHAINS.includes(chain)) die("apply <id> [--chain base|solana|sui]");
|
|
1298
1921
|
const p = proposal(await bridgeInfo(), target);
|
|
1299
|
-
if (p.status !== "applied") die(`#${p.id} is ${p.status}; it
|
|
1922
|
+
if (p.status !== "applied") die(`#${p.id} is ${p.status}; its operators approve it and the nodes apply it first`);
|
|
1923
|
+
p.votes = (await collectChainSignatures({ root: PUSD, node: NODE, proposal: p.id })).votes;
|
|
1300
1924
|
if (p.op === "migrate") {
|
|
1301
1925
|
const oldRoot = processHex(PUSD).toLowerCase();
|
|
1302
1926
|
const successor = processHex(p.successor).toLowerCase();
|