agentwallet-mcp 1.14.9 → 1.14.10

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/README.md CHANGED
@@ -119,7 +119,7 @@ Add to your config:
119
119
  }
120
120
  ```
121
121
 
122
- > `AGENTWALLET_WALLET_ID` is optional. Set it to enable x402 auto-pay: when you exceed the free tier without a credit card, the MCP server automatically pays for operations with USDC from this wallet. Only the metered routes (creating a wallet, signing, sending) are paid this way, at most `AGENTWALLET_MAX_AUTOPAY_PER_HOUR` times an hour (default 20), and every automatic payment is reported in the tool result under `autopay_payment`. A 402 on any other route is reported, never paid.
122
+ > `AGENTWALLET_WALLET_ID` is optional. Set it to enable x402 auto-pay: when you exceed the free tier without a credit card, the MCP server automatically pays for operations with USDC from this wallet. Only the metered routes (creating a wallet, signing, sending) are paid this way, at most `AGENTWALLET_MAX_AUTOPAY_PER_HOUR` times an hour (default 20; the slot is taken before the payment is sent, so parallel calls cannot overrun it, and processes sharing a ledger file share the hour, while without one the count is per process), and every automatic payment is reported in the tool result under `autopay_payment`. A 402 on any other route is reported, never paid.
123
123
  >
124
124
  > **Auto-pay safety cap.** `AGENTWALLET_MAX_AUTOPAY` (optional, default `1`) is the most one x402 payment may authorize, in stablecoin units: `1` means one dollar. It prices registry stablecoins only (USDC, USDT, USDbC, DAI on the supported chains, USDC and USDT on Solana). A requirement in the chain's native asset or in any other token is refused, because "1" measured in ETH is a few thousand dollars; list such assets in `AGENTWALLET_AUTOPAY_ASSETS` (comma-separated addresses or mints, or the word `native`) to allow them, and the cap then applies in that asset's own units. Any requirement above the cap is rejected instead of paid, so a malformed or tampered payment requirement cannot drain the wallet. This automatic path settles `exact` requirements only; an `upto` offer from the API is refused before any wallet call, because paying a usage maximum upfront is not what the offer means (use `pay_x402`, which signs a Permit2 authorization for it). The cap is the operator's ceiling: a `max_payment` argument can lower it for one call but never raise it. Raise the variable itself if you genuinely need larger automatic payments (for example `"5"` for up to 5 USDC per call).
125
125
 
@@ -375,8 +375,8 @@ A per-transaction cap bounds one signature. It cannot see that the five hundredt
375
375
  ```
376
376
 
377
377
  - **`budget`**: rolling dollar budgets (last 24 hours, last 30 days, lifetime) across every chain, counting x402 payments, stablecoin transfers and stablecoin approvals in registry stablecoins. A spend the budget cannot price (a token outside the registry) is refused while a budget is set, unless `"unpriced_spends": "allow"`. An SPL send is priced at the mint's own decimals; a `token_decimals` hint that disagrees with the mint is refused before any request is made.
