@priors/mcp 0.19.0 → 0.20.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 +58 -0
- package/README.md +66 -12
- package/package.json +2 -2
- package/src/board-trade-core.cjs +234 -0
- package/src/line-options.mjs +21 -6
- package/src/offer-becomes.mjs +71 -0
- package/src/server.mjs +519 -12
- package/src/strategies.mjs +162 -0
- package/src/strategy-tools.mjs +107 -0
- package/src/trade-core.cjs +691 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
# @priors/mcp changelog
|
|
2
2
|
|
|
3
|
+
## 0.20.0 (2026-11-11)
|
|
4
|
+
|
|
5
|
+
- **The backing side of the line board, signed and sent here** (only with `PRIORS_LINE_BOARD=on`, off by default; off,
|
|
6
|
+
the tool list and the instructions are 0.19.0's, word for word, and `PRIORS_MAX_BACK_DAY_USD` is not read). For a
|
|
7
|
+
root (a backer of the pool) whose owner's key runs this server, three tools beside `line_ask` and `line_take`, each
|
|
8
|
+
with `dry_run`:
|
|
9
|
+
- `line_offer(request_id, root_id, amount_usd, premium_bps?, days?)` checks the offer as the hosted `line_offer` does
|
|
10
|
+
(the request and the board's rules, the root's owner, that it is a root, its free backing) and against the root's
|
|
11
|
+
offers standing on the board, and refuses with the reason, nothing signed. Its answer says what the offer can become
|
|
12
|
+
under the pool's rules (the agent's loans open and their due dates against the offer's end, a line it would make
|
|
13
|
+
smaller, the root's free backing: `src/offer-becomes.mjs`, the same words as the site's) and what Score v2 would say
|
|
14
|
+
of a line from that root, before the signature; then it signs the board's LineOffer and posts it.
|
|
15
|
+
- `line_send(request_id)` sends the line of an offer of this wallet's root that the agent's owner took: the pool's
|
|
16
|
+
`vouchWithConsent`, rebuilt from the board's acceptance (the request, the offer, the agent owner's consent and its
|
|
17
|
+
signature) and refused if the call the board prints differs from it by one byte, or is not from this wallet, for
|
|
18
|
+
that agent, to the pool on chain 4663. The consent's end is checked against this clock, then the day's cap, then the
|
|
19
|
+
call is simulated from this wallet: a refusal gives the pool's own reason (`LoanOpen` with the loan and its due date,
|
|
20
|
+
`ConsentExpired`, `InsufficientBacking`, `BadConsent`...) and sends nothing. One transaction, its gas in this
|
|
21
|
+
wallet's ETH; the answer reads the receipt's `Vouched` and `SponsorChanged`.
|
|
22
|
+
- `line_back_own(root_id, agent_id, amount_usd, premium_bps?)` backs an agent this wallet owns from a root it owns,
|
|
23
|
+
as Builder mode does for one owner: its answer opens with the sentence that Score v2 counts nothing on a line its own
|
|
24
|
+
owner backs (the line opens credit for the agent and builds it no record). A root or an agent this wallet does not
|
|
25
|
+
own is refused before anything is signed; otherwise the agent's consent is signed here, simulated and sent.
|
|
26
|
+
- `line_send` and `line_back_own` say Go mode's words for a backer first: every line backed is the stake's USDG, and
|
|
27
|
+
a loan not repaid is paid from the stake, its default staying on the agent's record. They run one at a time with the
|
|
28
|
+
other money tools.
|
|
29
|
+
- **`PRIORS_MAX_BACK_DAY_USD`**, read only with `PRIORS_LINE_BOARD=on`: the most line `line_send` and `line_back_own`
|
|
30
|
+
may send from this wallet per UTC day (none by default; `0` sends none), counted from the broadcast and kept in
|
|
31
|
+
`PRIORS_STATE_DIR` across restarts and every process of the wallet (with `PRIORS_STATE_DIR` off, for the process
|
|
32
|
+
only). A value that is not a dollar amount stops the start, and is never echoed.
|
|
33
|
+
- **The taken offers of this wallet's roots, named when a session starts** (with `PRIORS_LINE_BOARD=on` and a key):
|
|
34
|
+
`initialize`'s instructions end with each one waiting to be sent, the soonest consent's end first: the agent, the
|
|
35
|
+
root, the amount, the request and the consent's end in UTC, and that `line_send` sends the line. The roots are
|
|
36
|
+
`PRIORS_AGENT_ID` and the agents the board's `/api/agents?owner=` lists for this wallet, each kept only when the chain
|
|
37
|
+
says it is a root this wallet owns; a taken offer waits while its consent's deadline is ahead and its nonce is still
|
|
38
|
+
the agent's. One bounded read beside the open loans' (5 s): nothing is said when none waits or any read fails.
|
|
39
|
+
- **Published trading strategies, read-only, off by default.** With `PRIORS_STRATEGIES=on`, `strategies_list` and
|
|
40
|
+
`strategy_read` read the strategy board's GET routes (`PRIORS_STRATEGIES_URL`, the test site's
|
|
41
|
+
`https://test.priors.trade/api/strategies` by default): each strategy accounts published from Go mode's Trade tab,
|
|
42
|
+
its nodes path by path with their levels and amounts, the agent it is for, and its record read on chain (its
|
|
43
|
+
account's key's trades, the agent's loans paid to that account, repaid on time or late as Score v2 counts it), in the
|
|
44
|
+
board's own words. A Borrow node opens a loan of the agent that must be repaid; a list ends "Not an endorsement.".
|
|
45
|
+
Nothing is signed or sent. Off, `tools/list` and the instructions are 0.19.1's byte for byte, and nothing of it is
|
|
46
|
+
loaded. Ships the site's Trade core and the board's (`src/trade-core.cjs`, `src/board-trade-core.cjs`, byte for byte)
|
|
47
|
+
and `src/strategies.mjs`.
|
|
48
|
+
|
|
49
|
+
## 0.19.1 (2026-11-10)
|
|
50
|
+
|
|
51
|
+
- **`line_key_spend` pays only for an agent this wallet owns or is the declared ERC-8004 wallet of, and that wallet
|
|
52
|
+
repays under LineKey** (GHSA-45h8-v5q8-4j43, reported by @pa-khan). An agent's owner names its spending key's operator
|
|
53
|
+
with no word from it, as it names a pool delegate (GHSA-9pw7), and `line_key_spend` (0.18.0, with
|
|
54
|
+
`PRIORS_LINE_KEY=on`) took being the operator as enough: a stranger who named this wallet, and a model told to pass
|
|
55
|
+
that `agent_id`, had it pay from the stranger's line with its own gas and borrowing limits. It now refuses a wallet
|
|
56
|
+
that is neither the agent's owner nor its declared wallet before the key is read, and `line_key_status` says so. Once
|
|
57
|
+
LineKey is the agent's pool delegate, the agent's own key controls nothing at the pool, and `repay` and `autopay_on`
|
|
58
|
+
refused it, though `line_key_spend`'s answer sends it there: the declared wallet now repays and turns Autopay on
|
|
59
|
+
whether or not the pool names it the delegate; any other wallet is refused as before. With `@priors/x402` 0.8.9.
|
|
60
|
+
|
|
3
61
|
## 0.19.0 (2026-11-09)
|
|
4
62
|
|
|
5
63
|
- **The agent's open loans, named when a session starts.** `initialize`'s instructions end with each open loan of the
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ repaying.
|
|
|
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
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 |
|
|
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`. 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 |
|
|
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 |
|
|
40
40
|
| `unsave(amount_usd? \| all)` | take USDG back out of savings into the wallet: a normal withdrawal, and when that is not enough, the rest from the vault's other markets in the same transaction (only where that costs no penalty); refused before any transaction when even that cannot pay it; needs ETH for gas | yes |
|
|
@@ -54,7 +54,7 @@ repaying.
|
|
|
54
54
|
| `join()` | (since 0.11.0) only with `PRIORS_JOIN=on`: register an ERC-8004 identity on Robinhood Chain for the wallet when it owns none (one transaction, its gas in the wallet's ETH; too little is refused before anything is signed) and answer its id and its routes to a first line; a wallet that owns one gets its id and nothing is sent; a registration whose answer is lost is never sent twice | yes |
|
|
55
55
|
| `first_line(agent_id?)` | (since 0.12.0) only with `PRIORS_JOIN=on`: take the treasury's first line by invite for the identity the wallet owns, when it has no Priors record (after `join`), with no clone or Telegram: post the invite's 5 USDG bond from the wallet (USDG's approve, then InviteBond's deposit; it comes back by InviteBond's release, and a default forfeits it), get the invite from Priors' invite bot with one signature that proves ownership (only the bot's own start-page text, rebuilt here byte for byte, is signed), then sign the pool consent and redeem it (treasury v4's `firstLine`). Refused before anything is signed when the wallet does not own the identity, the identity already has a record (its state is the answer), the wallet lacks the ETH or the USDG, the bond would pass `PRIORS_MAX_BOND_TOTAL_USD` or `PRIORS_MAX_SPEND_DAY_USD`, or the bot says no invite is open now (its reason, with `line_options`' routes). A transaction whose answer is lost answers `TX_UNCONFIRMED`, and a second call never posts a second bond; needs ETH for gas | yes |
|
|
56
56
|
| `line_key_status(agent_id?)` | only with `PRIORS_LINE_KEY=on` (below): the agent's spending key on LineKey: whether one is set and live (or stale: the agent changed hands; expired; not the line's delegate: each pays nothing), its operator and whether that is this wallet, its caps per payment and per trailing period, its expiry, each payment's loan term and most fee, the payees with their own caps and what each can be paid now, what was paid in the period and when room frees up, and the pool's smallest loan (5 USDG) | no (with `agent_id`) |
|
|
57
|
-
| `line_key_spend(payee, amount_usdg, ref?, agent_id?, dry_run?)` | only with `PRIORS_LINE_KEY=on`: pay a payee the agent's owner listed on the key, from the agent's line, as a loan of the agent: the pool pays the payee directly, never through this wallet, which must be the key's operator. A `ref` (a job or an invoice: up to 31 bytes of text, or 32 in hex) is paid once per payee. Refused before anything is signed when the key's `check` refuses (each reason in words), the amount is under the pool's smallest loan or over its largest, the line refuses it in a simulation (no room, its backer's rule, a fee above the key's most), the wallet lacks the ETH for the gas, or a borrowing limit would pass. One transaction to LineKey, gas limit 900,000; the answer names the loan (from LineKey's `Paid` log), its fee and due date, to repay with `repay`; `dry_run` lists the call; needs ETH for gas | yes |
|
|
57
|
+
| `line_key_spend(payee, amount_usdg, ref?, agent_id?, dry_run?)` | only with `PRIORS_LINE_KEY=on`: pay a payee the agent's owner listed on the key, from the agent's line, as a loan of the agent: the pool pays the payee directly, never through this wallet, which must be the key's operator and (0.19.1) the agent's owner or its declared ERC-8004 wallet (the owner names an operator with no word from it). A `ref` (a job or an invoice: up to 31 bytes of text, or 32 in hex) is paid once per payee. Refused before anything is signed when the key's `check` refuses (each reason in words), the amount is under the pool's smallest loan or over its largest, the line refuses it in a simulation (no room, its backer's rule, a fee above the key's most), the wallet lacks the ETH for the gas, or a borrowing limit would pass. One transaction to LineKey, gas limit 900,000; the answer names the loan (from LineKey's `Paid` log), its fee and due date, to repay with `repay`; `dry_run` lists the call; needs ETH for gas | yes |
|
|
58
58
|
|
|
59
59
|
Tools that move money state the amounts in their answer, are marked destructive for MCP clients, and their
|
|
60
60
|
descriptions tell the assistant to confirm with you first. They run one at a time and each answers within 45 s, under an
|
|
@@ -128,10 +128,13 @@ spending key for an agent's Priors line. The agent's owner names it the line's d
|
|
|
128
128
|
an operator (a hot key, such as this server's wallet), caps per payment and per trailing period, the payees it may pay
|
|
129
129
|
(each with an optional cap of its own), an expiry, the loan term and the most fee. The owner sets it up in Go mode's
|
|
130
130
|
agent panel, Spending key (on the test site for now). With `PRIORS_LINE_KEY=on`, `line_key_status` reads the key, and
|
|
131
|
-
`line_key_spend` pays a listed payee from this wallet when it is the key's operator
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
`line_key_spend` pays a listed payee from this wallet when it is the key's operator and (0.19.1) the agent's owner or
|
|
132
|
+
its declared ERC-8004 wallet (`priors-mcp link-wallet` declares it; the owner names an operator with no word from it):
|
|
133
|
+
the pool lends the amount and pays it straight to the payee, so every payment is an ordinary loan of the agent, repaid
|
|
134
|
+
like any other before its due date, by `repay` from the agent's owner or its declared wallet (the pool no longer names
|
|
135
|
+
that wallet the agent's delegate: the key is). The operator holds nothing for it and pays only its own gas, in ETH.
|
|
136
|
+
The key's caps bound what a stolen operator key could pay, and only to the listed payees; this server's borrowing
|
|
137
|
+
limits count each payment too.
|
|
135
138
|
|
|
136
139
|
## Asking for a line on the line board (off by default, since 0.19.0)
|
|
137
140
|
|
|
@@ -152,6 +155,54 @@ promises no line: a backer may offer, or not, and once a take is posted the root
|
|
|
152
155
|
wallet, or not. Without the switch nothing changes: no tool, no sentence in the instructions, and
|
|
153
156
|
`PRIORS_LINE_BOARD_URL` is not read.
|
|
154
157
|
|
|
158
|
+
## Backing a line from the line board (off by default, from 0.20.0)
|
|
159
|
+
|
|
160
|
+
A root is a backer of the pool: an ERC-8004 identity with USDG staked behind it, whose free backing becomes the lines it
|
|
161
|
+
gives agents. With `PRIORS_LINE_BOARD=on`, when this server's wallet owns a root in the ERC-8004 registry, it can offer
|
|
162
|
+
lines on the line board and send them from that wallet:
|
|
163
|
+
|
|
164
|
+
| Tool | What it does |
|
|
165
|
+
|---|---|
|
|
166
|
+
| `line_offer(request_id, root_id, amount_usd, premium_bps?, days?, dry_run?)` | checks an offer from the root on an open request as the hosted `line_offer` does, and against the root's offers standing on the board; says what the offer can become under the pool's rules and what Score v2 would say of a line from that root, then signs the LineOffer and posts it |
|
|
167
|
+
| `line_send(request_id, dry_run?)` | sends the line of an offer of the root that the agent's owner took: the pool's `vouchWithConsent` exactly as the board's acceptance prints it, checked byte for byte, simulated, then sent from this wallet |
|
|
168
|
+
| `line_back_own(root_id, agent_id, amount_usd, premium_bps?, dry_run?)` | backs an agent this wallet owns from a root it owns, the agent's consent signed here |
|
|
169
|
+
|
|
170
|
+
With `dry_run`, each checks and says what it would do, and nothing is posted or sent. A refusal says why and sends
|
|
171
|
+
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
|
+
too little free backing), or a call that differs from the board's acceptance.
|
|
173
|
+
|
|
174
|
+
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
|
+
for the agent and builds it no record.
|
|
176
|
+
|
|
177
|
+
A line moves the root's free backing into the agent's line. If the agent doesn't repay, its loan is paid from the root's
|
|
178
|
+
stake, and the default stays on the agent's record. `line_send` and `line_back_own` say so before they send, and send at
|
|
179
|
+
most `PRIORS_MAX_BACK_DAY_USD` of line a UTC day from this wallet (none by default; `0` sends none), counted across restarts
|
|
180
|
+
in `PRIORS_STATE_DIR`.
|
|
181
|
+
|
|
182
|
+
When a session starts, the instructions name each taken offer of this wallet's roots waiting to be sent: the agent, the
|
|
183
|
+
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
|
|
185
|
+
changes: no tool, no sentence in the instructions, and `PRIORS_MAX_BACK_DAY_USD` is not read.
|
|
186
|
+
|
|
187
|
+
## Published trading strategies (off by default)
|
|
188
|
+
|
|
189
|
+
Priors' strategy board lists the trading strategies accounts published for their agents from Go mode's Trade tab
|
|
190
|
+
(the board's Trade tab): triggers, If branches and actions, each with its levels and amounts. With
|
|
191
|
+
`PRIORS_STRATEGIES=on`, this server reads it (`PRIORS_STRATEGIES_URL`, the test site's
|
|
192
|
+
`https://test.priors.trade/api/strategies` by default):
|
|
193
|
+
|
|
194
|
+
| Tool | What it reads |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `strategies_list(agent_id?, publisher?, limit?)` | the published strategies, newest first (10 by default, at most 20), or only one agent's or one publisher's: each one's name, the agent it is for, its nodes path by path with their levels and amounts, its limits, and its record read on chain (the trades its account's key made, the agent's loans paid to that account, repaid on time or late as Score v2 counts it) |
|
|
197
|
+
| `strategy_read(id)` | one of them, with each trade and loan of its record |
|
|
198
|
+
|
|
199
|
+
Both read only: nothing is signed or sent, and this server's key is not used. A Borrow node opens a loan of the agent
|
|
200
|
+
that must be repaid. A strategy's name is its publisher's words, and a strategy listed is not an endorsement. The test
|
|
201
|
+
site's board asks for the Priors team's password: elsewhere, set `PRIORS_STRATEGIES_URL` to a board this server can
|
|
202
|
+
read. Priors' hosted test server also checks a strategy before it is built (`strategy_draft`: Go mode's own checks, what
|
|
203
|
+
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
|
+
the instructions, nothing of it loaded, and `PRIORS_STRATEGIES_URL` is not read.
|
|
205
|
+
|
|
155
206
|
## Trading agents (off by default)
|
|
156
207
|
|
|
157
208
|
With `PRIORS_MARKET=on`, the agent's own key trades agents on Priors' agent market: it reads an agent, lists one it
|
|
@@ -393,6 +444,9 @@ may spend. Rows marked (0.8.0) take effect from that version; 0.7.x ignores them
|
|
|
393
444
|
| `PRIORS_LINE_KEY` | off | `on`: `line_key_status` and `line_key_spend` (the agent's spending key, above); any value other than on or off stops the start |
|
|
394
445
|
| `PRIORS_LINE_BOARD` | off | (since 0.19.0) `on`: `line_ask` and `line_take` (the line board, above); any value other than on or off stops the start |
|
|
395
446
|
| `PRIORS_LINE_BOARD_URL` | `https://priors.trade/api/line-requests` | (since 0.19.0) read only with `PRIORS_LINE_BOARD=on`: the line board; https, or http for localhost only, with no credentials, query or fragment; any other value stops the start |
|
|
447
|
+
| `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
|
+
| `PRIORS_STRATEGIES` | off | `on`: `strategies_list` and `strategy_read` (published trading strategies, above); any value other than on or off stops the start |
|
|
449
|
+
| `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 |
|
|
396
450
|
| `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 |
|
|
397
451
|
| `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 |
|
|
398
452
|
| `PRIORS_BASE_RPC` | `https://mainnet.base.org` | Base JSON-RPC endpoint, read only (a private URL is redacted from every answer) |
|
|
@@ -422,7 +476,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
|
|
|
422
476
|
"mcpServers": {
|
|
423
477
|
"priors": {
|
|
424
478
|
"command": "npx",
|
|
425
|
-
"args": ["-y", "@priors/mcp@0.
|
|
479
|
+
"args": ["-y", "@priors/mcp@0.20.0"],
|
|
426
480
|
"env": {
|
|
427
481
|
"PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
|
|
428
482
|
"PRIORS_AGENT_ID": "1234"
|
|
@@ -444,7 +498,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
444
498
|
"mcpServers": {
|
|
445
499
|
"priors": {
|
|
446
500
|
"command": "npx",
|
|
447
|
-
"args": ["-y", "@priors/mcp@0.
|
|
501
|
+
"args": ["-y", "@priors/mcp@0.20.0"],
|
|
448
502
|
"env": {
|
|
449
503
|
"PRIORS_KEY": "${PRIORS_KEY}",
|
|
450
504
|
"PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
|
|
@@ -457,7 +511,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
457
511
|
or, for your user only, from a macOS or Linux terminal:
|
|
458
512
|
|
|
459
513
|
```sh
|
|
460
|
-
(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.
|
|
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.0' priors-mcp ~/.config/priors/agent.key
|
|
461
515
|
```
|
|
462
516
|
|
|
463
517
|
It waits for the key without showing it (paste it, then Enter), saves it in a file only you can read, and gives Claude
|
|
@@ -538,7 +592,7 @@ to approve a borrow; this package, with the key, pays for APIs. With borrowing o
|
|
|
538
592
|
approves each loan in Priors' Go mode. ElizaOS (`@elizaos/plugin-mcp`):
|
|
539
593
|
|
|
540
594
|
```ts
|
|
541
|
-
"priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.
|
|
595
|
+
"priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.20.0"],
|
|
542
596
|
env: { PRIORS_KEY_FILE: "/home/agent/.config/priors/agent-7311.key", PRIORS_AGENT_ID: "7311",
|
|
543
597
|
PRIORS_MAX_BORROW_USD: "0", PRIORS_MAX_BORROW_DAY_USD: "0", PRIORS_MAX_SPEND_DAY_USD: "1", PRIORS_MAX_PRICE_USD: "0.10",
|
|
544
598
|
PRIORS_PAY_HOSTS: "api.example.com" } }
|
|
@@ -550,7 +604,7 @@ OpenClaw (`mcp.servers`, JSON5) takes the same `command`, `args` and `env`; Herm
|
|
|
550
604
|
mcp_servers:
|
|
551
605
|
priors-wallet:
|
|
552
606
|
command: npx
|
|
553
|
-
args: ["-y", "@priors/mcp@0.
|
|
607
|
+
args: ["-y", "@priors/mcp@0.20.0"]
|
|
554
608
|
env:
|
|
555
609
|
PRIORS_KEY_FILE: /home/agent/.config/priors/agent-7311.key
|
|
556
610
|
PRIORS_AGENT_ID: "7311"
|
|
@@ -577,7 +631,7 @@ key proves it is there: it signs the ERC-8004 identity registry's `AgentWalletSe
|
|
|
577
631
|
agent's).
|
|
578
632
|
|
|
579
633
|
```sh
|
|
580
|
-
PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.
|
|
634
|
+
PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.20.0 link-wallet --agent 7311
|
|
581
635
|
```
|
|
582
636
|
|
|
583
637
|
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.
|
|
4
|
+
"version": "0.20.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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
48
|
-
"@priors/x402": "0.8.
|
|
48
|
+
"@priors/x402": "0.8.9",
|
|
49
49
|
"ethers": "^6.13.4",
|
|
50
50
|
"undici": "6.29.1",
|
|
51
51
|
"viem": "^2.56.9",
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/* Trade on the board (SITE_BOARD_TRADE, with SITE_BOARD and SITE_TRADE; docs/builds/2026-11-10-trade-strategies.md, Task 4):
|
|
2
|
+
the published strategies' one source of truth for three places. Pure (no DOM, no fetch, no clock of its own), UMD as
|
|
3
|
+
board-core.js: window.PriorsStrategyBoardCore; node and the data Worker require it as it is.
|
|
4
|
+
- the data Worker's store (data-worker/strategy-board.mjs): the typed data it checks, the content's one written form;
|
|
5
|
+
- Go mode's Publish and Unpublish (web/account-trade.js's [board-trade] lines): the typed data the account signs;
|
|
6
|
+
- the board's Trade tab (web/board-trade.js): each strategy's card, its record's words, Copy into Go mode's link.
|
|
7
|
+
|
|
8
|
+
Publishing is one EIP-712 message, domain "Priors Strategy Board" 1 on chain 4663 (a board message can never be read as
|
|
9
|
+
any other Priors message), signed by the publisher: a Go mode account (a smart account: ERC-1271, ERC-6492's wrapper
|
|
10
|
+
while it is not on chain yet) or, in Builder mode, a plain wallet. The publisher must be the registry owner of the
|
|
11
|
+
agent the message names, and every agent the strategy names is that one.
|
|
12
|
+
StrategyPublish { publisher address, agentId uint256, name string, strategy string, at uint256 }
|
|
13
|
+
`strategy`: contentOf({ strategy, layout }), the strategy rules (trade-core.js compile, priors.strategy
|
|
14
|
+
v1) and the cards' places, as one canonical JSON text (keys sorted, no space): the wallet shows
|
|
15
|
+
exactly what is published. `at`: when it was signed (unix seconds). Its id: the message's EIP-712
|
|
16
|
+
hash, in lower case.
|
|
17
|
+
StrategyUnpublish { publisher address, id bytes32, at uint256 } the same publisher, for one id
|
|
18
|
+
|
|
19
|
+
DOMAIN, TYPES, RULES, contentOf(x), parseContent(text), layoutOf(graph), agentsOf(strategy), publishMessage(o),
|
|
20
|
+
unpublishMessage(o), typedData(primaryType, message, { bigint }), copyHref(app, id)
|
|
21
|
+
cardOf(row, x) a strategy as the board's card shows it (x: { T: trade-core.js, C: board-core.js, board, assets })
|
|
22
|
+
recordLines(record) its record read on chain, in words: [{ key, text }]
|
|
23
|
+
Every word is English (the board has no dictionary): no promise of gains, no one named as running an agent, a borrow
|
|
24
|
+
says it opens a loan of the agent that must be repaid, and the list ends "Not an endorsement." */
|
|
25
|
+
(function (root, factory) {
|
|
26
|
+
const api = factory();
|
|
27
|
+
if (typeof module === "object" && module && module.exports) module.exports = api;
|
|
28
|
+
if (root) root.PriorsStrategyBoardCore = api;
|
|
29
|
+
})(typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : null, function () {
|
|
30
|
+
"use strict";
|
|
31
|
+
|
|
32
|
+
const CHAIN_ID = 4663;
|
|
33
|
+
const DOMAIN = Object.freeze({ name: "Priors Strategy Board", version: "1", chainId: CHAIN_ID });
|
|
34
|
+
const TYPES = Object.freeze({
|
|
35
|
+
StrategyPublish: Object.freeze([
|
|
36
|
+
{ name: "publisher", type: "address" },
|
|
37
|
+
{ name: "agentId", type: "uint256" },
|
|
38
|
+
{ name: "name", type: "string" },
|
|
39
|
+
{ name: "strategy", type: "string" },
|
|
40
|
+
{ name: "at", type: "uint256" },
|
|
41
|
+
]),
|
|
42
|
+
StrategyUnpublish: Object.freeze([
|
|
43
|
+
{ name: "publisher", type: "address" },
|
|
44
|
+
{ name: "id", type: "bytes32" },
|
|
45
|
+
{ name: "at", type: "uint256" },
|
|
46
|
+
]),
|
|
47
|
+
});
|
|
48
|
+
// the store's rules (data-worker/strategy-board.mjs holds them; Go mode and Builder mode read them to say why first)
|
|
49
|
+
const RULES = Object.freeze({
|
|
50
|
+
nameMax: 60, // a name, after its spaces are trimmed
|
|
51
|
+
contentMax: 24000, // the content's characters
|
|
52
|
+
bodyBytes: 32768, // a POST's body
|
|
53
|
+
signedAgoS: 3600, // a message signed at most an hour ago
|
|
54
|
+
signedAheadS: 300, // and at most 5 minutes ahead of the store's clock
|
|
55
|
+
livePerPublisher: 10, // live strategies a publisher keeps on the board
|
|
56
|
+
liveMax: 300, // live strategies on the board, each space
|
|
57
|
+
writesPerSignerDay: 30, // writes a publisher signs in any 24 hours
|
|
58
|
+
listMax: 100, // GET /api/strategies' rows, newest first
|
|
59
|
+
recordTtlS: 600, // a record read on chain is read again after this long
|
|
60
|
+
});
|
|
61
|
+
const SCHEMA = "priors.strategy", NODE_ID = /^n\d{1,4}$/, AGENT = /^[1-9]\d{0,11}$/;
|
|
62
|
+
const own = (o, k) => Object.prototype.hasOwnProperty.call(o || {}, k);
|
|
63
|
+
|
|
64
|
+
/* ---- the content: one written form ---- */
|
|
65
|
+
function canon(v) {
|
|
66
|
+
if (Array.isArray(v)) return v.map(canon);
|
|
67
|
+
if (v && typeof v === "object") return Object.fromEntries(Object.keys(v).sort().map((k) => [k, canon(v[k])]));
|
|
68
|
+
return v;
|
|
69
|
+
}
|
|
70
|
+
/** The cards' places a graph gives (trade-core.js's graph: its nodes' id, type, x, y), whole pixels from 0 to 4000. */
|
|
71
|
+
function layoutOf(graph) {
|
|
72
|
+
const nodes = graph && Array.isArray(graph.nodes) ? graph.nodes : [];
|
|
73
|
+
const px = (v) => Math.max(0, Math.min(4000, Math.round(Number(v) || 0)));
|
|
74
|
+
return nodes.filter((n) => n && NODE_ID.test(String(n.id)) && typeof n.type === "string").map((n) => ({ id: n.id, type: n.type, x: px(n.x), y: px(n.y) }));
|
|
75
|
+
}
|
|
76
|
+
/** The text a StrategyPublish message carries as `strategy`: { layout, strategy } as canonical JSON. */
|
|
77
|
+
const contentOf = (x) => JSON.stringify(canon({ layout: Array.isArray(x && x.layout) ? x.layout : [], strategy: x && x.strategy }));
|
|
78
|
+
/** The content back: { strategy, layout }, or an Error naming what is wrong. Its one written form only (the same text
|
|
79
|
+
* contentOf gives), at most RULES.contentMax characters, with a priors.strategy v1 and a layout of known nodes. */
|
|
80
|
+
function parseContent(text) {
|
|
81
|
+
if (typeof text !== "string" || !text || text.length > RULES.contentMax) throw new Error(`the strategy must be a JSON text of at most ${RULES.contentMax} characters`);
|
|
82
|
+
let x;
|
|
83
|
+
try { x = JSON.parse(text); } catch (_) { throw new Error("the strategy is not JSON"); }
|
|
84
|
+
if (!x || typeof x !== "object" || Array.isArray(x) || Object.keys(x).sort().join(",") !== "layout,strategy") throw new Error("the strategy takes exactly layout and strategy");
|
|
85
|
+
if (!x.strategy || x.strategy.kind !== SCHEMA || x.strategy.v !== 1) throw new Error("the strategy is not a priors.strategy v1");
|
|
86
|
+
if (!Array.isArray(x.layout) || x.layout.length > 40 || !x.layout.every((n) => n && Object.keys(n).sort().join(",") === "id,type,x,y" && NODE_ID.test(n.id) && typeof n.type === "string" && n.type.length <= 12 && Number.isInteger(n.x) && Number.isInteger(n.y) && n.x >= 0 && n.y >= 0 && n.x <= 4000 && n.y <= 4000)) throw new Error("the layout must list the cards' places: { id, type, x, y }, whole pixels from 0 to 4000");
|
|
87
|
+
if (contentOf(x) !== text) throw new Error("the strategy is not in its one written form (contentOf: keys sorted, no space)");
|
|
88
|
+
return { strategy: x.strategy, layout: x.layout };
|
|
89
|
+
}
|
|
90
|
+
/** Every agent id the strategy rules name (a trigger's, a step's, a test's), as decimal strings, A to Z. */
|
|
91
|
+
function agentsOf(strategy) {
|
|
92
|
+
const out = new Set();
|
|
93
|
+
const seen = (o) => { if (o && typeof o === "object" && own(o, "agent")) out.add(String(o.agent)); };
|
|
94
|
+
const steps = (list, depth) => {
|
|
95
|
+
if (!Array.isArray(list) || depth > 50) return;
|
|
96
|
+
for (const s of list) { seen(s); if (s && s.op === "if") { seen(s.test); steps(s.yes, depth + 1); steps(s.no, depth + 1); } }
|
|
97
|
+
};
|
|
98
|
+
for (const r of (strategy && Array.isArray(strategy.rules) ? strategy.rules : [])) { seen(r && r.when); steps(r && r.do, 0); }
|
|
99
|
+
return [...out].sort();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* ---- the messages ---- */
|
|
103
|
+
const uint = (v) => String(typeof v === "bigint" ? v : Math.floor(Number(v)));
|
|
104
|
+
/** A StrategyPublish message: publisher (an address), agentId, name (trimmed), the content of { strategy, layout }, at. */
|
|
105
|
+
const publishMessage = (o) => ({ publisher: String(o.publisher), agentId: uint(o.agentId), name: String(o.name == null ? "" : o.name).trim().slice(0, RULES.nameMax), strategy: contentOf({ strategy: o.strategy, layout: o.layout }), at: uint(o.at) });
|
|
106
|
+
const unpublishMessage = (o) => ({ publisher: String(o.publisher), id: String(o.id).toLowerCase(), at: uint(o.at) });
|
|
107
|
+
/** The typed data for eth_signTypedData_v4 and the account's own signTypedData: { domain, types, primaryType, message };
|
|
108
|
+
* with `bigint`, its uints as bigints (viem's account), else as decimal strings (ethers, a wallet's JSON). */
|
|
109
|
+
function typedData(primaryType, message, { bigint = false } = {}) {
|
|
110
|
+
if (!own(TYPES, primaryType)) throw new Error("no such message: " + primaryType);
|
|
111
|
+
const m = { ...message };
|
|
112
|
+
for (const f of TYPES[primaryType]) if (f.type === "uint256" && m[f.name] != null) m[f.name] = bigint ? BigInt(m[f.name]) : String(m[f.name]);
|
|
113
|
+
return { domain: { ...DOMAIN }, types: { [primaryType]: TYPES[primaryType].map((f) => ({ ...f })) }, primaryType, message: m };
|
|
114
|
+
}
|
|
115
|
+
const ID = /^0x[0-9a-f]{64}$/;
|
|
116
|
+
/** Copy into Go mode: the account's Trade tab, which opens the strategy `id` as a draft (account-trade.js). */
|
|
117
|
+
const copyHref = (app, id) => (typeof app === "string" && /^https:\/\/[a-z0-9.-]+$/.test(app) && ID.test(String(id)) ? `${app}/account?trade=${id}` : null);
|
|
118
|
+
|
|
119
|
+
/* ---- the board's words ---- */
|
|
120
|
+
const TITLE = "Trade";
|
|
121
|
+
const SUB = "Trading strategies their owners published for their agents: each one's nodes, levels and amounts in full, the agent it runs for, and that agent's record read on chain. Copy one into Go mode to start from it: it opens as a draft, and nothing runs before you turn it on there.";
|
|
122
|
+
const NOT_ENDORSEMENT = "Not an endorsement.";
|
|
123
|
+
const EMPTY = "No strategy is published yet.";
|
|
124
|
+
const LOADING = "Loading strategies…";
|
|
125
|
+
const UNREAD = "The strategies can't be read just now. The board tries again in a minute.";
|
|
126
|
+
const COPY = "Copy into Go mode";
|
|
127
|
+
const COPY_NOTE = "Opens as a draft in Go mode's Trade tab, with these levels and amounts. Nothing runs until you check it and turn it on there.";
|
|
128
|
+
const BORROW_NOTE = "Opens a loan of the agent that must be repaid.";
|
|
129
|
+
const TITLES = {
|
|
130
|
+
schedule: "On a timer", price_up: "Price rises to", price_down: "Price falls to", loan_due: "Loan due soon", tick: "Every pass",
|
|
131
|
+
if: "If", borrow: "Borrow on the agent's line", buy: "Buy a token", sell: "Sell a share of a token", repay: "Repay the agent's loan", stop: "Stop here",
|
|
132
|
+
};
|
|
133
|
+
const KINDS = { trigger: "Trigger", if: "If", action: "Action" };
|
|
134
|
+
const NUM = (v) => { const n = Number(v); return Number.isFinite(n) ? n : 0; };
|
|
135
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
136
|
+
const money = (v) => { const n = NUM(v); return "$" + (Math.round(n * 100) / 100).toLocaleString("en-US", { minimumFractionDigits: n % 1 ? 2 : 0, maximumFractionDigits: 2 }); };
|
|
137
|
+
|
|
138
|
+
/** A node as the card shows it: its title, its kind, what it does in a few words (its levels and amounts). */
|
|
139
|
+
function nodeOf(T, n, ctx) {
|
|
140
|
+
const m = T.node(n.type, n.values);
|
|
141
|
+
let summary = T.summary(n, ctx);
|
|
142
|
+
if (n.type === "buy") summary = summary.replace(/ · (?:your USDG|borrowed USDG)$/, "") + (n.values && n.values.from === "loan" ? ", with the USDG borrowed before it" : ", with the account's USDG");
|
|
143
|
+
const out = { id: n.id, type: n.type, kind: m.kind, kindLabel: KINDS[m.kind] || m.kind, title: TITLES[n.type] || m.title, summary };
|
|
144
|
+
if (n.type === "borrow") out.note = BORROW_NOTE;
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
/** Each trigger's path, top to bottom: [{ node, then: [paths] (an If's Yes and No: { branch, label, steps }) }]; a node
|
|
148
|
+
* two paths share is shown once, and named again where the second meets it. */
|
|
149
|
+
function pathsOf(T, g, ctx) {
|
|
150
|
+
const shown = new Set(), byId = (id) => g.nodes.find((x) => x.id === id) || null;
|
|
151
|
+
const walk = (id, depth) => {
|
|
152
|
+
const steps = [];
|
|
153
|
+
for (let cur = id; cur && depth < 40; depth++) {
|
|
154
|
+
const n = byId(cur); if (!n) break;
|
|
155
|
+
if (shown.has(n.id)) { steps.push({ again: n.id }); break; }
|
|
156
|
+
shown.add(n.id);
|
|
157
|
+
const step = { node: nodeOf(T, n, ctx) };
|
|
158
|
+
steps.push(step);
|
|
159
|
+
if (T.kindOf(n.type) === "if") { step.branches = [["yes", "Yes"], ["no", "No"]].map(([b, label]) => ({ branch: b, label, steps: walk(T.next(g, n.id, b), depth + 1) })); break; }
|
|
160
|
+
if (!T.outputs(n.type).length) break;
|
|
161
|
+
cur = T.next(g, n.id, "out");
|
|
162
|
+
}
|
|
163
|
+
return steps;
|
|
164
|
+
};
|
|
165
|
+
const ts = g.nodes.filter((n) => T.kindOf(n.type) === "trigger").sort((a, b) => a.y - b.y || a.x - b.x);
|
|
166
|
+
return ts.map((t) => walk(t.id, 0));
|
|
167
|
+
}
|
|
168
|
+
/** The agent's Priors record as the board's row has it, in a few words. */
|
|
169
|
+
function agentRecord(C, row) {
|
|
170
|
+
if (!row) return "No Priors record yet";
|
|
171
|
+
if (row.defaulted) return "Defaulted";
|
|
172
|
+
const n = NUM(row.loansRepaid), late = NUM(row.late);
|
|
173
|
+
return plural(n, "loan repaid", "loans repaid") + (late > 0 ? ` · ${late} late` : "");
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A published strategy as the board's card shows it (`row`: GET /api/strategies' row: { id, name, agentId, at, strategy,
|
|
177
|
+
* layout, record }), or null when trade-core.js can't read it. x: { T (trade-core.js), C (board-core.js), board (the
|
|
178
|
+
* board's answer, for the agent's name and record), assets ([{ symbol, name, token }]), app (Go mode's origin) }.
|
|
179
|
+
* { id, name, agent: { id, name, idText, href, record }, limits, paths, record (recordLines), copy }
|
|
180
|
+
*/
|
|
181
|
+
function cardOf(row, x) {
|
|
182
|
+
const T = x && x.T, C = x && x.C;
|
|
183
|
+
if (!row || !T || !C || !ID.test(String(row.id))) return null;
|
|
184
|
+
let g;
|
|
185
|
+
try { g = T.fromPublished({ id: row.id, name: row.name, strategy: row.strategy, graph: { nodes: Array.isArray(row.layout) ? row.layout : [] } }); } catch (_) { return null; }
|
|
186
|
+
const agentId = String(row.agentId), rows = x.board && Array.isArray(x.board.agents) ? x.board.agents : [];
|
|
187
|
+
const r = rows.find((a) => a && String(a.id) === agentId) || null, nm = C.nameOf(r || { id: agentId });
|
|
188
|
+
const ctx = { assets: x.assets || [], agents: [{ id: agentId, label: `#${agentId}` }] };
|
|
189
|
+
return {
|
|
190
|
+
id: row.id,
|
|
191
|
+
name: String(row.name || "").trim() || "Strategy",
|
|
192
|
+
agent: { id: agentId, name: nm.name, idText: nm.id, href: C.agentPath(agentId), record: agentRecord(C, r) },
|
|
193
|
+
published: NUM(row.at) > 0 ? C.date(NUM(row.at)) : "",
|
|
194
|
+
limits: T.limitsSentence(T.limitsOf(g)),
|
|
195
|
+
paths: pathsOf(T, g, ctx),
|
|
196
|
+
record: recordLines(row.record),
|
|
197
|
+
copy: copyHref(x.app, row.id),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* A strategy's record read on chain (data-worker/strategy-board.mjs's `record`), in words: [{ key, text }].
|
|
203
|
+
* trades the trades its account's trading key made (the key's operations' Uniswap swaps)
|
|
204
|
+
* loans the loans of the agent paid to the account, and how they ended: "repaid on time" is Score v2's, repaid
|
|
205
|
+
* at most 24 hours after the due time; a late one says so
|
|
206
|
+
* own the loans on a line its owner backs itself, or on its owner's own collateral, which build nothing in
|
|
207
|
+
* Score v2
|
|
208
|
+
* reading the record is still being read (older blocks wait for the next read)
|
|
209
|
+
*/
|
|
210
|
+
function recordLines(record) {
|
|
211
|
+
if (!record || typeof record !== "object" || !record.counts) return [{ key: "none", text: "Its record is being read on chain." }];
|
|
212
|
+
const c = record.counts, out = [];
|
|
213
|
+
const trades = NUM(c.trades), buys = NUM(c.buys), sells = NUM(c.sells);
|
|
214
|
+
out.push({ key: "trades", text: trades ? `Trades by its account's key: ${trades} (${plural(buys, "buy", "buys")}, ${plural(sells, "sell", "sells")}), ${money(c.tradedUsd)} in all.` : "Trades by its account's key: none yet." });
|
|
215
|
+
const loans = NUM(c.loans);
|
|
216
|
+
if (!loans) out.push({ key: "loans", text: "Loans of the agent paid to its account: none yet." });
|
|
217
|
+
else {
|
|
218
|
+
const parts = [`${NUM(c.onTime)} repaid on time`];
|
|
219
|
+
if (NUM(c.late)) parts.push(`${NUM(c.late)} repaid late`);
|
|
220
|
+
if (NUM(c.open)) parts.push(`${NUM(c.open)} open`);
|
|
221
|
+
if (NUM(c.overdue)) parts.push(`${NUM(c.overdue)} past due`);
|
|
222
|
+
if (NUM(c.defaulted)) parts.push(`${NUM(c.defaulted)} defaulted`);
|
|
223
|
+
out.push({ key: "loans", text: `Loans of the agent paid to its account: ${loans}, ${money(c.borrowedUsd)} borrowed. ${parts.join(", ")}. On time as Score v2 counts it: repaid at most 24 hours after the due time.` });
|
|
224
|
+
}
|
|
225
|
+
if (NUM(c.ownLine)) out.push({ key: "own", text: `${NUM(c.ownLine) === loans ? (loans === 1 ? "It is" : "All of them are") : `${NUM(c.ownLine)} of them ${NUM(c.ownLine) === 1 ? "is" : "are"}`} on a line its owner backs itself or on its owner's own collateral, which builds nothing in Score v2.` });
|
|
226
|
+
if (record.partial) out.push({ key: "reading", text: "Older blocks are still being read: the record grows at the next reads." });
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
CHAIN_ID, DOMAIN, TYPES, RULES, SCHEMA, contentOf, parseContent, layoutOf, agentsOf, publishMessage, unpublishMessage, typedData, copyHref,
|
|
232
|
+
TITLE, SUB, NOT_ENDORSEMENT, EMPTY, LOADING, UNREAD, COPY, COPY_NOTE, BORROW_NOTE, TITLES, cardOf, pathsOf, nodeOf, recordLines, agentRecord,
|
|
233
|
+
};
|
|
234
|
+
});
|
package/src/line-options.mjs
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
// (tools.mjs) and the data Worker's GET /api/line-options?id=N (data-worker/line-options.mjs), which the agent page of an
|
|
17
17
|
// identity with no Priors record reads (docs/growth/bring-your-agent.md). Each makes the same reads its own way (the MCP
|
|
18
18
|
// through the data Worker's routes, the data Worker from its own store) and hands them to it.
|
|
19
|
+
// Behind each server's LINE_OPTIONS_NEXT (growth loop batch 11's AN; docs/growth/line-options.md), routes 1 and 3 give an
|
|
20
|
+
// identity with no Priors record next steps it can take itself (lineOptions' `next`); off, every word is what it was.
|
|
19
21
|
import { encodeFunctionData, decodeFunctionResult, parseAbi } from "viem";
|
|
20
22
|
import DEP from "../deployments/4663.v2.json" with { type: "json" };
|
|
21
23
|
|
|
@@ -150,7 +152,12 @@ const RECORD_UNREAD = "its Priors record could not be read just now; agent_recor
|
|
|
150
152
|
* chain (readLineFacts'); stocks (/api/stocks, null when not read); lane (/ethos/status, null when not read, { off:
|
|
151
153
|
* true } when the site answered 404); minLoan (the pool's, USDG units);
|
|
152
154
|
* links: { invite, builder, agentPage, start, seats, stocks }; asOf: { snapshot, stocks, directoryBlock }; now
|
|
153
|
-
* (seconds: the snapshot's time when it was read, the clock for days and dates)
|
|
155
|
+
* (seconds: the snapshot's time when it was read, the clock for days and dates);
|
|
156
|
+
* next (growth loop batch 11's AN, the hosted LINE_OPTIONS_NEXT and the data Worker's): null or absent, the words as
|
|
157
|
+
* before; { firstLine }, for an identity with no Priors record, route 3's next step names the two paths open to it
|
|
158
|
+
* (Go mode's Stocks for its account's agents with a record or a new one; the stock vault's own open from its owner's
|
|
159
|
+
* key) and, with firstLine (LOCAL_FIRST_LINE), route 1's names the local @priors/mcp's first_line. The data is the
|
|
160
|
+
* same either way.
|
|
154
161
|
*/
|
|
155
162
|
export function lineOptions(o) {
|
|
156
163
|
const id = o.agentId, rec = o.recordRead ? o.record : null, ch = o.chain && o.chain.read ? o.chain : { read: false }, L = o.links, now = o.now;
|
|
@@ -198,7 +205,10 @@ export function lineOptions(o) {
|
|
|
198
205
|
close(r, `this week's first lines are taken (${r.room} USDG of room left, a first line is ${r.line} USDG); the room fills again ${refill && refill > now ? `after ${r.refillsAt}` : "with the next week"}`);
|
|
199
206
|
} else {
|
|
200
207
|
r.open = true; r.bond = ch.bond != null ? usd(ch.bond) : null; r.next = { url: L.invite, builder: L.builder };
|
|
201
|
-
|
|
208
|
+
// AN: from a runtime, the local @priors/mcp's first_line takes it from the owner's key (an identity with no record:
|
|
209
|
+
// first_line refuses one with a record)
|
|
210
|
+
const runtime = o.next && o.next.firstLine && !rec ? `from a runtime that holds the key of the wallet that owns agent #${id}, the local @priors/mcp's first_line (PRIORS_JOIN=on in its env) takes this line with no clone (it posts the bond, proves the key owns the identity to Priors' invite bot and signs the pool consent); or that wallet` : null;
|
|
211
|
+
body = `A ${r.line} USDG line, for ${r.bond ? `a ${r.bond} USDG bond` : "a bond (its amount could not be read just now)"} its owner posts first: it comes back once the line is closed with no loan open, or 4 days after it was posted if the agent never takes a line, and a default forfeits it. This week's room: ${r.room} USDG, ${plural(r.firstLines, "first line")}. The invite service applies its own limits too (first lines per owner, a daily cap). Next: ${runtime || `the wallet that owns agent #${id}`} asks at ${L.invite} (it proves it owns it, posts the bond and gets an invite), then takes the line in Builder mode with its pool consent: ${L.builder}`;
|
|
202
212
|
}
|
|
203
213
|
}
|
|
204
214
|
say(1, "The treasury's first line, by invite", r, body);
|
|
@@ -254,7 +264,11 @@ export function lineOptions(o) {
|
|
|
254
264
|
else {
|
|
255
265
|
r.open = true; r.upTo = usd(upTo); r.next = { tool: "stock_line_request", arguments: rec ? { agent_id: id } : {} };
|
|
256
266
|
const facts = [maxLine != null ? `the vault's cap is ${r.maxLine} USDG a line` : "", week != null ? `${r.weekLeft} USDG of new lines are left this week` : "", `${lending.length} of its ${S.assets.length} stock tokens take a new line now (stock_assets lists them)`].filter(Boolean);
|
|
257
|
-
|
|
267
|
+
// AN: for an identity with no record, the two paths open to it. Go mode's Stocks lists only the signed-in account's
|
|
268
|
+
// agents with a record, and a new one it registers (web/account-stocks.js); the vault itself takes the identity
|
|
269
|
+
// from its owner's (or delegate's) key (src/StockVault.sol open: isController)
|
|
270
|
+
const paths = o.next && !rec ? `gives the link to Go mode's Stocks, which opens a stock line for an agent with a Priors record that the account signed in there owns, or for a new agent it registers there; for agent #${id} itself, the wallet that owns it calls the stock vault's own open with its own key (the public SDK's openStockLine, sdk/priors-v2.mjs: the pool consent for the vault's root, then the deposit): https://github.com/priors-agents/priors` : null;
|
|
271
|
+
body = `Up to ${r.upTo} USDG, backed by stock tokens its owner deposits: ${facts.slice(0, -1).join(", ")}${facts.length > 1 ? ", and " : ""}${facts[facts.length - 1]}.${rec && backer && rec.line > 0n ? ` Its current ${usd(rec.line)} USDG line moves to the stock vault when this one opens.` : ""} Next: stock_line_request (${rec ? `agent_id ${id}, a symbol and line_usd` : "a symbol and line_usd, and no agent_id: it has no Priors record yet"}) sizes the deposit for the line wanted and ${paths || `gives the Go mode link where its owner deposits${rec ? "" : `, choosing agent #${id} on the sheet`}.`}`;
|
|
258
272
|
}
|
|
259
273
|
}
|
|
260
274
|
say(3, "A stock line", r, body);
|
|
@@ -413,9 +427,10 @@ const isoOrNull = (t) => (t ? iso(t) : null);
|
|
|
413
427
|
* off); snap: the snapshot (its meta's takenAt and timestamp, its params' minLoan), null when it could not be read;
|
|
414
428
|
* agent: the snapshot's agent with this id (or its lineFields), null without one; stocks: /api/stocks, null when not
|
|
415
429
|
* read; lane: the Ethos lane's status (null when not read, { off: true } when its site answered 404); client: the
|
|
416
|
-
* chain (an EIP-1193 `request`; null: none); builderUrl, appUrl (linksOf)
|
|
430
|
+
* chain (an EIP-1193 `request`; null: none); builderUrl, appUrl (linksOf); next: lineOptions' (AN's next steps; null
|
|
431
|
+
* or absent, the words as before).
|
|
417
432
|
*/
|
|
418
|
-
export async function lineOptionsAnswer({ agentId, reg, snap, agent, stocks, lane, client, builderUrl, appUrl }) {
|
|
433
|
+
export async function lineOptionsAnswer({ agentId, reg, snap, agent, stocks, lane, client, builderUrl, appUrl, next = null }) {
|
|
419
434
|
const regRead = !!(reg && typeof reg === "object" && !reg.__status);
|
|
420
435
|
if (regRead && !reg.item && !agent) return { status: 404, error: `No identity #${agentId} in the ERC-8004 registry on Robinhood Chain (the Directory knows ${Number(reg.n) || 0}, ids 0 to ${Math.max(0, (Number(reg.n) || 0) - 1)}).` };
|
|
421
436
|
if (!regRead && !agent) return { status: 503, error: `Agent #${agentId}: the ERC-8004 registry (the Priors Directory) could not be read just now${snap ? "" : ", nor the Priors snapshot"}, so whether this identity exists is not known: try again in a minute.` };
|
|
@@ -427,7 +442,7 @@ export async function lineOptionsAnswer({ agentId, reg, snap, agent, stocks, lan
|
|
|
427
442
|
agentId, owner, record: recordOf(agent), recordRead: !!snap, chain, stocks, lane, minLoan: snap && snap.params && snap.params.minLoan != null ? Number(snap.params.minLoan) : null,
|
|
428
443
|
links: linksOf(builderUrl, appUrl, agentId),
|
|
429
444
|
asOf: { snapshot: snap ? isoOrNull(meta.takenAt ?? meta.timestamp) : null, stocks: stocks ? isoOrNull(stocks.updatedAt) : null, directoryBlock: regRead ? Number(reg.block) || null : null },
|
|
430
|
-
now: Number(meta.timestamp) || Math.floor(Date.now() / 1000),
|
|
445
|
+
now: Number(meta.timestamp) || Math.floor(Date.now() / 1000), next,
|
|
431
446
|
}),
|
|
432
447
|
};
|
|
433
448
|
}
|