apow-cli 0.12.0 → 0.12.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/dist/wallet.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walletClient = exports.account = exports.publicClient = void 0;
3
+ exports.walletClient = exports.account = exports.publicClient = exports.DATA_SUFFIX = void 0;
4
4
  exports.reinitClients = reinitClients;
5
5
  exports.getFundingClients = getFundingClients;
6
6
  exports.requireWallet = requireWallet;
@@ -10,10 +10,12 @@ const erc8021_1 = require("ox/erc8021");
10
10
  const config_1 = require("./config");
11
11
  const local_keystore_1 = require("./signer/local-keystore");
12
12
  const x402_1 = require("./x402");
13
- const DATA_SUFFIX = erc8021_1.Attribution.toDataSuffix({ codes: ["bc_6wfeb1kd"] });
13
+ exports.DATA_SUFFIX = erc8021_1.Attribution.toDataSuffix({ codes: ["bc_6wfeb1kd"] });
14
+ const FREE_BASE_RPC = "https://base.publicnode.com";
14
15
  function getTransport() {
15
16
  const signer = (0, local_keystore_1.getSigner)();
16
17
  if (config_1.config.useX402 && signer) {
18
+ // Easy Mode: every RPC call is paid through x402 (AKLO, Dec 2: RPC, AI and GPU all on x402).
17
19
  return (0, x402_1.createX402Transport)(signer.account);
18
20
  }
19
21
  return (0, viem_1.http)(config_1.config.rpcUrl);
@@ -29,7 +31,7 @@ exports.walletClient = exports.account
29
31
  account: exports.account,
30
32
  chain: config_1.config.chain,
31
33
  transport,
32
- dataSuffix: DATA_SUFFIX,
34
+ dataSuffix: exports.DATA_SUFFIX,
33
35
  })
34
36
  : null;
35
37
  let bootstrapPublicClient = (0, viem_1.createPublicClient)({
@@ -42,14 +44,14 @@ let bootstrapWalletClient = bootstrapAccount
42
44
  account: bootstrapAccount,
43
45
  chain: config_1.config.chain,
44
46
  transport: getBootstrapTransport(),
45
- dataSuffix: DATA_SUFFIX,
47
+ dataSuffix: exports.DATA_SUFFIX,
46
48
  })
47
49
  : null;
48
50
  function shouldUseBootstrapFundingClients() {
49
- return config_1.config.useX402 && config_1.config.chainName === "base" && !!config_1.config.rpcUrl;
51
+ return config_1.config.chainName === "base";
50
52
  }
51
53
  function getBootstrapTransport() {
52
- return config_1.config.rpcUrl ? (0, viem_1.http)(config_1.config.rpcUrl) : transport;
54
+ return config_1.config.chainName === "base" ? (0, viem_1.http)(config_1.config.rpcUrl || FREE_BASE_RPC) : transport;
53
55
  }
54
56
  /** Reinitialize clients after config changes (e.g., x402 fallback). */
55
57
  function reinitClients() {
@@ -62,7 +64,7 @@ function reinitClients() {
62
64
  account: exports.account,
63
65
  chain: config_1.config.chain,
64
66
  transport,
65
- dataSuffix: DATA_SUFFIX,
67
+ dataSuffix: exports.DATA_SUFFIX,
66
68
  })
67
69
  : null;
68
70
  bootstrapPublicClient = (0, viem_1.createPublicClient)({
@@ -75,7 +77,7 @@ function reinitClients() {
75
77
  account: bootstrapAccount,
76
78
  chain: config_1.config.chain,
77
79
  transport: getBootstrapTransport(),
78
- dataSuffix: DATA_SUFFIX,
80
+ dataSuffix: exports.DATA_SUFFIX,
79
81
  })
80
82
  : null;
81
83
  }
package/dist/x402.js CHANGED
@@ -33,35 +33,71 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.currentRpcPaymentModel = currentRpcPaymentModel;
36
37
  exports.createX402Transport = createX402Transport;
37
38
  exports.resetX402 = resetX402;
38
39
  const viem_1 = require("viem");
40
+ const gateway_1 = require("./gateway");
39
41
  const QUICKNODE_BASE = "https://x402.quicknode.com";
40
42
  const BASE_MAINNET = "eip155:8453";
41
43
  const X402_RPC_TIMEOUT_MS = 10_000;
