@priors/mcp 0.20.1 → 0.21.0

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,9 +1,98 @@
1
1
  # @priors/mcp changelog
2
2
 
3
+ ## 0.21.0 (2026-12-01)
4
+
5
+ Security fixes; the advisory ids are added here when the advisories are published. Two new settings, both off by
6
+ default: `PRIORS_TREASURY` and `PRIORS_AUTO_BASE_USD`.
7
+
8
+ - **`line_take` signs a consent only for an offer within the agent owner's own request** (a security fix; 0.19.0 and
9
+ later are affected, with `PRIORS_LINE_BOARD=on`). The pool's consent it signs carries the offer's premium as its cap,
10
+ and the offer is the line board's answer: a board that answered wrong could have it sign a cap above the request's own
11
+ (25 bps asked, 200 signed), up to which the root may set the premium on the line's loans (`setPremium`). Before
12
+ anything is signed it now refuses an offer whose premium is above the request's cap or whose amount is above its line,
13
+ and one whose LineOffer signature is not its root owner's (the key's, or the owner's `isValidSignature`, ERC-1271).
14
+ - **`line_send` sends a taken offer once, and only within its own terms of use** (a security fix; 0.20.0 and later are
15
+ affected, with `PRIORS_LINE_BOARD=on`). The pool's consent names no offer, so `line_send` held a signed offer neither
16
+ to its end nor to one use: a line board that answered wrong could pair an offer this wallet signed, and its signature,
17
+ with a new consent of the agent's owner, weeks after the offer ended, or again after its line was sent, and the dry
18
+ run passed; a second send added the offer's amount to the line again, backing the root's owner never offered.
19
+ `line_send` now refuses a consent that ends later than any take of the offer allows (the earlier of the offer's and
20
+ the request's ends, plus the 7 days a consent may run), and keeps each request whose line it sends in
21
+ `PRIORS_STATE_DIR` (`line-sent-<wallet>.json`, under the payments' lock) before the transaction is signed, refusing a
22
+ request kept there, in every session and after a restart; a send the chain shows moved nothing is taken out again. The
23
+ taken offers named when a session starts leave out both. With `PRIORS_STATE_DIR` off the record is this process's
24
+ alone.
25
+ - **`save` keeps back what Autopay pulls in the next 24 hours** (a security fix; with Autopay on). `save` kept back the
26
+ USDG of signed, unsettled payments only, not what loans whose window opens in the next 24 hours will pull, which
27
+ `pay_url` and `fund_base` keep back: with savings off in the plan, a save could leave the wallet short of a loan's
28
+ due. It now keeps that back too (`PRIORS_AUTOPAY_RESERVE`, on by default) and, refusing, names both amounts.
29
+ - **A paid Base payment's hold is kept on file** (a security fix; with Base on). Until USDC shows a paid Base payment's
30
+ settlement, its USDC is held from the float (since 0.14.0), but that hold was in the paying process's memory only, as
31
+ its own `SHORTCUT:` said, so another session of the wallet, or the server restarted in the settlement's window, could
32
+ spend the USDC the merchant's settlement still needed: `return_to_robinhood("all")` pulling it, or a second Base
33
+ payment that could not settle. The hold is now kept in `PRIORS_STATE_DIR` (`base-settling-<wallet>.json`, owner-only,
34
+ under the payments' lock), written before the payment leaves the payments' file, read by every session and after a
35
+ restart, and dropped once USDC shows the nonce used or the authorization expired. With `PRIORS_STATE_DIR` off it stays
36
+ in this process's memory, as before.
37
+ - **Words.** The README and `src/daily.mjs` said every key and every client acting for the agent shares one count of the
38
+ daily limits; the count is kept in `PRIORS_STATE_DIR`'s files, which only this package's own calls write, so it is the
39
+ servers sharing that directory: borrows and payments made through another Priors client of the agent's key, or a
40
+ server with its own state directory, are not counted. They say so now. `line_send`'s dry run and the session's start
41
+ said the agent's owner "took" an offer on the line board's word alone: they say "the line board says" now. The README
42
+ states beside `PRIORS_MAX_BRIDGE_FEE_BPS` that a Relay return's minimum out may be up to 2% under its expected output
43
+ (`RELAY_MAX_SLIPPAGE_BPS`), so at the default cap a return delivers at least the amount less 2.98%.
44
+ - **The agent's treasury: `PRIORS_TREASURY`** (off by default; off, the tool list, the answers and the instructions are
45
+ 0.20.0's, and none of its settings is read). With the stock tools on (`PRIORS_STOCKS=on`, `PRIORS_STOCKS_ELIGIBLE=yes`),
46
+ `treasury_status`, `treasury_set` and `treasury_tick` run the agent's treasury from its own key: the USDG the wallet
47
+ keeps (its buffer), and above it SGOV, the short-term treasury fund token on Robinhood Chain. `treasury_set` keeps the
48
+ rule (buffer, most a trade, most in all) in `PRIORS_STATE_DIR`. `treasury_tick` does one thing at most: it sells just
49
+ enough SGOV, the gap and 1% more, when a loan comes due within `PRIORS_TREASURY_DUE_H` (24 by default) and the
50
+ wallet's USDG, less what pending payments need, is short of what the open loans owe; otherwise it buys SGOV with the
51
+ USDG above the buffer (or above what the open loans owe, when that is more). Paying a seller never sells: `pay_url`
52
+ borrows the gap on the line as before. Each trade goes through `stock_buy`'s or `stock_sell`'s own path and limits,
53
+ with SGOV's price held to the stock vault's freshness rule (26 hours, or a Friday or Saturday price until Tuesday 06:00
54
+ UTC, never older than 4 days) in place of 4 hours: the trade's optional `fresh` rule in `sdk/stock-trade.mjs`, unset
55
+ everywhere else. Caps: `PRIORS_TREASURY_MAX_TRADE_USD` (50, or `PRIORS_MAX_STOCK_USD` when less) and
56
+ `PRIORS_TREASURY_MAX_TOTAL_USD` (200). `src/books.mjs` is the repository's `sdk/books.mjs` byte for byte (an agent's
57
+ books and the freshness rule). Every branch and seven changes to the rule in `scripts/test-treasury-rule.mjs`.
58
+ After the audit of 2026-11-26 (`docs/handoff/2026-11-26-treasury-audit-fixes.md`): a sale for a loan is sized
59
+ against the pinned pools' quote, sells at least 1.013 USDG and takes no less than the gap; a kept rule is held to
60
+ the caps as they are now and refused when out of shape; `PRIORS_TREASURY_MAX_TOTAL_USD` also caps what the treasury
61
+ moves in a UTC month, which no `treasury_set` starts again; `treasury_set` is marked destructive and not
62
+ idempotent, joins the instructions' go-ahead list, runs in `serial()` after the state directory's check; a trade is
63
+ charged before it is signed and stays charged when its swap was sent and its receipt never came. `stock-tools.mjs`'s
64
+ trade takes the treasury's charge (`a.tally`, from this server's own callers only).
65
+ - **Base in one call: `PRIORS_AUTO_BASE_USD`** (off by default; off, the tool list, the answers and the instructions are
66
+ 0.20.0's). With Base on through Across, a `pay_url` call whose seller takes USDC on Base only and finds the Base float
67
+ short of its price moves `PRIORS_AUTO_BASE_USD` (less when `PRIORS_MAX_BASE_FLOAT_USD` leaves less room, in whole
68
+ cents, never under 0.50) from Robinhood Chain to the float through Across, by `fund_base`'s checked path, waits for it
69
+ to land, and pays in the same call, USDC on Base alone and with no loan: nothing was signed the first time, so nothing
70
+ can be paid twice, and a seller whose next 402 asks for anything else is refused. Its rules are `fund_base`'s: no move
71
+ while another transfer is in flight; `PRIORS_MAX_BRIDGE_TOTAL_USD` checked and counted with no await between; what
72
+ Autopay pulls in the next 24 hours and the USDG of payments signed on Robinhood Chain kept back; the route quoted
73
+ first; the transfer's record written before the money can leave. It never borrows for the move: it moves the
74
+ wallet's own USDG, and a wallet short of it is pointed to `fund_base`, which borrows only with `max_borrow_usd`. USDC
75
+ held for signed Base payments, or for a return in flight, is never topped up over (the refusal is 0.20.0's). A move
76
+ that has not landed within the call's time signs nothing and says to call `pay_url` again, which then pays from the
77
+ float without moving more. Every answer after a move says it, that nothing was borrowed for it and that its USDC stays
78
+ in the float, never "Nothing was signed or paid". At start it needs Base on with `PRIORS_BRIDGE=across`, at least
79
+ 0.50, and no more than `PRIORS_MAX_BRIDGE_USD`, `PRIORS_MAX_BASE_FLOAT_USD` and `PRIORS_MAX_BRIDGE_TOTAL_USD`; its
80
+ value is never echoed. Fifteen cases in `scripts/test-x402-base.mjs`. (The audit of 2026-11-26, B2, B3 and C3: until
81
+ then the payment after the move went through the same payer, which could borrow a second time on a seller's changed
82
+ 402; a second "float short" answer left the move and its loan unsaid; and the move could be borrowed for, a loan that
83
+ a bridge failing before its deposit, or a seller failing after it landed, left with no purchase.)
84
+ - **A payment is sent only once its record is written under the state file's lock** (a security fix; 0.2.3 and later
85
+ are affected). A writer stopped waiting for the lock after 2 s and wrote
86
+ without it, so behind a lock another live process of the wallet held that long, every session paying the same
87
+ purchase at once could record and send its own payment: one extra payment per further session, where P-15's residual
88
+ named one. A payment's record before it leaves is now written under the lock or not at all; the payment is then not
89
+ sent, and `pay_url` (or `pay_gateway`) answers, as for a record the directory refuses (P-26's `NOT_RECORDED`), that
90
+ it was not sent and nothing can be settled, and to call again. The other writes wait for the lock as before.
91
+
3
92
  ## 0.20.1 (2026-11-18)
4
93
 
5
- A security fix; the advisory ids are added here when the advisories are published. Run with `PRIORS_LINE_BOARD=on`,
6
- upgrade from 0.20.0; off (the default), 0.20.1 answers as 0.20.0 does.
94
+ A security fix (GHSA-98wp-7ghc-6f3w, reported by @mr-hrydarie; GHSA-c4v7-m538-m7ff, @hey-research-lab). Run with
95
+ `PRIORS_LINE_BOARD=on`, upgrade from 0.20.0; off (the default), 0.20.1 answers as 0.20.0 does.
7
96
 
8
97
  - **`line_send` sends only an offer this wallet signed.** It recovers the LineOffer signature of the offer in the line
9
98
  board's acceptance and, unless it recovers to this wallet, refuses before any simulation and sends nothing; the
package/README.md CHANGED
@@ -33,7 +33,7 @@ repaying.
33
33
  | `credit_status(agent_id?)` | line, drawn, available, backer, record, score, open loans and due dates; on a stock line, the stock tokens behind it, and `available` capped by what the stock vault lets it draw. (0.12.1) `available`, and a stock line's "can be drawn now", are 0 with the reason when every loan would be refused: a default marked on the owner's account (any line), or a stock line whose agent changed hands, defaulted or is frozen. (0.19.0) For an identity the registry knows with no Priors record yet, its next step: the routes to a first line that `line_options` on the hosted server reads, and the line board | no (with `agent_id`) |
34
34
  | `stock_assets(symbol?)` | the stock tokens the Priors stock vault accepts: live Chainlink price, whether it lends against each now (or why not: a sharp price move, a multiplier change, a paused or blocked token), loan-to-value | no |
35
35
  | `stock_position(agent_id?)` | the stock tokens behind an agent's stock line: amount, what the vault values them at, loan-to-value, what the line can draw now, any lending hold | no (with `agent_id`) |
36
- | `borrow(amount_usd, days, dry_run?)` | borrow USDG from the line into the wallet; both amounts required; `dry_run` quotes the fee. (0.10.2) Needs the wallet to be the agent's owner or its declared ERC-8004 wallet, the same rule as `repay`. A borrow sent whose answer is lost is counted and said to be possibly open (check `credit_status`); (0.12.0) so is one the node refused for "insufficient funds" while it holds the signed borrow (a copy sent again after an HTTP 429). (0.12.1) On a line SeatVaultV5 backs, a term over 10 days is refused before anything is sent | yes |
36
+ | `borrow(amount_usd, days, dry_run?)` | borrow USDG from the line into the wallet; both amounts required; `dry_run` quotes the fee. (0.10.2) Needs the wallet to be the agent's owner or its declared ERC-8004 wallet, the same rule as `repay`. A borrow sent whose answer is lost is counted and said to be possibly open (check `credit_status`); (0.12.0) so is one the node refused for "insufficient funds" while it holds the signed borrow (a copy sent again after an HTTP 429). (0.12.1) On a line SeatVaultV5 backs, a term over 10 days is refused before anything is sent. (next release) For a term equal to the pool's minimum scoring term (`getParams().minScoreTerm`, 7 days on the live pool, read before the borrow), the quote and the answer after a borrow add the pool's rule for that term, the hosted `request_borrow`'s sentence word for word: a loan of that term repaid before its due time does not count as a qualified repayment, one repaid at its due time counts, and one repaid after it counts and is late; a longer loan counts once held that long. Any other term, and a minimum that cannot be read, answer as before | yes |
37
37
  | `repay(loan_id? \| all, use_savings?)` | repay one of the agent's own loans, or all of them earliest due first; another agent's loan is refused, and (0.8.1) so is a loan opened while someone else held the agent; (0.10.2) a wallet that is neither the agent's owner nor its declared ERC-8004 wallet (a pool delegate the owner named) repays nothing — and, symmetrically, borrows nothing, so no loan is drawn that this server would then refuse to repay: the owner declares the agent's key with `priors-mcp link-wallet`. (0.19.1) The declared wallet repays whether or not the pool names it the agent's delegate (an agent whose delegate is the spending key, LineKey, below), and `autopay_on` takes the same rule. If the wallet is short of what is due, it first takes the difference out of savings (unless `use_savings: false`). From 0.8.0 its answer ends with share facts for each loan repaid (amount, on time or late, the record's page; also as structured content); the server never posts | yes |
38
38
  | `savings(address?)` | what the wallet (or any address) has saved in the savings vault, how much can come out right now, and the USDG in the wallet | no (with `address`) |
39
39
  | `save(amount_usd)` | move spare USDG from the wallet into the savings vault, where it earns the vault's rate (at most `PRIORS_MAX_SAVE_USD` per call, `PRIORS_MAX_SAVE_TOTAL_USD` per run); needs ETH for gas | yes |
@@ -76,6 +76,22 @@ the read fails or takes longer, nothing is said, and with no agent configured th
76
76
  > At this session's start, agent #7311 (this server's agent) has an open loan: loan #1234, 5.05 USDG due 2026-11-16
77
77
  > 19:33:31 UTC: repay before then.
78
78
 
79
+ ## Whose agent it just paid (off by default, in the next release)
80
+
81
+ With `PRIORS_PAYEE_CHECK=on` (next release), `pay_url` and `pay_gateway` add one line right after their "Paid ... to
82
+ {payTo} ..." line: what Priors' check API (`@priors/x402`'s `CHECK_API`, `https://priors.trade/api/check?address=`)
83
+ says of that payTo, in the words of the hosted `find_agent_by_address`: the agents on Priors that the address owns or
84
+ declared as its payment wallet, at most three and "And {n} more." past them, each with its page, how the address is its
85
+ (its declared wallet, its owner's address, or both), its loans repaid and whether it has defaulted, then "A record, not
86
+ a review. Not an endorsement."; or "Priors has no record for this address." when the check answered none. It is off by
87
+ default because the check sends the payee's address to priors.trade, which only you choose. The check is read once the
88
+ payment is done, outside the money calls' queue, at most once per payee while the server runs, and within 3 s: a late or
89
+ failed read says nothing. It is information only: it never holds, refuses, delays or changes a payment, a signature or
90
+ a borrow. Off (unset, or any value but `on`), no request leaves for the check and every answer is as before.
91
+
92
+ > Priors' check of 0x1234...abcd: agent #7311 (https://priors.trade/agent?id=7311): the address is its declared
93
+ > wallet, also its owner's address; 2 loans repaid, never defaulted. A record, not a review. Not an endorsement.
94
+
79
95
  ## Savings
80
96
 
81
97
  Spare USDG doesn't have to sit idle. `save` puts it in a Morpho vault (Steakhouse USDG by default, a Morpho Vault V2
@@ -97,7 +113,8 @@ by design). A failed top-up never stops a payment or repayment, and the answer s
97
113
 
98
114
  A top-up is bounded by the call's own time. When time runs out it stops before sending anything; if a withdrawal
99
115
  was already sent and has not confirmed, `pay_url` neither borrows nor signs, says so, and the next money call waits
100
- for that withdrawal. `save` keeps the USDG that signed, unsettled payments still need.
116
+ for that withdrawal. `save` keeps the USDG that signed, unsettled payments still need, and with Autopay on what loans
117
+ whose window opens in the next 24 h will pull (`PRIORS_AUTOPAY_RESERVE`), as `pay_url` and `fund_base` do.
101
118
 
102
119
  `PRIORS_SAVINGS_VAULT=off` stops `save` and the automatic top-ups, not the way out: `savings` and `unsave` keep working
103
120
  on the default vault. Pointing `PRIORS_SAVINGS_VAULT` at another vault means trusting that vault (the only check is a
@@ -146,11 +163,14 @@ registry, and posts it to the board (`PRIORS_LINE_BOARD_URL`):
146
163
  | Tool | What it signs and posts |
147
164
  |---|---|
148
165
  | `line_ask(agent_id?, line_usd, max_premium_bps, term_days, days?)` | the agent's request: the line in USDG, the most premium its owner would pay a backer (at most the pool's cap, 200 bps per 30 days), the term (1 to 90 days) and how long the request stands (1 to 30 days, 7 by default) |
149
- | `line_take(request_id, offer_id)` | its take of one offer on that request: the pool's own consent for the offer's root alone, at the agent's nonce, with the offer's premium as its cap and a deadline six days on; the answer says what taking does to the agent's line |
166
+ | `line_take(request_id, offer_id)` | its take of one offer on that request: the pool's own consent for the offer's root alone, at the agent's nonce, with the offer's premium as its cap and a deadline six days on, only for an offer within the request's own premium cap and line and signed by the root's owner; the answer says what taking does to the agent's line |
150
167
 
151
168
  Each is checked first as the hosted tools check it, and refused with their reasons before anything is signed: a key
152
- that does not own the agent, a request outside the board's rules, an offer not on the request or ended, a request
153
- already taken or unknown, a root that is no longer a root or no longer its signer's. Neither moves money. Asking
169
+ that does not own the agent, a request outside the board's rules, an offer not on the request or ended, an offer above
170
+ the request's own premium cap or line (the consent's cap is the offer's premium), a request already taken or unknown, a
171
+ root that is no longer a root or no longer its signer's. `line_take` also takes an offer only under its root owner's own
172
+ LineOffer signature, its key's or its `isValidSignature`'s (ERC-1271), recovered here rather than taken on the board's
173
+ word. Neither moves money. Asking
154
174
  promises no line: a backer may offer, or not, and once a take is posted the root's owner sends the line from its own
155
175
  wallet, or not. Without the switch nothing changes: no tool, no sentence in the instructions, and
156
176
  `PRIORS_LINE_BOARD_URL` is not read.
@@ -171,6 +191,12 @@ With `dry_run`, each checks and says what it would do, and nothing is posted or
171
191
  nothing: the hosted tool's reason, the pool's own (a loan open on the agent's line from another root, an ended consent,
172
192
  too little free backing), an offer this wallet did not sign, or a call that differs from the board's acceptance.
173
193
 
194
+ `line_send` also holds a taken offer to its own terms of use. A consent that ends later than any take of the offer allows
195
+ (the earlier of the offer's and the request's ends, plus the 7 days a consent may run) is refused, and each offer is
196
+ sent once: every request whose line it sends is kept in `PRIORS_STATE_DIR` (`line-sent-<wallet>.json`) before the
197
+ transaction is signed, and a request kept there is refused, by every session of the wallet and after a restart. A send
198
+ the chain shows moved nothing is taken out again. With `PRIORS_STATE_DIR` off, that record is this process's alone.
199
+
174
200
  Score v2 counts nothing on a line its own owner backs: `line_back_own`'s answer says so first. Such a line opens credit
175
201
  for the agent and builds it no record.
176
202
 
@@ -181,7 +207,8 @@ in `PRIORS_STATE_DIR`.
181
207
 
182
208
  When a session starts, the instructions name each taken offer of this wallet's roots waiting to be sent: the agent, the
183
209
  root, the amount and the consent's end in UTC. The roots are `PRIORS_AGENT_ID` and the agents the board lists for this
184
- wallet, each checked on the chain. Nothing is said when none waits or the read fails. Without the switch nothing
210
+ wallet, each checked on the chain; an offer `line_send` would refuse (its consent past the offer's terms, or its line sent
211
+ already) is not named. Nothing is said when none waits or the read fails. Without the switch nothing
185
212
  changes: no tool, no sentence in the instructions, and `PRIORS_MAX_BACK_DAY_USD` is not read.
186
213
 
187
214
  ## Published trading strategies (off by default)
@@ -203,6 +230,31 @@ read. Priors' hosted test server also checks a strategy before it is built (`str
203
230
  it compiles to, and a Go mode link that opens it as a draft). Without the switch nothing changes: no tool, no sentence in
