vantyx-cli 0.0.0-stage → 0.2.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 +14 -2
- package/abi/VantyxVault.json +776 -0
- package/bin/admin-password.mjs +27 -0
- package/bin/vantyx.mjs +110 -0
- package/package.json +50 -4
- package/public/companion.js +172 -0
- package/public/index.html +120 -0
- package/public/mark.png +0 -0
- package/public/studio.html +93 -0
- package/public/vault.css +104 -0
- package/public/vendor/jsQR.js +10102 -0
- package/public/vendor/qrcode.js +2297 -0
- package/src/agents.mjs +108 -0
- package/src/chain.mjs +111 -0
- package/src/config.mjs +19 -0
- package/src/frames.mjs +77 -0
- package/src/guardian.mjs +102 -0
- package/src/holders.mjs +104 -0
- package/src/hosted.mjs +106 -0
- package/src/pq.mjs +56 -0
- package/src/server.mjs +191 -0
- package/src/studio.mjs +303 -0
- package/src/support.mjs +200 -0
- package/src/token.mjs +15 -0
- package/src/vaultkeys.mjs +42 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Sets the support-inbox password for the hosted server: asks for it without echoing, stores only a scrypt hash in .env.
|
|
3
|
+
// node bin/admin-password.mjs (run on the server, in /opt/vantyx-hosted)
|
|
4
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
5
|
+
import { randomBytes, scryptSync } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
const ask = (q) => new Promise((res) => {
|
|
8
|
+
process.stdout.write(q);
|
|
9
|
+
const input = process.stdin;
|
|
10
|
+
input.setRawMode?.(true); input.resume(); input.setEncoding("utf8");
|
|
11
|
+
let s = "";
|
|
12
|
+
input.on("data", function on(ch) {
|
|
13
|
+
if (ch === "\r" || ch === "\n") { input.setRawMode?.(false); input.pause(); input.removeListener("data", on); process.stdout.write("\n"); res(s); }
|
|
14
|
+
else if (ch === "\u0003") process.exit(1);
|
|
15
|
+
else if (ch === "\u007f") s = s.slice(0, -1);
|
|
16
|
+
else s += ch;
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
const pw = await ask("New support inbox password (at least 12 characters): ");
|
|
20
|
+
if (pw.length < 12) { console.error("too short"); process.exit(1); }
|
|
21
|
+
if ((await ask("Again: ")) !== pw) { console.error("they don't match"); process.exit(1); }
|
|
22
|
+
const salt = randomBytes(16);
|
|
23
|
+
const line = `VANTYX_ADMIN_HASH=${salt.toString("hex")}:${scryptSync(pw, salt, 32).toString("hex")}`;
|
|
24
|
+
const file = new URL("../.env", import.meta.url).pathname;
|
|
25
|
+
const env = existsSync(file) ? readFileSync(file, "utf8").split("\n").filter((l) => l && !l.startsWith("VANTYX_ADMIN_HASH=")) : [];
|
|
26
|
+
writeFileSync(file, [...env, line].join("\n") + "\n", { mode: 0o600 });
|
|
27
|
+
console.log("Saved. Apply it: pm2 restart ecosystem.config.cjs --update-env");
|
package/bin/vantyx.mjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// vantyx-cli: the online half of Vantyx on the command line.
|
|
3
|
+
// npx vantyx-cli companion dashboard + relayer + agents + guardian on http://127.0.0.1:5893
|
|
4
|
+
// npx vantyx-cli status <vault> a vault's mode, counters and balance, read from Robinhood Chain
|
|
5
|
+
// npx vantyx-cli submit <frames.txt> put an action signed by the offline vault on chain (fast or strict)
|
|
6
|
+
// npx vantyx-cli register <vault> <genesis.txt> learn a vault's keys from its deploy QR (once, if this companion did not deploy it)
|
|
7
|
+
// npx vantyx-cli agents list agents and what they may still spend
|
|
8
|
+
// npx vantyx-cli agent new <vault> scheduled|x402 [--to 0x… --amount 25 --every-hours 24 | --max 1]
|
|
9
|
+
// npx vantyx-cli guardian <vault> [--max-single 1000] [--max-daily 2500] [--unknown-owner]
|
|
10
|
+
// Keys (online, gas only): VANTYX_RELAYER_KEY, VANTYX_GUARDIAN_KEY. Data: ~/.vantyx (VANTYX_DATA to change).
|
|
11
|
+
// The vault's own keys are never needed here: they stay on the offline machine.
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
|
|
14
|
+
process.env.VANTYX_CLI = "1";
|
|
15
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
16
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url)));
|
|
17
|
+
const flag = (name, def = null) => { const i = rest.indexOf(`--${name}`); return i >= 0 ? (rest[i + 1] && !rest[i + 1].startsWith("--") ? rest[i + 1] : true) : def; };
|
|
18
|
+
const usd = (u) => { const v = BigInt(u || 0); return `${v / 1000000n}.${(v % 1000000n).toString().padStart(6, "0")}`; };
|
|
19
|
+
const units = (s) => { const m = String(s).match(/^(\d+)(?:\.(\d{0,6}))?$/); if (!m) throw new Error(`not an amount: ${s}`); return (BigInt(m[1]) * 1000000n + BigInt((m[2] || "").padEnd(6, "0"))).toString(); };
|
|
20
|
+
const fail = (m) => { console.error(`vantyx: ${m}`); process.exit(1); };
|
|
21
|
+
const HELP = readFileSync(new URL(import.meta.url), "utf8").split("\n").filter((l) => l.startsWith("//")).map((l) => l.slice(3)).join("\n");
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
switch (cmd) {
|
|
25
|
+
case "companion":
|
|
26
|
+
case "start":
|
|
27
|
+
if (flag("port")) process.env.PORT = String(flag("port"));
|
|
28
|
+
await import("../src/server.mjs");
|
|
29
|
+
break;
|
|
30
|
+
case "status": {
|
|
31
|
+
const vault = rest[0] || fail("usage: vantyx status <vault address>");
|
|
32
|
+
const { vaultStatus } = await import("../src/chain.mjs");
|
|
33
|
+
const s = await vaultStatus(vault);
|
|
34
|
+
console.log(`vault ${s.vault}
|
|
35
|
+
identity ${s.identity.slice(2, 18).toUpperCase().match(/.{4}/g).join("-")}
|
|
36
|
+
mode ${s.mode === 0 ? "fast (hash chain)" : "strict (Winternitz)"}
|
|
37
|
+
next action #${s.nonce}
|
|
38
|
+
left ${s.mode === 0 ? `${s.chainLeft} chain links` : `${s.oneTimeKeysLeft} one-time keys`}
|
|
39
|
+
USDG ${usd(s.usdg)}
|
|
40
|
+
guardian ${s.guardian}
|
|
41
|
+
evacuates to ${s.evacuateTo}`);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "submit": {
|
|
45
|
+
const file = rest[0] || fail("usage: vantyx submit <file with VX1 frames or a signed JSON bundle>");
|
|
46
|
+
const text = readFileSync(file, "utf8").trim();
|
|
47
|
+
const { submit } = await import("../src/chain.mjs");
|
|
48
|
+
const { Joiner } = await import("../src/frames.mjs");
|
|
49
|
+
let bundle;
|
|
50
|
+
if (text.startsWith("{")) bundle = JSON.parse(text);
|
|
51
|
+
else { const j = new Joiner(); let d = null; for (const f of text.split(/\s+/)) if (f.startsWith("VX1/")) d = j.push(f) || d; if (!d) fail(`only ${j.progress().join(" of ")} frames`); bundle = JSON.parse(new TextDecoder().decode(d)); }
|
|
52
|
+
const { verifyBundle } = await import("../src/vaultkeys.mjs");
|
|
53
|
+
await verifyBundle(bundle);
|
|
54
|
+
console.log(`relaying #${bundle.nonce}: ${bundle.description} (ML-DSA-65 verified${bundle.kind === 7 ? ", SLH-DSA-128s verified" : ""})`);
|
|
55
|
+
const r = await submit(bundle, (m) => console.log(` ${m}`));
|
|
56
|
+
console.log(r.ok ? `done in block ${r.block}: ${r.tx}` : `proof spent but the action failed: ${r.tx}`);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "register": {
|
|
60
|
+
// once per vault this companion did not deploy: the deploy QR's frames (or the genesis JSON), saved to a file
|
|
61
|
+
const [vault, file] = rest;
|
|
62
|
+
if (!vault || !file) fail("usage: vantyx register <vault> <file with the deploy QR's VX1 frames>");
|
|
63
|
+
const text = readFileSync(file, "utf8").trim();
|
|
64
|
+
const { Joiner } = await import("../src/frames.mjs");
|
|
65
|
+
let g;
|
|
66
|
+
if (text.startsWith("{")) g = JSON.parse(text);
|
|
67
|
+
else { const j = new Joiner(); let d = null; for (const f of text.split(/\s+/)) if (f.startsWith("VX1/")) d = j.push(f) || d; if (!d) fail(`only ${j.progress().join(" of ")} frames`); g = JSON.parse(new TextDecoder().decode(d)); }
|
|
68
|
+
await (await import("../src/vaultkeys.mjs")).register(vault, g);
|
|
69
|
+
console.log(`registered ${vault}: ML-DSA-65, SLH-DSA-128s and ML-KEM-768 keys checked against the contract`);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case "agents": {
|
|
73
|
+
const { listAgents } = await import("../src/agents.mjs");
|
|
74
|
+
const { remaining } = await import("../src/chain.mjs");
|
|
75
|
+
const list = listAgents();
|
|
76
|
+
if (!list.length) console.log("no agents yet: vantyx agent new <vault> scheduled|x402");
|
|
77
|
+
for (const a of list) {
|
|
78
|
+
const r = await remaining(a.vault, a.address).catch(() => null);
|
|
79
|
+
console.log(`${a.id} ${a.kind.padEnd(9)} ${a.name.padEnd(14)} ${a.address} ${r ? `${usd(r.today)} today, ${usd(r.total)} total` : "no allowance yet"}${a.paused ? " (paused)" : ""}`);
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "agent": {
|
|
84
|
+
if (rest[0] !== "new") fail("usage: vantyx agent new <vault> scheduled|x402 …");
|
|
85
|
+
const [, vault, kind] = rest;
|
|
86
|
+
const { createAgent } = await import("../src/agents.mjs");
|
|
87
|
+
const a = await createAgent({ vault, kind, name: flag("name") || kind, to: flag("to"), amount: flag("amount") && units(flag("amount")), everySeconds: flag("every-hours") && Number(flag("every-hours")) * 3600, maxPerInvoice: flag("max") && units(flag("max")) });
|
|
88
|
+
console.log(`agent ${a.id} created: ${a.address}\nGive it an allowance in the vault app (Agents), and send it a little ETH for gas.`);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case "guardian": {
|
|
92
|
+
const vault = rest[0] || fail("usage: vantyx guardian <vault> [--max-single N] [--max-daily N] [--unknown-owner]");
|
|
93
|
+
const { watch } = await import("../src/guardian.mjs");
|
|
94
|
+
await (await import("../src/hosted.mjs")).requirePro(vault);
|
|
95
|
+
watch(vault, { maxSingle: flag("max-single") && units(flag("max-single")), maxDaily: flag("max-daily") && units(flag("max-daily")), unknownOwner: !!flag("unknown-owner") });
|
|
96
|
+
console.log(`guardian rules saved for ${vault}. They run while \`vantyx companion\` is running with VANTYX_GUARDIAN_KEY set.`);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case "--version":
|
|
100
|
+
case "-v":
|
|
101
|
+
case "version":
|
|
102
|
+
console.log(pkg.version);
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
console.log(HELP);
|
|
106
|
+
if (cmd && !["help", "--help", "-h"].includes(cmd)) process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
} catch (e) {
|
|
109
|
+
fail(e.shortMessage || e.message);
|
|
110
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vantyx-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Vantyx on the command line: relayer, agents, guardian and dashboard for an offline post-quantum vault on Robinhood Chain",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"vantyx": "bin/vantyx.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src",
|
|
12
|
+
"public",
|
|
13
|
+
"abi",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://vantyxvault.com",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/vantyxvault/vantyx.git",
|
|
24
|
+
"directory": "companion"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"vantyx",
|
|
28
|
+
"post-quantum",
|
|
29
|
+
"vault",
|
|
30
|
+
"robinhood-chain",
|
|
31
|
+
"usdg",
|
|
32
|
+
"x402",
|
|
33
|
+
"guardian"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "node --test test/",
|
|
37
|
+
"abi": "node scripts/abi.mjs",
|
|
38
|
+
"start": "node src/server.mjs",
|
|
39
|
+
"e2e": "node test/e2e.mjs"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@anthropic-ai/sdk": "^1.17.0",
|
|
43
|
+
"@noble/ciphers": "^2.4.0",
|
|
44
|
+
"@noble/hashes": "^2.4.0",
|
|
45
|
+
"@noble/post-quantum": "^0.7.1",
|
|
46
|
+
"ethers": "6.13.4",
|
|
47
|
+
"viem": "^2.58.10"
|
|
48
|
+
},
|
|
49
|
+
"overrides": {
|
|
50
|
+
"ws": "^8.23.0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Joiner } from "./frames.js";
|
|
2
|
+
const $ = (id) => document.getElementById(id);
|
|
3
|
+
const api = async (path, body, method = body ? "POST" : "GET") => {
|
|
4
|
+
const r = await fetch(path, { method, headers: { "content-type": "application/json" }, body: body ? JSON.stringify(body) : undefined });
|
|
5
|
+
const j = await r.json();
|
|
6
|
+
if (!r.ok) throw new Error(j.error || r.statusText);
|
|
7
|
+
return j;
|
|
8
|
+
};
|
|
9
|
+
const usd = (u) => { const v = BigInt(u || 0); return `${v / 1000000n}.${(v % 1000000n).toString().padStart(6, "0").replace(/0{1,4}$/, "")}`; };
|
|
10
|
+
const units = (s) => { const m = String(s).trim().match(/^(\d+)(?:\.(\d{0,6}))?$/); if (!m) throw new Error("amount like 12.50"); return (BigInt(m[1]) * 1000000n + BigInt((m[2] || "").padEnd(6, "0"))).toString(); };
|
|
11
|
+
const fp = (id) => id.slice(2, 18).toUpperCase().match(/.{4}/g).join("-");
|
|
12
|
+
const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
|
|
13
|
+
let CFG = {}, VAULT = localStorage.getItem("vantyx.vault") || "";
|
|
14
|
+
|
|
15
|
+
document.querySelectorAll("[data-page]").forEach((b) => (b.onclick = () => {
|
|
16
|
+
document.querySelectorAll("[data-page]").forEach((x) => x.classList.toggle("on", x === b));
|
|
17
|
+
document.querySelectorAll("[data-p]").forEach((s) => (s.hidden = s.dataset.p !== b.dataset.page));
|
|
18
|
+
if (b.dataset.page !== "scan") stopCam();
|
|
19
|
+
if (b.dataset.page === "agents") loadAgents();
|
|
20
|
+
if (b.dataset.page === "vault" && $("vAddr").value) loadVault();
|
|
21
|
+
if (b.dataset.page === "guardian") loadGuardian();
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
async function header() {
|
|
25
|
+
try {
|
|
26
|
+
CFG = await api("/api/config");
|
|
27
|
+
$("hdr").innerHTML = `<span>chain <b>${CFG.chainId}</b></span><span>block <b>${CFG.block}</b></span><span>relayer <b>${CFG.relayer || "not set"}</b></span><span>guardian <b>${CFG.guardian || "not set"}</b></span>`;
|
|
28
|
+
$("gGuard").textContent = CFG.guardian || "(no guardian key set in this companion)";
|
|
29
|
+
} catch (e) { $("hdr").textContent = "companion API not reachable: " + e.message; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------- vault
|
|
33
|
+
$("vAddr").value = VAULT;
|
|
34
|
+
$("vLoad").onclick = loadVault;
|
|
35
|
+
async function loadVault() {
|
|
36
|
+
$("vErr").textContent = "";
|
|
37
|
+
const a = $("vAddr").value.trim();
|
|
38
|
+
try {
|
|
39
|
+
const s = await api(`/api/vault/${a}`);
|
|
40
|
+
VAULT = a; localStorage.setItem("vantyx.vault", a);
|
|
41
|
+
const card = (k, v, cls = "") => `<div class="card"><span class="k">${k}</span><span class="v ${cls}">${v}</span></div>`;
|
|
42
|
+
$("vCards").innerHTML = card("USDG balance", usd(s.usdg)) + card("Identity fingerprint", fp(s.identity), "mono") + card("Mode", s.mode === 0 ? "Fast" : "Strict")
|
|
43
|
+
+ card("Next action", "#" + s.nonce) + card("Approvals left", s.mode === 0 ? `${s.chainLeft} chain links` : `${s.oneTimeKeysLeft} one-time keys`)
|
|
44
|
+
+ card("Evacuates to", esc(s.evacuateTo), "mono small");
|
|
45
|
+
$("vCards").hidden = false;
|
|
46
|
+
} catch (e) { $("vErr").textContent = e.message; }
|
|
47
|
+
}
|
|
48
|
+
$("vSync").onclick = async () => {
|
|
49
|
+
try { const r = await api(`/api/vault/${$("vAddr").value.trim()}/sync`); play(r.frames); $("dlg").showModal(); } catch (e) { $("vErr").textContent = e.message; }
|
|
50
|
+
};
|
|
51
|
+
let qrT;
|
|
52
|
+
function play(frames) {
|
|
53
|
+
clearInterval(qrT);
|
|
54
|
+
let i = 0;
|
|
55
|
+
const draw = () => {
|
|
56
|
+
const q = qrcode(0, "M"); q.addData(frames[i], "Alphanumeric"); q.make();
|
|
57
|
+
const cv = $("qr"), n = q.getModuleCount(), cell = Math.floor(cv.width / (n + 8)), off = Math.floor((cv.width - cell * n) / 2), c = cv.getContext("2d");
|
|
58
|
+
c.fillStyle = "#fff"; c.fillRect(0, 0, cv.width, cv.height); c.fillStyle = "#0e1d3c";
|
|
59
|
+
for (let r = 0; r < n; r++) for (let k = 0; k < n; k++) if (q.isDark(r, k)) c.fillRect(off + k * cell, off + r * cell, cell, cell);
|
|
60
|
+
$("qrInfo").textContent = `frame ${i + 1} of ${frames.length}`; i = (i + 1) % frames.length;
|
|
61
|
+
};
|
|
62
|
+
draw(); if (frames.length > 1) qrT = setInterval(draw, 160);
|
|
63
|
+
$("copyFrames").onclick = () => navigator.clipboard.writeText(frames.join("\n"));
|
|
64
|
+
}
|
|
65
|
+
$("dClose").onclick = () => { clearInterval(qrT); $("dlg").close(); };
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------- scan
|
|
68
|
+
let stream, scanT, seen = new Map(), payload = null, rawFrames = [];
|
|
69
|
+
function stopCam() { clearInterval(scanT); stream?.getTracks().forEach((t) => t.stop()); stream = null; $("camBtn").textContent = "Start camera"; }
|
|
70
|
+
$("camBtn").onclick = async () => {
|
|
71
|
+
if (stream) return stopCam();
|
|
72
|
+
$("scanErr").textContent = "";
|
|
73
|
+
try { stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }); } catch { $("scanErr").textContent = "No camera access. Paste the frames instead."; return; }
|
|
74
|
+
const v = $("cam"), cv = $("camCv"), c = cv.getContext("2d", { willReadFrequently: true });
|
|
75
|
+
v.srcObject = stream; await v.play(); $("camBtn").textContent = "Stop"; seen = new Map();
|
|
76
|
+
scanT = setInterval(() => {
|
|
77
|
+
if (!v.videoWidth) return;
|
|
78
|
+
cv.width = v.videoWidth; cv.height = v.videoHeight; c.drawImage(v, 0, 0);
|
|
79
|
+
const code = jsQR(c.getImageData(0, 0, cv.width, cv.height).data, cv.width, cv.height);
|
|
80
|
+
if (!code || !code.data.startsWith("VX1/")) return;
|
|
81
|
+
const [, i, n] = code.data.split("/"); seen.set(i, code.data);
|
|
82
|
+
$("scanProg").textContent = `${seen.size} of ${n} frames`;
|
|
83
|
+
if (seen.size === Number(n)) { stopCam(); read([...seen.values()]); }
|
|
84
|
+
}, 100);
|
|
85
|
+
};
|
|
86
|
+
$("frBtn").onclick = () => read($("frIn").value.split(/\s+/).filter((x) => x.startsWith("VX1/")));
|
|
87
|
+
function read(frames) {
|
|
88
|
+
$("scanErr").textContent = ""; $("genesisBox").hidden = $("actionBox").hidden = true; $("gOk").textContent = $("aOk").textContent = "";
|
|
89
|
+
try {
|
|
90
|
+
const j = new Joiner(); let data = null;
|
|
91
|
+
for (const f of frames) data = j.push(f) || data;
|
|
92
|
+
if (!data) throw new Error(`only ${j.progress().join(" of ")} frames`);
|
|
93
|
+
payload = JSON.parse(new TextDecoder().decode(data)); rawFrames = frames;
|
|
94
|
+
if (payload.type === "genesis") {
|
|
95
|
+
$("gFp").textContent = fp(payload.identity); $("genesisBox").hidden = false;
|
|
96
|
+
const zero = /^0x0{40}$/i.test(payload.guardian || "");
|
|
97
|
+
$("gFixed").textContent = !payload.dsa_sig ? "This deploy QR comes from an older Vantyx Vault. Update the app and show it again."
|
|
98
|
+
: zero ? "No guardian in this genesis. You can add one later from the vault app (Guardian page)."
|
|
99
|
+
: `Guardian ${payload.guardian}, evacuating to ${payload.evacuate_to}. Fixed by the vault's signature.`;
|
|
100
|
+
}
|
|
101
|
+
else if (payload.action_hash) {
|
|
102
|
+
$("aDesc").textContent = payload.description;
|
|
103
|
+
$("aMeta").textContent = `Action #${payload.nonce} · ${payload.mode} mode · vault ${payload.vault}`;
|
|
104
|
+
$("actionBox").hidden = false;
|
|
105
|
+
} else throw new Error("not something this companion knows");
|
|
106
|
+
} catch (e) { $("scanErr").textContent = e.message; }
|
|
107
|
+
}
|
|
108
|
+
$("gDeploy").onclick = async () => {
|
|
109
|
+
$("gDeploy").disabled = true; $("gOk").textContent = "Deploying…";
|
|
110
|
+
try {
|
|
111
|
+
const r = await api("/api/deploy", { genesis: payload });
|
|
112
|
+
$("gOk").textContent = `Deployed at ${r.vault}. Type this address into the vault app.`;
|
|
113
|
+
$("vAddr").value = r.vault; VAULT = r.vault; localStorage.setItem("vantyx.vault", r.vault);
|
|
114
|
+
} catch (e) { $("gOk").textContent = ""; $("scanErr").textContent = e.message; }
|
|
115
|
+
$("gDeploy").disabled = false;
|
|
116
|
+
};
|
|
117
|
+
$("gRegister").onclick = async () => {
|
|
118
|
+
const v = $("gExisting").value.trim();
|
|
119
|
+
$("gOk").textContent = ""; $("scanErr").textContent = "";
|
|
120
|
+
try {
|
|
121
|
+
await api(`/api/identity/${v}`, { genesis: payload });
|
|
122
|
+
$("gOk").textContent = `This companion now knows the keys of ${v}: it checks every ML-DSA-65 signature, every SLH-DSA-128s rotation, and encrypts the status QR to its ML-KEM-768 key.`;
|
|
123
|
+
$("vAddr").value = v; VAULT = v; localStorage.setItem("vantyx.vault", v);
|
|
124
|
+
} catch (e) { $("scanErr").textContent = e.message; }
|
|
125
|
+
};
|
|
126
|
+
$("aSubmit").onclick = async () => {
|
|
127
|
+
$("aSubmit").disabled = true; $("aOk").textContent = payload.mode === "fast" ? "Committing, then revealing in the next block…" : "Sending…";
|
|
128
|
+
try {
|
|
129
|
+
const r = await api("/api/submit", { frames: rawFrames });
|
|
130
|
+
$("aOk").textContent = r.ok ? `Done in block ${r.block} (${r.tx.slice(0, 12)}…). ML-DSA-65 identity verified.`
|
|
131
|
+
: `The proof was accepted but the action failed (for example, not enough balance). Tx ${r.tx}.`;
|
|
132
|
+
} catch (e) { $("aOk").textContent = ""; $("scanErr").textContent = e.message; }
|
|
133
|
+
$("aSubmit").disabled = false;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// ---------------------------------------------------------------- agents
|
|
137
|
+
$("nKind").onchange = () => document.querySelectorAll("[data-k]").forEach((el) => (el.hidden = el.dataset.k !== $("nKind").value));
|
|
138
|
+
$("nCreate").onclick = async () => {
|
|
139
|
+
$("nErr").textContent = "";
|
|
140
|
+
try {
|
|
141
|
+
if (!VAULT) throw new Error("load a vault first (Vault page)");
|
|
142
|
+
const kind = $("nKind").value;
|
|
143
|
+
const body = { name: $("nName").value || undefined, kind, vault: VAULT };
|
|
144
|
+
if (kind === "scheduled") Object.assign(body, { to: $("nTo").value.trim(), amount: units($("nAmt").value), everySeconds: Math.round(Number($("nEvery").value) * 3600) });
|
|
145
|
+
else body.maxPerInvoice = units($("nMax").value);
|
|
146
|
+
await api("/api/agents", body); loadAgents();
|
|
147
|
+
} catch (e) { $("nErr").textContent = e.message; }
|
|
148
|
+
};
|
|
149
|
+
async function loadAgents() {
|
|
150
|
+
const list = await api("/api/agents").catch(() => []);
|
|
151
|
+
$("agTable").querySelector("tbody").innerHTML = list.map((a) => `<tr><td>${esc(a.name)}<br><span class="pill">${a.kind}</span> ${a.paused ? '<span class="pill bad">paused</span>' : ""}</td>
|
|
152
|
+
<td class="mono small">${a.address}</td><td>${a.remaining ? `${usd(a.remaining.today)} / ${usd(a.remaining.total)}` : "no allowance yet"}</td>
|
|
153
|
+
<td><button class="btn" data-pause="${a.id}" data-v="${!a.paused}">${a.paused ? "Resume" : "Pause"}</button></td></tr>`).join("") || `<tr><td colspan="4" class="muted">No agents yet.</td></tr>`;
|
|
154
|
+
document.querySelectorAll("[data-pause]").forEach((b) => (b.onclick = async () => { await api(`/api/agents/${b.dataset.pause}`, { paused: b.dataset.v === "true" }, "PATCH"); loadAgents(); }));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---------------------------------------------------------------- guardian
|
|
158
|
+
$("rSave").onclick = async () => {
|
|
159
|
+
try {
|
|
160
|
+
await api(`/api/guardian/${VAULT}`, { maxSingle: $("rSingle").value ? units($("rSingle").value) : null, maxDaily: $("rDaily").value ? units($("rDaily").value) : null, unknownOwner: $("rOwner").checked });
|
|
161
|
+
loadGuardian();
|
|
162
|
+
} catch (e) { $("gLog").textContent = e.message; }
|
|
163
|
+
};
|
|
164
|
+
async function loadGuardian() {
|
|
165
|
+
if (!VAULT) return ($("gLog").textContent = "Load a vault first.");
|
|
166
|
+
const g = await api(`/api/guardian/${VAULT}`).catch(() => null);
|
|
167
|
+
if (!g) return ($("gLog").textContent = "Not watching this vault yet.");
|
|
168
|
+
$("gLog").innerHTML = g.events.length ? g.events.map((e) => `${new Date(e.at).toLocaleString()} ${esc(e.kind)} ${esc(e.note || (e.amount ? usd(e.amount) + " USDG → " + e.to : e.tx || ""))}`).join("<br>") : "Watching. Nothing yet.";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
header(); setInterval(header, 8000);
|
|
172
|
+
if (VAULT) loadVault();
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Vantyx Companion</title>
|
|
7
|
+
<link rel="icon" href="mark.png">
|
|
8
|
+
<link rel="stylesheet" href="vault.css">
|
|
9
|
+
<style>
|
|
10
|
+
.app { grid-template-columns: 220px 1fr; }
|
|
11
|
+
.hdr { display: flex; gap: 18px; flex-wrap: wrap; font: 12px var(--mono); color: var(--mut); margin-bottom: 22px; }
|
|
12
|
+
.hdr b { color: var(--ink); font-weight: 500; }
|
|
13
|
+
table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
14
|
+
td, th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
15
|
+
th { font-weight: 500; color: var(--mut); font-size: 12px; }
|
|
16
|
+
.pill { font: 11px var(--mono); padding: 2px 8px; border-radius: 99px; background: var(--blue-l); color: var(--blue-d); }
|
|
17
|
+
.pill.bad { background: #fde8e6; color: var(--err); }
|
|
18
|
+
.log { font: 12px/1.6 var(--mono); max-height: 260px; overflow: auto; background: var(--bg); border-radius: 8px; padding: 10px; }
|
|
19
|
+
select { display: block; width: 100%; margin-top: 5px; font: 14px var(--sans); border: 1px solid var(--line); border-radius: 8px; padding: 9px; background: #fff; }
|
|
20
|
+
main section { max-width: 760px; }
|
|
21
|
+
</style>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<div class="offline-pill" style="background:#fff">Online companion · holds no vault keys</div>
|
|
25
|
+
<div class="app">
|
|
26
|
+
<nav class="side">
|
|
27
|
+
<div class="brand"><img src="mark.png" alt=""><span>Companion</span></div>
|
|
28
|
+
<button class="nav on" data-page="vault">Vault</button>
|
|
29
|
+
<button class="nav" data-page="scan">Scan from vault</button>
|
|
30
|
+
<button class="nav" data-page="agents">Agents</button>
|
|
31
|
+
<button class="nav" data-page="guardian">Guardian</button>
|
|
32
|
+
</nav>
|
|
33
|
+
<main>
|
|
34
|
+
<div class="hdr" id="hdr">connecting…</div>
|
|
35
|
+
|
|
36
|
+
<section data-p="vault">
|
|
37
|
+
<h2>Vault</h2>
|
|
38
|
+
<label>Vault contract<input id="vAddr" placeholder="0x…" spellcheck="false"></label>
|
|
39
|
+
<div class="row"><button class="btn primary" id="vLoad">Load</button><button class="btn" id="vSync">Show status QR for the vault</button></div>
|
|
40
|
+
<p class="error" id="vErr"></p>
|
|
41
|
+
<div class="grid" id="vCards" hidden></div>
|
|
42
|
+
</section>
|
|
43
|
+
|
|
44
|
+
<section data-p="scan" hidden>
|
|
45
|
+
<h2>Scan from the vault</h2>
|
|
46
|
+
<p class="muted">Point the camera at the vault app's QR. It collects every frame, then shows what the vault signed before anything is sent.</p>
|
|
47
|
+
<div class="scan"><video id="cam" playsinline muted></video><canvas id="camCv" hidden></canvas>
|
|
48
|
+
<div class="scanbar"><span id="scanProg">Camera off</span><button class="btn" id="camBtn">Start camera</button></div></div>
|
|
49
|
+
<details><summary>Paste frames instead</summary><textarea id="frIn" rows="4" spellcheck="false" placeholder="VX1/1/…"></textarea><div class="row end"><button class="btn" id="frBtn">Read</button></div></details>
|
|
50
|
+
<p class="error" id="scanErr"></p>
|
|
51
|
+
|
|
52
|
+
<div class="panel" id="genesisBox" hidden>
|
|
53
|
+
<h3>Deploy this vault</h3>
|
|
54
|
+
<p class="muted">Identity fingerprint <b class="mono" id="gFp"></b>. It must match the one in the vault app. Signed by the vault with ML-DSA-65 and SLH-DSA-128s; this companion checks both before deploying.</p>
|
|
55
|
+
<p class="muted small" id="gFixed"></p>
|
|
56
|
+
<p class="muted small">To have this companion's guardian watch the vault, type <b class="mono" id="gGuard"></b> into the vault app as the guardian, with a cold address of yours, before showing the deploy QR.</p>
|
|
57
|
+
<div class="row end"><button class="btn primary" id="gDeploy">Deploy on Robinhood Chain</button></div>
|
|
58
|
+
<details><summary>I already have a vault</summary>
|
|
59
|
+
<p class="muted small">If the vault is already on chain (deployed by another companion), this companion only needs its keys. Enter its address and register.</p>
|
|
60
|
+
<label>Vault contract<input id="gExisting" placeholder="0x…" spellcheck="false"></label>
|
|
61
|
+
<div class="row end"><button class="btn" id="gRegister">Register this vault's keys</button></div>
|
|
62
|
+
</details>
|
|
63
|
+
<p class="ok" id="gOk"></p>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<div class="panel" id="actionBox" hidden>
|
|
67
|
+
<h3>The vault signed</h3>
|
|
68
|
+
<p class="big" id="aDesc"></p>
|
|
69
|
+
<p class="muted small" id="aMeta"></p>
|
|
70
|
+
<div class="row end"><button class="btn primary" id="aSubmit">Send to the chain</button></div>
|
|
71
|
+
<p class="ok" id="aOk"></p>
|
|
72
|
+
</div>
|
|
73
|
+
</section>
|
|
74
|
+
|
|
75
|
+
<section data-p="agents" hidden>
|
|
76
|
+
<h2>Agents</h2>
|
|
77
|
+
<p class="muted">Each agent gets its own key here. Copy its address into the vault app (Agents) to give it an allowance, and send it a little ETH for gas.</p>
|
|
78
|
+
<div class="panel">
|
|
79
|
+
<div class="two">
|
|
80
|
+
<label>Name<input id="nName" placeholder="Rent"></label>
|
|
81
|
+
<label>Kind<select id="nKind"><option value="scheduled">Scheduled payment</option><option value="x402">x402 API payer</option></select></label>
|
|
82
|
+
</div>
|
|
83
|
+
<div class="two" data-k="scheduled">
|
|
84
|
+
<label>Pay to<input id="nTo" placeholder="0x…" spellcheck="false"></label>
|
|
85
|
+
<label>Amount (USDG)<input id="nAmt" placeholder="25"></label>
|
|
86
|
+
</div>
|
|
87
|
+
<label data-k="scheduled">Every (hours)<input id="nEvery" value="24"></label>
|
|
88
|
+
<label data-k="x402" hidden>Most it may pay per invoice (USDG)<input id="nMax" placeholder="1"></label>
|
|
89
|
+
<div class="row end"><button class="btn primary" id="nCreate">Create agent</button></div>
|
|
90
|
+
<p class="error" id="nErr"></p>
|
|
91
|
+
</div>
|
|
92
|
+
<table id="agTable"><thead><tr><th>Agent</th><th>Address</th><th>Left today / total</th><th></th></tr></thead><tbody></tbody></table>
|
|
93
|
+
</section>
|
|
94
|
+
|
|
95
|
+
<section data-p="guardian" hidden>
|
|
96
|
+
<h2>Guardian</h2>
|
|
97
|
+
<p class="muted">When a rule trips, the guardian calls evacuate(): everything goes to the address the vault fixed, and every agent is cancelled.</p>
|
|
98
|
+
<div class="panel">
|
|
99
|
+
<div class="two">
|
|
100
|
+
<label>Evacuate if one outflow is above (USDG)<input id="rSingle" placeholder="1000"></label>
|
|
101
|
+
<label>…or 24 h outflow is above (USDG)<input id="rDaily" placeholder="2500"></label>
|
|
102
|
+
</div>
|
|
103
|
+
<label style="display:flex;gap:8px;align-items:center;color:var(--ink)"><input type="checkbox" id="rOwner" style="width:auto;margin:0"> Evacuate if an owner action appears that this companion did not relay</label>
|
|
104
|
+
<div class="row end"><button class="btn primary" id="rSave">Watch this vault</button></div>
|
|
105
|
+
</div>
|
|
106
|
+
<h3>Events</h3>
|
|
107
|
+
<div class="log" id="gLog">Nothing yet.</div>
|
|
108
|
+
</section>
|
|
109
|
+
</main>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<dialog id="dlg"><div class="dlg"><h3>Status for the vault</h3><p class="muted small">Scan this on the offline computer (Vault app → Sync).</p>
|
|
113
|
+
<div class="qr"><canvas id="qr" width="420" height="420"></canvas><div class="qrbar"><span id="qrInfo"></span><button class="btn" id="copyFrames">Copy frames</button></div></div>
|
|
114
|
+
<div class="row end"><button class="btn" id="dClose">Close</button></div></div></dialog>
|
|
115
|
+
|
|
116
|
+
<script src="vendor/qrcode.js"></script>
|
|
117
|
+
<script src="vendor/jsQR.js"></script>
|
|
118
|
+
<script type="module" src="companion.js"></script>
|
|
119
|
+
</body>
|
|
120
|
+
</html>
|
package/public/mark.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|
3
|
+
<title>Vantyx · studio</title><link rel="icon" href="/assets/mark-96.png"><link rel="apple-touch-icon" href="/assets/mark-96.png"><meta name="robots" content="noindex,nofollow">
|
|
4
|
+
<link rel="preconnect" href="https://fonts.googleapis.com"><link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=DM+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
5
|
+
<style>
|
|
6
|
+
:root{--bg:#08101f;--panel:#0f1c36;--fg:#e6edfb;--dim:#9aa9c6;--faint:#5a6b8c;--line:#1c2a47;--sig:#6e95d6;--warm:#d4e2f6;--bad:#f0a08c;--sans:"Inter",system-ui,sans-serif;--mono:"DM Mono",ui-monospace,Menlo,monospace}
|
|
7
|
+
*{box-sizing:border-box}html,body{margin:0;background:var(--bg);color:var(--fg);font:400 15px/1.55 var(--sans);-webkit-font-smoothing:antialiased}
|
|
8
|
+
body{background:radial-gradient(90% 60% at 80% -10%,rgba(76,127,208,.14),transparent 60%),var(--bg)}
|
|
9
|
+
a{color:var(--sig)}button,input{font:inherit;color:inherit}
|
|
10
|
+
.wrap{max-width:860px;margin:0 auto;padding:28px 18px 60px}
|
|
11
|
+
header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:26px}
|
|
12
|
+
.logo{display:flex;align-items:center;gap:10px;font:600 18px var(--sans);letter-spacing:-.02em;color:var(--fg);text-decoration:none}.logo img{width:30px;height:30px}
|
|
13
|
+
.tag{font-family:var(--mono);font-size:11.5px;color:var(--dim)}
|
|
14
|
+
.card{background:var(--panel);border:1px solid var(--line);border-radius:0;padding:22px;margin-bottom:16px;box-shadow:inset 0 1px 0 rgba(255,255,255,.04)}
|
|
15
|
+
h2{margin:0 0 4px;font:400 20px var(--mono);letter-spacing:-.03em}.sub{margin:0 0 16px;color:var(--dim);font-size:13.5px}
|
|
16
|
+
label{display:block;font-size:12.5px;color:var(--dim);margin:12px 0 6px}
|
|
17
|
+
input{width:100%;background:rgba(0,0,0,.35);border:1px solid var(--line);border-radius:0;padding:12px 13px;outline:0;font-family:var(--mono);font-size:13.5px}input:focus{border-color:var(--sig)}
|
|
18
|
+
.row{display:flex;gap:10px;flex-wrap:wrap;align-items:end}.row>*{flex:1;min-width:160px}
|
|
19
|
+
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:0 18px;border:0;border-radius:0;background:#4c7fd0;color:#fff;font-weight:600;cursor:pointer;white-space:nowrap}
|
|
20
|
+
.btn.sig{background:#4c7fd0}.btn.ghost{background:none;border:1px solid var(--line);color:var(--fg)}.btn:disabled{opacity:.45;cursor:default}.btn:focus-visible{outline:2px solid var(--sig);outline-offset:2px}
|
|
21
|
+
.kv{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:10px;margin:6px 0 2px}.kv div{border:1px solid var(--line);border-radius:12px;padding:12px 14px;background:rgba(0,0,0,.2)}.kv b{display:block;font-family:var(--mono);font-size:15px;font-weight:500;word-break:break-all}.kv span{font-size:12px;color:var(--dim)}
|
|
22
|
+
.msg{font-family:var(--mono);font-size:12.5px;margin-top:10px;min-height:18px;word-break:break-word}.msg.ok{color:var(--sig)}.msg.bad{color:var(--bad)}
|
|
23
|
+
table{width:100%;border-collapse:collapse;font-family:var(--mono);font-size:12px}td,th{padding:9px 6px;border-top:1px solid var(--line);text-align:left;vertical-align:top}th{color:var(--dim);font-weight:400}
|
|
24
|
+
.st{padding:2px 8px;border-radius:6px;border:1px solid var(--line)}.st.done{color:var(--sig);border-color:rgba(110,149,214,.5)}.st.failed{color:var(--bad)}
|
|
25
|
+
.scroll{overflow-x:auto}
|
|
26
|
+
#gate{max-width:420px;margin:12vh auto 0}
|
|
27
|
+
.note{font-size:12.5px;color:var(--dim);margin:10px 0 0}
|
|
28
|
+
</style></head><body>
|
|
29
|
+
<div class="wrap">
|
|
30
|
+
<header><a class="logo" href="/"><img src="/assets/mark-96.png" alt="">Vantyx</a><span class="tag">studio</span></header>
|
|
31
|
+
<div id="gate" class="card"><h2>Studio</h2><p class="sub">Owner only. The key is in the companion data folder on the server (studio/secrets.json), or STUDIO_KEY in the environment.</p>
|
|
32
|
+
<form id="gf"><label for="key">Studio key</label><input id="key" type="password" autocomplete="current-password"><div style="margin-top:14px"><button class="btn">Unlock</button></div><div class="msg bad" id="gm"></div></form></div>
|
|
33
|
+
|
|
34
|
+
<div id="app" hidden>
|
|
35
|
+
<section class="card"><h2>01 · Token</h2><p class="sub">The CA shows in the top bar of vantyxvault.com with a copy button and a Buy link as soon as you save it. It also switches on the holders gate (GitHub source access) and Guardian Pro for vaults that hold the minimum. Leave it empty to hide it.</p>
|
|
36
|
+
<form id="tf"><div class="row"><div style="flex:3"><label for="ca">Contract address</label><input id="ca" placeholder="0x…" spellcheck="false"></div><div><label for="sym">Ticker</label><input id="sym" maxlength="13"></div></div>
|
|
37
|
+
<div style="margin-top:14px"><button class="btn">Save token</button></div><div class="msg" id="tm"></div></form></section>
|
|
38
|
+
|
|
39
|
+
<section class="card"><h2>02 · Buyback wallet</h2><p class="sub">Use a fresh wallet that only holds the ETH for buybacks. The key is encrypted on the server and never shown again. Never paste your main wallet.</p>
|
|
40
|
+
<div class="kv" id="wkv"></div>
|
|
41
|
+
<form id="wf"><label for="pk">Private key of the buyback wallet</label><input id="pk" type="password" autocomplete="off" spellcheck="false" placeholder="0x…">
|
|
42
|
+
<div class="row" style="margin-top:14px"><div style="flex:0"><button class="btn">Save wallet</button></div><div style="flex:0"><button class="btn ghost" type="button" id="wrm">Remove wallet</button></div></div><div class="msg" id="wm"></div></form></section>
|
|
43
|
+
|
|
44
|
+
<section class="card"><h2>03 · Buyback and burn</h2><p class="sub">Enter dollars. The panel pays the matching ETH at the live price, buys the token (Pons curve before graduation, Uniswap v4 after), then sends exactly what it bought to the dead address. Two real transactions.</p>
|
|
45
|
+
<div class="kv" id="bkv"></div>
|
|
46
|
+
<form id="bf"><div class="row"><div><label for="usd">Dollars to spend</label><input id="usd" inputmode="decimal" placeholder="10"></div><div style="flex:0"><button class="btn sig" id="bgo">Buy back and burn</button></div></div><div class="note" id="bq"></div><div class="msg" id="bm"></div></form></section>
|
|
47
|
+
|
|
48
|
+
<section class="card"><h2>04 · Burn supply</h2><p class="sub">Burns tokens the burn wallet already holds, with no buy. Send the supply you want to burn to the burn wallet first, then enter a dollar amount or press Max to burn all of it. One real transaction.</p>
|
|
49
|
+
<div class="kv" id="skv"></div>
|
|
50
|
+
<form id="sf"><div class="row"><div><label for="susd">Dollars of supply to burn</label><input id="susd" inputmode="decimal" placeholder="25"></div><div style="flex:0"><button class="btn ghost" type="button" id="smax">Max</button></div><div style="flex:0"><button class="btn sig" id="sgo">Burn supply</button></div></div><div class="note" id="sq"></div><div class="msg" id="sm"></div></form>
|
|
51
|
+
<p class="note">Recovery: if a buyback bought but did not burn, <button class="btn ghost" type="button" id="held" style="min-height:34px;padding:0 14px;font-size:13px">burn what the wallet holds</button></p></section>
|
|
52
|
+
|
|
53
|
+
<section class="card"><h2>05 · History</h2><p class="sub">Every step is saved before the next wait, so a restart never loses a hash. Finished burns show on the site.</p><div class="scroll"><table id="ht"></table></div></section>
|
|
54
|
+
<section class="card"><h2>Log</h2><div class="scroll"><table id="lt"></table></div></section>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
<script>
|
|
58
|
+
const $=(i)=>document.getElementById(i),esc=(s)=>String(s??"").replace(/[&<>"]/g,(c)=>({"&":"&","<":"<",">":">",'"':"""}[c]));
|
|
59
|
+
let KEY=sessionStorage.ckKey||"",S=null;
|
|
60
|
+
const api=async(p,o={})=>{const r=await fetch("/api/studio"+p,{...o,headers:{"x-studio-key":KEY,"content-type":"application/json"}});const j=await r.json().catch(()=>({}));if(!r.ok)throw Object.assign(new Error(j.error||"Request failed"),{status:r.status});return j};
|
|
61
|
+
const say=(id,t,ok)=>{const m=$(id);m.textContent=t;m.className="msg "+(ok?"ok":"bad")};
|
|
62
|
+
const usd=(v)=>v==null?"—":"$"+Number(v).toLocaleString("en-US",{maximumFractionDigits:2});
|
|
63
|
+
const num=(v,d=4)=>v==null?"—":Number(v).toLocaleString("en-US",{maximumFractionDigits:d});
|
|
64
|
+
const tx=(h)=>h?`<a href="${S.explorer}/tx/${esc(h)}" target="_blank" rel="noopener">${esc(h.slice(0,10))}…</a>`:"—";
|
|
65
|
+
function render(){const c=S.config;if(document.activeElement!==$("ca"))$("ca").value=c.ca||"";if(document.activeElement!==$("sym"))$("sym").value=c.symbol||"";
|
|
66
|
+
$("wkv").innerHTML=S.wallet?[[S.wallet,"buyback wallet"],[num(S.walletEth,5)+" ETH","balance"],[num(S.spendableEth,5)+" ETH","spendable (gas kept back)"],[S.tokenBal!=null?num(S.tokenBal,0)+" $"+esc(c.symbol):"—","token held"]].map(([b,s])=>`<div><b>${esc(b)}</b><span>${s}</span></div>`).join(""):`<div><b>none</b><span>no wallet saved yet</span></div>`;
|
|
67
|
+
$("bkv").innerHTML=[[usd(S.spendableUsd),"the wallet can spend"],[num(S.totals.bought,0)+" $"+esc(c.symbol),"burned by buybacks"],[`${num(S.totals.boughtEth,4)} ETH`+(S.ethUsd?` (≈ ${usd(Number(S.totals.boughtEth)*S.ethUsd)} now)`:""),"spent on buybacks"],[`${usd(S.todayUsd)} of ${usd(S.dayUsd)}`,"used in the last 24 h"],[usd(S.maxUsd),"max per buyback"],[S.onPons===false?"not on Pons":S.phase==null?"—":S.phase===0?"Pons curve":"Uniswap v4","where it buys"]].map(([b,s])=>`<div><b>${esc(b)}</b><span>${s}</span></div>`).join("");
|
|
68
|
+
$("skv").innerHTML=[[S.tokenBal!=null?num(S.tokenBal,0)+" $"+esc(c.symbol):"—","in the burn wallet"],[usd(S.tokenBalUsd),"worth now"],[S.tokenPriceUsd?"$"+Number(S.tokenPriceUsd).toPrecision(3):"—","price per token"],[num(S.totals.supply,0)+" $"+esc(c.symbol),"burned from supply"]].map(([b,s])=>`<div><b>${esc(b)}</b><span>${s}</span></div>`).join("");
|
|
69
|
+
quote();
|
|
70
|
+
if(S.error)say("bm","Chain read failed: "+S.error,false);
|
|
71
|
+
$("ht").innerHTML="<tr><th>when</th><th>type</th><th>status</th><th>dollars</th><th>burned</th><th>buy</th><th>burn</th></tr>"+(S.history.map(h=>`<tr><td>${esc(h.t.slice(0,16).replace("T"," "))}</td><td>${esc(h.kind||"buyback")}</td><td><span class="st ${esc(h.status)}">${esc(h.status)}</span></td><td>${h.usd!=null?usd(h.usd):"—"}</td><td>${h.burned?num(h.burned,0):"—"}</td><td>${tx(h.buyTx)}</td><td>${tx(h.burnTx)}</td></tr>`).join("")||'<tr><td colspan="7" style="color:var(--dim)">No burns yet.</td></tr>');
|
|
72
|
+
$("lt").innerHTML=S.logs.map(l=>`<tr><td style="white-space:nowrap">${esc(l.t.slice(5,19).replace("T"," "))}</td><td style="color:${l.level==="error"?"var(--bad)":l.level==="ok"?"var(--sig)":"var(--dim)"}">${esc(l.level)}</td><td>${esc(l.text)}</td></tr>`).join("")||'<tr><td style="color:var(--dim)">Nothing yet.</td></tr>';}
|
|
73
|
+
async function load(){S=await api("/status");render()}
|
|
74
|
+
async function enter(){try{await load();$("gate").hidden=true;$("app").hidden=false;setInterval(()=>load().catch(()=>{}),20000)}catch(e){sessionStorage.removeItem("ckKey");$("gm").textContent=e.message}}
|
|
75
|
+
$("gf").onsubmit=(e)=>{e.preventDefault();KEY=$("key").value.trim();sessionStorage.ckKey=KEY;enter()};if(KEY)enter();
|
|
76
|
+
$("tf").onsubmit=async(e)=>{e.preventDefault();try{const r=await api("/token",{method:"POST",body:JSON.stringify({ca:$("ca").value.trim(),symbol:$("sym").value.trim()})});say("tm",r.warn||(r.config.ca?"Saved. The CA is live in the hero within a minute.":"Saved. The CA is hidden on the site."),!r.warn);load()}catch(x){say("tm",x.message,false)}};
|
|
77
|
+
$("wf").onsubmit=async(e)=>{e.preventDefault();const pk=$("pk").value.trim();$("pk").value="";try{const r=await api("/wallet",{method:"POST",body:JSON.stringify({privateKey:pk})});say("wm","Saved: "+r.address,true);load()}catch(x){say("wm",x.message,false)}};
|
|
78
|
+
$("wrm").onclick=async()=>{if(!confirm("Remove the buyback wallet key from the server?"))return;try{await api("/wallet",{method:"DELETE"});say("wm","Removed.",true);load()}catch(x){say("wm",x.message,false)}};
|
|
79
|
+
// live previews: dollars to ETH for the buyback, dollars to tokens for the supply burn
|
|
80
|
+
let MAXED=false;
|
|
81
|
+
function quote(){if(!S)return;const b=+$("usd").value,s=$("susd").value.trim();
|
|
82
|
+
$("bq").textContent=b>0&&S.ethUsd?`≈ ${(b/S.ethUsd).toFixed(6)} ETH at $${Math.round(S.ethUsd).toLocaleString("en-US")} per ETH`:"";
|
|
83
|
+
$("sq").textContent=MAXED&&S.tokenBal?`All ${num(S.tokenBal,0)} $${S.config.symbol} in the wallet (≈ ${usd(S.tokenBalUsd)})`:(+s>0&&S.tokenPriceUsd?`≈ ${num(+s/S.tokenPriceUsd,0)} $${S.config.symbol}`:"")}
|
|
84
|
+
$("usd").oninput=quote;$("susd").oninput=()=>{MAXED=false;quote()};
|
|
85
|
+
$("smax").onclick=()=>{MAXED=true;$("susd").value=S&&S.tokenBalUsd!=null?String(S.tokenBalUsd):"";quote()};
|
|
86
|
+
$("bf").onsubmit=async(e)=>{e.preventDefault();const u=$("usd").value.trim();if(!u)return;if(!confirm(`Spend $${u} of ETH on $${S.config.symbol} and burn everything it buys? This sends two real transactions.`))return;const b=$("bgo");b.disabled=true;b.textContent="Working…";say("bm","Buying, then burning. Keep this tab open.",true);
|
|
87
|
+
try{const r=await api("/buyback",{method:"POST",body:JSON.stringify({usd:u})});say("bm",`Burned ${num(r.burned,0)} $${S.config.symbol} for $${r.usd}. Buy ${r.buyTx.slice(0,10)}…, burn ${r.burnTx.slice(0,10)}…`,true);$("usd").value=""}catch(x){say("bm",x.message,false)}finally{b.disabled=false;b.textContent="Buy back and burn";load()}};
|
|
88
|
+
$("sf").onsubmit=async(e)=>{e.preventDefault();const u=MAXED?"max":$("susd").value.trim();if(!u)return;const what=MAXED?`ALL ${num(S.tokenBal,0)} $${S.config.symbol} in the burn wallet`:`$${u} of $${S.config.symbol}`;
|
|
89
|
+
if(!confirm(`Burn ${what} from supply? Tokens sent to the dead address can never come back.`))return;if(MAXED&&!confirm("Last check: burn everything the burn wallet holds?"))return;
|
|
90
|
+
const b=$("sgo");b.disabled=true;b.textContent="Burning…";say("sm","Burning. Keep this tab open.",true);
|
|
91
|
+
try{const r=await api("/supply",{method:"POST",body:JSON.stringify({usd:u})});say("sm",`Burned ${num(r.burned,0)} $${S.config.symbol} (≈ $${r.usd}). Tx ${r.burnTx.slice(0,10)}…`,true);$("susd").value="";MAXED=false}catch(x){say("sm",x.message,false)}finally{b.disabled=false;b.textContent="Burn supply";load()}};
|
|
92
|
+
$("held").onclick=async()=>{if(!confirm("Burn every token the buyback wallet holds?"))return;try{const r=await api("/burn-held",{method:"POST"});say("bm",`Burned ${num(r.burned,0)} held tokens.`,true)}catch(x){say("bm",x.message,false)}load()};
|
|
93
|
+
</script></body></html>
|