@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.
- package/LICENSE +17 -0
- package/README.md +378 -0
- package/bin/moonbeam.mjs +56 -0
- package/dist/acp/coverage.d.ts +36 -0
- package/dist/acp/coverage.d.ts.map +1 -0
- package/dist/acp/coverage.js +51 -0
- package/dist/acp/coverage.js.map +1 -0
- package/dist/acp/events.d.ts +201 -0
- package/dist/acp/events.d.ts.map +1 -0
- package/dist/acp/events.js +201 -0
- package/dist/acp/events.js.map +1 -0
- package/dist/acp/hex.d.ts +29 -0
- package/dist/acp/hex.d.ts.map +1 -0
- package/dist/acp/hex.js +51 -0
- package/dist/acp/hex.js.map +1 -0
- package/dist/acp/lifecycle-types.d.ts +11 -0
- package/dist/acp/lifecycle-types.d.ts.map +1 -0
- package/dist/acp/lifecycle-types.js +8 -0
- package/dist/acp/lifecycle-types.js.map +1 -0
- package/dist/acp/lifecycle.d.ts +78 -0
- package/dist/acp/lifecycle.d.ts.map +1 -0
- package/dist/acp/lifecycle.js +224 -0
- package/dist/acp/lifecycle.js.map +1 -0
- package/dist/acp/outcome.d.ts +45 -0
- package/dist/acp/outcome.d.ts.map +1 -0
- package/dist/acp/outcome.js +104 -0
- package/dist/acp/outcome.js.map +1 -0
- package/dist/acp/pipeline.d.ts +30 -0
- package/dist/acp/pipeline.d.ts.map +1 -0
- package/dist/acp/pipeline.js +25 -0
- package/dist/acp/pipeline.js.map +1 -0
- package/dist/acp/recourse.d.ts +74 -0
- package/dist/acp/recourse.d.ts.map +1 -0
- package/dist/acp/recourse.js +234 -0
- package/dist/acp/recourse.js.map +1 -0
- package/dist/acp/registry.d.ts +62 -0
- package/dist/acp/registry.d.ts.map +1 -0
- package/dist/acp/registry.js +86 -0
- package/dist/acp/registry.js.map +1 -0
- package/dist/acp/transitions.d.ts +82 -0
- package/dist/acp/transitions.d.ts.map +1 -0
- package/dist/acp/transitions.js +106 -0
- package/dist/acp/transitions.js.map +1 -0
- package/dist/actors/index.d.ts +84 -0
- package/dist/actors/index.d.ts.map +1 -0
- package/dist/actors/index.js +133 -0
- package/dist/actors/index.js.map +1 -0
- package/dist/actors/track-record.d.ts +79 -0
- package/dist/actors/track-record.d.ts.map +1 -0
- package/dist/actors/track-record.js +105 -0
- package/dist/actors/track-record.js.map +1 -0
- package/dist/adapters/acp.d.ts +48 -0
- package/dist/adapters/acp.d.ts.map +1 -0
- package/dist/adapters/acp.js +74 -0
- package/dist/adapters/acp.js.map +1 -0
- package/dist/adapters/port.d.ts +53 -0
- package/dist/adapters/port.d.ts.map +1 -0
- package/dist/adapters/port.js +2 -0
- package/dist/adapters/port.js.map +1 -0
- package/dist/adapters/stamp.d.ts +57 -0
- package/dist/adapters/stamp.d.ts.map +1 -0
- package/dist/adapters/stamp.js +114 -0
- package/dist/adapters/stamp.js.map +1 -0
- package/dist/client/index.d.ts +123 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +78 -0
- package/dist/client/index.js.map +1 -0
- package/dist/connect/attestation.d.ts +64 -0
- package/dist/connect/attestation.d.ts.map +1 -0
- package/dist/connect/attestation.js +62 -0
- package/dist/connect/attestation.js.map +1 -0
- package/dist/connect/http.d.ts +36 -0
- package/dist/connect/http.d.ts.map +1 -0
- package/dist/connect/http.js +51 -0
- package/dist/connect/http.js.map +1 -0
- package/dist/connect/logs.d.ts +53 -0
- package/dist/connect/logs.d.ts.map +1 -0
- package/dist/connect/logs.js +42 -0
- package/dist/connect/logs.js.map +1 -0
- package/dist/connect/result.d.ts +49 -0
- package/dist/connect/result.d.ts.map +1 -0
- package/dist/connect/result.js +41 -0
- package/dist/connect/result.js.map +1 -0
- package/dist/core/actors.d.ts +13 -0
- package/dist/core/actors.d.ts.map +1 -0
- package/dist/core/actors.js +57 -0
- package/dist/core/actors.js.map +1 -0
- package/dist/core/clock.d.ts +55 -0
- package/dist/core/clock.d.ts.map +1 -0
- package/dist/core/clock.js +36 -0
- package/dist/core/clock.js.map +1 -0
- package/dist/core/money.d.ts +32 -0
- package/dist/core/money.d.ts.map +1 -0
- package/dist/core/money.js +57 -0
- package/dist/core/money.js.map +1 -0
- package/dist/core/pool.d.ts +71 -0
- package/dist/core/pool.d.ts.map +1 -0
- package/dist/core/pool.js +98 -0
- package/dist/core/pool.js.map +1 -0
- package/dist/core/settle.d.ts +50 -0
- package/dist/core/settle.d.ts.map +1 -0
- package/dist/core/settle.js +175 -0
- package/dist/core/settle.js.map +1 -0
- package/dist/core/types.d.ts +109 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +6 -0
- package/dist/core/types.js.map +1 -0
- package/dist/erc8004/index.d.ts +94 -0
- package/dist/erc8004/index.d.ts.map +1 -0
- package/dist/erc8004/index.js +118 -0
- package/dist/erc8004/index.js.map +1 -0
- package/dist/erc8004/registry.generated.d.ts +17 -0
- package/dist/erc8004/registry.generated.d.ts.map +1 -0
- package/dist/erc8004/registry.generated.js +20 -0
- package/dist/erc8004/registry.generated.js.map +1 -0
- package/dist/erc8183/index.d.ts +114 -0
- package/dist/erc8183/index.d.ts.map +1 -0
- package/dist/erc8183/index.js +109 -0
- package/dist/erc8183/index.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/judge/index.d.ts +64 -0
- package/dist/judge/index.d.ts.map +1 -0
- package/dist/judge/index.js +64 -0
- package/dist/judge/index.js.map +1 -0
- package/dist/launcher/index.d.ts +109 -0
- package/dist/launcher/index.d.ts.map +1 -0
- package/dist/launcher/index.js +144 -0
- package/dist/launcher/index.js.map +1 -0
- package/dist/negotiate/index.d.ts +166 -0
- package/dist/negotiate/index.d.ts.map +1 -0
- package/dist/negotiate/index.js +150 -0
- package/dist/negotiate/index.js.map +1 -0
- package/dist/onboard/index.d.ts +533 -0
- package/dist/onboard/index.d.ts.map +1 -0
- package/dist/onboard/index.js +509 -0
- package/dist/onboard/index.js.map +1 -0
- package/dist/onboarding/index.d.ts +177 -0
- package/dist/onboarding/index.d.ts.map +1 -0
- package/dist/onboarding/index.js +390 -0
- package/dist/onboarding/index.js.map +1 -0
- package/dist/pools/index.d.ts +191 -0
- package/dist/pools/index.d.ts.map +1 -0
- package/dist/pools/index.js +244 -0
- package/dist/pools/index.js.map +1 -0
- package/docs/demo.gif +0 -0
- package/docs/demo.tape +14 -0
- package/examples/01-settle-a-covered-job.mjs +18 -0
- package/examples/02-negotiate-a-hire.mjs +21 -0
- package/examples/03-end-to-end-offline.mjs +27 -0
- package/examples/10-grade-evidence.mjs +12 -0
- package/examples/11-grade-facts.mjs +10 -0
- package/examples/12-grade-answers.mjs +8 -0
- package/examples/13-grade-verdict.mjs +10 -0
- package/examples/14-grade-record.mjs +11 -0
- package/examples/15-grade-end-the-job.mjs +11 -0
- package/examples/16-grade-verify.mjs +9 -0
- package/examples/17-grade-live.mjs +14 -0
- package/examples/20-onboard-client.mjs +8 -0
- package/examples/21-onboard-provider.mjs +9 -0
- package/examples/22-onboard-evaluator.mjs +7 -0
- package/examples/23-onboard-backer.mjs +8 -0
- package/examples/30-read-a-real-job.mjs +19 -0
- package/examples/31-read-the-ending.mjs +15 -0
- package/examples/32-read-live-from-base.mjs +33 -0
- package/examples/33-read-many-jobs.mjs +12 -0
- package/examples/40-the-article.mjs +78 -0
- package/examples/README.md +93 -0
- package/examples/data/answers.mjs +8 -0
- package/examples/data/base-grade.recorded.json +72 -0
- package/examples/data/pilot-grade.recorded.json +78 -0
- package/examples/data/pilot-hire.json +35 -0
- package/examples/data/terms.mjs +11 -0
- package/examples/data/virtuals-job-74926.json +74 -0
- package/examples/data/virtuals-job-rejected.json +74 -0
- package/package.json +124 -0
- package/skills/moonbeam-acp-decoding/SKILL.md +80 -0
- package/skills/moonbeam-actor-backer/SKILL.md +81 -0
- package/skills/moonbeam-actor-challenger/SKILL.md +62 -0
- package/skills/moonbeam-actor-client/SKILL.md +67 -0
- package/skills/moonbeam-actor-doubter/SKILL.md +55 -0
- package/skills/moonbeam-actor-evaluator/SKILL.md +67 -0
- package/skills/moonbeam-actor-provider/SKILL.md +63 -0
- package/skills/moonbeam-assurance/SKILL.md +58 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Bps, Money } from '../core/money.js';
|
|
2
|
+
import type { JobTerms, Ledger, Role, Verdict } from '../core/types.js';
|
|
3
|
+
/** This actor's position under one verdict. */
|
|
4
|
+
export declare function positionUnder(role: Role, terms: JobTerms, verdict: Verdict): Money;
|
|
5
|
+
/** This actor's position under every verdict — the whole risk picture at once. */
|
|
6
|
+
export declare function positionsByVerdict(role: Role, terms: JobTerms): Readonly<Record<Verdict, Money>>;
|
|
7
|
+
/** The worst this actor can do on a single job. Negative means a loss. */
|
|
8
|
+
export declare function worstCase(role: Role, terms: JobTerms): Money;
|
|
9
|
+
/** The best this actor can do on a single job. */
|
|
10
|
+
export declare function bestCase(role: Role, terms: JobTerms): Money;
|
|
11
|
+
/**
|
|
12
|
+
* Damage the client would bear alone.
|
|
13
|
+
*
|
|
14
|
+
* Cover is limited by what is actually bonded. If the loss a job can cause
|
|
15
|
+
* exceeds the deposit plus the pool, the excess falls on the client and no
|
|
16
|
+
* escrow anywhere shows them that number before they commit.
|
|
17
|
+
*/
|
|
18
|
+
export declare function coverGap(terms: JobTerms): Money;
|
|
19
|
+
/** What the client actually recovers if cheating is established. */
|
|
20
|
+
export declare function recoveryFor(terms: JobTerms): Money;
|
|
21
|
+
/** Capital the provider must post to take this job. */
|
|
22
|
+
export declare function capitalRequired(terms: JobTerms): Money;
|
|
23
|
+
export type Decision = {
|
|
24
|
+
readonly ok: true;
|
|
25
|
+
} | {
|
|
26
|
+
readonly ok: false;
|
|
27
|
+
readonly reason: string;
|
|
28
|
+
};
|
|
29
|
+
/** Can this provider take the job with the capital it has free? */
|
|
30
|
+
export declare function canAccept(terms: JobTerms, freeCapital: Money): Decision;
|
|
31
|
+
/**
|
|
32
|
+
* Whether an action requires a verified proof.
|
|
33
|
+
*
|
|
34
|
+
* Refusing to pay is always safe, so rejection needs no proof. Releasing
|
|
35
|
+
* someone else's money is not safe, so approval does. Encoding the asymmetry
|
|
36
|
+
* here — rather than leaving it in a comment — means an integrator cannot
|
|
37
|
+
* invert it by accident.
|
|
38
|
+
*/
|
|
39
|
+
export declare function proofRequiredFor(action: 'approve' | 'reject'): boolean;
|
|
40
|
+
export declare function bondAtRisk(terms: JobTerms): Money;
|
|
41
|
+
export interface Exposure {
|
|
42
|
+
readonly committed: Money;
|
|
43
|
+
readonly capital: Money;
|
|
44
|
+
readonly utilisation: number;
|
|
45
|
+
readonly solvent: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Exposure across jobs that could fail together.
|
|
49
|
+
*
|
|
50
|
+
* `runSeason` averages over a period and assumes failures are independent.
|
|
51
|
+
* This asks the question that actually ends pools: what if several of the jobs
|
|
52
|
+
* standing behind the same capital fail at once?
|
|
53
|
+
*/
|
|
54
|
+
export declare function poolExposure(terms: JobTerms, concurrentJobs: number, capital: Money): Exposure;
|
|
55
|
+
/** Could the pool honour this many simultaneous failures? */
|
|
56
|
+
export declare function solventUnder(capital: Money, terms: JobTerms, simultaneousFailures: number): boolean;
|
|
57
|
+
export interface DoubtQuote {
|
|
58
|
+
readonly fee: Money;
|
|
59
|
+
readonly maxPayout: Money;
|
|
60
|
+
/** True when the position is larger than the bonded capital behind the job. */
|
|
61
|
+
readonly capped: boolean;
|
|
62
|
+
/** Failure probability at which the position is break-even. */
|
|
63
|
+
readonly breakEvenProbability: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Price a doubt position.
|
|
67
|
+
*
|
|
68
|
+
* `capped` is the number a doubter most needs and is least likely to work out:
|
|
69
|
+
* sizing above the bonded capital buys coverage that cannot pay out, so the fee
|
|
70
|
+
* on the excess is spent for nothing.
|
|
71
|
+
*/
|
|
72
|
+
export declare function doubtQuote(terms: JobTerms, notional: Money, feeBps: Bps): DoubtQuote;
|
|
73
|
+
/** Does a doubt position size stay within what can actually pay out? */
|
|
74
|
+
export declare function sizeWithinCap(terms: JobTerms, notional: Money): boolean;
|
|
75
|
+
export interface ChallengeQuote {
|
|
76
|
+
readonly winAmount: Money;
|
|
77
|
+
readonly loseAmount: Money;
|
|
78
|
+
readonly breakEvenProbability: number;
|
|
79
|
+
}
|
|
80
|
+
/** What a challenge pays, what it costs, and the odds at which it is worth taking. */
|
|
81
|
+
export declare function challengeQuote(terms: JobTerms, bond: Money): ChallengeQuote;
|
|
82
|
+
export declare function worthChallenging(terms: JobTerms, bond: Money, probabilityOfWinning: number): boolean;
|
|
83
|
+
export type { Ledger };
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actors/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAaxE,+CAA+C;AAC/C,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,KAAK,CAElF;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAIhG;AAED,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAG5D;AAED,kDAAkD;AAClD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAG3D;AAID;;;;;;GAMG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AAE,KAAK,CAAC;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;CACvC;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,UAAU,CAMpF;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,GAAG,OAAO,CAEvE;AAID,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;CACvC;AAED,sFAAsF;AACtF,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,GAAG,cAAc,CAS3E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,GAAG,OAAO,CAEpG;AAED,YAAY,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { applyBps, clampToZero, formatUnits, min, ZERO } from '../core/money.js';
|
|
2
|
+
import { maxDoubtPayout, poolLossPerFailure, settle } from '../core/settle.js';
|
|
3
|
+
/**
|
|
4
|
+
* Per-actor arithmetic.
|
|
5
|
+
*
|
|
6
|
+
* Everything here is derived from `settle()` rather than restated, so no actor
|
|
7
|
+
* can be shown a number that disagrees with how the job would actually settle.
|
|
8
|
+
* Each function answers one question a participant actually asks before
|
|
9
|
+
* committing capital.
|
|
10
|
+
*/
|
|
11
|
+
const ALL_VERDICTS = ['doneRight', 'notDelivered', 'rejected', 'cheated'];
|
|
12
|
+
/** This actor's position under one verdict. */
|
|
13
|
+
export function positionUnder(role, terms, verdict) {
|
|
14
|
+
return settle({ terms, verdict }).ledger[role];
|
|
15
|
+
}
|
|
16
|
+
/** This actor's position under every verdict — the whole risk picture at once. */
|
|
17
|
+
export function positionsByVerdict(role, terms) {
|
|
18
|
+
const out = {};
|
|
19
|
+
for (const verdict of ALL_VERDICTS)
|
|
20
|
+
out[verdict] = positionUnder(role, terms, verdict);
|
|
21
|
+
return Object.freeze(out);
|
|
22
|
+
}
|
|
23
|
+
/** The worst this actor can do on a single job. Negative means a loss. */
|
|
24
|
+
export function worstCase(role, terms) {
|
|
25
|
+
const positions = Object.values(positionsByVerdict(role, terms));
|
|
26
|
+
return positions.reduce((worst, p) => (p < worst ? p : worst), positions[0] ?? ZERO);
|
|
27
|
+
}
|
|
28
|
+
/** The best this actor can do on a single job. */
|
|
29
|
+
export function bestCase(role, terms) {
|
|
30
|
+
const positions = Object.values(positionsByVerdict(role, terms));
|
|
31
|
+
return positions.reduce((best, p) => (p > best ? p : best), positions[0] ?? ZERO);
|
|
32
|
+
}
|
|
33
|
+
// ── Client ────────────────────────────────────────────────────────────────
|
|
34
|
+
/**
|
|
35
|
+
* Damage the client would bear alone.
|
|
36
|
+
*
|
|
37
|
+
* Cover is limited by what is actually bonded. If the loss a job can cause
|
|
38
|
+
* exceeds the deposit plus the pool, the excess falls on the client and no
|
|
39
|
+
* escrow anywhere shows them that number before they commit.
|
|
40
|
+
*/
|
|
41
|
+
export function coverGap(terms) {
|
|
42
|
+
return clampToZero(terms.damage - (terms.deposit + terms.poolCapital));
|
|
43
|
+
}
|
|
44
|
+
/** What the client actually recovers if cheating is established. */
|
|
45
|
+
export function recoveryFor(terms) {
|
|
46
|
+
return positionUnder('client', terms, 'cheated');
|
|
47
|
+
}
|
|
48
|
+
// ── Provider ──────────────────────────────────────────────────────────────
|
|
49
|
+
/** Capital the provider must post to take this job. */
|
|
50
|
+
export function capitalRequired(terms) {
|
|
51
|
+
return terms.deposit;
|
|
52
|
+
}
|
|
53
|
+
/** Can this provider take the job with the capital it has free? */
|
|
54
|
+
export function canAccept(terms, freeCapital) {
|
|
55
|
+
if (freeCapital < terms.deposit) {
|
|
56
|
+
// Formatted, not raw. This string is shown to whoever is deciding whether
|
|
57
|
+
// to take the job, and printing `200000000` for 200 USDC is off by six
|
|
58
|
+
// orders of magnitude — the same defect already fixed in onboarding.
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
reason: `deposit of ${formatUnits(terms.deposit)} exceeds free capital of ${formatUnits(freeCapital)}`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return { ok: true };
|
|
65
|
+
}
|
|
66
|
+
// ── Evaluator ─────────────────────────────────────────────────────────────
|
|
67
|
+
/**
|
|
68
|
+
* Whether an action requires a verified proof.
|
|
69
|
+
*
|
|
70
|
+
* Refusing to pay is always safe, so rejection needs no proof. Releasing
|
|
71
|
+
* someone else's money is not safe, so approval does. Encoding the asymmetry
|
|
72
|
+
* here — rather than leaving it in a comment — means an integrator cannot
|
|
73
|
+
* invert it by accident.
|
|
74
|
+
*/
|
|
75
|
+
export function proofRequiredFor(action) {
|
|
76
|
+
return action === 'approve';
|
|
77
|
+
}
|
|
78
|
+
export function bondAtRisk(terms) {
|
|
79
|
+
return terms.evaluatorBond;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Exposure across jobs that could fail together.
|
|
83
|
+
*
|
|
84
|
+
* `runSeason` averages over a period and assumes failures are independent.
|
|
85
|
+
* This asks the question that actually ends pools: what if several of the jobs
|
|
86
|
+
* standing behind the same capital fail at once?
|
|
87
|
+
*/
|
|
88
|
+
export function poolExposure(terms, concurrentJobs, capital) {
|
|
89
|
+
// Was `clampToZero(min(damage - deposit, poolCapital))` — the same quantity
|
|
90
|
+
// `settle` computes, restated. It happened to agree; two of the four sites
|
|
91
|
+
// that restated it did not.
|
|
92
|
+
const perJob = poolLossPerFailure(terms);
|
|
93
|
+
const committed = perJob * BigInt(Math.max(0, Math.trunc(concurrentJobs)));
|
|
94
|
+
const utilisation = capital > ZERO ? Number(committed) / Number(capital) : 0;
|
|
95
|
+
return { committed, capital, utilisation, solvent: committed <= capital };
|
|
96
|
+
}
|
|
97
|
+
/** Could the pool honour this many simultaneous failures? */
|
|
98
|
+
export function solventUnder(capital, terms, simultaneousFailures) {
|
|
99
|
+
return poolExposure(terms, simultaneousFailures, capital).solvent;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Price a doubt position.
|
|
103
|
+
*
|
|
104
|
+
* `capped` is the number a doubter most needs and is least likely to work out:
|
|
105
|
+
* sizing above the bonded capital buys coverage that cannot pay out, so the fee
|
|
106
|
+
* on the excess is spent for nothing.
|
|
107
|
+
*/
|
|
108
|
+
export function doubtQuote(terms, notional, feeBps) {
|
|
109
|
+
const fee = applyBps(notional, feeBps);
|
|
110
|
+
const cap = maxDoubtPayout(terms);
|
|
111
|
+
const maxPayout = min(notional, cap);
|
|
112
|
+
const breakEvenProbability = maxPayout > ZERO ? Number(fee) / Number(maxPayout) : 1;
|
|
113
|
+
return { fee, maxPayout, capped: notional > cap, breakEvenProbability };
|
|
114
|
+
}
|
|
115
|
+
/** Does a doubt position size stay within what can actually pay out? */
|
|
116
|
+
export function sizeWithinCap(terms, notional) {
|
|
117
|
+
return notional <= maxDoubtPayout(terms);
|
|
118
|
+
}
|
|
119
|
+
/** What a challenge pays, what it costs, and the odds at which it is worth taking. */
|
|
120
|
+
export function challengeQuote(terms, bond) {
|
|
121
|
+
const winAmount = terms.evaluatorBond;
|
|
122
|
+
const loseAmount = bond;
|
|
123
|
+
const total = Number(winAmount) + Number(loseAmount);
|
|
124
|
+
return {
|
|
125
|
+
winAmount,
|
|
126
|
+
loseAmount,
|
|
127
|
+
breakEvenProbability: total > 0 ? Number(loseAmount) / total : 1,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function worthChallenging(terms, bond, probabilityOfWinning) {
|
|
131
|
+
return probabilityOfWinning > challengeQuote(terms, bond).breakEvenProbability;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG/E;;;;;;;GAOG;AAEH,MAAM,YAAY,GAAuB,CAAC,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AAE9F,+CAA+C;AAC/C,MAAM,UAAU,aAAa,CAAC,IAAU,EAAE,KAAe,EAAE,OAAgB;IACzE,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,kBAAkB,CAAC,IAAU,EAAE,KAAe;IAC5D,MAAM,GAAG,GAAG,EAA4B,CAAC;IACzC,KAAK,MAAM,OAAO,IAAI,YAAY;QAAE,GAAG,CAAC,OAAO,CAAC,GAAG,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACvF,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,SAAS,CAAC,IAAU,EAAE,KAAe;IACnD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACjE,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,C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,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACrC,MAAM,oBAAoB,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpF,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAG,GAAG,EAAE,oBAAoB,EAAE,CAAC;AAC1E,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAAC,KAAe,EAAE,QAAe;IAC5D,OAAO,QAAQ,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC;AAUD,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAAC,KAAe,EAAE,IAAW;IACzD,MAAM,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC;IACtC,MAAM,UAAU,GAAG,IAAI,CAAC;IACxB,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACrD,OAAO;QACL,SAAS;QACT,UAAU;QACV,oBAAoB,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;KACjE,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAe,EAAE,IAAW,EAAE,oBAA4B;IACzF,OAAO,oBAAoB,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,oBAAoB,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Address } from '../acp/hex.js';
|
|
2
|
+
import type { Clock } from '../core/clock.js';
|
|
3
|
+
import type { TaskState } from '../acp/lifecycle.js';
|
|
4
|
+
/**
|
|
5
|
+
* A single worker's record, computed from decoded history.
|
|
6
|
+
*
|
|
7
|
+
* This exists because the market average turned out to be useless. Measured on
|
|
8
|
+
* live traffic, one provider produced 70% of all jobs and failed 99.6% of them
|
|
9
|
+
* while everybody else failed around 10% — so an aggregate rate describes
|
|
10
|
+
* neither population, and a pool quoting one is quoting a number that applies
|
|
11
|
+
* to no worker it might actually back.
|
|
12
|
+
*
|
|
13
|
+
* The unit that *is* meaningful is a worker. This module computes it from the
|
|
14
|
+
* same decoded events everything else uses, so a backer can ask about the
|
|
15
|
+
* counterparty rather than about the market.
|
|
16
|
+
*/
|
|
17
|
+
export interface TrackRecord {
|
|
18
|
+
readonly provider: Address;
|
|
19
|
+
/** Jobs that were funded and whose deadline has passed. */
|
|
20
|
+
readonly matured: number;
|
|
21
|
+
readonly delivered: number;
|
|
22
|
+
readonly expired: number;
|
|
23
|
+
readonly rejected: number;
|
|
24
|
+
/** Share of matured jobs that never delivered. */
|
|
25
|
+
readonly nonDeliveryRate: number;
|
|
26
|
+
/** Share delivered but graded bad. */
|
|
27
|
+
readonly rejectionRate: number;
|
|
28
|
+
/**
|
|
29
|
+
* Wilson 95% interval on the non-delivery rate.
|
|
30
|
+
*
|
|
31
|
+
* A worker with three jobs and no failures has not demonstrated
|
|
32
|
+
* reliability, and a point estimate would imply it had. The interval makes
|
|
33
|
+
* a thin record look thin.
|
|
34
|
+
*/
|
|
35
|
+
readonly nonDeliveryInterval: readonly [number, number];
|
|
36
|
+
/** False when the sample is too small to support any conclusion. */
|
|
37
|
+
readonly sufficient: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Below this, a record is an anecdote rather than evidence. */
|
|
40
|
+
export declare const MIN_JOBS_FOR_A_RECORD = 20;
|
|
41
|
+
/**
|
|
42
|
+
* Wilson score interval — deliberately not the textbook normal approximation,
|
|
43
|
+
* which produces impossible bounds (below 0, above 1) exactly where these
|
|
44
|
+
* records live: very high and very low rates on small samples. The one
|
|
45
|
+
* implementation, shared with the premium curve, so the numbers never drift.
|
|
46
|
+
*/
|
|
47
|
+
export declare const WILSON_Z = 1.959963984540054;
|
|
48
|
+
/**
|
|
49
|
+
* The 95 % Wilson score interval on k events in n trials: @taifoon/jev-wilson's `wilson`, the same arithmetic as
|
|
50
|
+
* /v1/pools/quote. [0, 1] when n is 0. Kept as a name for the studio's folds and the onboard module.
|
|
51
|
+
*/
|
|
52
|
+
export declare function wilsonScore(k: number, n: number, z?: number): [number, number];
|
|
53
|
+
/** Build one worker's record from decoded job history. */
|
|
54
|
+
export declare function trackRecordFor(provider: Address, history: readonly TaskState[], clock: Clock): TrackRecord;
|
|
55
|
+
/** Every worker in the history, worst record first. */
|
|
56
|
+
export declare function trackRecords(history: readonly TaskState[], clock: Clock): readonly TrackRecord[];
|
|
57
|
+
export interface ConcentrationReport {
|
|
58
|
+
readonly providers: number;
|
|
59
|
+
readonly jobs: number;
|
|
60
|
+
/** Share of all jobs from the single busiest worker. */
|
|
61
|
+
readonly topShare: number;
|
|
62
|
+
/**
|
|
63
|
+
* True when one worker dominates enough that an aggregate rate is really
|
|
64
|
+
* a statement about that worker.
|
|
65
|
+
*/
|
|
66
|
+
readonly dominated: boolean;
|
|
67
|
+
readonly topProvider?: Address;
|
|
68
|
+
}
|
|
69
|
+
/** Above this share, the average is mostly one participant's behaviour. */
|
|
70
|
+
export declare const DOMINANCE_THRESHOLD = 0.4;
|
|
71
|
+
/**
|
|
72
|
+
* Is an aggregate over this history meaningful, or is it one worker?
|
|
73
|
+
*
|
|
74
|
+
* Worth running before quoting any market-wide rate. On live traffic this
|
|
75
|
+
* returns `dominated: true`, which is why the SDK does not publish a single
|
|
76
|
+
* failure rate.
|
|
77
|
+
*/
|
|
78
|
+
export declare function concentrationOf(history: readonly TaskState[], clock: Clock): ConcentrationReport;
|
|
79
|
+
//# sourceMappingURL=track-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track-record.d.ts","sourceRoot":"","sources":["../../src/actors/track-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAA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AAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,mBAAmB,CAoBhG"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { sameAddress } from '../acp/hex.js';
|
|
2
|
+
import { toOutcome } from '../acp/outcome.js';
|
|
3
|
+
import { wilson, Z } from '@taifoon/jev-wilson';
|
|
4
|
+
/** Below this, a record is an anecdote rather than evidence. */
|
|
5
|
+
export const MIN_JOBS_FOR_A_RECORD = 20;
|
|
6
|
+
/**
|
|
7
|
+
* Wilson score interval — deliberately not the textbook normal approximation,
|
|
8
|
+
* which produces impossible bounds (below 0, above 1) exactly where these
|
|
9
|
+
* records live: very high and very low rates on small samples. The one
|
|
10
|
+
* implementation, shared with the premium curve, so the numbers never drift.
|
|
11
|
+
*/
|
|
12
|
+
export const WILSON_Z = Z;
|
|
13
|
+
/**
|
|
14
|
+
* The 95 % Wilson score interval on k events in n trials: @taifoon/jev-wilson's `wilson`, the same arithmetic as
|
|
15
|
+
* /v1/pools/quote. [0, 1] when n is 0. Kept as a name for the studio's folds and the onboard module.
|
|
16
|
+
*/
|
|
17
|
+
export function wilsonScore(k, n, z = WILSON_Z) {
|
|
18
|
+
return wilson(k, n, z);
|
|
19
|
+
}
|
|
20
|
+
/** Was this job funded and given its full time to deliver? */
|
|
21
|
+
function isMatured(state, nowSeconds) {
|
|
22
|
+
const funded = state.escrow !== 'none' ||
|
|
23
|
+
state.work === 'funded' ||
|
|
24
|
+
state.work === 'submitted' ||
|
|
25
|
+
state.work === 'graded' ||
|
|
26
|
+
state.work === 'expired';
|
|
27
|
+
return funded && state.deadline !== undefined && state.deadline < nowSeconds;
|
|
28
|
+
}
|
|
29
|
+
/** Build one worker's record from decoded job history. */
|
|
30
|
+
export function trackRecordFor(provider, history, clock) {
|
|
31
|
+
let delivered = 0;
|
|
32
|
+
let expired = 0;
|
|
33
|
+
let rejected = 0;
|
|
34
|
+
for (const state of history) {
|
|
35
|
+
if (!sameAddress(state.provider, provider))
|
|
36
|
+
continue;
|
|
37
|
+
if (!isMatured(state, clock.now))
|
|
38
|
+
continue;
|
|
39
|
+
const outcome = toOutcome(state, clock);
|
|
40
|
+
switch (outcome.verdict) {
|
|
41
|
+
case 'doneRight':
|
|
42
|
+
delivered += 1;
|
|
43
|
+
break;
|
|
44
|
+
case 'rejected':
|
|
45
|
+
rejected += 1;
|
|
46
|
+
break;
|
|
47
|
+
case 'notDelivered':
|
|
48
|
+
expired += 1;
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const matured = delivered + expired + rejected;
|
|
55
|
+
return {
|
|
56
|
+
provider,
|
|
57
|
+
matured,
|
|
58
|
+
delivered,
|
|
59
|
+
expired,
|
|
60
|
+
rejected,
|
|
61
|
+
nonDeliveryRate: matured === 0 ? 0 : expired / matured,
|
|
62
|
+
rejectionRate: matured === 0 ? 0 : rejected / matured,
|
|
63
|
+
nonDeliveryInterval: wilson(expired, matured),
|
|
64
|
+
sufficient: matured >= MIN_JOBS_FOR_A_RECORD,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Every worker in the history, worst record first. */
|
|
68
|
+
export function trackRecords(history, clock) {
|
|
69
|
+
const providers = new Set();
|
|
70
|
+
for (const state of history)
|
|
71
|
+
if (state.provider)
|
|
72
|
+
providers.add(state.provider);
|
|
73
|
+
return [...providers]
|
|
74
|
+
.map((provider) => trackRecordFor(provider, history, clock))
|
|
75
|
+
.filter((record) => record.matured > 0)
|
|
76
|
+
.sort((a, b) => b.nonDeliveryRate - a.nonDeliveryRate);
|
|
77
|
+
}
|
|
78
|
+
/** Above this share, the average is mostly one participant's behaviour. */
|
|
79
|
+
export const DOMINANCE_THRESHOLD = 0.4;
|
|
80
|
+
/**
|
|
81
|
+
* Is an aggregate over this history meaningful, or is it one worker?
|
|
82
|
+
*
|
|
83
|
+
* Worth running before quoting any market-wide rate. On live traffic this
|
|
84
|
+
* returns `dominated: true`, which is why the SDK does not publish a single
|
|
85
|
+
* failure rate.
|
|
86
|
+
*/
|
|
87
|
+
export function concentrationOf(history, clock) {
|
|
88
|
+
const records = trackRecords(history, clock);
|
|
89
|
+
const jobs = records.reduce((total, record) => total + record.matured, 0);
|
|
90
|
+
const busiest = records.reduce((best, record) => (best === undefined || record.matured > best.matured ? record : best), undefined);
|
|
91
|
+
const topShare = jobs === 0 || !busiest ? 0 : busiest.matured / jobs;
|
|
92
|
+
// With few workers a large share is arithmetic, not dominance — with two
|
|
93
|
+
// workers somebody necessarily holds at least half. Dominance means holding
|
|
94
|
+
// much more than an even split would give, which is what makes an average a
|
|
95
|
+
// statement about one participant.
|
|
96
|
+
const evenShare = records.length === 0 ? 1 : 1 / records.length;
|
|
97
|
+
return {
|
|
98
|
+
providers: records.length,
|
|
99
|
+
jobs,
|
|
100
|
+
topShare,
|
|
101
|
+
dominated: topShare >= DOMINANCE_THRESHOLD && topShare > evenShare * 1.5,
|
|
102
|
+
...(busiest ? { topProvider: busiest.provider } : {}),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=track-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track-record.js","sourceRoot":"","sources":["../../src/actors/track-record.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MA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AAC;KACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AssuranceAdapter, CoveragePolicy } from './port.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adapter for the Agent Commerce Protocol (ACP).
|
|
4
|
+
*
|
|
5
|
+
* ACP runs a job through four phases — Request, Negotiation, Transaction,
|
|
6
|
+
* Evaluation — across three roles: Client, Provider, Evaluator. Payment sits in
|
|
7
|
+
* an escrow wallet and is released when the evaluator approves; if the provider
|
|
8
|
+
* misses the SLA or the job expires, escrow refunds the client.
|
|
9
|
+
*
|
|
10
|
+
* That covers the price of the job. What it does not cover is the *cost of the
|
|
11
|
+
* failure* — the campaign that missed its slot, the fill that never happened —
|
|
12
|
+
* and it leaves the evaluator with no capital behind its verdict. Those two
|
|
13
|
+
* gaps are what this adapter hands to the assurance core.
|
|
14
|
+
*/
|
|
15
|
+
/** ACP job phases, in lifecycle order. */
|
|
16
|
+
export type AcpPhase = 'request' | 'negotiation' | 'transaction' | 'evaluation' | 'completed' | 'rejected' | 'expired';
|
|
17
|
+
/** The subset of an ACP job the adapter needs. Deliberately structural. */
|
|
18
|
+
export interface AcpJob {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
/** Agreed price in USDC minor units (6 decimals). */
|
|
21
|
+
readonly priceUsdc: bigint;
|
|
22
|
+
readonly phase: AcpPhase;
|
|
23
|
+
/** Hash of the cryptographically signed Proof of Agreement. */
|
|
24
|
+
readonly proofOfAgreement?: string;
|
|
25
|
+
/** Unix seconds by which the provider must deliver. */
|
|
26
|
+
readonly slaDeadline?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What the evaluator said.
|
|
30
|
+
*
|
|
31
|
+
* `score` is optional because ACP evaluators approve or reject; a numeric score
|
|
32
|
+
* is extra signal some evaluators provide. When present it is advisory only —
|
|
33
|
+
* `approved` is the field that settles the job. A rejection that a challenger
|
|
34
|
+
* later overturns is handled by the core, not here.
|
|
35
|
+
*/
|
|
36
|
+
export interface AcpEvaluation {
|
|
37
|
+
readonly approved: boolean;
|
|
38
|
+
readonly score?: number;
|
|
39
|
+
readonly reasoning?: string;
|
|
40
|
+
/** True when the job ended by SLA expiry rather than a verdict. */
|
|
41
|
+
readonly expired?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** A sensible starting policy: 1% premium, 40% provider bond, small caps. */
|
|
44
|
+
export declare const DEFAULT_ACP_POLICY: CoveragePolicy;
|
|
45
|
+
export declare const acpAdapter: AssuranceAdapter<AcpJob, AcpEvaluation>;
|
|
46
|
+
/** Whether an ACP job is eligible for cover under a policy. */
|
|
47
|
+
export declare function isInsurable(job: AcpJob, policy?: CoveragePolicy): boolean;
|
|
48
|
+
//# sourceMappingURL=acp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.d.ts","sourceRoot":"","sources":["../../src/adapters/acp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAElE;;;;;;;;;;;;GAYG;AAEH,0CAA0C;AAC1C,MAAM,MAAM,QAAQ,GAChB,SAAS,GACT,aAAa,GACb,aAAa,GACb,YAAY,GACZ,WAAW,GACX,UAAU,GACV,SAAS,CAAC;AAEd,2EAA2E;AAC3E,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,uDAAuD;IACvD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,EAAE,cAO/B,CAAC;AAeH,eAAO,MAAM,UAAU,EAAE,gBAAgB,CAAC,MAAM,EAAE,aAAa,CA2C9D,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,cAAmC,GAAG,OAAO,CAE7F"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { applyBps } from '../core/money.js';
|
|
2
|
+
/** A sensible starting policy: 1% premium, 40% provider bond, small caps. */
|
|
3
|
+
export const DEFAULT_ACP_POLICY = Object.freeze({
|
|
4
|
+
premiumBps: 100,
|
|
5
|
+
depositBps: 4_000,
|
|
6
|
+
evaluatorBondBps: 2_500,
|
|
7
|
+
poolCapital: 5000000000n, // 5,000 USDC
|
|
8
|
+
maxJobValue: 1000000000n, // 1,000 USDC — Phase 2 opens with small caps
|
|
9
|
+
damageCoverBps: 7_000,
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Phases at which a job can still be insured.
|
|
13
|
+
*
|
|
14
|
+
* Cover must be bought before the outcome is known. Once a job is in evaluation
|
|
15
|
+
* or beyond, the answer is already being decided, so insuring it would be
|
|
16
|
+
* writing cover against a known result.
|
|
17
|
+
*/
|
|
18
|
+
const INSURABLE_PHASES = new Set([
|
|
19
|
+
'request',
|
|
20
|
+
'negotiation',
|
|
21
|
+
'transaction',
|
|
22
|
+
]);
|
|
23
|
+
export const acpAdapter = {
|
|
24
|
+
protocol: 'acp',
|
|
25
|
+
toTerms(job, policy) {
|
|
26
|
+
if (job.priceUsdc <= 0n)
|
|
27
|
+
return null;
|
|
28
|
+
if (job.priceUsdc > policy.maxJobValue)
|
|
29
|
+
return null;
|
|
30
|
+
// Below a certain size the premium rounds away to nothing and the cover
|
|
31
|
+
// becomes free — an underwriter would then be carrying real damage
|
|
32
|
+
// exposure for zero income, at whatever volume an attacker cares to
|
|
33
|
+
// generate. Rounding down is correct (never mint a unit nobody funded), so
|
|
34
|
+
// the fix belongs here: decline the job rather than insure it for free.
|
|
35
|
+
// Live agent jobs are genuinely this small, so this is not hypothetical.
|
|
36
|
+
if (applyBps(job.priceUsdc, policy.premiumBps) <= 0n)
|
|
37
|
+
return null;
|
|
38
|
+
if (!INSURABLE_PHASES.has(job.phase))
|
|
39
|
+
return null;
|
|
40
|
+
// No signed agreement means no agreed terms to grade against, so there is
|
|
41
|
+
// nothing an evaluator could be held to.
|
|
42
|
+
if (!job.proofOfAgreement)
|
|
43
|
+
return null;
|
|
44
|
+
// No deadline means a job can never be "late", and the deadline is what
|
|
45
|
+
// resolves a job when an evaluator goes silent.
|
|
46
|
+
if (job.slaDeadline === undefined)
|
|
47
|
+
return null;
|
|
48
|
+
return {
|
|
49
|
+
pay: job.priceUsdc,
|
|
50
|
+
premium: applyBps(job.priceUsdc, policy.premiumBps),
|
|
51
|
+
deposit: applyBps(job.priceUsdc, policy.depositBps),
|
|
52
|
+
evaluatorBond: applyBps(job.priceUsdc, policy.evaluatorBondBps),
|
|
53
|
+
poolCapital: policy.poolCapital,
|
|
54
|
+
damage: applyBps(job.priceUsdc, policy.damageCoverBps),
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
toVerdict(outcome) {
|
|
58
|
+
// SLA expiry is ACP's own refund path: everyone walks back whole. It is
|
|
59
|
+
// explicitly NOT cheating — nobody is punished for a job that expired.
|
|
60
|
+
if (outcome.expired)
|
|
61
|
+
return 'notDelivered';
|
|
62
|
+
// A bare rejection is `rejected`, never `cheated`. An evaluator can refuse
|
|
63
|
+
// without posting proof and without cost, so its refusal alone cannot
|
|
64
|
+
// charge a coverage pool. `cheated` is reserved for the one on-chain fact
|
|
65
|
+
// where a neutral third party found against the provider — an adjudication
|
|
66
|
+
// in the client's favour (see acp/outcome.ts).
|
|
67
|
+
return outcome.approved ? 'doneRight' : 'rejected';
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
/** Whether an ACP job is eligible for cover under a policy. */
|
|
71
|
+
export function isInsurable(job, policy = DEFAULT_ACP_POLICY) {
|
|
72
|
+
return acpAdapter.toTerms(job, policy) !== null;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=acp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.js","sourceRoot":"","sources":["../../src/adapters/acp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAwD5C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAmB,MAAM,CAAC,MAAM,CAAC;IAC9D,UAAU,EAAE,GAAG;IACf,UAAU,EAAE,KAAK;IACjB,gBAAgB,EAAE,KAAK;IACvB,WAAW,EAAE,WAAc,EAAE,aAAa;IAC1C,WAAW,EAAE,WAAc,EAAE,6CAA6C;IAC1E,cAAc,EAAE,KAAK;CACtB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,gBAAgB,GAA0B,IAAI,GAAG,CAAW;IAChE,SAAS;IACT,aAAa;IACb,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,UAAU,GAA4C;IACjE,QAAQ,EAAE,KAAK;IAEf,OAAO,CAAC,GAAW,EAAE,MAAsB;QACzC,IAAI,GAAG,CAAC,SAAS,IAAI,EAAE;YAAE,OAAO,IAAI,CAAC;QACrC,IAAI,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC;QAEpD,wEAAwE;QACxE,mEAAmE;QACnE,oEAAoE;QACpE,2EAA2E;QAC3E,wEAAwE;QACxE,yEAAyE;QACzE,IAAI,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,UAA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1,53 @@
|
|
|
1
|
+
import type { JobTerms, Verdict } from '../core/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The adapter port.
|
|
4
|
+
*
|
|
5
|
+
* An adapter's whole job is translation: take whatever a host protocol calls
|
|
6
|
+
* its job, and say what it is in assurance terms — a price, a judge, a
|
|
7
|
+
* deadline. It does not settle anything; settlement is the core's business.
|
|
8
|
+
*
|
|
9
|
+
* A caution worth keeping in the code: one adapter is a hypothetical seam, two
|
|
10
|
+
* is a real one. This interface is deliberately minimal because it currently
|
|
11
|
+
* has exactly one implementation (ACP). Resist widening it to fit a second
|
|
12
|
+
* protocol until that protocol actually exists and its shape is known — the
|
|
13
|
+
* cheapest time to fix an interface is before anyone depends on it.
|
|
14
|
+
*/
|
|
15
|
+
export interface AssuranceAdapter<HostJob, HostOutcome> {
|
|
16
|
+
/** Stable identifier for the host protocol, e.g. "acp". */
|
|
17
|
+
readonly protocol: string;
|
|
18
|
+
/**
|
|
19
|
+
* Express a host protocol's job as insurable terms.
|
|
20
|
+
*
|
|
21
|
+
* Returns `null` when the job cannot be insured as presented — an unpriced
|
|
22
|
+
* job, a missing deadline, a bond below policy. Returning null rather than
|
|
23
|
+
* throwing keeps "not insurable" an ordinary answer instead of an error path,
|
|
24
|
+
* because most jobs on a host protocol will not be insured.
|
|
25
|
+
*/
|
|
26
|
+
toTerms(job: HostJob, policy: CoveragePolicy): JobTerms | null;
|
|
27
|
+
/** Map the host's own outcome onto a settlement verdict. */
|
|
28
|
+
toVerdict(outcome: HostOutcome): Verdict;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* What an underwriter is willing to cover, independent of any host protocol.
|
|
32
|
+
*
|
|
33
|
+
* Kept separate from the adapter so the same policy can be applied across
|
|
34
|
+
* protocols, and so changing appetite never means editing an adapter.
|
|
35
|
+
*/
|
|
36
|
+
export interface CoveragePolicy {
|
|
37
|
+
/** Premium charged on the job price, in basis points. */
|
|
38
|
+
readonly premiumBps: number;
|
|
39
|
+
/** Provider bond required, as basis points of the job price. */
|
|
40
|
+
readonly depositBps: number;
|
|
41
|
+
/** Evaluator bond required, as basis points of the job price. */
|
|
42
|
+
readonly evaluatorBondBps: number;
|
|
43
|
+
/** Capital standing behind the provider for this job. */
|
|
44
|
+
readonly poolCapital: bigint;
|
|
45
|
+
/** Largest job price the policy will cover. Bigger jobs are declined. */
|
|
46
|
+
readonly maxJobValue: bigint;
|
|
47
|
+
/**
|
|
48
|
+
* Consequential loss covered, as basis points of the job price.
|
|
49
|
+
* This is the part a bare escrow refund does not address.
|
|
50
|
+
*/
|
|
51
|
+
readonly damageCoverBps: number;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port.d.ts","sourceRoot":"","sources":["../../src/adapters/port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE1D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB,CAAC,OAAO,EAAE,WAAW;IACpD,2DAA2D;IAC3D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,GAAG,QAAQ,GAAG,IAAI,CAAC;IAE/D,4DAA4D;IAC5D,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC;CAC1C;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,iEAAiE;IACjE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,yDAAyD;IACzD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port.js","sourceRoot":"","sources":["../../src/adapters/port.ts"],"names":[],"mappings":""}
|