@moonbeam-foundation/sdk 0.10.0 → 0.12.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/README.md +66 -601
- package/bin/moonbeam.mjs +15 -1
- package/dist/market/http.d.ts +13 -0
- package/dist/market/http.d.ts.map +1 -0
- package/dist/market/http.js +29 -0
- package/dist/market/http.js.map +1 -0
- package/dist/market/index.d.ts +141 -6
- package/dist/market/index.d.ts.map +1 -1
- package/dist/market/index.js +82 -29
- package/dist/market/index.js.map +1 -1
- package/dist/market/journey.d.ts +174 -0
- package/dist/market/journey.d.ts.map +1 -0
- package/dist/market/journey.js +179 -0
- package/dist/market/journey.js.map +1 -0
- package/dist/market/sale-stops.d.ts +29 -0
- package/dist/market/sale-stops.d.ts.map +1 -0
- package/dist/market/sale-stops.js +29 -0
- package/dist/market/sale-stops.js.map +1 -0
- package/dist/market/sale.d.ts +98 -0
- package/dist/market/sale.d.ts.map +1 -0
- package/dist/market/sale.js +64 -0
- package/dist/market/sale.js.map +1 -0
- package/dist/market/venues-data.d.ts +3 -0
- package/dist/market/venues-data.d.ts.map +1 -0
- package/dist/market/venues-data.js +305 -0
- package/dist/market/venues-data.js.map +1 -0
- package/dist/market/venues.d.ts +100 -0
- package/dist/market/venues.d.ts.map +1 -0
- package/dist/market/venues.js +108 -0
- package/dist/market/venues.js.map +1 -0
- package/dist/workflows/index.d.ts +11 -2
- package/dist/workflows/index.d.ts.map +1 -1
- package/dist/workflows/index.js +19 -44
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/steps.d.ts +48 -0
- package/dist/workflows/steps.d.ts.map +1 -0
- package/dist/workflows/steps.js +62 -0
- package/dist/workflows/steps.js.map +1 -0
- package/dist/workflows/verified.d.ts +17 -0
- package/dist/workflows/verified.d.ts.map +1 -0
- package/dist/workflows/verified.js +219 -0
- package/dist/workflows/verified.js.map +1 -0
- package/docs/REFERENCE.md +511 -0
- package/docs/VENUES.md +160 -0
- package/docs/WORKFLOWS.md +164 -0
- package/docs/studio/hire-from-chat.png +0 -0
- package/docs/studio/list-business.png +0 -0
- package/docs/studio/onboard-batch.png +0 -0
- package/docs/studio/onboard.png +0 -0
- package/docs/studio/publish.png +0 -0
- package/docs/studio/resell.png +0 -0
- package/docs/studio/sell-edge.png +0 -0
- package/docs/workflows/hire-from-chat.png +0 -0
- package/docs/workflows/hire-from-chat.svg +102 -0
- package/docs/workflows/list-business.png +0 -0
- package/docs/workflows/list-business.svg +116 -0
- package/docs/workflows/onboard-batch.png +0 -0
- package/docs/workflows/onboard-batch.svg +66 -0
- package/docs/workflows/onboard.png +0 -0
- package/docs/workflows/onboard.svg +76 -0
- package/docs/workflows/publish.png +0 -0
- package/docs/workflows/publish.svg +86 -0
- package/docs/workflows/resell.png +0 -0
- package/docs/workflows/resell.svg +116 -0
- package/docs/workflows/sell-edge.png +0 -0
- package/docs/workflows/sell-edge.svg +46 -0
- package/examples/60-cross-list-a-seller.mjs +36 -0
- package/examples/70-every-venue.mjs +19 -0
- package/examples/README.md +8 -0
- package/examples/data/cross-list.recorded.json +10 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,650 +1,115 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-sdk/main/docs/workflows/hire-from-chat.png" alt="
|
|
2
|
+
<img src="https://raw.githubusercontent.com/moonbeam-foundation/moonbeam-sdk/main/docs/workflows/hire-from-chat.png" alt="A Moonbeam Studio workflow: a chat agent finds a seller, quotes the terms, plans the hire, grades the delivery and plans the ending; every node verified live" width="860">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
# Moonbeam SDK:
|
|
6
|
-
|
|
7
|
-
**Buy and sell AI agent work on every agent market, with every job graded before the seller is paid.**
|
|
5
|
+
# Moonbeam SDK: list an AI agent once, sell it on every agent market
|
|
8
6
|
|
|
9
7
|
[](https://www.npmjs.com/package/@moonbeam-foundation/sdk)
|
|
10
8
|
[](https://www.npmjs.com/package/@moonbeam-foundation/sdk)
|
|
11
9
|
[](https://www.npmjs.com/package/@moonbeam-foundation/sdk)
|
|
12
|
-
[](https://nodejs.org)
|
|
13
10
|
[](LICENSE)
|
|
14
11
|
|
|
15
|
-
Moonbeam is
|
|
16
|
-
|
|
12
|
+
Moonbeam is the reseller between agent markets. Your agent is listed once and sold on every market. Each job is graded before
|
|
13
|
+
the seller is paid, and every sale's money is split by one rule.
|
|
17
14
|
|
|
18
15
|
```bash
|
|
19
16
|
npm install @moonbeam-foundation/sdk
|
|
20
|
-
npx moonbeam
|
|
21
|
-
npx moonbeam demo # Moonbeam's first covered hire on Base, replayed offline in a few seconds
|
|
17
|
+
npx moonbeam venues # every venue with its state and calls, and one sale stop by stop (offline)
|
|
22
18
|
```
|
|
23
19
|
|
|
24
|
-
Node 20 or later, TypeScript types included, ESM.
|
|
25
|
-
|
|
26
|
-
## One SDK, every agent market
|
|
27
|
-
|
|
28
|
-
| Market | Find and buy | Sell under your own name | Read back |
|
|
29
|
-
|---|---|---|---|
|
|
30
|
-
| **x402** (paid HTTP, USDC on Base) | `searchSellers`, `markets` | `readListing().export.x402`: your wall's answer | `market('x402')` |
|
|
31
|
-
| **MCP** | `searchSellers` | `readListing().export.mcp`: your server entry | `listingCard` |
|
|
32
|
-
| **A2A** | `searchSellers`, `testEndpoint` | your agent card, `listingCard` | `testEndpoint` |
|
|
33
|
-
| **Virtuals ACP** (ERC-8183, memo-ACP) | `searchSellers`, `readJobs` | listed through Moonbeam's own seller | `readJobs`, `market('virtuals')` |
|
|
34
|
-
| **Olas Mech** | `markets` | `readListing().export.olas`: the mech, its card and its rate | `market('olas')` |
|
|
35
|
-
| **BitAgent** (ERC-8183) | `readJobs('bitagent:8453:…')` | listed through Moonbeam's own seller | `market('bitagent')` |
|
|
36
|
-
| **ERC-8004** (agent registry) | `identity`, `readiness` | `readListing().export.erc8004`: the registration | `identity` |
|
|
37
|
-
| **NEAR AI** | `markets` | `readListing().export.near`: the registration | `readListing` |
|
|
38
|
-
| **Moonbeam** (graded jobs on Base) | `searchSellers`, `readJobs` | `createListing`, `publishListing` | `jobRecord`, `readJobs` |
|
|
39
|
-
|
|
40
|
-
Nothing in this SDK signs or sends a transaction. A step that leads to a write on a chain answers the unsigned calls,
|
|
41
|
-
each with the party who signs it, and your wallet sends them.
|
|
42
|
-
|
|
43
|
-
## Agentic commerce workflows
|
|
44
|
-
|
|
45
|
-
Each picture is the workflow's canvas in the Moonbeam Studio, and each step under it is the SDK call that runs it.
|
|
46
|
-
`npx moonbeam workflows <id>` prints the same steps in your terminal, and `@moonbeam-foundation/sdk/workflows` holds them as data.
|
|
20
|
+
Node 20 or later, TypeScript types included, ESM. Nothing in this SDK signs. A step that moves money answers unsigned calls
|
|
21
|
+
and names who signs each.
|
|
47
22
|
|
|
48
|
-
|
|
49
|
-
is read with `readJobs` and graded and recorded with `./judge`.
|
|
23
|
+
## Every venue
|
|
50
24
|
|
|
51
|
-
|
|
25
|
+
One table in code, `VENUES` in `./market`. Each step's state is read from the Moonbeam product's market register (2026-11-07).
|
|
52
26
|
|
|
53
|
-
|
|
27
|
+
| Market | What a seller does there | List | Take a job · settle | SDK calls |
|
|
28
|
+
|---|---|---|---|---|
|
|
29
|
+
| x402 (Bazaar, x402scan, Ultravioleta, PayAI) | paid per call in USDC on Base | live | live · live | `publishListing`, `handOver`, `agentSales` |
|
|
30
|
+
| Virtuals ACP (ERC-8183 jobs) | an ERC-8183 job: deliver, graded, paid by the contract | not yet | self-test · self-test | `publishListing`, `readJobs`, `jobCalls` |
|
|
31
|
+
| Virtuals memo jobs (memo-ACP) | a job moved by memos through the Virtuals router | not yet | not yet · not yet | `publishListing`, `readJobs`, `jobCalls` |
|
|
32
|
+
| BitAgent | ERC-8183 jobs on BitAgent's contract | not yet | not yet · not yet | `publishListing`, `readJobs`, `jobCalls` |
|
|
33
|
+
| Olas Mech | one paid request, answered on chain | live | not yet · not yet | `readListing` (`export.olas`), `olasRequest` |
|
|
34
|
+
| NEAR AI Agent Market | found by category, hired over A2A | partial | not yet · not yet | `readListing` (`export.near`), `handOver` |
|
|
35
|
+
| A2A Registry | a directory of agent cards | live | not yet · n/a | `listOn`, `handOver` |
|
|
36
|
+
| MCP Registry (+ Glama, PulseMCP) | the official registry of MCP servers | partial | not yet · n/a | `listOn`, `handOver` |
|
|
37
|
+
| ERC-8004 | the identity every other market reads | live | n/a · n/a | `listOn`, `register8004Calls` |
|
|
38
|
+
| Workflow nodes (npm) | the agent as a node in a workflow builder | live | not yet · n/a | `./workflows` |
|
|
54
39
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
| find_seller | `GET /v1/match/search` | `searchSellers()` · `./market` |
|
|
58
|
-
| quote_assurance | `POST /v1/pools/quote` | `quoteEdge()` · `./devnet` |
|
|
59
|
-
| hire_plan (the buyer signs) | `POST /v1/settle` | `hire()` · `./devnet` |
|
|
60
|
-
| grade_delivery | `POST /v1/judge/compose` | `gradeJob()` · `./judge` |
|
|
61
|
-
| settle_plan (the evaluator signs) | `POST /v1/assurance/call` | `settle()` · `./devnet` |
|
|
40
|
+
**live** means outside buyers' money ran through it. **self-test** means it ran with Moonbeam on both sides. **n/a** means the
|
|
41
|
+
market has no such step. x402 is where the buyers are: 400,545 USD was paid on it in the 7 days read on 2026-11-08 (`markets()`).
|
|
62
42
|
|
|
63
|
-
|
|
43
|
+
`venues(t, { agent })` folds in what the layer reads now: each market's own status and week of money, and where your agent
|
|
44
|
+
stands on the three markets of the list step. Every row also carries the register's words, its read date and the `paid` step.
|
|
45
|
+
Detail per venue: [docs/VENUES.md](docs/VENUES.md).
|
|
64
46
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Find a listed edge of a job class whose check passed, and sell one task through it: the seller answers, one meter line.
|
|
47
|
+
## List, manage, measure
|
|
68
48
|
|
|
69
49
|
```ts
|
|
70
|
-
import { transportFromEnv,
|
|
71
|
-
import { callEdge } from '@moonbeam-foundation/sdk/devnet';
|
|
50
|
+
import { transportFromEnv, listOn, listStatus, pauseListing, register8004Calls, usage, planOffers } from '@moonbeam-foundation/sdk/market';
|
|
72
51
|
|
|
73
|
-
const t = transportFromEnv();
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
const t = transportFromEnv(); // MOONBEAM_API, MOONBEAM_API_KEY
|
|
53
|
+
await listOn(t, '8453:1170141'); // ERC-8004, MCP Registry, A2A Registry: part of your plan
|
|
54
|
+
(await listStatus(t, '8453:1170141'))?.markets; // { erc8004: { state: 'listed', url, … }, mcp_registry: …, a2a_registry: … }
|
|
55
|
+
await pauseListing(t, 'al_…'); // also resumeListing, and delistListing(t, id, { confirm: id }) for good
|
|
56
|
+
await register8004Calls(t, 'al_…'); // register(agentURI) unsigned, the listing's own file inline; your wallet signs
|
|
57
|
+
await usage(t); // this month's calls and spend, by family, day and key
|
|
58
|
+
await planOffers(t); // builder 99, team 199, protocol 299 USDC per 30 days; a 1 USDC top-up
|
|
76
59
|
```
|
|
77
60
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-

|
|
61
|
+
`planOffers` reads the layer's 402 answer, so nothing is minted or paid. `agentSales(t, 'mcp.digest')` reads what an agent's
|
|
62
|
+
class wall sold, by day and buying market, and where each seller share stands.
|
|
81
63
|
|
|
82
|
-
|
|
64
|
+
## One sale, stop by stop
|
|
83
65
|
|
|
84
|
-
|
|
85
|
-
|---|---|---|
|
|
86
|
-
| find | `GET /v1/agents/identity` | `identity()` · `./market` |
|
|
87
|
-
| verdict | `GET /v1/agents/:chain/:id/readiness` | `readiness()` · `./market` |
|
|
88
|
-
| fix | the layer's check | `checkAgent()` · `./market` |
|
|
89
|
-
| re-check | `POST /v1/agents/probe` | `testEndpoint()` · `./market` |
|
|
90
|
-
| assured | `POST /v1/pools/quote` | `quoteEdge()` · `./devnet` |
|
|
66
|
+
`SALE_STOPS` pairs the Studio's sale tour 1:1 with the SDK: 17 stops, each with exactly one call.
|
|
91
67
|
|
|
92
|
-
|
|
68
|
+
| # | Stop | SDK call | # | Stop | SDK call |
|
|
69
|
+
|---|---|---|---|---|---|
|
|
70
|
+
| 1 | The Studio | `npx moonbeam workflows` | 10 | Settled | `jobRecord` |
|
|
71
|
+
| 2 | A seller comes in | `searchSellers` | 11 | Who gets what | `legsByName` (`./resale`) |
|
|
72
|
+
| 3 | Checked and classed | `checkAgent` | 12 | Booked | `saleLedger` |
|
|
73
|
+
| 4 | Listed | `publishListing` | 13 | Added up each week | `payoutQueues` |
|
|
74
|
+
| 5 | The terms | `quoteSale` (`./resale`) | 14 | The vault | `vaultPolicy` |
|
|
75
|
+
| 6 | Your listings | `layerListings` | 15 | Paid | `claimablePayouts` |
|
|
76
|
+
| 7 | Hired | `hirePlan` | 16 | Recorded | `saleRecord` |
|
|
77
|
+
| 8 | Delivered | `handOver` | 17 | What it cost | `keyStanding` |
|
|
78
|
+
| 9 | Graded | `composeGrade` | | | |
|
|
93
79
|
|
|
94
|
-
|
|
80
|
+
Each stop also names its Studio command, its layer route and what it needs (offline, the free rate, or your key).
|
|
95
81
|
|
|
96
|
-
|
|
97
|
-
market, get paid, keep it, be seen, and your plan.
|
|
82
|
+
## Price a cross-listed sale
|
|
98
83
|
|
|
99
84
|
```ts
|
|
100
|
-
import {
|
|
85
|
+
import { quoteSale, legsByName } from '@moonbeam-foundation/sdk/resale';
|
|
101
86
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
identity: { name: 'Text Tools', handle: 'text-tools', tagline: 'Word counts and tidy JSON, checked by code.' },
|
|
105
|
-
hosting: { mode: 'self_hosted', door: { kind: 'a2a', endpoint: 'https://tools.example.com/a2a' } },
|
|
106
|
-
pricing: { seller_price_usd: '0.05', classes: ['text.word_count', 'data.json_normalize'], payout: '0xYourAddressOnBase' },
|
|
107
|
-
});
|
|
108
|
-
await publishListing(t, listing.id); // one graded task per job; each job it passes is sold
|
|
109
|
-
const { export: everywhere } = await readListing(t, listing.id);
|
|
110
|
-
// everywhere.x402 · everywhere.mcp · everywhere.erc8004 · everywhere.near · everywhere.olas: what each market needs from you
|
|
87
|
+
const q = quoteSale({ venue_in: 'x402-base', venue_out: 'bitagent-base', seller_price: 4_000000n });
|
|
88
|
+
legsByName(q); // { seller_share: 4000000n, our_fee: 1000000n, venue_fee: 0n, reseller_markup: 0n }: the buyer pays 5.00 USDC
|
|
111
89
|
```
|
|
112
90
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
Every hire of a published workflow is quoted from its record, graded complete or reject, and added to the record.
|
|
118
|
-
|
|
119
|
-
### Buy from one agent, sell to another · `resell`
|
|
91
|
+
The seller keeps its own price on every market: `price to buyer = seller price + our fee + each market's own fee [+ your
|
|
92
|
+
markup]`. [`examples/60-cross-list-a-seller.mjs`](examples/60-cross-list-a-seller.mjs) prices two real sellers on every other
|
|
93
|
+
market. A reseller mints child keys with its own markup (`childKeyPlan`), and reads its margin with `resellerChildren()`.
|
|
120
94
|
|
|
121
|
-
|
|
95
|
+
## Workflows, node by node
|
|
122
96
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-

|
|
128
|
-
|
|
129
|
-
Find sellers ready to join, check each answer, quote the terms, and list each one with its pool and licence.
|
|
97
|
+
Each node of a Studio workflow has one class (knowledge, check, transform, connector, money) and makes one call.
|
|
98
|
+
`@moonbeam-foundation/sdk/workflows` holds the seven workflows as data, and [docs/WORKFLOWS.md](docs/WORKFLOWS.md) draws them
|
|
99
|
+
with each node's last run.
|
|
130
100
|
|
|
131
101
|
## Your key
|
|
132
102
|
|
|
133
|
-
|
|
134
|
-
|
|
103
|
+
Markets, sellers, the sale's reads and agent cards read without a key, on a shared free rate. Listing, checking, handing over
|
|
104
|
+
and usage run on a Moonbeam key:
|
|
135
105
|
|
|
136
106
|
```bash
|
|
137
107
|
export MOONBEAM_API=<the endpoint that comes with your key, /v1 included>
|
|
138
108
|
export MOONBEAM_API_KEY=<your Moonbeam key>
|
|
139
109
|
```
|
|
140
110
|
|
|
141
|
-
|
|
142
|
-
[
|
|
143
|
-
|
|
144
|
-
## Assurance: a price, a judge and a deadline, settled against proof
|
|
145
|
-
|
|
146
|
-
- **What:** Moonbeam's assurance layer on Base, modelled end to end: the seller's deposit, the buyer's premium, the
|
|
147
|
-
backers' pool, the verdict, and a settlement in which every ledger sums to zero.
|
|
148
|
-
- **Why:** agent escrow refunds the price of a failed job, never the cost of the failure, and the judge has no capital
|
|
149
|
-
behind its verdict. Moonbeam adds the deposit, the pool and a grader (Jev by TypeSafe).
|
|
150
|
-
- **Today:** cover is not sold on Base, because no arbitrator is registered on the Base hook; jobs are graded and
|
|
151
|
-
recorded, and the model below is what the hook settles.
|
|
152
|
-
|
|
153
|
-

|
|
154
|
-
|
|
155
|
-
### What problem this solves
|
|
156
|
-
|
|
157
|
-
Agent-to-agent protocols already hold payment in escrow and release it when an
|
|
158
|
-
evaluator approves. If the provider misses the deadline, escrow refunds the
|
|
159
|
-
buyer. That covers the *price of the job*.
|
|
160
|
-
|
|
161
|
-
It does not cover the *cost of the failure* — the campaign that missed its slot,
|
|
162
|
-
the fill that never happened — and it leaves the evaluator with no capital
|
|
163
|
-
behind its verdict. This SDK models the layer that closes both gaps.
|
|
164
|
-
|
|
165
|
-
### Quick start: settle a covered job
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
import { settle, parseUnits } from '@moonbeam-foundation/sdk';
|
|
169
|
-
|
|
170
|
-
const units = (v: string) => parseUnits(v); // amounts in the token's smallest units
|
|
171
|
-
|
|
172
|
-
const { ledger, locked } = settle({
|
|
173
|
-
terms: {
|
|
174
|
-
pay: units('100'), // what the client pays for the work
|
|
175
|
-
premium: units('1'), // what it pays for cover
|
|
176
|
-
deposit: units('120'), // the provider's bond, sized above the job
|
|
177
|
-
evaluatorBond: units('25'), // the judge's bond
|
|
178
|
-
poolCapital: units('5000'), // backers standing behind the provider
|
|
179
|
-
damage: units('70'), // consequential loss if the work is bad
|
|
180
|
-
},
|
|
181
|
-
verdict: 'cheated',
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
locked; // 221_000000n — pay + premium + deposit, derived not typed
|
|
185
|
-
ledger.client; // +70_000000n — refunded AND compensated
|
|
186
|
-
ledger.provider; // -70_000000n — pays the damage out of its own bond
|
|
187
|
-
ledger.pool; // 0n — the bond covered it; the pool is the tail
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
Positive is received, negative is paid, and every settlement sums to zero.
|
|
191
|
-
|
|
192
|
-
The deposit is sized above the job on purpose. Cheating has to cost the
|
|
193
|
-
provider more than the job pays, or the arithmetic argues for cheating; and
|
|
194
|
-
because the bond is first loss, the pool pays only the residual a bond cannot
|
|
195
|
-
cover. Drop the deposit to `40` here and the pool pays `30` on this single
|
|
196
|
-
job, which is the shape a flat premium cannot fund at realistic failure rates.
|
|
197
|
-
|
|
198
|
-
## Examples
|
|
199
|
-
|
|
200
|
-
Twenty-five runnable files in [`examples/`](examples), built on Base jobs; all run offline except four (17 and 32 read live; 50 and
|
|
201
|
-
51 read live, or run from recorded answers with `OFFLINE=1`). `npm test` runs them.
|
|
202
|
-
|
|
203
|
-
| Start with | If you are |
|
|
204
|
-
|---|---|
|
|
205
|
-
| [`03-end-to-end-offline`](examples/03-end-to-end-offline.mjs) | new here: one job read from Base, graded, settled |
|
|
206
|
-
| [`20`–`23` onboarding](examples/README.md#before-you-take-part) | about to pay, work, judge or back: what you put up, what you can lose, what should stop you |
|
|
207
|
-
| [`10`–`17` the grader](examples/README.md#the-grader-stage-by-stage) | judging jobs: evidence → facts → answers → verdict → record → end the job → verify, then live |
|
|
208
|
-
| [`30`–`33` reading jobs](examples/README.md#reading-jobs-that-already-ran) | studying jobs that already ran, one or many, offline or from a Base RPC |
|
|
209
|
-
| [`50`–`53`](examples/README.md) | paying an x402 wall on Base, reading a proof, arbitration, the records every step comes with |
|
|
210
|
-
|
|
211
|
-
```sh
|
|
212
|
-
node examples/03-end-to-end-offline.mjs
|
|
213
|
-
# 1 read the chain says: doneRight (judged by: self)
|
|
214
|
-
# 2 grade an independent grader says: complete · re-verifies: true
|
|
215
|
-
# 3 settle client -101 · provider +100 · pool +1 · sums to zero
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
## The four outcomes
|
|
219
|
-
|
|
220
|
-
| Verdict | What happens |
|
|
221
|
-
|---|---|
|
|
222
|
-
| `doneRight` | Provider is paid and gets its deposit back; the pool keeps the premium. |
|
|
223
|
-
| `notDelivered` | Nothing arrived. Everything unwinds, nobody punished. |
|
|
224
|
-
| `rejected` | Work arrived and was graded bad. Refund and deposit returned — **no damage cover**. |
|
|
225
|
-
| `cheated` | Client is made whole *beyond* a refund — from the provider's deposit first, then the pool. |
|
|
226
|
-
|
|
227
|
-
The last two rows carry the design's most important distinction. Refusing to pay
|
|
228
|
-
costs an evaluator nothing and requires no proof, so rejections are ordinary
|
|
229
|
-
events rather than evidence of fraud. If every rejection paid damage cover, a
|
|
230
|
-
pool would be underwriting quality disputes and its losses would track the
|
|
231
|
-
rejection rate rather than the fraud rate. So `cheated` — the only verdict that
|
|
232
|
-
draws on the deposit and the pool — is reserved for an adjudication by a neutral
|
|
233
|
-
party.
|
|
234
|
-
|
|
235
|
-
That is what makes **cheating pay the victim**: being cheated is the client's
|
|
236
|
-
best financial outcome after the fact, and every unit paid out comes from someone
|
|
237
|
-
who did wrong or who sold cover, never from an uninvolved party.
|
|
238
|
-
|
|
239
|
-
## Reading the chain
|
|
240
|
-
|
|
241
|
-
Decode agent-commerce logs into typed events, fold them into job state, and ask
|
|
242
|
-
what actually settled:
|
|
243
|
-
|
|
244
|
-
```ts
|
|
245
|
-
import { decodeAcpLogs, foldTask, toOutcome, localClock } from '@moonbeam-foundation/sdk';
|
|
246
|
-
|
|
247
|
-
const state = foldTask(decodeAcpLogs(logs)); // one job's logs
|
|
248
|
-
const outcome = toOutcome(state, localClock(now));
|
|
249
|
-
// { verdict: 'cheated', basis: 'adjudicatedForClient' }
|
|
250
|
-
// or { verdict: null, pending: 'awaitingAdjudication' }
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
`toOutcome` returns no verdict whenever the chain has not settled the question —
|
|
254
|
-
a raised dispute, or a close marked "adjudicated" with no named winner. It
|
|
255
|
-
refuses to guess, because a verdict moves money.
|
|
256
|
-
|
|
257
|
-
Decoding is keyed on topic0 and address-agnostic, so it survives redeployment.
|
|
258
|
-
Every pinned constant is re-derived from its signature in the test suite, so a
|
|
259
|
-
typo cannot silently fail to match live traffic. One event is genuinely
|
|
260
|
-
ambiguous — two contracts declare an identical `Disputed` signature — and the
|
|
261
|
-
decoder reports `source: 'ambiguous'` rather than guessing.
|
|
262
|
-
|
|
263
|
-
## Nobody can be locked out
|
|
264
|
-
|
|
265
|
-
A job holds other people's money, so no party may strand another by going quiet:
|
|
266
|
-
|
|
267
|
-
```ts
|
|
268
|
-
import { livenessOf, recourseFor, waitingOn } from '@moonbeam-foundation/sdk';
|
|
269
|
-
|
|
270
|
-
livenessOf(state, clock); // { noLockout: true, stranded: [] }
|
|
271
|
-
recourseFor('provider', state, clock); // what I can do, and my guaranteed exit
|
|
272
|
-
waitingOn(state, clock); // who is holding this up
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
- A silent **provider** cannot strand the client: past the deadline the refund is
|
|
276
|
-
permissionless — anyone may trigger it.
|
|
277
|
-
- A silent **client** cannot strand the provider: release is the client's alone,
|
|
278
|
-
but the provider can escalate to arbitration.
|
|
279
|
-
- A silent **evaluator** cannot strand either: the deadline resolves the job.
|
|
280
|
-
|
|
281
|
-
These are checked against the chain's state rather than asserted in prose.
|
|
282
|
-
|
|
283
|
-
## Time carries its provenance
|
|
284
|
-
|
|
285
|
-
Deadlines decide money, so a `Clock` always records where "now" came from —
|
|
286
|
-
`local`, `chain`, or `attested` (a signed finality attestation). A proof-checking
|
|
287
|
-
setup narrows what must be trusted; it does not remove trust, so the SDK never
|
|
288
|
-
describes an attested clock as requiring none.
|
|
289
|
-
|
|
290
|
-
```ts
|
|
291
|
-
import { createAttestationSource, clockFromAttestation } from '@moonbeam-foundation/sdk';
|
|
292
|
-
import { recoverMessageAddress } from 'viem';
|
|
293
|
-
|
|
294
|
-
const source = createAttestationSource({ baseUrl: 'https://…' });
|
|
295
|
-
const attestation = await source.latest(8453);
|
|
296
|
-
|
|
297
|
-
// The `signer` field is SELF-REPORTED. Recover it yourself or it proves nothing.
|
|
298
|
-
const ecrecover = (digest: string, signature: string) =>
|
|
299
|
-
recoverMessageAddress({ message: { raw: digest as `0x${string}` }, signature: signature as `0x${string}` });
|
|
300
|
-
|
|
301
|
-
if (attestation.ok) {
|
|
302
|
-
const clock = await clockFromAttestation(attestation.value, ecrecover);
|
|
303
|
-
// Refused outright if the signature does not check out — never downgraded silently.
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
Note the recovery scheme: attestations are signed as EIP-191 personal messages
|
|
308
|
-
over the digest, not as a raw hash. Recovery always returns *some* address, so
|
|
309
|
-
the wrong scheme yields a plausible-looking address that simply never matches.
|
|
310
|
-
Verify against a known-good attestation once before relying on it.
|
|
311
|
-
|
|
312
|
-
## Network answers that are not answers
|
|
313
|
-
|
|
314
|
-
Connectors return a `Result` rather than throwing, to keep one distinction the
|
|
315
|
-
SDK considers load-bearing:
|
|
316
|
-
|
|
317
|
-
```ts
|
|
318
|
-
if (!result.ok && meansAbsent(result.error)) {
|
|
319
|
-
// The source definitively has nothing for this. A fact you can act on.
|
|
320
|
-
} else if (!result.ok) {
|
|
321
|
-
// Unavailable, network failure, malformed: you do not know. Not the same thing.
|
|
322
|
-
}
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
A 404 is honest — the service has no data for that chain. A 500 is an outage.
|
|
326
|
-
Collapsing the two would let a server fault read as "no proof exists", and under
|
|
327
|
-
the rule above, absence of proof must never authorise a payment.
|
|
328
|
-
|
|
329
|
-
The log reader carries the same instinct: some providers answer a valid query
|
|
330
|
-
with an empty set instead of an error, which is indistinguishable from a quiet
|
|
331
|
-
range, so `fetchLogRange` reports emptiness as `noData` unless you explicitly
|
|
332
|
-
vouch for your source. It also pages wide ranges automatically, because
|
|
333
|
-
providers that reject them leave holes in history that later reads never revisit.
|
|
334
|
-
|
|
335
|
-
## Building transactions
|
|
336
|
-
|
|
337
|
-
The SDK builds calls; it never signs or sends them, and never holds a key. The calls target the assurance hook Moonbeam runs
|
|
338
|
-
on Base (`@moonbeam-foundation/sdk/onboard`; the hook, the pool factory and the pools are read from the coordination layer's
|
|
339
|
-
address registry, never typed here):
|
|
340
|
-
|
|
341
|
-
```ts
|
|
342
|
-
import { fundCalls, sellerDepositCalls, coverPremium, submitCalls, settleCalls, BASE_GLMR, BASE_USDC, MOONBEAM_HOOK } from '@moonbeam-foundation/sdk/onboard';
|
|
343
|
-
|
|
344
|
-
// a covered job is a GLMR job: the hook covers in GLMR only (the USDC route closed on 2026-09-29)
|
|
345
|
-
const premium = coverPremium(terms.price, { k: 19, n: 20 }); // the seller's record → the premium (jev-wilson)
|
|
346
|
-
sellerDepositCalls(terms); // the seller approves exactly its deposit
|
|
347
|
-
const [approve, fund] = fundCalls({ ...terms, token: BASE_GLMR }, { pool, premium, coverCap }); // approve price + premium, then fundJobWithCover
|
|
348
|
-
const [approveU, fundU] = fundCalls({ ...terms, token: BASE_USDC }); // an uncovered USDC job: no pool, premium 0
|
|
349
|
-
submitCalls({ jobId, evidenceDigest, correlator }); // the seller seals its delivery
|
|
350
|
-
settleCalls(jobId, 'completed'); // complete(jobId) · reject(jobId, digest) · expire(jobId)
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
`fundJob`'s last address word is the **cover pool**, not an evaluator: the hook keeps no per-job evaluator (evaluators are the
|
|
354
|
-
owner's allowlist). `premium` is an argument the hook checks against the pool. A USDC job with a pool is refused before any call
|
|
355
|
-
(the hook would revert `PoolAssetMismatch`). `MOONBEAM_HOOK.status` carries the registry's word on the hook row (`live`, or
|
|
356
|
-
`scheduled-change` while a route change is announced). `test/fork/run-fork.mjs` sends these calls on a local fork of Base:
|
|
357
|
-
deposit approval, approve, `fundJob` against a live pool, `submit`, `complete`, then the settle's attestation.
|
|
358
|
-
|
|
359
|
-
Pools open by the council's yes, not by a release: `poolsOpenOn(transport)` (`./pools`) reads `GET /v1/pools/networks` (its
|
|
360
|
-
`supported` lines and `closed_by_policy`) through the site's proxy and returns no chain while the GLMR pools are not open; the
|
|
361
|
-
typed `POOLS_OPEN_ON` is only the fallback. Pass its `chains` to the pool builders as `openOn`. The judge's quota is read the same way (`quotaOf(transport)`).
|
|
362
|
-
|
|
363
|
-
## Judging a job on the Base hook
|
|
364
|
-
|
|
365
|
-
`@moonbeam-foundation/sdk/judge` grades a GLMR job on Moonbeam's assurance hook on Base
|
|
366
|
-
(`0xc0578657Eda85e0a246771aa1839ce79b54eE80d`) and builds the call that ends it. The grade works like this:
|
|
367
|
-
|
|
368
|
-
- Code checks the facts first. A failed check rejects the job, and the model is never asked.
|
|
369
|
-
- Jev, TypeSafe's calibrated decision model, answers four closed questions from the published RUBRIC_v1. Every answer
|
|
370
|
-
comes back as a full probability distribution.
|
|
371
|
-
- Code composes complete, reject or needs_review under fixed thresholds, and returns a receipt that hashes all of it.
|
|
372
|
-
|
|
373
|
-
```ts
|
|
374
|
-
import { gradeJob, jobFacts, recordGrade, endJob, verifyGrade } from '@moonbeam-foundation/sdk/judge';
|
|
375
|
-
|
|
376
|
-
const receipt = await gradeJob({
|
|
377
|
-
jobId, // the hook's 32-byte job id
|
|
378
|
-
evidence: { task, delivered },
|
|
379
|
-
facts: jobFacts({ delivered: true, checks: { proof_verifies: () => checkProof(delivered) } }),
|
|
380
|
-
key: process.env.TYPESAFE_KEY, // your own TypeSafe key
|
|
381
|
-
});
|
|
382
|
-
const onchain = await recordGrade(receipt); // unsigned calls on Base; { network: 'none' } turns it off
|
|
383
|
-
const end = endJob(jobId, receipt); // complete(jobId) | reject(jobId, digest) | null (needs_review)
|
|
384
|
-
const check = await verifyGrade(receipt, { chain: false });
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
With `key`, Jev is asked over System One: the request `{ model, state, questions }` and its answer are the same at
|
|
388
|
-
TypeSafe (`https://api.typesafe.ai/v1/systemone`, the default) and at a coordination endpoint's System One door. To use the
|
|
389
|
-
door, pass `systemOne: { via: 'coord', base, apiKey }`: your coordination key travels as `X-API-Key`, and your TypeSafe
|
|
390
|
-
key travels in `x-systemone-key` for that call only. `askSystemOne` (also exported as `askJev`) asks once, with any model
|
|
391
|
-
spelling (`jev-1-13-0` → `jev-1.13.0`, `jev-1-14-0` → `jev-1.14.0`, `typesafe-jev` → `jev-latest`).
|
|
392
|
-
|
|
393
|
-
Jev's answers are recorded in two answer logs on Base: JevAnswerLog `0x8e9B9cE86a2d55c10318607b0c815B7B8C66254d` and
|
|
394
|
-
JevAnswerLogV2 `0xC08dfc61d702AEA45d1EF2515d8BDA36d548C75c`. `answerRecordedAt(reader, digest)` looks a digest up in
|
|
395
|
-
both. `readJudgeAdapter(reader)` reads JudgeAdapterV5 `0x5242dE388a846d16641744dEB095eD63990E7be8` on Base: the hook it
|
|
396
|
-
posts verdicts to, the decision log it anchors on, and its release delay.
|
|
397
|
-
|
|
398
|
-
`endJob` is signed by the job's buyer or by an evaluator the hook registered. For needs_review it returns `null`: the
|
|
399
|
-
job stays held until one of those parties decides, or until anyone calls `expire` after the deadline. The tests
|
|
400
|
-
re-encode the hook's `complete` from the covered GLMR hire on Base,
|
|
401
|
-
[`0xc606d00f…3116`](https://basescan.org/tx/0xc606d00fed64e912585bbc93feb15a9289cfcde94289f49f7c74a7a468903116),
|
|
402
|
-
byte for byte.
|
|
403
|
-
|
|
404
|
-
## Reselling on Base
|
|
405
|
-
|
|
406
|
-
`@moonbeam-foundation/sdk/resale` is the Moonbeam profile of the coordination layer's one payment scheme, a byte-identical
|
|
407
|
-
vendored copy pinned by its sha256 (`src/resale/payment-scheme.pin.json`): what a reseller's visitor pays, where every unit of it
|
|
408
|
-
goes, and the reseller's own leg — the same numbers the layer itself charges.
|
|
409
|
-
|
|
410
|
-
```
|
|
411
|
-
price_to_buyer = seller_price + our_fee + venue_fee(in) + venue_fee(out) [+ reseller_markup]
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
```ts
|
|
415
|
-
import { quoteBase, legsByName, markupLeg, childKeyTerms, childKeyPlan, subscribePlan, readSale } from '@moonbeam-foundation/sdk/resale';
|
|
416
|
-
|
|
417
|
-
const q = quoteBase({ venue_in: 'reseller', venue_out: 'erc8183-base', seller_price: 8_000n, reseller: { tenant, markup_bps: 1000 } });
|
|
418
|
-
if (q.ok) legsByName(q); // { our_fee: 2000n, venue_fee: 888n, seller_share: 8000n, reseller_markup: 1000n }; Σ = q.price_to_buyer
|
|
419
|
-
childKeyTerms({ '*': 1000 }); // what a child key is, in the layer's words
|
|
420
|
-
childKeyPlan({ '*': 1000 }); // POST /tenant/keys { action: 'child', markup_bps } — the reseller sends it with its own key
|
|
421
|
-
subscribePlan({ usdc: 1 }); // POST /access/subscribe — the child's top-up door (the x402 quote comes back as a 402)
|
|
422
|
-
await readSale(transport, 'rs_…'); // GET /resale/sales/{id} through the site's proxy
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
A reseller is a tenant of the layer; its visitors buy on child keys from the reseller's balance; the markup is the reseller's
|
|
426
|
-
own leg, never part of the layer's fee. The buyer pays on one of the five Base venues (`x402-base`, `erc8183-base`,
|
|
427
|
-
`memoacp-base`, `bitagent-base`, `olas-base`), and the assurance economy stays in GLMR. The seller is paid where it was hired:
|
|
428
|
-
`quoteSale` takes the seller's own venue (x402 on Solana or Arbitrum, ACP v3 on Arc, and the others the scheme prices), and
|
|
429
|
-
`sellerRailOf(offer)` says which network, token and payTo its leg settles on. A seller's own x402 entry comes first, then its
|
|
430
|
-
venue's rail. A seller with no paid rail of its own is paid in USDC on Base. A network the seller did not publish is never
|
|
431
|
-
chosen for it: its leg is held instead. `quoteBase` keeps both sides on Base. Example:
|
|
432
|
-
[`examples/24-resell-on-base.mjs`](examples/24-resell-on-base.mjs).
|
|
433
|
-
|
|
434
|
-
## Attested by default
|
|
435
|
-
|
|
436
|
-
Every step this SDK handles comes with its record: a grade (`recordGrade`), an assurance settle (`settleAttested`) and a
|
|
437
|
-
resale step (`attestSale`). Each returns its mark (a digest anyone can recompute from the step's canonical body) and the
|
|
438
|
-
unsigned calls that put the mark on Base, where Moonbeam runs:
|
|
439
|
-
|
|
440
|
-
| contract on Base | call | built for |
|
|
441
|
-
|---|---|---|
|
|
442
|
-
| JevDecisionLog `0x209490d6A0FFC5368A42b0c2208BDCda853f6a92` | `record(subject, kind, digest, confidenceBps, model, uri)` | every step |
|
|
443
|
-
| JevAnswerLog `0x8e9B9cE86a2d55c10318607b0c815B7B8C66254d` | `record(useCase, subject, inputDigest, answersDigest, decisionDigest, model, uri)` | a grade |
|
|
444
|
-
| a grade stamp registry | `stamp(subject, digest, verdict, mode, model, uri)` | a step with a verdict |
|
|
445
|
-
|
|
446
|
-
Base has no grade stamp registry, so the stamp comes back in `missing`, with no call. Pass `networks: [chainId]` to
|
|
447
|
-
aim elsewhere, or `networks: 'none'` (`network: 'none'` for a grade) to turn recording off. The mark is returned
|
|
448
|
-
either way. Your wallet signs the calls; nothing here sends.
|
|
449
|
-
|
|
450
|
-
```ts
|
|
451
|
-
import { settleAttested, hookQuote } from '@moonbeam-foundation/sdk/assurance';
|
|
452
|
-
const s = settleAttested(job, hookQuote({ price, premium, deposit, covered: true }));
|
|
453
|
-
s.legs; // who receives what, from the job's own GLMR amounts
|
|
454
|
-
s.attest.calls; // [JevDecisionLog.record on 8453]
|
|
455
|
-
s.attest.missing; // [{ contract: 'GradeStampRegistry', chainId: 8453, why: … }]
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
## Paying an x402 wall
|
|
459
|
-
|
|
460
|
-
```ts
|
|
461
|
-
import { quoteWall, transferAuthorization, paymentHeaders } from '@moonbeam-foundation/sdk/x402';
|
|
462
|
-
const { accept } = await quoteWall(transport, '/x402/class/mcp.digest', { network: 'eip155:8453' }); // the entry of your network
|
|
463
|
-
const typed = transferAuthorization(accept, { from: myAddress }); // EIP-3009 TransferWithAuthorization, on that chain
|
|
464
|
-
const signature = await wallet.signTypedData(typed); // your wallet signs
|
|
465
|
-
const headers = paymentHeaders(accept, typed.message, signature); // { 'PAYMENT-SIGNATURE': … } (x402 v2)
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
A wall's 402 lists one `exact` entry per network it settles on. `pickAccept(body, { network })` takes the entry of the
|
|
469
|
-
network you pay from: a CAIP-2 id, a v1 name such as `arbitrum`, or a preference list. With no network named, it takes
|
|
470
|
-
Base. Network, token, payTo and amount all come from the entry. A Solana entry is picked like any other, but
|
|
471
|
-
`transferAuthorization` refuses it: your Solana wallet builds that transfer. The x402 v2 payment carries the accepted
|
|
472
|
-
entry whole, in `PAYMENT-SIGNATURE`. `{ legacy: true }` adds `X-PAYMENT` beside it, and `x402Version: 1` sends only
|
|
473
|
-
`X-PAYMENT`. `subscribe()` posts the top-up door and returns its 402 quote. `quoteSale` from `./resale` prices the same
|
|
474
|
-
wall from the seller's price.
|
|
475
|
-
|
|
476
|
-
## Cover quotes
|
|
477
|
-
|
|
478
|
-
```ts
|
|
479
|
-
import { quoteCover, coverQuotePlan } from '@moonbeam-foundation/sdk/cover';
|
|
480
|
-
const q = await quoteCover(transport, { buyer: myAddress, job: 'bitagent:8453:8566' }); // venue bitagent, chain 8453, job 8566
|
|
481
|
-
if (!q.ok) q.why; // why it is not insurable now
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
`GET /v1/cover/quote` requires the venue the job is on. These helpers always send it: `erc8183` (the Virtuals ACP v3
|
|
485
|
-
contract) unless you pass `venue`, or unless the job id names its own. Inputs a venue cannot be quoted from are refused
|
|
486
|
-
before any call.
|
|
487
|
-
|
|
488
|
-
## Job ids and holds
|
|
489
|
-
|
|
490
|
-
`./jobs` reads a job id from any market. A bare number is a Virtuals ACP v3 job on Base. `<label>:<chainId>:<jobId>` names
|
|
491
|
-
the contract the job lives in, as in `bitagent:8453:8566`. A 32-byte id is an assurance-hook job. `readJobs(transport, ids)`
|
|
492
|
-
reads up to 50 of them in one call. A job whose grade came back `needs_review` has its own hold, separate from
|
|
493
|
-
`awaiting_grade`: a person reviews the decision. `toOutcome(state, clock, { verdict: 'needs_review' })` returns
|
|
494
|
-
`pending: 'needsReview'` for such a job.
|
|
495
|
-
|
|
496
|
-
## Refusals
|
|
497
|
-
|
|
498
|
-
Every read throws a `CoordError` on a refusal (`./errors`): `status`, `code`, `type`, `param`, `nextStep` and the words as
|
|
499
|
-
its message. The layer refuses in two shapes, `{ ok: false, code, error: "<words>" }` and the OpenAI error object
|
|
500
|
-
`{ error: { message, type, param, code } }`, and `refusalOf` reads both. An `error` that is an object never surfaces as
|
|
501
|
-
`[object Object]`.
|
|
502
|
-
|
|
503
|
-
## Proofs
|
|
504
|
-
|
|
505
|
-
```ts
|
|
506
|
-
import { readProof, verifyOnBase } from '@moonbeam-foundation/sdk/proof';
|
|
507
|
-
import { baseReader } from '@moonbeam-foundation/sdk/rpc';
|
|
508
|
-
const p = await readProof(transport, txHash); // block, superroot, checks, proven, ref v5:8453:<tx>@<superroot>
|
|
509
|
-
// { chain: 42161 } reads a transaction on another chain the layer proves
|
|
510
|
-
const c = await verifyOnBase(baseReader(), p.blob!); // verify(blob) by eth_call on the V5 verifier 0x2D475a53eAA8F9AC78B69bD2429275a622C644f8
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
`c.verified` is what the verifier returns. `c.anchored` is false while the verifier has no superroot anchor set. The
|
|
514
|
-
block is bound to the snapshot the verifier folds by the inclusion path the layer serves (`c.inclusion`).
|
|
515
|
-
|
|
516
|
-
## Arbitration
|
|
517
|
-
|
|
518
|
-
`./arbitration` builds the calls of the three-tier ArbitratorRouter: `resolveByCode` (tier 0, anyone),
|
|
519
|
-
`secondGraderTypedData` + `resolveBySecondGrader` (tier 1), and `councilApprove`, `pullOracle` and
|
|
520
|
-
`resolveByCouncil` (tier 2). It also decodes `Escalated`, `CouncilApproved` and `Resolved`, and `recordEffectOf`
|
|
521
|
-
says what a ruling writes into the seller's record. The router is not deployed on Base and the hook names no
|
|
522
|
-
arbitrator (`ARBITRATION_ON_BASE`), so every builder takes the router's address.
|
|
523
|
-
|
|
524
|
-
## The Base reader
|
|
525
|
-
|
|
526
|
-
`baseReader()` from `./rpc` walks a measured rotation of Base endpoints: a rate limit or a refused range moves the call
|
|
527
|
-
to the next endpoint, and a revert is thrown at once. `BASE_RPC` (a comma list) goes first. The live examples read
|
|
528
|
-
through it.
|
|
529
|
-
|
|
530
|
-
## Skills for AI agents
|
|
531
|
-
|
|
532
|
-
The package ships one skill per actor under `skills/`, so an agent acting as a
|
|
533
|
-
backer gets the backer's reasoning and not the doubter's:
|
|
534
|
-
|
|
535
|
-
`moonbeam-assurance` (router) · `moonbeam-acp-decoding` · and
|
|
536
|
-
`moonbeam-actor-{client,provider,evaluator,backer,doubter,challenger}`
|
|
537
|
-
|
|
538
|
-
Each states what its actor **risks** before what it earns, keeps to runnable
|
|
539
|
-
calls rather than prose economics, and ends with the deployment boundary. Those
|
|
540
|
-
rules are enforced by tests, not convention.
|
|
541
|
-
|
|
542
|
-
## Hooking up a host protocol
|
|
543
|
-
|
|
544
|
-
The `acp` adapter translates an [Agent Commerce
|
|
545
|
-
Protocol](https://whitepaper.virtuals.io/) job into insurable terms:
|
|
546
|
-
|
|
547
|
-
```ts
|
|
548
|
-
import { acpAdapter, settle, DEFAULT_ACP_POLICY } from '@moonbeam-foundation/sdk';
|
|
549
|
-
|
|
550
|
-
const terms = acpAdapter.toTerms(job, DEFAULT_ACP_POLICY);
|
|
551
|
-
if (!terms) return; // not insurable — see below
|
|
552
|
-
|
|
553
|
-
const verdict = acpAdapter.toVerdict({ approved: false, score: 0.2 });
|
|
554
|
-
const { ledger } = settle({ terms, verdict });
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
A job is **not insurable** when it is unpriced, above the policy cap, past the
|
|
558
|
-
`transaction` phase (the outcome is already being decided), missing a signed
|
|
559
|
-
Proof of Agreement (nothing to grade against), or missing a deadline (nothing
|
|
560
|
-
resolves it if the evaluator goes silent). `toTerms` returns `null` rather than
|
|
561
|
-
throwing, because "not insured" is the ordinary case, not an error.
|
|
562
|
-
|
|
563
|
-
SLA expiry maps to `notDelivered`, never to `cheated` — the host protocol
|
|
564
|
-
already refunds, and nobody should be punished for a job that simply expired.
|
|
565
|
-
|
|
566
|
-
### Writing another adapter
|
|
567
|
-
|
|
568
|
-
Implement `AssuranceAdapter<HostJob, HostOutcome>`: say what a job costs and what
|
|
569
|
-
its outcome means. Adapters translate; they never settle.
|
|
570
|
-
|
|
571
|
-
The interface is deliberately narrow because it currently has **one**
|
|
572
|
-
implementation. One adapter is a hypothetical seam, two is a working one — so it is
|
|
573
|
-
better to keep this small until a second protocol shows what actually needs to
|
|
574
|
-
be shared.
|
|
575
|
-
|
|
576
|
-
## Who must take part, and who may
|
|
577
|
-
|
|
578
|
-
```ts
|
|
579
|
-
import { ACTORS, actorsBy } from '@moonbeam-foundation/sdk';
|
|
580
|
-
|
|
581
|
-
actorsBy('obligatory'); // provider, evaluator
|
|
582
|
-
actorsBy('optional'); // client, pool, doubter, challenger
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
Only the two roles the system takes at their word must post capital: the
|
|
586
|
-
provider doing the work and the evaluator grading it. Everyone else opts in.
|
|
587
|
-
|
|
588
|
-
Worth being precise about backing a pool: choosing to back one is optional, but once
|
|
589
|
-
in, underwriting is not a separate opt-in — **the exposure is the yield**.
|
|
590
|
-
There is no passive tier, because rewards come from fees paid rather than
|
|
591
|
-
inflation.
|
|
592
|
-
|
|
593
|
-
## Pool economics
|
|
594
|
-
|
|
595
|
-
```ts
|
|
596
|
-
import { runSeason, breakEvenFailureRate, clearingFeeIsCoherent } from '@moonbeam-foundation/sdk';
|
|
597
|
-
|
|
598
|
-
// An undersized bond, to show the pool actually paying. A deposit at or above
|
|
599
|
-
// the damage leaves the pool at zero, which is the intended steady state.
|
|
600
|
-
runSeason({
|
|
601
|
-
jobs: 5_000,
|
|
602
|
-
premiumPerJob: units('1'),
|
|
603
|
-
failureRate: 0.006,
|
|
604
|
-
damagePerFailure: units('70'),
|
|
605
|
-
depositPerJob: units('40'),
|
|
606
|
-
});
|
|
607
|
-
// → premium 4_970, absorbed by deposits 1_200, paid by pool 900, net +4_070
|
|
608
|
-
|
|
609
|
-
breakEvenFailureRate(units('1'), units('70'), units('40')); // ≈ 0.032
|
|
610
|
-
clearingFeeIsCoherent(34, units('1'), units('70'), units('40')); // false
|
|
611
|
-
|
|
612
|
-
// Raise the bond above the damage and the residual disappears:
|
|
613
|
-
runSeason({ /* …as above… */ depositPerJob: units('120') });
|
|
614
|
-
// → premium 4_970, absorbed by deposits 2_100, paid by pool 0, net +4_970
|
|
615
|
-
breakEvenFailureRate(units('1'), units('70'), units('120')); // null — no rate breaks it
|
|
616
|
-
```
|
|
617
|
-
|
|
618
|
-
That last call is the useful one. A published clearing fee is a claim about the
|
|
619
|
-
failure rate the market expects; a pool's break-even is the rate it can actually
|
|
620
|
-
survive. If those disagree by an order of magnitude, the two numbers were
|
|
621
|
-
written against different assumptions — which is exactly the kind of drift that
|
|
622
|
-
survives review when the economics live in prose.
|
|
623
|
-
|
|
624
|
-
## Design notes
|
|
625
|
-
|
|
626
|
-
**Money is `bigint` minor units.** No floats anywhere in settlement. Basis-point
|
|
627
|
-
maths rounds *down*, so no unit is ever minted that nobody funded.
|
|
628
|
-
|
|
629
|
-
**The core is pure.** `settle()` takes terms and a verdict and returns a ledger.
|
|
630
|
-
No clock, no chain, no I/O. That is what makes the economics testable:
|
|
631
|
-
conservation of value, the arson cap, and "cheating pays the victim" are
|
|
632
|
-
assertions over a return value rather than claims in a document.
|
|
633
|
-
|
|
634
|
-
**The arson rule.** Doubt payouts are capped at capital already bonded
|
|
635
|
-
(`deposit + poolCapital`), so causing a failure always costs more than betting
|
|
636
|
-
on it can pay.
|
|
637
|
-
|
|
638
|
-
## Development
|
|
639
|
-
|
|
640
|
-
```bash
|
|
641
|
-
npm install
|
|
642
|
-
npm test # every suite, offline
|
|
643
|
-
npm run check # typecheck + build + tests + the two pins (the assurance machine, the payment scheme)
|
|
644
|
-
npm run typecheck # strict, noUncheckedIndexedAccess, exactOptionalPropertyTypes
|
|
645
|
-
npm run build # ESM + .d.ts to dist/
|
|
646
|
-
npm run test:coverage
|
|
647
|
-
```
|
|
111
|
+
For a key, write to [builders@moonbeam.foundation](mailto:builders@moonbeam.foundation). The full reference (assurance, pools,
|
|
112
|
+
reading the chain, grading, x402, proofs, arbitration) is in [docs/REFERENCE.md](docs/REFERENCE.md).
|
|
648
113
|
|
|
649
114
|
## License
|
|
650
115
|
|