apow-cli 0.8.1 → 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 +17 -5
- package/README.md +38 -5
- package/dist/clawrouter.js +96 -0
- package/dist/config.js +10 -3
- package/dist/dashboard.js +1 -1
- package/dist/errors.js +16 -0
- package/dist/grinder-native.js +270 -0
- package/dist/grinder.js +14 -0
- package/dist/index.js +21 -5
- package/dist/miner.js +89 -17
- package/dist/preflight.js +17 -2
- package/dist/smhl.js +56 -0
- package/package.json +3 -2
- package/skill.md +47 -30
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
|
-
|
|
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
|
|
13
15
|
|
|
14
|
-
# API key (not needed for ollama, claude-code, or codex)
|
|
15
|
-
LLM_API_KEY=
|
|
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=
|
|
@@ -26,6 +28,16 @@ LLM_API_KEY=
|
|
|
26
28
|
# SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
|
|
27
29
|
# SQUID_INTEGRATOR_ID=
|
|
28
30
|
|
|
31
|
+
# GPU Mining (optional — auto-detected, massive speed boost)
|
|
32
|
+
# GRINDER_MODE=auto # auto (default) or js (force JS-only)
|
|
33
|
+
# GPU_GRINDER_PATH=./gpu/grinder-gpu # Metal binary (macOS, auto-detected)
|
|
34
|
+
# CPU_GRINDER_PATH=./gpu/grinder-cpu # C binary (any platform, auto-detected)
|
|
35
|
+
# CPU_THREADS=16 # Threads for CPU-C grinder (default: all cores)
|
|
36
|
+
# Remote GPU via Vast.ai (see: local/vast-setup.sh)
|
|
37
|
+
# VAST_IP= # Remote GPU host IP
|
|
38
|
+
# VAST_PORT= # Remote GPU SSH port
|
|
39
|
+
# REMOTE_GRINDER=/root/grinder-cuda # Path to CUDA binary on remote
|
|
40
|
+
|
|
29
41
|
# Contract addresses (defaults built-in, override only if needed)
|
|
30
42
|
# MINING_AGENT_ADDRESS=0xB7caD3ca5F2BD8aEC2Eb67d6E8D448099B3bC03D
|
|
31
43
|
# AGENT_COIN_ADDRESS=0x12577CF0D8a07363224D6909c54C056A183e13b3
|
package/README.md
CHANGED
|
@@ -159,14 +159,47 @@ apow fund --chain base --no-swap
|
|
|
159
159
|
|
|
160
160
|
**Auto-split targets:** 0.003 ETH (gas for ~100 mine txns) + 2.00 USDC (~100K x402 RPC calls). If both are already met, the CLI skips the swap.
|
|
161
161
|
|
|
162
|
-
##
|
|
162
|
+
## GPU Mining (v0.9.0+)
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
The miner auto-detects native GPU and CPU grinder binaries for dramatically faster nonce grinding:
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
| Grinder | Platform | Speed | Setup |
|
|
167
|
+
|---------|----------|-------|-------|
|
|
168
|
+
| Metal GPU | macOS (Apple Silicon) | ~260-500 MH/s | `cd local/gpu && make metal` |
|
|
169
|
+
| CUDA | Linux (RTX 4090 via Vast.ai) | ~20 GH/s | `./local/vast-setup.sh` |
|
|
170
|
+
| CPU-C | Any (multi-threaded C) | ~150-300 MH/s | `cd local/gpu && make cpu` |
|
|
171
|
+
| JS (fallback) | Any (worker_threads) | ~2-5 MH/s | Built-in, no setup |
|
|
172
|
+
|
|
173
|
+
All available grinders race in parallel -- first valid nonce wins. Falls back to JS automatically if no native binaries are found.
|
|
174
|
+
|
|
175
|
+
### Local GPU Setup (macOS)
|
|
168
176
|
|
|
169
|
-
|
|
177
|
+
```bash
|
|
178
|
+
cd local/gpu
|
|
179
|
+
make metal # builds grinder-gpu (Metal compute shader)
|
|
180
|
+
make cpu # builds grinder-cpu (multi-threaded C)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Place binaries in `./gpu/`, `~/.apow/`, or set `GPU_GRINDER_PATH`/`CPU_GRINDER_PATH` in `.env`.
|
|
184
|
+
|
|
185
|
+
### Remote GPU Setup (Vast.ai)
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
./local/vast-setup.sh # rent RTX 4090, upload + compile CUDA grinder
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Then add to `.env`:
|
|
192
|
+
```
|
|
193
|
+
VAST_IP=<ip>
|
|
194
|
+
VAST_PORT=<port>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The CUDA grinder runs over SSH alongside your local Metal/CPU grinders -- genuinely additive hash power.
|
|
198
|
+
|
|
199
|
+
### Other Optimizations
|
|
200
|
+
|
|
201
|
+
- **Algorithmic SMHL**: Mining SMHL challenges are solved algorithmically in microseconds (no LLM call). Your AI was already proven when you minted your Mining Rig.
|
|
202
|
+
- **JS threads**: If no native grinders are found, falls back to `worker_threads` across all CPU cores. Set `MINER_THREADS` in `.env` to override.
|
|
170
203
|
|
|
171
204
|
## Dashboard
|
|
172
205
|
|
|
@@ -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;
|
|
@@ -88,6 +88,13 @@ exports.config = {
|
|
|
88
88
|
miningAgentAddress: parseAddress("MINING_AGENT_ADDRESS", DEFAULT_MINING_AGENT_ADDRESS),
|
|
89
89
|
agentCoinAddress: parseAddress("AGENT_COIN_ADDRESS", DEFAULT_AGENT_COIN_ADDRESS),
|
|
90
90
|
minerThreads: parseInt(process.env.MINER_THREADS ?? String(node_os_1.default.cpus().length), 10),
|
|
91
|
+
grinderMode: (process.env.GRINDER_MODE === "js" ? "js" : "auto"),
|
|
92
|
+
gpuGrinderPath: process.env.GPU_GRINDER_PATH,
|
|
93
|
+
cpuGrinderPath: process.env.CPU_GRINDER_PATH,
|
|
94
|
+
vastIp: process.env.VAST_IP,
|
|
95
|
+
vastPort: process.env.VAST_PORT,
|
|
96
|
+
cpuGrinderThreads: parseInt(process.env.CPU_THREADS ?? String(node_os_1.default.cpus().length), 10),
|
|
97
|
+
remoteGrinderPath: process.env.REMOTE_GRINDER ?? "/root/grinder-cuda",
|
|
91
98
|
};
|
|
92
99
|
function requirePrivateKey() {
|
|
93
100
|
if (!exports.config.privateKey) {
|
|
@@ -96,7 +103,7 @@ function requirePrivateKey() {
|
|
|
96
103
|
return exports.config.privateKey;
|
|
97
104
|
}
|
|
98
105
|
function requireLlmApiKey() {
|
|
99
|
-
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") {
|
|
100
107
|
return "";
|
|
101
108
|
}
|
|
102
109
|
if (!exports.config.llmApiKey) {
|
package/dist/dashboard.js
CHANGED
|
@@ -427,7 +427,7 @@ function startDashboardServer(opts) {
|
|
|
427
427
|
return JSON.stringify(fleets.map((f) => ({ name: f.name, walletCount: f.addresses.length })));
|
|
428
428
|
}
|
|
429
429
|
function handleConfig() {
|
|
430
|
-
const rpcIsDefault = useX402
|
|
430
|
+
const rpcIsDefault = !useX402 && rpcUrl === DEFAULT_RPC;
|
|
431
431
|
const walletCount = getWalletAddresses(walletsPath).length;
|
|
432
432
|
return JSON.stringify({ rpcIsDefault, walletCount });
|
|
433
433
|
}
|
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: () => ({
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Native GPU/CPU nonce grinder integration.
|
|
4
|
+
*
|
|
5
|
+
* Detects and spawns native grinder binaries (Metal, CPU-C, CUDA) for
|
|
6
|
+
* dramatically faster nonce grinding compared to JS worker_threads.
|
|
7
|
+
*
|
|
8
|
+
* Supported grinders:
|
|
9
|
+
* - Metal (macOS Apple Silicon): local GPU, ~260-500 MH/s
|
|
10
|
+
* - CPU-C (any platform): multi-threaded C, ~150-300 MH/s
|
|
11
|
+
* - CUDA (remote via SSH): Vast.ai RTX 4090, ~20 GH/s
|
|
12
|
+
*
|
|
13
|
+
* All grinders race in parallel. First valid nonce wins; others are killed.
|
|
14
|
+
*
|
|
15
|
+
* Binary interface:
|
|
16
|
+
* Metal/CPU: ./grinder <challenge> <address> <target> [threads]
|
|
17
|
+
* stdout: <nonce> <attempts> <elapsed_seconds>
|
|
18
|
+
*
|
|
19
|
+
* CUDA: ./grinder-cuda <challenge> <target> <address>
|
|
20
|
+
* stdout: F <addr_index> <nonce> <elapsed_seconds>
|
|
21
|
+
*/
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.detectGrinders = detectGrinders;
|
|
27
|
+
exports.hasNativeGrinders = hasNativeGrinders;
|
|
28
|
+
exports.grinderLabel = grinderLabel;
|
|
29
|
+
exports.grindNonceNative = grindNonceNative;
|
|
30
|
+
const node_child_process_1 = require("node:child_process");
|
|
31
|
+
const node_fs_1 = require("node:fs");
|
|
32
|
+
const node_path_1 = require("node:path");
|
|
33
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
34
|
+
const config_1 = require("./config");
|
|
35
|
+
/**
|
|
36
|
+
* Detect available native grinder binaries.
|
|
37
|
+
* Checks: explicit env var > ./gpu/ > ./ > ~/.apow/
|
|
38
|
+
*/
|
|
39
|
+
function detectGrinders() {
|
|
40
|
+
return {
|
|
41
|
+
gpu: detectLocalGpu(),
|
|
42
|
+
cpu: detectLocalCpu(),
|
|
43
|
+
remoteGpu: !!(config_1.config.vastIp && config_1.config.vastPort),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function detectLocalGpu() {
|
|
47
|
+
if (config_1.config.gpuGrinderPath) {
|
|
48
|
+
return (0, node_fs_1.existsSync)(config_1.config.gpuGrinderPath) ? config_1.config.gpuGrinderPath : null;
|
|
49
|
+
}
|
|
50
|
+
if (process.platform !== "darwin")
|
|
51
|
+
return null;
|
|
52
|
+
const candidates = [
|
|
53
|
+
(0, node_path_1.join)(process.cwd(), "gpu", "grinder-gpu"),
|
|
54
|
+
(0, node_path_1.join)(process.cwd(), "local", "gpu", "grinder-gpu"),
|
|
55
|
+
(0, node_path_1.join)(process.cwd(), "grinder-gpu"),
|
|
56
|
+
(0, node_path_1.join)(node_os_1.default.homedir(), ".apow", "grinder-gpu"),
|
|
57
|
+
];
|
|
58
|
+
for (const p of candidates) {
|
|
59
|
+
if ((0, node_fs_1.existsSync)(p))
|
|
60
|
+
return p;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function detectLocalCpu() {
|
|
65
|
+
if (config_1.config.cpuGrinderPath) {
|
|
66
|
+
return (0, node_fs_1.existsSync)(config_1.config.cpuGrinderPath) ? config_1.config.cpuGrinderPath : null;
|
|
67
|
+
}
|
|
68
|
+
const candidates = [
|
|
69
|
+
(0, node_path_1.join)(process.cwd(), "gpu", "grinder-cpu"),
|
|
70
|
+
(0, node_path_1.join)(process.cwd(), "local", "gpu", "grinder-cpu"),
|
|
71
|
+
(0, node_path_1.join)(process.cwd(), "grinder-cpu"),
|
|
72
|
+
(0, node_path_1.join)(node_os_1.default.homedir(), ".apow", "grinder-cpu"),
|
|
73
|
+
];
|
|
74
|
+
for (const p of candidates) {
|
|
75
|
+
if ((0, node_fs_1.existsSync)(p))
|
|
76
|
+
return p;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function hasNativeGrinders(info) {
|
|
81
|
+
return !!(info.gpu || info.cpu || info.remoteGpu);
|
|
82
|
+
}
|
|
83
|
+
function grinderLabel(info) {
|
|
84
|
+
const parts = [];
|
|
85
|
+
if (info.remoteGpu)
|
|
86
|
+
parts.push("CUDA (remote)");
|
|
87
|
+
if (info.gpu)
|
|
88
|
+
parts.push(process.platform === "darwin" ? "Metal GPU" : "GPU");
|
|
89
|
+
if (info.cpu)
|
|
90
|
+
parts.push(`CPU-C (${config_1.config.cpuGrinderThreads}t)`);
|
|
91
|
+
if (parts.length === 0)
|
|
92
|
+
return "JS worker_threads";
|
|
93
|
+
return parts.join(" + ");
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Grind nonce using all available native grinders in parallel.
|
|
97
|
+
* First to find a valid nonce wins; all others are killed.
|
|
98
|
+
*/
|
|
99
|
+
async function grindNonceNative(challengeNumber, target, minerAddress, info, signal) {
|
|
100
|
+
const targetHex = "0x" + target.toString(16).padStart(64, "0");
|
|
101
|
+
const processes = [];
|
|
102
|
+
const start = process.hrtime();
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
let settled = false;
|
|
105
|
+
let failCount = 0;
|
|
106
|
+
let totalGrinders = 0;
|
|
107
|
+
function elapsed() {
|
|
108
|
+
const [s, ns] = process.hrtime(start);
|
|
109
|
+
return s + ns / 1_000_000_000;
|
|
110
|
+
}
|
|
111
|
+
function cleanup() {
|
|
112
|
+
for (const proc of processes) {
|
|
113
|
+
try {
|
|
114
|
+
proc.kill("SIGTERM");
|
|
115
|
+
}
|
|
116
|
+
catch { }
|
|
117
|
+
}
|
|
118
|
+
if (info.remoteGpu) {
|
|
119
|
+
try {
|
|
120
|
+
const kp = (0, node_child_process_1.spawn)("ssh", [
|
|
121
|
+
"-o", "StrictHostKeyChecking=no",
|
|
122
|
+
"-o", "ConnectTimeout=5",
|
|
123
|
+
"-p", config_1.config.vastPort,
|
|
124
|
+
`root@${config_1.config.vastIp}`,
|
|
125
|
+
"pkill -9 grinder-cuda 2>/dev/null",
|
|
126
|
+
]);
|
|
127
|
+
setTimeout(() => { try {
|
|
128
|
+
kp.kill();
|
|
129
|
+
}
|
|
130
|
+
catch { } }, 5000);
|
|
131
|
+
}
|
|
132
|
+
catch { }
|
|
133
|
+
}
|
|
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
|
+
}
|
|
149
|
+
function onResult(result) {
|
|
150
|
+
if (settled)
|
|
151
|
+
return;
|
|
152
|
+
settled = true;
|
|
153
|
+
cleanup();
|
|
154
|
+
resolve(result);
|
|
155
|
+
}
|
|
156
|
+
function onFail() {
|
|
157
|
+
failCount++;
|
|
158
|
+
if (failCount >= totalGrinders && !settled) {
|
|
159
|
+
settled = true;
|
|
160
|
+
cleanup();
|
|
161
|
+
reject(new Error("All native grinders failed to find a nonce"));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Local Metal GPU
|
|
165
|
+
if (info.gpu) {
|
|
166
|
+
totalGrinders++;
|
|
167
|
+
const proc = (0, node_child_process_1.spawn)(info.gpu, [challengeNumber, minerAddress, targetHex]);
|
|
168
|
+
processes.push(proc);
|
|
169
|
+
let stdout = "";
|
|
170
|
+
proc.stdout.on("data", (d) => { stdout += d.toString(); });
|
|
171
|
+
proc.on("close", (code) => {
|
|
172
|
+
if (settled)
|
|
173
|
+
return;
|
|
174
|
+
if (code === 0) {
|
|
175
|
+
const parts = stdout.trim().split(/\s+/);
|
|
176
|
+
if (parts.length >= 3) {
|
|
177
|
+
const attempts = BigInt(parts[1]);
|
|
178
|
+
const e = parseFloat(parts[2]);
|
|
179
|
+
onResult({
|
|
180
|
+
nonce: BigInt(parts[0]),
|
|
181
|
+
attempts,
|
|
182
|
+
elapsed: e,
|
|
183
|
+
hashrate: e > 0 ? Number(attempts) / e : 0,
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
onFail();
|
|
189
|
+
});
|
|
190
|
+
proc.on("error", () => onFail());
|
|
191
|
+
}
|
|
192
|
+
// Local CPU-C
|
|
193
|
+
if (info.cpu) {
|
|
194
|
+
totalGrinders++;
|
|
195
|
+
const proc = (0, node_child_process_1.spawn)(info.cpu, [
|
|
196
|
+
challengeNumber, minerAddress, targetHex,
|
|
197
|
+
String(config_1.config.cpuGrinderThreads),
|
|
198
|
+
]);
|
|
199
|
+
processes.push(proc);
|
|
200
|
+
let stdout = "";
|
|
201
|
+
proc.stdout.on("data", (d) => { stdout += d.toString(); });
|
|
202
|
+
proc.on("close", (code) => {
|
|
203
|
+
if (settled)
|
|
204
|
+
return;
|
|
205
|
+
if (code === 0) {
|
|
206
|
+
const parts = stdout.trim().split(/\s+/);
|
|
207
|
+
if (parts.length >= 3) {
|
|
208
|
+
const attempts = BigInt(parts[1]);
|
|
209
|
+
const e = parseFloat(parts[2]);
|
|
210
|
+
onResult({
|
|
211
|
+
nonce: BigInt(parts[0]),
|
|
212
|
+
attempts,
|
|
213
|
+
elapsed: e,
|
|
214
|
+
hashrate: e > 0 ? Number(attempts) / e : 0,
|
|
215
|
+
});
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
onFail();
|
|
220
|
+
});
|
|
221
|
+
proc.on("error", () => onFail());
|
|
222
|
+
}
|
|
223
|
+
// Remote CUDA via SSH
|
|
224
|
+
if (info.remoteGpu) {
|
|
225
|
+
totalGrinders++;
|
|
226
|
+
// CUDA arg order differs: <challenge> <target> <address>
|
|
227
|
+
const proc = (0, node_child_process_1.spawn)("ssh", [
|
|
228
|
+
"-o", "StrictHostKeyChecking=no",
|
|
229
|
+
"-o", "ConnectTimeout=10",
|
|
230
|
+
"-o", "ServerAliveInterval=30",
|
|
231
|
+
"-p", config_1.config.vastPort,
|
|
232
|
+
`root@${config_1.config.vastIp}`,
|
|
233
|
+
`${config_1.config.remoteGrinderPath} ${challengeNumber} ${targetHex} ${minerAddress}`,
|
|
234
|
+
]);
|
|
235
|
+
processes.push(proc);
|
|
236
|
+
let buf = "";
|
|
237
|
+
proc.stdout.on("data", (d) => {
|
|
238
|
+
if (settled)
|
|
239
|
+
return;
|
|
240
|
+
buf += d.toString();
|
|
241
|
+
let nl;
|
|
242
|
+
while ((nl = buf.indexOf("\n")) !== -1) {
|
|
243
|
+
const line = buf.slice(0, nl).trim();
|
|
244
|
+
buf = buf.slice(nl + 1);
|
|
245
|
+
if (line.startsWith("F ")) {
|
|
246
|
+
const parts = line.split(/\s+/);
|
|
247
|
+
if (parts.length >= 4) {
|
|
248
|
+
const e = parseFloat(parts[3]);
|
|
249
|
+
onResult({
|
|
250
|
+
nonce: BigInt(parts[2]),
|
|
251
|
+
attempts: 0n,
|
|
252
|
+
elapsed: e,
|
|
253
|
+
hashrate: 0,
|
|
254
|
+
});
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
proc.on("close", () => {
|
|
261
|
+
if (!settled)
|
|
262
|
+
onFail();
|
|
263
|
+
});
|
|
264
|
+
proc.on("error", () => onFail());
|
|
265
|
+
}
|
|
266
|
+
if (totalGrinders === 0) {
|
|
267
|
+
reject(new Error("No native grinders available"));
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
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
|
@@ -45,6 +45,7 @@ const detect_1 = require("./detect");
|
|
|
45
45
|
const errors_1 = require("./errors");
|
|
46
46
|
const explorer_1 = require("./explorer");
|
|
47
47
|
const grinder_1 = require("./grinder");
|
|
48
|
+
const grinder_native_1 = require("./grinder-native");
|
|
48
49
|
const smhl_1 = require("./smhl");
|
|
49
50
|
const ui = __importStar(require("./ui"));
|
|
50
51
|
const wallet_1 = require("./wallet");
|
|
@@ -171,7 +172,13 @@ async function startMining(tokenId) {
|
|
|
171
172
|
let consecutiveFailures = 0;
|
|
172
173
|
let mineCount = 0;
|
|
173
174
|
let runningTotal = 0n;
|
|
175
|
+
// Detect native grinders once at startup
|
|
176
|
+
const grinderInfo = (0, grinder_native_1.detectGrinders)();
|
|
177
|
+
const useNative = config_1.config.grinderMode !== "js" && (0, grinder_native_1.hasNativeGrinders)(grinderInfo);
|
|
178
|
+
const modeLabel = useNative ? (0, grinder_native_1.grinderLabel)(grinderInfo) : `JS (${config_1.config.minerThreads} threads)`;
|
|
174
179
|
await showStartupBanner(tokenId);
|
|
180
|
+
console.log(` Grinder: ${ui.bold(modeLabel)}`);
|
|
181
|
+
console.log("");
|
|
175
182
|
while (true) {
|
|
176
183
|
try {
|
|
177
184
|
// Pre-flight ownership check
|
|
@@ -233,31 +240,96 @@ async function startMining(tokenId) {
|
|
|
233
240
|
abi: agentCoinAbi,
|
|
234
241
|
functionName: "getMiningChallenge",
|
|
235
242
|
}));
|
|
236
|
-
|
|
237
|
-
const smhl = (0, smhl_1.normalizeSmhlChallenge)(
|
|
243
|
+
let [challengeNumber, target] = [miningChallenge[0], miningChallenge[1]];
|
|
244
|
+
const smhl = (0, smhl_1.normalizeSmhlChallenge)(miningChallenge[2]);
|
|
238
245
|
// Solve SMHL algorithmically (sub-millisecond)
|
|
239
246
|
const smhlStart = process.hrtime();
|
|
240
|
-
|
|
247
|
+
let smhlSolution = (0, smhl_1.solveSmhlAlgorithmic)(smhl);
|
|
241
248
|
const smhlIssues = (0, smhl_1.validateSmhlSolution)(smhlSolution, smhl);
|
|
242
249
|
if (smhlIssues.length > 0) {
|
|
243
250
|
throw new Error(`SMHL generation failed: ${smhlIssues.join(", ")}`);
|
|
244
251
|
}
|
|
245
252
|
const smhlElapsed = elapsedSeconds(smhlStart);
|
|
246
253
|
console.log(` ${ui.dim(`SMHL solved (${(smhlElapsed * 1000).toFixed(1)}ms)`)}`);
|
|
247
|
-
// Grind nonce
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
// Grind nonce — native GPU/CPU if available, JS fallback
|
|
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);
|
|
279
|
+
try {
|
|
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` : ""})`);
|
|
313
|
+
}
|
|
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
|
|
331
|
+
}
|
|
332
|
+
}
|
|
261
333
|
// Submit transaction with spinner
|
|
262
334
|
const txSpinner = ui.spinner("Submitting transaction...");
|
|
263
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.
|
|
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.
|
|
@@ -519,7 +536,7 @@ pm2 logs
|
|
|
519
536
|
|
|
520
537
|
**RPC rate limits:** For 3+ concurrent miners, use a dedicated RPC endpoint (Alchemy, Infura, QuickNode). Free public RPCs will not handle the load.
|
|
521
538
|
|
|
522
|
-
**
|
|
539
|
+
**GPU mining (v0.9.0+):** The miner auto-detects native GPU grinder binaries for 50-1000x faster nonce grinding. Build Metal (macOS) or CPU-C grinders from `local/gpu/`, or rent a CUDA GPU on [vast.ai](https://vast.ai/) with `./local/vast-setup.sh`. All grinders race in parallel -- first nonce wins. Falls back to JS automatically.
|
|
523
540
|
|
|
524
541
|
### Local LLM Setup (Ollama)
|
|
525
542
|
|