apow-cli 0.9.0 → 0.9.1
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 +8 -6
- package/dist/clawrouter.js +96 -0
- package/dist/config.js +3 -3
- package/dist/errors.js +16 -0
- package/dist/grinder-native.js +15 -1
- package/dist/grinder.js +14 -0
- package/dist/index.js +21 -5
- package/dist/miner.js +77 -29
- package/dist/preflight.js +17 -2
- package/dist/smhl.js +56 -0
- package/package.json +3 -2
- package/skill.md +46 -29
package/.env.example
CHANGED
|
@@ -7,12 +7,14 @@ RPC_URL=
|
|
|
7
7
|
# Option 2: Auto-pay via QuickNode x402 ($10 USDC for ~1M calls, no API key needed)
|
|
8
8
|
# USE_X402=true
|
|
9
9
|
|
|
10
|
-
# LLM Provider (openai / anthropic / gemini / ollama / claude-code / codex)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
#
|
|
15
|
-
|
|
10
|
+
# LLM Provider (clawrouter / openai / anthropic / gemini / ollama / claude-code / codex)
|
|
11
|
+
# clawrouter (recommended): Zero credentials. Pays with USDC from your wallet via x402.
|
|
12
|
+
LLM_PROVIDER=clawrouter
|
|
13
|
+
LLM_MODEL=blockrun/eco
|
|
14
|
+
# CLAWROUTER_PORT=8402 # only if default port is in use
|
|
15
|
+
|
|
16
|
+
# API key (not needed for clawrouter, ollama, claude-code, or codex)
|
|
17
|
+
# LLM_API_KEY=
|
|
16
18
|
|
|
17
19
|
# Provider-specific keys (alternative to LLM_API_KEY)
|
|
18
20
|
# OPENAI_API_KEY=
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ClawRouter x402 LLM proxy lifecycle.
|
|
4
|
+
*
|
|
5
|
+
* Manages an in-process ClawRouter proxy that routes LLM calls through x402,
|
|
6
|
+
* paying for inference with USDC from the agent's existing wallet.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.isClawRouterRunning = isClawRouterRunning;
|
|
43
|
+
exports.getClawRouterBaseUrl = getClawRouterBaseUrl;
|
|
44
|
+
exports.ensureClawRouter = ensureClawRouter;
|
|
45
|
+
exports.stopClawRouter = stopClawRouter;
|
|
46
|
+
let _handle = null;
|
|
47
|
+
let _starting = null;
|
|
48
|
+
function getPort() {
|
|
49
|
+
const envPort = process.env.CLAWROUTER_PORT;
|
|
50
|
+
if (envPort) {
|
|
51
|
+
const parsed = parseInt(envPort, 10);
|
|
52
|
+
if (!isNaN(parsed) && parsed > 0 && parsed < 65536)
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
return 8402;
|
|
56
|
+
}
|
|
57
|
+
function isClawRouterRunning() {
|
|
58
|
+
return _handle !== null;
|
|
59
|
+
}
|
|
60
|
+
function getClawRouterBaseUrl() {
|
|
61
|
+
if (_handle)
|
|
62
|
+
return _handle.baseUrl;
|
|
63
|
+
return `http://127.0.0.1:${getPort()}`;
|
|
64
|
+
}
|
|
65
|
+
async function ensureClawRouter(privateKey) {
|
|
66
|
+
if (_handle)
|
|
67
|
+
return;
|
|
68
|
+
// Concurrent startup gate — if another call is already starting, wait for it
|
|
69
|
+
if (_starting) {
|
|
70
|
+
await _starting;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
_starting = (async () => {
|
|
74
|
+
const { startProxy } = await Promise.resolve().then(() => __importStar(require("@blockrun/clawrouter")));
|
|
75
|
+
const port = getPort();
|
|
76
|
+
const handle = await startProxy({
|
|
77
|
+
wallet: privateKey,
|
|
78
|
+
port,
|
|
79
|
+
paymentChain: "base",
|
|
80
|
+
});
|
|
81
|
+
_handle = handle;
|
|
82
|
+
return handle;
|
|
83
|
+
})();
|
|
84
|
+
try {
|
|
85
|
+
await _starting;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
_starting = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function stopClawRouter() {
|
|
92
|
+
if (_handle) {
|
|
93
|
+
await _handle.close();
|
|
94
|
+
_handle = null;
|
|
95
|
+
}
|
|
96
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -24,7 +24,7 @@ const DEFAULT_AGENT_COIN_ADDRESS = "0x12577CF0D8a07363224D6909c54C056A183e13b3";
|
|
|
24
24
|
const EXPENSIVE_MODELS = ["gpt-4o", "gpt-4", "claude-3-opus", "claude-3-5-sonnet"];
|
|
25
25
|
const CHEAP_OVERRIDES = ["gpt-4o-mini", "gpt-4-mini"];
|
|
26
26
|
function normalizeProvider(value) {
|
|
27
|
-
if (value === "anthropic" || value === "ollama" || value === "openai" || value === "gemini" || value === "claude-code" || value === "codex" || value === "deepseek" || value === "qwen") {
|
|
27
|
+
if (value === "anthropic" || value === "ollama" || value === "openai" || value === "gemini" || value === "claude-code" || value === "codex" || value === "deepseek" || value === "qwen" || value === "clawrouter") {
|
|
28
28
|
return value;
|
|
29
29
|
}
|
|
30
30
|
return DEFAULT_LLM_PROVIDER;
|
|
@@ -61,7 +61,7 @@ function parseAddress(envKey, fallback) {
|
|
|
61
61
|
return ZERO_ADDRESS;
|
|
62
62
|
}
|
|
63
63
|
function resolveLlmApiKey(provider) {
|
|
64
|
-
if (provider === "claude-code" || provider === "codex")
|
|
64
|
+
if (provider === "claude-code" || provider === "codex" || provider === "clawrouter")
|
|
65
65
|
return "";
|
|
66
66
|
if (process.env.LLM_API_KEY)
|
|
67
67
|
return process.env.LLM_API_KEY;
|
|
@@ -103,7 +103,7 @@ function requirePrivateKey() {
|
|
|
103
103
|
return exports.config.privateKey;
|
|
104
104
|
}
|
|
105
105
|
function requireLlmApiKey() {
|
|
106
|
-
if (exports.config.llmProvider === "ollama" || exports.config.llmProvider === "claude-code" || exports.config.llmProvider === "codex") {
|
|
106
|
+
if (exports.config.llmProvider === "ollama" || exports.config.llmProvider === "claude-code" || exports.config.llmProvider === "codex" || exports.config.llmProvider === "clawrouter") {
|
|
107
107
|
return "";
|
|
108
108
|
}
|
|
109
109
|
if (!exports.config.llmApiKey) {
|
package/dist/errors.js
CHANGED
|
@@ -93,6 +93,22 @@ const patterns = [
|
|
|
93
93
|
recovery: "Try a different model (gpt-4o-mini recommended) or check your LLM API key",
|
|
94
94
|
}),
|
|
95
95
|
},
|
|
96
|
+
{
|
|
97
|
+
test: (m) => m.includes("EADDRINUSE") && m.includes("8402"),
|
|
98
|
+
classify: () => ({
|
|
99
|
+
category: "setup",
|
|
100
|
+
userMessage: "ClawRouter proxy port 8402 is already in use",
|
|
101
|
+
recovery: "Set CLAWROUTER_PORT in .env to use a different port",
|
|
102
|
+
}),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
test: (m) => m.toLowerCase().includes("insufficient") && m.toLowerCase().includes("clawrouter"),
|
|
106
|
+
classify: () => ({
|
|
107
|
+
category: "setup",
|
|
108
|
+
userMessage: "Insufficient USDC for ClawRouter x402 LLM payment",
|
|
109
|
+
recovery: "Send USDC to your wallet on Base",
|
|
110
|
+
}),
|
|
111
|
+
},
|
|
96
112
|
{
|
|
97
113
|
test: (m) => m.includes("INSUFFICIENT_OUTPUT_AMOUNT") || m.includes("Too little received"),
|
|
98
114
|
classify: () => ({
|
package/dist/grinder-native.js
CHANGED
|
@@ -96,7 +96,7 @@ function grinderLabel(info) {
|
|
|
96
96
|
* Grind nonce using all available native grinders in parallel.
|
|
97
97
|
* First to find a valid nonce wins; all others are killed.
|
|
98
98
|
*/
|
|
99
|
-
async function grindNonceNative(challengeNumber, target, minerAddress, info) {
|
|
99
|
+
async function grindNonceNative(challengeNumber, target, minerAddress, info, signal) {
|
|
100
100
|
const targetHex = "0x" + target.toString(16).padStart(64, "0");
|
|
101
101
|
const processes = [];
|
|
102
102
|
const start = process.hrtime();
|
|
@@ -132,6 +132,20 @@ async function grindNonceNative(challengeNumber, target, minerAddress, info) {
|
|
|
132
132
|
catch { }
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
+
// Abort signal support — kill all grinder processes if challenge goes stale
|
|
136
|
+
if (signal) {
|
|
137
|
+
if (signal.aborted) {
|
|
138
|
+
reject(new Error("Grind aborted: challenge stale"));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
signal.addEventListener("abort", () => {
|
|
142
|
+
if (!settled) {
|
|
143
|
+
settled = true;
|
|
144
|
+
cleanup();
|
|
145
|
+
reject(new Error("Grind aborted: challenge stale"));
|
|
146
|
+
}
|
|
147
|
+
}, { once: true });
|
|
148
|
+
}
|
|
135
149
|
function onResult(result) {
|
|
136
150
|
if (settled)
|
|
137
151
|
return;
|
package/dist/grinder.js
CHANGED
|
@@ -57,6 +57,20 @@ async function grindNonceParallel(params) {
|
|
|
57
57
|
const [s, ns] = process.hrtime(start);
|
|
58
58
|
return s + ns / 1_000_000_000;
|
|
59
59
|
}
|
|
60
|
+
// Abort signal support — kill all workers if challenge goes stale
|
|
61
|
+
if (params.signal) {
|
|
62
|
+
if (params.signal.aborted) {
|
|
63
|
+
reject(new Error("Grind aborted: challenge stale"));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
params.signal.addEventListener("abort", () => {
|
|
67
|
+
if (!settled) {
|
|
68
|
+
settled = true;
|
|
69
|
+
cleanup();
|
|
70
|
+
reject(new Error("Grind aborted: challenge stale"));
|
|
71
|
+
}
|
|
72
|
+
}, { once: true });
|
|
73
|
+
}
|
|
60
74
|
for (let i = 0; i < threadCount; i++) {
|
|
61
75
|
// Each worker starts at a random offset to avoid overlap
|
|
62
76
|
const startNonce = BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER));
|
package/dist/index.js
CHANGED
|
@@ -197,10 +197,20 @@ async function setupWizard() {
|
|
|
197
197
|
console.log(` ${ui.bold("Step 3/3: LLM Provider (for minting)")}`);
|
|
198
198
|
console.log(` ${ui.dim("An LLM solves the SMHL challenge when minting your Mining Rig.")}`);
|
|
199
199
|
console.log(` ${ui.dim("Mining uses optimized solving — no LLM needed after minting.")}`);
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
console.log(` ${ui.dim(" clawrouter (recommended) — Zero credentials. Pays with USDC from your wallet.")}`);
|
|
201
|
+
console.log(` ${ui.dim(" openai / anthropic / gemini / deepseek / qwen — Requires API key.")}`);
|
|
202
|
+
console.log(` ${ui.dim(" ollama / claude-code / codex — Local, no API key.")}`);
|
|
203
|
+
const providerInput = await ui.prompt("Provider", "clawrouter");
|
|
204
|
+
const provider = (["clawrouter", "openai", "anthropic", "gemini", "ollama", "deepseek", "qwen", "claude-code", "codex"].includes(providerInput) ? providerInput : "clawrouter");
|
|
202
205
|
values.LLM_PROVIDER = provider;
|
|
203
|
-
if (provider === "
|
|
206
|
+
if (provider === "clawrouter") {
|
|
207
|
+
ui.ok("ClawRouter x402 — no API key needed, pays with USDC from your wallet");
|
|
208
|
+
if (!values.USE_X402 && !values.RPC_URL) {
|
|
209
|
+
values.USE_X402 = "true";
|
|
210
|
+
ui.ok("Auto-enabled x402 RPC (same wallet, same USDC balance)");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (provider === "ollama") {
|
|
204
214
|
const ollamaUrl = await ui.prompt("Ollama URL", "http://127.0.0.1:11434");
|
|
205
215
|
values.OLLAMA_URL = ollamaUrl;
|
|
206
216
|
ui.ok(`Ollama at ${ollamaUrl}`);
|
|
@@ -219,7 +229,7 @@ async function setupWizard() {
|
|
|
219
229
|
ui.hint(`Set LLM_API_KEY in .env later`);
|
|
220
230
|
}
|
|
221
231
|
}
|
|
222
|
-
const defaultModel = provider === "gemini" ? "gemini-2.5-flash" : provider === "anthropic" ? "claude-sonnet-4-5-20250929" : provider === "deepseek" ? "deepseek-chat" : provider === "qwen" ? "qwen-plus" : provider === "claude-code" || provider === "codex" ? "default" : "gpt-4o-mini";
|
|
232
|
+
const defaultModel = provider === "clawrouter" ? "blockrun/eco" : provider === "gemini" ? "gemini-2.5-flash" : provider === "anthropic" ? "claude-sonnet-4-5-20250929" : provider === "deepseek" ? "deepseek-chat" : provider === "qwen" ? "qwen-plus" : provider === "claude-code" || provider === "codex" ? "default" : "gpt-4o-mini";
|
|
223
233
|
const model = await ui.prompt("Model", defaultModel);
|
|
224
234
|
values.LLM_MODEL = model;
|
|
225
235
|
if ((0, config_1.isExpensiveModel)(model)) {
|
|
@@ -260,8 +270,14 @@ async function main() {
|
|
|
260
270
|
const version = readVersion();
|
|
261
271
|
const program = new commander_1.Command();
|
|
262
272
|
// SIGINT handler
|
|
263
|
-
process.on("SIGINT", () => {
|
|
273
|
+
process.on("SIGINT", async () => {
|
|
264
274
|
ui.stopAll();
|
|
275
|
+
try {
|
|
276
|
+
const { stopClawRouter, isClawRouterRunning } = await Promise.resolve().then(() => __importStar(require("./clawrouter")));
|
|
277
|
+
if (isClawRouterRunning())
|
|
278
|
+
await stopClawRouter();
|
|
279
|
+
}
|
|
280
|
+
catch { }
|
|
265
281
|
console.log("");
|
|
266
282
|
console.log(ui.dim(" Interrupted. Bye!"));
|
|
267
283
|
process.exit(0);
|
package/dist/miner.js
CHANGED
|
@@ -240,11 +240,11 @@ async function startMining(tokenId) {
|
|
|
240
240
|
abi: agentCoinAbi,
|
|
241
241
|
functionName: "getMiningChallenge",
|
|
242
242
|
}));
|
|
243
|
-
|
|
244
|
-
const smhl = (0, smhl_1.normalizeSmhlChallenge)(
|
|
243
|
+
let [challengeNumber, target] = [miningChallenge[0], miningChallenge[1]];
|
|
244
|
+
const smhl = (0, smhl_1.normalizeSmhlChallenge)(miningChallenge[2]);
|
|
245
245
|
// Solve SMHL algorithmically (sub-millisecond)
|
|
246
246
|
const smhlStart = process.hrtime();
|
|
247
|
-
|
|
247
|
+
let smhlSolution = (0, smhl_1.solveSmhlAlgorithmic)(smhl);
|
|
248
248
|
const smhlIssues = (0, smhl_1.validateSmhlSolution)(smhlSolution, smhl);
|
|
249
249
|
if (smhlIssues.length > 0) {
|
|
250
250
|
throw new Error(`SMHL generation failed: ${smhlIssues.join(", ")}`);
|
|
@@ -252,36 +252,84 @@ async function startMining(tokenId) {
|
|
|
252
252
|
const smhlElapsed = elapsedSeconds(smhlStart);
|
|
253
253
|
console.log(` ${ui.dim(`SMHL solved (${(smhlElapsed * 1000).toFixed(1)}ms)`)}`);
|
|
254
254
|
// Grind nonce — native GPU/CPU if available, JS fallback
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
// Abort and re-fetch challenge every STALE_CHECK_INTERVAL_MS to avoid
|
|
256
|
+
// grinding a dead nonce after another miner wins the block.
|
|
257
|
+
const STALE_CHECK_INTERVAL_MS = 20_000;
|
|
258
|
+
let grind = null;
|
|
259
|
+
while (!grind) {
|
|
260
|
+
const abortController = new AbortController();
|
|
261
|
+
const nonceSpinner = ui.spinner(`Grinding nonce (${modeLabel})...`);
|
|
262
|
+
// Background staleness checker — polls challenge every 20s
|
|
263
|
+
const staleTimer = setInterval(async () => {
|
|
264
|
+
try {
|
|
265
|
+
const fresh = (await wallet_1.publicClient.readContract({
|
|
266
|
+
address: config_1.config.agentCoinAddress,
|
|
267
|
+
abi: agentCoinAbi,
|
|
268
|
+
functionName: "getMiningChallenge",
|
|
269
|
+
}));
|
|
270
|
+
if (fresh[0] !== challengeNumber) {
|
|
271
|
+
nonceSpinner.stop("Challenge changed — restarting grind");
|
|
272
|
+
abortController.abort();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// RPC hiccup — don't abort, just skip this check
|
|
277
|
+
}
|
|
278
|
+
}, STALE_CHECK_INTERVAL_MS);
|
|
258
279
|
try {
|
|
259
|
-
|
|
280
|
+
if (useNative) {
|
|
281
|
+
try {
|
|
282
|
+
grind = await (0, grinder_native_1.grindNonceNative)(challengeNumber, target, account.address, grinderInfo, abortController.signal);
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
if (abortController.signal.aborted)
|
|
286
|
+
throw err; // re-throw abort
|
|
287
|
+
nonceSpinner.update("Native grinder failed — falling back to JS...");
|
|
288
|
+
grind = await (0, grinder_1.grindNonceParallel)({
|
|
289
|
+
challengeNumber,
|
|
290
|
+
target,
|
|
291
|
+
minerAddress: account.address,
|
|
292
|
+
threads: config_1.config.minerThreads,
|
|
293
|
+
signal: abortController.signal,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
grind = await (0, grinder_1.grindNonceParallel)({
|
|
299
|
+
challengeNumber,
|
|
300
|
+
target,
|
|
301
|
+
minerAddress: account.address,
|
|
302
|
+
threads: config_1.config.minerThreads,
|
|
303
|
+
signal: abortController.signal,
|
|
304
|
+
onProgress: (attempts, hashrate) => {
|
|
305
|
+
const khs = (hashrate / 1000).toFixed(0);
|
|
306
|
+
nonceSpinner.update(`Grinding nonce (JS)... ${khs}k H/s (${attempts.toLocaleString()} attempts)`);
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
clearInterval(staleTimer);
|
|
311
|
+
const khs = grind.hashrate > 0 ? (grind.hashrate / 1000).toFixed(0) : "?";
|
|
312
|
+
nonceSpinner.stop(`Nonce found (${grind.elapsed.toFixed(1)}s${grind.hashrate > 0 ? `, ${khs}k H/s` : ""})`);
|
|
260
313
|
}
|
|
261
|
-
catch {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
314
|
+
catch (err) {
|
|
315
|
+
clearInterval(staleTimer);
|
|
316
|
+
if (abortController.signal.aborted) {
|
|
317
|
+
// Challenge went stale — re-fetch and retry
|
|
318
|
+
const freshChallenge = (await wallet_1.publicClient.readContract({
|
|
319
|
+
address: config_1.config.agentCoinAddress,
|
|
320
|
+
abi: agentCoinAbi,
|
|
321
|
+
functionName: "getMiningChallenge",
|
|
322
|
+
}));
|
|
323
|
+
[challengeNumber, target] = [freshChallenge[0], freshChallenge[1]];
|
|
324
|
+
const freshSmhl = (0, smhl_1.normalizeSmhlChallenge)(freshChallenge[2]);
|
|
325
|
+
smhlSolution = (0, smhl_1.solveSmhlAlgorithmic)(freshSmhl);
|
|
326
|
+
console.log(` ${ui.dim("SMHL re-solved, grinding fresh challenge...")}`);
|
|
327
|
+
grind = null; // loop again
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
throw err; // non-abort error — propagate
|
|
269
331
|
}
|
|
270
332
|
}
|
|
271
|
-
else {
|
|
272
|
-
grind = await (0, grinder_1.grindNonceParallel)({
|
|
273
|
-
challengeNumber,
|
|
274
|
-
target,
|
|
275
|
-
minerAddress: account.address,
|
|
276
|
-
threads: config_1.config.minerThreads,
|
|
277
|
-
onProgress: (attempts, hashrate) => {
|
|
278
|
-
const khs = (hashrate / 1000).toFixed(0);
|
|
279
|
-
nonceSpinner.update(`Grinding nonce (JS)... ${khs}k H/s (${attempts.toLocaleString()} attempts)`);
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
const khs = grind.hashrate > 0 ? (grind.hashrate / 1000).toFixed(0) : "?";
|
|
284
|
-
nonceSpinner.stop(`Nonce found (${grind.elapsed.toFixed(1)}s${grind.hashrate > 0 ? `, ${khs}k H/s` : ""})`);
|
|
285
333
|
// Submit transaction with spinner
|
|
286
334
|
const txSpinner = ui.spinner("Submitting transaction...");
|
|
287
335
|
const txHash = await walletClient.writeContract({
|
package/dist/preflight.js
CHANGED
|
@@ -97,7 +97,7 @@ async function runPreflight(level) {
|
|
|
97
97
|
results.push({
|
|
98
98
|
label: "No USDC balance — QuickNode x402 requires USDC on Base",
|
|
99
99
|
passed: false,
|
|
100
|
-
fix: `Send USDC to ${wallet_1.account.address} on Base (~$10
|
|
100
|
+
fix: `Send USDC to ${wallet_1.account.address} on Base (~$10 covers ${config_1.config.llmProvider === "clawrouter" ? "both RPC and LLM calls" : "~1M RPC calls"}). Run \`apow fund\` to bridge from Solana.`,
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
@@ -184,7 +184,22 @@ async function runPreflight(level) {
|
|
|
184
184
|
}
|
|
185
185
|
// Check 5: LLM key set (only required for minting, not mining)
|
|
186
186
|
if (level === "wallet") {
|
|
187
|
-
if (config_1.config.llmProvider === "
|
|
187
|
+
if (config_1.config.llmProvider === "clawrouter") {
|
|
188
|
+
if (!wallet_1.account) {
|
|
189
|
+
results.push({
|
|
190
|
+
label: "ClawRouter requires PRIVATE_KEY (wallet signs x402 payments)",
|
|
191
|
+
passed: false,
|
|
192
|
+
fix: "Set PRIVATE_KEY in .env",
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
results.push({
|
|
197
|
+
label: `LLM provider: clawrouter (x402, same wallet as mining)`,
|
|
198
|
+
passed: true,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (config_1.config.llmProvider === "ollama") {
|
|
188
203
|
results.push({ label: `LLM provider: ollama (${config_1.config.ollamaUrl})`, passed: true });
|
|
189
204
|
}
|
|
190
205
|
else if (config_1.config.llmProvider === "claude-code" || config_1.config.llmProvider === "codex") {
|
package/dist/smhl.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -286,6 +319,27 @@ async function requestQwenSolution(prompt) {
|
|
|
286
319
|
}, { timeout: 15_000 });
|
|
287
320
|
return response.choices[0]?.message.content ?? "";
|
|
288
321
|
}
|
|
322
|
+
async function requestClawRouterSolution(prompt) {
|
|
323
|
+
const { ensureClawRouter, getClawRouterBaseUrl } = await Promise.resolve().then(() => __importStar(require("./clawrouter")));
|
|
324
|
+
const { requirePrivateKey } = await Promise.resolve().then(() => __importStar(require("./config")));
|
|
325
|
+
await ensureClawRouter(requirePrivateKey());
|
|
326
|
+
const client = new openai_1.default({
|
|
327
|
+
apiKey: "x402",
|
|
328
|
+
baseURL: `${getClawRouterBaseUrl()}/v1`,
|
|
329
|
+
});
|
|
330
|
+
const response = await client.chat.completions.create({
|
|
331
|
+
model: config_1.config.llmModel || "blockrun/eco",
|
|
332
|
+
temperature: 0.7,
|
|
333
|
+
messages: [
|
|
334
|
+
{
|
|
335
|
+
role: "system",
|
|
336
|
+
content: "You generate short lowercase word sequences that match exact constraints. Return only the words separated by spaces. Nothing else.",
|
|
337
|
+
},
|
|
338
|
+
{ role: "user", content: prompt },
|
|
339
|
+
],
|
|
340
|
+
}, { timeout: 15_000 });
|
|
341
|
+
return response.choices[0]?.message.content ?? "";
|
|
342
|
+
}
|
|
289
343
|
async function requestClaudeCodeSolution(prompt) {
|
|
290
344
|
return new Promise((resolve, reject) => {
|
|
291
345
|
const escaped = prompt.replace(/'/g, "'\\''");
|
|
@@ -325,6 +379,8 @@ async function requestProviderSolution(prompt) {
|
|
|
325
379
|
return requestDeepSeekSolution(prompt);
|
|
326
380
|
case "qwen":
|
|
327
381
|
return requestQwenSolution(prompt);
|
|
382
|
+
case "clawrouter":
|
|
383
|
+
return requestClawRouterSolution(prompt);
|
|
328
384
|
case "openai":
|
|
329
385
|
default:
|
|
330
386
|
return requestOpenAiSolution(prompt);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apow-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Mine AGENT tokens on Base L2 with Agentic Proof of Work",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apow",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"apow-cli": "dist/index.js"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=20.0.0"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"dist",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"prepublishOnly": "npm run build"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@blockrun/clawrouter": "^0.12.81",
|
|
42
43
|
"@quicknode/x402": "^0.1.2",
|
|
43
44
|
"@solana/web3.js": "^1.98.0",
|
|
44
45
|
"commander": "^14.0.0",
|
package/skill.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: apow-mine
|
|
3
|
-
description: Set up and start mining AGENT tokens on Base L2 using apow-cli. Handles wallet creation, RPC setup, LLM config, minting a rig, and starting the mining loop.
|
|
3
|
+
description: Set up and start mining AGENT tokens on Base L2 using apow-cli. Handles wallet creation, RPC setup, LLM config, minting a rig, and starting the mining loop. Zero credentials needed — only ETH + USDC on Base.
|
|
4
4
|
allowed-tools: Bash(npx:*), Bash(node:*), Bash(curl:*)
|
|
5
5
|
argument-hint: [setup|mint|mine|stats]
|
|
6
6
|
metadata:
|
|
@@ -8,9 +8,6 @@ metadata:
|
|
|
8
8
|
requires:
|
|
9
9
|
env:
|
|
10
10
|
- PRIVATE_KEY
|
|
11
|
-
- RPC_URL
|
|
12
|
-
- LLM_PROVIDER
|
|
13
|
-
- LLM_API_KEY
|
|
14
11
|
anyBins:
|
|
15
12
|
- npx
|
|
16
13
|
- node
|
|
@@ -48,35 +45,51 @@ npx tsx src/index.ts mint
|
|
|
48
45
|
npx tsx src/index.ts mine
|
|
49
46
|
```
|
|
50
47
|
|
|
51
|
-
### Autonomous Agent Flow (non-interactive)
|
|
48
|
+
### Autonomous Agent Flow — Zero Credentials (non-interactive)
|
|
52
49
|
|
|
53
|
-
If you're an AI agent, skip the interactive wizard and write the `.env` directly
|
|
50
|
+
If you're an AI agent, skip the interactive wizard and write the `.env` directly.
|
|
51
|
+
**No API keys needed.** ClawRouter pays for LLM inference with USDC from your mining wallet via x402. Same private key, same USDC balance, zero credentials.
|
|
54
52
|
|
|
55
53
|
```bash
|
|
56
54
|
# 1. Generate a wallet
|
|
57
55
|
npx apow-cli wallet new
|
|
58
56
|
# Captures address + private key from output (also saved to wallet-<address>.txt)
|
|
59
57
|
|
|
60
|
-
# 2. Write .env directly
|
|
61
|
-
# LLM config is only needed for minting (one-time); mining uses algorithmic SMHL.
|
|
62
|
-
# IMPORTANT: Use an API-based provider for minting (openai/anthropic/gemini/deepseek/qwen).
|
|
63
|
-
# RPC: set RPC_URL (free from Alchemy) or USE_X402=true (auto-pay $10 USDC via QuickNode).
|
|
58
|
+
# 2. Write .env directly — ZERO API keys needed
|
|
64
59
|
cat > .env << 'EOF'
|
|
65
60
|
PRIVATE_KEY=0x<from step 1>
|
|
66
|
-
|
|
67
|
-
LLM_PROVIDER=
|
|
68
|
-
LLM_MODEL=
|
|
69
|
-
LLM_API_KEY=<your key> # Required for minting only
|
|
61
|
+
USE_X402=true
|
|
62
|
+
LLM_PROVIDER=clawrouter
|
|
63
|
+
LLM_MODEL=blockrun/eco
|
|
70
64
|
MINING_AGENT_ADDRESS=0xB7caD3ca5F2BD8aEC2Eb67d6E8D448099B3bC03D
|
|
71
65
|
AGENT_COIN_ADDRESS=0x12577CF0D8a07363224D6909c54C056A183e13b3
|
|
72
66
|
EOF
|
|
73
67
|
|
|
74
|
-
# 3. Fund the wallet
|
|
68
|
+
# 3. Fund the wallet with ETH (gas) + USDC (x402 RPC + LLM payments)
|
|
75
69
|
npx apow-cli fund --chain solana --token sol # bridge SOL → ETH+USDC on Base
|
|
76
70
|
# Or: npx apow-cli fund --chain base # send ETH or USDC on Base directly
|
|
77
71
|
# Or: ask your user to send ETH + USDC on Base directly
|
|
78
72
|
|
|
79
|
-
# 4. Mint + mine (fully autonomous from here)
|
|
73
|
+
# 4. Mint + mine (fully autonomous from here — zero human intervention)
|
|
74
|
+
npx apow-cli mint
|
|
75
|
+
npx apow-cli mine
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Legacy Flow (with API keys)
|
|
79
|
+
|
|
80
|
+
If you prefer to use your own LLM API key instead of ClawRouter:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
cat > .env << 'EOF'
|
|
84
|
+
PRIVATE_KEY=0x<your key>
|
|
85
|
+
RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR_KEY # Free from alchemy.com
|
|
86
|
+
LLM_PROVIDER=openai
|
|
87
|
+
LLM_MODEL=gpt-4o-mini
|
|
88
|
+
LLM_API_KEY=<your key>
|
|
89
|
+
MINING_AGENT_ADDRESS=0xB7caD3ca5F2BD8aEC2Eb67d6E8D448099B3bC03D
|
|
90
|
+
AGENT_COIN_ADDRESS=0x12577CF0D8a07363224D6909c54C056A183e13b3
|
|
91
|
+
EOF
|
|
92
|
+
|
|
80
93
|
npx apow-cli mint
|
|
81
94
|
npx apow-cli mine
|
|
82
95
|
```
|
|
@@ -108,9 +121,10 @@ The miner client validates locally before submitting.
|
|
|
108
121
|
|
|
109
122
|
| Requirement | Details |
|
|
110
123
|
|---|---|
|
|
111
|
-
| **Node.js** |
|
|
124
|
+
| **Node.js** | v20 or higher |
|
|
112
125
|
| **Base wallet** | A private key with ETH on Base (for gas + mint fee) |
|
|
113
|
-
| **
|
|
126
|
+
| **USDC on Base** | ~$10 covers both x402 RPC and ClawRouter LLM calls (only if using zero-credential path) |
|
|
127
|
+
| **LLM access** | ClawRouter (zero credentials, recommended) OR API key (OpenAI, Gemini, etc.) OR local Ollama (**required for minting only**) |
|
|
114
128
|
| **git** | Only if installing from source (not needed for npm) |
|
|
115
129
|
|
|
116
130
|
---
|
|
@@ -233,14 +247,15 @@ AGENT_COIN_ADDRESS=0x12577CF0D8a07363224D6909c54C056A183e13b3
|
|
|
233
247
|
|
|
234
248
|
# === LLM Configuration (required for minting only; mining uses optimized solving) ===
|
|
235
249
|
|
|
236
|
-
# Provider: "openai" | "gemini" | "deepseek" | "qwen" | "anthropic" | "ollama"
|
|
237
|
-
|
|
250
|
+
# Provider: "clawrouter" (recommended) | "openai" | "gemini" | "deepseek" | "qwen" | "anthropic" | "ollama"
|
|
251
|
+
# clawrouter: zero credentials, pays with USDC from your wallet via x402
|
|
252
|
+
LLM_PROVIDER=clawrouter
|
|
238
253
|
|
|
239
|
-
# API key (not required if LLM_PROVIDER=ollama)
|
|
240
|
-
LLM_API_KEY=sk-your-api-key
|
|
254
|
+
# API key (not required if LLM_PROVIDER=clawrouter, ollama, claude-code, or codex)
|
|
255
|
+
# LLM_API_KEY=sk-your-api-key
|
|
241
256
|
|
|
242
257
|
# Model name (provider-specific)
|
|
243
|
-
LLM_MODEL=
|
|
258
|
+
LLM_MODEL=blockrun/eco
|
|
244
259
|
|
|
245
260
|
# === Network ===
|
|
246
261
|
|
|
@@ -259,10 +274,11 @@ CHAIN=base
|
|
|
259
274
|
| `PRIVATE_KEY` | Yes | - | Wallet private key (0x + 64 hex chars) |
|
|
260
275
|
| `MINING_AGENT_ADDRESS` | Yes | - | Deployed MiningAgent contract address |
|
|
261
276
|
| `AGENT_COIN_ADDRESS` | Yes | - | Deployed AgentCoin contract address |
|
|
262
|
-
| `LLM_PROVIDER` | For minting | `
|
|
263
|
-
| `LLM_API_KEY` | For minting | - | API key for minting.
|
|
264
|
-
| `LLM_MODEL` | For minting | `
|
|
265
|
-
| `
|
|
277
|
+
| `LLM_PROVIDER` | For minting | `clawrouter` | LLM provider for minting: `clawrouter` (recommended, zero credentials), `openai`, `gemini`, `deepseek`, `qwen`, `anthropic`, or `ollama`. Not needed for mining. |
|
|
278
|
+
| `LLM_API_KEY` | For minting* | - | API key for minting. Not needed for `clawrouter`, `ollama`, `claude-code`, `codex`, or mining. Falls back to provider-specific env vars. |
|
|
279
|
+
| `LLM_MODEL` | For minting | `blockrun/eco` | Model identifier passed to the provider (minting only) |
|
|
280
|
+
| `CLAWROUTER_PORT` | No | `8402` | Port for ClawRouter local proxy (only if default is in use) |
|
|
281
|
+
| `MINER_THREADS` | No | All CPU cores | Threads for JS nonce grinding (fallback if no native GPU/CPU grinder detected) |
|
|
266
282
|
| `RPC_URL` | Yes* | — | Base JSON-RPC endpoint. Get a free URL from Alchemy or QuickNode. *Not needed if `USE_X402=true`. |
|
|
267
283
|
| `USE_X402` | No | `false` | Set to `true` to auto-pay via QuickNode x402 ($10 USDC for ~1M calls). Replaces `RPC_URL`. |
|
|
268
284
|
| `CHAIN` | No | `base` | Network selector; auto-detects `baseSepolia` if RPC URL contains "sepolia" |
|
|
@@ -277,7 +293,8 @@ CHAIN=base
|
|
|
277
293
|
|
|
278
294
|
| Provider | Model | Cost per call | Notes |
|
|
279
295
|
|---|---|---|---|
|
|
280
|
-
|
|
|
296
|
+
| ClawRouter | `blockrun/eco` | <$0.01 | **Recommended.** Zero credentials, pays with USDC via x402 |
|
|
297
|
+
| OpenAI | `gpt-4o-mini` | ~$0.001 | Cheapest API key option, fast, reliable |
|
|
281
298
|
| Gemini | `gemini-2.5-flash` | ~$0.001 | Fast, good accuracy |
|
|
282
299
|
| DeepSeek | `deepseek-chat` | ~$0.001 | Fast, accessible in China |
|
|
283
300
|
| Qwen | `qwen-plus` | ~$0.002 | Alibaba Cloud, accessible in China |
|
|
@@ -392,7 +409,7 @@ npx apow-cli mine <tokenId> # or specify a rig by token ID
|
|
|
392
409
|
- `miningTarget` (uint256): the difficulty target
|
|
393
410
|
- `smhl`: the SMHL format challenge
|
|
394
411
|
4. **Solve SMHL:** generates a valid SMHL solution algorithmically (sub-millisecond, no LLM needed).
|
|
395
|
-
5. **Grind nonce:**
|
|
412
|
+
5. **Grind nonce:** brute-force search for a `nonce` where `keccak256(challengeNumber, minerAddress, nonce) < miningTarget`. Works on any CPU out of the box. Add a GPU for 100x+ faster grinding.
|
|
396
413
|
6. **Submit proof:** calls `mine(nonce, smhlSolution, tokenId)` on AgentCoin. The contract verifies both the hash and SMHL solution on-chain.
|
|
397
414
|
7. **Collect reward:** AGENT tokens are minted directly to your wallet.
|
|
398
415
|
8. **Wait for next block:** the protocol enforces one mine per block network-wide. The client waits for block advancement before the next cycle.
|