378
- - **`native_budget`**: the same per chain, in the chain's own coin, counting native transfers and the native value sent into any contract (`wrap_eth`, `send_transaction` with value and calldata), including value carried on a token transfer or approval call (a payable token contract keeps it, so it is a second spend, to that contract) and, in local Solana mode, the rent an SPL send pays to create the recipient's token account (the recipient owns that account and can close it for the lamports; the ledger records it as its own line, method `rent`, to the recipient, and `assets.allow` does not need to list `native` for it).
379
- - **Approvals are spends.** An ERC-20 allowance (`approve_token`, `approve_permit2`, `increaseAllowance`, `approveAndCall`, Permit2 `approve`, a signed `permit` in its EIP-2612, DAI or Permit2 shape, or the same calldata through `send_transaction`) is what the spender will take later, so it is priced, checked and reserved on the ledger when it is granted, the spender is checked against the recipient lists, and an unlimited approval (2^128 base units or more) is refused, since no budget can count it; grant an exact amount. An NFT operator grant (`setApprovalForAll`, ERC-777 `authorizeOperator`) is unbounded by construction and refused the same way, and an ERC-721 or ERC-1155 transfer is a spend of the collection to the recipient that no budget can price, so it is refused under a dollar budget unless `unpriced_spends` is `"allow"`, with the recipient checked either way. A zero-value call to any other contract (a router, a bridge) reserves nothing: it can only pull what an approval already granted. The exception is Permit2 itself: a call to it that the policy cannot price (`permitBatch`, `transferFrom`, `permitTransferFrom`, `lockdown`, nonce invalidation, or an unknown selector) is refused under a policy, since each moves tokens or changes what may be moved.
378
+ - **`native_budget`**: the same per chain, in the chain's own coin, counting native transfers, native x402 payments and the native value sent into any contract (`wrap_eth`, `send_transaction` with value and calldata), including value carried on a token transfer or approval call (a payable token contract keeps it, so it is a second spend, to that contract) and, in local Solana mode, the rent an SPL send pays to create the recipient's token account (the recipient owns that account and can close it for the lamports; the ledger records it as its own line, method `rent`, to the recipient, and `assets.allow` does not need to list `native` for it). The dollar budget has no price for the chain's coin, so on a chain with no `native_budget` entry a native spend is an unpriced spend: refused while a `budget` or a `per_host` ceiling is set, unless `"unpriced_spends": "allow"`. Give every chain the wallet spends on an entry.
379
+ - **Approvals are spends.** An ERC-20 allowance (`approve_token`, `approve_permit2`, `increaseAllowance`, `increaseApproval`, either `approveAndCall`, Permit2 `approve`, a signed `permit` in its EIP-2612, DAI or Permit2 shape, or the same calldata through `send_transaction`) is what the spender will take later, so it is priced, checked and reserved on the ledger when it is granted, the spender is checked against the recipient lists, and an unlimited approval (2^128 base units or more) is refused, since no budget can count it; grant an exact amount. An operator grant (`setApprovalForAll`, ERC-777 `authorizeOperator`, EIP-6909 `setOperator`) is unbounded by construction and refused the same way. Every token mover the standards define is a spend to its recipient: ERC-20 `transfer` and `transferFrom`, the ERC-677 and ERC-1363 `transferAndCall` and `transferFromAndCall` shapes, the ERC-223 `transfer` with data, ERC-777 `send` and `operatorSend`, and the ERC-721, ERC-1155 and EIP-6909 transfers, which no budget can price and so are refused under a dollar budget unless `unpriced_spends` is `"allow"`, with the recipient checked either way. A redemption of the wallet's own position is a spend too: ERC-4626 `redeem` and `withdraw` are spends of the vault to the receiver (unpriced, like an NFT), and Aave `Pool.withdraw` is a transfer of the underlying to the receiver. A zero-value call to any other contract (a router, a bridge, a protocol whose payout shape is not listed here) reserves nothing: it can only pull what an approval already granted, or pay out a position in a shape the policy does not know, so a policy that holds positions elsewhere should set `recipients.allow`. The exception is Permit2 itself: a call to it that the policy cannot price (`permitBatch`, `transferFrom`, `permitTransferFrom`, `lockdown`, nonce invalidation, or an unknown selector) is refused under a policy, since each moves tokens or changes what may be moved.
380
380
  - **`hosts`**, **`per_host`**: which endpoints `pay_x402` may pay, and how much per host per day, per month and per payment. A denied host is never contacted, not even for a quote. A host is matched by its canonical DNS name (lowercase, the root label's trailing dot removed), so `api.example.com.` and its percent-encoded spelling are `api.example.com` to every list and to the ledger's per-host sums.
381
381
  - **`recipients`**: where funds may go (transfers, x402 `payTo`, approval spenders, contracts that receive native value). The allow list covers those funds destinations; the contract a zero-value call is aimed at (a token being approved, a router) is checked against the deny list and the chain list.
382
382
  - **`chains`**, **`assets`**: allow lists; an asset entry can be scoped `"8453:0x..."` or be the word `native`.
@@ -385,7 +385,7 @@ A per-transaction cap bounds one signature. It cannot see that the five hundredt
385
385
 
386
386
  An unknown key stops the server, so a misspelled `budgets` cannot run unbounded. `spend_policy` reports the file, its sha256 (compare it with the file you reviewed), what each budget has spent and has left, and which tools the policy hid. `quote_x402` answers "would this be paid?" for a URL before anything is signed.
387
387
 
388
- **The ledger.** Budgets are enforced from an append-only, hash-chained JSONL file (`AGENTWALLET_LEDGER`, or the policy's `ledger`, or `agentwallet-ledger.jsonl` beside the policy when a budget needs one). A spend is reserved on it before the signature exists; a reservation whose signing fails is voided by a later line; the endpoint's or chain's answer is settled onto it afterwards. A spend that may already be on the wire (a broadcast that failed after the bytes left, a hosted request the API host took and then dropped) is kept counted as `unknown` rather than voided; a failure before anything left this process, including a policy or local-mode refusal, is always voided and never consumes budget. The chain is verified on every read, and a ledger that does not verify refuses every spend until the operator has looked at it. Several agentwallet-mcp processes may share one ledger (two MCP clients on one wallet): the file is re-read before every check, and the check-and-append step holds an exclusive lock file (`<ledger>.lock`) across processes, so the budget is one budget however many processes enforce it; a lock older than 30 seconds is treated as left by a dead process. A transaction signed without being broadcast (`sign_transaction`) is reserved and counted like a send, since whoever holds it can broadcast it. A call that moves two things (a token transfer that also carries native value) is two lines, reserved in turn and released together when either is refused. `list_payments` reads it, `export_receipts` turns it into CSV or JSONL, and `AGENTWALLET_WEBHOOK_URL` receives every line as it is written.
388
+ **The ledger.** Budgets are enforced from an append-only, hash-chained JSONL file (`AGENTWALLET_LEDGER`, or the policy's `ledger`, or `agentwallet-ledger.jsonl` beside the policy when a budget needs one). A spend is reserved on it before the signature exists; a reservation whose signing fails is voided by a later line; the endpoint's or chain's answer is settled onto it afterwards. A spend that may already be on the wire (a broadcast that failed after the bytes left, a hosted request the API host took and then dropped or answered with a 5xx, any host answer that carries a transaction hash) is kept counted as `unknown` rather than voided; a failure before anything left this process, including a policy or local-mode refusal, or a 4xx refusal from the host, is always voided and never consumes budget. A hosted send is forwarded with the chain the policy priced it on (`chain_id`, else `AGENTWALLET_CHAIN_ID`, else 8453), and a custodian answer naming another chain is written onto the ledger line as a mismatch. The chain is verified on every read, and a ledger that does not verify refuses every spend until the operator has looked at it. Several agentwallet-mcp processes may share one ledger (two MCP clients on one wallet): the file is re-read before every check, and the check-and-append step holds an exclusive lock file (`<ledger>.lock`) across processes, so the budget is one budget however many processes enforce it; a lock older than 30 seconds is treated as left by a dead process. A transaction signed without being broadcast (`sign_transaction`) is reserved and counted like a send, since whoever holds it can broadcast it. A call that moves two things (a token transfer that also carries native value) is two lines, reserved in turn and released together when either is refused. `list_payments` reads it, `export_receipts` turns it into CSV or JSONL, and `AGENTWALLET_WEBHOOK_URL` receives every line as it is written.
389
389
 
390
390
  ### Encrypted keyfiles
391
391
 
package/build/index.js CHANGED
@@ -162,6 +162,43 @@ const SPEND_LAYOUTS = {
162
162
  d505accf: { kind: 'approval', what: 'EIP-2612 permit', toIndex: 1, amountIndex: 2 }, // permit(address,address,uint256,uint256,uint8,bytes32,bytes32)
163
163
  '8fcbaf0c': { kind: 'approval', what: 'DAI permit', toIndex: 1, amountIndex: 4, operator: true }, // permit(address,address,uint256,uint256,bool,uint8,bytes32,bytes32): allowed=true is unbounded by construction
164
164
  '2b67b570': { kind: 'approval', what: 'Permit2 permit', toIndex: 5, amountIndex: 2, tokenIndex: 1, permit2Only: true }, // Permit2.permit(address,((address,uint160,uint48,uint48),address,uint256),bytes): PermitSingle is static, so inlined
165
+ // Sibling shapes of the movers and grants above (reported privately
166
+ // 2026-11-02, 1.14.10, four reports): the legacy StandardToken
167
+ // increaseApproval, the ERC-1363 two-argument transferAndCall and
168
+ // approveAndCall and both transferFromAndCall shapes, the ERC-223 transfer
169
+ // with data, and the EIP-6909 multi-token movers and grants. Each moves the
170
+ // token or grants a standing allowance exactly as the shape already decoded
171
+ // beside it, and each fell through as a zero-value contract call.
172
+ d73dd623: { kind: 'approval', what: 'increaseApproval', toIndex: 0, amountIndex: 1 }, // increaseApproval(address,uint256)
173
+ '3177029f': { kind: 'approval', what: 'approveAndCall', toIndex: 0, amountIndex: 1 }, // approveAndCall(address,uint256) (ERC-1363)
174
+ '1296ee62': { kind: 'token', what: 'transferAndCall', toIndex: 0, amountIndex: 1 }, // transferAndCall(address,uint256) (ERC-1363)
175
+ d8fbe994: { kind: 'token', what: 'transferFromAndCall', toIndex: 1, amountIndex: 2 }, // transferFromAndCall(address,address,uint256) (ERC-1363)
176
+ c1d34b89: { kind: 'token', what: 'transferFromAndCall', toIndex: 1, amountIndex: 2 }, // transferFromAndCall(address,address,uint256,bytes) (ERC-1363)
177
+ be45fd62: { kind: 'token', what: 'ERC-223 transfer', toIndex: 0, amountIndex: 1 }, // transfer(address,uint256,bytes)
178
+ // EIP-6909: setOperator is the setApprovalForAll of a multi-token contract
179
+ // (unbounded by construction); the per-id approve and the movers carry an
180
+ // id word before the amount, and the contract has no decimals or price, so
181
+ // they are treated as the ERC-1155 shapes are: unpriced, recipient-checked.
182
+ '558a7297': { kind: 'approval', what: 'EIP-6909 setOperator', toIndex: 0, amountIndex: 1, nft: true, operator: true }, // setOperator(address,bool)
183
+ '426a8493': { kind: 'approval', what: 'EIP-6909 approve', toIndex: 0, amountIndex: 2, nft: true }, // approve(address,uint256,uint256)
184
+ '095bcdb6': { kind: 'token', what: 'EIP-6909 transfer', toIndex: 0, amountIndex: 2, nft: true }, // transfer(address,uint256,uint256)
185
+ fe99049a: { kind: 'token', what: 'EIP-6909 transferFrom', toIndex: 1, amountIndex: 3, nft: true }, // transferFrom(address,address,uint256,uint256)
186
+ // Redemptions (reported privately 2026-11-02, 1.14.10): a vault or lending
187
+ // position is the wallet's asset, and its withdraw and redeem calls name a
188
+ // receiver, so a zero-value call paid the whole position to any address
189
+ // with nothing reserved. An ERC-4626 vault is itself the share token, so
190
+ // the spend is recorded under the vault (shares for redeem; for withdraw
191
+ // the amount is in the underlying, printed at the vault's decimals, which
192
+ // the standard keeps equal to the underlying's in every common vault), and
193
+ // priced only if the registry knows it, which a vault never is: refused
194
+ // under a dollar budget unless unpriced_spends allows, recipient-checked
195
+ // either way. Aave's Pool.withdraw names the underlying in the calldata, so
196
+ // that one is priced like a transfer of it. Any other protocol's shape is
197
+ // outside this table: a policy that holds positions elsewhere should list
198
+ // recipients.allow and, where it can, the contracts it may call.
199
+ ba087652: { kind: 'token', what: 'ERC-4626 redeem', toIndex: 1, amountIndex: 0 }, // redeem(uint256,address,address)
200
+ b460af94: { kind: 'token', what: 'ERC-4626 withdraw', toIndex: 1, amountIndex: 0 }, // withdraw(uint256,address,address)
201
+ '69328dec': { kind: 'token', what: 'Aave withdraw', toIndex: 2, amountIndex: 1, tokenIndex: 0 }, // Pool.withdraw(address,uint256,address)
165
202
  };
166
203
  /* The rest of Permit2's surface, by selector: permitBatch, transferFrom (two
167
204
  shapes), lockdown, permitTransferFrom and permitWitnessTransferFrom (two
@@ -401,7 +438,13 @@ function localChainId(body, qs) {
401
438
  const fromEnv = (process.env.AGENTWALLET_CHAIN_ID || '').trim();
402
439
  if (fromEnv)
403
440
  return parseInt(fromEnv, 10);
404
- return 8453; // Base, matching the custodial default
441
+ // Base. This used to say "matching the custodial default", and it did not:
442
+ // the hosted signer falls back to chain 1 when a body names no chain, so a
443
+ // chain-less hosted send was priced and ledgered here on 8453 and executed
444
+ // there on Ethereum (reported privately 2026-11-02, 1.14.10). The hosted
445
+ // path now writes the chain it priced into the body it forwards (api()), so
446
+ // whatever this returns, the custodian is told the same chain.
447
+ return 8453;
405
448
  }
406
449
  /**
407
450
  * Refuse rather than silently hand the operation to someone else's signer.
@@ -584,8 +627,18 @@ async function api(path, method = 'GET', body, extraHeaders) {
584
627
  // signature (body.message) moves nothing and is not gated.
585
628
  const m = /^\/wallets\/([^/]+)\/(send|sign)(\?|$)/.exec(path);
586
629
  const signsTx = m !== null && (m[2] === 'send' || typeof body?.message !== 'string');
630
+ let reservedChain = null;
587
631
  if (method === 'POST' && m && body && signsTx) {
588
632
  const chainId = localChainId(body, new URLSearchParams(path.split('?')[1] || ''));
633
+ // The custodian must execute on the chain the policy priced. A body with
634
+ // no chain_id used to go out as it came and the hosted signer chose its
635
+ // own default (chain 1), while the ledger said 8453 (reported privately
636
+ // 2026-11-02, 1.14.10). The chain is written into the body here, before
637
+ // the decode, so the two cannot differ; the custodian's answer is still
638
+ // compared with it below.
639
+ if (!anyLocalMode() && typeof body.chain_id !== 'number')
640
+ body = { ...body, chain_id: chainId };
641
+ reservedChain = chainId;
589
642
  const d = await describeSend(body, chainId);
590
643
  assertSendTarget(d, chainId);
591
644
  const tool = ctx.tool || (m[2] === 'sign' ? 'sign_transaction' : 'send');
@@ -604,12 +657,21 @@ async function api(path, method = 'GET', body, extraHeaders) {
604
657
  }
605
658
  try {
606
659
  const out = await apiInner(path, method, body, extraHeaders);
660
+ // A custodian that answers with a chain other than the one it was asked
661
+ // for executed somewhere the ledger did not count; the line cannot be
662
+ // re-booked (the spend is live), so the mismatch is written onto it and
663
+ // onto stderr for the operator.
664
+ const reported = out?.chain_id;
665
+ const mismatch = reserved.length && reservedChain !== null && typeof reported === 'number' && reported !== reservedChain
666
+ ? ` CHAIN MISMATCH: reserved on chain ${reservedChain}, the API host reports chain ${reported}; the budget of chain ${reported} did not count this spend.` : '';
667
+ if (mismatch)
668
+ console.error(`[agentwallet] ${path}:${mismatch}`);
607
669
  for (const seq of reserved) {
608
670
  const r = out;
609
671
  if (m[2] === 'sign')
610
- LEDGER.settle(seq, 'signed', 'raw transaction returned to the caller; not broadcast by this process, so it stays counted');
672
+ LEDGER.settle(seq, 'signed', 'raw transaction returned to the caller; not broadcast by this process, so it stays counted' + mismatch);
611
673
  else
612
- LEDGER.settle(seq, 'broadcast', typeof r?.tx_hash === 'string' ? r.tx_hash : typeof r?.signature === 'string' ? r.signature : null);
674
+ LEDGER.settle(seq, 'broadcast', (typeof r?.tx_hash === 'string' ? r.tx_hash : typeof r?.signature === 'string' ? r.signature : '') + mismatch || null);
613
675
  }
614
676
  return out;
615
677
  }
@@ -713,6 +775,21 @@ async function apiInner(path, method = 'GET', body, extraHeaders) {
713
775
  }
714
776
  if (!res.ok) {
715
777
  const error = serverText(data.error) || `HTTP ${res.status}`;
778
+ // The host was reached and answered. A 4xx is its refusal and the
779
+ // reservation is voided; a 5xx on a send or sign came after it took the
780
+ // request, and the custodian may have broadcast before whatever failed
781
+ // (a downstream write, a proxy), so the spend stays counted as unknown.
782
+ // Until 1.14.10 every non-2xx voided, and a 500 that carried the
783
+ // transaction hash in its body restored the whole budget and dropped
784
+ // the hash (reported privately 2026-11-02).
785
+ if (method === 'POST' && /^\/wallets\/[^/]+\/(send|sign)(\?|$)/.test(path)) {
786
+ const d = data;
787
+ const hash = looksLikeTxHash(d?.tx_hash) ? d.tx_hash : typeof d?.signature === 'string' && /^[1-9A-HJ-NP-Za-km-z]{43,120}$/.test(d.signature) ? d.signature : null;
788
+ if (hash)
789
+ throw markMaybeLive(new Error(`${error} The AgentWallet API host answered ${path} with HTTP ${res.status} but reported a transaction (${hash}), so the spend is live and stays counted; check the wallet's history before retrying.`));
790
+ if (res.status >= 500)
791
+ throw markMaybeLive(new Error(`${error} The AgentWallet API host answered ${path} with HTTP ${res.status} after taking the request; whether the custodian broadcast is unknown, so the spend stays counted. Check the wallet's history before retrying.`));
792
+ }
716
793
  throw new Error(error);
717
794
  }
718
795
  // A send that comes back without a hash was not sent, whatever the body says
@@ -893,12 +970,24 @@ async function handleX402Payment(x402Data, originalPath, originalMethod, origina
893
970
  const { tokenAddress, rawAmount, decimals } = deriveX402Payment(accept, maxAutopay, trustedDecimals);
894
971
  // A hostile or broken host that answers 402 on every call must not drain the
895
972
  // wallet one cap at a time: at most AUTOPAY_PER_HOUR payments an hour (round 3).
973
+ // The slot is taken here, synchronously, before anything is awaited: the
974
+ // count used to be read here and written after the payment, so eight calls
975
+ // pipelined at once all read 0 and all paid under a limit of 2 (reported
976
+ // privately 2026-11-02, 1.14.10). A payment that never left this process
977
+ // gives its slot back below; one that may be live keeps it. The ledger's
978
+ // own auto-pay lines are counted too, so several processes sharing one
979
+ // ledger share the hour; without a ledger file the count is per process.
896
980
  const hourAgo = Date.now() - 3_600_000;
897
981
  while (autopayLog.length && autopayLog[0] < hourAgo)
898
982
  autopayLog.shift();
899
- if (autopayLog.length >= AUTOPAY_PER_HOUR) {
900
- throw new Error(`x402 auto-pay: ${autopayLog.length} automatic payments were already made in the last hour (AGENTWALLET_MAX_AUTOPAY_PER_HOUR=${AUTOPAY_PER_HOUR}); refusing another. Original error: ${serverText(x402Data.error)}`);
901
- }
983
+ const made = Math.max(autopayLog.length, LEDGER.countSince('autopay', hourAgo));
984
+ if (made >= AUTOPAY_PER_HOUR) {
985
+ throw new Error(`x402 auto-pay: ${made} automatic payments were already made in the last hour (AGENTWALLET_MAX_AUTOPAY_PER_HOUR=${AUTOPAY_PER_HOUR}); refusing another. Original error: ${serverText(x402Data.error)}`);
986
+ }
987
+ const slot = Date.now();
988
+ autopayLog.push(slot);
989
+ const giveBack = () => { const i = autopayLog.indexOf(slot); if (i >= 0)
990
+ autopayLog.splice(i, 1); };
902
991
  // Send payment using our wallet (with X-AGW-SKIP-X402 to prevent recursion).
903
992
  // The ledger context names the API host and route; the /send hook reserves and settles the spend.
904
993
  const ctx = { 'X-AGW-SKIP-X402': 'true', 'X-AGW-CTX': JSON.stringify({ tool: 'autopay', host: hostOf(API_BASE), resource: `${originalMethod} ${originalPath.split('?')[0]}`, method: 'autopay' }) };
@@ -922,12 +1011,13 @@ async function handleX402Payment(x402Data, originalPath, originalMethod, origina
922
1011
  }
923
1012
  }
924
1013
  catch (e) {
1014
+ if (!isMaybeLive(e))
1015
+ giveBack(); // refused, or never reached the host: the slot is free again
925
1016
  throw new Error(`x402 auto-pay failed: ${e.message}. Original error: ${serverText(x402Data.error)}`);
926
1017
  }
927
1018
  if (!txHash) {
928
- throw new Error('x402 auto-pay: no transaction hash returned.');
1019
+ throw new Error('x402 auto-pay: no transaction hash returned.'); // the host answered the send; the slot stays taken
929
1020
  }
930
- autopayLog.push(Date.now());
931
1021
  const autopayNotice = {
932
1022
  amount: formatUnits(rawAmount, decimals), token: assetLabel(chainId, tokenAddress), pay_to: payTo, chain_id: chainId, tx_hash: txHash,
933
1023
  route: `${originalMethod} ${originalPath}`,
@@ -1287,7 +1377,7 @@ function resolveChainId(network) {
1287
1377
  const AddressSchema = z.string().regex(/^(0x[a-fA-F0-9]{40}|[1-9A-HJ-NP-Za-km-z]{32,44})$/, 'Must be a 0x-prefixed 40-hex EVM address or a base58 Solana address');
1288
1378
  const server = new McpServer({
1289
1379
  name: 'agentwallet',
1290
- version: '1.14.9',
1380
+ version: '1.14.10',
1291
1381
  }, {
1292
1382
  instructions: `AgentWallet gives AI agents their own blockchain wallets. ${anyLocalMode()
1293
1383
  ? 'This server runs in LOCAL (self-custody) mode: the operator supplied the key, signing happens in this process, and the only spend guards are the environment caps (AGENTWALLET_MAX_TX_NATIVE / _TOKEN / _SOL per transaction, AGENTWALLET_MAX_AUTOPAY and AGENTWALLET_AUTOPAY_ASSETS for x402, AGENTWALLET_X402_MAX_TIMEOUT for authorization windows). There is no server-side pause, daily limit or approval email; pause_wallet, unpause_wallet and delete_wallet are refused.'
package/build/ledger.d.ts CHANGED
@@ -110,6 +110,8 @@ export declare class Ledger {
110
110
  private liveSpends;
111
111
  /** Dollar sums over rolling windows from a fresh read of the file; nowMs for tests. */
112
112
  spentUsd(nowMs?: number, host?: string): Spent;
113
+ /** Live spends (not voided) with this method written since `sinceMs`, from a fresh read: the hourly auto-pay count across every process sharing the file (1.14.10). */
114
+ countSince(method: SpendMethod, sinceMs: number): number;
113
115
  spentNative(chainId: number, nowMs?: number): Spent;
114
116
  private sumUsd;
115
117
  private sumNative;
package/build/ledger.js CHANGED
@@ -185,6 +185,11 @@ export class Ledger {
185
185
  this.sync();
186
186
  return this.sumUsd(nowMs, host);
187
187
  }
188
+ /** Live spends (not voided) with this method written since `sinceMs`, from a fresh read: the hourly auto-pay count across every process sharing the file (1.14.10). */
189
+ countSince(method, sinceMs) {
190
+ this.sync();
191
+ return this.liveSpends().filter(e => e.method === method && Date.parse(e.ts) >= sinceMs).length;
192
+ }
188
193
  spentNative(chainId, nowMs = Date.now()) {
189
194
  this.sync();
190
195
  return this.sumNative(chainId, nowMs);
@@ -223,9 +228,21 @@ export class Ledger {
223
228
  return { ok: false, reason: `The ledger at ${this.path} is not intact (${this.integrity}); every spend is refused until the operator has looked at it.` };
224
229
  const amount18 = rawToUnits(input.raw, input.decimals);
225
230
  if (input.asset === '') {
226
- const r = refusal(limits.native, this.sumNative(input.chainId, nowMs), amount18, `native_budget.${input.chainId}`);
227
- if (r)
228
- return { ok: false, reason: r };
231
+ // The chain's own coin is counted by native_budget alone; the dollar
232
+ // budget has no price for it. Until 1.14.10 a chain with no
233
+ // native_budget entry fell through here with nothing checked, so a
234
+ // policy of "budget daily 0.5, unpriced_spends refuse" bounded every
235
+ // stablecoin payment and no native one (reported privately
236
+ // 2026-11-02). Now such a spend is what it is to the dollar budget, an
237
+ // unpriced spend, and the unpriced rule decides it.
238
+ if (limits.native) {
239
+ const r = refusal(limits.native, this.sumNative(input.chainId, nowMs), amount18, `native_budget.${input.chainId}`);
240
+ if (r)
241
+ return { ok: false, reason: r };
242
+ }
243
+ else if (limits.unpriced === 'refuse' && (limits.usd || limits.host)) {
244
+ return { ok: false, reason: `policy: ${input.assetLabel} on chain ${input.chainId} is the chain's own coin, which the dollar budget cannot price, and the policy has no native_budget.${input.chainId}; refused (add native_budget.${input.chainId} to the policy to count it, or set unpriced_spends to "allow" to let native spends through uncounted). Nothing was signed.` };
245
+ }
229
246
  }
230
247
  else if (input.usd === null) {
231
248
  if (limits.unpriced === 'refuse' && (limits.usd || limits.host)) {
@@ -337,7 +337,8 @@ const PERMIT2_SELECTORS = new Set(['87517c45', '2b67b570', '2a2d80d1', '36c78516
337
337
  and so read as "not a token" to the cap, which let setApprovalForAll to an
338
338
  attacker through uncapped (2026-10-04 round 2, verified on a live
339
339
  collection). Nothing prices an NFT, so these are refused outright. */
340
- const NFT_SELECTORS = new Set(['a22cb465', '42842e0e', 'b88d4fde', 'f242432a', '2eb2c2d6', '959b8c3f']); // plus ERC-777 authorizeOperator: an unbounded delegation
340
+ const NFT_SELECTORS = new Set(['a22cb465', '42842e0e', 'b88d4fde', 'f242432a', '2eb2c2d6', '959b8c3f', // plus ERC-777 authorizeOperator: an unbounded delegation
341
+ '558a7297', '426a8493', '095bcdb6', 'fe99049a']); // EIP-6909 setOperator, approve, transfer, transferFrom: a multi-token contract has no decimals() either (1.14.10)
341
342
  const CAP_LAYOUTS = {
342
343
  a9059cbb: { amountIndex: 1, what: 'token transfer' }, // transfer(address,uint256)
343
344
  '23b872dd': { amountIndex: 2, what: 'token transfer' }, // transferFrom(address,address,uint256)
@@ -358,6 +359,15 @@ const CAP_LAYOUTS = {
358
359
  // and are refused by the rule below, as every unpriced call to a token or to
359
360
  // Permit2 is; the spend policy classifies both.
360
361
  d505accf: { amountIndex: 2, what: 'approval (EIP-2612 permit)' }, // permit(address,address,uint256,uint256,uint8,bytes32,bytes32)
362
+ // Sibling shapes priced by the spend policy since 1.14.10 (reported
363
+ // privately 2026-11-02): the same amount word, the same treatment, so the
364
+ // two guards keep pricing the same calls.
365
+ d73dd623: { amountIndex: 1, what: 'approval (increaseApproval)' }, // increaseApproval(address,uint256)
366
+ '3177029f': { amountIndex: 1, what: 'approval (approveAndCall)' }, // approveAndCall(address,uint256)
367
+ '1296ee62': { amountIndex: 1, what: 'token transfer (transferAndCall)' }, // transferAndCall(address,uint256)
368
+ d8fbe994: { amountIndex: 2, what: 'token transfer (transferFromAndCall)' }, // transferFromAndCall(address,address,uint256)
369
+ c1d34b89: { amountIndex: 2, what: 'token transfer (transferFromAndCall)' }, // transferFromAndCall(address,address,uint256,bytes)
370
+ be45fd62: { amountIndex: 1, what: 'token transfer (ERC-223)' }, // transfer(address,uint256,bytes)
361
371
  // WETH9 calls, priced only when `to` is the chain's own wrapped-native
362
372
  // contract (wrappedNativeOnly). deposit() carries its amount as msg.value,
363
373
  // not in calldata, hence amountIndex -1; withdraw(uint256) has it at word 0.
@@ -416,7 +426,7 @@ async function assertWithinTokenCap(chainId, to, data, valueWei = 0n) {
416
426
  `or ask the operator, who alone can set AGENTWALLET_ALLOW_UNKNOWN_TOKEN_CALLS=1.`);
417
427
  }
418
428
  if (NFT_SELECTORS.has(selector)) {
419
- throw new Error(`Blocked by local guard: calldata selector 0x${selector} is an NFT approval or transfer (ERC-721/1155) aimed at ${to}; AGENTWALLET_MAX_TX_TOKEN cannot price it, ` +
429
+ throw new Error(`Blocked by local guard: calldata selector 0x${selector} is an NFT approval or transfer (ERC-721/1155, or an EIP-6909 multi-token call) aimed at ${to}; AGENTWALLET_MAX_TX_TOKEN cannot price it, ` +
420
430
  `so it is refused rather than let through uncapped. Only the operator can allow it (AGENTWALLET_ALLOW_UNKNOWN_TOKEN_CALLS=1).`);
421
431
  }
422
432
  if (PERMIT2_SELECTORS.has(selector)) {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hifriendbot/agentwallet-mcp.git"
7
7
  },
8
- "version": "1.14.9",
8
+ "version": "1.14.10",
9
9
  "description": "MCP server for AgentWallet: self-custody local signing on EVM and Solana, or hosted wallets. Sign, broadcast, pay x402 invoices, and accept x402 payments.",
10
10
  "type": "module",
11
11
  "main": "build/index.js",