@priors/mcp 0.14.1 → 0.15.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 +31 -0
- package/README.md +34 -6
- package/package.json +2 -2
- package/src/agent-lease.mjs +657 -0
- package/src/market-plan.mjs +86 -33
- package/src/market-tools.mjs +130 -45
- package/src/server.mjs +85 -18
- package/src/work-types.mjs +67 -8
package/src/market-plan.mjs
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// one plain transaction at a time. @priors/mcp's market tools (packages/mcp/src/market-tools.mjs) run it; the package
|
|
4
4
|
// holds a byte-for-byte copy (scripts/test-packages.mjs fails on any drift). Pure: no network, no clock, no file.
|
|
5
5
|
//
|
|
6
|
-
// 1. kindReads(market): which market answers at the address, v1 or V2, at one block (marketKindOf). v1's
|
|
7
|
-
// reverts with no data; V2's is CREATE(market, 1) (market-bids spenderOf), whose market() is the
|
|
8
|
-
// registry and USDG must be the package's record's. A V2 with the builder share (the P5 spec, section 2)
|
|
9
|
-
// MAX_BUILDER_BPS(); one without it reverts with no data, and every sale then pays no share. Its owner's
|
|
10
|
-
// buildersOn() (false until the Safe calls enableBuilders(), once, for good), is read with each agent's
|
|
11
|
-
// the plan's block, never kept: while it is off no share can be set, and none is reported.
|
|
6
|
+
// 1. kindReads(market, lease): which market answers at the address, v1 or V2, at one block (marketKindOf). v1's
|
|
7
|
+
// bidSpender() reverts with no data; V2's is CREATE(market, 1) (market-bids spenderOf), whose market() is the
|
|
8
|
+
// market. Its registry and USDG must be the package's record's. A V2 with the builder share (the P5 spec, section 2)
|
|
9
|
+
// answers MAX_BUILDER_BPS(); one without it reverts with no data, and every sale then pays no share. Its owner's
|
|
10
|
+
// switch, buildersOn() (false until the Safe calls enableBuilders(), once, for good), is read with each agent's
|
|
11
|
+
// reads, at the plan's block, never kept: while it is off no share can be set, and none is reported. With the
|
|
12
|
+
// package's AgentLease record, the lease's market() must be this market (addr.lease).
|
|
12
13
|
// 2. agentReads, accountReads, bidReads, then moreReads (the agent's sponsor's followsLine, the seller's and the
|
|
13
14
|
// makers' accounts): one Multicall3 aggregate3 each, every call allowed to fail, all at one block. readsOut decodes
|
|
14
15
|
// them into `c`, the object every plan reads; a read that failed is null, and a plan given null answers "unread",
|
|
@@ -16,15 +17,23 @@
|
|
|
16
17
|
// 3. sellPlan, buyPlan, cancelPlan, bidPlan, bidAnyPlan, cancelBidPlan, acceptPlan: the contract's rules in its order
|
|
17
18
|
// (web/board-wallet-core.js sellState and buyPlan, web/board-wallet-bids-core.js, which a test holds this to), then
|
|
18
19
|
// the steps, each one transaction: { steps, pins, ... } or { error: kind, ...vars }.
|
|
19
|
-
// 4. stepCalls(step, o): a step's { to, data }, from market-abi's MARKET_IFACE
|
|
20
|
+
// 4. stepCalls(step, o): a step's { to, data }, from market-abi's MARKET_IFACE, market-bids' call builders and the
|
|
21
|
+
// lease seam's handoverCalls (sdk/agent-lease.mjs).
|
|
20
22
|
// 5. MARKET_ERRORS and errorKindOf(revertData, role): a revert's kind; PLAN_WORDS and planWords(kind, vars): its words.
|
|
21
23
|
//
|
|
22
24
|
// What a sale leaves the seller is computed in netOf alone: price - fee - the builder's share, the share only where the
|
|
23
25
|
// market answers builderOf (P5), else price - fee. An open asking price and an open bid are worded; a price paid or taken
|
|
24
26
|
// is never worded after the fact.
|
|
27
|
+
//
|
|
28
|
+
// Renting (AgentLease, docs/AGENT-LEASE.md): only where the package records the lease (addr.lease) does agentReads read
|
|
29
|
+
// the lease stored on the agent (leaseOf), and while one is stored (its renter not zero: running, or ended and not paid
|
|
30
|
+
// out) buyPlan and acceptPlan claim on the lease before and after the change of hands, as every change of hands on
|
|
31
|
+
// Priors does (the client rule): "claimBefore" pays each day ended to whoever held the agent when it ended, and
|
|
32
|
+
// "claimAfter" records the new holder at once. Without the lease's record every read, plan and call is as before.
|
|
25
33
|
import { ethers } from "ethers";
|
|
26
34
|
import { MARKET_IFACE, LISTING_RULES, feeOf } from "./market-abi.mjs";
|
|
27
35
|
import { BID_RULES, BID_WORDS, spenderOf, idsRootOf, listOf, inRoot, reserveCall, bidCall, bidAnyCall, cancelBidCall, acceptCall } from "./market-bids.mjs";
|
|
36
|
+
import { LEASE_IFACE, LEASE_WORDS, handoverCalls } from "./agent-lease.mjs";
|
|
28
37
|
|
|
29
38
|
/* ---- small helpers ---- */
|
|
30
39
|
|
|
@@ -58,8 +67,9 @@ const BID = "tuple(address maker, uint64 expiry, uint16 left, bool any, uint96 p
|
|
|
58
67
|
const AGENT_V2 = "tuple(bool enrolled, bool isRoot, bool defaulted, bool frozen, bool importedFromV1, uint64 enrolledAt, uint64 lastBorrowAt, uint64 lastRepayAt, uint256 sponsor, uint256 delegatedIn, uint256 delegatedOut, uint256 principalOut, uint256 activeLoans, uint256 premiumBps, uint256 premiumCap, uint256 loansRepaid, uint256 volumeRepaid, uint256 feesPaid, uint256 recourseHonored, uint256 childrenDefaulted, uint256 qualifiedRepaid, uint256 dollarSecondsRepaid)";
|
|
59
68
|
const AGENT_V1 = "tuple(bool enrolled, bool isRoot, bool defaulted, uint64 enrolledAt, uint256 sponsor, uint256 delegatedIn, uint256 delegatedOut, uint256 earned, uint256 stake, uint256 principalOut, uint256 activeLoans, uint256 loansRepaid, uint256 volumeRepaid, uint256 feesPaid, uint256 recourseHonored, uint256 childrenDefaulted, uint64 epochStart, uint256 earnedThisEpoch, uint256 qualifiedRepaid, uint256 dollarSecondsRepaid)";
|
|
60
69
|
/** Every view a plan reads, by the contract that answers it (src/AgentMarket.sol, src/AgentMarketV2.sol, BidSpender,
|
|
61
|
-
* the ERC-8004 registry, CreditPoolV2, CreditPool v1, InviteBond v1 and V2, USDG
|
|
62
|
-
* their own structs under the same selectors, so each
|
|
70
|
+
* the ERC-8004 registry, CreditPoolV2, CreditPool v1, InviteBond v1 and V2, USDG, and AgentLease as the lease's seam
|
|
71
|
+
* names it: leaseOf and market()). Pool v1 and the two bonds answer their own structs under the same selectors, so each
|
|
72
|
+
* contract has its own Interface. */
|
|
63
73
|
export const READS = Object.freeze({
|
|
64
74
|
market: new ethers.Interface([
|
|
65
75
|
`function listingOf(uint256 id) view returns (${LISTING})`, "function feeBps() view returns (uint256)", "function minFee() view returns (uint256)",
|
|
@@ -79,6 +89,7 @@ export const READS = Object.freeze({
|
|
|
79
89
|
bondV1: new ethers.Interface(["function bonds(uint256 id) view returns (tuple(address depositor, uint64 at, uint256 amount, uint256 qualifiedAt))"]),
|
|
80
90
|
bondV2: new ethers.Interface(["function bonds(uint256 id) view returns (tuple(address depositor, uint64 at, uint256 amount))", "function amount() view returns (uint256)"]),
|
|
81
91
|
usdg: new ethers.Interface(["function balanceOf(address account) view returns (uint256)", "function allowance(address owner, address spender) view returns (uint256)"]),
|
|
92
|
+
lease: LEASE_IFACE,
|
|
82
93
|
});
|
|
83
94
|
|
|
84
95
|
/** One read: { key, to, data, as: [contract, fn] }. A read on a zero address is never made (that contract isn't on
|
|
@@ -134,27 +145,30 @@ export function readsOut(reads, results, into = null) {
|
|
|
134
145
|
}
|
|
135
146
|
|
|
136
147
|
/** Which market answers at `market`, and its own addresses: the spender's market() is read in the same call, at the
|
|
137
|
-
* address V2's spender would have (spenderOf). */
|
|
138
|
-
export function kindReads(market) {
|
|
148
|
+
* address V2's spender would have (spenderOf); with `lease` (the package's AgentLease record), the lease's market(). */
|
|
149
|
+
export function kindReads(market, lease = null) {
|
|
139
150
|
const out = [], add = adder(out), m = lc(market);
|
|
140
151
|
for (const k of ["bidSpender", "feeBps", "previous", "registry", "usdg", "poolV2", "poolV1", "inviteBond", "inviteBondV2", "MAX_BUILDER_BPS"]) add(k, m, "market", k);
|
|
141
152
|
add("spenderMarket", spenderOf(m), "spender", "market");
|
|
153
|
+
add("leaseMarket", lease, "lease", "market");
|
|
142
154
|
return out;
|
|
143
155
|
}
|
|
144
156
|
/**
|
|
145
157
|
* The market `c` (kindReads' answers) shows, against the package's `record` ({ registry, usdg }): { kind: "v1" | "v2",
|
|
146
158
|
* addr: { market, registry, usdg, poolV2, poolV1, inviteBond, inviteBondV2, spender (V2's), previous (V2's v1, or
|
|
147
|
-
* null) }, shares (V2 with the builder share) }, or { error }: "unread" (a read failed: try
|
|
148
|
-
* registry or USDG isn't the record's), "unknown" (neither v1's nor V2's answers)
|
|
159
|
+
* null), lease (only with `lease`) }, shares (V2 with the builder share) }, or { error }: "unread" (a read failed: try
|
|
160
|
+
* again), "mismatch" (its registry or USDG isn't the record's), "unknown" (neither v1's nor V2's answers),
|
|
161
|
+
* "unknownLease" (`lease`, the package's AgentLease, answers no market() or another market's: it reads this market's
|
|
162
|
+
* sales, so only this one's lease is claimed on).
|
|
149
163
|
*/
|
|
150
|
-
export function marketKindOf(c, { market, record }) {
|
|
164
|
+
export function marketKindOf(c, { market, record, lease = null }) {
|
|
151
165
|
const f = c.failed || {}, z = (a) => (isAddr(a) ? lc(a) : null);
|
|
152
166
|
if (c.registry == null || c.usdg == null || c.poolV2 == null) return { error: f.registry === "empty" || f.usdg === "empty" ? "unknown" : "unread" };
|
|
153
167
|
if (!same(c.registry, record && record.registry) || !same(c.usdg, record && record.usdg)) return { error: "mismatch" };
|
|
154
168
|
const addr = { market: lc(market), registry: lc(c.registry), usdg: lc(c.usdg), poolV2: z(c.poolV2), poolV1: z(c.poolV1), inviteBond: z(c.inviteBond), inviteBondV2: z(c.inviteBondV2), spender: null, previous: null };
|
|
155
169
|
if (c.bidSpender == null && f.bidSpender === "empty") {
|
|
156
170
|
if (c.feeBps == null) return { error: "unread" };
|
|
157
|
-
return { kind: "v1", addr, shares: false };
|
|
171
|
+
return leaseIn({ kind: "v1", addr, shares: false }, c, { market, lease });
|
|
158
172
|
}
|
|
159
173
|
if (c.bidSpender == null) return { error: f.bidSpender === "reverted" ? "unknown" : "unread" };
|
|
160
174
|
const spender = spenderOf(market);
|
|
@@ -163,12 +177,21 @@ export function marketKindOf(c, { market, record }) {
|
|
|
163
177
|
if (c.MAX_BUILDER_BPS != null) shares = true;
|
|
164
178
|
else if (f.MAX_BUILDER_BPS === "empty") shares = false;
|
|
165
179
|
if (shares === null) return { error: "unread" };
|
|
166
|
-
return { kind: "v2", addr: { ...addr, spender, previous: z(c.previous) }, shares };
|
|
180
|
+
return leaseIn({ kind: "v2", addr: { ...addr, spender, previous: z(c.previous) }, shares }, c, { market, lease });
|
|
181
|
+
}
|
|
182
|
+
/** Market `k` with the package's `lease` confirmed (its market(), `c.leaseMarket`, is `market`): k.addr.lease. No
|
|
183
|
+
* lease: `k` as it is. */
|
|
184
|
+
function leaseIn(k, c, { market, lease }) {
|
|
185
|
+
if (lease == null) return k;
|
|
186
|
+
if (c.leaseMarket == null) return { error: c.failed && ["empty", "reverted"].includes(c.failed.leaseMarket) ? "unknownLease" : "unread" };
|
|
187
|
+
if (!isAddr(lease) || !same(c.leaseMarket, market)) return { error: "unknownLease" };
|
|
188
|
+
return { ...k, addr: { ...k.addr, lease: lc(lease) } };
|
|
167
189
|
}
|
|
168
190
|
|
|
169
191
|
/** What a sale reads of agent `id` (round one): its listing on the market and on `previous`, owner, approval, token
|
|
170
|
-
* URI, the market's record pin, both pools' records, both bonds and the bond's amount, its last sale,
|
|
171
|
-
* share where the market has one, with the owner's switch for shares (buildersOn) at the same block
|
|
192
|
+
* URI, the market's record pin, both pools' records, both bonds and the bond's amount, its last sale, its builder
|
|
193
|
+
* share where the market has one, with the owner's switch for shares (buildersOn) at the same block, and the lease
|
|
194
|
+
* stored on it where the package records AgentLease (addr.lease). */
|
|
172
195
|
export function agentReads({ addr, id, shares = false }) {
|
|
173
196
|
const a = addr || {}, i = big(id), out = [], add = adder(out);
|
|
174
197
|
add("listing", a.market, "market", "listingOf", [i]);
|
|
@@ -184,6 +207,7 @@ export function agentReads({ addr, id, shares = false }) {
|
|
|
184
207
|
add("bondAmount", a.inviteBondV2, "bondV2", "amount");
|
|
185
208
|
add("soldAt", a.market, "market", "lastSoldAt", [i]);
|
|
186
209
|
if (shares) { add("builder", a.market, "market", "builderOf", [i]); add("saleSplit", a.market, "market", "saleSplit", [i]); add("buildersOn", a.market, "market", "buildersOn"); }
|
|
210
|
+
add("lease", a.lease, "lease", "leaseOf", [i]);
|
|
187
211
|
return out;
|
|
188
212
|
}
|
|
189
213
|
/** The wallet's own (`me`): its standing (the pool's custodian and marks, the market's refusal), the pause and the
|
|
@@ -344,6 +368,23 @@ function builderIn(c, shares) {
|
|
|
344
368
|
if (big(b.bps) > 500n) return { error: "unread" };
|
|
345
369
|
return { builder: { to: lc(b.to), bps: big(b.bps) } };
|
|
346
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* The claims on the lease around a change of hands of the agent `c` read (the client rule, docs/AGENT-LEASE.md), where
|
|
373
|
+
* the package records AgentLease (addr.lease): while leaseOf names a renter (a lease that runs, or one that ended and
|
|
374
|
+
* isn't paid out yet), "claimBefore" first, so each day ended goes to whoever held the agent when it ended, and
|
|
375
|
+
* "claimAfter" last, so the new holder is recorded at once. A later plan of the same call gives `leased` (the first
|
|
376
|
+
* plan's: the bracket holds whatever leaseOf says now, since the claim before may close a lease that ran out and a
|
|
377
|
+
* claim with nothing stored returns 0) and `claimed` (the claim before was sent). { steps, leased } with the claims;
|
|
378
|
+
* { steps } as they are without them; { error: "unread" } while the lease's read failed.
|
|
379
|
+
*/
|
|
380
|
+
function bracket(c, steps, { addr, leased = false, claimed = false }) {
|
|
381
|
+
if (!addr || !isAddr(addr.lease)) return { steps };
|
|
382
|
+
if (!leased) {
|
|
383
|
+
if (c.lease == null) return { error: "unread" };
|
|
384
|
+
if (!isAddr(c.lease.renter)) return { steps };
|
|
385
|
+
}
|
|
386
|
+
return { steps: [...(claimed ? [] : ["claimBefore"]), ...steps, "claimAfter"], leased: true };
|
|
387
|
+
}
|
|
347
388
|
|
|
348
389
|
/**
|
|
349
390
|
* Listing agent `id` from `me` (sellState with the terms): `price` (USDG units, 5 USDG or more), `days` (1 to 30) or
|
|
@@ -434,11 +475,12 @@ export function listingBlock(c, { addr, now }) {
|
|
|
434
475
|
* "relisted" with `price` (a nonce or price other than `seen`'s), "changed" with `price` (above `maxPrice`), "self",
|
|
435
476
|
* "paused", "account", "marked", takeChecks' kinds, "record" with `n` and `m` (fewer repaid loans than `minRecord`),
|
|
436
477
|
* "short" with `short` and `cash`), or { steps ("approveUsdg": exactly the price, while the USDG approved to the market
|
|
437
|
-
* is short of it; "buy"
|
|
438
|
-
*
|
|
439
|
-
*
|
|
478
|
+
* is short of it; "buy"; "claimBefore" first and "claimAfter" last while a lease is stored, with `leased`: bracket's,
|
|
479
|
+
* from its `leased` and `claimed`), listing, follows (the treasury line comes with it), line, bond (what the buyer locks
|
|
480
|
+
* before it borrows on it), fee, share, net (the seller's), pins: { price, nonce, uriHash (the token URI's bytes hashed
|
|
481
|
+
* here), recordHash (the market's own, at the same block) } }.
|
|
440
482
|
*/
|
|
441
|
-
export function buyPlan(c, { addr, me, now, maxPrice, seen = null, minRecord = 0n, shares = false }) {
|
|
483
|
+
export function buyPlan(c, { addr, me, now, maxPrice, seen = null, minRecord = 0n, shares = false, leased = false, claimed = false }) {
|
|
442
484
|
c = c || {};
|
|
443
485
|
if (noAgent(c)) return { error: "gone" };
|
|
444
486
|
if (unread(c.listing, c.owner, c.approved)) return { error: "unread" };
|
|
@@ -465,8 +507,10 @@ export function buyPlan(c, { addr, me, now, maxPrice, seen = null, minRecord = 0
|
|
|
465
507
|
// what the seller gets: the market's own split when it answers one (the lower fee and share of list and now), else
|
|
466
508
|
// the fee and the share now
|
|
467
509
|
const split = shares && c.saleSplit ? { fee: big(c.saleSplit.fee), share: big(c.saleSplit.share), net: big(c.saleSplit.net) } : netOf(listing.price, { ...feesOf(c), builder: bi.builder, seller: listing.seller });
|
|
510
|
+
const br = bracket(c, [...(big(c.allowance) < listing.price ? ["approveUsdg"] : []), "buy"], { addr, leased, claimed });
|
|
511
|
+
if (br.error) return br;
|
|
468
512
|
return {
|
|
469
|
-
steps:
|
|
513
|
+
steps: br.steps, ...(br.leased ? { leased: true } : {}), listing, follows, line: follows ? lent : 0n, bond: wants ? big(c.bondAmount) : 0n,
|
|
470
514
|
fee: split.fee, share: split.share, net: split.net,
|
|
471
515
|
pins: { price: listing.price, nonce: listing.nonce, uriHash, recordHash: lc(c.record) },
|
|
472
516
|
};
|
|
@@ -604,11 +648,11 @@ export function cancelBidPlan(c, { me, now, bidIds, myBids = [] }) {
|
|
|
604
648
|
* seller, the maker's pins, the net. { error } ("unread", "gone", "notInBid", "taken", "selfAccept", "maker",
|
|
605
649
|
* "unfunded", "paused", saleChecks' kinds, "repaid" (`n`, `m`), "lineBelow" (`line`), "card", "noNet" (`price`, `fee`:
|
|
606
650
|
* the fee takes the whole price, which the contract allows only when the bid is at the minimum fee)), or { steps
|
|
607
|
-
* ("cancelOldPrev", "cancelOld", "bondApprove", "bond", "approve", "accept", in acceptCalls' order
|
|
608
|
-
*
|
|
609
|
-
* lower), bond, pins }.
|
|
651
|
+
* ("cancelOldPrev", "cancelOld", "bondApprove", "bond", "approve", "accept", in acceptCalls' order; "claimBefore" first
|
|
652
|
+
* and "claimAfter" last while a lease is stored, with `leased`, as buyPlan's), price, maker, proof, fee, share, net
|
|
653
|
+
* (minNet: exact at the read block; a fee changes only after the market's 48 h, and a share only lower), bond, pins }.
|
|
610
654
|
*/
|
|
611
|
-
export function acceptPlan(c, { addr, me, now, bidId, id, proof = [], shares = false }) {
|
|
655
|
+
export function acceptPlan(c, { addr, me, now, bidId, id, proof = [], shares = false, leased = false, claimed = false }) {
|
|
612
656
|
c = c || {};
|
|
613
657
|
const key = String(bidId), b = c.bids.get(key);
|
|
614
658
|
if (b == null) return { error: "unread" };
|
|
@@ -634,10 +678,11 @@ export function acceptPlan(c, { addr, me, now, bidId, id, proof = [], shares = f
|
|
|
634
678
|
const approved = same(c.approved, addr.market), mine = ownListing(c.listing, me, now);
|
|
635
679
|
let prevMine = null;
|
|
636
680
|
if (addr.previous) { if (c.prevListing == null) return { error: "unread" }; prevMine = ownListing(c.prevListing, me, now); }
|
|
637
|
-
const
|
|
638
|
-
...(s.bond > 0n ? ["bond"] : []), ...(approved ? [] : ["approve"]), "accept"];
|
|
681
|
+
const br = bracket(c, [...(prevMine ? ["cancelOldPrev"] : []), ...(mine && !approved ? ["cancelOld"] : []), ...(s.bond > 0n && s.bondApprove ? ["bondApprove"] : []),
|
|
682
|
+
...(s.bond > 0n ? ["bond"] : []), ...(approved ? [] : ["approve"]), "accept"], { addr, leased, claimed });
|
|
683
|
+
if (br.error) return br;
|
|
639
684
|
const pr = b.any ? proof.map(lc) : [];
|
|
640
|
-
return { steps, price: big(b.price), maker: lc(b.maker), any: b.any === true, proof: pr, fee, share, net, bond: s.bond,
|
|
685
|
+
return { steps: br.steps, ...(br.leased ? { leased: true } : {}), price: big(b.price), maker: lc(b.maker), any: b.any === true, proof: pr, fee, share, net, bond: s.bond,
|
|
641
686
|
pins: { bidId: key, id: big(id), price: big(b.price), maker: lc(b.maker), minNet: net } };
|
|
642
687
|
}
|
|
643
688
|
|
|
@@ -648,8 +693,9 @@ const REGISTRY = new ethers.Interface(["function approve(address to, uint256 tok
|
|
|
648
693
|
const BOND_V2 = new ethers.Interface(["function deposit(uint256 agentId)"]);
|
|
649
694
|
const to_ = (a) => ethers.getAddress(a).toLowerCase();
|
|
650
695
|
/**
|
|
651
|
-
* One step's transaction: { to, data }. `o`: { addr (marketKindOf's), id, now (the block's
|
|
652
|
-
* and the plan's own: price, expiry, bond, pins, reserve, proof, net, root, count, uriHash,
|
|
696
|
+
* One step's transaction: { to, data }. `o`: { addr (marketKindOf's; its `lease` for the claims), id, now (the block's
|
|
697
|
+
* time, for the bids' terms), and the plan's own: price, expiry, bond, pins, reserve, proof, net, root, count, uriHash,
|
|
698
|
+
* minRepaid, minLine }. "claimBefore" and "claimAfter" are the seam's handoverCalls: claim(id) on the lease.
|
|
653
699
|
*/
|
|
654
700
|
export function stepCalls(step, o) {
|
|
655
701
|
const a = o.addr, id = o.id == null ? null : big(o.id);
|
|
@@ -667,6 +713,7 @@ export function stepCalls(step, o) {
|
|
|
667
713
|
if (step === "bidAny") return bidAnyCall({ market: a.market, root: o.root, count: o.count, price: o.price, expiry: o.expiry, now: o.now, minRepaid: o.minRepaid, minLine: o.minLine });
|
|
668
714
|
if (step.startsWith("cancelBid:")) return cancelBidCall({ market: a.market, bidId: step.slice("cancelBid:".length) });
|
|
669
715
|
if (step === "accept") return acceptCall({ market: a.market, bidId: o.pins.bidId, id, proof: o.proof || [], minNet: o.pins.minNet });
|
|
716
|
+
if (step === "claimBefore" || step === "claimAfter") { const h = handoverCalls({ lease: a.lease, id, leased: true }); return (step === "claimBefore" ? h.before : h.after)[0]; }
|
|
670
717
|
throw new Error(`no such step: ${step}`);
|
|
671
718
|
}
|
|
672
719
|
/** What a step's receipt must hold from the market: the event, by name, the final step of each tool ends with. */
|
|
@@ -678,7 +725,8 @@ export const STEP_EVENTS = Object.freeze({ list: "Listed", cancel: "Cancelled",
|
|
|
678
725
|
* Every error a step can revert with, by signature, and its kind: AgentMarket's and AgentMarketV2's (src/AgentMarket.sol
|
|
679
726
|
* 123-151, src/AgentMarketV2.sol 151-190, the builder share's of the P5 spec 2.8), the pause's (src/GuardianPause.sol
|
|
680
727
|
* 27-32), BidSpender's (src/BidSpender.sol 22), USDG's two as deployed, the registry's approve from a wallet that doesn't
|
|
681
|
-
* hold the agent,
|
|
728
|
+
* hold the agent, InviteBondV2's deposit's, and AgentLease's claim's (src/AgentLease.sol: its payout's PayOutOfGas is
|
|
729
|
+
* the builder share's selector). The board's ERR set (web/board-wallet-core.js) and the bids' (web/
|
|
682
730
|
* board-wallet-bids-core.js), one table. "failed": nothing a plan checks; the step's own words.
|
|
683
731
|
*/
|
|
684
732
|
export const MARKET_ERRORS = Object.freeze({
|
|
@@ -705,6 +753,8 @@ export const MARKET_ERRORS = Object.freeze({
|
|
|
705
753
|
// USDG as deployed, the registry, InviteBondV2's deposit
|
|
706
754
|
"InsufficientAllowance()": "allowance", "InsufficientFunds()": "short", "ERC721InvalidApprover(address)": "notOwner", "ERC721NonexistentToken(uint256)": "cantSell",
|
|
707
755
|
"NotOwner(uint256)": "notOwner", "AgentDefaulted(uint256)": "defaulted", "LoanOpen(uint256)": "loan", "NotTreasuryLine(uint256)": "line", "AlreadyBonded(uint256)": "failed",
|
|
756
|
+
// AgentLease's claim around a change of hands: never paused, it waits while the registry doesn't answer
|
|
757
|
+
"RegistryFailed(uint256)": "registry",
|
|
708
758
|
});
|
|
709
759
|
const SELECTORS = new Map(Object.entries(MARKET_ERRORS).map(([sig, kind]) => [ethers.id(sig).slice(0, 10), { sig, kind }]));
|
|
710
760
|
/**
|
|
@@ -797,6 +847,9 @@ export const PLAN_WORDS = Object.freeze({
|
|
|
797
847
|
// the hub
|
|
798
848
|
hubDown: "Priors' hub at {hub} didn't answer, so {what} can't be read. Try again later.",
|
|
799
849
|
noSet: "Priors' hub has no list for {origin} now. Bid on one agent instead.",
|
|
850
|
+
// the lease's claims around a change of hands (AgentLease, where the package records it)
|
|
851
|
+
unknownLease: "The lease at {lease} doesn't answer as the lease of the market this server knows. Update @priors/mcp.",
|
|
852
|
+
registry: LEASE_WORDS.errors.registry,
|
|
800
853
|
});
|
|
801
854
|
/** A bid's and an accept's refusals: market-bids' BID_WORDS.errors as they are, but "over" (this server's own limit),
|
|
802
855
|
* the two that name Go mode's buttons, which this server doesn't have, "notInBid", said here without the list's day
|