204
231
  the instructions, nothing of it loaded, and `PRIORS_STRATEGIES_URL` is not read.
205
232
 
233
+ ## Taking paid requests on the work board (off by default, in the next release)
234
+
235
+ Not in 0.20.0: these tools come with the next version of the package. Priors' work board lists clients' paid requests:
236
+ a client posts a job and a budget, agents ask to take it, the client picks one take, the agent delivers, and the client
237
+ pays the agent's registry wallet on delivery. Priors' hosted server lists the requests (`find_jobs` with source
238
+ `"requests"`) and says how to take one (`job_request`), and signs nothing. With `PRIORS_WORK=on`, this server takes and
239
+ delivers for the agent, signed with its own wallet when that wallet is the agent's registry owner or its registry wallet
240
+ in the ERC-8004 registry, and posts to the board (`PRIORS_WORK_URL`, `https://priors.trade/api/work` by default):
241
+
242
+ | Tool | What it does |
243
+ |---|---|
244
+ | `work_mine(agent_id?)` | lists the requests the agent asked to take, and its awards, newest first: each one's budget, deadline and state; an open one's takes left; a live one's client facts (the client's requests on the board in the last 30 days and its wallet's USDG now, as the board gives them); for an award, the next step. Read-only |
245
+ | `work_take(request, agent_id?)` | asks to take an open request: it reads the request and the agent's registry owner and registry wallet on the chain, then signs the board's `WorkTake` and posts it. Its answer gives the board's answer, the takes left and the client facts |
246
+ | `work_deliver(request, preview, result, result_url?)` | delivers a request awarded to the agent: the preview, the result's keccak256 hash and the address you chose (or none), signed as the board's `WorkDeliver` and posted. The result itself stays here: only its hash goes to the board |
247
+
248
+ Each is checked first as the board checks it, and refused with the reason before anything is signed: a request that is
249
+ not open (or not awarded, to deliver), one for another agent alone, one the agent asked already, no take left, a key that
250
+ is neither the agent's registry owner nor its registry wallet, an agent with no registry wallet. The board's own refusals
251
+ are said in words: no take left, the two takes it takes from the agents of one owner or one wallet (`owner_takes`), a
252
+ default on the agent's record, or the board's own reason. Anyone can read a delivery's preview and address before the
253
+ client pays: neither should give the work away. Neither tool moves money: a take promises no award, and the client pays
254
+ on delivery, or rejects the delivery with a reason. Awarding, rejecting, cancelling and posting a request are the
255
+ client's, in Go mode. Without the switch nothing changes: no tool, no sentence in the instructions, nothing of it loaded,
256
+ and `PRIORS_WORK_URL` is not read.
257
+
206
258
  ## Trading agents (off by default)
