flop-guild 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/content.js +9 -4
- package/dist/mcp.js +1 -1
- package/dist/minerpage.js +120 -30
- package/dist/net.js +13 -0
- package/dist/server.js +15 -12
- package/dist/shell.js +2 -1
- package/dist/sync-docs.js +2 -1
- package/dist/testnet.js +18 -3
- package/networks.json +1 -0
- package/package.json +1 -1
- package/skill.md +1 -1
package/dist/cli.js
CHANGED
|
@@ -83,7 +83,7 @@ async function main() {
|
|
|
83
83
|
const { pos, opt, get, num, need } = parse(rest);
|
|
84
84
|
const key = get("key") ?? process.env.FLOP_GUILD_KEY ?? "default";
|
|
85
85
|
const room = get("room") ?? DEFAULT_ROOM;
|
|
86
|
-
const network = get("network") ?? "
|
|
86
|
+
const network = get("network") ?? (await import("./net.js")).activeNetwork();
|
|
87
87
|
const agent = { name: pos[0] ?? key };
|
|
88
88
|
const flows = (get("flow") ? [get("flow")] : undefined);
|
|
89
89
|
let out;
|
package/dist/content.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Text uses a small Markdown subset: `code`, [text](url), and the word PROVISIONAL.
|
|
4
4
|
import { render } from "./config.js";
|
|
5
5
|
import { esc } from "./shell.js";
|
|
6
|
+
import { testnetLine } from "./testnet.js";
|
|
6
7
|
export const ROLES = [
|
|
7
8
|
{
|
|
8
9
|
id: "agent",
|
|
@@ -41,7 +42,7 @@ export const ROLES = [
|
|
|
41
42
|
{ title: "Verify", before: "Find your did:key in the [{{ROOM}}]({{ROOM_URL}}) room on Technocore." },
|
|
42
43
|
],
|
|
43
44
|
notes: [
|
|
44
|
-
"
|
|
45
|
+
"{{TESTNET_LINE}} No airdrop is promised.",
|
|
45
46
|
"More: [Start](/start) (make a key in the browser), [Agent quick start](/guides/agent-quickstart), [Autopilot](/guides/autopilot), [Join the guild](/guides/join-guild).",
|
|
46
47
|
],
|
|
47
48
|
},
|
|
@@ -205,11 +206,15 @@ export function guidesMd() {
|
|
|
205
206
|
return GUIDES.map((g) => `- [${g.title}]({{PUBLIC_URL}}/guides/${g.slug}) ([Markdown]({{PUBLIC_URL}}/guides/${g.slug}.md)): ${g.summary}`).join("\n");
|
|
206
207
|
}
|
|
207
208
|
/** Fill {{ROLES_MD}}, {{ROLE_MD:agent}}, {{GUIDES_MD}}, then the host and room placeholders. */
|
|
208
|
-
export function expand(template) {
|
|
209
|
-
return render(template
|
|
209
|
+
export function expand(template, line) {
|
|
210
|
+
return withTestnetLine(render(template
|
|
210
211
|
.replace(/\{\{ROLE_MD:(agent|miner|validator)\}\}/g, (_m, id) => roleMd(ROLES.find((r) => r.id === id), 2))
|
|
211
212
|
.replaceAll("{{ROLES_MD}}", rolesMd(2))
|
|
212
|
-
.replaceAll("{{GUIDES_MD}}", guidesMd()));
|
|
213
|
+
.replaceAll("{{GUIDES_MD}}", guidesMd())), line === undefined ? undefined : render(line));
|
|
214
|
+
}
|
|
215
|
+
/** Fill {{TESTNET_LINE}} with the sentence the testnet watcher's state calls for. */
|
|
216
|
+
export function withTestnetLine(text, line = testnetLine()) {
|
|
217
|
+
return text.replaceAll("{{TESTNET_LINE}}", line);
|
|
213
218
|
}
|
|
214
219
|
function cmdHtml(c) {
|
|
215
220
|
return `<pre${c.runin ? ` data-runin="${esc(c.runin)}"` : ""}><code>${esc(c.code)}</code></pre>`;
|
package/dist/mcp.js
CHANGED
|
@@ -72,7 +72,7 @@ const tools = [
|
|
|
72
72
|
async function withChain(network, fn) {
|
|
73
73
|
const { loadNetwork, connect } = await import("./net.js");
|
|
74
74
|
const f = await import("./flop.js");
|
|
75
|
-
const net = loadNetwork(network ?? "
|
|
75
|
+
const net = loadNetwork(network ?? (await import("./net.js")).activeNetwork());
|
|
76
76
|
const { api } = await connect(net);
|
|
77
77
|
try {
|
|
78
78
|
return await fn(net, api, f);
|
package/dist/minerpage.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// /miner: demand by UTC hour (7 days, cached 10 min) and a rent vs airdrop calculator.
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { CALC_DEFAULTS, loadDemand, minerCalc } from "./econ.js";
|
|
4
|
-
import { networksPath } from "./net.js";
|
|
5
|
-
|
|
4
|
+
import { activeNetwork, networksPath } from "./net.js";
|
|
5
|
+
import { testnetLine } from "./testnet.js";
|
|
6
6
|
export const MINER_FOOTER = "Unofficial community tool. Estimates only. Draft Flop rules may change. No airdrop promises.";
|
|
7
7
|
const TTL = 10 * 60 * 1000;
|
|
8
8
|
export const PARTIAL_NOTE = "Partial data, showing last complete read";
|
|
@@ -25,7 +25,7 @@ function view() {
|
|
|
25
25
|
return { shown: lastComplete ?? latest, latest, partial: !latest.complete };
|
|
26
26
|
}
|
|
27
27
|
/** Cached demand: refresh after 10 minutes (2 after a partial read); a partial read never replaces a complete one. */
|
|
28
|
-
export async function demand(network = process.env.MINER_NETWORK ||
|
|
28
|
+
export async function demand(network = process.env.MINER_NETWORK || activeNetwork(), waitMs = 25_000) {
|
|
29
29
|
const age = Date.now() - lastAttemptAt;
|
|
30
30
|
const stale = !lastAttempt || age > (lastAttempt.complete ? TTL : PARTIAL_RETRY);
|
|
31
31
|
if (stale && !inflight) {
|
|
@@ -77,15 +77,18 @@ function chart(byHour) {
|
|
|
77
77
|
.join("");
|
|
78
78
|
return `<svg viewBox="0 0 ${W} ${H}" role="img" aria-label="Sessions opened per UTC hour over the last 7 days" class="chart">${bars}${ticks}</svg>`;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
export const NA = "n/a (explorer unavailable)";
|
|
81
|
+
/** Without a miner count, every row that depends on it is n/a; only the rent is known. */
|
|
82
|
+
function calcRows(o, known = true, missing = NA) {
|
|
83
|
+
const k = (v) => (known ? v : missing);
|
|
81
84
|
const rows = [
|
|
82
85
|
["out-rent", "Total rent", usd(o.totalRent)],
|
|
83
|
-
["out-share", "Your share of the miner pool (estimate)", pct(o.share)],
|
|
84
|
-
["out-airdrop", "Airdrop FLOP (estimate)", flop(o.airdropFlop)],
|
|
85
|
-
["out-liquid", "Liquid FLOP at launch (estimate)", flop(o.liquidFlop)],
|
|
86
|
-
["out-be-liquid", "Break-even FLOP price, liquid FLOP only", price(o.breakEvenLiquid)],
|
|
87
|
-
["out-be-all", "Break-even FLOP price, if all airdrop FLOP unlocked", price(o.breakEvenAll)],
|
|
88
|
-
["out-net", "Liquid value minus rent, at your FLOP price", o.net === null ? "enter a FLOP price" : usd(o.net)],
|
|
86
|
+
["out-share", "Your share of the miner pool (estimate)", k(pct(o.share))],
|
|
87
|
+
["out-airdrop", "Airdrop FLOP (estimate)", k(flop(o.airdropFlop))],
|
|
88
|
+
["out-liquid", "Liquid FLOP at launch (estimate)", k(flop(o.liquidFlop))],
|
|
89
|
+
["out-be-liquid", "Break-even FLOP price, liquid FLOP only", k(price(o.breakEvenLiquid))],
|
|
90
|
+
["out-be-all", "Break-even FLOP price, if all airdrop FLOP unlocked", k(price(o.breakEvenAll))],
|
|
91
|
+
["out-net", "Liquid value minus rent, at your FLOP price", known ? (o.net === null ? "enter a FLOP price" : usd(o.net)) : missing],
|
|
89
92
|
];
|
|
90
93
|
return rows.map(([id, label, v]) => `<tr><th scope="row">${label}</th><td id="${id}">${v}</td></tr>`).join("");
|
|
91
94
|
}
|
|
@@ -94,31 +97,51 @@ export const MINER_STYLE = `
|
|
|
94
97
|
.prose table{margin:.6rem 0}.prose td{text-align:right;font-variant-numeric:tabular-nums}.prose th{font-weight:400;color:var(--muted)}
|
|
95
98
|
#miner-count{font-family:var(--display)}
|
|
96
99
|
.note{font-size:.88rem}`;
|
|
97
|
-
export
|
|
100
|
+
export const LOADING = "loading";
|
|
101
|
+
const utc = (t) => new Date(t).toISOString().slice(0, 16).replace("T", " ");
|
|
102
|
+
const RETRY = '<p id="retry-wrap"><a class="btn" id="retry" href="/miner" role="button">Retry</a></p>';
|
|
103
|
+
/** The demand block: chart and numbers when there is data, otherwise the loading or unavailable message. */
|
|
104
|
+
export function demandSection(v, state, err) {
|
|
98
105
|
const d = v?.shown;
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
if (!d) {
|
|
107
|
+
return state === "loading"
|
|
108
|
+
? `<p class="note">Loading demand data from the explorer. The calculator works meanwhile.</p>
|
|
109
|
+
<noscript><p>This part loads with JavaScript. Without it, reload the page in a minute.</p></noscript>`
|
|
110
|
+
: `<p>The explorer is unavailable${err ? ` (${esc(err)})` : " (no answer after 3 tries)"}. Demand and the miner count cannot be shown right now.</p>\n${RETRY}`;
|
|
111
|
+
}
|
|
101
112
|
const partialHtml = v?.partial
|
|
102
113
|
? `<p><strong>${v.shown.complete ? PARTIAL_NOTE : "Partial data, no complete read yet"}</strong> (latest read ${utc(v.latest.fetchedAt)} UTC stopped early: ${esc(v.latest.note ?? "incomplete")}; ${v.latest.pagesRead} pages, ${v.latest.sessions.toLocaleString("en-US")} sessions).</p>`
|
|
103
114
|
: "";
|
|
104
|
-
|
|
105
|
-
? ` <span class="note">(${d.sessions.toLocaleString("en-US")} sessions read since ${utc(d.windowStart)} UTC, ${d.pagesRead} explorer pages, ${d.complete ? "complete read" : "partial read"})</span>`
|
|
106
|
-
: "";
|
|
107
|
-
const out = minerCalc({ ...CALC_DEFAULTS, minerCount });
|
|
108
|
-
const demandHtml = d
|
|
109
|
-
? `<p>${d.sessions.toLocaleString("en-US")} sessions opened on ${esc(d.network)} between ${new Date(d.windowStart).toISOString().slice(0, 16).replace("T", " ")} and ${new Date(d.windowEnd).toISOString().slice(0, 16).replace("T", " ")} UTC, about <strong>${d.perHour.toFixed(1)} sessions per hour</strong>.</p>
|
|
115
|
+
return `<p>${d.sessions.toLocaleString("en-US")} sessions opened on ${esc(d.network)} between ${utc(d.windowStart)} and ${utc(d.windowEnd)} UTC, about <strong>${d.perHour.toFixed(1)} sessions per hour</strong>.</p>
|
|
110
116
|
${partialHtml}
|
|
111
117
|
${chart(d.byHour)}
|
|
112
118
|
<p>Busiest UTC hours: ${d.busiest.map((b) => `<strong>${hh(b.hour)}</strong> (${b.sessions.toLocaleString("en-US")})`).join(", ")}.</p>
|
|
113
|
-
<p class="note">Source: ${esc(d.explorer)}/api/compute-channels, bucketed by the hour each session opened. Updated ${new Date(d.fetchedAt).toISOString().slice(11, 16)} UTC, refreshed every 10 minutes.</p
|
|
114
|
-
|
|
119
|
+
<p class="note">Source: ${esc(d.explorer)}/api/compute-channels, bucketed by the hour each session opened. Updated ${new Date(d.fetchedAt).toISOString().slice(11, 16)} UTC, refreshed every 10 minutes.</p>`;
|
|
120
|
+
}
|
|
121
|
+
export function readInfoHtml(v) {
|
|
122
|
+
const d = v?.shown;
|
|
123
|
+
return d ? ` <span class="note">(${d.sessions.toLocaleString("en-US")} sessions read since ${utc(d.windowStart)} UTC, ${d.pagesRead} explorer pages, ${d.complete ? "complete read" : "partial read"})</span>` : "";
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* /miner. With cached data it renders complete. Without, it renders at once in the "loading" state and
|
|
127
|
+
* /miner.js fetches /api/miner-stats in the background (3 tries, 3 s apart), then fills in or shows
|
|
128
|
+
* "unavailable" with a Retry button. A missing miner count is never treated as 0.
|
|
129
|
+
*/
|
|
130
|
+
export function minerPage(v, err, state = v?.shown ? "ready" : "unavailable") {
|
|
131
|
+
const d = v?.shown;
|
|
132
|
+
const known = !!d;
|
|
133
|
+
const minerCount = d?.minerCount ?? 0;
|
|
134
|
+
const out = minerCalc({ ...CALC_DEFAULTS, minerCount });
|
|
135
|
+
const countText = known ? minerCount.toLocaleString("en-US") : state === "loading" ? LOADING : "unavailable";
|
|
115
136
|
return `<h1>Miner economics</h1>
|
|
116
137
|
<p>What miners are paid for: how much inference demand there is, by hour, and what renting a GPU costs against an estimated airdrop share.</p>
|
|
117
138
|
<h2>Demand by UTC hour, last 7 days</h2>
|
|
118
|
-
|
|
119
|
-
${
|
|
139
|
+
<p><strong>${esc(testnetLine())}</strong></p>
|
|
140
|
+
<div id="demand" data-state="${known ? "ready" : state}" aria-live="polite">
|
|
141
|
+
${demandSection(v, state, err)}
|
|
142
|
+
</div>
|
|
120
143
|
<h2>Rent vs airdrop calculator</h2>
|
|
121
|
-
<form id="calc" class="grid" data-miners="${minerCount}">
|
|
144
|
+
<form id="calc" class="grid" data-miners="${known ? minerCount : ""}">
|
|
122
145
|
<label>Rent, $ per hour<input id="in-rent" type="number" step="0.01" min="0" value="${CALC_DEFAULTS.rentPerHour}"></label>
|
|
123
146
|
<label>Hours per day<input id="in-hours" type="number" step="1" min="0" max="24" value="${CALC_DEFAULTS.hoursPerDay}"></label>
|
|
124
147
|
<label>Days<input id="in-days" type="number" step="1" min="0" value="${CALC_DEFAULTS.days}"></label>
|
|
@@ -128,29 +151,38 @@ ${demandHtml}
|
|
|
128
151
|
<label>Miner pool, FLOP<input id="in-pool" type="number" step="1" min="0" value="${CALC_DEFAULTS.poolFlop}"></label>
|
|
129
152
|
<label>Liquid share, %<input id="in-liquid" type="number" step="1" min="0" max="100" value="${CALC_DEFAULTS.liquidShare * 100}"></label>
|
|
130
153
|
</form>
|
|
131
|
-
<p>Miners active in the last 7 days (live from the explorer): <strong id="miner-count">${
|
|
132
|
-
|
|
154
|
+
<p>Miners active in the last 7 days (live from the explorer): <strong id="miner-count">${countText}</strong><span id="read-info">${readInfoHtml(v)}</span></p>
|
|
155
|
+
${!known && state === "unavailable" ? RETRY : ""}
|
|
156
|
+
<table><tbody>${calcRows(out, known, state === "loading" ? "waiting for the miner count" : NA)}</tbody></table>
|
|
133
157
|
<p class="note">Share estimate = your weight / (miner count × average weight) × (hours per day / 24). The share assumes the average miner runs 24 hours a day.</p>
|
|
134
158
|
<p class="note">The real share is your verified compute divided by all verified compute, which nobody can know in advance. No FLOP token or price exists yet.</p>`;
|
|
135
159
|
}
|
|
136
|
-
/** Browser script: the same minerCalc as the server,
|
|
160
|
+
/** Browser script: the same minerCalc as the server, input wiring, and the background data fetch. */
|
|
137
161
|
export function minerScript() {
|
|
138
162
|
return `"use strict";
|
|
139
163
|
${minerCalc.toString()}
|
|
140
164
|
(function () {
|
|
141
165
|
var f = document.getElementById("calc");
|
|
142
166
|
if (!f) return;
|
|
143
|
-
var
|
|
144
|
-
|
|
167
|
+
var raw = f.getAttribute("data-miners");
|
|
168
|
+
var known = raw !== "" && raw !== null; // empty: no explorer data yet, never treat as 0 miners
|
|
169
|
+
var miners = known ? Number(raw) || 0 : 0;
|
|
170
|
+
var NA = "n/a (explorer unavailable)";
|
|
171
|
+
var WAITING = "waiting for the miner count";
|
|
172
|
+
var missing = WAITING;
|
|
173
|
+
var DEPENDENT = ["out-share", "out-airdrop", "out-liquid", "out-be-liquid", "out-be-all", "out-net"];
|
|
174
|
+
function $(id) { return document.getElementById(id); }
|
|
175
|
+
function v(id) { var x = $(id).value; return x === "" ? undefined : Number(x); }
|
|
145
176
|
function usd(n) { return "$" + n.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 }); }
|
|
146
177
|
function fl(n) { return Math.round(n).toLocaleString("en-US") + " FLOP"; }
|
|
147
178
|
function pr(n) { return n === null ? "n/a" : "$" + (n < 0.01 ? n.toPrecision(3) : n.toFixed(4)); }
|
|
148
|
-
function set(id, t) {
|
|
179
|
+
function set(id, t) { $(id).textContent = t; }
|
|
149
180
|
function run() {
|
|
150
181
|
var o = minerCalc({ rentPerHour: v("in-rent") || 0, hoursPerDay: v("in-hours") || 0, days: v("in-days") || 0,
|
|
151
182
|
gpuWeight: v("in-weight") || 0, avgWeight: v("in-avg") || 0, minerCount: miners,
|
|
152
183
|
poolFlop: v("in-pool") || 0, liquidShare: (v("in-liquid") || 0) / 100, flopPrice: v("in-price") });
|
|
153
184
|
set("out-rent", usd(o.totalRent));
|
|
185
|
+
if (!known) { DEPENDENT.forEach(function (id) { set(id, missing); }); return; }
|
|
154
186
|
set("out-share", (o.share * 100).toPrecision(3) + "%");
|
|
155
187
|
set("out-airdrop", fl(o.airdropFlop));
|
|
156
188
|
set("out-liquid", fl(o.liquidFlop));
|
|
@@ -161,6 +193,64 @@ ${minerCalc.toString()}
|
|
|
161
193
|
f.addEventListener("submit", function (e) { e.preventDefault(); });
|
|
162
194
|
f.addEventListener("input", run);
|
|
163
195
|
run();
|
|
196
|
+
|
|
197
|
+
// Background load: /api/miner-stats, 3 tries 3 s apart, then "unavailable" with a Retry button.
|
|
198
|
+
var box = $("demand");
|
|
199
|
+
if (!box || box.getAttribute("data-state") === "ready") return;
|
|
200
|
+
var timer = null;
|
|
201
|
+
function wireRetry() {
|
|
202
|
+
var b = $("retry");
|
|
203
|
+
if (b) b.addEventListener("click", function (e) { e.preventDefault(); load(0); });
|
|
204
|
+
}
|
|
205
|
+
function loading() {
|
|
206
|
+
box.setAttribute("data-state", "loading");
|
|
207
|
+
box.innerHTML = '<p class="note">Loading demand data from the explorer. The calculator works meanwhile.</p>';
|
|
208
|
+
set("miner-count", "loading");
|
|
209
|
+
missing = WAITING; run();
|
|
210
|
+
}
|
|
211
|
+
function unavailable(why) {
|
|
212
|
+
box.setAttribute("data-state", "unavailable");
|
|
213
|
+
box.innerHTML = "";
|
|
214
|
+
var p = document.createElement("p");
|
|
215
|
+
p.textContent = "The explorer is unavailable (" + why + "). Demand and the miner count cannot be shown right now.";
|
|
216
|
+
box.appendChild(p);
|
|
217
|
+
var w = document.createElement("p"); w.id = "retry-wrap";
|
|
218
|
+
var a = document.createElement("a"); a.className = "btn"; a.id = "retry"; a.href = "/miner"; a.setAttribute("role", "button"); a.textContent = "Retry";
|
|
219
|
+
w.appendChild(a); box.appendChild(w);
|
|
220
|
+
set("miner-count", "unavailable");
|
|
221
|
+
missing = NA; run();
|
|
222
|
+
wireRetry();
|
|
223
|
+
}
|
|
224
|
+
function ready(j) {
|
|
225
|
+
box.innerHTML = j.fragments.demand;
|
|
226
|
+
box.setAttribute("data-state", "ready");
|
|
227
|
+
$("read-info").innerHTML = j.fragments.readInfo;
|
|
228
|
+
miners = Number(j.demand.minerCount) || 0;
|
|
229
|
+
known = true;
|
|
230
|
+
f.setAttribute("data-miners", String(miners));
|
|
231
|
+
set("miner-count", miners.toLocaleString("en-US"));
|
|
232
|
+
run();
|
|
233
|
+
}
|
|
234
|
+
function load(attempt) {
|
|
235
|
+
clearTimeout(timer);
|
|
236
|
+
if (attempt === 0) loading();
|
|
237
|
+
var ctl = window.AbortController ? new AbortController() : null;
|
|
238
|
+
var stop = ctl ? setTimeout(function () { ctl.abort(); }, 30000) : null;
|
|
239
|
+
fetch("/api/miner-stats", { cache: "no-store", credentials: "same-origin", signal: ctl ? ctl.signal : undefined })
|
|
240
|
+
.then(function (r) { return r.json().then(function (j) { return { ok: r.ok, j: j }; }); })
|
|
241
|
+
.then(function (x) {
|
|
242
|
+
clearTimeout(stop);
|
|
243
|
+
if (x.ok && x.j.demand && x.j.fragments) return ready(x.j);
|
|
244
|
+
throw new Error(x.j.error || "no data yet");
|
|
245
|
+
})
|
|
246
|
+
.catch(function (e) {
|
|
247
|
+
clearTimeout(stop);
|
|
248
|
+
if (attempt < 2) timer = setTimeout(function () { load(attempt + 1); }, 3000);
|
|
249
|
+
else unavailable(e && e.name === "AbortError" ? "no answer within 30 s" : (e && e.message) || "no answer");
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
wireRetry();
|
|
253
|
+
load(0);
|
|
164
254
|
})();
|
|
165
255
|
`;
|
|
166
256
|
}
|
package/dist/net.js
CHANGED
|
@@ -9,6 +9,19 @@ export const FLOP = 10n ** 18n;
|
|
|
9
9
|
export function networksPath() {
|
|
10
10
|
return process.env.FLOP_GUILD_NETWORKS || join(dirname(fileURLToPath(import.meta.url)), "..", "networks.json");
|
|
11
11
|
}
|
|
12
|
+
/** The kit's active network: FLOP_NETWORK, else "default" in networks.json, else devnet. Never changed automatically. */
|
|
13
|
+
export function activeNetwork() {
|
|
14
|
+
const env = process.env.FLOP_NETWORK?.trim();
|
|
15
|
+
if (env)
|
|
16
|
+
return env;
|
|
17
|
+
try {
|
|
18
|
+
const d = JSON.parse(readFileSync(networksPath(), "utf8")).default;
|
|
19
|
+
if (typeof d === "string" && /^[a-z0-9_-]+$/.test(d))
|
|
20
|
+
return d;
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
return "devnet";
|
|
24
|
+
}
|
|
12
25
|
export function loadNetwork(name) {
|
|
13
26
|
const all = JSON.parse(readFileSync(networksPath(), "utf8"));
|
|
14
27
|
const n = all[name];
|
package/dist/server.js
CHANGED
|
@@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url";
|
|
|
8
8
|
import { GUILD_ROOM, publicHost, render } from "./config.js";
|
|
9
9
|
import { networksPath } from "./net.js";
|
|
10
10
|
import { DISCLAIMER, esc, ICONS, page } from "./shell.js";
|
|
11
|
-
import { expand, GUIDES, guidesHtml, mdToHtml, ROLES, roleMd, rolesHtml, rolesMd } from "./content.js";
|
|
11
|
+
import { expand, GUIDES, guidesHtml, mdToHtml, ROLES, roleMd, rolesHtml, rolesMd, withTestnetLine } from "./content.js";
|
|
12
12
|
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
13
13
|
const SITE = join(ROOT, "site");
|
|
14
14
|
const VERSION = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8")).version;
|
|
@@ -43,7 +43,7 @@ async function networkStatus(network) {
|
|
|
43
43
|
const all = JSON.parse(readFileSync(networksPath(), "utf8"));
|
|
44
44
|
const net = all[network];
|
|
45
45
|
if (!net)
|
|
46
|
-
throw new Error(`unknown network "${network}"; known: ${Object.keys(all).join(", ")}`);
|
|
46
|
+
throw new Error(`unknown network "${network}"; known: ${Object.keys(all).filter((k) => typeof all[k] === "object").join(", ")}`);
|
|
47
47
|
if (!net.faucet || !net.genesis)
|
|
48
48
|
return JSON.stringify({ network, configured: false }, null, 2);
|
|
49
49
|
return cached(`status:${network}`, 30_000, async () => {
|
|
@@ -128,7 +128,7 @@ const tools = [
|
|
|
128
128
|
name: "network_status",
|
|
129
129
|
description: "Public FLOP network status: genesis match (faucet and explorer vs networks.json), faucet state, indexer lag, gateway models. Cached 30 s.",
|
|
130
130
|
inputSchema: { type: "object", properties: { network: { type: "string", description: "default devnet" } } },
|
|
131
|
-
run: (a) => networkStatus(String(a.network ?? "
|
|
131
|
+
run: async (a) => networkStatus(String(a.network ?? (await import("./net.js")).activeNetwork())),
|
|
132
132
|
},
|
|
133
133
|
{
|
|
134
134
|
name: "get_role_steps",
|
|
@@ -268,7 +268,7 @@ let limitsCache;
|
|
|
268
268
|
let limitsInflight;
|
|
269
269
|
/** Faucet /limits (the same endpoint network_status reads). Never blocks a page for more than 1.5 s. */
|
|
270
270
|
async function faucetLimits() {
|
|
271
|
-
const net = JSON.parse(readFileSync(networksPath(), "utf8")).
|
|
271
|
+
const net = JSON.parse(readFileSync(networksPath(), "utf8"))[(await import("./net.js")).activeNetwork()];
|
|
272
272
|
if ((!limitsCache || Date.now() - limitsCache.at > 60_000) && !limitsInflight && net?.faucet) {
|
|
273
273
|
limitsInflight = getJson(`${net.faucet}/limits`)
|
|
274
274
|
.then((v) => void (limitsCache = { at: Date.now(), v }))
|
|
@@ -288,11 +288,12 @@ async function homeStats() {
|
|
|
288
288
|
const mp = await import("./minerpage.js");
|
|
289
289
|
const [v, limits] = await Promise.all([mp.demand(undefined, 0).catch(() => undefined), faucetLimits().catch(() => undefined)]);
|
|
290
290
|
const nets = JSON.parse(readFileSync(networksPath(), "utf8"));
|
|
291
|
-
const
|
|
291
|
+
const active = (await import("./net.js")).activeNetwork();
|
|
292
|
+
const devnet = `<span class="tag">${esc(active)}</span>`;
|
|
292
293
|
const d = v?.shown;
|
|
293
294
|
const miners = d
|
|
294
|
-
? stat(ICONS.miner,
|
|
295
|
-
: stat(ICONS.miner,
|
|
295
|
+
? stat(ICONS.miner, `Miners on ${active}`, d.minerCount.toLocaleString("en-US"), `active in the last 7 days${d.complete ? "" : ", partial read"} ${devnet}`, "on", "LIVE")
|
|
296
|
+
: stat(ICONS.miner, `Miners on ${active}`, DASH, `explorer read in progress, refresh in a minute ${devnet}`, "off", "NO DATA");
|
|
296
297
|
const validators = stat(ICONS.validator, "Validators", DASH, `not read by this kit yet ${devnet}`, "off", "NO DATA");
|
|
297
298
|
const cap = Number(limits?.faucet?.dailyCap?.limitFlop);
|
|
298
299
|
const grant = Number(limits?.faucet?.anonymous?.grantFlop);
|
|
@@ -405,22 +406,24 @@ export function startServer(port, host = "0.0.0.0") {
|
|
|
405
406
|
const mp = await import("./minerpage.js");
|
|
406
407
|
if (path === "/miner.js")
|
|
407
408
|
return send(res, 200, "text/javascript; charset=utf-8", mp.minerScript());
|
|
408
|
-
|
|
409
|
+
// /miner never waits for the explorer: it renders from the cache (or "loading") and the page script
|
|
410
|
+
// fetches /api/miner-stats in the background. The API waits up to 20 s per try.
|
|
411
|
+
const v = path === "/miner" ? await mp.demand(undefined, 0) : await mp.demand(undefined, 20_000);
|
|
409
412
|
const d = v?.shown;
|
|
410
413
|
const fresh = { "cache-control": "public, max-age=60" };
|
|
411
414
|
if (path === "/api/miner-stats") {
|
|
412
415
|
const { CALC_DEFAULTS, minerCalc } = await import("./econ.js");
|
|
413
416
|
const body = d
|
|
414
|
-
? { demand: d, partial: v.partial, latestRead: v.partial ? v.latest : undefined, defaults: CALC_DEFAULTS, defaultResult: minerCalc({ ...CALC_DEFAULTS, minerCount: d.minerCount }), disclaimer: mp.MINER_FOOTER }
|
|
417
|
+
? { demand: d, partial: v.partial, latestRead: v.partial ? v.latest : undefined, defaults: CALC_DEFAULTS, defaultResult: minerCalc({ ...CALC_DEFAULTS, minerCount: d.minerCount }), fragments: { demand: mp.demandSection(v, "ready"), readInfo: mp.readInfoHtml(v) }, disclaimer: mp.MINER_FOOTER }
|
|
415
418
|
: { error: mp.demandError() ?? "loading, try again in a minute", disclaimer: mp.MINER_FOOTER };
|
|
416
|
-
return send(res, d ? 200 : 503, "application/json", JSON.stringify(body, null, 2), fresh);
|
|
419
|
+
return send(res, d ? 200 : 503, "application/json", JSON.stringify(body, null, 2), d ? fresh : { "cache-control": "no-store" });
|
|
417
420
|
}
|
|
418
|
-
return send(res, 200, "text/html; charset=utf-8", page("Miner economics", mp.minerPage(v, mp.demandError()), { footerNote: mp.MINER_FOOTER, style: mp.MINER_STYLE, script: "/miner.js", cards: true }), fresh);
|
|
421
|
+
return send(res, 200, "text/html; charset=utf-8", page("Miner economics", mp.minerPage(v, mp.demandError(), v?.shown ? "ready" : "loading"), { footerNote: mp.MINER_FOOTER, style: mp.MINER_STYLE, script: "/miner.js", cards: true }), fresh);
|
|
419
422
|
}
|
|
420
423
|
if (path === "/") {
|
|
421
424
|
const body = render(readFileSync(join(SITE, "index.html"), "utf8"))
|
|
422
425
|
.replace(/\{\{icon:([a-z]+)\}\}/g, (_m, k) => ICONS[k] ?? "")
|
|
423
|
-
.replace("{{ROLES}}", render(rolesHtml(ICONS)))
|
|
426
|
+
.replace("{{ROLES}}", withTestnetLine(render(rolesHtml(ICONS))))
|
|
424
427
|
.replace("{{GUIDES}}", guidesHtml(ICONS.doc))
|
|
425
428
|
.replace("{{STATS}}", await homeStats());
|
|
426
429
|
return send(res, 200, "text/html; charset=utf-8", page("flopguild: pick your role", body, { footerNote: START_FOOTER, style: HOME_STYLE, script: "/tabs.js" }), { "cache-control": "public, max-age=60" });
|
package/dist/shell.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Shared page shell for the site: top bar, cards, terminal-style code blocks, fonts. Dark only.
|
|
2
2
|
// Everything is served from this site: fonts from /fonts, scripts from /copy.js and page scripts.
|
|
3
3
|
import { GUILD_ROOM, GUILD_ROOM_URL } from "./config.js";
|
|
4
|
+
import { activeNetwork } from "./net.js";
|
|
4
5
|
export const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
5
6
|
export const RUN_IN_SHELL = "Run in: Ubuntu, macOS Terminal, or WSL on Windows (not PowerShell)";
|
|
6
7
|
export const RUN_IN_POWERSHELL = "Run in: PowerShell";
|
|
@@ -171,7 +172,7 @@ ${o.style ?? ""}
|
|
|
171
172
|
</style>${copy}${o.script ? `<script ${o.module ? 'type="module"' : "defer"} src="${o.script}"></script>` : ""}</head><body>
|
|
172
173
|
<header class="topbar"><div class="wrap">
|
|
173
174
|
<a class="brand" href="/" aria-label="flopguild home"><img src="/logo.svg" alt="" width="28" height="28"><span class="wm"><span>flop</span><b>guild</b></span></a>
|
|
174
|
-
<span class="pill" title="The
|
|
175
|
+
<span class="pill" title="The network this kit is set to use (networks.json)">${esc(activeNetwork().toUpperCase())}</span>
|
|
175
176
|
${NAV}
|
|
176
177
|
<a class="btn" href="/#agent">Start your agent</a>
|
|
177
178
|
</div></header>
|
package/dist/sync-docs.js
CHANGED
|
@@ -13,7 +13,8 @@ const a = text.indexOf(START);
|
|
|
13
13
|
const b = text.indexOf(END);
|
|
14
14
|
if (a < 0 || b < a)
|
|
15
15
|
throw new Error("skill.md: generated markers not found");
|
|
16
|
-
|
|
16
|
+
// The package is built once; the testnet line changes over time, so point to the live status instead.
|
|
17
|
+
const body = expand("## Roles\n\n{{ROLES_MD}}\n## Guides\n\n{{GUIDES_MD}}\n", "Testnet status changes over time: see {{PUBLIC_URL}}/api/status. This kit runs on devnet, which earns nothing.");
|
|
17
18
|
const next = `${text.slice(0, a)}${START}\n\n${body.trim()}\n\n${text.slice(b)}`;
|
|
18
19
|
if (next !== text)
|
|
19
20
|
writeFileSync(path, next);
|
package/dist/testnet.js
CHANGED
|
@@ -254,17 +254,32 @@ export async function checkOnce(o = {}) {
|
|
|
254
254
|
await notify(message(next, firstFlip), log);
|
|
255
255
|
return next;
|
|
256
256
|
}
|
|
257
|
+
const LABEL = { rpc: "RPC", gateway: "gateway", faucet: "faucet", genesis: "genesis hash", chainId: "chain ID" };
|
|
258
|
+
const list = (xs) => (xs.length < 2 ? xs.join("") : `${xs.slice(0, -1).join(", ")} and ${xs.at(-1)}`);
|
|
259
|
+
/** The one sentence the site uses for testnet, from the watcher's state. Never mentions an airdrop. */
|
|
260
|
+
export function testnetLine(st = status()) {
|
|
261
|
+
if (st.published)
|
|
262
|
+
return "Flop has published testnet endpoints. They are not enabled in the kit yet.";
|
|
263
|
+
if (!st.found.length)
|
|
264
|
+
return "Testnet endpoints are not published yet. This kit runs on devnet, which earns nothing.";
|
|
265
|
+
const waitFor = st.missing.filter((f) => f === "gateway" || f === "faucet" || f === "rpc").map((f) => LABEL[f]);
|
|
266
|
+
const pending = waitFor.length ? waitFor : st.missing.map((f) => LABEL[f]);
|
|
267
|
+
return `Flop has published part of its testnet details (found: ${list(st.found.map((f) => LABEL[f]))}; missing: ${list(st.missing.map((f) => LABEL[f]))}). The kit stays on devnet until the ${list(pending)} ${pending.length > 1 ? "are" : "is"} published.`;
|
|
268
|
+
}
|
|
257
269
|
/** Public summary for /api/status and the home page card. */
|
|
258
270
|
export function status() {
|
|
259
271
|
const s = loadState();
|
|
260
|
-
|
|
261
|
-
|
|
272
|
+
const missing = (s.missing ?? [...FIELDS]).filter((f) => FIELDS.includes(f));
|
|
273
|
+
const base = {
|
|
274
|
+
published: !!s.published,
|
|
275
|
+
found: FIELDS.filter((f) => !missing.includes(f)),
|
|
262
276
|
lastChecked: s.lastChecked ?? null,
|
|
263
277
|
lastChanged: s.lastChanged ?? null,
|
|
264
|
-
missing
|
|
278
|
+
missing,
|
|
265
279
|
lastError: s.lastError ?? null,
|
|
266
280
|
note: "Endpoints are never enabled in the kit automatically.",
|
|
267
281
|
};
|
|
282
|
+
return { ...base, line: testnetLine(base) };
|
|
268
283
|
}
|
|
269
284
|
let timer;
|
|
270
285
|
/** Start the 5-minute loop inside the site server. TESTNET_WATCH=0 turns it off. */
|
package/networks.json
CHANGED
package/package.json
CHANGED
package/skill.md
CHANGED
|
@@ -124,7 +124,7 @@ Run in: Ubuntu, macOS Terminal, or WSL on Windows (not PowerShell)
|
|
|
124
124
|
|
|
125
125
|
Find your did:key in the [d-flopguild](https://technocore.chat/r/d-flopguild) room on Technocore.
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
Testnet status changes over time: see https://flopguild.xyz/api/status. This kit runs on devnet, which earns nothing. No airdrop is promised.
|
|
128
128
|
|
|
129
129
|
More: [Start](https://flopguild.xyz/start) (make a key in the browser), [Agent quick start](https://flopguild.xyz/guides/agent-quickstart), [Autopilot](https://flopguild.xyz/guides/autopilot), [Join the guild](https://flopguild.xyz/guides/join-guild).
|
|
130
130
|
|