@priors/mcp 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @priors/mcp changelog
2
2
 
3
+ ## 0.9.3 (2026-10-14)
4
+
5
+ - **A PT-USDG trade whose answer is lost is never said to have done nothing.** `pt_buy`, `pt_sell` and `pt_redeem` now
6
+ sign each step before sending it, so its hash is known first, and after a failed broadcast they ask the node about
7
+ that hash: a step the node shows mined goes on (the trade is done and said so, once), one it shows pending is waited
8
+ for, and "insufficient funds" with no trace of the transaction is a refusal that counts nothing. Any other failure
9
+ says the trade may have been sent, keeps a buy counted against `PRIORS_MAX_PT_TOTAL_USD`, and asks to check
10
+ `pt_position` and `wallet_balance` before trying again. Until now a node's "insufficient funds" was always a refusal,
11
+ though it can also answer a retried request after the first one was taken (GHSA-g5cv's class); the buy was then
12
+ uncounted and given back as nothing sent. Waiting for a receipt is bounded (3 minutes), a lookup that never answers
13
+ included, and a lookup that fails is asked again. The same change is in the SDK's `sdk/pt-usdg.mjs`, whose
14
+ `ptBuy`/`ptSell`/`ptRedeem` throw `TX_UNCONFIRMED` (with the hash and the steps done before) instead of a bare error.
15
+
3
16
  ## 0.9.2 (2026-10-13)
4
17
 
5
18
  - **Merchant text can no longer write a line outside the data fence, or spell its marker.** The marker's keyword was
package/README.md CHANGED
@@ -178,7 +178,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
178
178
  "mcpServers": {
179
179
  "priors": {
180
180
  "command": "npx",
181
- "args": ["-y", "@priors/mcp@0.9.2"],
181
+ "args": ["-y", "@priors/mcp@0.9.3"],
182
182
  "env": {
183
183
  "PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
184
184
  "PRIORS_AGENT_ID": "1234"
@@ -200,7 +200,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
200
200
  "mcpServers": {
201
201
  "priors": {
202
202
  "command": "npx",
203
- "args": ["-y", "@priors/mcp@0.9.2"],
203
+ "args": ["-y", "@priors/mcp@0.9.3"],
204
204
  "env": {
205
205
  "PRIORS_KEY": "${PRIORS_KEY}",
206
206
  "PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
@@ -213,7 +213,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
213
213
  or, for your user only, from a macOS or Linux terminal:
214
214
 
215
215
  ```sh
216
- (read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.9.2' priors-mcp ~/.config/priors/agent.key
216
+ (read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.9.3' priors-mcp ~/.config/priors/agent.key
217
217
  ```
218
218
 
219
219
  It waits for the key without showing it (paste it, then Enter), saves it in a file only you can read, and gives Claude
@@ -269,7 +269,7 @@ to approve a borrow; this package, with the key, pays for APIs. With borrowing o
269
269
  approves each loan in Priors' Go mode. ElizaOS (`@elizaos/plugin-mcp`):
270
270
 
271
271
  ```ts
272
- "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.9.2"],
272
+ "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.9.3"],
273
273
  env: { PRIORS_KEY_FILE: "/home/agent/.config/priors/agent-7311.key", PRIORS_AGENT_ID: "7311",
274
274
  PRIORS_MAX_BORROW_USD: "0", PRIORS_MAX_BORROW_DAY_USD: "0", PRIORS_MAX_SPEND_DAY_USD: "1", PRIORS_MAX_PRICE_USD: "0.10",
275
275
  PRIORS_PAY_HOSTS: "api.example.com" } }
@@ -281,7 +281,7 @@ OpenClaw (`mcp.servers`, JSON5) takes the same `command`, `args` and `env`; Herm
281
281
  mcp_servers:
282
282
  priors-wallet:
283
283
  command: npx
284
- args: ["-y", "@priors/mcp@0.9.2"]
284
+ args: ["-y", "@priors/mcp@0.9.3"]
285
285
  env:
286
286
  PRIORS_KEY_FILE: /home/agent/.config/priors/agent-7311.key
287
287
  PRIORS_AGENT_ID: "7311"
@@ -308,7 +308,7 @@ key proves it is there: it signs the ERC-8004 identity registry's `AgentWalletSe
308
308
  agent's).
309
309
 
310
310
  ```sh
311
- PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.9.2 link-wallet --agent 7311
311
+ PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.9.3 link-wallet --agent 7311
312
312
  ```
313
313
 
314
314
  It reads the registry's EIP-712 domain and refuses to sign for any other, takes the owner from the chain (`--owner`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@priors/mcp",
3
3
  "mcpName": "io.github.priors-agents/priors",
4
- "version": "0.9.2",
4
+ "version": "0.9.3",
5
5
  "private": false,
6
6
  "description": "MCP server for Priors on Robinhood Chain: pay x402 URLs in USDG, read balances, credit lines and scores, borrow and repay, and buy, sell and redeem PT-USDG. Key from PRIORS_KEY_FILE (a file only you can read) or PRIORS_KEY, never the command line.",
7
7
  "type": "module",
package/src/pt-usdg.mjs CHANGED
@@ -25,7 +25,16 @@
25
25
  // price impact (about 0.1% per 1,000 USDG on 2026-10-01): a large trade may need a wider slippage or several trades.
26
26
  // Every approval is for exactly the amount of the trade after it, the shape the gas gate sponsors; a call bundle is
27
27
  // sponsorable when its amount is within PT_USDG.maxUsdgPerOp (2,000).
28
- import { formatUnits, getAddress, parseUnits, encodeFunctionData, decodeFunctionResult } from "viem";
28
+ //
29
+ // Sending (`wallet`): each call is simulated, sent, and waited for (at most `waitTimeoutMs`, 3 minutes by default). A step
30
+ // that may have been sent but whose outcome is not known throws TX_UNCONFIRMED ({ code, unconfirmed: true, hash, hashes:
31
+ // the steps done before, step }): do not run the trade again before checking the balances (ptPosition), or it could
32
+ // trade twice. A lost answer of a transaction the node shows mined is no error: the trade goes on. A wallet that signs in
33
+ // the process (an ethers Wallet, a viem local account) gives the hash before the broadcast, so only it can tell a node's
34
+ // "insufficient funds" (an ordinary error, nothing sent) from a transaction already taken; with a wallet that sends
35
+ // itself, any failure but its user declining is TX_UNCONFIRMED, and its deadline runs from the moment it is asked (its
36
+ // user's approval included). `onSend(hash, what)` is told of each step as it leaves.
37
+ import { formatUnits, getAddress, parseUnits, encodeFunctionData, decodeFunctionResult, keccak256 } from "viem";
29
38
  import { PENDLE, PENDLE_ADDR, ORACLE_ABI, PT_ABI, buildBuy, buildSell, buildRedeem, quoteBuy, quoteSell, marketOf, maturedMarkets } from "./pendle-pt.mjs";
30
39
  import PT from "../deployments/pt-usdg.4663.json" with { type: "json" };
31
40
 
@@ -169,36 +178,139 @@ async function accountOf(account, wallet) {
169
178
  throw new Error("give the account that signs (account) or a wallet to send with");
170
179
  }
171
180
 
172
- /** Wait for `hash` and check it succeeded. */
173
- async function receipt(client, hash, { timeoutMs = 180_000 } = {}) {
174
- const end = Date.now() + timeoutMs;
181
+ // ---- sending: a step whose broadcast may have gone through is never given back as a bare error ----
182
+ // A caller that retries a bare error after the node took the transaction trades twice (GHSA-g5cv's class, for PT-USDG).
183
+ // So: a wallet that signs in this process (an ethers Wallet, a viem local account) signs first, which gives the hash
184
+ // before anything is sent; after a failed broadcast the node is asked about that hash: mined is done, pending is waited
185
+ // for, unknown is a refusal only for "insufficient funds". Anything else, and any failure of a wallet that sends itself
186
+ // (a browser wallet) other than its user declining, is TX_UNCONFIRMED: { code, unconfirmed: true, hash (null when the
187
+ // wallet never said it), hashes (the steps that went through before), step }. Waiting is bounded by `waitTimeoutMs`.
188
+
189
+ /** TX_UNCONFIRMED: step `c` may have been sent and what it did is not known; running the trade again could trade twice. */
190
+ function unconfirmed(c, hash, cause, hashes, { awaiting = false } = {}) {
191
+ const why = cause?.shortMessage || cause?.message || String(cause);
192
+ const what = awaiting ? "got no answer from the wallet in time: it may still be awaiting approval there, or it may have been sent" : "may have been sent";
193
+ return Object.assign(new Error(`${c.what || "a call"}${hash ? ` (tx ${hash})` : ""} ${what}, and what it did is not known (${why}): check the balances (ptPosition) before trying again, since running the trade again could trade twice`),
194
+ { code: "TX_UNCONFIRMED", unconfirmed: true, hash: hash ?? null, hashes: [...hashes], step: c.what || null, cause });
195
+ }
196
+ const causes = (e) => { const out = []; for (let x = e, i = 0; x && i < 8; x = x.cause, i++) out.push(x); return out; };
197
+ /** The wallet's own user declined: nothing was sent. */
198
+ const declined = (e) => causes(e).some((x) => x.code === "ACTION_REJECTED" || x.code === 4001 || x.name === "UserRejectedRequestError");
199
+ /** The node refused the transaction for its funds (gas or value). A refusal only once the node shows no trace of it. */
200
+ const noFunds = (e) => causes(e).some((x) => x.code === "INSUFFICIENT_FUNDS" || /insufficient funds/i.test(String(x.shortMessage || x.message || "")));
201
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
202
+ /** `onSend` told of a step that already left: its own failure, thrown or a promise that rejects, cannot undo the send,
203
+ * so it never stops the trade (and a rejection is consumed, not left unhandled). */
204
+ const told = (onSend, hash, what) => {
205
+ try { const r = onSend?.(hash, what); if (r && typeof r.then === "function") r.then(null, () => {}); } catch (_) { /* the step is out; its receipt decides */ }
206
+ };
207
+ /** `p`, or `undefined` once `ms` have passed (a request that never answers does not hold the trade). */
208
+ const within = (p, ms) => { let t; return Promise.race([p, new Promise((r) => { t = setTimeout(r, Math.max(1, ms)); })]).finally(() => clearTimeout(t)); };
209
+ const succeeded = (rc) => rc.status === "0x1" || rc.status === 1 || rc.status === "success";
210
+
211
+ /** What the node says of `hash` before `end` (one deadline for both lookups): "mined" (with `rc`), "pending",
212
+ * "unknown", or null when a lookup failed or the deadline passed. */
213
+ async function lookup(client, hash, end) {
214
+ try {
215
+ const rc = await within(rpc(client, "eth_getTransactionReceipt", [hash]), end - Date.now());
216
+ if (rc === undefined) return null;
217
+ if (rc) return { state: "mined", rc };
218
+ if (Date.now() >= end) return null;
219
+ const tx = await within(rpc(client, "eth_getTransactionByHash", [hash]), end - Date.now());
220
+ if (tx === undefined) return null;
221
+ return { state: tx ? "pending" : "unknown" };
222
+ } catch (_) { return null; }
223
+ }
224
+ /** Step `c`'s receipt `rc`: itself when it succeeded, an ordinary error when it reverted (that step did nothing). */
225
+ function checked(c, hash, rc, hashes) {
226
+ if (!succeeded(rc)) throw Object.assign(new Error(`${c.what || "the call"} (tx ${hash}) reverted: that step did nothing`), { code: "CALL_EXCEPTION", hash, hashes: [...hashes] });
227
+ return rc;
228
+ }
229
+
230
+ /** Wait, until `end`, for step `c`'s receipt: done when it succeeded, an ordinary error when it reverted (that step did
231
+ * nothing), TX_UNCONFIRMED when none came; a lookup that fails is asked again. */
232
+ async function receipt(client, c, hash, hashes, end) {
233
+ let last = null;
175
234
  for (;;) {
176
- const rc = await rpc(client, "eth_getTransactionReceipt", [hash]);
177
- if (rc) { if (rc.status !== "0x1" && rc.status !== 1 && rc.status !== "success") throw new Error(`transaction ${hash} reverted`); return rc; }
178
- if (Date.now() > end) throw new Error(`transaction ${hash} not mined after ${timeoutMs / 1000} s`);
179
- await new Promise((r) => setTimeout(r, 1500));
235
+ let rc;
236
+ try { rc = await within(rpc(client, "eth_getTransactionReceipt", [hash]), end - Date.now()); } catch (e) { last = e; }
237
+ if (rc) return checked(c, hash, rc, hashes);
238
+ if (Date.now() >= end) throw unconfirmed(c, hash, last || new Error("no receipt in time"), hashes);
239
+ await sleep(Math.min(1500, Math.max(1, end - Date.now())));
240
+ }
241
+ }
242
+
243
+ /** The signed bytes of step `c` when `wallet` signs in this process (an ethers Wallet; a viem WalletClient with a local
244
+ * account), else null. Signing sends nothing: an error here is an ordinary one. An ethers signer holds its key here
245
+ * only with a `signingKey` (a Wallet): a NonceManager counts its nonces in its own sendTransaction, and a
246
+ * JsonRpcSigner has the node sign, so both send themselves. */
247
+ async function signHere(wallet, c) {
248
+ if (wallet.signingKey != null && typeof wallet.signTransaction === "function" && typeof wallet.populateTransaction === "function" && wallet.provider) {
249
+ return wallet.signTransaction(await wallet.populateTransaction({ to: c.to, data: c.data, value: c.value })); // ethers Wallet
250
+ }
251
+ if (wallet.account?.type === "local" && typeof wallet.prepareTransactionRequest === "function" && typeof wallet.signTransaction === "function") {
252
+ return wallet.signTransaction(await wallet.prepareTransactionRequest({ account: wallet.account, chain: wallet.chain ?? null, to: c.to, data: c.data, value: c.value }));
180
253
  }
254
+ return null;
181
255
  }
182
256
 
183
- /** Send `calls` in order from `wallet`, each simulated first, each waited for: the hashes. */
184
- export async function sendCalls(client, wallet, calls, from) {
257
+ /** Send `calls` in order from `wallet`, each simulated first, each waited for: the hashes. `onSend(hash, what)` is told
258
+ * of each step as it leaves: signed here, just before its broadcast (if it throws, nothing is sent); with a wallet that
259
+ * sends itself, once the wallet answers (null when its answer was lost; if it throws, the step goes on). */
260
+ export async function sendCalls(client, wallet, calls, from, { waitTimeoutMs = 180_000, onSend } = {}) {
185
261
  const hashes = [];
186
262
  for (const c of calls) {
187
263
  try { await rpc(client, "eth_call", [{ from, to: c.to, data: c.data }, "latest"]); } catch (e) { throw new Error(`${c.what || "the call"} would revert: ${e.shortMessage || e.message}`); }
188
- let hash;
189
- if (wallet.account && typeof wallet.sendTransaction === "function" && !wallet.getAddress) {
190
- hash = await wallet.sendTransaction({ account: wallet.account, chain: wallet.chain ?? null, to: c.to, data: c.data, value: c.value });
264
+ const signed = await signHere(wallet, c);
265
+ let hash = null;
266
+ if (signed) {
267
+ hash = keccak256(signed);
268
+ const end = Date.now() + waitTimeoutMs;
269
+ // awaited, within the deadline: a caller that could not record the step (or never answers) stops it before it is
270
+ // sent; a rejection after the deadline is consumed
271
+ const recorded = Promise.resolve(onSend?.(hash, c.what)).then(() => true);
272
+ recorded.catch(() => {});
273
+ if ((await within(recorded, end - Date.now())) !== true) throw new Error(`${c.what || "the call"} was not sent: onSend gave no answer in time`);
274
+ let seen = null;
275
+ try {
276
+ const answer = await within(rpc(client, "eth_sendRawTransaction", [signed]), end - Date.now());
277
+ if (answer === undefined) throw unconfirmed(c, hash, new Error("no answer to the broadcast in time"), hashes);
278
+ } catch (e) {
279
+ if (e?.unconfirmed) throw e;
280
+ seen = await lookup(client, hash, end);
281
+ if (!seen) throw unconfirmed(c, hash, e, hashes);
282
+ if (seen.state === "unknown") {
283
+ if (noFunds(e)) throw Object.assign(new Error(`${c.what || "the call"} was refused: ${e.shortMessage || e.message}`), { code: "INSUFFICIENT_FUNDS", hashes: [...hashes], cause: e });
284
+ throw unconfirmed(c, hash, e, hashes);
285
+ }
286
+ // "mined" (its receipt in hand) or "pending" (waited for below): the node took it
287
+ }
288
+ if (seen?.state === "mined") checked(c, hash, seen.rc, hashes);
289
+ else await receipt(client, c, hash, hashes, end);
191
290
  } else {
192
- const tx = await wallet.sendTransaction({ to: c.to, data: c.data, value: c.value });
193
- hash = tx.hash;
291
+ // a wallet that sends itself: one deadline from the moment it is asked (its user's approval included), over its
292
+ // send (an ethers JsonRpcSigner polls the node before it returns) and the receipt
293
+ const end = Date.now() + waitTimeoutMs;
294
+ try {
295
+ const sending = wallet.account && typeof wallet.sendTransaction === "function" && !wallet.getAddress
296
+ ? wallet.sendTransaction({ account: wallet.account, chain: wallet.chain ?? null, to: c.to, data: c.data, value: c.value })
297
+ : Promise.resolve(wallet.sendTransaction({ to: c.to, data: c.data, value: c.value })).then((tx) => tx.hash);
298
+ hash = await within(sending, end - Date.now());
299
+ if (hash === undefined) throw unconfirmed(c, null, new Error("the wallet gave no answer in time"), hashes, { awaiting: true });
300
+ } catch (e) {
301
+ if (!e?.unconfirmed && declined(e)) throw e;
302
+ told(onSend, null, c.what);
303
+ throw e?.unconfirmed ? e : unconfirmed(c, null, e, hashes);
304
+ }
305
+ told(onSend, hash, c.what);
306
+ await receipt(client, c, hash, hashes, end);
194
307
  }
195
- await receipt(client, hash);
196
308
  hashes.push(hash);
197
309
  }
198
310
  return hashes;
199
311
  }
200
312
 
201
- async function bundle(client, { kind, account, wallet, amount, slippageBps, minOut, approve = "auto", now, market }) {
313
+ async function bundle(client, { kind, account, wallet, amount, slippageBps, minOut, approve = "auto", now, market, waitTimeoutMs, onSend }) {
202
314
  const from = await accountOf(account, wallet);
203
315
  const t = now ?? (await chainNow(client));
204
316
  let m = market != null ? marketOf(market) : VIEW;
@@ -234,7 +346,7 @@ async function bundle(client, { kind, account, wallet, amount, slippageBps, minO
234
346
  const out = { kind, account: from, chainId: PT_USDG.chainId, quote: { ...q, minOut: min, minOutText: fmt6(min) }, calls, warnings };
235
347
  if (!wallet) return out;
236
348
  if (have < units) throw new Error(warnings[0]);
237
- return { ...out, hashes: await sendCalls(client, wallet, calls, from) };
349
+ return { ...out, hashes: await sendCalls(client, wallet, calls, from, { waitTimeoutMs, onSend }) };
238
350
  }
239
351
 
240
352
  /** Buy PT-USDG with `amount` USDG: the calls (approve, then the router's swap), sent when `wallet` is given. */
package/src/server.mjs CHANGED
@@ -1694,26 +1694,25 @@ export async function createPriorsMcpServer({ env = process.env, fetchImpl = glo
1694
1694
  try { b = await pt.trade(kind, o); } catch (e) { throw asked(e); }
1695
1695
  return [termsLine(b.quote), `Nothing was sent. From ${b.account}, ${b.calls.length} call${b.calls.length > 1 ? "s" : ""} in order:`, callsText(b), minLine(b), ...b.warnings.map((w) => `Note: ${w}.`)].join("\n");
1696
1696
  }
1697
- // what left the wallet is counted even when the answer is lost: a send that started may have landed. A send that
1698
- // failed is `lost` unless it was refused before it left (a reverting estimate, no ETH for gas), as for a borrow
1699
- // (GHSA-v9xj): the node may have taken it and its answer been lost, so it stays counted and is said (GHSA-549m: it
1700
- // was given back as "nothing sent" and answered with the bare transport error)
1697
+ // what left the wallet is counted even when the answer is lost: a send that started may have landed (GHSA-549m:
1698
+ // it was given back as "nothing sent" with the bare transport error). The SDK signs each step here first, so it
1699
+ // knows the hash before the broadcast and asks the node about it after a failure: mined goes on, pending is waited
1700
+ // for, "insufficient funds" with no trace of it is a refusal (nothing sent), anything else is TX_UNCONFIRMED. A
1701
+ // node's "insufficient funds" alone was a refusal here, though it can answer a retried request after the first
1702
+ // one was taken (GHSA-g5cv's class).
1701
1703
  const sent = [];
1702
- let lost = false;
1703
- const counting = { getAddress: async () => signer.address, sendTransaction: async (tx) => {
1704
- let r;
1705
- try { r = await signer.sendTransaction(tx); } catch (e) { lost = e?.code !== "CALL_EXCEPTION" && e?.code !== "INSUFFICIENT_FUNDS"; throw e; }
1706
- sent.push(r.hash);
1707
- return r;
1708
- } };
1709
1704
  if (units !== null) session.ptBought += units;
1710
1705
  let r;
1711
- try { r = await pt.trade(kind, { ...o, wallet: counting }); } catch (e) {
1706
+ try { r = await pt.trade(kind, { ...o, wallet: signer, onSend: (h) => sent.push(h) }); } catch (e) {
1712
1707
  const why = clean(e?.shortMessage || e?.message || String(e), 300);
1713
- const was = `${sent.length} transaction${sent.length > 1 ? "s were" : " was"} sent (${sent.join(", ")})`;
1714
- if (lost) throw new ToolError(`${sent.length ? `${was}, then another` : "A transaction"} may have been sent: its answer was lost (${why}).${units !== null ? ` Its ${usd(units)} stays counted against PRIORS_MAX_PT_TOTAL_USD.` : ""} Check pt_position and wallet_balance before trying again.`);
1715
- if (sent.length === 0 && units !== null) session.ptBought -= units;
1716
- if (sent.length) throw new ToolError(`${was}, then: ${why}. Check pt_position and wallet_balance before trying again.`);
1708
+ const done = Array.isArray(e?.hashes) ? e.hashes : [];
1709
+ const was = (list) => `${list.length} transaction${list.length > 1 ? "s were" : " was"} sent (${list.join(", ")})`;
1710
+ if (e?.unconfirmed) throw new ToolError(`${done.length ? `${was(done)}, then another` : "A transaction"} may have been sent: its answer was lost (${why}).${units !== null ? ` Its ${usd(units)} stays counted against PRIORS_MAX_PT_TOTAL_USD.` : ""} Check pt_position and wallet_balance before trying again.`);
1711
+ // not unconfirmed: the steps that went through are the SDK's `hashes` (a refused or reverted step did nothing);
1712
+ // an error before any step left carries none
1713
+ const went = Array.isArray(e?.hashes) ? done : sent.filter(Boolean);
1714
+ if (went.length === 0 && units !== null) session.ptBought -= units;
1715
+ if (went.length) throw new ToolError(`${was(went)}, then: ${why}. Check pt_position and wallet_balance before trying again.`);
1717
1716
  throw asked(e);
1718
1717
  }
1719
1718
  const done = kind === "buy" ? `Bought about ${nf(r.quote.expectedOutText)} PT-USDG (at least ${nf(r.quote.minOutText)}) with ${usd(units)}`