@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,51 @@
1
+ import { parseAttestation } from './attestation.js';
2
+ import { err, ok } from './result.js';
3
+ const DEFAULT_TIMEOUT_MS = 10_000;
4
+ async function getJson(options, path) {
5
+ const doFetch = options.fetch ?? globalThis.fetch;
6
+ if (!doFetch) {
7
+ return err({ kind: 'network', message: 'no fetch implementation available' });
8
+ }
9
+ const controller = new AbortController();
10
+ const timeout = setTimeout(() => controller.abort(), options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
11
+ try {
12
+ const response = await doFetch(`${options.baseUrl}${path}`, { signal: controller.signal });
13
+ if (response.status === 404) {
14
+ // A definitive "nothing here" — the one negative answer that is a fact.
15
+ return err({ kind: 'noData', detail: `not served: ${path}` });
16
+ }
17
+ if (!response.ok) {
18
+ // Everything else means we do not know. Never read as absence.
19
+ return err({ kind: 'unavailable', status: response.status });
20
+ }
21
+ return ok(await response.json());
22
+ }
23
+ catch (cause) {
24
+ return err({ kind: 'network', message: String(cause) });
25
+ }
26
+ finally {
27
+ clearTimeout(timeout);
28
+ }
29
+ }
30
+ /** Reads signed finality attestations over HTTP. */
31
+ export function createAttestationSource(options) {
32
+ return {
33
+ async latest(chainId) {
34
+ const response = await getJson(options, `/v5/acp/liveness/${chainId}`);
35
+ if (!response.ok)
36
+ return response;
37
+ return parseAttestation(response.value);
38
+ },
39
+ };
40
+ }
41
+ export function formatEventRef(ref) {
42
+ return `${ref.chainId}:${ref.txHash}:${ref.logIndex}`;
43
+ }
44
+ export function createProofSource(options) {
45
+ return {
46
+ forEvent(ref) {
47
+ return getJson(options, `/v5/acp/event/${formatEventRef(ref)}`);
48
+ },
49
+ };
50
+ }
51
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/connect/http.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAuBtC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,KAAK,UAAU,OAAO,CACpB,OAA0B,EAC1B,IAAY;IAEZ,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAK,UAAU,CAAC,KAAsC,CAAC;IACpF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,mCAAmC,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC,CAAC;IAC9F,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MA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;QACL,QAAQ,CAAC,GAAa;YACpB,OAAO,OAAO,CAAC,OAAO,EAAE,iBAAiB,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { RawLog } from '../acp/events.js';
2
+ import type { LookupError, Result } from './result.js';
3
+ /**
4
+ * Reading event logs, with the guards that experience demands.
5
+ *
6
+ * Two failure modes are common enough to design against, and both are
7
+ * dangerous precisely because they look like success:
8
+ *
9
+ * 1. Some providers return an empty log set instead of an error. An empty
10
+ * result is indistinguishable from a genuinely quiet range, so a caller
11
+ * concludes "nothing happened" when the truth is "nobody looked".
12
+ * 2. Some providers reject wide block ranges. A query that silently fails
13
+ * leaves a hole in history that later reads never revisit.
14
+ *
15
+ * The answer to both is to make emptiness explicit and paging automatic.
16
+ */
17
+ export interface LogQuery {
18
+ readonly fromBlock: number;
19
+ readonly toBlock: number;
20
+ readonly address?: string;
21
+ readonly topics?: readonly (string | null)[];
22
+ }
23
+ export interface LogSource {
24
+ logs(query: LogQuery): Promise<Result<readonly RawLog[], LookupError>>;
25
+ }
26
+ /**
27
+ * Largest span a single query may cover.
28
+ *
29
+ * Chosen because widely used endpoints reject anything larger. Paging below
30
+ * this is always safe; above it, results may be silently truncated.
31
+ */
32
+ export declare const MAX_BLOCK_SPAN = 1800;
33
+ export declare function splitRange(fromBlock: number, toBlock: number, span?: number): LogQuery[];
34
+ export interface FetchLogsOptions {
35
+ readonly span?: number;
36
+ /**
37
+ * Treat an empty result as authoritative.
38
+ *
39
+ * Defaults to `false`: an empty page is reported as `noData` rather than as
40
+ * "no events", because the two are not the same and only the caller knows
41
+ * whether its source is one that lies about emptiness.
42
+ */
43
+ readonly trustEmpty?: boolean;
44
+ }
45
+ /**
46
+ * Read a block range in safe-sized pages.
47
+ *
48
+ * Stops at the first page that fails, rather than returning a partial history
49
+ * that looks complete — a gap silently swallowed here becomes a wrong verdict
50
+ * later.
51
+ */
52
+ export declare function fetchLogRange(source: LogSource, query: LogQuery, options?: FetchLogsOptions): Promise<Result<readonly RawLog[], LookupError>>;
53
+ //# sourceMappingURL=logs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/connect/logs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;CAC9C;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC;CACxE;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,OAAQ,CAAC;AAEpC,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,SAAiB,GAAG,QAAQ,EAAE,CAOhG;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,QAAQ,EACf,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,MAAM,CAAC,SAAS,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC,CAkBjD"}
@@ -0,0 +1,42 @@
1
+ import { err, ok } from './result.js';
2
+ /**
3
+ * Largest span a single query may cover.
4
+ *
5
+ * Chosen because widely used endpoints reject anything larger. Paging below
6
+ * this is always safe; above it, results may be silently truncated.
7
+ */
8
+ export const MAX_BLOCK_SPAN = 1_800;
9
+ export function splitRange(fromBlock, toBlock, span = MAX_BLOCK_SPAN) {
10
+ if (toBlock < fromBlock)
11
+ return [];
12
+ const pages = [];
13
+ for (let start = fromBlock; start <= toBlock; start += span) {
14
+ pages.push({ fromBlock: start, toBlock: Math.min(start + span - 1, toBlock) });
15
+ }
16
+ return pages;
17
+ }
18
+ /**
19
+ * Read a block range in safe-sized pages.
20
+ *
21
+ * Stops at the first page that fails, rather than returning a partial history
22
+ * that looks complete — a gap silently swallowed here becomes a wrong verdict
23
+ * later.
24
+ */
25
+ export async function fetchLogRange(source, query, options = {}) {
26
+ const pages = splitRange(query.fromBlock, query.toBlock, options.span ?? MAX_BLOCK_SPAN);
27
+ const collected = [];
28
+ for (const page of pages) {
29
+ const result = await source.logs({ ...query, ...page });
30
+ if (!result.ok)
31
+ return result;
32
+ collected.push(...result.value);
33
+ }
34
+ if (collected.length === 0 && !options.trustEmpty) {
35
+ return err({
36
+ kind: 'noData',
37
+ detail: `no logs in blocks ${query.fromBlock}-${query.toBlock}; empty results are not treated as authoritative`,
38
+ });
39
+ }
40
+ return ok(collected);
41
+ }
42
+ //# sourceMappingURL=logs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs.js","sourceRoot":"","sources":["../../src/connect/logs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AA6BtC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC;AAEpC,MAAM,UAAU,UAAU,CAAC,SAAiB,EAAE,OAAe,EAAE,IAAI,GAAG,cAAc;IAClF,IAAI,OAAO,GAAG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+1,49 @@
1
+ /**
2
+ * Results rather than exceptions, at the network edge.
3
+ *
4
+ * The distinction this type exists to preserve: "the service honestly has no
5
+ * data for this chain" and "the service is broken" are different answers, and
6
+ * only the first is safe to act on. Throwing collapses them into one, which is
7
+ * how an outage gets mistaken for a fact about the world.
8
+ */
9
+ export type Result<T, E> = {
10
+ readonly ok: true;
11
+ readonly value: T;
12
+ } | {
13
+ readonly ok: false;
14
+ readonly error: E;
15
+ };
16
+ export declare function ok<T>(value: T): Result<T, never>;
17
+ export declare function err<E>(error: E): Result<never, E>;
18
+ /** The value, or a fallback. Use when the distinction genuinely does not matter. */
19
+ export declare function valueOr<T, E>(result: Result<T, E>, fallback: T): T;
20
+ /**
21
+ * Why a lookup did not return data.
22
+ *
23
+ * `noData` is a fact: the source served a definitive "I have nothing for this".
24
+ * Everything else is an absence of information, and must never be read as
25
+ * evidence that the thing being looked for does not exist.
26
+ */
27
+ export type LookupError = {
28
+ readonly kind: 'noData';
29
+ readonly detail: string;
30
+ } | {
31
+ readonly kind: 'unavailable';
32
+ readonly status: number;
33
+ } | {
34
+ readonly kind: 'network';
35
+ readonly message: string;
36
+ } | {
37
+ readonly kind: 'malformed';
38
+ readonly message: string;
39
+ };
40
+ /**
41
+ * Did the source actually tell us there is nothing, or do we simply not know?
42
+ *
43
+ * Only `noData` is a statement about the world. Treating `unavailable` as
44
+ * absence is the failure mode that would let a server outage authorise a
45
+ * payment, so this predicate exists to make the check explicit at call sites.
46
+ */
47
+ export declare function meansAbsent(error: LookupError): boolean;
48
+ export declare function describeError(error: LookupError): string;
49
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/connect/result.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAE9C,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAEhD;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAEjD;AAED,oFAAoF;AACpF,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAElE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACtD;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEvD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAWxD"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Results rather than exceptions, at the network edge.
3
+ *
4
+ * The distinction this type exists to preserve: "the service honestly has no
5
+ * data for this chain" and "the service is broken" are different answers, and
6
+ * only the first is safe to act on. Throwing collapses them into one, which is
7
+ * how an outage gets mistaken for a fact about the world.
8
+ */
9
+ export function ok(value) {
10
+ return { ok: true, value };
11
+ }
12
+ export function err(error) {
13
+ return { ok: false, error };
14
+ }
15
+ /** The value, or a fallback. Use when the distinction genuinely does not matter. */
16
+ export function valueOr(result, fallback) {
17
+ return result.ok ? result.value : fallback;
18
+ }
19
+ /**
20
+ * Did the source actually tell us there is nothing, or do we simply not know?
21
+ *
22
+ * Only `noData` is a statement about the world. Treating `unavailable` as
23
+ * absence is the failure mode that would let a server outage authorise a
24
+ * payment, so this predicate exists to make the check explicit at call sites.
25
+ */
26
+ export function meansAbsent(error) {
27
+ return error.kind === 'noData';
28
+ }
29
+ export function describeError(error) {
30
+ switch (error.kind) {
31
+ case 'noData':
32
+ return `no data: ${error.detail}`;
33
+ case 'unavailable':
34
+ return `source unavailable (status ${error.status}) — unknown, not absent`;
35
+ case 'network':
36
+ return `network failure: ${error.message} — unknown, not absent`;
37
+ case 'malformed':
38
+ return `malformed response: ${error.message}`;
39
+ }
40
+ }
41
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/connect/result.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,UAAU,EAAE,CAAI,KAAQ;IAC5B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,GAAG,CAAI,KAAQ;IAC7B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,OAAO,CAAO,MAAoB,EAAE,QAAW;IAC7D,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7C,CAAC;AAeD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAkB;IAC9C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,YAAY,KAAK,CAAC,MAAM,EAAE,CAAC;QACpC,KAAK,aAAa;YAChB,OAAO,8BAA8B,KAAK,CAAC,MAAM,yBAAyB,CAAC;QAC7E,KAAK,SAAS;YACZ,OAAO,oBAAoB,KAAK,CAAC,OAAO,wBAAwB,CAAC;QACnE,KAAK,WAAW;YACd,OAAO,uBAAuB,KAAK,CAAC,OAAO,EAAE,CAAC;IAClD,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { ActorSpec, Role } from './types.js';
2
+ /**
3
+ * Who must put capital at risk to take part, and who may simply opt in.
4
+ *
5
+ * This answers the question the docs never state in one place: assurance is
6
+ * obligatory for the two roles whose word the system relies on (the provider
7
+ * doing the work and the evaluator grading it), and optional for everyone else.
8
+ * A backer chooses whether to back a pool at all — but once in, underwriting is
9
+ * not a separate opt-in: the exposure *is* the yield.
10
+ */
11
+ export declare const ACTORS: Readonly<Record<Role, ActorSpec>>;
12
+ export declare function actorsBy(obligation: ActorSpec['obligation']): readonly ActorSpec[];
13
+ //# sourceMappingURL=actors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actors.d.ts","sourceRoot":"","sources":["../../src/core/actors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CA2CnD,CAAC;AAEH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,SAAS,EAAE,CAElF"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Who must put capital at risk to take part, and who may simply opt in.
3
+ *
4
+ * This answers the question the docs never state in one place: assurance is
5
+ * obligatory for the two roles whose word the system relies on (the provider
6
+ * doing the work and the evaluator grading it), and optional for everyone else.
7
+ * A backer chooses whether to back a pool at all — but once in, underwriting is
8
+ * not a separate opt-in: the exposure *is* the yield.
9
+ */
10
+ export const ACTORS = Object.freeze({
11
+ client: {
12
+ role: 'client',
13
+ obligation: 'optional',
14
+ bonds: 'nothing beyond the price; the premium buys cover and is optional',
15
+ earns: 'work delivered, or its money back',
16
+ risks: 'the premium, which is not returned when cover was not needed',
17
+ },
18
+ provider: {
19
+ role: 'provider',
20
+ obligation: 'obligatory',
21
+ bonds: 'a deposit, without which it cannot take insured work',
22
+ earns: 'the job price, and its deposit back',
23
+ risks: 'the deposit, consumed first when cheating is established',
24
+ },
25
+ evaluator: {
26
+ role: 'evaluator',
27
+ obligation: 'obligatory',
28
+ bonds: 'a bond, without which it cannot issue verdicts',
29
+ earns: 'a grading fee, and a failed challenge forfeits its bond to the evaluator',
30
+ risks: 'the bond, paid to a challenger when its call is overturned',
31
+ },
32
+ pool: {
33
+ role: 'pool',
34
+ obligation: 'optional',
35
+ bonds: 'capital put into a pool, chosen freely and per pool',
36
+ earns: 'the premium on every job graded good, plus doubt fees',
37
+ risks: 'covering damage the provider deposit cannot, after the provider pays first',
38
+ },
39
+ doubter: {
40
+ role: 'doubter',
41
+ obligation: 'optional',
42
+ bonds: 'the fee, paid up front',
43
+ earns: 'a payout when a protocol fails more than its price implied',
44
+ risks: 'the fee, lost whenever the work is delivered',
45
+ },
46
+ challenger: {
47
+ role: 'challenger',
48
+ obligation: 'optional',
49
+ bonds: 'a bond against one specific verdict',
50
+ earns: "the evaluator's bond when the verdict is overturned",
51
+ risks: 'the bond, forfeited when the challenge fails',
52
+ },
53
+ });
54
+ export function actorsBy(obligation) {
55
+ return Object.values(ACTORS).filter((actor) => actor.obligation === obligation);
56
+ }
57
+ //# sourceMappingURL=actors.js.map
@@ -0,0 +1 @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K,UAAU,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Time, and where it came from.
3
+ *
4
+ * Deadlines decide money here: whether a refund is claimable, whether a job has
5
+ * expired, whether a dispute window is still open. So the SDK refuses to accept
6
+ * a bare number as "now". Every `Clock` carries its provenance, and a caller
7
+ * settling on a deadline can always tell whether the time came from their own
8
+ * machine or from something attested.
9
+ *
10
+ * The strongest source available is a signed finality attestation: an operator
11
+ * signs (chain, finalized block, timestamp) and the signature is recoverable,
12
+ * so a claim about time is non-repudiable rather than merely asserted. That is
13
+ * better than an unsigned RPC — but it is still one signer, so the SDK calls it
14
+ * `attested`, never "trustless".
15
+ */
16
+ export type Seconds = number;
17
+ export type ClockSource =
18
+ /** The caller's own machine. Fine for previews; not evidence. */
19
+ 'local'
20
+ /** A signed finality attestation. Non-repudiable, but trusts one signer. */
21
+ | 'attested'
22
+ /** A block timestamp read directly from a chain. */
23
+ | 'chain';
24
+ export interface FinalityAttestation {
25
+ readonly chainId: number;
26
+ readonly finalizedBlock: number;
27
+ readonly timestamp: Seconds;
28
+ readonly digest: string;
29
+ readonly signature: string;
30
+ /** Self-reported by the source. Worth nothing until recovered from the signature. */
31
+ readonly signer: string;
32
+ }
33
+ export interface Clock {
34
+ readonly now: Seconds;
35
+ readonly source: ClockSource;
36
+ readonly attestation?: FinalityAttestation;
37
+ }
38
+ export declare function localClock(now: Seconds): Clock;
39
+ export declare function chainClock(blockTimestamp: Seconds): Clock;
40
+ export declare function attestedClock(attestation: FinalityAttestation): Clock;
41
+ /** Is this clock recent enough to act on? */
42
+ export declare function isFresh(clock: Clock, now: Seconds, maxAgeSeconds: number): boolean;
43
+ export type Expiry = {
44
+ readonly state: 'live';
45
+ readonly secondsRemaining: number;
46
+ } | {
47
+ readonly state: 'expired';
48
+ readonly secondsSince: number;
49
+ }
50
+ /** No deadline was recorded, so nothing can be said about expiry. */
51
+ | {
52
+ readonly state: 'unknown';
53
+ };
54
+ export declare function expiryOf(deadline: Seconds | undefined, clock: Clock): Expiry;
55
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../src/core/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,WAAW;AACrB,iEAAiE;AAC/D,OAAO;AACT,4EAA4E;GAC1E,UAAU;AACZ,oDAAoD;GAClD,OAAO,CAAC;AAEZ,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qFAAqF;IACrF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC;CAC5C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAE9C;AAED,wBAAgB,UAAU,CAAC,cAAc,EAAE,OAAO,GAAG,KAAK,CAEzD;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,mBAAmB,GAAG,KAAK,CAErE;AAED,6CAA6C;AAC7C,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAElF;AAED,MAAM,MAAM,MAAM,GACd;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE;AAC9D,qEAAqE;GACnE;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAElC,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAI5E"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Time, and where it came from.
3
+ *
4
+ * Deadlines decide money here: whether a refund is claimable, whether a job has
5
+ * expired, whether a dispute window is still open. So the SDK refuses to accept
6
+ * a bare number as "now". Every `Clock` carries its provenance, and a caller
7
+ * settling on a deadline can always tell whether the time came from their own
8
+ * machine or from something attested.
9
+ *
10
+ * The strongest source available is a signed finality attestation: an operator
11
+ * signs (chain, finalized block, timestamp) and the signature is recoverable,
12
+ * so a claim about time is non-repudiable rather than merely asserted. That is
13
+ * better than an unsigned RPC — but it is still one signer, so the SDK calls it
14
+ * `attested`, never "trustless".
15
+ */
16
+ export function localClock(now) {
17
+ return { now, source: 'local' };
18
+ }
19
+ export function chainClock(blockTimestamp) {
20
+ return { now: blockTimestamp, source: 'chain' };
21
+ }
22
+ export function attestedClock(attestation) {
23
+ return { now: attestation.timestamp, source: 'attested', attestation };
24
+ }
25
+ /** Is this clock recent enough to act on? */
26
+ export function isFresh(clock, now, maxAgeSeconds) {
27
+ return now - clock.now <= maxAgeSeconds;
28
+ }
29
+ export function expiryOf(deadline, clock) {
30
+ if (deadline === undefined)
31
+ return { state: 'unknown' };
32
+ if (clock.now < deadline)
33
+ return { state: 'live', secondsRemaining: deadline - clock.now };
34
+ return { state: 'expired', secondsSince: clock.now - deadline };
35
+ }
36
+ //# sourceMappingURL=clock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.js","sourceRoot":"","sources":["../../src/core/clock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA4BH,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,cAAuB;IAChD,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAAgC;IAC5D,OAAO,EAAE,GAAG,EAAE,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AACzE,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,OAAO,CAAC,KAAY,EAAE,GAAY,EAAE,aAAqB;IACvE,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,aAAa,CAAC;AAC1C,CAAC;AAQD,MAAM,UAAU,QAAQ,CAAC,QAA6B,EAAE,KAAY;IAClE,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACxD,IAAI,KAAK,CAAC,GAAG,GAAG,QAAQ;QAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,QAAQ,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;IAC3F,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,GAAG,GAAG,QAAQ,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Money is a bigint count of minor units (USDC has 6 decimals, so 1 USDC = 1_000_000n).
3
+ *
4
+ * Floats are not used anywhere in settlement. A settlement that loses a
5
+ * fraction of a unit to rounding is a settlement that does not conserve value,
6
+ * and conservation is the property the whole model rests on.
7
+ */
8
+ export type Money = bigint;
9
+ /** Decimals of the settlement asset. ACP settles in USDC (6). */
10
+ export declare const USDC_DECIMALS = 6;
11
+ /** Basis points: 1 bp = 1/10_000. Coverage fees are quoted in bps. */
12
+ export type Bps = number;
13
+ export declare const ZERO: Money;
14
+ /** Parse a decimal string ("1.25") into minor units. Exact — no float path. */
15
+ export declare function parseUnits(value: string, decimals?: number): Money;
16
+ /** Format minor units back to a decimal string. Round-trips with parseUnits. */
17
+ export declare function formatUnits(value: Money, decimals?: number): string;
18
+ /**
19
+ * Apply a basis-point rate, rounding DOWN (toward zero).
20
+ *
21
+ * Rounding down is deliberate and always favours the escrow rather than a
22
+ * claimant: a fee computed against a payer rounds in the payer's favour, and a
23
+ * payout computed for a claimant never exceeds the exact entitlement. The
24
+ * alternative — rounding up somewhere — can mint a unit that no one funded.
25
+ */
26
+ export declare function applyBps(amount: Money, bps: Bps): Money;
27
+ /** Smaller of two amounts — used to cap payouts at what is actually bonded. */
28
+ export declare function min(a: Money, b: Money): Money;
29
+ /** Never-negative subtraction, for shortfalls. */
30
+ export declare function clampToZero(value: Money): Money;
31
+ export declare function sum(values: readonly Money[]): Money;
32
+ //# sourceMappingURL=money.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/core/money.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC;AAE3B,iEAAiE;AACjE,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,sEAAsE;AACtE,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB,eAAO,MAAM,IAAI,EAAE,KAAU,CAAC;AAE9B,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAsB,GAAG,KAAK,CAajF;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,GAAE,MAAsB,GAAG,MAAM,CAQlF;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,GAAG,KAAK,CAQvD;AAED,+EAA+E;AAC/E,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,KAAK,CAE7C;AAED,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C;AAED,wBAAgB,GAAG,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,KAAK,CAEnD"}
@@ -0,0 +1,57 @@
1
+ /** Decimals of the settlement asset. ACP settles in USDC (6). */
2
+ export const USDC_DECIMALS = 6;
3
+ export const ZERO = 0n;
4
+ /** Parse a decimal string ("1.25") into minor units. Exact — no float path. */
5
+ export function parseUnits(value, decimals = USDC_DECIMALS) {
6
+ if (!/^-?\d+(\.\d+)?$/.test(value)) {
7
+ throw new RangeError(`not a decimal number: ${value}`);
8
+ }
9
+ const negative = value.startsWith('-');
10
+ const body = negative ? value.slice(1) : value;
11
+ const [whole = '0', fraction = ''] = body.split('.');
12
+ if (fraction.length > decimals) {
13
+ throw new RangeError(`${value} has more than ${decimals} decimal places`);
14
+ }
15
+ const padded = fraction.padEnd(decimals, '0');
16
+ const magnitude = BigInt(whole) * 10n ** BigInt(decimals) + BigInt(padded || '0');
17
+ return negative ? -magnitude : magnitude;
18
+ }
19
+ /** Format minor units back to a decimal string. Round-trips with parseUnits. */
20
+ export function formatUnits(value, decimals = USDC_DECIMALS) {
21
+ const negative = value < 0n;
22
+ const magnitude = negative ? -value : value;
23
+ const base = 10n ** BigInt(decimals);
24
+ const whole = magnitude / base;
25
+ const fraction = (magnitude % base).toString().padStart(decimals, '0').replace(/0+$/, '');
26
+ const body = fraction ? `${whole}.${fraction}` : `${whole}`;
27
+ return negative ? `-${body}` : body;
28
+ }
29
+ /**
30
+ * Apply a basis-point rate, rounding DOWN (toward zero).
31
+ *
32
+ * Rounding down is deliberate and always favours the escrow rather than a
33
+ * claimant: a fee computed against a payer rounds in the payer's favour, and a
34
+ * payout computed for a claimant never exceeds the exact entitlement. The
35
+ * alternative — rounding up somewhere — can mint a unit that no one funded.
36
+ */
37
+ export function applyBps(amount, bps) {
38
+ if (!Number.isInteger(bps) || bps < 0) {
39
+ throw new RangeError(`bps must be a non-negative integer, got ${bps}`);
40
+ }
41
+ const negative = amount < 0n;
42
+ const magnitude = negative ? -amount : amount;
43
+ const result = (magnitude * BigInt(bps)) / 10000n;
44
+ return negative ? -result : result;
45
+ }
46
+ /** Smaller of two amounts — used to cap payouts at what is actually bonded. */
47
+ export function min(a, b) {
48
+ return a < b ? a : b;
49
+ }
50
+ /** Never-negative subtraction, for shortfalls. */
51
+ export function clampToZero(value) {
52
+ return value < 0n ? 0n : value;
53
+ }
54
+ export function sum(values) {
55
+ return values.reduce((total, value) => total + value, 0n);
56
+ }
57
+ //# sourceMappingURL=money.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"money.js","sourceRoot":"","sources":["../../src/core/money.ts"],"names":[],"mappings":"AASA,iEAAiE;AACjE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAK/B,MAAM,CAAC,MAAM,IAAI,GAAU,EAAE,CAAC;AAE9B,+EAA+E;AAC/E,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,WAAmB,aAAa;IACxE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,UAAU,CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/C,MAAM,CAAC,KAAK,GAAG,GAAG,EAAE,QAAQ,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrD,IAAI,QAAQ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AC9C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,UAAU,CAAC,2CAA2C,GAAG,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,GAAG,EAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9C,MAAM,MAAM,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAO,CAAC;IACnD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACrC,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,GAAG,CAAC,CAAQ,EAAE,CAAQ;IACpC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,MAAwB;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,71 @@
1
+ import type { Bps, Money } from './money.js';
2
+ /**
3
+ * Pool economics over a season.
4
+ *
5
+ * This module exists to answer one question that prose kept getting wrong:
6
+ * at what failure rate does a coverage pool stop making money? A published
7
+ * clearing fee is a claim about the failure rate the market expects. If the
8
+ * fee a pool charges implies a different break-even than the fee the auction
9
+ * clears at, the two numbers are describing different economies — and until
10
+ * this is computed, nothing catches that.
11
+ */
12
+ export interface SeasonInput {
13
+ /** Jobs the pool backed over the period. */
14
+ readonly jobs: number;
15
+ /** Premium earned per job graded good. */
16
+ readonly premiumPerJob: Money;
17
+ /** Share of jobs that ended in `cheated`. 0.006 = 0.6%. */
18
+ readonly failureRate: number;
19
+ /** Consequential loss per failure. */
20
+ readonly damagePerFailure: Money;
21
+ /** Provider bond, consumed before the pool pays anything. */
22
+ readonly depositPerJob: Money;
23
+ /**
24
+ * Capital standing behind the provider — the ceiling on what the pool can
25
+ * lose per failure.
26
+ *
27
+ * Optional because omitting it is a meaningful statement: "model an
28
+ * uncapped loss". But omitting it also means this projection can exceed what
29
+ * `settle` would ever pay, so `capped` on the result says which you got.
30
+ */
31
+ readonly poolCapital?: Money;
32
+ }
33
+ export interface SeasonResult {
34
+ readonly failures: number;
35
+ readonly premiumEarned: Money;
36
+ /** Loss absorbed by the cheating providers themselves. */
37
+ readonly absorbedByDeposits: Money;
38
+ /** Loss that reached the pool. */
39
+ readonly paidByPool: Money;
40
+ readonly net: Money;
41
+ readonly profitable: boolean;
42
+ /**
43
+ * Whether the per-failure loss was capped at pool capital.
44
+ *
45
+ * False means no capital was supplied, so `paidByPool` is an uncapped
46
+ * projection that can exceed anything `settle` would actually pay. A caller
47
+ * comparing a season against real settlements must check this before
48
+ * treating the two as the same quantity.
49
+ */
50
+ readonly capped: boolean;
51
+ }
52
+ export declare function runSeason(input: SeasonInput): SeasonResult;
53
+ /**
54
+ * The failure rate at which a pool exactly breaks even.
55
+ *
56
+ * Returns `null` when the pool cannot lose (the provider deposit always covers
57
+ * the damage in full), because there is then no rate at which it goes negative.
58
+ */
59
+ export declare function breakEvenFailureRate(premiumPerJob: Money, damagePerFailure: Money, depositPerJob: Money, poolCapital?: Money): number | null;
60
+ /** A clearing fee in bps read as the failure rate the market is pricing. */
61
+ export declare function impliedFailureRate(clearingFeeBps: Bps): number;
62
+ /**
63
+ * Does a published clearing fee agree with what the pool actually needs?
64
+ *
65
+ * `tolerance` is a ratio: 0.5 accepts the implied rate landing within half an
66
+ * order of magnitude of break-even. A mismatch is not necessarily a bug — a
67
+ * pool may deliberately price in a margin — but an *order-of-magnitude* gap
68
+ * means the two figures were authored against different assumptions.
69
+ */
70
+ export declare function clearingFeeIsCoherent(clearingFeeBps: Bps, premiumPerJob: Money, damagePerFailure: Money, depositPerJob: Money, tolerance?: number): boolean;
71
+ //# sourceMappingURL=pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/core/pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAG7C;;;;;;;;;GASG;AAEH,MAAM,WAAW,WAAW;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC;IACjC,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC;IAC9B;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC;IACnC,kCAAkC;IAClC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAQD,wBA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