@moonbeam-foundation/sdk 0.5.2

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.
Files changed (186) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +378 -0
  3. package/bin/moonbeam.mjs +56 -0
  4. package/dist/acp/coverage.d.ts +36 -0
  5. package/dist/acp/coverage.d.ts.map +1 -0
  6. package/dist/acp/coverage.js +51 -0
  7. package/dist/acp/coverage.js.map +1 -0
  8. package/dist/acp/events.d.ts +201 -0
  9. package/dist/acp/events.d.ts.map +1 -0
  10. package/dist/acp/events.js +201 -0
  11. package/dist/acp/events.js.map +1 -0
  12. package/dist/acp/hex.d.ts +29 -0
  13. package/dist/acp/hex.d.ts.map +1 -0
  14. package/dist/acp/hex.js +51 -0
  15. package/dist/acp/hex.js.map +1 -0
  16. package/dist/acp/lifecycle-types.d.ts +11 -0
  17. package/dist/acp/lifecycle-types.d.ts.map +1 -0
  18. package/dist/acp/lifecycle-types.js +8 -0
  19. package/dist/acp/lifecycle-types.js.map +1 -0
  20. package/dist/acp/lifecycle.d.ts +78 -0
  21. package/dist/acp/lifecycle.d.ts.map +1 -0
  22. package/dist/acp/lifecycle.js +224 -0
  23. package/dist/acp/lifecycle.js.map +1 -0
  24. package/dist/acp/outcome.d.ts +45 -0
  25. package/dist/acp/outcome.d.ts.map +1 -0
  26. package/dist/acp/outcome.js +104 -0
  27. package/dist/acp/outcome.js.map +1 -0
  28. package/dist/acp/pipeline.d.ts +30 -0
  29. package/dist/acp/pipeline.d.ts.map +1 -0
  30. package/dist/acp/pipeline.js +25 -0
  31. package/dist/acp/pipeline.js.map +1 -0
  32. package/dist/acp/recourse.d.ts +74 -0
  33. package/dist/acp/recourse.d.ts.map +1 -0
  34. package/dist/acp/recourse.js +234 -0
  35. package/dist/acp/recourse.js.map +1 -0
  36. package/dist/acp/registry.d.ts +62 -0
  37. package/dist/acp/registry.d.ts.map +1 -0
  38. package/dist/acp/registry.js +86 -0
  39. package/dist/acp/registry.js.map +1 -0
  40. package/dist/acp/transitions.d.ts +82 -0
  41. package/dist/acp/transitions.d.ts.map +1 -0
  42. package/dist/acp/transitions.js +106 -0
  43. package/dist/acp/transitions.js.map +1 -0
  44. package/dist/actors/index.d.ts +84 -0
  45. package/dist/actors/index.d.ts.map +1 -0
  46. package/dist/actors/index.js +133 -0
  47. package/dist/actors/index.js.map +1 -0
  48. package/dist/actors/track-record.d.ts +79 -0
  49. package/dist/actors/track-record.d.ts.map +1 -0
  50. package/dist/actors/track-record.js +105 -0
  51. package/dist/actors/track-record.js.map +1 -0
  52. package/dist/adapters/acp.d.ts +48 -0
  53. package/dist/adapters/acp.d.ts.map +1 -0
  54. package/dist/adapters/acp.js +74 -0
  55. package/dist/adapters/acp.js.map +1 -0
  56. package/dist/adapters/port.d.ts +53 -0
  57. package/dist/adapters/port.d.ts.map +1 -0
  58. package/dist/adapters/port.js +2 -0
  59. package/dist/adapters/port.js.map +1 -0
  60. package/dist/adapters/stamp.d.ts +57 -0
  61. package/dist/adapters/stamp.d.ts.map +1 -0
  62. package/dist/adapters/stamp.js +114 -0
  63. package/dist/adapters/stamp.js.map +1 -0
  64. package/dist/client/index.d.ts +123 -0
  65. package/dist/client/index.d.ts.map +1 -0
  66. package/dist/client/index.js +78 -0
  67. package/dist/client/index.js.map +1 -0
  68. package/dist/connect/attestation.d.ts +64 -0
  69. package/dist/connect/attestation.d.ts.map +1 -0
  70. package/dist/connect/attestation.js +62 -0
  71. package/dist/connect/attestation.js.map +1 -0
  72. package/dist/connect/http.d.ts +36 -0
  73. package/dist/connect/http.d.ts.map +1 -0
  74. package/dist/connect/http.js +51 -0
  75. package/dist/connect/http.js.map +1 -0
  76. package/dist/connect/logs.d.ts +53 -0
  77. package/dist/connect/logs.d.ts.map +1 -0
  78. package/dist/connect/logs.js +42 -0
  79. package/dist/connect/logs.js.map +1 -0
  80. package/dist/connect/result.d.ts +49 -0
  81. package/dist/connect/result.d.ts.map +1 -0
  82. package/dist/connect/result.js +41 -0
  83. package/dist/connect/result.js.map +1 -0
  84. package/dist/core/actors.d.ts +13 -0
  85. package/dist/core/actors.d.ts.map +1 -0
  86. package/dist/core/actors.js +57 -0
  87. package/dist/core/actors.js.map +1 -0
  88. package/dist/core/clock.d.ts +55 -0
  89. package/dist/core/clock.d.ts.map +1 -0
  90. package/dist/core/clock.js +36 -0
  91. package/dist/core/clock.js.map +1 -0
  92. package/dist/core/money.d.ts +32 -0
  93. package/dist/core/money.d.ts.map +1 -0
  94. package/dist/core/money.js +57 -0
  95. package/dist/core/money.js.map +1 -0
  96. package/dist/core/pool.d.ts +71 -0
  97. package/dist/core/pool.d.ts.map +1 -0
  98. package/dist/core/pool.js +98 -0
  99. package/dist/core/pool.js.map +1 -0
  100. package/dist/core/settle.d.ts +50 -0
  101. package/dist/core/settle.d.ts.map +1 -0
  102. package/dist/core/settle.js +175 -0
  103. package/dist/core/settle.js.map +1 -0
  104. package/dist/core/types.d.ts +109 -0
  105. package/dist/core/types.d.ts.map +1 -0
  106. package/dist/core/types.js +6 -0
  107. package/dist/core/types.js.map +1 -0
  108. package/dist/erc8004/index.d.ts +94 -0
  109. package/dist/erc8004/index.d.ts.map +1 -0
  110. package/dist/erc8004/index.js +118 -0
  111. package/dist/erc8004/index.js.map +1 -0
  112. package/dist/erc8004/registry.generated.d.ts +17 -0
  113. package/dist/erc8004/registry.generated.d.ts.map +1 -0
  114. package/dist/erc8004/registry.generated.js +20 -0
  115. package/dist/erc8004/registry.generated.js.map +1 -0
  116. package/dist/erc8183/index.d.ts +114 -0
  117. package/dist/erc8183/index.d.ts.map +1 -0
  118. package/dist/erc8183/index.js +109 -0
  119. package/dist/erc8183/index.js.map +1 -0
  120. package/dist/index.d.ts +81 -0
  121. package/dist/index.d.ts.map +1 -0
  122. package/dist/index.js +73 -0
  123. package/dist/index.js.map +1 -0
  124. package/dist/judge/index.d.ts +64 -0
  125. package/dist/judge/index.d.ts.map +1 -0
  126. package/dist/judge/index.js +64 -0
  127. package/dist/judge/index.js.map +1 -0
  128. package/dist/launcher/index.d.ts +109 -0
  129. package/dist/launcher/index.d.ts.map +1 -0
  130. package/dist/launcher/index.js +144 -0
  131. package/dist/launcher/index.js.map +1 -0
  132. package/dist/negotiate/index.d.ts +166 -0
  133. package/dist/negotiate/index.d.ts.map +1 -0
  134. package/dist/negotiate/index.js +150 -0
  135. package/dist/negotiate/index.js.map +1 -0
  136. package/dist/onboard/index.d.ts +533 -0
  137. package/dist/onboard/index.d.ts.map +1 -0
  138. package/dist/onboard/index.js +509 -0
  139. package/dist/onboard/index.js.map +1 -0
  140. package/dist/onboarding/index.d.ts +177 -0
  141. package/dist/onboarding/index.d.ts.map +1 -0
  142. package/dist/onboarding/index.js +390 -0
  143. package/dist/onboarding/index.js.map +1 -0
  144. package/dist/pools/index.d.ts +191 -0
  145. package/dist/pools/index.d.ts.map +1 -0
  146. package/dist/pools/index.js +244 -0
  147. package/dist/pools/index.js.map +1 -0
  148. package/docs/demo.gif +0 -0
  149. package/docs/demo.tape +14 -0
  150. package/examples/01-settle-a-covered-job.mjs +18 -0
  151. package/examples/02-negotiate-a-hire.mjs +21 -0
  152. package/examples/03-end-to-end-offline.mjs +27 -0
  153. package/examples/10-grade-evidence.mjs +12 -0
  154. package/examples/11-grade-facts.mjs +10 -0
  155. package/examples/12-grade-answers.mjs +8 -0
  156. package/examples/13-grade-verdict.mjs +10 -0
  157. package/examples/14-grade-record.mjs +11 -0
  158. package/examples/15-grade-end-the-job.mjs +11 -0
  159. package/examples/16-grade-verify.mjs +9 -0
  160. package/examples/17-grade-live.mjs +14 -0
  161. package/examples/20-onboard-client.mjs +8 -0
  162. package/examples/21-onboard-provider.mjs +9 -0
  163. package/examples/22-onboard-evaluator.mjs +7 -0
  164. package/examples/23-onboard-backer.mjs +8 -0
  165. package/examples/30-read-a-real-job.mjs +19 -0
  166. package/examples/31-read-the-ending.mjs +15 -0
  167. package/examples/32-read-live-from-base.mjs +33 -0
  168. package/examples/33-read-many-jobs.mjs +12 -0
  169. package/examples/40-the-article.mjs +78 -0
  170. package/examples/README.md +93 -0
  171. package/examples/data/answers.mjs +8 -0
  172. package/examples/data/base-grade.recorded.json +72 -0
  173. package/examples/data/pilot-grade.recorded.json +78 -0
  174. package/examples/data/pilot-hire.json +35 -0
  175. package/examples/data/terms.mjs +11 -0
  176. package/examples/data/virtuals-job-74926.json +74 -0
  177. package/examples/data/virtuals-job-rejected.json +74 -0
  178. package/package.json +124 -0
  179. package/skills/moonbeam-acp-decoding/SKILL.md +80 -0
  180. package/skills/moonbeam-actor-backer/SKILL.md +81 -0
  181. package/skills/moonbeam-actor-challenger/SKILL.md +62 -0
  182. package/skills/moonbeam-actor-client/SKILL.md +67 -0
  183. package/skills/moonbeam-actor-doubter/SKILL.md +55 -0
  184. package/skills/moonbeam-actor-evaluator/SKILL.md +67 -0
  185. package/skills/moonbeam-actor-provider/SKILL.md +63 -0
  186. package/skills/moonbeam-assurance/SKILL.md +58 -0
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Pools — the GLMR cover pool as a backer sees it: exact to 18 decimals.
3
+ *
4
+ * Every function here is pure and takes what the pool contract reports (total assets, total shares,
5
+ * a backer's shares, free assets) as plain bigints. Nothing reads a chain, nothing rounds in the
6
+ * backer's favour: shares = floor(deposit × S ÷ A) and assets = floor(shares × A ÷ S), the ERC-4626
7
+ * rule, so any fraction below the last decimal stays in the pool. The deposit card's four block
8
+ * reasons, the cap, the minimum and the withdraw preview live here so the page cannot drift from
9
+ * the SDK, and the two calls a wallet signs (approve, deposit / redeem) are built here byte for byte.
10
+ */
11
+ import { isAddress, isHex32 } from '../onboard/index.js';
12
+ import type { Address, UnsignedCall } from '../onboard/index.js';
13
+ export declare const D18: bigint;
14
+ export declare const GLMR_DECIMALS = 18;
15
+ export declare const USDC_DECIMALS = 6;
16
+ /** 50,000 GLMR per pool while the pools are new. A rule of this surface, not of the pool contract. */
17
+ export declare const POOL_CAP: bigint;
18
+ /** The smallest deposit the card accepts. */
19
+ export declare const MIN_DEPOSIT: bigint;
20
+ /** The dispute window a withdrawal waits out when the pool holds the exit, in seconds. */
21
+ /** The layer's default challenge window (V2 holds cover only until each job ends; the window is recorded, not enforced). */
22
+ export declare const DISPUTE_WINDOW_S = 3600;
23
+ /** The premium is a share of each job's price; 100 % of it goes to shares. */
24
+ export declare const PREMIUM_TO_SHARES_BPS = 10000;
25
+ /** Base GLMR: the immutable token the site already knows (18 decimals). */
26
+ export declare const BASE_GLMR: "0xB3846fD356c2149ee8D30b0449088Dc74e265459";
27
+ export declare const BASE_CHAIN_ID: 8453;
28
+ export declare const DEVNET_CHAIN_ID: 36927;
29
+ /** "1,234.5" → 1234500000000000000000n at 18 decimals. Anything that is not a decimal number is 0n; extra decimals are cut, never rounded. */
30
+ export declare function parseU(str: string, decimals?: number): bigint;
31
+ /** 1234500000000000000000n → "1,234.500000" with `show` decimals (cut, never rounded). */
32
+ export declare function formatU(v: bigint, decimals?: number, show?: number): string;
33
+ /** n ÷ d as a percentage string with `show` decimals; "0.00%" on an empty denominator. */
34
+ export declare function pct(n: bigint, d: bigint, show?: number): string;
35
+ export interface PoolState {
36
+ /** the pool's GLMR, from totalAssets() */
37
+ totalAssets: bigint;
38
+ /** shares in issue, from totalSupply() */
39
+ totalShares: bigint;
40
+ }
41
+ /** Shares for a deposit: floor(deposit × S ÷ A); one share per GLMR while the pool is empty. */
42
+ export declare function sharesFor(deposit: bigint, p: PoolState): bigint;
43
+ /** GLMR for shares: floor(shares × A ÷ S). */
44
+ export declare function assetsFor(shares: bigint, p: PoolState): bigint;
45
+ /** GLMR per share at 18 decimals: 1.000000 while nothing has been paid in or out. */
46
+ export declare function sharePrice(p: PoolState): bigint;
47
+ /** What still fits under the cap. */
48
+ export declare function roomUnderCap(totalAssets: bigint, cap?: bigint): bigint;
49
+ /** The premium a backer gets of one job's premium: floor(premium × mine ÷ S). */
50
+ export declare function premiumShare(premium: bigint, myShares: bigint, totalShares: bigint): bigint;
51
+ export type BlockCode = 'FULL' | 'EMPTY' | 'BELOW_MIN' | 'OVER_BALANCE' | 'OVER_CAP';
52
+ export interface Block {
53
+ code: BlockCode;
54
+ label: string;
55
+ danger: boolean;
56
+ }
57
+ /** Why the deposit button is blocked, in the design's words, or null when it may go. Checked in the order the card shows them. */
58
+ export declare function depositBlock(a: {
59
+ amount: bigint;
60
+ balance: bigint;
61
+ totalAssets: bigint;
62
+ cap?: bigint;
63
+ min?: bigint;
64
+ }): Block | null;
65
+ export interface DepositPreview {
66
+ shares: bigint;
67
+ price: bigint;
68
+ /** the pool after this deposit */
69
+ after: PoolState;
70
+ mineAfter: bigint;
71
+ /** basis points of the pool, before and after */
72
+ shareBefore: bigint;
73
+ shareAfter: bigint;
74
+ valueBefore: bigint;
75
+ valueAfter: bigint;
76
+ block: Block | null;
77
+ }
78
+ /** The whole card in one fold: exact shares, the share of the pool before and after, and the reason the button is blocked. */
79
+ export declare function depositPreview(a: {
80
+ amount: bigint;
81
+ balance: bigint;
82
+ pool: PoolState;
83
+ myShares: bigint;
84
+ cap?: bigint;
85
+ min?: bigint;
86
+ }): DepositPreview;
87
+ /** The largest deposit the card allows: min(balance, room under the cap). */
88
+ export declare function maxDeposit(balance: bigint, totalAssets: bigint, cap?: bigint): bigint;
89
+ export declare const WITHDRAW_STEPS: readonly [25, 50, 75, 100];
90
+ export interface WithdrawPreview {
91
+ sharesIn: bigint;
92
+ /** GLMR for those shares at today's value */
93
+ assetsOut: bigint;
94
+ /** what the pool lets out right now: min(assetsOut, free assets, maxWithdraw) */
95
+ availableNow: bigint;
96
+ /** unix seconds when the GLMR arrives: now when nothing holds it, else the end of the window */
97
+ availableAt: number;
98
+ /** the window in seconds still to wait (0 when none) */
99
+ waitS: number;
100
+ /** premiums already earned, paid out now (USDC, 6 decimals) */
101
+ premiumsNow: bigint;
102
+ sharesLeft: bigint;
103
+ /** basis points of the pool, before and after */
104
+ shareBefore: bigint;
105
+ shareAfter: bigint;
106
+ block: Block | null;
107
+ }
108
+ /**
109
+ * A withdrawal of `percent` of the backer's shares. `holdUntil` is the pool's hold (0 when it has none), `freeAssets` what is not
110
+ * promised to an open job (undefined when the pool does not report it), `maxWithdraw` the pool's own limit for this backer.
111
+ */
112
+ export declare function withdrawPreview(a: {
113
+ percent: number;
114
+ myShares: bigint;
115
+ pool: PoolState;
116
+ premiumsClaimable?: bigint;
117
+ now: number;
118
+ holdUntil?: number;
119
+ freeAssets?: bigint;
120
+ maxWithdraw?: bigint;
121
+ windowS?: number;
122
+ }): WithdrawPreview;
123
+ export interface Rule {
124
+ n: string;
125
+ title: string;
126
+ formula: string;
127
+ body: string;
128
+ }
129
+ /** "How your share is worked out": three plain rules using this pool as it stands. `typicalPrice` and `premiumBps` come from the record; null when it has none. */
130
+ export declare function rulesFor(a: {
131
+ pool: PoolState;
132
+ myShares: bigint;
133
+ typicalPriceUsdc: bigint | null;
134
+ premiumBps: number | null;
135
+ sellerDepositX: string;
136
+ }): Rule[];
137
+ export type GraderMode = 'judged' | 'declared';
138
+ /** How a pool's jobs are judged, in the design's words. The grader role is an address the hook accepts; Jev is one such grader. */
139
+ export declare const GRADER_MODES: Readonly<Record<GraderMode, {
140
+ tag: string;
141
+ title: string;
142
+ body: string;
143
+ }>>;
144
+ export declare const GRADER_ROLE = "The grader is a role, not a name: an address or adapter the hook accepts as evaluator. Jev is the calibrated grader this surface integrates; a deterministic check, or another grader, may hold the same seat.";
145
+ export declare const POOL_SIGNATURES: Readonly<{
146
+ readonly approve: "approve(address,uint256)";
147
+ readonly deposit: "deposit(uint256,address)";
148
+ readonly redeem: "redeem(uint256,address,address)";
149
+ readonly withdraw: "withdraw(uint256,address,address)";
150
+ readonly createPool: "createPool(address,address,string,string)";
151
+ }>;
152
+ /** The pool factories this surface knows: one pool per (seller, asset), permissionless to open. */
153
+ export declare const POOL_FACTORY: Readonly<Record<number, Address>>;
154
+ /**
155
+ * Chains where the pool calls may be built. GLMR pools are not open, so Base mainnet is deliberately absent: a deposit,
156
+ * a redemption or a new pool can be built on the devnet only. The maths above (shares, previews, rules) works
157
+ * everywhere. Add 8453 here, and to nothing else, on the day pools open.
158
+ */
159
+ export declare const POOLS_OPEN_ON: readonly number[];
160
+ export declare class PoolsNotOpenError extends Error {
161
+ readonly chainId: number;
162
+ constructor(chainId: number);
163
+ }
164
+ /** The two calls a deposit takes, in order: an exact-amount approve to the pool, then deposit(assets, receiver). Never a standing allowance. */
165
+ export declare function depositCalls(a: {
166
+ chainId: number;
167
+ pool: Address;
168
+ asset: Address;
169
+ amount: bigint;
170
+ receiver: Address;
171
+ }): UnsignedCall[];
172
+ /** The one call a withdrawal takes: redeem(shares, receiver, owner). The pool pays today’s value of the shares, up to what nothing holds. */
173
+ export declare function redeemCalls(a: {
174
+ chainId: number;
175
+ pool: Address;
176
+ shares: bigint;
177
+ owner: Address;
178
+ }): UnsignedCall[];
179
+ /**
180
+ * The one call that opens a pool: createPool(seller, asset, name, symbol) on the chain's factory. Anyone may
181
+ * send it; it costs gas and moves no money. Refused when the chain has no factory this surface knows.
182
+ */
183
+ export declare function createPoolCalls(a: {
184
+ chainId: number;
185
+ seller: Address;
186
+ asset: Address;
187
+ name: string;
188
+ symbol: string;
189
+ }): UnsignedCall[];
190
+ export { isAddress, isHex32 };
191
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAY,SAAS,EAAE,OAAO,EAAQ,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,OAAO,EAAO,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEtE,eAAO,MAAM,GAAG,QAAa,CAAC;AAC9B,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,sGAAsG;AACtG,eAAO,MAAM,QAAQ,QAAgB,CAAC;AACtC,6CAA6C;AAC7C,eAAO,MAAM,WAAW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AAK,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,EAAE,CAQrI;AAED,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Pools — the GLMR cover pool as a backer sees it: exact to 18 decimals.
3
+ *
4
+ * Every function here is pure and takes what the pool contract reports (total assets, total shares,
5
+ * a backer's shares, free assets) as plain bigints. Nothing reads a chain, nothing rounds in the
6
+ * backer's favour: shares = floor(deposit × S ÷ A) and assets = floor(shares × A ÷ S), the ERC-4626
7
+ * rule, so any fraction below the last decimal stays in the pool. The deposit card's four block
8
+ * reasons, the cap, the minimum and the withdraw preview live here so the page cannot drift from
9
+ * the SDK, and the two calls a wallet signs (approve, deposit / redeem) are built here byte for byte.
10
+ */
11
+ import { selector, isAddress, isHex32, utf8 } from '../onboard/index.js';
12
+ export const D18 = 10n ** 18n;
13
+ export const GLMR_DECIMALS = 18;
14
+ export const USDC_DECIMALS = 6;
15
+ /** 50,000 GLMR per pool while the pools are new. A rule of this surface, not of the pool contract. */
16
+ export const POOL_CAP = 50000n * D18;
17
+ /** The smallest deposit the card accepts. */
18
+ export const MIN_DEPOSIT = 10n * D18;
19
+ /** The dispute window a withdrawal waits out when the pool holds the exit, in seconds. */
20
+ /** The layer's default challenge window (V2 holds cover only until each job ends; the window is recorded, not enforced). */
21
+ export const DISPUTE_WINDOW_S = 3600;
22
+ /** The premium is a share of each job's price; 100 % of it goes to shares. */
23
+ export const PREMIUM_TO_SHARES_BPS = 10_000;
24
+ /** Base GLMR: the immutable token the site already knows (18 decimals). */
25
+ export const BASE_GLMR = '0xB3846fD356c2149ee8D30b0449088Dc74e265459';
26
+ export const BASE_CHAIN_ID = 8453;
27
+ export const DEVNET_CHAIN_ID = 36927;
28
+ // ── fixed-point strings ───────────────────────────────────────────────────────
29
+ /** "1,234.5" → 1234500000000000000000n at 18 decimals. Anything that is not a decimal number is 0n; extra decimals are cut, never rounded. */
30
+ export function parseU(str, decimals = GLMR_DECIMALS) {
31
+ const c = String(str).replace(/,/g, '').trim();
32
+ if (!c || c === '.' || !/^\d*\.?\d*$/.test(c))
33
+ return 0n;
34
+ const [w = '', f = ''] = c.split('.');
35
+ return BigInt(w || '0') * 10n ** BigInt(decimals) + BigInt((f + '0'.repeat(decimals)).slice(0, decimals) || '0');
36
+ }
37
+ const commas = (x) => x.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
38
+ /** 1234500000000000000000n → "1,234.500000" with `show` decimals (cut, never rounded). */
39
+ export function formatU(v, decimals = GLMR_DECIMALS, show = 6) {
40
+ const neg = v < 0n;
41
+ if (neg)
42
+ v = -v;
43
+ const base = 10n ** BigInt(decimals);
44
+ const frac = (v % base).toString().padStart(decimals, '0').slice(0, show);
45
+ return (neg ? '-' : '') + commas((v / base).toString()) + (show > 0 ? '.' + frac : '');
46
+ }
47
+ /** n ÷ d as a percentage string with `show` decimals; "0.00%" on an empty denominator. */
48
+ export function pct(n, d, show = 2) {
49
+ if (d === 0n)
50
+ return '0.' + '0'.repeat(show) + '%';
51
+ return formatU((n * 100n * 10n ** BigInt(show)) / d, show, show) + '%';
52
+ }
53
+ function assertState(p) {
54
+ if (p.totalAssets < 0n || p.totalShares < 0n)
55
+ throw new RangeError('pool totals must not be negative');
56
+ }
57
+ /** Shares for a deposit: floor(deposit × S ÷ A); one share per GLMR while the pool is empty. */
58
+ export function sharesFor(deposit, p) {
59
+ assertState(p);
60
+ if (deposit < 0n)
61
+ throw new RangeError('deposit must not be negative');
62
+ if (p.totalShares === 0n || p.totalAssets === 0n)
63
+ return deposit;
64
+ return (deposit * p.totalShares) / p.totalAssets;
65
+ }
66
+ /** GLMR for shares: floor(shares × A ÷ S). */
67
+ export function assetsFor(shares, p) {
68
+ assertState(p);
69
+ if (shares < 0n)
70
+ throw new RangeError('shares must not be negative');
71
+ if (p.totalShares === 0n)
72
+ return 0n;
73
+ return (shares * p.totalAssets) / p.totalShares;
74
+ }
75
+ /** GLMR per share at 18 decimals: 1.000000 while nothing has been paid in or out. */
76
+ export function sharePrice(p) {
77
+ assertState(p);
78
+ if (p.totalShares === 0n)
79
+ return D18;
80
+ return (p.totalAssets * D18) / p.totalShares;
81
+ }
82
+ /** What still fits under the cap. */
83
+ export function roomUnderCap(totalAssets, cap = POOL_CAP) {
84
+ return cap > totalAssets ? cap - totalAssets : 0n;
85
+ }
86
+ /** The premium a backer gets of one job's premium: floor(premium × mine ÷ S). */
87
+ export function premiumShare(premium, myShares, totalShares) {
88
+ if (totalShares === 0n)
89
+ return 0n;
90
+ return (premium * myShares) / totalShares;
91
+ }
92
+ /** Why the deposit button is blocked, in the design's words, or null when it may go. Checked in the order the card shows them. */
93
+ export function depositBlock(a) {
94
+ const cap = a.cap ?? POOL_CAP;
95
+ const min = a.min ?? MIN_DEPOSIT;
96
+ const room = roomUnderCap(a.totalAssets, cap);
97
+ if (room === 0n)
98
+ return { code: 'FULL', label: 'This pool is full', danger: false };
99
+ if (a.amount === 0n)
100
+ return { code: 'EMPTY', label: 'Enter an amount', danger: false };
101
+ if (a.amount < min)
102
+ return { code: 'BELOW_MIN', label: `Minimum deposit is ${formatU(min, GLMR_DECIMALS, 0)} GLMR`, danger: false };
103
+ if (a.amount > a.balance)
104
+ return { code: 'OVER_BALANCE', label: 'Not enough GLMR', danger: true };
105
+ if (a.amount > room)
106
+ return { code: 'OVER_CAP', label: `Only ${formatU(room, GLMR_DECIMALS, 2)} GLMR fits under the cap`, danger: true };
107
+ return null;
108
+ }
109
+ /** The whole card in one fold: exact shares, the share of the pool before and after, and the reason the button is blocked. */
110
+ export function depositPreview(a) {
111
+ const shares = sharesFor(a.amount, a.pool);
112
+ const after = { totalAssets: a.pool.totalAssets + a.amount, totalShares: a.pool.totalShares + shares };
113
+ const mineAfter = a.myShares + shares;
114
+ const bps = (n, d) => (d === 0n ? 0n : (n * 10000n) / d);
115
+ return {
116
+ shares, price: sharePrice(a.pool), after, mineAfter,
117
+ shareBefore: bps(a.myShares, a.pool.totalShares), shareAfter: bps(mineAfter, after.totalShares),
118
+ valueBefore: assetsFor(a.myShares, a.pool), valueAfter: assetsFor(mineAfter, after),
119
+ block: depositBlock({ amount: a.amount, balance: a.balance, totalAssets: a.pool.totalAssets, ...(a.cap !== undefined ? { cap: a.cap } : {}), ...(a.min !== undefined ? { min: a.min } : {}) }),
120
+ };
121
+ }
122
+ /** The largest deposit the card allows: min(balance, room under the cap). */
123
+ export function maxDeposit(balance, totalAssets, cap = POOL_CAP) {
124
+ const room = roomUnderCap(totalAssets, cap);
125
+ return balance < room ? balance : room;
126
+ }
127
+ // ── the withdraw card ─────────────────────────────────────────────────────────
128
+ export const WITHDRAW_STEPS = [25, 50, 75, 100];
129
+ /**
130
+ * A withdrawal of `percent` of the backer's shares. `holdUntil` is the pool's hold (0 when it has none), `freeAssets` what is not
131
+ * promised to an open job (undefined when the pool does not report it), `maxWithdraw` the pool's own limit for this backer.
132
+ */
133
+ export function withdrawPreview(a) {
134
+ if (!Number.isFinite(a.percent) || a.percent < 0 || a.percent > 100)
135
+ throw new RangeError('percent must be 0..100');
136
+ const sharesIn = (a.myShares * BigInt(Math.floor(a.percent))) / 100n;
137
+ const assetsOut = assetsFor(sharesIn, a.pool);
138
+ let availableNow = assetsOut;
139
+ if (a.freeAssets !== undefined && a.freeAssets < availableNow)
140
+ availableNow = a.freeAssets;
141
+ if (a.maxWithdraw !== undefined && a.maxWithdraw < availableNow)
142
+ availableNow = a.maxWithdraw;
143
+ const hold = a.holdUntil ?? 0;
144
+ const held = hold > a.now || availableNow < assetsOut;
145
+ const availableAt = hold > a.now ? hold : held ? a.now + (a.windowS ?? DISPUTE_WINDOW_S) : a.now;
146
+ const sharesLeft = a.myShares - sharesIn;
147
+ const afterShares = a.pool.totalShares - sharesIn;
148
+ const bps = (n, d) => (d === 0n ? 0n : (n * 10000n) / d);
149
+ const block = a.myShares === 0n ? { code: 'EMPTY', label: 'You have nothing in this pool', danger: false } : sharesIn === 0n ? { code: 'EMPTY', label: 'Pick how much to take out', danger: false } : null;
150
+ return { sharesIn, assetsOut, availableNow, availableAt, waitS: Math.max(0, availableAt - a.now), premiumsNow: a.premiumsClaimable ?? 0n, sharesLeft, shareBefore: bps(a.myShares, a.pool.totalShares), shareAfter: bps(sharesLeft, afterShares), block };
151
+ }
152
+ /** "How your share is worked out": three plain rules using this pool as it stands. `typicalPrice` and `premiumBps` come from the record; null when it has none. */
153
+ export function rulesFor(a) {
154
+ const price = sharePrice(a.pool);
155
+ const thousand = 1000n * D18;
156
+ const perJob = a.typicalPriceUsdc !== null && a.premiumBps !== null ? (a.typicalPriceUsdc * BigInt(a.premiumBps)) / 10000n : null;
157
+ const mine = perJob !== null ? premiumShare(perJob, a.myShares, a.pool.totalShares) : null;
158
+ return [
159
+ { n: '01', title: 'Your deposit becomes shares', formula: 'shares = deposit × S ÷ A', body: `At today’s price of ${formatU(price, 18, 6)} GLMR a share, 1,000 GLMR buys ${formatU(sharesFor(thousand, a.pool), 18, 6)} shares. Any fraction below the last decimal stays in the pool.` },
160
+ { n: '02', title: 'Premiums split by shares', formula: 'you get premium × your shares ÷ S', body: perJob !== null && a.typicalPriceUsdc !== null ? `A typical ${formatU(a.typicalPriceUsdc, 6, 2)} USDC job pays a ${formatU(perJob, 6, 4)} USDC premium. At ${pct(a.myShares, a.pool.totalShares, 2)} of the pool, ${formatU(mine ?? 0n, 6, 6)} USDC of it is yours.` : `No premium rate is priced from this record yet, so nothing in money can be worked out. At ${pct(a.myShares, a.pool.totalShares, 2)} of the pool, that share of every premium is yours.` },
161
+ { n: '03', title: 'Losses split the same way', formula: 'after the agent’s deposit', body: `Only a cheating finding reaches the pool, and only for what the agent’s own ${a.sellerDepositX} deposit doesn’t cover. That shortfall lowers the share price for everyone equally.` },
162
+ ];
163
+ }
164
+ /** How a pool's jobs are judged, in the design's words. The grader role is an address the hook accepts; Jev is one such grader. */
165
+ export const GRADER_MODES = Object.freeze({
166
+ judged: { tag: 'JEV GRADED', title: 'Graded by Jev', body: 'This agent sells judged work, so every job is graded by Jev over the sealed evidence. The grade decides whether the buyer is refunded from escrow. It can’t reach this pool: the pool only pays on a separate finding that the agent cheated.' },
167
+ declared: { tag: 'RE-RUN CHECK', title: 'Re-run check', body: 'This agent declares the shape of its output up front, so every job is checked by re-running the check. Anyone can re-run it and get the same answer. Jev grades only the jobs whose check can’t decide.' },
168
+ });
169
+ export const GRADER_ROLE = 'The grader is a role, not a name: an address or adapter the hook accepts as evaluator. Jev is the calibrated grader this surface integrates; a deterministic check, or another grader, may hold the same seat.';
170
+ // ── unsigned calls ────────────────────────────────────────────────────────────
171
+ export const POOL_SIGNATURES = Object.freeze({
172
+ approve: 'approve(address,uint256)',
173
+ deposit: 'deposit(uint256,address)',
174
+ redeem: 'redeem(uint256,address,address)',
175
+ withdraw: 'withdraw(uint256,address,address)',
176
+ createPool: 'createPool(address,address,string,string)',
177
+ });
178
+ /** The pool factories this surface knows: one pool per (seller, asset), permissionless to open. */
179
+ export const POOL_FACTORY = Object.freeze({ 8453: '0x91f078D10E3f0D05fEBcEA35f114063c696aef54', 36927: '0x9bea381ab97df2f10216c525d821412d8cae0001' });
180
+ /**
181
+ * Chains where the pool calls may be built. GLMR pools are not open, so Base mainnet is deliberately absent: a deposit,
182
+ * a redemption or a new pool can be built on the devnet only. The maths above (shares, previews, rules) works
183
+ * everywhere. Add 8453 here, and to nothing else, on the day pools open.
184
+ */
185
+ export const POOLS_OPEN_ON = Object.freeze([DEVNET_CHAIN_ID]);
186
+ export class PoolsNotOpenError extends Error {
187
+ chainId;
188
+ constructor(chainId) {
189
+ super(`pools are not open on chain ${chainId}: pool deposits, redemptions and new pools are built on the devnet (${DEVNET_CHAIN_ID}) only`);
190
+ this.chainId = chainId;
191
+ this.name = 'PoolsNotOpenError';
192
+ }
193
+ }
194
+ function assertPoolsOpen(chainId) {
195
+ if (!POOLS_OPEN_ON.includes(chainId))
196
+ throw new PoolsNotOpenError(chainId);
197
+ }
198
+ const word = (n) => { if (n < 0n)
199
+ throw new RangeError('negative word'); return n.toString(16).padStart(64, '0'); };
200
+ const addrWord = (a) => { if (!isAddress(a))
201
+ throw new Error(`not an address: ${a}`); return a.slice(2).toLowerCase().padStart(64, '0'); };
202
+ const call = (chainId, to, data, step, effect) => ({ chainId, to, data: data, value: '0x0', step, signer: 'anyone', effect });
203
+ /** The two calls a deposit takes, in order: an exact-amount approve to the pool, then deposit(assets, receiver). Never a standing allowance. */
204
+ export function depositCalls(a) {
205
+ assertPoolsOpen(a.chainId);
206
+ if (a.amount <= 0n)
207
+ throw new RangeError('amount must be positive');
208
+ return [
209
+ call(a.chainId, a.asset, selector(POOL_SIGNATURES.approve) + addrWord(a.pool) + word(a.amount), 'approve', `Allow the pool to take exactly ${formatU(a.amount, 18, 4)} GLMR. Nothing moves yet.`),
210
+ call(a.chainId, a.pool, selector(POOL_SIGNATURES.deposit) + word(a.amount) + addrWord(a.receiver), 'deposit', `Deposit ${formatU(a.amount, 18, 4)} GLMR; the pool mints your shares at today’s price.`),
211
+ ];
212
+ }
213
+ /** The one call a withdrawal takes: redeem(shares, receiver, owner). The pool pays today’s value of the shares, up to what nothing holds. */
214
+ export function redeemCalls(a) {
215
+ assertPoolsOpen(a.chainId);
216
+ if (a.shares <= 0n)
217
+ throw new RangeError('shares must be positive');
218
+ return [call(a.chainId, a.pool, selector(POOL_SIGNATURES.redeem) + word(a.shares) + addrWord(a.owner) + addrWord(a.owner), 'redeem', `Redeem ${formatU(a.shares, 18, 4)} shares for GLMR at today’s value.`)];
219
+ }
220
+ /** ABI-encode a string: its length word, then the bytes padded to 32. */
221
+ function stringWords(v) {
222
+ const b = utf8(v);
223
+ let hex = '';
224
+ for (const x of b)
225
+ hex += x.toString(16).padStart(2, '0');
226
+ return word(BigInt(b.length)) + hex.padEnd(Math.ceil(hex.length / 64) * 64, '0');
227
+ }
228
+ /**
229
+ * The one call that opens a pool: createPool(seller, asset, name, symbol) on the chain's factory. Anyone may
230
+ * send it; it costs gas and moves no money. Refused when the chain has no factory this surface knows.
231
+ */
232
+ export function createPoolCalls(a) {
233
+ assertPoolsOpen(a.chainId);
234
+ const factory = POOL_FACTORY[a.chainId];
235
+ if (!factory)
236
+ throw new Error(`no pool factory known on chain ${a.chainId}`);
237
+ if (!a.name.trim() || !a.symbol.trim())
238
+ throw new RangeError('a pool needs a name and a symbol');
239
+ const name = stringWords(a.name), symbol = stringWords(a.symbol);
240
+ const head = addrWord(a.seller) + addrWord(a.asset) + word(128n) + word(BigInt(128 + name.length / 2));
241
+ return [call(a.chainId, factory, selector(POOL_SIGNATURES.createPool) + head + name + symbol, 'createPool', `Open the pool behind ${a.seller} in ${a.symbol}: one pool per seller and asset, refused if one exists. Gas only; nothing is deposited.`)];
242
+ }
243
+ export { isAddress, isHex32 };
244
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAGzE,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,CAAC;AAC9B,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,sGAAsG;AACtG,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAO,GAAG,GAAG,CAAC;AACtC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,CAAC;AACrC,0FAA0F;AAC1F,4HAA4H;AAC5H,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AACrC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE5C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,SAAS,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,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,EAAE,YAAY,EAAE,wBAAwB,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,MAAM,yFAAyF,CAAC,CAAC,CAAC;AACzP,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC"}
package/docs/demo.gif ADDED
Binary file
package/docs/demo.tape ADDED
@@ -0,0 +1,14 @@
1
+ Output demo.gif
2
+ Set Shell "bash"
3
+ Set FontSize 14
4
+ Set Width 1340
5
+ Set Height 720
6
+ Set Padding 18
7
+ Set Theme "Catppuccin Mocha"
8
+ Set TypingSpeed 40ms
9
+ Hide
10
+ Type "export PATH=$PWD/node_modules/.bin:$PATH; clear" Enter
11
+ Show
12
+ Type "# A covered AI-agent job on Base: graded by Jev, settled by Moonbeam" Sleep 500ms Enter
13
+ Type "moonbeam demo" Sleep 300ms Enter
14
+ Sleep 6s
@@ -0,0 +1,18 @@
1
+ // Settle one covered job four ways. Positive is received, negative is paid, and every ledger sums to zero.
2
+ // node examples/01-settle-a-covered-job.mjs
3
+ import { settle, parseUnits, formatUnits, conservesValue } from '@moonbeam-foundation/sdk';
4
+
5
+ const usdc = (v) => parseUnits(v); // 6 decimals
6
+ const terms = {
7
+ pay: usdc('100'), // what the client pays for the work
8
+ premium: usdc('1'), // what it pays for cover
9
+ deposit: usdc('120'), // the provider's bond, sized above the job
10
+ evaluatorBond: usdc('25'), // the judge's bond
11
+ poolCapital: usdc('5000'), // backers standing behind the provider
12
+ damage: usdc('70'), // consequential loss if the work is bad
13
+ };
14
+ const fmt = (m) => `${m < 0n ? '-' : '+'}${formatUnits(m < 0n ? -m : m)}`.padStart(9);
15
+ for (const verdict of ['doneRight', 'notDelivered', 'rejected', 'cheated']) {
16
+ const { ledger } = settle({ terms, verdict });
17
+ console.log(`${verdict.padEnd(12)} client ${fmt(ledger.client)} provider ${fmt(ledger.provider)} pool ${fmt(ledger.pool)} sums to zero: ${conservesValue(ledger)}`);
18
+ }
@@ -0,0 +1,21 @@
1
+ // A buyer posts an intent, two agents bid, the one whose bond outweighs the job wins, and the buyer locks the terms.
2
+ // node examples/02-negotiate-a-hire.mjs
3
+ import { open, bid, bestBid, checkBid, accept, lockedByBuyer, coverSplit, parseUnits, formatUnits } from '@moonbeam-foundation/sdk';
4
+
5
+ const usdc = (v) => parseUnits(v);
6
+ const intent = { id: 'intent-1', specDigest: '0xspec', acceptanceDigest: '0xaccept', capabilities: ['summarize'], maxPay: usdc('100'), damage: usdc('70'), closesAt: 100 };
7
+ const cover = { premium: usdc('1'), poolCapital: usdc('5000'), evaluatorBond: usdc('25') };
8
+ const good = { intentId: 'intent-1', agent: 'agent-a', pay: usdc('100'), deposit: usdc('120'), capabilities: ['summarize'], at: 10 };
9
+ const thin = { ...good, agent: 'agent-b', deposit: usdc('40') };
10
+
11
+ console.log('agent-b refused:', checkBid(intent, thin, cover, 10)?.code); // a bond must outweigh the job
12
+ const n = bid(open(intent), good, cover, 10);
13
+ console.log('best bid:', bestBid(n)?.agent);
14
+ const winner = bestBid(n);
15
+ const agreed = accept(n, winner, cover);
16
+ if ('code' in agreed) throw new Error(agreed.reason);
17
+ const { terms } = agreed;
18
+ const locked = lockedByBuyer(terms);
19
+ const split = coverSplit(terms);
20
+ console.log(`buyer locks ${formatUnits(locked.total)} USDC (pay ${formatUnits(locked.pay)} + premium ${formatUnits(locked.premium)})`);
21
+ console.log(`damage is covered ${formatUnits(split.fromDeposit)} from the deposit, ${formatUnits(split.fromPool)} from the pool`);
@@ -0,0 +1,27 @@
1
+ // The whole covered job, offline, from a real Base trail: read the job's logs, grade the delivery, settle the money.
2
+ // No key, no network. Every step asserts its own result, so this file doubles as a check.
3
+ // node examples/03-end-to-end-offline.mjs
4
+ import { readFileSync } from 'node:fs';
5
+ import assert from 'node:assert/strict';
6
+ import { prepareSettlement, settle, localClock, conservesValue, formatUnits } from '@moonbeam-foundation/sdk';
7
+ import { gradeJob, verifyGrade } from '@moonbeam-foundation/sdk/judge';
8
+ import { TERMS } from './data/terms.mjs';
9
+ import { CLEAN } from './data/answers.mjs';
10
+
11
+ // 1. read: the real trail of Virtuals ACP job 74926 on Base
12
+ const logs = JSON.parse(readFileSync(new URL('./data/virtuals-job-74926.json', import.meta.url), 'utf8'));
13
+ const prepared = prepareSettlement(logs, TERMS, localClock(Math.floor(Date.UTC(2026, 8, 1) / 1000)));
14
+ assert.equal(prepared.ready, true);
15
+ console.log('1 read the chain says:', prepared.outcome.verdict, `(judged by: ${prepared.state.verification})`);
16
+
17
+ // 2. grade: that job was judged by the buyer itself; an independent grade of the same delivery
18
+ const grade = await gradeJob({ jobId: '0x' + BigInt(prepared.state.id).toString(16).padStart(64, '0'), evidence: 'the delivered report', answers: CLEAN, model: 'jev-1.13.0' });
19
+ assert.equal(grade.verdict, 'complete');
20
+ assert.equal((await verifyGrade(grade, { chain: false })).ok, true);
21
+ console.log('2 grade an independent grader says:', grade.verdict, '· re-verifies:', true);
22
+
23
+ // 3. settle: who ends up with what, under the chain's verdict
24
+ const { ledger } = settle({ terms: TERMS, verdict: prepared.input.verdict });
25
+ assert.ok(conservesValue(ledger));
26
+ const fmt = (m) => `${m < 0n ? '-' : '+'}${formatUnits(m < 0n ? -m : m)}`;
27
+ console.log('3 settle client', fmt(ledger.client), '· provider', fmt(ledger.provider), '· pool', fmt(ledger.pool), '· sums to zero');
@@ -0,0 +1,12 @@
1
+ // Grader stage 1: the evidence. What Jev reads about a job: the task as the buyer wrote it, what "done" means,
2
+ // what came back, and the job's trail. Build it from the job, never from a summary someone wrote about it.
3
+ // node examples/10-grade-evidence.mjs
4
+ import { readFileSync } from 'node:fs';
5
+ const hire = JSON.parse(readFileSync(new URL('./data/pilot-hire.json', import.meta.url), 'utf8'));
6
+ export const evidence = {
7
+ task: 'Deliver the agreed report and submit its digest to the hook',
8
+ acceptance_criteria: ['1. A deliverable is submitted before the deadline', '2. The submitted digest matches the delivered file'].join('\n'),
9
+ delivered: `digest submitted in ${hire.txs.delivered.hash} (block ${hire.txs.delivered.block})`,
10
+ trail: Object.entries(hire.txs).map(([k, t]) => `${k}: ${t.hash} · block ${t.block}`).join('\n'),
11
+ };
12
+ console.log(JSON.stringify(evidence, null, 2));
@@ -0,0 +1,10 @@
1
+ // Grader stage 2: the facts. Code checks what code can check. A failed check is final: the job is rejected
2
+ // and Jev is never asked, so no key and no network are needed for this path.
3
+ // node examples/11-grade-facts.mjs
4
+ import { gradeJob, jobFacts } from '@moonbeam-foundation/sdk/judge';
5
+ import { PILOT_JOB } from './data/answers.mjs';
6
+
7
+ const facts = await jobFacts({ delivered: true, checks: { digest_matches_file: false, before_deadline: true } });
8
+ console.log('facts:', facts);
9
+ const receipt = await gradeJob({ jobId: PILOT_JOB, evidence: 'the report', facts });
10
+ console.log(receipt.verdict, '·', receipt.reasons[0]); // reject, decided by the failed check
@@ -0,0 +1,8 @@
1
+ // Grader stage 3: Jev's answers. Four closed questions, each with a full probability distribution.
2
+ // Here the answers are supplied; with your key, gradeJob asks Jev instead (see 17-grade-live.mjs).
3
+ // node examples/12-grade-answers.mjs
4
+ import { gradeJob } from '@moonbeam-foundation/sdk/judge';
5
+ import { CLEAN, PILOT_JOB } from './data/answers.mjs';
6
+
7
+ const receipt = await gradeJob({ jobId: PILOT_JOB, evidence: 'the report', answers: CLEAN, model: 'jev-1.13.0' });
8
+ for (const [id, a] of Object.entries(receipt.answers)) console.log(id.padEnd(18), a.value.padEnd(9), JSON.stringify(a.probabilities));
@@ -0,0 +1,10 @@
1
+ // Grader stage 4: the verdict. Code composes complete, reject or needs_review from the answers under published
2
+ // thresholds. Mid-band answers are needs_review: nothing ends, the job goes to appeal.
3
+ // node examples/13-grade-verdict.mjs
4
+ import { gradeJob } from '@moonbeam-foundation/sdk/judge';
5
+ import { CLEAN, REJECT, UNSURE, PILOT_JOB } from './data/answers.mjs';
6
+
7
+ for (const [name, answers] of Object.entries({ CLEAN, REJECT, UNSURE })) {
8
+ const r = await gradeJob({ jobId: PILOT_JOB, evidence: 'the report', answers, model: 'jev-1.13.0' });
9
+ console.log(name.padEnd(7), '→', r.verdict.padEnd(13), r.reasons[0]);
10
+ }
@@ -0,0 +1,11 @@
1
+ // Grader stage 5: the record (optional). The unsigned calls that put the answers and the decision on chain.
2
+ // Recording is your choice: nothing here signs or sends; hand the calls to your own wallet.
3
+ // node examples/14-grade-record.mjs
4
+ import { gradeJob, recordGrade } from '@moonbeam-foundation/sdk/judge';
5
+ import { CLEAN, PILOT_JOB } from './data/answers.mjs';
6
+
7
+ const receipt = await gradeJob({ jobId: PILOT_JOB, evidence: 'the report', answers: CLEAN, model: 'jev-1.13.0' });
8
+ const none = await recordGrade(receipt, { network: 'none' });
9
+ console.log('network none →', none.calls.length, 'calls; digests only:', none.digests.decision);
10
+ const base = await recordGrade(receipt, { network: 'base' });
11
+ for (const c of base.calls) console.log(`${c.fn} on chain ${c.chainId} → ${c.to} · ${c.data.length / 2 - 1} bytes of calldata`);
@@ -0,0 +1,11 @@
1
+ // Grader stage 6: end the job. The one unsigned call that completes or rejects the job on Moonbeam's hook.
2
+ // needs_review returns null: nothing ends until a person decides.
3
+ // node examples/15-grade-end-the-job.mjs
4
+ import { gradeJob, endJob } from '@moonbeam-foundation/sdk/judge';
5
+ import { CLEAN, UNSURE, PILOT_JOB } from './data/answers.mjs';
6
+
7
+ for (const answers of [CLEAN, UNSURE]) {
8
+ const r = await gradeJob({ jobId: PILOT_JOB, evidence: 'the report', answers, model: 'jev-1.13.0' });
9
+ const call = endJob(PILOT_JOB, r);
10
+ console.log(r.verdict.padEnd(13), '→', call ? `${call.fn} to ${call.to}, signed by ${call.signer}` : 'no call: the job waits for a person');
11
+ }