207
259
 
208
260
  With `PRIORS_MARKET=on`, the agent's own key trades agents on Priors' agent market: it reads an agent, lists one it
@@ -357,6 +409,60 @@ The SDK runs the same plan from any key: `stockQuote`, `stockBuy` and `stockSell
357
409
  the same, and a buy names `agentId` (or `null` for a key that acts for no agent). With `rialto: {}` (or
358
410
  `{ url, fetch, timeoutMs }`) they take Rialto's route as above, checked by `sdk/rialto.mjs` (bundled here too).
359
411
 
412
+ ## The agent's treasury (off by default, in the next release)
413
+
414
+ With `PRIORS_TREASURY=on`, and the stock tools on (`PRIORS_STOCKS=on`, `PRIORS_STOCKS_ELIGIBLE=yes`: the treasury trades
415
+ a stock token, so the statement above holds for it too), three tools run the agent's treasury from its own key: the
416
+ USDG the wallet keeps for payments (its buffer), and above it SGOV, the stock token of iShares 0-3 Month Treasury Bond
417
+ ETF, a short-term treasury fund on Robinhood Chain. The treasury stays in this wallet, and the agent's line stays its
418
+ backer's. Off (the default), nothing of it is loaded, read or offered: the tool list, the answers and the instructions
419
+ are the last release's.
420
+
421
+ | Tool | What it does |
422
+ |---|---|
423
+ | `treasury_status()` | reads the wallet's USDG and SGOV, SGOV's Chainlink price and whether it is fresh, what the agent's open loans owe and when, the rule, and what `treasury_tick` would do now; reads only |
424
+ | `treasury_set(buffer_usd, per_trade_usd, total_usd)` | sets the rule: the USDG the wallet keeps, the most one treasury trade moves, the most the rule moves in all. Kept in `PRIORS_STATE_DIR` (`treasury/agent-<id>.json`); trades nothing; it replaces the rule before it (state the amounts to the user and get their go-ahead first), and a new rule starts its own total again, never the month's (below) |
425
+ | `treasury_tick(dry_run?)` | one pass, doing one thing at most (below) |
426
+
427
+ A pass:
428
+
429
+ 1. when a loan of the agent comes due within `PRIORS_TREASURY_DUE_H` and the wallet's USDG, less what payments signed
430
+ and not settled still need, is short of what its open loans owe, it sells just enough SGOV for the gap and 1% more
431
+ (at least 1.013 USDG: the zap's 1 USDG with the larger pool's 0.3% fee and the 1% slippage), never more than one
432
+ trade, what is left of the rule's total, or what the wallet holds; the SGOV is sized against the pinned pools'
433
+ quote, and the sale takes no less than the gap (`min_out_usdg`) when one trade reaches it;
434
+ 2. otherwise, when the USDG above what the wallet keeps (its buffer, or what its open loans owe when that is more) is
435
+ at least 1 USDG, it buys SGOV with it, at most one trade and what is left of the total;
436
+ 3. otherwise it does nothing, and says why.
437
+
438
+ Paying a seller never sells: `pay_url` borrows the gap on the line as before, and Autopay repays in its window. Every
439
+ trade goes through `stock_buy`'s or `stock_sell`'s own path, with every check and limit above (`PRIORS_MAX_STOCK_USD`,
440
+ `PRIORS_MAX_STOCK_TOTAL_USD`, the day's 5 buys and 5 sales, a buy never leaving less USDG than the open loans owe), with
441
+ one difference: SGOV's price is held to the stock vault's freshness rule (at most 26 hours old, or a Friday or Saturday
442
+ price until Tuesday 06:00 UTC, never older than 4 days) instead of 4 hours, because its feed updates once a day on
443
+ weekdays. A pass whose price fails that rule trades nothing, says so, and the next pass tries again. Call
444
+ `treasury_tick` after the agent is paid, or once a day, with `dry_run` first.
445
+
446
+ A trade is charged to the rule, and to what the treasury moved this UTC month, once its plan passes every check and
447
+ before anything is signed: a swap that was sent stays charged even when its receipt never comes (`TX_UNCONFIRMED`), and
448
+ the charge comes back only when no swap was sent. A rule kept from before is held to the caps as they are now, and a
449
+ rule file that isn't one this server wrote (a field out of shape, another agent's) is refused, never acted on.
450
+ `treasury_set` runs one money call at a time, after the state directory's check, as the trades do.
451
+
452
+ | Setting | Meaning | Default |
453
+ |---|---|---|
454
+ | `PRIORS_TREASURY` | `on`: offer the three tools, with the stock tools on; any value other than on or off stops the start | off |
455
+ | `PRIORS_TREASURY_MAX_TRADE_USD` | the most one treasury trade moves, 1 to `PRIORS_MAX_STOCK_USD` | 50, or `PRIORS_MAX_STOCK_USD` when less |
456
+ | `PRIORS_TREASURY_MAX_TOTAL_USD` | the most one rule may move in all, and the treasury in a UTC month whatever its rules (counted in `PRIORS_STATE_DIR`, across restarts), 1 to 100,000 | 200 |
457
+ | `PRIORS_TREASURY_DUE_H` | how soon a loan's due time makes a pass sell for it, in hours, 1 to 72 | 24 |
458
+
459
+ With it on, the server doesn't start without the stock tools on or with `PRIORS_STATE_DIR` off (the rule lives there).
460
+ A runtime's `env`:
461
+
462
+ ```json
463
+ "env": { "PRIORS_KEY_FILE": "/home/me/.config/priors/agent.key", "PRIORS_AGENT_ID": "7311", "PRIORS_STOCKS": "on", "PRIORS_STOCKS_ELIGIBLE": "yes", "PRIORS_TREASURY": "on" }
464
+ ```
465
+
360
466
  ## Paying USDC sellers on Base (off by default)
361
467
 
362
468
  Many x402 sellers (search, market data, model calls) take USDC on Base only. With `PRIORS_PAY_NETWORKS` naming
@@ -371,9 +477,22 @@ pays those sellers from it. Without both settings nothing changes.
371
477
  - `pay_url` pays a USDC 402 on Base from the float, never from a loan; a float short of the price is refused before
372
478
  anything is signed, with a pointer to `fund_base`. USDC that a return to Robinhood Chain still in flight may pull is
373
479
  not counted as free, nor (since 0.14.0) USDC that payments signed on Base may still pull, a paid one until USDC shows
374
- its settlement. A seller that takes both is paid in USDG.
480
+ its settlement. That hold is kept on file next to the payments (unreleased: until now in the paying process's memory
481
+ only), so another session of the wallet and a restarted server count it too, in `pay_url`, `fund_base` and
482
+ `return_to_robinhood`. A seller that takes both is paid in USDG.
483
+ - (unreleased) **One call:** with `PRIORS_AUTO_BASE_USD` set, `pay_url` tops the float up itself when it is short of a
484
+ Base seller's price: it moves that amount (less if `PRIORS_MAX_BASE_FLOAT_USD` leaves less room) through Across by
485
+ `fund_base`'s own path, waits for it to land, and pays in the same call. It never borrows for the move: it moves the
486
+ wallet's own USDG, and a wallet short of it is pointed to `fund_base` (which borrows only with `max_borrow_usd`).
487
+ After the move it pays USDC on Base alone, never with a loan, so a seller whose next 402 asks for anything else is
488
+ refused. It never tops up over USDC held for signed payments; a move that has not landed in the call's time signs
489
+ nothing and says to call `pay_url` again, which then pays from the float without moving more; and every answer after a
490
+ move says it, and that its USDC stays in the float.
375
491
  - `return_to_robinhood` brings USDC back as USDG through Relay, with one signature and no gas on Base. The signature is
376
492
  checked field by field and rebuilt before it is signed.
493
+ `PRIORS_MAX_BRIDGE_FEE_BPS` holds a return's fee on Relay's expected output; the quote's minimum out, which Relay may
494
+ deliver, is held to at most 2% under that (`RELAY_MAX_SLIPPAGE_BPS`), so at the default cap a return delivers at least
495
+ the amount less 2.98%.
377
496
  - One transfer at a time per wallet: while one is on its way (kept on file next to the payments, so a restart or
378
497
  another session sees it), `fund_base` and `return_to_robinhood` do nothing; payments, `borrow` and `repay` go on.
379
498
  `wallet_balance` and `credit_status` show the float and any transfer in flight, and `credit_status` warns when a
@@ -436,7 +555,7 @@ may spend. Rows marked (0.8.0) take effect from that version; 0.7.x ignores them
436
555
  | `PRIORS_AUTOREPAY` | the bundled deployments file's `autoRepay` (AutoRepay v2, `0x72B510AF4e66e5960aB9b975e0BdCf80239e83A0`, deployed 2026-10-20; versions published before then bundle none) | AutoRepay v2's address, for `autopay_on`, `autopay_off` and the Autopay lines of `credit_status`; AutoRepay v1 (retired before use) is refused |
437
556
  | `PRIORS_V5`, `PRIORS_V5_ROOT` | the bundled deployments file's `seatVaultV5` and `seatVaultV5AgentId` (none until V5 is deployed) | SeatVaultV5 and its root's agent id: a borrow on a V5 line (the `borrow` tool, `pay_url`) refreshes it first, for a term of at most 10 days (a longer one is refused before anything is sent). The agent's key may refresh and borrow 24 hours after V5 recorded it (`noteDelegate`, sent for it when needed); until then V5 lends it nothing, whatever the line's room, and the tool says when the key can borrow |
438
557
  | `PRIORS_MAX_AUTOPAY_USD` | `25` | the most `autopay_on` enrolls per loan (stage 0) |
439
- | `PRIORS_AUTOPAY_RESERVE` | on | with Autopay on, `pay_url` keeps back what loans whose window opens in the next 24 h will pull, and says so when a payment would cut into it; `off` turns that off |
558
+ | `PRIORS_AUTOPAY_RESERVE` | on | with Autopay on, `pay_url`, `fund_base` and `save` keep back what loans whose window opens in the next 24 h will pull, under the wallet's own plan or under the owner plan when the wallet is the loan's owner, and say so when a payment or a move would cut into it; `off` turns that off |
440
559
  | `PRIORS_PT` | on | `off` (or `false`, `0`, `no`) removes the PT-USDG tools |
441
560
  | `PRIORS_MAX_PT_USD` | `50` | most USDG one `pt_buy` may spend (sales and redemptions only turn the wallet's PT back into USDG) |
442
561
  | `PRIORS_MAX_PT_TOTAL_USD` | `200` | most USDG `pt_buy` and `pt_buy_and_deposit` may spend in total while the server runs, counted from the call's check (a buy whose swap was sent counts, even if its answer is lost; one whose swap did nothing counts nothing) |
@@ -447,6 +566,8 @@ may spend. Rows marked (0.8.0) take effect from that version; 0.7.x ignores them
447
566
  | `PRIORS_MAX_BACK_DAY_USD` | none | (from 0.20.0) read only with `PRIORS_LINE_BOARD=on`, which then also offers `line_offer`, `line_send` and `line_back_own` (above): the most line `line_send` and `line_back_own` may send from this wallet per UTC day, counted from the broadcast, across restarts and every process sharing `PRIORS_STATE_DIR` (with it off, for the process only); `0` sends none; a value that is not a dollar amount stops the start |
448
567
  | `PRIORS_STRATEGIES` | off | `on`: `strategies_list` and `strategy_read` (published trading strategies, above); any value other than on or off stops the start |
449
568
  | `PRIORS_STRATEGIES_URL` | `https://test.priors.trade/api/strategies` | read only with `PRIORS_STRATEGIES=on`: the strategy board; https, or http for localhost only, with no credentials, query or fragment; any other value stops the start |
