apow-cli 0.11.10 → 0.11.12
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/dist/index.js +11 -3
- package/dist/miner.js +6 -21
- package/dist/mint.js +44 -22
- package/dist/preflight.js +33 -27
- package/dist/smhl.js +3 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -522,17 +522,25 @@ async function main() {
|
|
|
522
522
|
const miningAccount = wallet_1.account;
|
|
523
523
|
let tokenId;
|
|
524
524
|
if (tokenIdArg) {
|
|
525
|
-
await (0, preflight_1.runPreflight)("mining");
|
|
526
525
|
tokenId = parseTokenId(tokenIdArg);
|
|
526
|
+
await (0, preflight_1.runPreflight)("mining");
|
|
527
527
|
}
|
|
528
528
|
else {
|
|
529
|
-
|
|
529
|
+
await (0, preflight_1.runPreflight)("mining");
|
|
530
|
+
let miners;
|
|
531
|
+
try {
|
|
532
|
+
miners = await (0, detect_1.detectMiners)(miningAccount.address);
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
ui.error("Could not detect mining rigs — RPC may be unreachable.");
|
|
536
|
+
ui.hint("Check your RPC_URL or USDC balance for x402, then retry.");
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
530
539
|
if (miners.length === 0) {
|
|
531
540
|
ui.warn("No mining rigs found — launching guided start flow.");
|
|
532
541
|
await runStartFlow();
|
|
533
542
|
return;
|
|
534
543
|
}
|
|
535
|
-
await (0, preflight_1.runPreflight)("mining");
|
|
536
544
|
tokenId = (0, detect_1.selectBestMiner)(miners).tokenId;
|
|
537
545
|
if (miners.length === 1) {
|
|
538
546
|
console.log(` Using miner #${tokenId} (${miners[0].rarityLabel}, ${(0, detect_1.formatHashpower)(miners[0].hashpower)})`);
|
package/dist/miner.js
CHANGED
|
@@ -241,26 +241,6 @@ function autoBuildGrinders() {
|
|
|
241
241
|
}
|
|
242
242
|
return built > 0;
|
|
243
243
|
}
|
|
244
|
-
async function grindNonce(challengeNumber, target, minerAddress, onProgress) {
|
|
245
|
-
let nonce = 0n;
|
|
246
|
-
let attempts = 0n;
|
|
247
|
-
const start = process.hrtime();
|
|
248
|
-
while (true) {
|
|
249
|
-
const digest = BigInt((0, viem_1.keccak256)((0, viem_1.encodePacked)(["bytes32", "address", "uint256"], [challengeNumber, minerAddress, nonce])));
|
|
250
|
-
attempts += 1n;
|
|
251
|
-
if (digest < target) {
|
|
252
|
-
const elapsed = elapsedSeconds(start);
|
|
253
|
-
const hashrate = elapsed > 0 ? Number(attempts) / elapsed : Number(attempts);
|
|
254
|
-
return { nonce, attempts, hashrate, elapsed };
|
|
255
|
-
}
|
|
256
|
-
if (onProgress && attempts % 50000n === 0n) {
|
|
257
|
-
const elapsed = elapsedSeconds(start);
|
|
258
|
-
const hashrate = elapsed > 0 ? Number(attempts) / elapsed : Number(attempts);
|
|
259
|
-
onProgress(attempts, hashrate);
|
|
260
|
-
}
|
|
261
|
-
nonce += 1n;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
244
|
function toBigInt(value) {
|
|
265
245
|
return typeof value === "bigint" ? value : BigInt(value);
|
|
266
246
|
}
|
|
@@ -492,7 +472,9 @@ async function startMining(tokenId) {
|
|
|
492
472
|
return;
|
|
493
473
|
staleTimer = setTimeout(async () => {
|
|
494
474
|
if (staleCheckStopped || abortController.signal.aborted || staleCheckInFlight) {
|
|
495
|
-
|
|
475
|
+
// Don't reschedule here — the in-flight check's finally block
|
|
476
|
+
// will reschedule when it completes. Rescheduling here causes
|
|
477
|
+
// exponential timer duplication over long sessions.
|
|
496
478
|
return;
|
|
497
479
|
}
|
|
498
480
|
staleCheckInFlight = true;
|
|
@@ -592,6 +574,9 @@ async function startMining(tokenId) {
|
|
|
592
574
|
}
|
|
593
575
|
throw err;
|
|
594
576
|
}
|
|
577
|
+
// Signal all losing grinders to stop — prevents zombie JS workers,
|
|
578
|
+
// HTTP fetches, and native processes from lingering between mines.
|
|
579
|
+
abortController.abort();
|
|
595
580
|
const khs = grind.hashrate > 0 ? (grind.hashrate / 1000).toFixed(0) : "?";
|
|
596
581
|
nonceSpinner.stop(`Nonce found (${grind.elapsed.toFixed(1)}s${grind.hashrate > 0 ? `, ${khs}k H/s` : ""})`);
|
|
597
582
|
// Final stale check: a challenge can change between the periodic
|
package/dist/mint.js
CHANGED
|
@@ -156,27 +156,42 @@ async function runMintFlow(options = {}) {
|
|
|
156
156
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
157
157
|
// Request challenge
|
|
158
158
|
const challengeSpinner = ui.spinner(`Requesting challenge${attempt > 1 ? ` (retry ${attempt}/2)` : ""}...`);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
let challengeReceipt;
|
|
160
|
+
try {
|
|
161
|
+
const challengeTx = await walletClient.writeContract({
|
|
162
|
+
address: config_1.config.miningAgentAddress,
|
|
163
|
+
abi: miningAgentAbi,
|
|
164
|
+
account,
|
|
165
|
+
functionName: "getChallenge",
|
|
166
|
+
args: [account.address],
|
|
167
|
+
});
|
|
168
|
+
challengeReceipt = await wallet_1.publicClient.waitForTransactionReceipt({ hash: challengeTx });
|
|
169
|
+
if (challengeReceipt.status === "reverted") {
|
|
170
|
+
throw new Error("Challenge request reverted on-chain");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
challengeSpinner.fail(`Requesting challenge... failed`);
|
|
175
|
+
throw error;
|
|
169
176
|
}
|
|
170
177
|
challengeSpinner.stop(`Requesting challenge${attempt > 1 ? ` (retry ${attempt}/2)` : ""}... done`);
|
|
171
|
-
//
|
|
172
|
-
// waiting for latest-state propagation
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
// Try reading the seed at the exact receipt block to avoid burning the 20s
|
|
179
|
+
// window waiting for latest-state propagation. Many public RPCs are NOT
|
|
180
|
+
// archive nodes, so they throw "header not found" for historical blocks —
|
|
181
|
+
// catch that and fall through to latest-state polling.
|
|
182
|
+
let challengeSeed = ZERO_SEED;
|
|
183
|
+
try {
|
|
184
|
+
challengeSeed = (await wallet_1.publicClient.readContract({
|
|
185
|
+
address: config_1.config.miningAgentAddress,
|
|
186
|
+
abi: miningAgentAbi,
|
|
187
|
+
functionName: "challengeSeeds",
|
|
188
|
+
args: [account.address],
|
|
189
|
+
blockNumber: challengeReceipt.blockNumber,
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// Non-archive RPC — fall through to latest-state polling below.
|
|
194
|
+
}
|
|
180
195
|
if (challengeSeed.toLowerCase() === ZERO_SEED.toLowerCase()) {
|
|
181
196
|
// Fall back to latest-state polling if the provider does not expose the
|
|
182
197
|
// just-mined storage view reliably.
|
|
@@ -198,9 +213,16 @@ async function runMintFlow(options = {}) {
|
|
|
198
213
|
// Solve SMHL
|
|
199
214
|
const challenge = deriveChallengeFromSeed(challengeSeed);
|
|
200
215
|
const smhlSpinner = ui.spinner("Solving SMHL...");
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
216
|
+
let solution;
|
|
217
|
+
try {
|
|
218
|
+
solution = await (0, smhl_1.solveSmhlChallenge)(challenge, (smhlAttempt) => {
|
|
219
|
+
smhlSpinner.update(`Solving SMHL... attempt ${smhlAttempt}/5`);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
smhlSpinner.fail("Solving SMHL... failed");
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
204
226
|
smhlSpinner.stop("Solving SMHL... done");
|
|
205
227
|
// Mint
|
|
206
228
|
const mintSpinner = ui.spinner("Minting...");
|
package/dist/preflight.js
CHANGED
|
@@ -132,6 +132,7 @@ async function runPreflight(level) {
|
|
|
132
132
|
// Check 2: RPC reachable + chain ID
|
|
133
133
|
// Skip when: no RPC configured at all, or x402 active but unfunded
|
|
134
134
|
const hasRpc = config_1.config.useX402 || !!config_1.config.rpcUrl;
|
|
135
|
+
let rpcReachable = false;
|
|
135
136
|
if (hasRpc && (!config_1.config.useX402 || x402Funded)) {
|
|
136
137
|
try {
|
|
137
138
|
const chainId = await wallet_1.publicClient.getChainId();
|
|
@@ -144,6 +145,7 @@ async function runPreflight(level) {
|
|
|
144
145
|
});
|
|
145
146
|
}
|
|
146
147
|
else {
|
|
148
|
+
rpcReachable = true;
|
|
147
149
|
results.push({ label: `RPC connected — ${config_1.config.chain.name}`, passed: true });
|
|
148
150
|
}
|
|
149
151
|
}
|
|
@@ -172,8 +174,8 @@ async function runPreflight(level) {
|
|
|
172
174
|
fix: "Run `apow setup` and choose Easy Mode, or set PRIVATE_KEY in .env (0x-prefixed 32-byte hex)",
|
|
173
175
|
});
|
|
174
176
|
}
|
|
175
|
-
// Check 4: Wallet has ETH
|
|
176
|
-
if (wallet_1.account) {
|
|
177
|
+
// Check 4: Wallet has ETH (skip if RPC already failed — avoids duplicate errors)
|
|
178
|
+
if (wallet_1.account && rpcReachable) {
|
|
177
179
|
try {
|
|
178
180
|
const balance = await wallet_1.publicClient.getBalance({ address: wallet_1.account.address });
|
|
179
181
|
const ethBalance = Number((0, viem_1.formatEther)(balance));
|
|
@@ -279,33 +281,37 @@ async function runPreflight(level) {
|
|
|
279
281
|
}
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
|
-
// Check 6: Contracts exist on-chain (bytecode check)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
284
|
+
// Check 6: Contracts exist on-chain (bytecode check) — skip if RPC is unreachable
|
|
285
|
+
if (!rpcReachable) {
|
|
286
|
+
// Don't pile on errors when RPC is already known to be down
|
|
287
|
+
}
|
|
288
|
+
else
|
|
289
|
+
try {
|
|
290
|
+
const [miningAgentCode, agentCoinCode] = await Promise.all([
|
|
291
|
+
wallet_1.publicClient.getCode({ address: config_1.config.miningAgentAddress }),
|
|
292
|
+
wallet_1.publicClient.getCode({ address: config_1.config.agentCoinAddress }),
|
|
293
|
+
]);
|
|
294
|
+
if (!miningAgentCode || miningAgentCode === "0x") {
|
|
295
|
+
results.push({
|
|
296
|
+
label: "MiningAgent contract not found on-chain",
|
|
297
|
+
passed: false,
|
|
298
|
+
fix: "Verify MINING_AGENT_ADDRESS is correct for this network",
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
else if (!agentCoinCode || agentCoinCode === "0x") {
|
|
302
|
+
results.push({
|
|
303
|
+
label: "AgentCoin contract not found on-chain",
|
|
304
|
+
passed: false,
|
|
305
|
+
fix: "Verify AGENT_COIN_ADDRESS is correct for this network",
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
results.push({ label: "Contracts verified on-chain", passed: true });
|
|
310
|
+
}
|
|
301
311
|
}
|
|
302
|
-
|
|
303
|
-
|
|
312
|
+
catch {
|
|
313
|
+
// Skip if contract addresses not configured (already caught above)
|
|
304
314
|
}
|
|
305
|
-
}
|
|
306
|
-
catch {
|
|
307
|
-
// Skip if contract addresses not configured (already caught above)
|
|
308
|
-
}
|
|
309
315
|
// Check: GrindProxy reachability (mining only, non-blocking)
|
|
310
316
|
if (level === "mining" && (0, grinder_http_1.isHttpGrinderConfigured)()) {
|
|
311
317
|
const grindUrl = (0, grinder_http_1.getGrindUrl)();
|
package/dist/smhl.js
CHANGED
|
@@ -475,7 +475,9 @@ async function solveSmhlChallenge(challenge, onAttempt) {
|
|
|
475
475
|
if (isPermanentProviderError(msg)) {
|
|
476
476
|
throw new Error(`SMHL solve failed with ${describeProvider(provider)}: ${msg}`);
|
|
477
477
|
}
|
|
478
|
-
feedback
|
|
478
|
+
// Don't pass network/provider error messages as LLM feedback —
|
|
479
|
+
// it confuses the prompt. Clear feedback so next attempt starts fresh.
|
|
480
|
+
feedback = undefined;
|
|
479
481
|
lastIssues = `attempt ${attempt} (${describeProvider(provider)}): ${msg}`;
|
|
480
482
|
break;
|
|
481
483
|
}
|