42
- let _client = null;
43
- async function getClient(account) {
44
- if (_client && !_client.isTokenExpired())
45
- return _client;
44
+ const _clients = {};
45
+ let _gatewayOk = false;
46
+ let _gatewayCheckedAt = 0;
47
+ let _nanoPausedUntil = 0;
48
+ let _lastModel = null;
49
+ const MODEL_RECHECK_MS = 5 * 60_000;
50
+ /** QuickNode's nanopayment settlement rejects bursts; fall back to per-call payment for a while. */
51
+ const NANO_PAUSE_MS = 30_000;
52
+ async function clientFor(account, model) {
53
+ const existing = _clients[model];
54
+ if (existing && !existing.isTokenExpired())
55
+ return existing;
46
56
  const { createQuicknodeX402Client } = await Promise.resolve().then(() => __importStar(require("@quicknode/x402")));
47
- _client = await createQuicknodeX402Client({
57
+ const created = await createQuicknodeX402Client({
48
58
  baseUrl: QUICKNODE_BASE,
49
59
  network: BASE_MAINNET,
50
60
  evmSigner: account,
51
- paymentModel: "pay-per-request",
61
+ paymentModel: model,
52
62
  });
53
- return _client;
63
+ _clients[model] = created;
64
+ return created;
65
+ }
66
+ /** Nanopayments ($0.0001, batched by Circle) when the Gateway deposit covers them; else $0.001 per call. */
67
+ async function preferredModel(account) {
68
+ const now = Date.now();
69
+ if (now - _gatewayCheckedAt > MODEL_RECHECK_MS) {
70
+ const balance = await (0, gateway_1.getGatewayBalanceUsdc)(account.address);
71
+ _gatewayOk = balance !== null && balance >= gateway_1.GATEWAY_MIN_USDC;
72
+ _gatewayCheckedAt = now;
73
+ }
74
+ return _gatewayOk && now >= _nanoPausedUntil ? "nanopayment" : "pay-per-request";
75
+ }
76
+ function currentRpcPaymentModel() {
77
+ return _lastModel;
78
+ }
79
+ async function paidRpc(account, body) {
80
+ const model = await preferredModel(account);
81
+ _lastModel = model;
82
+ const send = async (m) => (await clientFor(account, m)).fetch(`${QUICKNODE_BASE}/base-mainnet`, {
83
+ method: "POST",
84
+ headers: { "Content-Type": "application/json" },
85
+ body,
86
+ signal: AbortSignal.timeout(X402_RPC_TIMEOUT_MS),
87
+ });
88
+ const response = await send(model);
89
+ if (response.status === 402 && model === "nanopayment") {
90
+ // A rejected nanopayment was not settled; retry once paying per call.
91
+ _nanoPausedUntil = Date.now() + NANO_PAUSE_MS;
92
+ _lastModel = "pay-per-request";
93
+ return send("pay-per-request");
94
+ }
95
+ return response;
54
96
  }
55
97
  function createX402Transport(account) {
56
98
  return (0, viem_1.custom)({
57
99
  async request({ method, params }) {
58
- const client = await getClient(account);
59
- const response = await client.fetch(`${QUICKNODE_BASE}/base-mainnet`, {
60
- method: "POST",
61
- headers: { "Content-Type": "application/json" },
62
- body: JSON.stringify({ jsonrpc: "2.0", method, params, id: 1 }),
63
- signal: AbortSignal.timeout(X402_RPC_TIMEOUT_MS),
64
- });
100
+ const response = await paidRpc(account, JSON.stringify({ jsonrpc: "2.0", method, params, id: 1 }));
65
101
  if (response.status === 402) {
66
102
  throw new Error("x402 payment failed — insufficient USDC balance on Base");
67
103
  }
@@ -78,5 +114,9 @@ function createX402Transport(account) {
78
114
  });
79
115
  }
80
116
  function resetX402() {
81
- _client = null;
117
+ delete _clients.nanopayment;
118
+ delete _clients["pay-per-request"];
119
+ _gatewayCheckedAt = 0;
120
+ _nanoPausedUntil = 0;
121
+ _lastModel = null;
82
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apow-cli",
3
- "version": "0.12.0",
3
+ "version": "0.12.4",
4
4
  "description": "Mine AGENT tokens on Base L2 with Agentic Proof of Work",
5
5
  "keywords": [
6
6
  "apow",
@@ -16,11 +16,12 @@
16
16
  "author": "Agentoshi",
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/Agentoshi/apow-cli.git"
19
+ "url": "git+https://github.com/Agentoshi/apow.git",
20
+ "directory": "packages/cli"
20
21
  },
21
22
  "homepage": "https://apow.io",
22
23
  "bugs": {
23
- "url": "https://github.com/Agentoshi/apow-cli/issues"
24
+ "url": "https://github.com/Agentoshi/apow/issues"
24
25
  },
25
26
  "bin": {
26
27
  "apow": "dist/index.js",
@@ -45,13 +46,13 @@
45
46
  "scripts": {
46
47
  "build": "tsc",
47
48
  "dev": "tsx src/index.ts",
48
- "test": "tsx --test \"src/**/*.test.ts\"",
49
+ "test": "npm run build && tsx --test \"src/**/*.test.ts\"",
49
50
  "prepublishOnly": "npm run build"
50
51
  },
51
52
  "dependencies": {
52
53
  "@blockrun/clawrouter": "0.12.81",
53
54
  "@noble/hashes": "^1.8.0",
54
- "@quicknode/x402": "^0.1.2",
55
+ "@quicknode/x402": "^0.1.3",
55
56
  "@x402/evm": "^2.8.0",
56
57
  "@x402/fetch": "^2.8.0",
57
58
  "commander": "^14.0.0",
package/skill.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: apow-mining
3
- description: This skill teaches your agent how to mine $AGENT coin via the apow-cli.
4
- allowed-tools: Bash(npx --yes apow-cli@0.12.0 start --easy)
3
+ description: Mine AGENT on Base with the official APoW CLI from any AI agent that can run commands. One encrypted local wallet, x402 remote GPU grinding, one Base ETH deposit.
4
+ allowed-tools: Bash(npx --yes apow-cli@0.12.4 --version) Bash(npx --yes apow-cli@0.12.4 start --easy) Bash(npx --yes apow-cli@0.12.4 wallet verify-recovery)
5
5
  metadata:
6
6
  openclaw:
7
7
  requires:
@@ -11,82 +11,68 @@ metadata:
11
11
 
12
12
  # APoW Mining
13
13
 
14
- Use this skill only to set up a fresh APoW mining wallet and run the official APoW miner. It is deliberately limited to that workflow.
14
+ Mine AGENT on Base with the official CLI. The same steps work in any agent that
15
+ can run shell commands and keep files, such as Claude Code, Codex, OpenClaw or
16
+ Hermes, on the user's laptop or another computer they control.
15
17
 
16
- APoW mining uses real assets on Base. Use a fresh, low-balance hot wallet dedicated to APoW. The CLI stores generated wallets as password-protected JSON keystores and applies a local signing policy with spend caps.
18
+ ## What the agent needs
17
19
 
18
- ## Required approval
20
+ - Node 20 or newer, outbound HTTPS, and files that survive a restart.
21
+ - Permission from its host to run a long process and sign transactions.
19
22
 
20
- Before running the miner, show the user this scope and wait for an explicit approval:
23
+ If it can't run commands or keep files, say so and stop. Don't work around a
24
+ platform rule to make mining run.
21
25
 
22
- > Approve APoW to create or use one fresh encrypted low-balance wallet; spend up to the local policy caps for one rig mint and x402 RPC, SMHL, and grinding services; submit Base mining transactions continuously until stopped; and sweep mined AGENT only if a payout address and automatic sweep were already configured?
26
+ ## The wallet stays on this machine
23
27
 
24
- Do not infer approval from funding, installation, prior mining, or a general request to inspect the project. Run the command only after the user approves the scope above.
28
+ The CLI creates one encrypted wallet on the machine it runs on and keeps two
29
+ encrypted copies there, in separate folders (`apow wallet backup` shows both).
30
+ Nothing goes to a server, a cloud backup or this chat. The user may also copy the
31
+ encrypted file to an external drive or another device; that is their choice.
25
32
 
26
- Once approved, select the CLI's existing Easy Mode with the pinned package:
33
+ - Never ask for, print or store a private key, password or recovery phrase in chat.
34
+ - The password comes from the machine's secret manager (`KEYSTORE_PASSWORD_CMD`)
35
+ or the user types it in a terminal.
36
+ - Mined AGENT can't be transferred until the protocol's LP deploys, so this wallet
37
+ holds its rewards for a long time. Losing the machine, or its disk, loses them
38
+ unless the user kept an outside copy. Tell the user this once.
27
39
 
28
- ```bash
29
- npx --yes apow-cli@0.12.0 start --easy
30
- ```
31
-
32
- Funding is a mandatory external prerequisite: the CLI cannot mint or mine until
33
- the dedicated wallet has ETH and USDC on Base. The same command handles the two
34
- phases around that checkpoint:
35
-
36
- - before funding, it creates an encrypted APoW wallet if needed, configures Easy
37
- Mode, prints the complete Base address and required balances, then stops;
38
- - after the user funds that address and confirms funding, rerunning it detects
39
- an existing rig or mints one within the configured cap, starts continuous
40
- mining, retries normal transient failures, and keeps signing behind the local
41
- enforce-mode policy.
42
-
43
- The user's approval authorizes this Easy Mode invocation; Wallet Protocol v2 remains the sole runtime opsec and signing-policy layer. The user can stop mining with Ctrl+C.
44
-
45
- ## Funding handoff
46
-
47
- If the CLI pauses because the wallet needs funds:
40
+ ## Start
48
41
 
49
- 1. Return the complete Base wallet address and the ETH and USDC minimums printed by the CLI.
50
- 2. Tell the user to send those assets to that address on Base.
51
- 3. Stop. Do not move, convert, or source funds for the user.
52
- 4. After the user confirms funding, resume the same Easy Mode flow with the pinned `start --easy` command.
42
+ Explain once, with the real numbers the CLI prints: one wallet, one rig mint,
43
+ part of the ETH swapped to USDC for grinding, then continuous mining until
44
+ stopped. Get the user's OK, then:
53
45
 
54
- Funding is a handoff, not permission to operate another wallet or move assets.
55
-
56
- ## Security boundaries
57
-
58
- - Never request, read, reveal, copy, or transmit wallet secrets.
59
- - Never search files, directories, environment variables, shell history, mounted drives, or other machines for wallets or credentials.
60
- - Never import or operate a main wallet for this skill.
61
- - Never create a raw-key file or place a raw wallet secret in project configuration.
62
- - Invoke only the single pinned `start --easy` command in this skill; every other CLI command is out of scope.
63
- - Never change the signing policy from `enforce`.
64
- - Never raise the mint, transfer, sweep, or x402 spend caps.
65
- - Never install or execute an unpinned package version.
66
- - Never continue if the package version, contract addresses, chain, approval scope, or policy state differs from what the CLI displays.
67
-
68
- If setup asks for a keystore password, the user must enter it directly into their local terminal or provide it through their own secret manager. Never ask them to paste it into chat.
46
+ ```bash
47
+ npx --yes apow-cli@0.12.4 start --easy
48
+ ```
69
49
 
70
- ## Expected policy caps
50
+ Easy Mode grinds on APoW's remote GPUs and pays per job with x402, so the agent's
51
+ own hardware doesn't matter. The first run creates the wallet and asks for **one
52
+ Base ETH deposit**, printing the address and amount. Before the user sends it,
53
+ check the wallet unlocks from scratch:
71
54
 
72
- The default enforce-mode policy limits:
55
+ ```bash
56
+ npx --yes apow-cli@0.12.4 wallet verify-recovery
57
+ ```
73
58
 
74
- - one rig mint to at most `0.01 ETH`;
75
- - each x402 payment to at most `1 USDC`;
76
- - aggregate x402 payments to at most `20 USDC` per UTC day;
77
- - transfers and sweeps to their separately configured destinations and caps.
59
+ After the deposit, run `start --easy` again: it swaps what it needs, mints a rig
60
+ (or finds the existing one) and starts mining.
78
61
 
79
- Treat the CLI’s displayed policy as authoritative. If it is less restrictive than these defaults, stop and ask the user to review it.
62
+ ## While it runs
80
63
 
81
- ## Failure handling
64
+ - One runner per wallet. Never start a second miner from a status check.
65
+ - Report only what happened: wallet verified, awaiting ETH, funded, rig minted,
66
+ runner active, first mine with its Base transaction hash. Never invent yields.
67
+ - Keep the signing policy in enforce mode. Defaults: 0.01 ETH per rig mint,
68
+ 1 USDC per grind, 20 USDC per day. Never raise a cap to get past an error.
82
69
 
83
- - No wallet: allow `start` to create one encrypted APoW wallet.
84
- - Password unavailable: pause for direct local entry; do not handle it in chat.
85
- - Funding needed: use the Base-only handoff above.
86
- - Policy not in enforce mode: stop.
87
- - User approval for the scoped Easy Mode command missing: stop.
88
- - Package version unavailable: stop; do not substitute `latest`.
89
- - RPC, SMHL, grinder, or transaction failure: report the concise error and let the CLI’s bounded retry behavior handle transient failures.
90
- - Mining stopped: report whether the user interrupted it or the CLI exited with an error.
70
+ ## When something fails
91
71
 
92
- Do not expand scope to “helpful” wallet operations. This skill’s complete job is the existing Easy Mode flow: encrypted APoW setup, a Base funding handoff, and policy-capped mining.
72
+ - Locked wallet: fix the unlock. Never make a replacement wallet.
73
+ - No funds: show the same deposit address and amount again.
74
+ - Policy refused a transaction: stop and report what was refused.
75
+ - Slow first grind: the GPU may be waking up; the CLI waits up to 330 s. Don't
76
+ send a second paid request.
77
+ - Unclear payment or transaction: stop and check before resuming.
78
+ - User says stop: stop the process and report anything still in flight.