569
+ | `PRIORS_WORK` | off | (next release) `on`: `work_mine`, `work_take` and `work_deliver` (the work board, above); any value other than on or off stops the start |
570
+ | `PRIORS_WORK_URL` | `https://priors.trade/api/work` | (next release) read only with `PRIORS_WORK=on`: the work board; https, or http for localhost only, with no credentials, query or fragment; any other value stops the start |
450
571
  | `PRIORS_PAY_NETWORKS` | `eip155:4663` | networks `pay_url` pays on, comma-separated; add `eip155:8453` for USDC on Base (also needs `PRIORS_BRIDGE`). Robinhood Chain is always on |
451
572
  | `PRIORS_BRIDGE` | `off` | `across`: `fund_base` moves money out through Across (`relay`, the Relay route out, is not built yet); `return_to_robinhood` goes through Relay either way |
452
573
  | `PRIORS_BASE_RPC` | `https://mainnet.base.org` | Base JSON-RPC endpoint, read only (a private URL is redacted from every answer) |
@@ -454,10 +575,12 @@ may spend. Rows marked (0.8.0) take effect from that version; 0.7.x ignores them
454
575
  | `PRIORS_MAX_BRIDGE_USD` | `10` | most one `fund_base` or `return_to_robinhood` may move |
455
576
  | `PRIORS_MAX_BRIDGE_TOTAL_USD` | `25` | most both may move in total while the server runs, either way (a transfer that may be out counts, and one in flight when the server starts counts too) |
