apow-cli 0.9.2 → 0.9.4
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 -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 +5 -0
- package/dist/config.js +26 -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 +4 -2
- package/dist/index.js +85 -60
- package/dist/miner.js +46 -27
- package/dist/preflight.js +27 -2
- package/local/gpu/grinder-cuda.cu +276 -50
- package/package.json +3 -1
- package/skill.md +56 -19
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,8 +28,14 @@ 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)
|
|
32
40
|
# Run `apow build-grinders` to compile native binaries automatically.
|
|
33
41
|
# GRINDER_MODE=auto # auto (default) or js (force JS-only)
|
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.006 | 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.006/grind (dynamic pricing tracks actual GPU cost), 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
CHANGED
|
@@ -151,6 +151,11 @@ function buildMetal(sourceDir) {
|
|
|
151
151
|
try {
|
|
152
152
|
(0, node_child_process_1.execSync)(`clang -O2 -framework Metal -framework Foundation "${src}" -o "${out}"`, { stdio: "pipe", timeout: 60000 });
|
|
153
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
|
+
}
|
|
154
159
|
return { name, success: true, path: out };
|
|
155
160
|
}
|
|
156
161
|
catch (e) {
|
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,
|
|
@@ -96,6 +110,10 @@ exports.config = {
|
|
|
96
110
|
vastPort: process.env.VAST_PORT,
|
|
97
111
|
cpuGrinderThreads: parseInt(process.env.CPU_THREADS ?? String(node_os_1.default.cpus().length), 10),
|
|
98
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
|
|
99
117
|
};
|
|
100
118
|
function requirePrivateKey() {
|
|
101
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",
|
|
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: () => ({
|
package/dist/fund.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Fund command — unified funding for mining on Base.
|
|
3
|
-
// Accepts deposits from Solana (via Squid Router bridge) or Base (direct send),
|
|
3
|
+
// Accepts deposits from Solana/Ethereum (via Squid Router bridge) or Base (direct send),
|
|
4
4
|
// auto-splits into ETH (gas) + USDC (x402 RPC).
|
|
5
5
|
//
|
|
6
6
|
// Deposit types:
|
|
7
7
|
// 1. Solana SOL → bridge → ETH on Base → swap portion to USDC
|
|
8
8
|
// 2. Solana USDC → bridge → USDC on Base → swap portion to ETH
|
|
9
|
-
// 3.
|
|
10
|
-
// 4. Base
|
|
9
|
+
// 3. Ethereum ETH → bridge → ETH on Base → swap portion to USDC
|
|
10
|
+
// 4. Base ETH → (already there) → swap portion to USDC
|
|
11
|
+
// 5. Base USDC → (already there) → swap portion to ETH
|
|
11
12
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
13
|
if (k2 === undefined) k2 = k;
|
|
13
14
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -288,6 +289,87 @@ async function runSolanaFund(baseAddress, sourceToken, targetEth) {
|
|
|
288
289
|
await showFinalBalances();
|
|
289
290
|
}
|
|
290
291
|
// ---------------------------------------------------------------------------
|
|
292
|
+
// Ethereum fund (Squid Router deposit address)
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
async function runEthereumFund(baseAddress, targetEth) {
|
|
295
|
+
const priceSpinner = ui.spinner("Fetching prices...");
|
|
296
|
+
const prices = await fetchPrices();
|
|
297
|
+
priceSpinner.stop(`ETH price: $${prices.ethPriceUsd.toFixed(0)}`);
|
|
298
|
+
// ETH→ETH bridge is ~1:1, add 5% buffer for bridge fees
|
|
299
|
+
const amount = targetEth * 1.05;
|
|
300
|
+
const addrSpinner = ui.spinner("Generating deposit address...");
|
|
301
|
+
const squid = await Promise.resolve().then(() => __importStar(require("./bridge/squid")));
|
|
302
|
+
let deposit;
|
|
303
|
+
try {
|
|
304
|
+
deposit = await squid.getDepositAddress(baseAddress, amount, squid.SQUID_ROUTES.eth_to_base_eth);
|
|
305
|
+
}
|
|
306
|
+
catch (err) {
|
|
307
|
+
addrSpinner.fail("Failed to get deposit address");
|
|
308
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
309
|
+
if (msg.includes("DEPOSIT_ADDRESS_UNAVAILABLE")) {
|
|
310
|
+
console.log("");
|
|
311
|
+
ui.warn("Squid Router doesn't support deposit addresses for Ethereum.");
|
|
312
|
+
console.log(" Alternatives:");
|
|
313
|
+
console.log(` ${ui.cyan("1.")} Bridge via ${ui.bold("bridge.base.org")} → paste your mining wallet as recipient`);
|
|
314
|
+
console.log(` ${ui.cyan("2.")} Send ETH on Base directly: ${ui.cyan("apow fund --chain base")}`);
|
|
315
|
+
console.log(` ${ui.cyan("3.")} Bridge from Solana instead: ${ui.cyan("apow fund --chain solana")}`);
|
|
316
|
+
console.log("");
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
throw err;
|
|
320
|
+
}
|
|
321
|
+
addrSpinner.stop("Deposit address ready");
|
|
322
|
+
console.log("");
|
|
323
|
+
console.log(` ${ui.bold("Send ETH on Ethereum mainnet to this address:")}`);
|
|
324
|
+
console.log("");
|
|
325
|
+
console.log(` ${ui.cyan(deposit.depositAddress)}`);
|
|
326
|
+
console.log("");
|
|
327
|
+
await showQrCode(deposit.depositAddress);
|
|
328
|
+
console.log("");
|
|
329
|
+
ui.table([
|
|
330
|
+
["Amount", `~${amount.toFixed(6)} ETH`],
|
|
331
|
+
["You'll receive", `~${deposit.expectedReceive} ETH on Base`],
|
|
332
|
+
["Bridge", "Squid Router (Chainflip)"],
|
|
333
|
+
["Time", "~1-3 minutes"],
|
|
334
|
+
]);
|
|
335
|
+
console.log("");
|
|
336
|
+
if (deposit.expiresAt) {
|
|
337
|
+
ui.warn(`Deposit address expires: ${deposit.expiresAt}`);
|
|
338
|
+
console.log("");
|
|
339
|
+
}
|
|
340
|
+
// Poll for deposit on Ethereum mainnet
|
|
341
|
+
const ethereum = await Promise.resolve().then(() => __importStar(require("./bridge/ethereum")));
|
|
342
|
+
const depositSpinner = ui.spinner("Waiting for ETH deposit on Ethereum mainnet... (Ctrl+C to cancel)");
|
|
343
|
+
const initialBalance = await ethereum.getAddressBalance(deposit.depositAddress);
|
|
344
|
+
let depositDetected = false;
|
|
345
|
+
const depositDeadline = Date.now() + 600_000;
|
|
346
|
+
while (!depositDetected && Date.now() < depositDeadline) {
|
|
347
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
348
|
+
try {
|
|
349
|
+
const currentBalance = await ethereum.getAddressBalance(deposit.depositAddress);
|
|
350
|
+
if (currentBalance > initialBalance + 0.0001) {
|
|
351
|
+
depositDetected = true;
|
|
352
|
+
depositSpinner.stop(`Deposit received! ${(currentBalance - initialBalance).toFixed(6)} ETH`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
// Transient RPC error
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (!depositDetected) {
|
|
360
|
+
depositSpinner.fail("No ETH deposit detected after 10 minutes");
|
|
361
|
+
ui.hint("If you sent ETH, check: https://explorer.squidrouter.com");
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
// Poll for bridge completion
|
|
365
|
+
const bridgeSpinner = ui.spinner("Bridging to Base... (~1-3 min)");
|
|
366
|
+
const result = await (0, squid_1.pollBridgeStatus)(deposit.requestId, 18, (status) => bridgeSpinner.update(`Bridge status: ${status}`));
|
|
367
|
+
const received = result.received || deposit.expectedReceive;
|
|
368
|
+
bridgeSpinner.stop(`Bridge complete! ${received} ETH arrived`);
|
|
369
|
+
await autoSplit("eth", prices, false);
|
|
370
|
+
await showFinalBalances();
|
|
371
|
+
}
|
|
372
|
+
// ---------------------------------------------------------------------------
|
|
291
373
|
// Base manual send (already on the right chain)
|
|
292
374
|
// ---------------------------------------------------------------------------
|
|
293
375
|
async function runBaseFund(baseAddress, sourceToken, noSwap) {
|
|
@@ -356,12 +438,20 @@ async function runBaseFund(baseAddress, sourceToken, noSwap) {
|
|
|
356
438
|
async function selectSourceChain() {
|
|
357
439
|
console.log(" Where are your funds?");
|
|
358
440
|
console.log(` ${ui.cyan("1.")} Solana (SOL or USDC)`);
|
|
359
|
-
console.log(` ${ui.cyan("2.")}
|
|
441
|
+
console.log(` ${ui.cyan("2.")} Ethereum mainnet (ETH)`);
|
|
442
|
+
console.log(` ${ui.cyan("3.")} Base (send ETH or USDC directly)`);
|
|
360
443
|
console.log("");
|
|
361
444
|
const choice = await ui.prompt("Choice", "1");
|
|
362
|
-
|
|
445
|
+
if (choice === "2")
|
|
446
|
+
return "ethereum";
|
|
447
|
+
if (choice === "3")
|
|
448
|
+
return "base";
|
|
449
|
+
return "solana";
|
|
363
450
|
}
|
|
364
451
|
async function selectSourceToken(chain) {
|
|
452
|
+
// Ethereum only supports native ETH — skip token prompt
|
|
453
|
+
if (chain === "ethereum")
|
|
454
|
+
return "native";
|
|
365
455
|
const nativeLabel = chain === "solana" ? "SOL" : "ETH";
|
|
366
456
|
console.log("");
|
|
367
457
|
console.log(" What token?");
|
|
@@ -377,6 +467,8 @@ function parseSourceChain(value) {
|
|
|
377
467
|
const v = value.toLowerCase();
|
|
378
468
|
if (v === "solana" || v === "sol")
|
|
379
469
|
return "solana";
|
|
470
|
+
if (v === "ethereum" || v === "eth" || v === "mainnet")
|
|
471
|
+
return "ethereum";
|
|
380
472
|
if (v === "base")
|
|
381
473
|
return "base";
|
|
382
474
|
return undefined;
|
|
@@ -443,6 +535,10 @@ async function runFundFlow(options) {
|
|
|
443
535
|
await runSolanaFund(baseAddress, token, targetEth);
|
|
444
536
|
break;
|
|
445
537
|
}
|
|
538
|
+
case "ethereum": {
|
|
539
|
+
await runEthereumFund(baseAddress, targetEth);
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
446
542
|
case "base": {
|
|
447
543
|
await runBaseFund(baseAddress, token, noSwap);
|
|
448
544
|
break;
|