tryflop 0.0.0-stage → 0.1.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 +68 -2
- package/bin/flop-mcp.mjs +22 -0
- package/bin/tryflop.mjs +36 -0
- package/e2e/sandbox-smoke.mjs +136 -0
- package/npm-shrinkwrap.json +2648 -0
- package/package.json +55 -4
- package/src/agent-settings.js +76 -0
- package/src/claim.js +516 -0
- package/src/cli.js +428 -0
- package/src/daily.js +363 -0
- package/src/files.js +104 -0
- package/src/flop-core.js +189 -0
- package/src/flop-node.js +346 -0
- package/src/format.js +180 -0
- package/src/gate.js +19 -0
- package/src/guard.js +231 -0
- package/src/home.js +96 -0
- package/src/install.js +110 -0
- package/src/keyfile.js +70 -0
- package/src/layout.js +55 -0
- package/src/miners.js +65 -0
- package/src/moments.js +50 -0
- package/src/outcome.js +128 -0
- package/src/outer.js +969 -0
- package/src/payer.js +834 -0
- package/src/questions.js +47 -0
- package/src/requests.js +178 -0
- package/src/roots.js +48 -0
- package/src/sandbox.js +223 -0
- package/src/scheduler.js +221 -0
- package/src/scoring.js +67 -0
- package/src/secrets.js +41 -0
- package/src/server.js +13 -0
- package/src/shared/config.js +366 -0
- package/src/shared/direct-core.js +226 -0
- package/src/shared/grants-core.js +69 -0
- package/src/shared/units.js +47 -0
- package/src/statusfile.js +70 -0
- package/src/tools.js +107 -0
- package/src/tryflop.js +622 -0
- package/src/wallet.js +123 -0
package/src/guard.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Local limits on top of the chain's. GuardedJournal wraps the SDK's spend journal:
|
|
2
|
+
// LongSession signs every purchase, calls journal.reserve(entry, budget) with its exact amount, and only
|
|
3
|
+
// then broadcasts it (long-session.js JournaledSubmitter.submit, byte-identical in 0.9.0 and 0.12.1). A refusal here therefore means
|
|
4
|
+
// nothing was sent, and the account and session nonces are read fresh at the next prepare.
|
|
5
|
+
// - per answer: what one ask_flop call may commit in total (its open plus any top-ups);
|
|
6
|
+
// - per rolling 24 h: from ledger.jsonl, written BEFORE the SDK reserves (a crash over-counts, never
|
|
7
|
+
// under-counts); a spend the SDK then refuses gets a void line;
|
|
8
|
+
// - the chain session's own terms (its remaining cap, per-payment and daily limits), from the fresh read
|
|
9
|
+
// beforeSpend takes just before each purchase: the exact amount is compared with them here, so a purchase
|
|
10
|
+
// the chain must refuse is never broadcast (a broadcast the chain refuses still costs its network fee and
|
|
11
|
+
// uses up the SDK's never-refunded lifetime debit and this ledger's day). Each read is good for one
|
|
12
|
+
// purchase only.
|
|
13
|
+
// The lifetime limit is the SDK's own budgetPlanck (its journal's debit never goes down).
|
|
14
|
+
import { closeSync, fsyncSync, openSync, readFileSync, writeSync } from 'node:fs';
|
|
15
|
+
import { formatFlop } from './shared/units.js';
|
|
16
|
+
|
|
17
|
+
/** @typedef {import('@flop-labs/sdk').computeChannel.SpendJournal} SpendJournal */
|
|
18
|
+
/** @typedef {import('@flop-labs/sdk').computeChannel.SpendEntry} SpendEntry */
|
|
19
|
+
/** @typedef {import('@flop-labs/sdk').computeChannel.ChannelRecord} ChannelRecord */
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {{ at: number, requestId: string, txHash: string, kind: 'open'|'topUp', channel: string, amount: string }
|
|
22
|
+
* | { at: number, txHash: string, void: true }} LedgerLine
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The granted session's remaining allowance, read fresh from the chain before each purchase. For tryflop's own wallet
|
|
26
|
+
* (`own: true`) the same three numbers mean: what the wallet holds beyond its fee reserve, one channel's ceiling, and
|
|
27
|
+
* what this daily run may still spend (SPEC.md "Asking as the wallet itself").
|
|
28
|
+
*/
|
|
29
|
+
/** @typedef {{ capLeftPlanck: bigint, perTxPlanck: bigint, dailyLeftPlanck: bigint, own?: boolean }} ChainLimits */
|
|
30
|
+
|
|
31
|
+
const DAY_MS = 86_400_000;
|
|
32
|
+
|
|
33
|
+
export class LimitError extends Error {
|
|
34
|
+
/** @param {'per_ask'|'per_day'|'no_request'|'ledger_damaged'|'chain_cap'|'chain_per_tx'|'chain_per_day'|'no_chain_check'|'per_batch'|'wallet_balance'|'per_channel'|'per_run'} which @param {string} message */
|
|
35
|
+
constructor(which, message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = 'LimitError';
|
|
38
|
+
this.code = 'CONNECTOR_LIMIT';
|
|
39
|
+
this.which = which;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @param {any} line @returns {line is LedgerLine} */
|
|
44
|
+
function wellFormed(line) {
|
|
45
|
+
if (!line || typeof line !== 'object' || !Number.isFinite(line.at) || typeof line.txHash !== 'string') return false;
|
|
46
|
+
if (line.void === true) return true;
|
|
47
|
+
return typeof line.amount === 'string' && /^[0-9]+$/.test(line.amount) && typeof line.requestId === 'string';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Every ledger line. A torn last line (the process stopped mid-write) is ignored; damage anywhere else
|
|
52
|
+
* refuses, because skipping a line could under-count the day.
|
|
53
|
+
* @param {string} file @returns {LedgerLine[]}
|
|
54
|
+
*/
|
|
55
|
+
export function readLedger(file) {
|
|
56
|
+
let text;
|
|
57
|
+
try {
|
|
58
|
+
text = readFileSync(file, 'utf8');
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (/** @type {any} */ (error).code === 'ENOENT') return [];
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
const rows = text.split('\n');
|
|
64
|
+
const lines = [];
|
|
65
|
+
for (const [index, row] of rows.entries()) {
|
|
66
|
+
if (row === '') continue;
|
|
67
|
+
let line;
|
|
68
|
+
try {
|
|
69
|
+
line = JSON.parse(row);
|
|
70
|
+
} catch {
|
|
71
|
+
line = undefined;
|
|
72
|
+
}
|
|
73
|
+
if (wellFormed(line)) {
|
|
74
|
+
lines.push(line);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (index === rows.length - 1) continue; // torn last line: no newline after it
|
|
78
|
+
throw new LimitError('ledger_damaged', `The spend ledger ${file} has a damaged line (${index + 1}); no new purchase is made until it is fixed.`);
|
|
79
|
+
}
|
|
80
|
+
return lines;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Append one line and flush it to disk before returning. @param {string} file @param {LedgerLine} line */
|
|
84
|
+
export function appendLedger(file, line) {
|
|
85
|
+
const fd = openSync(file, 'a', 0o600);
|
|
86
|
+
try {
|
|
87
|
+
writeSync(fd, `${JSON.stringify(line)}\n`);
|
|
88
|
+
fsyncSync(fd);
|
|
89
|
+
} finally {
|
|
90
|
+
closeSync(fd);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** FLOP committed in the 24 hours before `now` (voided spends excluded). @param {LedgerLine[]} lines @param {number} now */
|
|
95
|
+
export function dayTotal(lines, now) {
|
|
96
|
+
const voided = new Set(lines.filter((l) => 'void' in l).map((l) => l.txHash));
|
|
97
|
+
let total = 0n;
|
|
98
|
+
for (const line of lines) {
|
|
99
|
+
if ('void' in line || voided.has(line.txHash) || line.at <= now - DAY_MS) continue;
|
|
100
|
+
total += BigInt(line.amount);
|
|
101
|
+
}
|
|
102
|
+
return total;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @implements {SpendJournal} */
|
|
106
|
+
export class GuardedJournal {
|
|
107
|
+
/**
|
|
108
|
+
* @param {SpendJournal} inner the SDK's FileSpendJournal (or a stand-in in tests)
|
|
109
|
+
* @param {{ ledgerFile: string, maxPerDayPlanck: bigint, now: () => number, onReserved?: (kind: 'open'|'topUp') => void }} options
|
|
110
|
+
* onReserved: told after each purchase the SDK journaled (it is broadcast next; its outcome may still be unknown)
|
|
111
|
+
*/
|
|
112
|
+
constructor(inner, { ledgerFile, maxPerDayPlanck, now, onReserved = () => {} }) {
|
|
113
|
+
this.inner = inner;
|
|
114
|
+
this.onReserved = onReserved;
|
|
115
|
+
this.ledgerFile = ledgerFile;
|
|
116
|
+
this.maxPerDayPlanck = maxPerDayPlanck;
|
|
117
|
+
this.now = now;
|
|
118
|
+
/** @type {{ requestId: string, maxPlanck: bigint, reserved: Array<{ txHash: string, amount: bigint, kind: 'open'|'topUp', channel: string, at: number }>, started: boolean } | undefined} */
|
|
119
|
+
this.current = undefined;
|
|
120
|
+
/** @type {ChainLimits | undefined} */
|
|
121
|
+
this.chainLimits = undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get genesis() { return this.inner.genesis; }
|
|
125
|
+
|
|
126
|
+
get owner() { return this.inner.owner; }
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The granted session's remaining allowance, from the fresh chain read `beforeSpend` takes right before
|
|
130
|
+
* each purchase. It is good for exactly one purchase: reserve consumes it, and a later purchase that
|
|
131
|
+
* never got its own read is refused rather than judged by an older one.
|
|
132
|
+
* @param {ChainLimits} limits
|
|
133
|
+
*/
|
|
134
|
+
setChainLimits(limits) {
|
|
135
|
+
this.chainLimits = limits;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The ask_flop call whose purchases the next reserves belong to. @param {string} requestId @param {bigint} maxPlanck */
|
|
139
|
+
begin(requestId, maxPlanck) {
|
|
140
|
+
if (this.current) throw new Error(`request ${this.current.requestId} is already open in the spend guard`);
|
|
141
|
+
this.current = { requestId, maxPlanck, reserved: [], started: false };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Close the call: what it reserved, and whether its turn may have reached the miner. */
|
|
145
|
+
end() {
|
|
146
|
+
const current = this.current;
|
|
147
|
+
this.current = undefined;
|
|
148
|
+
return { reserved: current?.reserved ?? [], started: current?.started ?? false };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** @param {Omit<SpendEntry, 'status'|'reason'>} entry @param {bigint} budget */
|
|
152
|
+
async reserve(entry, budget) {
|
|
153
|
+
const current = this.current;
|
|
154
|
+
if (!current) throw new LimitError('no_request', 'A purchase outside any ask_flop call was refused.');
|
|
155
|
+
const at = this.now(); // signed, not yet broadcast: never later than the open on chain
|
|
156
|
+
const amount = BigInt(entry.amount);
|
|
157
|
+
// The granted session's own terms, against the exact amount: the chain would refuse a broadcast above
|
|
158
|
+
// any of them, and that still costs its fee and the SDK's never-refunded debit. The read is one-shot: a
|
|
159
|
+
// purchase without its own fresh read is refused (fail closed) instead of judged by an older one.
|
|
160
|
+
const limits = this.chainLimits;
|
|
161
|
+
this.chainLimits = undefined;
|
|
162
|
+
if (!limits) throw new LimitError('no_chain_check', 'The spending limit on Flop\'s chain could not be checked before this purchase, so nothing was bought.');
|
|
163
|
+
if (limits.own) {
|
|
164
|
+
if (amount > limits.capLeftPlanck) {
|
|
165
|
+
throw new LimitError('wallet_balance', `This purchase would lock ${formatFlop(amount)} FLOP, but the wallet holds only ${formatFlop(limits.capLeftPlanck > 0n ? limits.capLeftPlanck : 0n)} FLOP beyond what it keeps for network fees.`);
|
|
166
|
+
}
|
|
167
|
+
if (amount > limits.perTxPlanck) {
|
|
168
|
+
throw new LimitError('per_channel', `This purchase would lock ${formatFlop(amount)} FLOP, more than one channel may hold (${formatFlop(limits.perTxPlanck)} FLOP).`);
|
|
169
|
+
}
|
|
170
|
+
if (amount > limits.dailyLeftPlanck) {
|
|
171
|
+
throw new LimitError('per_run', `This purchase would lock ${formatFlop(amount)} FLOP, more than this run may still spend (${formatFlop(limits.dailyLeftPlanck > 0n ? limits.dailyLeftPlanck : 0n)} FLOP).`);
|
|
172
|
+
}
|
|
173
|
+
} else if (amount > limits.capLeftPlanck) {
|
|
174
|
+
throw new LimitError('chain_cap', `This purchase would commit ${formatFlop(amount)} FLOP, but only ${formatFlop(limits.capLeftPlanck)} FLOP of your wallet's spending limit is left.`);
|
|
175
|
+
}
|
|
176
|
+
if (!limits.own && amount > limits.perTxPlanck) {
|
|
177
|
+
throw new LimitError('chain_per_tx', `This purchase would commit ${formatFlop(amount)} FLOP, more than the ${formatFlop(limits.perTxPlanck)} FLOP per-payment limit your wallet granted.`);
|
|
178
|
+
}
|
|
179
|
+
if (!limits.own && amount > limits.dailyLeftPlanck) {
|
|
180
|
+
throw new LimitError('chain_per_day', `This purchase would commit ${formatFlop(amount)} FLOP, more than the ${formatFlop(limits.dailyLeftPlanck)} FLOP left of your wallet's daily limit on Flop's chain.`);
|
|
181
|
+
}
|
|
182
|
+
const mine = current.reserved.reduce((sum, r) => sum + r.amount, 0n);
|
|
183
|
+
if (mine + amount > current.maxPlanck) {
|
|
184
|
+
throw new LimitError('per_ask', `This answer would commit ${formatFlop(mine + amount)} FLOP, more than its limit of ${formatFlop(current.maxPlanck)} FLOP.`);
|
|
185
|
+
}
|
|
186
|
+
const day = dayTotal(readLedger(this.ledgerFile), this.now());
|
|
187
|
+
if (day + amount > this.maxPerDayPlanck) {
|
|
188
|
+
throw new LimitError('per_day', `Today's limit on this computer is ${formatFlop(this.maxPerDayPlanck)} FLOP and ${formatFlop(day)} FLOP is already committed; this purchase (${formatFlop(amount)} FLOP) would pass it.`);
|
|
189
|
+
}
|
|
190
|
+
appendLedger(this.ledgerFile, { at: this.now(), requestId: current.requestId, txHash: entry.txHash, kind: entry.kind, channel: entry.channel, amount: entry.amount });
|
|
191
|
+
try {
|
|
192
|
+
await this.inner.reserve(entry, budget);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
try {
|
|
195
|
+
appendLedger(this.ledgerFile, { at: this.now(), txHash: entry.txHash, void: true });
|
|
196
|
+
} catch {
|
|
197
|
+
// The ledger keeps the line: it over-counts the day, which only refuses sooner.
|
|
198
|
+
}
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
current.reserved.push({ txHash: entry.txHash, amount, kind: entry.kind, channel: entry.channel, at });
|
|
202
|
+
this.onReserved(entry.kind);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** @param {string} requestId @param {string} channel */
|
|
206
|
+
async beginRequest(requestId, channel) {
|
|
207
|
+
// Marked first: from here on the turn may reach the miner, so it is never retried automatically.
|
|
208
|
+
if (this.current && this.current.requestId === requestId) this.current.started = true;
|
|
209
|
+
return this.inner.beginRequest(requestId, channel);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
acquire() { return this.inner.acquire(); }
|
|
213
|
+
|
|
214
|
+
release() { return this.inner.release(); }
|
|
215
|
+
|
|
216
|
+
state() { return this.inner.state(); }
|
|
217
|
+
|
|
218
|
+
/** @param {Parameters<SpendJournal['resolve']>} args */
|
|
219
|
+
resolve(...args) { return this.inner.resolve(...args); }
|
|
220
|
+
|
|
221
|
+
/** @param {ChannelRecord} record */
|
|
222
|
+
putChannel(record) { return this.inner.putChannel(record); }
|
|
223
|
+
|
|
224
|
+
/** @param {string} requestId */
|
|
225
|
+
dropRequest(requestId) { return this.inner.dropRequest(requestId); }
|
|
226
|
+
|
|
227
|
+
/** @param {ChannelRecord} channel @param {string} requestId @param {unknown} result */
|
|
228
|
+
commitTurn(channel, requestId, result) { return this.inner.commitTurn(channel, requestId, result); }
|
|
229
|
+
|
|
230
|
+
clearTerminal() { return this.inner.clearTerminal(); }
|
|
231
|
+
}
|
package/src/home.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The connector's private data folder: ~/.flop-mcp/<network>/ (FLOP_MCP_HOME replaces
|
|
2
|
+
// ~/.flop-mcp). Folders 0700, files 0600, no symbolic links, like ~/.ssh: anything looser is refused with
|
|
3
|
+
// the command that fixes it. Settings are exact FLOP amounts kept as decimal strings in config.json.
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
|
6
|
+
import { assertPrivateFile, ensurePrivateDir, HomeError, writePrivateFile } from './files.js';
|
|
7
|
+
import { PLANCK_PER_FLOP, toPlanck } from './shared/units.js';
|
|
8
|
+
|
|
9
|
+
export { homeRoot } from './roots.js';
|
|
10
|
+
export { assertPrivateFile, createPrivateFileOnce, ensurePrivateDir, HomeError, writePrivateFile } from './files.js';
|
|
11
|
+
export { networkHome, walletHome } from './layout.js';
|
|
12
|
+
/** @typedef {import('./layout.js').Home} Home */
|
|
13
|
+
/** @typedef {import('./layout.js').WalletHome} WalletHome */
|
|
14
|
+
|
|
15
|
+
/** SS58 prefix the keyring and the agent app use; addresses are compared as strings, so one form only. */
|
|
16
|
+
export const SS58_PREFIX = 42;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{ owner: string, maxFlopPerAsk: bigint, maxFlopPerDay: bigint, maxFlopTotal: bigint, idleSettleSeconds: number }} Settings
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_LIMITS = Object.freeze({ maxFlopPerAsk: '1', maxFlopPerDay: '5', maxFlopTotal: '20', idleSettleSeconds: 60 });
|
|
23
|
+
/**
|
|
24
|
+
* The local limits a new set-up gets on each network. Per answer: a round amount above one channel's escrow on that
|
|
25
|
+
* network's miners, or every first question is refused (nothing bought, nothing answered): devnet's ecamli opens at
|
|
26
|
+
* 0.89 FLOP (23 Nov 2026), testnet's m11 at 1.68 FLOP (26 Nov 2026); never above the
|
|
27
|
+
* 2 FLOP any one channel may take (DIRECT.maxChannelPlanck).
|
|
28
|
+
*/
|
|
29
|
+
const NETWORK_LIMITS = Object.freeze({ devnet: DEFAULT_LIMITS, testnet: Object.freeze({ ...DEFAULT_LIMITS, maxFlopPerAsk: '2' }) });
|
|
30
|
+
/** @param {string} network @returns {{ maxFlopPerAsk: string, maxFlopPerDay: string, maxFlopTotal: string, idleSettleSeconds: number }} */
|
|
31
|
+
export const defaultLimits = (network) => (Object.hasOwn(NETWORK_LIMITS, network) ? NETWORK_LIMITS[/** @type {'devnet'|'testnet'} */ (network)] : DEFAULT_LIMITS);
|
|
32
|
+
const AMOUNTS = /** @type {const} */ (['maxFlopPerAsk', 'maxFlopPerDay', 'maxFlopTotal']);
|
|
33
|
+
|
|
34
|
+
/** @param {string} field @param {unknown} value @returns {bigint} */
|
|
35
|
+
function amount(field, value) {
|
|
36
|
+
if (typeof value !== 'string') throw new HomeError('BAD_SETTINGS', `config.json: ${field} must be a FLOP amount in quotes, like "1" or "0.5".`);
|
|
37
|
+
let planck;
|
|
38
|
+
try {
|
|
39
|
+
planck = toPlanck(value);
|
|
40
|
+
} catch {
|
|
41
|
+
throw new HomeError('BAD_SETTINGS', `config.json: ${field} must be a FLOP amount like "1" or "0.5" (at most 18 decimals), not ${JSON.stringify(value)}.`);
|
|
42
|
+
}
|
|
43
|
+
if (planck <= 0n) throw new HomeError('BAD_SETTINGS', `config.json: ${field} must be more than 0.`);
|
|
44
|
+
return planck;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Validate config.json's content. Every field is required: nothing falls back to a default silently. @returns {Settings} */
|
|
48
|
+
export function parseSettings(json) {
|
|
49
|
+
if (!json || typeof json !== 'object' || Array.isArray(json)) throw new HomeError('BAD_SETTINGS', 'config.json must hold an object with owner and the limits.');
|
|
50
|
+
for (const field of ['owner', ...AMOUNTS, 'idleSettleSeconds']) {
|
|
51
|
+
if (!(field in json)) throw new HomeError('BAD_SETTINGS', `config.json is missing ${field}.`);
|
|
52
|
+
}
|
|
53
|
+
let owner;
|
|
54
|
+
try {
|
|
55
|
+
owner = encodeAddress(decodeAddress(json.owner), SS58_PREFIX);
|
|
56
|
+
} catch {
|
|
57
|
+
throw new HomeError('BAD_SETTINGS', 'config.json: owner must be your wallet\'s Flop address.');
|
|
58
|
+
}
|
|
59
|
+
const [perAsk, perDay, total] = AMOUNTS.map((field) => amount(field, json[field]));
|
|
60
|
+
if (perAsk > perDay) throw new HomeError('BAD_SETTINGS', 'config.json: maxFlopPerAsk cannot be more than maxFlopPerDay.');
|
|
61
|
+
if (perDay > total) throw new HomeError('BAD_SETTINGS', 'config.json: maxFlopPerDay cannot be more than maxFlopTotal.');
|
|
62
|
+
const idle = json.idleSettleSeconds;
|
|
63
|
+
if (!Number.isInteger(idle) || idle < 10 || idle > 300) throw new HomeError('BAD_SETTINGS', 'config.json: idleSettleSeconds must be a whole number from 10 to 300.');
|
|
64
|
+
return { owner, maxFlopPerAsk: perAsk, maxFlopPerDay: perDay, maxFlopTotal: total, idleSettleSeconds: idle };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Planck as an exact decimal FLOP string ("0.5", "20", "0.000000000000000001"). @param {bigint} planck */
|
|
68
|
+
export function planckToDecimal(planck) {
|
|
69
|
+
const whole = planck / PLANCK_PER_FLOP;
|
|
70
|
+
const fraction = (planck % PLANCK_PER_FLOP).toString().padStart(18, '0').replace(/0+$/, '');
|
|
71
|
+
return fraction ? `${whole}.${fraction}` : `${whole}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @param {Home} home @returns {Settings} */
|
|
75
|
+
export function loadSettings(home) {
|
|
76
|
+
assertPrivateFile(home.settingsFile);
|
|
77
|
+
let json;
|
|
78
|
+
try {
|
|
79
|
+
json = JSON.parse(readFileSync(home.settingsFile, 'utf8'));
|
|
80
|
+
} catch {
|
|
81
|
+
throw new HomeError('BAD_SETTINGS', `config.json is not valid JSON (${home.settingsFile}).`);
|
|
82
|
+
}
|
|
83
|
+
return parseSettings(json);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @param {Home} home @param {Settings} settings */
|
|
87
|
+
export function saveSettings(home, settings) {
|
|
88
|
+
ensurePrivateDir(home.dir);
|
|
89
|
+
writePrivateFile(home.settingsFile, `${JSON.stringify({
|
|
90
|
+
owner: settings.owner,
|
|
91
|
+
maxFlopPerAsk: planckToDecimal(settings.maxFlopPerAsk),
|
|
92
|
+
maxFlopPerDay: planckToDecimal(settings.maxFlopPerDay),
|
|
93
|
+
maxFlopTotal: planckToDecimal(settings.maxFlopTotal),
|
|
94
|
+
idleSettleSeconds: settings.idleSettleSeconds,
|
|
95
|
+
}, null, 2)}\n`);
|
|
96
|
+
}
|
package/src/install.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The copy of tryflop the scheduler and Claude Code start (SPEC.md "tryflop setup", COPY). `npx` runs the package from
|
|
2
|
+
// npm's cache, which npm may clean at any time, so setup copies this package and exactly its dependency closure to
|
|
3
|
+
// ~/.tryflop/app/<version>-<fingerprint>/node_modules/ — outside every folder the sandbox may write (code that could rewrite what runs
|
|
4
|
+
// next, outside the sandbox, would escape it). Run from a checkout (no node_modules folder around it), the checkout is
|
|
5
|
+
// used as it is. Node built-ins only: this runs outside the sandbox.
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { constants, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
9
|
+
import { dependencyDir } from './sandbox.js';
|
|
10
|
+
|
|
11
|
+
/** @param {string} dir */
|
|
12
|
+
const manifest = (dir) => JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Where Node finds package `name` for code in `fromDir` (its own node_modules, then each ancestor's that is not itself
|
|
16
|
+
* a node_modules folder), never above `rootNm`'s parent.
|
|
17
|
+
* @param {string} name @param {string} fromDir @param {string} rootNm @returns {string | null}
|
|
18
|
+
*/
|
|
19
|
+
function locate(name, fromDir, rootNm) {
|
|
20
|
+
const stop = dirname(rootNm);
|
|
21
|
+
for (let dir = fromDir; ; dir = dirname(dir)) {
|
|
22
|
+
if (basename(dir) !== 'node_modules') {
|
|
23
|
+
const candidate = join(dir, 'node_modules', name);
|
|
24
|
+
if (existsSync(join(candidate, 'package.json'))) return candidate;
|
|
25
|
+
}
|
|
26
|
+
if (dir === stop || dirname(dir) === dir) return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Every package directory the package at `appDir` needs at run time (dependencies, optional and peer dependencies that
|
|
32
|
+
* are installed), found the way Node resolves them, with `appDir` itself first.
|
|
33
|
+
* @param {string} appDir @param {string} rootNm the node_modules folder that holds appDir
|
|
34
|
+
* @returns {string[]}
|
|
35
|
+
*/
|
|
36
|
+
export function dependencyClosure(appDir, rootNm) {
|
|
37
|
+
const seen = new Set([appDir]);
|
|
38
|
+
const queue = [appDir];
|
|
39
|
+
while (queue.length) {
|
|
40
|
+
const dir = /** @type {string} */ (queue.shift());
|
|
41
|
+
const pkg = manifest(dir);
|
|
42
|
+
const names = [...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.optionalDependencies ?? {}), ...Object.keys(pkg.peerDependencies ?? {})];
|
|
43
|
+
for (const name of names) {
|
|
44
|
+
const found = locate(name, dir, rootNm);
|
|
45
|
+
if (!found) {
|
|
46
|
+
if (Object.hasOwn(pkg.dependencies ?? {}, name)) throw new Error(`${pkg.name} needs ${name}, which is not installed next to it`);
|
|
47
|
+
continue; // an optional or peer dependency that is not installed
|
|
48
|
+
}
|
|
49
|
+
if (!seen.has(found)) {
|
|
50
|
+
seen.add(found);
|
|
51
|
+
queue.push(found);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [...seen];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A fingerprint of the package's own files: its manifest, its pinned dependency tree (npm-shrinkwrap.json) and its code
|
|
60
|
+
* (bin/, src/, and e2e/, whose sandbox smoke test `sandbox-check` loads at run time). Two builds with the same version number but other content (a dependency bumped, a fix) get different
|
|
61
|
+
* fingerprints (merge review: SDK 0.13.1 arrived without a version change, and a copy keyed on the version alone kept
|
|
62
|
+
* running 0.12.1).
|
|
63
|
+
* @param {string} appDir
|
|
64
|
+
*/
|
|
65
|
+
export function packageFingerprint(appDir) {
|
|
66
|
+
const hash = createHash('sha256');
|
|
67
|
+
/** @param {string} rel */
|
|
68
|
+
const walk = (rel) => {
|
|
69
|
+
const abs = join(appDir, rel);
|
|
70
|
+
if (statSync(abs).isDirectory()) {
|
|
71
|
+
for (const entry of readdirSync(abs).sort()) walk(join(rel, entry));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
hash.update(`${rel.split(sep).join('/')}\0`);
|
|
75
|
+
hash.update(readFileSync(abs));
|
|
76
|
+
hash.update('\0');
|
|
77
|
+
};
|
|
78
|
+
for (const rel of ['package.json', 'npm-shrinkwrap.json', 'bin', 'src', 'e2e']) if (existsSync(join(appDir, rel))) walk(rel);
|
|
79
|
+
return hash.digest('hex').slice(0, 12);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Copy the running package to `<appRoot>/<version>-<fingerprint>/` (once per content), or use the checkout it runs
|
|
84
|
+
* from. A new build always gets a NEW folder and an existing one is never rewritten: a daily run may be running from
|
|
85
|
+
* it (the scheduler is re-pointed afterwards, never during a run). Old copies go at uninstall.
|
|
86
|
+
* @param {{ appDir: string, appRoot: string, version: string, name: string }} o
|
|
87
|
+
* @returns {{ binPath: string, copied: boolean, dir: string }}
|
|
88
|
+
*/
|
|
89
|
+
export function installApp({ appDir, appRoot, version, name }) {
|
|
90
|
+
const rootNm = dependencyDir(appDir);
|
|
91
|
+
if (!rootNm) return { binPath: join(appDir, 'bin', 'tryflop.mjs'), copied: false, dir: appDir };
|
|
92
|
+
const fingerprint = packageFingerprint(appDir);
|
|
93
|
+
const target = join(appRoot, `${version}-${fingerprint}`);
|
|
94
|
+
const rel = relative(rootNm, appDir);
|
|
95
|
+
const binPath = join(target, 'node_modules', rel, 'bin', 'tryflop.mjs');
|
|
96
|
+
if (existsSync(join(target, '.complete'))) return { binPath, copied: false, dir: target };
|
|
97
|
+
// Made private before anything is copied in: cpSync creates folders with the default mode (group-writable under
|
|
98
|
+
// Linux's usual umask 002), and the code copy must be writable by this user alone (push-gate review of 2875307).
|
|
99
|
+
mkdirSync(appRoot, { recursive: true, mode: 0o700 });
|
|
100
|
+
const temp = `${target}.tmp-${process.pid}`;
|
|
101
|
+
rmSync(temp, { recursive: true, force: true });
|
|
102
|
+
// Only the top of each nested tree is copied: a package's own node_modules travels with it.
|
|
103
|
+
const dirs = dependencyClosure(appDir, rootNm).filter((dir, _i, all) => !all.some((other) => other !== dir && dir.startsWith(other + sep)));
|
|
104
|
+
// A clone where the file system can (APFS on a Mac: no extra disk space), a plain copy elsewhere (~255 MB).
|
|
105
|
+
for (const dir of dirs) cpSync(dir, join(temp, 'node_modules', relative(rootNm, dir)), { recursive: true, dereference: false, mode: constants.COPYFILE_FICLONE });
|
|
106
|
+
writeFileSync(join(temp, '.complete'), `${name}@${version} ${fingerprint}\n`);
|
|
107
|
+
rmSync(target, { recursive: true, force: true });
|
|
108
|
+
renameSync(temp, target);
|
|
109
|
+
return { binPath, copied: true, dir: target };
|
|
110
|
+
}
|
package/src/keyfile.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The connector's own session key: made on this computer from the operating
|
|
2
|
+
// system's random source, kept in <home>/key.json (0600), never printed, never sent anywhere. The owner's
|
|
3
|
+
// wallet grants this key's public address a capped, compute-only spending session on Flop's chain.
|
|
4
|
+
// No error message ever quotes the file: it holds the seed.
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { Keyring } from '@polkadot/keyring';
|
|
7
|
+
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
|
8
|
+
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
|
9
|
+
import { assertPrivateFile, createPrivateFileOnce, ensurePrivateDir, HomeError, SS58_PREFIX } from './home.js';
|
|
10
|
+
|
|
11
|
+
export class KeyError extends Error {
|
|
12
|
+
/** @param {'EXISTS'|'MISSING'|'WRONG_NETWORK'|'DAMAGED'} code @param {string} message */
|
|
13
|
+
constructor(code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'KeyError';
|
|
16
|
+
this.code = code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const keyring = () => new Keyring({ type: 'sr25519', ss58Format: SS58_PREFIX });
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Make this network's session key. Refuses (EXISTS) when one exists: replacing it would orphan the
|
|
24
|
+
* spending limit the owner granted to the old address.
|
|
25
|
+
* @param {import('./home.js').Home} home @param {{ genesis: string }} network
|
|
26
|
+
* @returns {Promise<{ address: string }>}
|
|
27
|
+
*/
|
|
28
|
+
export async function createKey(home, { genesis }) {
|
|
29
|
+
await cryptoWaitReady();
|
|
30
|
+
ensurePrivateDir(home.dir);
|
|
31
|
+
const seed = globalThis.crypto.getRandomValues(new Uint8Array(32));
|
|
32
|
+
const { address } = keyring().addFromSeed(seed);
|
|
33
|
+
const file = { version: 1, network: home.network, genesis, address, seed: u8aToHex(seed), createdAt: new Date().toISOString() };
|
|
34
|
+
const made = createPrivateFileOnce(home.keyFile, `${JSON.stringify(file, null, 2)}\n`);
|
|
35
|
+
seed.fill(0);
|
|
36
|
+
if (!made) throw new KeyError('EXISTS', `${home.network} already has a session key (${home.keyFile}); it was left unchanged.`);
|
|
37
|
+
return { address };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Load this network's session key.
|
|
42
|
+
* @param {import('./home.js').Home} home @param {{ genesis: string }} network
|
|
43
|
+
* @returns {Promise<{ address: string, pair: import('@polkadot/keyring/types').KeyringPair }>}
|
|
44
|
+
*/
|
|
45
|
+
export async function loadKey(home, { genesis }) {
|
|
46
|
+
await cryptoWaitReady();
|
|
47
|
+
try {
|
|
48
|
+
assertPrivateFile(home.keyFile);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof HomeError && error.code === 'MISSING') {
|
|
51
|
+
throw new KeyError('MISSING', `There is no ${home.network} session key yet. Make one with: flop-mcp init --owner <your wallet address> --network ${home.network}`);
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
let file;
|
|
56
|
+
try {
|
|
57
|
+
file = JSON.parse(readFileSync(home.keyFile, 'utf8'));
|
|
58
|
+
} catch {
|
|
59
|
+
throw new KeyError('DAMAGED', `${home.keyFile} is damaged (not valid JSON).`);
|
|
60
|
+
}
|
|
61
|
+
if (!file || file.version !== 1 || typeof file.seed !== 'string' || !/^0x[0-9a-f]{64}$/.test(file.seed) || typeof file.address !== 'string') {
|
|
62
|
+
throw new KeyError('DAMAGED', `${home.keyFile} is damaged (missing or malformed fields).`);
|
|
63
|
+
}
|
|
64
|
+
if (file.network !== home.network || file.genesis !== genesis) {
|
|
65
|
+
throw new KeyError('WRONG_NETWORK', `${home.keyFile} belongs to another Flop network than ${home.network}.`);
|
|
66
|
+
}
|
|
67
|
+
const pair = keyring().addFromSeed(hexToU8a(file.seed));
|
|
68
|
+
if (pair.address !== file.address) throw new KeyError('DAMAGED', `${home.keyFile} is damaged (its address does not match its key).`);
|
|
69
|
+
return { address: pair.address, pair };
|
|
70
|
+
}
|
package/src/layout.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Where each route keeps its files (SPEC.md "tryflop"). Node built-ins only (see src/files.js).
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {{ network: 'devnet'|'testnet', dir: string, keyFile: string, settingsFile: string, ledgerFile: string,
|
|
6
|
+
* requestsFile: string, answersDir: string, claimFile: string, journalDir: (owner: string) => string }} Home
|
|
7
|
+
* claimFile: the last faucet claim and transfer to the owner (`flop-mcp claim`, testnet)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** @param {string} root @param {'devnet'|'testnet'} network @returns {Home} */
|
|
11
|
+
export function networkHome(root, network) {
|
|
12
|
+
const dir = join(root, network);
|
|
13
|
+
return {
|
|
14
|
+
network,
|
|
15
|
+
dir,
|
|
16
|
+
keyFile: join(dir, 'key.json'),
|
|
17
|
+
settingsFile: join(dir, 'config.json'),
|
|
18
|
+
ledgerFile: join(dir, 'ledger.jsonl'),
|
|
19
|
+
requestsFile: join(dir, 'requests.jsonl'),
|
|
20
|
+
answersDir: join(dir, 'answers'),
|
|
21
|
+
claimFile: join(dir, 'claim.json'),
|
|
22
|
+
journalDir: (owner) => join(dir, `journal-${owner}`),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Home & { walletFile: string, tryflopFile: string, dailyFile: string, lockFile: string, momentsFile: string }} WalletHome
|
|
28
|
+
* tryflop's own route (SPEC.md "tryflop"): the agent's ONE wallet and everything it pays with, in a folder of its own so
|
|
29
|
+
* its ledger, request log, journal and claim record never mix with a flop-mcp session key's in the network folder.
|
|
30
|
+
* walletFile: the 12 words (0600); tryflopFile: settings (topic, daily minute); dailyFile: what the daily runs did;
|
|
31
|
+
* lockFile: one daily run at a time; momentsFile: which human moments were already notified
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** @param {string} root @param {'devnet'|'testnet'} network @returns {WalletHome} */
|
|
35
|
+
export function walletHome(root, network) {
|
|
36
|
+
const base = networkHome(root, network);
|
|
37
|
+
const dir = join(base.dir, 'wallet');
|
|
38
|
+
return {
|
|
39
|
+
network,
|
|
40
|
+
dir,
|
|
41
|
+
keyFile: join(dir, 'wallet.json'),
|
|
42
|
+
walletFile: join(dir, 'wallet.json'),
|
|
43
|
+
settingsFile: join(dir, 'settings.json'),
|
|
44
|
+
tryflopFile: join(dir, 'settings.json'),
|
|
45
|
+
ledgerFile: join(dir, 'ledger.jsonl'),
|
|
46
|
+
requestsFile: join(dir, 'requests.jsonl'),
|
|
47
|
+
answersDir: join(dir, 'answers'),
|
|
48
|
+
claimFile: join(dir, 'claim.json'),
|
|
49
|
+
dailyFile: join(dir, 'daily.json'),
|
|
50
|
+
lockFile: join(dir, 'daily.lock'),
|
|
51
|
+
momentsFile: join(dir, 'moments.json'),
|
|
52
|
+
journalDir: (owner) => join(dir, `journal-${owner}`),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
package/src/miners.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Who tryflop may pay on each network: the agent app's allowlist (src/shared/config.js, a byte copy) plus the testnet
|
|
2
|
+
// miners this package vetted itself. The agent app lists a miner only after a paid run through the app (it lists
|
|
3
|
+
// m11 when its own run passes); this package's runs are paid through this package, so it keeps
|
|
4
|
+
// its own additions here instead of changing the app's list under that card. When the app lists one of these, the
|
|
5
|
+
// app's entry wins (same id or same account) and the duplicate here is ignored.
|
|
6
|
+
//
|
|
7
|
+
// Every entry: the operator's own post naming the account AND the host (miners publish their web address nowhere
|
|
8
|
+
// else), a signed readiness proof for that account on testnet, registered, active and calibrated at the finalized head,
|
|
9
|
+
// its model Verified in the chain's registry with this hash (a miner proving another model is never paid: payer.js),
|
|
10
|
+
// and a bare open priced under the 2 FLOP ceiling. The checks were made on 27 Nov 2026, the order on 28 Nov; the
|
|
11
|
+
// order is what the daily run tries first (it moves to the next one only before anything is bought).
|
|
12
|
+
import { NETWORKS } from './shared/config.js';
|
|
13
|
+
|
|
14
|
+
/** @typedef {import('./shared/config.js').Miner} Miner */
|
|
15
|
+
|
|
16
|
+
const QWEN3_8B = '0x2dc476dabd39fb86d216e04f3c50313a22fa9e5bfa65f8e236557c30ddfaba55';
|
|
17
|
+
|
|
18
|
+
/** @type {Readonly<Record<'devnet'|'testnet', readonly Miner[]>>} */
|
|
19
|
+
export const PACKAGE_MINERS = Object.freeze({
|
|
20
|
+
devnet: Object.freeze([]),
|
|
21
|
+
testnet: Object.freeze([
|
|
22
|
+
// Operator ariabrain, flop-labs/network#1651 (account and host in one post). Left out on 27 Nov (no cooperative settle
|
|
23
|
+
// in its last 50 then). FIRST since 28 Nov 15:31 UTC (read-only check): ready, escrow 0.470 FLOP, 25 cooperative settles
|
|
24
|
+
// with 11 other buyers in 24 h, last job paid; and a Try Flop paid run settled a 0.47 FLOP channel with it cooperatively
|
|
25
|
+
// the same day (0xa9c2be7f…f669, block 336,243, miner paid 0.3999 FLOP, 3 answers). antju2 is no longer listed: since
|
|
26
|
+
// 28 Nov it refuses, after the open, any escrow under its #163 fee minimum (7.94 FLOP for 4 turns), above the 2 FLOP cap.
|
|
27
|
+
Object.freeze({
|
|
28
|
+
id: 'ariabrain-m1', address: '5EZ1QVRE3gbSxupfYMreegFAgvmL4mhe5pCgHJaRUFvaZUTW', endpoint: 'https://m1.flop.ariabrain.com',
|
|
29
|
+
model: 'qwen/qwen3-8b', modelHash: QWEN3_8B, source: 'https://github.com/flop-labs/network/issues/1651', checked: '2026-11-28',
|
|
30
|
+
}),
|
|
31
|
+
// Operator erkancamli (devnet's ecamli), flop-labs/network#935: the comment that corrects the account names the host.
|
|
32
|
+
// 27 Nov 2026 16:32 UTC: ready, registered, calibrated (lease to block 794,800), escrow per batch 0.945 FLOP.
|
|
33
|
+
Object.freeze({
|
|
34
|
+
id: 'ecamli-testnet', address: '5Gjy2TuHGNkojLggYFMcXVrZvWq8hx9qt2bQKYfW9MomYWgn', endpoint: 'https://testnet.ecamliflop.fyi',
|
|
35
|
+
model: 'qwen/qwen3-8b', modelHash: QWEN3_8B, source: 'https://github.com/flop-labs/network/issues/935#issuecomment-7198236370', checked: '2026-11-27',
|
|
36
|
+
}),
|
|
37
|
+
// Operator doboongkun, flop-labs/network#1404 ("Physical 11 / tn11: 5EA9iNrZ… / m11.floptest.xyz"). 27 Nov 2026 16:32 UTC:
|
|
38
|
+
// ready, registered, calibrated (lease to block 776,529), many cooperative settles with other buyers; escrow 1.68 FLOP.
|
|
39
|
+
Object.freeze({
|
|
40
|
+
id: 'floptest-m11', address: '5EA9iNrZzNS2eAiZNQv55pA1hUYGVS8aK4ZQsfxuQcnx48ZD', endpoint: 'https://m11.floptest.xyz',
|
|
41
|
+
model: 'qwen/qwen3-8b', modelHash: QWEN3_8B, source: 'https://github.com/flop-labs/network/issues/1404', checked: '2026-11-27',
|
|
42
|
+
}),
|
|
43
|
+
// Operator 0xull, flop-labs/network#1665 (account and host in one post). 27 Nov 2026 01:32 UTC: ready, registered,
|
|
44
|
+
// calibrated, cooperative settles with other buyers; escrow 0.70 FLOP. Its connection was reset at 16:32 UTC.
|
|
45
|
+
Object.freeze({
|
|
46
|
+
id: 'ikehakinyemi', address: '5CoqW8nTc8xEWAmYmpUS1xh2qs6UiyYfDbGi4ct971zstS5e', endpoint: 'https://flop-miner.ikehakinyemi.net',
|
|
47
|
+
model: 'qwen/qwen3-8b', modelHash: QWEN3_8B, source: 'https://github.com/flop-labs/network/issues/1665', checked: '2026-11-27',
|
|
48
|
+
}),
|
|
49
|
+
]),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Every miner tryflop may pay on `network`, in the order to try them: the agent app's list first, then this package's
|
|
54
|
+
* additions it does not already have (by id or account).
|
|
55
|
+
* @param {import('./shared/config.js').NetworkConfig} network @param {Readonly<Record<string, readonly Miner[]>>} [extra]
|
|
56
|
+
* @returns {readonly Miner[]}
|
|
57
|
+
*/
|
|
58
|
+
export function minersFor(network, extra = PACKAGE_MINERS) {
|
|
59
|
+
const listed = network.miners;
|
|
60
|
+
const more = (Object.hasOwn(extra, network.name) ? extra[network.name] : []).filter((m) => !listed.some((n) => n.id === m.id || n.address === m.address));
|
|
61
|
+
return Object.freeze([...listed, ...more]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Every miner id across every network, the app's and this package's: each must name one miner. */
|
|
65
|
+
export const allMinerIds = () => [...Object.values(NETWORKS).flatMap((n) => minersFor(n).map((m) => m.id))];
|