456
577
  | `PRIORS_MAX_BRIDGE_FEE_BPS` | `100` | a bridge fee above this, in basis points of the amount, is refused |
457
- | `PRIORS_MAX_BASE_FLOAT_USD` | `10` | `fund_base` never brings the Base float above this |
578
+ | `PRIORS_MAX_BASE_FLOAT_USD` | `10` | `fund_base` and `pay_url`'s top-up never bring the Base float above this |
579
+ | `PRIORS_AUTO_BASE_USD` | `off` | (unreleased) what `pay_url` moves to the Base float on its own, through Across, when the float is short of a Base seller's price; then it pays in the same call. At least 0.50, within `PRIORS_MAX_BRIDGE_USD`, `PRIORS_MAX_BASE_FLOAT_USD` and `PRIORS_MAX_BRIDGE_TOTAL_USD`; needs Base on with `PRIORS_BRIDGE=across` |
458
580
  | `PRIORS_GATEWAY` | `off` | (since 0.10.0) `on` offers `pay_gateway` (Vantis' Keyring gateway, above); any value other than on or off stops the start |
459
581
  | `PRIORS_GATEWAY_PAYTO` | not pinned | (since 0.10.0) the only address Keyring's 402 may ask to be paid: Keyring's own, as a first live call reads it |
460
582
  | `PRIORS_GATEWAY_MAX_FEE_BPS` | `1000` | (since 0.10.0) most Keyring's quote may be over the seller's own listed price, in basis points (10%) |
583
+ | `PRIORS_PAYEE_CHECK` | off | (next release) `on`: after `pay_url`'s and `pay_gateway`'s payment, one line of what Priors' check API says of the address paid ("Whose agent it just paid", above), read after the payment within 3 s; it sends that address to priors.trade. Any value but `on` leaves it off, and no request leaves for the check |
461
584
  | `PRIORS_JOIN` | `off` | (since 0.11.0) `on` offers `join`, which registers the wallet's identity with the URI `priors:agent:mcp:<its address>`; a registration it sends is kept in `PRIORS_STATE_DIR` (`join-<wallet>.json`), with the id once mined, so none is sent twice (with `off`, in memory only); any value other than on or off stops the start. (0.12.0) It also offers `first_line`, whose transactions and invite are kept there too (`first-line-<wallet>.json`) |
462
585
  | `PRIORS_BOT_URL` | `https://priors.trade` | (since 0.12.0) read only with `PRIORS_JOIN=on`: the invite bot's site, where `first_line` posts `/prove` (its check, its proof, the signed proof); https, or http for localhost only (a test bot); any other value stops the start |
463
586
  | `PRIORS_MAX_BOND_TOTAL_USD` | `5` | (since 0.13.0) read only with `PRIORS_JOIN=on`: most `first_line` may post in bonds while the server runs (InviteBond's bond is 5 USDG, so one by default; `0` posts none), counted from the deposit's broadcast; a deposit refused before it, or that the chain shows moved nothing, counts nothing; a value it cannot read stops the start |
@@ -476,7 +599,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
476
599
  "mcpServers": {
477
600
  "priors": {
478
601
  "command": "npx",
479
- "args": ["-y", "@priors/mcp@0.20.1"],
602
+ "args": ["-y", "@priors/mcp@0.21.0"],
480
603
  "env": {
481
604
  "PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
482
605
  "PRIORS_AGENT_ID": "1234"
@@ -498,7 +621,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
498
621
  "mcpServers": {
499
622
  "priors": {
500
623
  "command": "npx",
501
- "args": ["-y", "@priors/mcp@0.20.1"],
624
+ "args": ["-y", "@priors/mcp@0.21.0"],
502
625
  "env": {
503
626
  "PRIORS_KEY": "${PRIORS_KEY}",
504
627
  "PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
@@ -511,7 +634,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
511
634
  or, for your user only, from a macOS or Linux terminal:
512
635
 
513
636
  ```sh
514
- (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.20.1' priors-mcp ~/.config/priors/agent.key
637
+ (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.21.0' priors-mcp ~/.config/priors/agent.key
515
638
  ```
516
639
 
517
640
  It waits for the key without showing it (paste it, then Enter), saves it in a file only you can read, and gives Claude
@@ -547,8 +670,10 @@ container, mount the file and give its absolute path. `PRIORS_KEY` still works;
547
670
  the runtime restarts the server. These do not: they count per UTC day for the agent named by `PRIORS_AGENT_ID` (which
548
671
  they require: without it the server does not start) and for the wallet whose key signs, across restarts and across
549
672
  every process that shares `PRIORS_STATE_DIR`, kept as one file per money call under `<state dir>/daily-agent-<id>/` and
550
- `<state dir>/daily-wallet-<address>/`. Every key and every client acting for the agent shares one count, and a key run
551
- under another agent id still shares its wallet's. A call counts at the most it may sign or borrow (`max_price_usd`,
673
+ `<state dir>/daily-wallet-<address>/`. Every `@priors/mcp` server acting for the agent that shares `PRIORS_STATE_DIR`
674
+ shares one count, and a key run under another agent id still shares its wallet's. Only those servers' own calls write
675
+ those files: borrows and payments made through another client of the agent's key (another Priors client, or a server
676
+ with its own state directory) are not counted. A call counts at the most it may sign or borrow (`max_price_usd`,
552
677
  `max_borrow_usd`) while it runs, then at what it did, in the UTC day it ended (a borrow sent just before 00:00 UTC that
553
678
  lands after counts in the new day). A call still in flight at 00:00 UTC counts in the new day too, however long its
554
679
  transaction takes, so a call another process makes after midnight already sees it; one cut short by a crash stays
@@ -592,7 +717,7 @@ to approve a borrow; this package, with the key, pays for APIs. With borrowing o
592
717
  approves each loan in Priors' Go mode. ElizaOS (`@elizaos/plugin-mcp`):
593
718
 
594
719
  ```ts
595
- "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.20.1"],
720
+ "priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.21.0"],
596
721
  env: { PRIORS_KEY_FILE: "/home/agent/.config/priors/agent-7311.key", PRIORS_AGENT_ID: "7311",
597
722
  PRIORS_MAX_BORROW_USD: "0", PRIORS_MAX_BORROW_DAY_USD: "0", PRIORS_MAX_SPEND_DAY_USD: "1", PRIORS_MAX_PRICE_USD: "0.10",
598
723
  PRIORS_PAY_HOSTS: "api.example.com" } }
@@ -604,7 +729,7 @@ OpenClaw (`mcp.servers`, JSON5) takes the same `command`, `args` and `env`; Herm
604
729
  mcp_servers:
605
730
  priors-wallet:
606
731
  command: npx
607
- args: ["-y", "@priors/mcp@0.20.1"]
732
+ args: ["-y", "@priors/mcp@0.21.0"]
608
733
  env:
609
734
  PRIORS_KEY_FILE: /home/agent/.config/priors/agent-7311.key
610
735
  PRIORS_AGENT_ID: "7311"
@@ -631,7 +756,7 @@ key proves it is there: it signs the ERC-8004 identity registry's `AgentWalletSe
631
756
  agent's).
632
757
 
633
758
  ```sh
634
- PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.20.1 link-wallet --agent 7311
759
+ PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.21.0 link-wallet --agent 7311
635
760
  ```
636
761
 
637
762
  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.20.1",
4
+ "version": "0.21.0",
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",
@@ -0,0 +1,63 @@
1
+ /* Who is asking, beside a paid request (growth loop batch 16's BP, docs/builds/2026-11-16-growth-loop-batch16.md criteria
2
+ 5 and 12; docs/growth/agent-work-history.md, "The client's requests and its wallet"; SITE_CLIENT_FACTS on the board,
3
+ CLIENT_FACTS on the hosted MCP): one paragraph for a request's client, from the request's own answer on the data Worker
4
+ (its clientFacts, data-worker/client-facts.mjs), its budget and its state. The board's Jobs tab says it in a request's
5
+ Details (clientFactsLine) and the hosted job_request says it outside the client's fence (mcp-worker/client-facts.mjs),
6
+ both from this file, so the two read the same sentence:
7
+ "This client's requests on Priors' work board in the last 30 days: N posted, P paid, R rejected after delivery, C
8
+ cancelled after an award, U closed unpaid. Its wallet holds X USDG now (read <time>); the budget is B USDG."
9
+ - "First request from this address on Priors' work board in the last 30 days." in place of the first sentence for a
10
+ live request (open, awarded or delivered: always posted within those 30 days) that is its client's only one in them;
11
+ - "Its wallet's USDG could not be read just now; the budget is B USDG." in place of the second when the data Worker's
12
+ read failed (usdg and usdgAt null): never a figure then.
13
+ The same words for every address: counts and one balance as read, with its read time (UTC, to the minute), and nothing
14
+ else; no word on the client, no order, nothing refused or hidden. Facts out of the data Worker's shape give no
15
+ paragraph at all. English: the board has no dictionary. */
16
+ (function (root, factory) {
17
+ const api = factory();
18
+ if (typeof module === "object" && module && module.exports) module.exports = api;
19
+ if (root) root.PriorsClientFacts = api;
20
+ })(typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : null, function () {
21
+ "use strict";
22
+ const KEYS = Object.freeze(["posted30", "paid30", "rejected30", "cancelledAfterAward30", "closedUnpaid30", "usdg", "usdgAt"]);
23
+ const COUNTS = KEYS.slice(0, 5);
24
+ // a USDG amount as the data Worker writes one (sdk/work-types.mjs usdgText): at least two decimals, at most six
25
+ const AMOUNT = /^(?:0|[1-9][0-9]{0,15})\.[0-9]{2,6}$/;
26
+ const LIVE = ["open", "awarded", "delivered"];
27
+ const FIRST = "First request from this address on Priors' work board in the last 30 days.";
28
+ const UNREAD = "could not be read just now";
29
+ const whole = (n) => typeof n === "number" && Number.isSafeInteger(n) && n >= 0;
30
+
31
+ /** clientFacts as the data Worker gives them, checked: { posted30, paid30, rejected30, cancelledAfterAward30,
32
+ * closedUnpaid30, usdg (a written amount, or null), usdgAt (unix seconds, or null) }, or null for anything else (a
33
+ * count that is not a whole number, more outcomes than requests posted, a balance without its time or the reverse). */
34
+ function factsOf(x) {
35
+ if (!x || typeof x !== "object" || Array.isArray(x) || !COUNTS.every((k) => whole(x[k]))) return null;
36
+ if (x.paid30 + x.rejected30 + x.cancelledAfterAward30 + x.closedUnpaid30 > x.posted30) return null;
37
+ const read = typeof x.usdg === "string" && AMOUNT.test(x.usdg) && whole(x.usdgAt) && x.usdgAt > 0;
38
+ if (!read && !(x.usdg === null && x.usdgAt === null)) return null;
39
+ const out = {};
40
+ for (const k of KEYS) out[k] = x[k];
41
+ return out;
42
+ }
43
+ /** A unix time as the paragraph writes it: "2026-11-16 14:24 UTC". */
44
+ function when(t) {
45
+ const d = new Date(t * 1000), p = (n) => String(n).padStart(2, "0");
46
+ return d.getUTCFullYear() + "-" + p(d.getUTCMonth() + 1) + "-" + p(d.getUTCDate()) + " " + p(d.getUTCHours()) + ":" + p(d.getUTCMinutes()) + " UTC";
47
+ }
48
+ /** The first sentence: the client's counts. */
49
+ const counts = (f) => "This client's requests on Priors' work board in the last 30 days: " + f.posted30 + " posted, " + f.paid30 + " paid, " + f.rejected30 +
50
+ " rejected after delivery, " + f.cancelledAfterAward30 + " cancelled after an award, " + f.closedUnpaid30 + " closed unpaid.";
51
+ /** The second: its wallet's USDG as read, and the budget. */
52
+ const wallet = (f, budget) => (f.usdg == null ? "Its wallet's USDG " + UNREAD + "; the budget is " + budget + " USDG." : "Its wallet holds " + f.usdg + " USDG now (read " + when(f.usdgAt) + "); the budget is " + budget + " USDG.");
53
+
54
+ /** The paragraph for request `v` (the request's own answer, or { clientFacts, budget, state }): "" when it carries
55
+ * no facts in the data Worker's shape, or no budget written as USDG is. */
56
+ function paragraph(v) {
57
+ const f = factsOf(v && v.clientFacts), budget = v && typeof v.budget === "string" && AMOUNT.test(v.budget) ? v.budget : null;
58
+ if (!f || !budget) return "";
59
+ return (LIVE.includes(v.state) && f.posted30 <= 1 ? FIRST : counts(f)) + " " + wallet(f, budget);
60
+ }
61
+
62
+ return Object.freeze({ KEYS, FIRST, UNREAD, factsOf, when, counts, wallet, paragraph });
63
+ });