apow-cli 0.9.1 → 0.9.3
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 +19 -9
- package/README.md +46 -28
- package/dist/bridge/constants.js +5 -0
- package/dist/bridge/ethereum.js +29 -0
- package/dist/bridge/squid.js +19 -2
- package/dist/build.js +234 -0
- package/dist/config.js +27 -8
- package/dist/errors.js +24 -0
- package/dist/fund.js +101 -5
- package/dist/grinder-http.js +108 -0
- package/dist/grinder-native.js +59 -2
- package/dist/index.js +93 -60
- package/dist/miner.js +46 -27
- package/dist/preflight.js +27 -2
- package/local/gpu/Makefile +39 -0
- package/local/gpu/grinder-cpu.c +241 -0
- package/local/gpu/grinder-cuda.cu +518 -0
- package/local/gpu/grinder.m +191 -0
- package/local/gpu/keccak.metal +143 -0
- package/package.json +9 -2
- package/skill.md +55 -18
package/.env.example
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# === Quick Start (zero credentials) ===
|
|
2
|
+
# Just these 2 lines to get started. RPC + LLM auto-pay with USDC from your wallet.
|
|
2
3
|
PRIVATE_KEY=
|
|
4
|
+
USE_X402=true
|
|
3
5
|
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
# USE_X402=
|
|
6
|
+
# === Custom Configuration (override any defaults below) ===
|
|
7
|
+
|
|
8
|
+
# RPC — bring your own endpoint instead of x402
|
|
9
|
+
# RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR_KEY
|
|
10
|
+
# USE_X402=false
|
|
9
11
|
|
|
10
12
|
# LLM Provider (clawrouter / openai / anthropic / gemini / ollama / claude-code / codex)
|
|
11
|
-
#
|
|
12
|
-
LLM_PROVIDER=clawrouter
|
|
13
|
-
LLM_MODEL=blockrun/eco
|
|
13
|
+
# Default: clawrouter when USE_X402=true, openai otherwise
|
|
14
|
+
# LLM_PROVIDER=clawrouter
|
|
15
|
+
# LLM_MODEL=blockrun/eco
|
|
14
16
|
# CLAWROUTER_PORT=8402 # only if default port is in use
|
|
15
17
|
|
|
16
18
|
# API key (not needed for clawrouter, ollama, claude-code, or codex)
|
|
@@ -26,11 +28,19 @@ LLM_MODEL=blockrun/eco
|
|
|
26
28
|
|
|
27
29
|
# Bridging (only needed for `apow fund`)
|
|
28
30
|
# SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
|
|
31
|
+
# ETHEREUM_RPC_URL=https://cloudflare-eth.com
|
|
29
32
|
# SQUID_INTEGRATOR_ID=
|
|
30
33
|
|
|
34
|
+
# x402 GPU Grinding (remote RTX 4090, $0.01/grind, zero setup)
|
|
35
|
+
# Enabled automatically when USE_X402=true. Override with USE_X402_GRIND=false to disable.
|
|
36
|
+
# USE_X402_GRIND=true
|
|
37
|
+
# GRIND_URL=https://grind.apow.io/grind
|
|
38
|
+
|
|
31
39
|
# GPU Mining (optional — auto-detected, massive speed boost)
|
|
40
|
+
# Run `apow build-grinders` to compile native binaries automatically.
|
|
32
41
|
# GRINDER_MODE=auto # auto (default) or js (force JS-only)
|
|
33
42
|
# GPU_GRINDER_PATH=./gpu/grinder-gpu # Metal binary (macOS, auto-detected)
|
|
43
|
+
# CUDA_GRINDER_PATH=~/.apow/grinder-cuda # CUDA binary (NVIDIA GPU, auto-detected)
|
|
34
44
|
# CPU_GRINDER_PATH=./gpu/grinder-cpu # C binary (any platform, auto-detected)
|
|
35
45
|
# CPU_THREADS=16 # Threads for CPU-C grinder (default: all cores)
|
|
36
46
|
# Remote GPU via Vast.ai (see: local/vast-setup.sh)
|
package/README.md
CHANGED
|
@@ -39,10 +39,10 @@ npx apow-cli wallet new
|
|
|
39
39
|
# RPC: set RPC_URL for a free RPC, or USE_X402=true for auto-pay ($10 USDC)
|
|
40
40
|
cat > .env << 'EOF'
|
|
41
41
|
PRIVATE_KEY=0x<from step 1>
|
|
42
|
-
|
|
43
|
-
LLM_MODEL=gpt-4o-mini # Required for minting only
|
|
44
|
-
LLM_API_KEY=<your key> # Required for minting only
|
|
42
|
+
USE_X402=true
|
|
45
43
|
EOF
|
|
44
|
+
# USE_X402=true auto-activates clawrouter LLM + QuickNode RPC (both pay with USDC)
|
|
45
|
+
# Contract addresses are built-in defaults — no need to specify them
|
|
46
46
|
|
|
47
47
|
# 3. Fund the wallet (bridge from any chain, auto-splits into ETH + USDC)
|
|
48
48
|
npx apow-cli fund --chain solana --token sol # bridge SOL → ETH+USDC on Base
|
|
@@ -77,7 +77,7 @@ If you prefer to do it yourself:
|
|
|
77
77
|
# 1. Interactive setup: wallet, RPC, LLM config
|
|
78
78
|
npx apow-cli setup
|
|
79
79
|
|
|
80
|
-
# 2. Fund your wallet (bridge from Solana or send ETH directly)
|
|
80
|
+
# 2. Fund your wallet (bridge from Solana/Ethereum or send ETH directly)
|
|
81
81
|
npx apow-cli fund
|
|
82
82
|
|
|
83
83
|
# 3. Mint a mining rig NFT
|
|
@@ -92,7 +92,7 @@ npx apow-cli mine
|
|
|
92
92
|
| Command | Description |
|
|
93
93
|
|---------|-------------|
|
|
94
94
|
| `apow setup` | Interactive setup wizard: configure wallet, RPC, and LLM |
|
|
95
|
-
| `apow fund` | Fund your wallet: bridge from Solana or send on Base, auto-split ETH+USDC |
|
|
95
|
+
| `apow fund` | Fund your wallet: bridge from Solana/Ethereum or send on Base, auto-split ETH+USDC |
|
|
96
96
|
| `apow wallet new` | Generate a new mining wallet |
|
|
97
97
|
| `apow wallet show` | Show configured wallet address |
|
|
98
98
|
| `apow wallet export` | Export your wallet's private key |
|
|
@@ -110,13 +110,14 @@ Create a `.env` file or use `apow setup`:
|
|
|
110
110
|
|
|
111
111
|
```bash
|
|
112
112
|
PRIVATE_KEY=0x... # Your wallet private key
|
|
113
|
-
|
|
114
|
-
#
|
|
115
|
-
LLM_PROVIDER=
|
|
116
|
-
LLM_MODEL=
|
|
117
|
-
LLM_API_KEY=sk-...
|
|
113
|
+
USE_X402=true # Auto-pay RPC + LLM via x402 ($10 USDC for ~1M calls, zero API keys)
|
|
114
|
+
# RPC_URL=https://... # Or: bring your own RPC (free from Alchemy, QuickNode, etc.)
|
|
115
|
+
# LLM_PROVIDER=clawrouter # clawrouter (auto with x402) | openai | gemini | deepseek | qwen | anthropic | ollama (for minting)
|
|
116
|
+
# LLM_MODEL=blockrun/eco # Auto-detected per provider; override only if needed
|
|
117
|
+
# LLM_API_KEY=sk-... # Not needed with clawrouter/ollama; required for openai/gemini/etc.
|
|
118
118
|
# Bridging (only for `apow fund`)
|
|
119
119
|
# SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
|
|
120
|
+
# ETHEREUM_RPC_URL=https://cloudflare-eth.com
|
|
120
121
|
# SQUID_INTEGRATOR_ID= # free, get at squidrouter.com
|
|
121
122
|
# Contract addresses (defaults built-in, override only if needed)
|
|
122
123
|
# MINING_AGENT_ADDRESS=0xB7caD3ca5F2BD8aEC2Eb67d6E8D448099B3bC03D
|
|
@@ -131,7 +132,8 @@ An LLM is required to mint your Mining Rig NFT (one-time identity verification).
|
|
|
131
132
|
|
|
132
133
|
| Provider | Model | Cost/call | Notes |
|
|
133
134
|
|----------|-------|-----------|-------|
|
|
134
|
-
|
|
|
135
|
+
| ClawRouter | `blockrun/eco` | <$0.01 | Recommended. Zero credentials, pays with USDC via x402 |
|
|
136
|
+
| OpenAI | `gpt-4o-mini` | ~$0.001 | Cheapest API key option, fast |
|
|
135
137
|
| Gemini | `gemini-2.5-flash` | ~$0.001 | Fast, good accuracy |
|
|
136
138
|
| DeepSeek | `deepseek-chat` | ~$0.001 | Fast, accessible in China |
|
|
137
139
|
| Qwen | `qwen-plus` | ~$0.002 | Alibaba Cloud |
|
|
@@ -140,13 +142,16 @@ An LLM is required to mint your Mining Rig NFT (one-time identity verification).
|
|
|
140
142
|
|
|
141
143
|
## Funding (v0.7.0+)
|
|
142
144
|
|
|
143
|
-
Mining requires two assets on Base: **ETH** (gas) and **USDC** (x402 RPC). The `fund` command bridges from Solana or accepts deposits on Base, and auto-splits into both:
|
|
145
|
+
Mining requires two assets on Base: **ETH** (gas) and **USDC** (x402 RPC). The `fund` command bridges from Solana or Ethereum, or accepts deposits on Base, and auto-splits into both:
|
|
144
146
|
|
|
145
147
|
```bash
|
|
146
148
|
# From Solana (deposit address — send from any wallet, QR code included)
|
|
147
149
|
apow fund --chain solana --token sol # bridge SOL → ETH, auto-swap portion to USDC
|
|
148
150
|
apow fund --chain solana --token usdc # bridge USDC, auto-swap portion to ETH
|
|
149
151
|
|
|
152
|
+
# From Ethereum mainnet
|
|
153
|
+
apow fund --chain ethereum # bridge ETH → ETH on Base, auto-swap portion to USDC
|
|
154
|
+
|
|
150
155
|
# Already on Base
|
|
151
156
|
apow fund --chain base --token eth # show address, wait for deposit, auto-split
|
|
152
157
|
apow fund --chain base --token usdc # show address, wait for deposit, auto-split
|
|
@@ -155,32 +160,45 @@ apow fund --chain base --token usdc # show address, wait for depos
|
|
|
155
160
|
apow fund --chain base --no-swap
|
|
156
161
|
```
|
|
157
162
|
|
|
158
|
-
**Solana bridging:** Uses [Squid Router](https://squidrouter.com/) (Chainflip). Generates a one-time deposit address with QR code — send from
|
|
163
|
+
**Solana/Ethereum bridging:** Uses [Squid Router](https://squidrouter.com/) (Chainflip). Generates a one-time deposit address with QR code — send from any wallet. Requires `SQUID_INTEGRATOR_ID` in `.env` (free at [squidrouter.com](https://app.squidrouter.com/)).
|
|
159
164
|
|
|
160
165
|
**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
166
|
|
|
162
|
-
## GPU
|
|
167
|
+
## x402 GPU Grinding
|
|
163
168
|
|
|
164
|
-
|
|
169
|
+
No GPU? No problem. Remote RTX 4090 nonce grinding via the [x402 payment protocol](https://www.x402.org/) — $0.01 USDC per grind, zero setup:
|
|
165
170
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
```bash
|
|
172
|
+
# In your .env (enabled automatically when USE_X402=true)
|
|
173
|
+
USE_X402_GRIND=true
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The HTTP grinder races alongside any local grinders you have. First valid nonce wins. Front-running is cryptographically impossible — nonces are bound to `keccak256(challenge, msg.sender, nonce)`.
|
|
172
177
|
|
|
173
|
-
|
|
178
|
+
| Config | Description |
|
|
179
|
+
|--------|-------------|
|
|
180
|
+
| `USE_X402_GRIND` | Enable remote GPU grinding (default: same as `USE_X402`) |
|
|
181
|
+
| `GRIND_URL` | Custom GrindProxy endpoint (default: `https://grind.apow.io/grind`) |
|
|
174
182
|
|
|
175
|
-
|
|
183
|
+
Self-host your own GrindProxy: see [apow-grind](https://github.com/Agentoshi/apow-grind).
|
|
184
|
+
|
|
185
|
+
## GPU Mining (v0.9.2+)
|
|
186
|
+
|
|
187
|
+
The miner auto-detects native GPU and CPU grinder binaries for dramatically faster nonce grinding. Source files ship with the npm package — run `apow build-grinders` to compile and install to `~/.apow/`:
|
|
176
188
|
|
|
177
189
|
```bash
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
make cpu # builds grinder-cpu (multi-threaded C)
|
|
190
|
+
npx apow-cli build-grinders # auto-detects compilers + GPU arch
|
|
191
|
+
npx apow-cli build-grinders --cuda-arch sm_89 # override CUDA architecture
|
|
181
192
|
```
|
|
182
193
|
|
|
183
|
-
|
|
194
|
+
| Grinder | Platform | Speed | Requirements |
|
|
195
|
+
|---------|----------|-------|--------------|
|
|
196
|
+
| Metal GPU | macOS (Apple Silicon) | ~260-500 MH/s | Xcode CLI tools (`clang`) |
|
|
197
|
+
| CUDA | NVIDIA GPU | ~20 GH/s | CUDA toolkit (`nvcc`) |
|
|
198
|
+
| CPU-C | Any (multi-threaded C) | ~150-300 MH/s | `clang` or `gcc` |
|
|
199
|
+
| JS (fallback) | Any (worker_threads) | ~2-5 MH/s | Built-in, no setup |
|
|
200
|
+
|
|
201
|
+
All available grinders race in parallel — first valid nonce wins. Falls back to JS automatically if no native binaries are found.
|
|
184
202
|
|
|
185
203
|
### Remote GPU Setup (Vast.ai)
|
|
186
204
|
|
|
@@ -194,7 +212,7 @@ VAST_IP=<ip>
|
|
|
194
212
|
VAST_PORT=<port>
|
|
195
213
|
```
|
|
196
214
|
|
|
197
|
-
The CUDA grinder runs over SSH alongside your local Metal/CPU grinders
|
|
215
|
+
The CUDA grinder runs over SSH alongside your local Metal/CPU grinders — genuinely additive hash power.
|
|
198
216
|
|
|
199
217
|
### Other Optimizations
|
|
200
218
|
|
package/dist/bridge/constants.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.SLIPPAGE_BPS = exports.MIN_USDC = exports.MIN_ETH = exports.TOKENS = exp
|
|
|
5
5
|
exports.bridgeOutputAsset = bridgeOutputAsset;
|
|
6
6
|
exports.CHAIN_IDS = {
|
|
7
7
|
solana: "solana",
|
|
8
|
+
ethereum: "1",
|
|
8
9
|
base: "8453",
|
|
9
10
|
};
|
|
10
11
|
exports.TOKENS = {
|
|
@@ -13,6 +14,10 @@ exports.TOKENS = {
|
|
|
13
14
|
nativeWrapped: "So11111111111111111111111111111111111111112",
|
|
14
15
|
usdc: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
15
16
|
},
|
|
17
|
+
ethereum: {
|
|
18
|
+
native: "0x0000000000000000000000000000000000000000",
|
|
19
|
+
nativeWrapped: "0xC02aaA39b223FE8D0A5827d8EE69cFde63831e7e",
|
|
20
|
+
},
|
|
16
21
|
base: {
|
|
17
22
|
native: "0x0000000000000000000000000000000000000000",
|
|
18
23
|
nativeSquid: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Ethereum mainnet balance utilities for deposit detection.
|
|
3
|
+
// Uses viem (already a dependency) — no new packages needed.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getEthereumRpcUrl = getEthereumRpcUrl;
|
|
6
|
+
exports.getAddressBalance = getAddressBalance;
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const chains_1 = require("viem/chains");
|
|
9
|
+
const DEFAULT_ETHEREUM_RPC = "https://cloudflare-eth.com";
|
|
10
|
+
let client;
|
|
11
|
+
function getEthereumRpcUrl() {
|
|
12
|
+
return process.env.ETHEREUM_RPC_URL || DEFAULT_ETHEREUM_RPC;
|
|
13
|
+
}
|
|
14
|
+
function getClient() {
|
|
15
|
+
if (!client) {
|
|
16
|
+
client = (0, viem_1.createPublicClient)({
|
|
17
|
+
chain: chains_1.mainnet,
|
|
18
|
+
transport: (0, viem_1.http)(getEthereumRpcUrl()),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return client;
|
|
22
|
+
}
|
|
23
|
+
/** Get ETH balance for any address on Ethereum mainnet (used to detect deposits). */
|
|
24
|
+
async function getAddressBalance(address) {
|
|
25
|
+
const balance = await getClient().getBalance({
|
|
26
|
+
address: address,
|
|
27
|
+
});
|
|
28
|
+
return Number((0, viem_1.formatEther)(balance));
|
|
29
|
+
}
|
package/dist/bridge/squid.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Squid Router bridge — deposit address flow.
|
|
3
|
-
// Supports SOL→Base via Chainflip multi-hop (~1-3 minutes).
|
|
3
|
+
// Supports SOL→Base and ETH→Base via Chainflip multi-hop (~1-3 minutes).
|
|
4
4
|
// Requires SQUID_INTEGRATOR_ID (free, apply at squidrouter.com).
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SQUID_ROUTES = void 0;
|
|
@@ -25,11 +25,19 @@ exports.SQUID_ROUTES = {
|
|
|
25
25
|
srcDecimals: 6,
|
|
26
26
|
dstDecimals: 6,
|
|
27
27
|
},
|
|
28
|
+
eth_to_base_eth: {
|
|
29
|
+
fromChain: constants_1.CHAIN_IDS.ethereum,
|
|
30
|
+
fromToken: constants_1.TOKENS.ethereum.nativeWrapped,
|
|
31
|
+
toChain: constants_1.CHAIN_IDS.base,
|
|
32
|
+
toToken: constants_1.TOKENS.base.nativeSquid,
|
|
33
|
+
srcDecimals: 18,
|
|
34
|
+
dstDecimals: 18,
|
|
35
|
+
},
|
|
28
36
|
};
|
|
29
37
|
function getIntegratorId() {
|
|
30
38
|
const id = process.env.SQUID_INTEGRATOR_ID;
|
|
31
39
|
if (!id) {
|
|
32
|
-
throw new Error("SQUID_INTEGRATOR_ID is required for bridging
|
|
40
|
+
throw new Error("SQUID_INTEGRATOR_ID is required for bridging.\n" +
|
|
33
41
|
"Get one free at https://app.squidrouter.com/");
|
|
34
42
|
}
|
|
35
43
|
return id;
|
|
@@ -68,6 +76,15 @@ async function getDepositAddress(baseAddress, amount, route = exports.SQUID_ROUT
|
|
|
68
76
|
if (routeData.error) {
|
|
69
77
|
throw new Error(`Squid route error: ${routeData.error.message || JSON.stringify(routeData.error)}`);
|
|
70
78
|
}
|
|
79
|
+
// Guard: if the route returned a transactionRequest instead of supporting
|
|
80
|
+
// deposit-address flow, the source chain likely requires a contract call
|
|
81
|
+
// (e.g., EVM chains without Chainflip deposit address support).
|
|
82
|
+
const tx = routeData.route?.transactionRequest;
|
|
83
|
+
if (tx && !routeData.route?.params?.prefer?.includes("CHAINFLIP_DEPOSIT_ADDRESS")) {
|
|
84
|
+
throw new Error("DEPOSIT_ADDRESS_UNAVAILABLE: Squid returned a contract-call route instead of a deposit address for this chain.\n" +
|
|
85
|
+
"This means the bridge requires an on-chain transaction from the source chain.\n" +
|
|
86
|
+
"Use an alternative: bridge.base.org, send ETH on Base directly, or bridge from Solana.");
|
|
87
|
+
}
|
|
71
88
|
// Step 2: Request deposit address from route
|
|
72
89
|
const depositResponse = await fetch(`${SQUID_API}/deposit-address`, {
|
|
73
90
|
method: "POST",
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Build native grinder binaries for GPU/CPU mining.
|
|
4
|
+
*
|
|
5
|
+
* Auto-detects available compilers and GPU architecture, then compiles
|
|
6
|
+
* whichever grinders are possible on the current platform:
|
|
7
|
+
* - CPU-C (any platform with clang or gcc)
|
|
8
|
+
* - CUDA (Linux/Windows with nvcc + NVIDIA GPU)
|
|
9
|
+
* - Metal (macOS with clang)
|
|
10
|
+
*
|
|
11
|
+
* Installs compiled binaries to ~/.apow/ where auto-detection will find them.
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.buildGrinders = buildGrinders;
|
|
51
|
+
const node_child_process_1 = require("node:child_process");
|
|
52
|
+
const node_fs_1 = require("node:fs");
|
|
53
|
+
const node_path_1 = require("node:path");
|
|
54
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
55
|
+
const ui = __importStar(require("./ui"));
|
|
56
|
+
const INSTALL_DIR = (0, node_path_1.join)(node_os_1.default.homedir(), ".apow");
|
|
57
|
+
function findSourceDir() {
|
|
58
|
+
// Check relative to this file's compiled location (dist/)
|
|
59
|
+
const fromDist = (0, node_path_1.join)((0, node_path_1.dirname)(__dirname), "local", "gpu");
|
|
60
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(fromDist, "grinder-cpu.c")))
|
|
61
|
+
return fromDist;
|
|
62
|
+
// Check CWD (git clone case)
|
|
63
|
+
const fromCwd = (0, node_path_1.join)(process.cwd(), "local", "gpu");
|
|
64
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(fromCwd, "grinder-cpu.c")))
|
|
65
|
+
return fromCwd;
|
|
66
|
+
const fromCwdGpu = (0, node_path_1.join)(process.cwd(), "gpu");
|
|
67
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(fromCwdGpu, "grinder-cpu.c")))
|
|
68
|
+
return fromCwdGpu;
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
function which(cmd) {
|
|
72
|
+
try {
|
|
73
|
+
(0, node_child_process_1.execSync)(`which ${cmd}`, { stdio: "ignore" });
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function detectCudaArch() {
|
|
81
|
+
try {
|
|
82
|
+
const raw = (0, node_child_process_1.execSync)("nvidia-smi --query-gpu=compute_cap --format=csv,noheader", { encoding: "utf8", timeout: 5000 }).trim();
|
|
83
|
+
// e.g. "8.9" → "sm_89"
|
|
84
|
+
const first = raw.split("\n")[0].trim();
|
|
85
|
+
if (/^\d+\.\d+$/.test(first)) {
|
|
86
|
+
return "sm_" + first.replace(".", "");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch { }
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function buildCpuC(sourceDir) {
|
|
93
|
+
const src = (0, node_path_1.join)(sourceDir, "grinder-cpu.c");
|
|
94
|
+
const out = (0, node_path_1.join)(INSTALL_DIR, "grinder-cpu");
|
|
95
|
+
const name = "CPU-C";
|
|
96
|
+
if (!(0, node_fs_1.existsSync)(src)) {
|
|
97
|
+
return { name, success: false, error: "source file not found" };
|
|
98
|
+
}
|
|
99
|
+
// Prefer clang, fall back to gcc
|
|
100
|
+
const cc = which("clang") ? "clang" : which("gcc") ? "gcc" : null;
|
|
101
|
+
if (!cc) {
|
|
102
|
+
return { name, success: false, error: "no C compiler found (need clang or gcc)" };
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
(0, node_child_process_1.execSync)(`${cc} -O2 -pthread "${src}" -o "${out}"`, {
|
|
106
|
+
stdio: "pipe",
|
|
107
|
+
timeout: 60000,
|
|
108
|
+
});
|
|
109
|
+
(0, node_fs_1.chmodSync)(out, 0o755);
|
|
110
|
+
return { name, success: true, path: out };
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
114
|
+
return { name, success: false, error: msg.split("\n")[0] };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function buildCuda(sourceDir, archOverride) {
|
|
118
|
+
const src = (0, node_path_1.join)(sourceDir, "grinder-cuda.cu");
|
|
119
|
+
const out = (0, node_path_1.join)(INSTALL_DIR, "grinder-cuda");
|
|
120
|
+
const name = "CUDA";
|
|
121
|
+
if (!(0, node_fs_1.existsSync)(src)) {
|
|
122
|
+
return { name, success: false, error: "source file not found" };
|
|
123
|
+
}
|
|
124
|
+
if (!which("nvcc")) {
|
|
125
|
+
return { name, success: false, error: "nvcc not found (install CUDA toolkit)" };
|
|
126
|
+
}
|
|
127
|
+
const arch = archOverride ?? detectCudaArch() ?? "sm_89";
|
|
128
|
+
try {
|
|
129
|
+
(0, node_child_process_1.execSync)(`nvcc "${src}" -o "${out}" -std=c++17 -O3 -arch=${arch}`, { stdio: "pipe", timeout: 120000 });
|
|
130
|
+
(0, node_fs_1.chmodSync)(out, 0o755);
|
|
131
|
+
return { name: `CUDA (${arch})`, success: true, path: out };
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
135
|
+
return { name, success: false, error: msg.split("\n")[0] };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function buildMetal(sourceDir) {
|
|
139
|
+
const src = (0, node_path_1.join)(sourceDir, "grinder.m");
|
|
140
|
+
const out = (0, node_path_1.join)(INSTALL_DIR, "grinder-gpu");
|
|
141
|
+
const name = "Metal GPU";
|
|
142
|
+
if (process.platform !== "darwin") {
|
|
143
|
+
return { name, success: false, error: "macOS only" };
|
|
144
|
+
}
|
|
145
|
+
if (!(0, node_fs_1.existsSync)(src)) {
|
|
146
|
+
return { name, success: false, error: "source file not found" };
|
|
147
|
+
}
|
|
148
|
+
if (!which("clang")) {
|
|
149
|
+
return { name, success: false, error: "clang not found (install Xcode CLI tools)" };
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
(0, node_child_process_1.execSync)(`clang -O2 -framework Metal -framework Foundation "${src}" -o "${out}"`, { stdio: "pipe", timeout: 60000 });
|
|
153
|
+
(0, node_fs_1.chmodSync)(out, 0o755);
|
|
154
|
+
// Copy Metal shader alongside binary — grinder loads it at runtime from CWD
|
|
155
|
+
const shader = (0, node_path_1.join)(sourceDir, "keccak.metal");
|
|
156
|
+
if ((0, node_fs_1.existsSync)(shader)) {
|
|
157
|
+
(0, node_fs_1.copyFileSync)(shader, (0, node_path_1.join)(INSTALL_DIR, "keccak.metal"));
|
|
158
|
+
}
|
|
159
|
+
return { name, success: true, path: out };
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
163
|
+
return { name, success: false, error: msg.split("\n")[0] };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function buildGrinders(opts) {
|
|
167
|
+
console.log("");
|
|
168
|
+
ui.banner(["Build Native Grinders"]);
|
|
169
|
+
console.log("");
|
|
170
|
+
// Find source files
|
|
171
|
+
const sourceDir = findSourceDir();
|
|
172
|
+
if (!sourceDir) {
|
|
173
|
+
ui.error("Grinder source files not found.");
|
|
174
|
+
ui.hint("Ensure local/gpu/ exists (included in npm package since v0.9.2)");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
console.log(` Source: ${ui.dim(sourceDir)}`);
|
|
178
|
+
// Create install directory
|
|
179
|
+
if (!(0, node_fs_1.existsSync)(INSTALL_DIR)) {
|
|
180
|
+
(0, node_fs_1.mkdirSync)(INSTALL_DIR, { recursive: true });
|
|
181
|
+
}
|
|
182
|
+
console.log(` Install: ${ui.dim(INSTALL_DIR)}`);
|
|
183
|
+
console.log("");
|
|
184
|
+
// Build each grinder
|
|
185
|
+
const results = [];
|
|
186
|
+
const cpuSpinner = ui.spinner("Building CPU-C grinder...");
|
|
187
|
+
const cpuResult = buildCpuC(sourceDir);
|
|
188
|
+
results.push(cpuResult);
|
|
189
|
+
if (cpuResult.success) {
|
|
190
|
+
cpuSpinner.stop(`Building CPU-C grinder... ${ui.green("OK")}`);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
cpuSpinner.stop(`Building CPU-C grinder... ${ui.yellow("skipped")} (${cpuResult.error})`);
|
|
194
|
+
}
|
|
195
|
+
const cudaSpinner = ui.spinner("Building CUDA grinder...");
|
|
196
|
+
const cudaResult = buildCuda(sourceDir, opts.cudaArch);
|
|
197
|
+
results.push(cudaResult);
|
|
198
|
+
if (cudaResult.success) {
|
|
199
|
+
cudaSpinner.stop(`Building CUDA grinder... ${ui.green("OK")}`);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
cudaSpinner.stop(`Building CUDA grinder... ${ui.yellow("skipped")} (${cudaResult.error})`);
|
|
203
|
+
}
|
|
204
|
+
const metalSpinner = ui.spinner("Building Metal GPU grinder...");
|
|
205
|
+
const metalResult = buildMetal(sourceDir);
|
|
206
|
+
results.push(metalResult);
|
|
207
|
+
if (metalResult.success) {
|
|
208
|
+
metalSpinner.stop(`Building Metal GPU grinder... ${ui.green("OK")}`);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
metalSpinner.stop(`Building Metal GPU grinder... ${ui.yellow("skipped")} (${metalResult.error})`);
|
|
212
|
+
}
|
|
213
|
+
// Summary
|
|
214
|
+
console.log("");
|
|
215
|
+
const built = results.filter((r) => r.success);
|
|
216
|
+
if (built.length === 0) {
|
|
217
|
+
ui.warn("No grinders could be built on this system.");
|
|
218
|
+
console.log("");
|
|
219
|
+
console.log(` ${ui.dim("Requirements:")}`);
|
|
220
|
+
console.log(` ${ui.dim(" CPU-C: clang or gcc")}`);
|
|
221
|
+
console.log(` ${ui.dim(" CUDA: nvcc + NVIDIA GPU (nvidia-smi)")}`);
|
|
222
|
+
console.log(` ${ui.dim(" Metal: macOS + Xcode CLI tools")}`);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
ui.ok(`Built ${built.length} grinder${built.length > 1 ? "s" : ""}:`);
|
|
226
|
+
for (const r of built) {
|
|
227
|
+
console.log(` ${ui.green(r.name)} → ${ui.dim(r.path)}`);
|
|
228
|
+
}
|
|
229
|
+
console.log("");
|
|
230
|
+
console.log(` Grinders installed to ${ui.cyan("~/.apow/")} — auto-detected on next mine.`);
|
|
231
|
+
console.log(` Run ${ui.cyan("apow mine")} to start GPU mining.`);
|
|
232
|
+
}
|
|
233
|
+
console.log("");
|
|
234
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.config = void 0;
|
|
7
|
+
exports.resolveDefaultModel = resolveDefaultModel;
|
|
7
8
|
exports.requirePrivateKey = requirePrivateKey;
|
|
8
9
|
exports.requireLlmApiKey = requireLlmApiKey;
|
|
9
10
|
exports.isExpensiveModel = isExpensiveModel;
|
|
@@ -15,19 +16,30 @@ const node_path_1 = require("node:path");
|
|
|
15
16
|
const chains_1 = require("viem/chains");
|
|
16
17
|
(0, dotenv_1.config)();
|
|
17
18
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
18
|
-
const DEFAULT_LLM_PROVIDER = "openai";
|
|
19
|
-
const DEFAULT_LLM_MODEL = "gpt-4o-mini";
|
|
20
19
|
const DEFAULT_OLLAMA_URL = "http://127.0.0.1:11434";
|
|
21
20
|
const DEFAULT_CHAIN_NAME = "base";
|
|
22
21
|
const DEFAULT_MINING_AGENT_ADDRESS = "0xB7caD3ca5F2BD8aEC2Eb67d6E8D448099B3bC03D";
|
|
23
22
|
const DEFAULT_AGENT_COIN_ADDRESS = "0x12577CF0D8a07363224D6909c54C056A183e13b3";
|
|
24
23
|
const EXPENSIVE_MODELS = ["gpt-4o", "gpt-4", "claude-3-opus", "claude-3-5-sonnet"];
|
|
25
24
|
const CHEAP_OVERRIDES = ["gpt-4o-mini", "gpt-4-mini"];
|
|
26
|
-
function normalizeProvider(value) {
|
|
25
|
+
function normalizeProvider(value, useX402) {
|
|
27
26
|
if (value === "anthropic" || value === "ollama" || value === "openai" || value === "gemini" || value === "claude-code" || value === "codex" || value === "deepseek" || value === "qwen" || value === "clawrouter") {
|
|
28
27
|
return value;
|
|
29
28
|
}
|
|
30
|
-
|
|
29
|
+
// No explicit provider: x402 users get clawrouter (zero-credential stack), others get openai
|
|
30
|
+
return useX402 ? "clawrouter" : "openai";
|
|
31
|
+
}
|
|
32
|
+
function resolveDefaultModel(provider) {
|
|
33
|
+
switch (provider) {
|
|
34
|
+
case "clawrouter": return "blockrun/eco";
|
|
35
|
+
case "gemini": return "gemini-2.5-flash";
|
|
36
|
+
case "anthropic": return "claude-sonnet-4-5-20250929";
|
|
37
|
+
case "deepseek": return "deepseek-chat";
|
|
38
|
+
case "qwen": return "qwen-plus";
|
|
39
|
+
case "claude-code":
|
|
40
|
+
case "codex": return "default";
|
|
41
|
+
default: return "gpt-4o-mini";
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
44
|
function resolveChainName() {
|
|
33
45
|
const envChain = process.env.CHAIN;
|
|
@@ -75,13 +87,15 @@ function resolveLlmApiKey(provider) {
|
|
|
75
87
|
}
|
|
76
88
|
}
|
|
77
89
|
const chainName = resolveChainName();
|
|
90
|
+
const useX402 = process.env.USE_X402 === "true";
|
|
91
|
+
const resolvedProvider = normalizeProvider(process.env.LLM_PROVIDER, useX402);
|
|
78
92
|
exports.config = {
|
|
79
93
|
privateKey: parsePrivateKey(process.env.PRIVATE_KEY),
|
|
80
94
|
rpcUrl: process.env.RPC_URL ?? "",
|
|
81
|
-
useX402
|
|
82
|
-
llmProvider:
|
|
83
|
-
llmApiKey: resolveLlmApiKey(
|
|
84
|
-
llmModel: process.env.LLM_MODEL ??
|
|
95
|
+
useX402,
|
|
96
|
+
llmProvider: resolvedProvider,
|
|
97
|
+
llmApiKey: resolveLlmApiKey(resolvedProvider),
|
|
98
|
+
llmModel: process.env.LLM_MODEL ?? resolveDefaultModel(resolvedProvider),
|
|
85
99
|
ollamaUrl: process.env.OLLAMA_URL ?? DEFAULT_OLLAMA_URL,
|
|
86
100
|
chain: chainName === "baseSepolia" ? chains_1.baseSepolia : chains_1.base,
|
|
87
101
|
chainName,
|
|
@@ -91,10 +105,15 @@ exports.config = {
|
|
|
91
105
|
grinderMode: (process.env.GRINDER_MODE === "js" ? "js" : "auto"),
|
|
92
106
|
gpuGrinderPath: process.env.GPU_GRINDER_PATH,
|
|
93
107
|
cpuGrinderPath: process.env.CPU_GRINDER_PATH,
|
|
108
|
+
cudaGrinderPath: process.env.CUDA_GRINDER_PATH,
|
|
94
109
|
vastIp: process.env.VAST_IP,
|
|
95
110
|
vastPort: process.env.VAST_PORT,
|
|
96
111
|
cpuGrinderThreads: parseInt(process.env.CPU_THREADS ?? String(node_os_1.default.cpus().length), 10),
|
|
97
112
|
remoteGrinderPath: process.env.REMOTE_GRINDER ?? "/root/grinder-cuda",
|
|
113
|
+
grindUrl: process.env.GRIND_URL,
|
|
114
|
+
useX402Grind: process.env.USE_X402_GRIND !== undefined
|
|
115
|
+
? process.env.USE_X402_GRIND === "true"
|
|
116
|
+
: useX402, // defaults to USE_X402 value when not explicitly set
|
|
98
117
|
};
|
|
99
118
|
function requirePrivateKey() {
|
|
100
119
|
if (!exports.config.privateKey) {
|
package/dist/errors.js
CHANGED
|
@@ -109,6 +109,30 @@ const patterns = [
|
|
|
109
109
|
recovery: "Send USDC to your wallet on Base",
|
|
110
110
|
}),
|
|
111
111
|
},
|
|
112
|
+
{
|
|
113
|
+
test: (m) => m.includes("GrindProxy") && /\b502\b/.test(m),
|
|
114
|
+
classify: () => ({
|
|
115
|
+
category: "transient",
|
|
116
|
+
userMessage: "Remote GPU backend unavailable",
|
|
117
|
+
recovery: "GrindProxy will retry automatically. Local grinders continue racing.",
|
|
118
|
+
}),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
test: (m) => m.includes("Remote GPU grind timed out") || (m.includes("GrindProxy") && /\b504\b/.test(m)),
|
|
122
|
+
classify: () => ({
|
|
123
|
+
category: "transient",
|
|
124
|
+
userMessage: "Remote GPU grind timed out (90s)",
|
|
125
|
+
recovery: "High difficulty — local grinders may still find a nonce.",
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
test: (m) => m.includes("x402 GPU grind payment failed"),
|
|
130
|
+
classify: () => ({
|
|
131
|
+
category: "setup",
|
|
132
|
+
userMessage: "Insufficient USDC for x402 GPU grinding ($0.01/grind)",
|
|
133
|
+
recovery: "Send USDC to your wallet on Base, or set USE_X402_GRIND=false to disable remote grinding",
|
|
134
|
+
}),
|
|
135
|
+
},
|
|
112
136
|
{
|
|
113
137
|
test: (m) => m.includes("INSUFFICIENT_OUTPUT_AMOUNT") || m.includes("Too little received"),
|
|
114
138
|
classify: () => ({
|