apow-cli 0.11.18 → 0.12.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/.env.example +23 -5
- package/README.md +117 -67
- package/dist/brand-intro.js +160 -0
- package/dist/bridge/solana.js +27 -45
- package/dist/config.js +90 -5
- package/dist/dashboard-html.js +36 -43
- package/dist/dashboard.js +22 -151
- package/dist/errors.js +22 -3
- package/dist/grinder-http.js +3 -5
- package/dist/grinder-native.js +6 -5
- package/dist/index.js +540 -343
- package/dist/llm-setup.js +42 -0
- package/dist/lp-gate.js +28 -0
- package/dist/miner.js +24 -10
- package/dist/mint.js +6 -7
- package/dist/policy/audit-log.js +57 -0
- package/dist/policy/context.js +11 -0
- package/dist/policy/decode.js +84 -0
- package/dist/policy/paths.js +41 -0
- package/dist/policy/policy.js +224 -0
- package/dist/policy/spend-ledger.js +43 -0
- package/dist/preflight.js +138 -50
- package/dist/secure-env.js +65 -0
- package/dist/signer/guarded-account.js +78 -0
- package/dist/signer/local-keystore.js +40 -0
- package/dist/signer/session.js +11 -0
- package/dist/signer/types.js +2 -0
- package/dist/smhl.js +83 -10
- package/dist/stats.js +13 -1
- package/dist/sweep.js +181 -0
- package/dist/ui.js +140 -16
- package/dist/wallet-store.js +127 -31
- package/dist/wallet.js +18 -22
- package/dist/x402.js +4 -4
- package/package.json +8 -5
- package/skill.md +57 -833
package/dist/config.js
CHANGED
|
@@ -5,17 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.config = void 0;
|
|
7
7
|
exports.resolveDefaultModel = resolveDefaultModel;
|
|
8
|
+
exports.resolveKeystorePassword = resolveKeystorePassword;
|
|
8
9
|
exports.reloadConfig = reloadConfig;
|
|
9
10
|
exports.requirePrivateKey = requirePrivateKey;
|
|
10
11
|
exports.requireLlmApiKey = requireLlmApiKey;
|
|
11
12
|
exports.isExpensiveModel = isExpensiveModel;
|
|
12
13
|
exports.writeEnvFile = writeEnvFile;
|
|
13
14
|
const dotenv_1 = require("dotenv");
|
|
15
|
+
const node_child_process_1 = require("node:child_process");
|
|
14
16
|
const node_fs_1 = require("node:fs");
|
|
15
17
|
const promises_1 = require("node:fs/promises");
|
|
16
18
|
const node_os_1 = __importDefault(require("node:os"));
|
|
17
19
|
const node_path_1 = require("node:path");
|
|
18
20
|
const chains_1 = require("viem/chains");
|
|
21
|
+
const session_1 = require("./signer/session");
|
|
22
|
+
const wallet_store_1 = require("./wallet-store");
|
|
19
23
|
(0, dotenv_1.config)({ quiet: true });
|
|
20
24
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
21
25
|
const DEFAULT_OLLAMA_URL = "http://127.0.0.1:11434";
|
|
@@ -41,8 +45,9 @@ function resolveDefaultModel(provider) {
|
|
|
41
45
|
case "anthropic": return "claude-sonnet-4-5-20250929";
|
|
42
46
|
case "deepseek": return "deepseek-chat";
|
|
43
47
|
case "qwen": return "qwen-plus";
|
|
44
|
-
case "
|
|
45
|
-
case "
|
|
48
|
+
case "ollama": return "llama3.1";
|
|
49
|
+
case "claude-code": return "haiku";
|
|
50
|
+
case "codex": return "gpt-5.6-luna";
|
|
46
51
|
default: return "gpt-4o-mini";
|
|
47
52
|
}
|
|
48
53
|
}
|
|
@@ -58,7 +63,7 @@ function resolveChainName() {
|
|
|
58
63
|
return DEFAULT_CHAIN_NAME;
|
|
59
64
|
}
|
|
60
65
|
function parsePrivateKey(value) {
|
|
61
|
-
if (!value) {
|
|
66
|
+
if (!value?.trim()) {
|
|
62
67
|
return undefined;
|
|
63
68
|
}
|
|
64
69
|
if (!/^0x[0-9a-fA-F]{64}$/.test(value)) {
|
|
@@ -66,6 +71,73 @@ function parsePrivateKey(value) {
|
|
|
66
71
|
}
|
|
67
72
|
return value;
|
|
68
73
|
}
|
|
74
|
+
function resolveKeystorePassword() {
|
|
75
|
+
const sessionPassword = (0, session_1.getSessionPassword)();
|
|
76
|
+
if (sessionPassword)
|
|
77
|
+
return sessionPassword;
|
|
78
|
+
const envPassword = process.env.KEYSTORE_PASSWORD?.trim()
|
|
79
|
+
|| process.env.APOW_KEYSTORE_PASSWORD?.trim();
|
|
80
|
+
if (envPassword)
|
|
81
|
+
return envPassword;
|
|
82
|
+
const command = process.env.KEYSTORE_PASSWORD_CMD?.trim()
|
|
83
|
+
|| process.env.APOW_KEYSTORE_PASSWORD_CMD?.trim();
|
|
84
|
+
if (command) {
|
|
85
|
+
const result = (0, node_child_process_1.spawnSync)(command, {
|
|
86
|
+
shell: true,
|
|
87
|
+
encoding: "utf8",
|
|
88
|
+
timeout: 10_000,
|
|
89
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
90
|
+
});
|
|
91
|
+
if (result.status === 0 && result.stdout.trim()) {
|
|
92
|
+
return result.stdout.trim();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return process.env.KEYSTORE_PASSWORD?.trim()
|
|
96
|
+
|| process.env.APOW_KEYSTORE_PASSWORD?.trim()
|
|
97
|
+
|| "";
|
|
98
|
+
}
|
|
99
|
+
function getConfiguredKeystorePath() {
|
|
100
|
+
const value = process.env.KEYSTORE_PATH
|
|
101
|
+
|| process.env.WALLET_KEYSTORE_PATH
|
|
102
|
+
|| process.env.APOW_KEYSTORE_PATH;
|
|
103
|
+
if (!value?.trim()) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return (0, wallet_store_1.resolveKeystorePath)(value.trim());
|
|
107
|
+
}
|
|
108
|
+
function resolveWalletConfig() {
|
|
109
|
+
const legacyPrivateKey = parsePrivateKey(process.env.PRIVATE_KEY);
|
|
110
|
+
const keystorePath = getConfiguredKeystorePath();
|
|
111
|
+
if (legacyPrivateKey) {
|
|
112
|
+
return {
|
|
113
|
+
privateKey: legacyPrivateKey,
|
|
114
|
+
keystorePath,
|
|
115
|
+
walletSource: "private-key",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (!keystorePath) {
|
|
119
|
+
return { walletSource: "none" };
|
|
120
|
+
}
|
|
121
|
+
const password = resolveKeystorePassword();
|
|
122
|
+
if (!password) {
|
|
123
|
+
return {
|
|
124
|
+
keystorePath,
|
|
125
|
+
walletSource: "keystore",
|
|
126
|
+
walletLoadError: "Encrypted keystore is configured but locked. Set KEYSTORE_PASSWORD in your shell or run an interactive command to unlock it.",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return {
|
|
131
|
+
privateKey: (0, wallet_store_1.loadEncryptedKeystoreFile)(keystorePath, password),
|
|
132
|
+
keystorePath,
|
|
133
|
+
walletSource: "keystore",
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
138
|
+
throw new Error(`Could not unlock KEYSTORE_PATH (${keystorePath}): ${message}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
69
141
|
function parseAddress(envKey, fallback) {
|
|
70
142
|
const value = process.env[envKey];
|
|
71
143
|
if (value && /^0x[0-9a-fA-F]{40}$/.test(value)) {
|
|
@@ -105,12 +177,16 @@ function buildConfig() {
|
|
|
105
177
|
const chainName = resolveChainName();
|
|
106
178
|
const useX402 = process.env.USE_X402 === "true";
|
|
107
179
|
const resolvedProvider = normalizeProvider(process.env.LLM_PROVIDER, useX402);
|
|
180
|
+
const walletConfig = resolveWalletConfig();
|
|
108
181
|
const useX402Grind = process.env.USE_X402_GRIND !== undefined
|
|
109
182
|
? process.env.USE_X402_GRIND === "true"
|
|
110
183
|
: useX402;
|
|
111
184
|
const allowLocalFallbackWithX402 = process.env.ALLOW_LOCAL_FALLBACK_WITH_X402 === "true";
|
|
112
185
|
return {
|
|
113
|
-
privateKey:
|
|
186
|
+
privateKey: walletConfig.privateKey,
|
|
187
|
+
keystorePath: walletConfig.keystorePath,
|
|
188
|
+
walletSource: walletConfig.walletSource,
|
|
189
|
+
walletLoadError: walletConfig.walletLoadError,
|
|
114
190
|
rpcUrl: process.env.RPC_URL ?? "",
|
|
115
191
|
useX402,
|
|
116
192
|
llmProvider: resolvedProvider,
|
|
@@ -143,7 +219,7 @@ function reloadConfig() {
|
|
|
143
219
|
}
|
|
144
220
|
function requirePrivateKey() {
|
|
145
221
|
if (!exports.config.privateKey) {
|
|
146
|
-
throw new Error("
|
|
222
|
+
throw new Error("An unlocked wallet signer is required. Configure KEYSTORE_PATH and unlock it with KEYSTORE_PASSWORD.");
|
|
147
223
|
}
|
|
148
224
|
return exports.config.privateKey;
|
|
149
225
|
}
|
|
@@ -165,6 +241,14 @@ function isExpensiveModel(model) {
|
|
|
165
241
|
return EXPENSIVE_MODELS.some((e) => m.startsWith(e));
|
|
166
242
|
}
|
|
167
243
|
async function writeEnvFile(values) {
|
|
244
|
+
for (const [key, value] of Object.entries(values)) {
|
|
245
|
+
if (/KEYSTORE_PASSWORD/i.test(key)) {
|
|
246
|
+
throw new Error(`${key} must not be written to .env. Use KEYSTORE_PASSWORD_CMD or a shell secret manager.`);
|
|
247
|
+
}
|
|
248
|
+
if (key === "PRIVATE_KEY" && value.trim()) {
|
|
249
|
+
throw new Error("PRIVATE_KEY must not be written to .env. Use an encrypted keystore.");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
168
252
|
const envPath = (0, node_path_1.join)(process.cwd(), ".env");
|
|
169
253
|
const preserved = [];
|
|
170
254
|
if ((0, node_fs_1.existsSync)(envPath)) {
|
|
@@ -173,6 +257,7 @@ async function writeEnvFile(values) {
|
|
|
173
257
|
for (const line of existingContent.split(/\r?\n/)) {
|
|
174
258
|
const trimmed = line.trim();
|
|
175
259
|
if (!trimmed || trimmed.startsWith("#")) {
|
|
260
|
+
preserved.push(line);
|
|
176
261
|
continue;
|
|
177
262
|
}
|
|
178
263
|
const eq = line.indexOf("=");
|
package/dist/dashboard-html.js
CHANGED
|
@@ -21,9 +21,13 @@ body{background:var(--bg);color:var(--text);font-family:SFMono-Regular,'SF Mono'
|
|
|
21
21
|
a{color:inherit;text-decoration:none}
|
|
22
22
|
.container{min-height:100vh;padding:12px}
|
|
23
23
|
/* Header */
|
|
24
|
-
.header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
|
|
24
|
+
.header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;gap:12px}
|
|
25
25
|
.header h1{font-size:14px;font-weight:700;letter-spacing:.05em}
|
|
26
|
-
.
|
|
26
|
+
.header-actions{display:flex;align-items:center;gap:10px}
|
|
27
|
+
.refresh-btn{border:1px solid var(--card-border);border-radius:4px;background:var(--card);color:var(--text);font:inherit;font-size:11px;padding:4px 10px;cursor:pointer;transition:all .15s}
|
|
28
|
+
.refresh-btn:hover:not(:disabled){border-color:var(--accent);color:var(--accent)}
|
|
29
|
+
.refresh-btn:disabled{cursor:not-allowed;opacity:.45}
|
|
30
|
+
.status{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--text-dim);white-space:nowrap}
|
|
27
31
|
.pulse{display:inline-block;height:6px;width:6px;border-radius:50%;background:var(--accent);animation:pulse 1.5s infinite}
|
|
28
32
|
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}
|
|
29
33
|
/* Banners */
|
|
@@ -32,10 +36,6 @@ a{color:inherit;text-decoration:none}
|
|
|
32
36
|
.rpc-warning a:hover{color:#fed7aa}
|
|
33
37
|
.error-banner{border-radius:6px;border:1px solid #7f1d1d;background:rgba(69,10,10,.3);padding:8px 12px;font-size:12px;color:#f87171;margin-bottom:12px}
|
|
34
38
|
/* Fleet tabs */
|
|
35
|
-
.fleet-tabs{display:flex;align-items:center;gap:4px;margin-bottom:12px;overflow-x:auto}
|
|
36
|
-
.fleet-tab{padding:4px 12px;font-size:12px;border-radius:4px;cursor:pointer;white-space:nowrap;border:1px solid transparent;background:var(--card);color:var(--text-dim);transition:all .15s}
|
|
37
|
-
.fleet-tab:hover{color:var(--text)}
|
|
38
|
-
.fleet-tab.active{background:var(--accent);color:#fff;border-color:var(--accent)}
|
|
39
39
|
/* Stats grid */
|
|
40
40
|
.stats-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:1px;background:var(--card-border);border-radius:8px;overflow:hidden;margin-bottom:12px}
|
|
41
41
|
@media(min-width:640px){.stats-grid{grid-template-columns:repeat(5,1fr)}}
|
|
@@ -81,30 +81,30 @@ a{color:inherit;text-decoration:none}
|
|
|
81
81
|
<div class="container">
|
|
82
82
|
<div class="header">
|
|
83
83
|
<h1>APoW DASHBOARD</h1>
|
|
84
|
-
<div class="
|
|
84
|
+
<div class="header-actions">
|
|
85
|
+
<button class="refresh-btn" id="refreshBtn" type="button">Refresh</button>
|
|
86
|
+
<div class="status"><span class="pulse" id="statusDot"></span><span id="statusText">Loading...</span></div>
|
|
87
|
+
</div>
|
|
85
88
|
</div>
|
|
86
89
|
<div id="rpcWarning" class="rpc-warning" style="display:none">
|
|
87
90
|
Set <code>RPC_URL</code> in your <code>.env</code> for reliable dashboard refreshes.
|
|
88
|
-
A dedicated Base RPC is recommended
|
|
91
|
+
A dedicated Base RPC is recommended.
|
|
89
92
|
</div>
|
|
90
93
|
<div id="errorBanner" class="error-banner" style="display:none">Failed to fetch data. Check RPC connection.</div>
|
|
91
|
-
<div id="fleetTabs" class="fleet-tabs" style="display:none"></div>
|
|
92
94
|
<div id="statsGrid" class="stats-grid" style="display:none"></div>
|
|
93
95
|
<div id="walletGrid" class="wallet-grid"></div>
|
|
94
96
|
<div id="emptyState" class="empty-state" style="display:none">
|
|
95
|
-
<h2>No wallets
|
|
96
|
-
<p>
|
|
97
|
+
<h2>No locally generated APoW wallets.</h2>
|
|
98
|
+
<p>Create one with:</p>
|
|
97
99
|
<div class="cmds">
|
|
98
|
-
<div><code>apow
|
|
99
|
-
<div><code>apow dashboard scan</code> <span>— auto-detect from wallet files in current dir</span></div>
|
|
100
|
+
<div><code>apow wallet new</code></div>
|
|
100
101
|
</div>
|
|
101
|
-
<p class="hint">
|
|
102
|
+
<p class="hint">The dashboard intentionally ignores imported wallets and filesystem wallet files.</p>
|
|
102
103
|
</div>
|
|
103
104
|
<div id="loading" class="loading">Loading...</div>
|
|
104
105
|
</div>
|
|
105
106
|
<script>
|
|
106
107
|
(function(){
|
|
107
|
-
var activeFleet = 'All';
|
|
108
108
|
var balanceHistory = [];
|
|
109
109
|
var prevMines = {};
|
|
110
110
|
var activeWallets = {};
|
|
@@ -181,27 +181,6 @@ a{color:inherit;text-decoration:none}
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
function renderFleetTabs(fleets) {
|
|
185
|
-
var el = document.getElementById('fleetTabs');
|
|
186
|
-
if (!fleets || fleets.length <= 1) { el.style.display = 'none'; return; }
|
|
187
|
-
el.style.display = 'flex';
|
|
188
|
-
var totalCount = 0;
|
|
189
|
-
for (var i = 0; i < fleets.length; i++) totalCount += fleets[i].walletCount;
|
|
190
|
-
var html = '<div class="fleet-tab' + (activeFleet === 'All' ? ' active' : '') + '" data-fleet="All">All (' + totalCount + ')</div>';
|
|
191
|
-
for (var i = 0; i < fleets.length; i++) {
|
|
192
|
-
var f = fleets[i];
|
|
193
|
-
html += '<div class="fleet-tab' + (activeFleet === f.name ? ' active' : '') + '" data-fleet="' + escapeHtml(f.name) + '">' + escapeHtml(f.name) + ' (' + f.walletCount + ')</div>';
|
|
194
|
-
}
|
|
195
|
-
el.innerHTML = html;
|
|
196
|
-
var tabs = el.querySelectorAll('.fleet-tab');
|
|
197
|
-
for (var t = 0; t < tabs.length; t++) {
|
|
198
|
-
tabs[t].addEventListener('click', function() {
|
|
199
|
-
activeFleet = this.getAttribute('data-fleet');
|
|
200
|
-
refresh();
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
184
|
function renderStats(wallets, network) {
|
|
206
185
|
var el = document.getElementById('statsGrid');
|
|
207
186
|
if (!wallets && !network) { el.style.display = 'none'; return; }
|
|
@@ -287,23 +266,35 @@ a{color:inherit;text-decoration:none}
|
|
|
287
266
|
var networkData = null;
|
|
288
267
|
var walletsData = null;
|
|
289
268
|
var hasError = false;
|
|
269
|
+
var isRefreshing = false;
|
|
290
270
|
|
|
291
271
|
function setStatus(refreshing) {
|
|
272
|
+
var btn = document.getElementById('refreshBtn');
|
|
292
273
|
document.getElementById('statusDot').style.display = refreshing ? 'inline-block' : 'none';
|
|
293
|
-
document.getElementById('statusText').textContent = refreshing ? 'Refreshing...' : '
|
|
274
|
+
document.getElementById('statusText').textContent = refreshing ? 'Refreshing...' : 'Manual';
|
|
275
|
+
if (btn) {
|
|
276
|
+
btn.disabled = refreshing;
|
|
277
|
+
btn.textContent = refreshing ? 'Refreshing...' : 'Refresh';
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function setReadyStatus() {
|
|
282
|
+
var now = new Date();
|
|
283
|
+
var ts = now.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
284
|
+
document.getElementById('statusText').textContent = 'Updated ' + ts;
|
|
294
285
|
}
|
|
295
286
|
|
|
296
287
|
function refresh() {
|
|
288
|
+
if (isRefreshing) return;
|
|
289
|
+
isRefreshing = true;
|
|
297
290
|
setStatus(true);
|
|
298
|
-
var fleetParam = encodeURIComponent(activeFleet);
|
|
299
291
|
Promise.all([
|
|
300
292
|
fetchJson('/api/network').catch(function(e) { return null; }),
|
|
301
|
-
fetchJson('/api/wallets
|
|
302
|
-
fetchJson('/api/fleets').catch(function(e) { return null; }),
|
|
293
|
+
fetchJson('/api/wallets').catch(function(e) { return null; }),
|
|
303
294
|
fetchJson('/api/config').catch(function(e) { return null; })
|
|
304
295
|
]).then(function(results) {
|
|
305
296
|
document.getElementById('loading').style.display = 'none';
|
|
306
|
-
var net = results[0], wal = results[1],
|
|
297
|
+
var net = results[0], wal = results[1], cfg = results[2];
|
|
307
298
|
hasError = !net && !wal;
|
|
308
299
|
document.getElementById('errorBanner').style.display = hasError ? 'block' : 'none';
|
|
309
300
|
if (net) networkData = net;
|
|
@@ -314,19 +305,21 @@ a{color:inherit;text-decoration:none}
|
|
|
314
305
|
if (cfg) {
|
|
315
306
|
document.getElementById('rpcWarning').style.display = cfg.rpcIsDefault ? 'block' : 'none';
|
|
316
307
|
}
|
|
317
|
-
renderFleetTabs(fleets);
|
|
318
308
|
renderStats(walletsData, networkData);
|
|
319
309
|
renderWallets(walletsData);
|
|
310
|
+
isRefreshing = false;
|
|
320
311
|
setStatus(false);
|
|
312
|
+
setReadyStatus();
|
|
321
313
|
}).catch(function() {
|
|
322
314
|
document.getElementById('loading').style.display = 'none';
|
|
323
315
|
document.getElementById('errorBanner').style.display = 'block';
|
|
316
|
+
isRefreshing = false;
|
|
324
317
|
setStatus(false);
|
|
325
318
|
});
|
|
326
319
|
}
|
|
327
320
|
|
|
321
|
+
document.getElementById('refreshBtn').addEventListener('click', refresh);
|
|
328
322
|
refresh();
|
|
329
|
-
setInterval(refresh, 30000);
|
|
330
323
|
})();
|
|
331
324
|
</script>
|
|
332
325
|
</body>
|
package/dist/dashboard.js
CHANGED
|
@@ -38,13 +38,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.startDashboardServer = startDashboardServer;
|
|
40
40
|
const http = __importStar(require("node:http"));
|
|
41
|
-
const node_fs_1 = require("node:fs");
|
|
42
|
-
const node_path_1 = require("node:path");
|
|
43
41
|
const viem_1 = require("viem");
|
|
44
42
|
const chains_1 = require("viem/chains");
|
|
45
43
|
const dashboard_html_1 = require("./dashboard-html");
|
|
46
|
-
const x402_1 = require("./x402");
|
|
47
44
|
const wallet_store_1 = require("./wallet-store");
|
|
45
|
+
const x402_1 = require("./x402");
|
|
48
46
|
const AgentCoin_json_1 = __importDefault(require("./abi/AgentCoin.json"));
|
|
49
47
|
const MiningAgent_json_1 = __importDefault(require("./abi/MiningAgent.json"));
|
|
50
48
|
const AgentCoinAbi = AgentCoin_json_1.default;
|
|
@@ -52,127 +50,14 @@ const MiningAgentAbi = MiningAgent_json_1.default;
|
|
|
52
50
|
const RARITY_LABELS = ["Common", "Uncommon", "Rare", "Epic", "Mythic"];
|
|
53
51
|
const ADDR_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
54
52
|
const DEFAULT_RPC = ""; // No default public RPC — user must set RPC_URL or USE_X402
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
function extractArray(path) {
|
|
61
|
-
const raw = (0, node_fs_1.readFileSync)(path, "utf8");
|
|
62
|
-
const data = JSON.parse(raw);
|
|
63
|
-
if (!Array.isArray(data))
|
|
64
|
-
return [];
|
|
65
|
-
return data.filter((a) => typeof a === "string" && isAddress(a));
|
|
66
|
-
}
|
|
67
|
-
function extractSolkek(path) {
|
|
68
|
-
const raw = (0, node_fs_1.readFileSync)(path, "utf8");
|
|
69
|
-
const data = JSON.parse(raw);
|
|
70
|
-
const addrs = [];
|
|
71
|
-
if (data.master?.address && isAddress(data.master.address)) {
|
|
72
|
-
addrs.push(data.master.address);
|
|
73
|
-
}
|
|
74
|
-
if (Array.isArray(data.miners)) {
|
|
75
|
-
for (const m of data.miners) {
|
|
76
|
-
if (m.address && isAddress(m.address)) {
|
|
77
|
-
addrs.push(m.address);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return addrs;
|
|
82
|
-
}
|
|
83
|
-
function extractRigdirs(dir) {
|
|
84
|
-
const addrs = [];
|
|
85
|
-
const entries = (0, node_fs_1.readdirSync)(dir, { withFileTypes: true });
|
|
86
|
-
for (const entry of entries) {
|
|
87
|
-
if (!entry.isDirectory() || !entry.name.startsWith("rig"))
|
|
88
|
-
continue;
|
|
89
|
-
const rigFiles = (0, node_fs_1.readdirSync)((0, node_path_1.join)(dir, entry.name));
|
|
90
|
-
for (const file of rigFiles) {
|
|
91
|
-
const address = (0, wallet_store_1.detectWalletAddressFromFilename)(file);
|
|
92
|
-
if (address && isAddress(address)) {
|
|
93
|
-
addrs.push(address);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return addrs;
|
|
98
|
-
}
|
|
99
|
-
function extractWalletfiles(dir) {
|
|
100
|
-
const addrs = [];
|
|
101
|
-
const files = (0, node_fs_1.readdirSync)(dir);
|
|
102
|
-
for (const file of files) {
|
|
103
|
-
const address = (0, wallet_store_1.detectWalletAddressFromFilename)(file);
|
|
104
|
-
if (address && isAddress(address)) {
|
|
105
|
-
addrs.push(address);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return addrs;
|
|
109
|
-
}
|
|
110
|
-
function getFleets(walletsPath) {
|
|
111
|
-
try {
|
|
112
|
-
const raw = (0, node_fs_1.readFileSync)(FLEETS_PATH, "utf8");
|
|
113
|
-
const configs = JSON.parse(raw);
|
|
114
|
-
return configs.map((cfg) => {
|
|
115
|
-
let addresses = [];
|
|
116
|
-
try {
|
|
117
|
-
switch (cfg.type) {
|
|
118
|
-
case "array":
|
|
119
|
-
addresses = extractArray(cfg.path);
|
|
120
|
-
break;
|
|
121
|
-
case "solkek":
|
|
122
|
-
addresses = extractSolkek(cfg.path);
|
|
123
|
-
break;
|
|
124
|
-
case "rigdirs":
|
|
125
|
-
addresses = extractRigdirs(cfg.path);
|
|
126
|
-
break;
|
|
127
|
-
case "walletfiles":
|
|
128
|
-
addresses = extractWalletfiles(cfg.path);
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
// Skip broken fleet sources silently
|
|
134
|
-
}
|
|
135
|
-
return { name: cfg.name, addresses };
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
return [{ name: "Main", addresses: getWalletAddresses(walletsPath) }];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function getWalletAddresses(walletsPath) {
|
|
143
|
-
try {
|
|
144
|
-
const raw = (0, node_fs_1.readFileSync)(walletsPath, "utf8");
|
|
145
|
-
const data = JSON.parse(raw);
|
|
146
|
-
if (Array.isArray(data)) {
|
|
147
|
-
return data.filter((addr) => typeof addr === "string" && ADDR_RE.test(addr));
|
|
148
|
-
}
|
|
149
|
-
return [];
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
return [];
|
|
153
|
-
}
|
|
53
|
+
// --- Wallet loading ---
|
|
54
|
+
function normalizeAddress(s) {
|
|
55
|
+
if (!ADDR_RE.test(s))
|
|
56
|
+
return null;
|
|
57
|
+
return (0, viem_1.getAddress)(s.toLowerCase());
|
|
154
58
|
}
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
const fleets = getFleets(walletsPath);
|
|
158
|
-
const seen = new Set();
|
|
159
|
-
const all = [];
|
|
160
|
-
for (const f of fleets) {
|
|
161
|
-
for (const addr of f.addresses) {
|
|
162
|
-
const lower = addr.toLowerCase();
|
|
163
|
-
if (!seen.has(lower)) {
|
|
164
|
-
seen.add(lower);
|
|
165
|
-
all.push(addr);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return all;
|
|
170
|
-
}
|
|
171
|
-
const fleets = getFleets(walletsPath);
|
|
172
|
-
const fleet = fleets.find((f) => f.name === fleetName);
|
|
173
|
-
if (fleet)
|
|
174
|
-
return fleet.addresses;
|
|
175
|
-
return getWalletAddresses(walletsPath);
|
|
59
|
+
function getWalletAddresses() {
|
|
60
|
+
return (0, wallet_store_1.loadGeneratedWalletAddresses)().flatMap((address) => normalizeAddress(address) ?? []);
|
|
176
61
|
}
|
|
177
62
|
// --- Art parsing ---
|
|
178
63
|
function parseArtFromTokenUri(raw) {
|
|
@@ -188,9 +73,9 @@ function parseArtFromTokenUri(raw) {
|
|
|
188
73
|
}
|
|
189
74
|
// --- Server ---
|
|
190
75
|
function startDashboardServer(opts) {
|
|
191
|
-
const { port,
|
|
192
|
-
const transport = useX402 &&
|
|
193
|
-
? (0, x402_1.createX402Transport)(
|
|
76
|
+
const { port, rpcUrl, useX402, signer, miningAgentAddress, agentCoinAddress } = opts;
|
|
77
|
+
const transport = useX402 && signer
|
|
78
|
+
? (0, x402_1.createX402Transport)(signer)
|
|
194
79
|
: (0, viem_1.http)(rpcUrl);
|
|
195
80
|
const publicClient = (0, viem_1.createPublicClient)({
|
|
196
81
|
chain: chains_1.base,
|
|
@@ -198,16 +83,16 @@ function startDashboardServer(opts) {
|
|
|
198
83
|
});
|
|
199
84
|
const artCache = new Map();
|
|
200
85
|
const htmlPage = (0, dashboard_html_1.getDashboardHtml)();
|
|
201
|
-
// Response cache with TTL
|
|
86
|
+
// Response cache with TTL. Manual refreshes wait for fresh stale data instead of
|
|
87
|
+
// returning old values and silently updating after the UI has already rendered.
|
|
202
88
|
const responseCache = new Map();
|
|
203
89
|
const pendingFetches = new Map();
|
|
204
|
-
const CACHE_TTL = 25_000;
|
|
90
|
+
const CACHE_TTL = 25_000;
|
|
205
91
|
async function cachedHandler(key, handler) {
|
|
206
92
|
const cached = responseCache.get(key);
|
|
207
93
|
const now = Date.now();
|
|
208
94
|
const isStale = !cached || (now - cached.ts > CACHE_TTL);
|
|
209
95
|
if (isStale && !pendingFetches.has(key)) {
|
|
210
|
-
// Fetch fresh data (non-blocking if we have stale data to return)
|
|
211
96
|
const fetchPromise = handler()
|
|
212
97
|
.then((result) => {
|
|
213
98
|
responseCache.set(key, { data: result, ts: Date.now() });
|
|
@@ -221,15 +106,12 @@ function startDashboardServer(opts) {
|
|
|
221
106
|
throw err;
|
|
222
107
|
});
|
|
223
108
|
pendingFetches.set(key, fetchPromise);
|
|
224
|
-
// No cached data yet — must wait for first fetch
|
|
225
|
-
if (!cached)
|
|
226
|
-
return fetchPromise;
|
|
227
109
|
}
|
|
228
|
-
//
|
|
229
|
-
|
|
110
|
+
// Stale manual refreshes should wait for the in-flight read so the button
|
|
111
|
+
// actually returns current balances.
|
|
112
|
+
if (isStale && pendingFetches.has(key)) {
|
|
230
113
|
return pendingFetches.get(key);
|
|
231
114
|
}
|
|
232
|
-
// Return cached data immediately (even if stale — background refresh handles it)
|
|
233
115
|
return cached ? cached.data : "{}";
|
|
234
116
|
}
|
|
235
117
|
const MULTICALL_CHUNK = 30; // max calls per multicall batch
|
|
@@ -252,8 +134,8 @@ function startDashboardServer(opts) {
|
|
|
252
134
|
}
|
|
253
135
|
return results;
|
|
254
136
|
}
|
|
255
|
-
async function handleWallets(
|
|
256
|
-
const addresses =
|
|
137
|
+
async function handleWallets() {
|
|
138
|
+
const addresses = getWalletAddresses();
|
|
257
139
|
if (addresses.length === 0)
|
|
258
140
|
return "[]";
|
|
259
141
|
// Phase 1: ETH balance + AGENT balance + NFT count (chunked)
|
|
@@ -423,13 +305,9 @@ function startDashboardServer(opts) {
|
|
|
423
305
|
supplyPct,
|
|
424
306
|
});
|
|
425
307
|
}
|
|
426
|
-
function handleFleets() {
|
|
427
|
-
const fleets = getFleets(walletsPath);
|
|
428
|
-
return JSON.stringify(fleets.map((f) => ({ name: f.name, walletCount: f.addresses.length })));
|
|
429
|
-
}
|
|
430
308
|
function handleConfig() {
|
|
431
309
|
const rpcIsDefault = !useX402 && rpcUrl === DEFAULT_RPC;
|
|
432
|
-
const walletCount = getWalletAddresses(
|
|
310
|
+
const walletCount = getWalletAddresses().length;
|
|
433
311
|
return JSON.stringify({ rpcIsDefault, walletCount });
|
|
434
312
|
}
|
|
435
313
|
function jsonResponse(res, body, status = 200) {
|
|
@@ -449,9 +327,7 @@ function startDashboardServer(opts) {
|
|
|
449
327
|
return;
|
|
450
328
|
}
|
|
451
329
|
if (pathname === "/api/wallets") {
|
|
452
|
-
const
|
|
453
|
-
const cacheKey = `wallets:${fleet ?? "All"}`;
|
|
454
|
-
const body = await cachedHandler(cacheKey, () => handleWallets(fleet));
|
|
330
|
+
const body = await cachedHandler("wallets", () => handleWallets());
|
|
455
331
|
jsonResponse(res, body);
|
|
456
332
|
return;
|
|
457
333
|
}
|
|
@@ -460,11 +336,6 @@ function startDashboardServer(opts) {
|
|
|
460
336
|
jsonResponse(res, body);
|
|
461
337
|
return;
|
|
462
338
|
}
|
|
463
|
-
if (pathname === "/api/fleets") {
|
|
464
|
-
const body = handleFleets();
|
|
465
|
-
jsonResponse(res, body);
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
339
|
if (pathname === "/api/config") {
|
|
469
340
|
const body = handleConfig();
|
|
470
341
|
jsonResponse(res, body);
|
|
@@ -478,6 +349,6 @@ function startDashboardServer(opts) {
|
|
|
478
349
|
errorResponse(res, message);
|
|
479
350
|
}
|
|
480
351
|
});
|
|
481
|
-
server.listen(port);
|
|
352
|
+
server.listen(port, "127.0.0.1");
|
|
482
353
|
return server;
|
|
483
354
|
}
|
package/dist/errors.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactUrls = redactUrls;
|
|
4
|
+
exports.errorText = errorText;
|
|
3
5
|
exports.classifyError = classifyError;
|
|
4
6
|
const patterns = [
|
|
7
|
+
{
|
|
8
|
+
test: (m) => m.includes("Policy denied:"),
|
|
9
|
+
classify: (msg) => ({
|
|
10
|
+
category: "setup",
|
|
11
|
+
userMessage: msg,
|
|
12
|
+
recovery: "Review `apow policy show`, set a payout if needed, or temporarily use `APOW_POLICY=warn` while debugging.",
|
|
13
|
+
}),
|
|
14
|
+
},
|
|
5
15
|
{
|
|
6
16
|
test: (m) => m.includes("Not your miner"),
|
|
7
17
|
classify: () => ({
|
|
@@ -153,7 +163,7 @@ const patterns = [
|
|
|
153
163
|
test: (m) => m.includes("EADDRINUSE") && m.includes("8402"),
|
|
154
164
|
classify: () => ({
|
|
155
165
|
category: "setup",
|
|
156
|
-
userMessage: "
|
|
166
|
+
userMessage: "The local x402 LLM service port 8402 is already in use",
|
|
157
167
|
recovery: "Set CLAWROUTER_PORT in .env to use a different port",
|
|
158
168
|
}),
|
|
159
169
|
},
|
|
@@ -161,7 +171,7 @@ const patterns = [
|
|
|
161
171
|
test: (m) => m.toLowerCase().includes("insufficient") && m.toLowerCase().includes("clawrouter"),
|
|
162
172
|
classify: () => ({
|
|
163
173
|
category: "setup",
|
|
164
|
-
userMessage: "Insufficient USDC for
|
|
174
|
+
userMessage: "Insufficient USDC for the x402 LLM payment",
|
|
165
175
|
recovery: "Send USDC to your wallet on Base",
|
|
166
176
|
}),
|
|
167
177
|
},
|
|
@@ -214,8 +224,17 @@ const patterns = [
|
|
|
214
224
|
}),
|
|
215
225
|
},
|
|
216
226
|
];
|
|
227
|
+
// Keyed RPC endpoints embed credentials in the URL path. Keep scheme+host so
|
|
228
|
+
// errors stay debuggable, drop everything after — terminal output may be
|
|
229
|
+
// public (streams, logs, screenshots).
|
|
230
|
+
function redactUrls(text) {
|
|
231
|
+
return text.replace(/(https?:\/\/[^/\s"']+)[^\s"')]*/g, "$1/…");
|
|
232
|
+
}
|
|
233
|
+
function errorText(error) {
|
|
234
|
+
return redactUrls(error instanceof Error ? error.message : String(error));
|
|
235
|
+
}
|
|
217
236
|
function classifyError(error) {
|
|
218
|
-
const message =
|
|
237
|
+
const message = errorText(error);
|
|
219
238
|
for (const pattern of patterns) {
|
|
220
239
|
if (pattern.test(message)) {
|
|
221
240
|
return pattern.classify(message);
|
package/dist/grinder-http.js
CHANGED
|
@@ -73,13 +73,11 @@ function extractErrorDetail(body) {
|
|
|
73
73
|
}
|
|
74
74
|
return body.trim();
|
|
75
75
|
}
|
|
76
|
-
async function getPaymentFetch(
|
|
76
|
+
async function getPaymentFetch(signer) {
|
|
77
77
|
if (_fetchWithPayment)
|
|
78
78
|
return _fetchWithPayment;
|
|
79
|
-
const { privateKeyToAccount } = await Promise.resolve().then(() => __importStar(require("viem/accounts")));
|
|
80
79
|
const { x402Client, wrapFetchWithPayment } = await Promise.resolve().then(() => __importStar(require("@x402/fetch")));
|
|
81
80
|
const { registerExactEvmScheme } = await Promise.resolve().then(() => __importStar(require("@x402/evm/exact/client")));
|
|
82
|
-
const signer = privateKeyToAccount(privateKey);
|
|
83
81
|
const client = new x402Client();
|
|
84
82
|
registerExactEvmScheme(client, { signer });
|
|
85
83
|
_fetchWithPayment = wrapFetchWithPayment(fetch, client);
|
|
@@ -91,7 +89,7 @@ function isHttpGrinderConfigured() {
|
|
|
91
89
|
function getGrindUrl() {
|
|
92
90
|
return config_1.config.grindUrl ?? DEFAULT_GRIND_URL;
|
|
93
91
|
}
|
|
94
|
-
async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl,
|
|
92
|
+
async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, signer, signal) {
|
|
95
93
|
const start = process.hrtime();
|
|
96
94
|
const timeoutSignal = AbortSignal.timeout(GRIND_HTTP_TIMEOUT_MS);
|
|
97
95
|
const requestSignal = signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
|
|
@@ -107,7 +105,7 @@ async function grindNonceHttp(challengeNumber, target, minerAddress, grindUrl, p
|
|
|
107
105
|
};
|
|
108
106
|
let response = null;
|
|
109
107
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
110
|
-
const paidFetch = await getPaymentFetch(
|
|
108
|
+
const paidFetch = await getPaymentFetch(signer);
|
|
111
109
|
try {
|
|
112
110
|
response = await paidFetch(grindUrl, requestInit);
|
|
113
111
|
}
|