@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,64 @@
|
|
|
1
|
+
import type { EvaluatorCall, FactsInput, GradeInput, Network, Receipt, Recorded, UnsignedCall, Verification } from '@taifoon/jev';
|
|
2
|
+
/** Moonbeam ACP on Base: the hook, the GLMR token, its tenant. */
|
|
3
|
+
export declare const MOONBEAM_JUDGE: Readonly<{
|
|
4
|
+
tenant: "moonbeam";
|
|
5
|
+
chainId: 8453;
|
|
6
|
+
hook: "0xc0578657Eda85e0a246771aa1839ce79b54eE80d";
|
|
7
|
+
token: Readonly<{
|
|
8
|
+
symbol: "GLMR";
|
|
9
|
+
address: "0xB3846fD356c2149ee8D30b0449088Dc74e265459";
|
|
10
|
+
decimals: 18;
|
|
11
|
+
}>;
|
|
12
|
+
}>;
|
|
13
|
+
export type GradeJobInput = Omit<GradeInput, 'subject' | 'caller'> & {
|
|
14
|
+
jobId: string;
|
|
15
|
+
};
|
|
16
|
+
/** Grade one job on the hook: facts first (a failed check rejects without asking Jev), then RUBRIC_v1, then the receipt. */
|
|
17
|
+
export declare function gradeJob(input: GradeJobInput): Promise<Receipt>;
|
|
18
|
+
/** The deterministic checks for a job: delivered, and whatever the job's class can prove (values or functions). */
|
|
19
|
+
export declare const jobFacts: (input: FactsInput) => Promise<import("@taifoon/jev").Facts>;
|
|
20
|
+
/** The unsigned record calls for a graded job (network: none | devnet | base | both; default devnet). */
|
|
21
|
+
export declare const recordGrade: (receipt: Receipt, opts?: {
|
|
22
|
+
network?: Network;
|
|
23
|
+
uri?: string;
|
|
24
|
+
send?: (call: UnsignedCall) => Promise<string>;
|
|
25
|
+
}) => Promise<Recorded>;
|
|
26
|
+
/**
|
|
27
|
+
* The call that ends the job on the hook: complete(jobId) for complete, reject(jobId, digest) for reject — the digest is
|
|
28
|
+
* the decision digest (or the receipt hash when facts alone decided). null for needs_review: the job stays held until
|
|
29
|
+
* the buyer or an evaluator decides, or anyone expires it after the deadline.
|
|
30
|
+
*/
|
|
31
|
+
export declare function endJob(jobId: string, receipt: Pick<Receipt, 'verdict' | 'decision' | 'receiptHash'>): EvaluatorCall | null;
|
|
32
|
+
/** Recompute every digest in a receipt (or take an answers digest) and find the log rows that hold it. */
|
|
33
|
+
/**
|
|
34
|
+
* Recompute every fingerprint of a receipt and find its record on chain. `x` is a receipt, or a recorded answers
|
|
35
|
+
* digest (32 bytes) to look up. Moonbeam lives on Base, so the lookup reads Base unless you pass network 'devnet'.
|
|
36
|
+
*/
|
|
37
|
+
export declare const verifyGrade: (x: Receipt | string, opts?: {
|
|
38
|
+
rpc?: string;
|
|
39
|
+
chain?: boolean;
|
|
40
|
+
network?: "base" | "devnet";
|
|
41
|
+
}) => Promise<Verification>;
|
|
42
|
+
export type { Receipt, Recorded, EvaluatorCall, Verification, FactsInput };
|
|
43
|
+
/** keccak256 of the UTF-8 bytes of a text (the task, or the delivery whose digest the seller seals with submit). */
|
|
44
|
+
export declare const textDigest: (text: string) => string;
|
|
45
|
+
/** The exact text the job's buyer signs (EIP-191 personal_sign) to bind a task to one hook job. */
|
|
46
|
+
export declare function taskMessage(p: {
|
|
47
|
+
jobId: string;
|
|
48
|
+
task: string;
|
|
49
|
+
chainId?: number;
|
|
50
|
+
hook?: string;
|
|
51
|
+
}): string;
|
|
52
|
+
/** The body a partner sends to put a job's task and delivery in its record; `task_signature` is the buyer's signature over taskMessage(). */
|
|
53
|
+
export declare function jobRecordBody(p: {
|
|
54
|
+
task?: string;
|
|
55
|
+
taskSignature?: string;
|
|
56
|
+
delivery?: string;
|
|
57
|
+
chainId?: number;
|
|
58
|
+
}): {
|
|
59
|
+
chainId: number;
|
|
60
|
+
task?: string;
|
|
61
|
+
task_signature?: string;
|
|
62
|
+
delivery?: string;
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
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GAAG,QAAQ,CAAA;CAAO,KAAG,OAAO,CAAC,YAAY,CACxF,CAAC;AAE1D,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AAQ3E,oHAAoH;AACpH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,KAAG,MAAwE,CAAC;AAEnH,mGAAmG;AACnG,wBAAgB,WAAW,CAAC,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAGvG;AAED,6IAA6I;AAC7I,wBAAgB,aAAa,CAAC,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAE/L"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The judge for Moonbeam's assurance hook on Base: Jev (TypeSafe System One, calibrated closed answers) graded against
|
|
3
|
+
* the published RUBRIC_v1, composed in code under THRESHOLDS_v1, recorded on the answer and decision logs, and turned
|
|
4
|
+
* into the one call that ends a GLMR job on the hook — complete(jobId) or reject(jobId, digest).
|
|
5
|
+
*
|
|
6
|
+
* The same five calls as the Jev SDK, bound to Moonbeam: the subject is (Base, the hook, the job id), the recorder is
|
|
7
|
+
* "moonbeam", the evaluator call goes to the hook. Nothing here signs: the job's buyer or a hook evaluator does.
|
|
8
|
+
*/
|
|
9
|
+
import { evaluatorCall, facts, grade, record, verify } from '@taifoon/jev';
|
|
10
|
+
import { keccak256Hex } from '../adapters/stamp.js';
|
|
11
|
+
/** Moonbeam ACP on Base: the hook, the GLMR token, its tenant. */
|
|
12
|
+
export const MOONBEAM_JUDGE = Object.freeze({
|
|
13
|
+
tenant: 'moonbeam',
|
|
14
|
+
chainId: 8453,
|
|
15
|
+
hook: '0xc0578657Eda85e0a246771aa1839ce79b54eE80d',
|
|
16
|
+
token: Object.freeze({ symbol: 'GLMR', address: '0xB3846fD356c2149ee8D30b0449088Dc74e265459', decimals: 18 }),
|
|
17
|
+
});
|
|
18
|
+
const JOB_ID = /^0x[0-9a-fA-F]{64}$/;
|
|
19
|
+
const jobIdOf = (jobId) => {
|
|
20
|
+
if (!JOB_ID.test(jobId))
|
|
21
|
+
throw new Error(`a Moonbeam job id is the hook's 32-byte id, got ${jobId.slice(0, 20)}`);
|
|
22
|
+
return jobId.toLowerCase();
|
|
23
|
+
};
|
|
24
|
+
/** Grade one job on the hook: facts first (a failed check rejects without asking Jev), then RUBRIC_v1, then the receipt. */
|
|
25
|
+
export async function gradeJob(input) {
|
|
26
|
+
const { jobId, ...rest } = input;
|
|
27
|
+
return grade({ ...rest, subject: { chainId: MOONBEAM_JUDGE.chainId, at: MOONBEAM_JUDGE.hook, ref: jobIdOf(jobId) }, caller: MOONBEAM_JUDGE.tenant });
|
|
28
|
+
}
|
|
29
|
+
/** The deterministic checks for a job: delivered, and whatever the job's class can prove (values or functions). */
|
|
30
|
+
export const jobFacts = (input) => facts(input);
|
|
31
|
+
/** The unsigned record calls for a graded job (network: none | devnet | base | both; default devnet). */
|
|
32
|
+
export const recordGrade = (receipt, opts = {}) => record(receipt, opts);
|
|
33
|
+
/**
|
|
34
|
+
* The call that ends the job on the hook: complete(jobId) for complete, reject(jobId, digest) for reject — the digest is
|
|
35
|
+
* the decision digest (or the receipt hash when facts alone decided). null for needs_review: the job stays held until
|
|
36
|
+
* the buyer or an evaluator decides, or anyone expires it after the deadline.
|
|
37
|
+
*/
|
|
38
|
+
export function endJob(jobId, receipt) {
|
|
39
|
+
return evaluatorCall('assurance-hook', jobIdOf(jobId), receipt.verdict, receipt.decision?.digest ?? receipt.receiptHash, { to: MOONBEAM_JUDGE.hook, chainId: MOONBEAM_JUDGE.chainId });
|
|
40
|
+
}
|
|
41
|
+
/** Recompute every digest in a receipt (or take an answers digest) and find the log rows that hold it. */
|
|
42
|
+
/**
|
|
43
|
+
* Recompute every fingerprint of a receipt and find its record on chain. `x` is a receipt, or a recorded answers
|
|
44
|
+
* digest (32 bytes) to look up. Moonbeam lives on Base, so the lookup reads Base unless you pass network 'devnet'.
|
|
45
|
+
*/
|
|
46
|
+
export const verifyGrade = (x, opts = {}) => verify(x, { ...opts, network: opts.network ?? 'base' });
|
|
47
|
+
// ── the job's record: the task and the delivery, for a hook that stores neither ─────────────────────────────────────
|
|
48
|
+
// The hook keeps the parties, the amounts, the deadline and a 32-byte evidence digest, never the task. A grader that
|
|
49
|
+
// reads only the chain then cannot tell what was asked. The job's record carries both, each bound so a reader can
|
|
50
|
+
// check it: the delivery's keccak256 must equal the evidence digest the seller sealed with submit, and the task is
|
|
51
|
+
// signed by the job's buyer (EIP-191) over taskMessage(). These are pure; the buyer's own wallet signs the message.
|
|
52
|
+
/** keccak256 of the UTF-8 bytes of a text (the task, or the delivery whose digest the seller seals with submit). */
|
|
53
|
+
export const textDigest = (text) => keccak256Hex('0x' + Buffer.from(text, 'utf8').toString('hex'));
|
|
54
|
+
/** The exact text the job's buyer signs (EIP-191 personal_sign) to bind a task to one hook job. */
|
|
55
|
+
export function taskMessage(p) {
|
|
56
|
+
const chainId = p.chainId ?? MOONBEAM_JUDGE.chainId;
|
|
57
|
+
const hook = (p.hook ?? MOONBEAM_JUDGE.hook).toLowerCase();
|
|
58
|
+
return ['ERC-8183 assurance-hook job: the task the buyer asked for', `chain: ${chainId}`, `hook: ${hook}`, `job: ${p.jobId.toLowerCase()}`, `task keccak256: ${textDigest(p.task)}`].join('\n');
|
|
59
|
+
}
|
|
60
|
+
/** The body a partner sends to put a job's task and delivery in its record; `task_signature` is the buyer's signature over taskMessage(). */
|
|
61
|
+
export function jobRecordBody(p) {
|
|
62
|
+
return { chainId: p.chainId ?? MOONBEAM_JUDGE.chainId, ...(p.task !== undefined ? { task: p.task } : {}), ...(p.taskSignature ? { task_signature: p.taskSignature } : {}), ...(p.delivery !== undefined ? { delivery: p.delivery } : {}) };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/judge/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,kEAAkE;AAClE,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,4CAA4C;IAClD,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,4CAA4C,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;CAC9G,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,qBAAqB,CAAC;AACrC,MAAM,OAAO,GAAG,CAAC,KAAa,EAAU,EAAE;IACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;IAClH,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC,CAAC;AAIF,4HAA4H;AAC5H,MAAM,CAAC,KAAK,UAAU,QAAQ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
|
+
import type { ClientIntent, ProviderIntent, BackerIntent, EvaluatorIntent, Readiness } from '../onboarding/index.js';
|
|
2
|
+
export declare const PHASES: readonly ["discover", "quote", "fund", "submit", "judge", "settle", "trail"];
|
|
3
|
+
export type Phase = (typeof PHASES)[number];
|
|
4
|
+
export declare const LAUNCH_ROLES: readonly ["client", "provider", "backer", "evaluator"];
|
|
5
|
+
export type LaunchRole = (typeof LAUNCH_ROLES)[number];
|
|
6
|
+
/** What a phase means, in the words the surface uses. */
|
|
7
|
+
export declare const PHASE_MEANING: Readonly<Record<Phase, {
|
|
8
|
+
title: string;
|
|
9
|
+
what: string;
|
|
10
|
+
}>>;
|
|
11
|
+
/** The phase a party acts in, and what they do there. `null` = they watch. */
|
|
12
|
+
export declare const ROLE_STEPS: Readonly<Record<LaunchRole, Readonly<Record<Phase, string | null>>>>;
|
|
13
|
+
export type LaunchIntent = {
|
|
14
|
+
role: 'client';
|
|
15
|
+
intent: ClientIntent;
|
|
16
|
+
} | {
|
|
17
|
+
role: 'provider';
|
|
18
|
+
intent: ProviderIntent;
|
|
19
|
+
} | {
|
|
20
|
+
role: 'backer';
|
|
21
|
+
intent: BackerIntent;
|
|
22
|
+
} | {
|
|
23
|
+
role: 'evaluator';
|
|
24
|
+
intent: EvaluatorIntent;
|
|
25
|
+
};
|
|
26
|
+
export interface LaunchPlan {
|
|
27
|
+
role: LaunchRole;
|
|
28
|
+
readiness: Readiness;
|
|
29
|
+
/** true when nothing blocks; cautions may remain */
|
|
30
|
+
canStart: boolean;
|
|
31
|
+
steps: ReadonlyArray<{
|
|
32
|
+
phase: Phase;
|
|
33
|
+
title: string;
|
|
34
|
+
what: string;
|
|
35
|
+
you: string | null;
|
|
36
|
+
status: 'ready' | 'blocked' | 'watch';
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
/** The readiness checks for the role, then the phase list with what this party does in each. */
|
|
40
|
+
export declare function launchFor(l: LaunchIntent): LaunchPlan;
|
|
41
|
+
/** The ERC-8183 lifecycle events a trail is made of (names as the standard emits them). */
|
|
42
|
+
export type TrailEvent = 'JobCreated' | 'BudgetSet' | 'JobFunded' | 'JobSubmitted' | 'JobCompleted' | 'PaymentReleased' | 'Refunded' | 'JobExpired' | 'JobRejected';
|
|
43
|
+
export declare const ENDINGS: readonly ["delivered_as_specified", "delivered_with_defects", "not_delivered", "cannot_determine"];
|
|
44
|
+
export type Ending = (typeof ENDINGS)[number];
|
|
45
|
+
export interface Decision {
|
|
46
|
+
ending: Ending;
|
|
47
|
+
/** 'trail' = decided by the events alone (anyone re-derives it); 'judge' = the trail cannot decide, a graded verdict is needed */
|
|
48
|
+
decidedBy: 'trail' | 'judge';
|
|
49
|
+
basis: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The deterministic decoder. The same rules on every chain, in this order:
|
|
53
|
+
* JobCompleted or PaymentReleased → delivered as specified (the buyer accepted and the escrow paid)
|
|
54
|
+
* JobSubmitted then Refunded/JobRejected → delivered with defects (work arrived and was refused)
|
|
55
|
+
* no submission, then Refunded/Expired → not delivered (nothing arrived)
|
|
56
|
+
* JobSubmitted then JobExpired → the trail cannot say; a grade is needed
|
|
57
|
+
* anything still open → the trail cannot say yet
|
|
58
|
+
* A trail decides the money; it never decides whether the work was good. That is why every
|
|
59
|
+
* undecided case is routed to the judge instead of guessed.
|
|
60
|
+
*/
|
|
61
|
+
export declare function endingFromTrail(events: readonly TrailEvent[]): Decision;
|
|
62
|
+
/** A grade as the judge returns it: one closed question, a distribution over the answers, a confidence. */
|
|
63
|
+
export interface GradeAnswer {
|
|
64
|
+
value: Ending;
|
|
65
|
+
probabilities: Readonly<Partial<Record<Ending, number>>>;
|
|
66
|
+
confidence: number;
|
|
67
|
+
}
|
|
68
|
+
export interface Comparison {
|
|
69
|
+
trail: Decision;
|
|
70
|
+
grade: GradeAnswer;
|
|
71
|
+
/** the grade names the same ending the trail settled */
|
|
72
|
+
agree: boolean;
|
|
73
|
+
/** the grade abstained (cannot_determine) — the right answer when the work is not on chain */
|
|
74
|
+
abstained: boolean;
|
|
75
|
+
/** the grade clears the bar the surface applies before it acts on a grade */
|
|
76
|
+
clearsBar: boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare const GRADE_BAR = 0.8;
|
|
79
|
+
/** DET against the grade, the comparison the study makes for every real job. */
|
|
80
|
+
export declare function compare(events: readonly TrailEvent[], grade: GradeAnswer, bar?: number): Comparison;
|
|
81
|
+
/** The ending's effect on the money, in the launcher's words (mirrors the settlement rules; a grade never touches a pool). */
|
|
82
|
+
export declare const ENDING_EFFECT: Readonly<Record<Ending, string>>;
|
|
83
|
+
export type CaseKind = 'trail' | 'graded' | 'attested';
|
|
84
|
+
export interface LaunchCase {
|
|
85
|
+
id: string;
|
|
86
|
+
chainId: number;
|
|
87
|
+
kind: CaseKind;
|
|
88
|
+
title: string;
|
|
89
|
+
decision: Decision;
|
|
90
|
+
grade?: GradeAnswer;
|
|
91
|
+
comparison?: Comparison;
|
|
92
|
+
}
|
|
93
|
+
/** Fold a job row (its events and, if present, its grade) into a case the surface can render. */
|
|
94
|
+
export declare function caseFor(row: {
|
|
95
|
+
id: string;
|
|
96
|
+
chainId: number;
|
|
97
|
+
events: readonly TrailEvent[];
|
|
98
|
+
grade?: GradeAnswer;
|
|
99
|
+
title?: string;
|
|
100
|
+
}): LaunchCase;
|
|
101
|
+
/** Counts the surface prints above a case list. */
|
|
102
|
+
export declare function summarise(cases: readonly LaunchCase[]): {
|
|
103
|
+
total: number;
|
|
104
|
+
byKind: Record<CaseKind, number>;
|
|
105
|
+
agree: number;
|
|
106
|
+
abstained: number;
|
|
107
|
+
disagree: number;
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/launcher/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,E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E,GAAG,SAAY,GAAG,UAAU,CAItG;AAED,8HAA8H;AAC9H,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKzD,CAAC;AAIH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEvD,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,iGAAiG;AACjG,wBAAgB,OAAO,CAAC,GAAG,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,CAM5I;AAED,mDAAmD;AACnD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAQ/J"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The launcher — one insured job, phase by phase, for every party.
|
|
3
|
+
*
|
|
4
|
+
* This module is the spine of the onboarding surface: it says which phases a
|
|
5
|
+
* job passes through, what each party does in each phase, whether they
|
|
6
|
+
* are allowed to start (the readiness checks refuse before capital moves),
|
|
7
|
+
* and how a job's ending is decided — by the trail alone when the chain can
|
|
8
|
+
* show it, by a graded verdict when it cannot.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is pure and browser-safe: no chain, no keys, no hashing.
|
|
11
|
+
* The digest, the stamp and the feedback call live in `adapters/stamp` and run
|
|
12
|
+
* where a hash library exists (a server, a wallet); the launcher only says
|
|
13
|
+
* when they are due.
|
|
14
|
+
*/
|
|
15
|
+
import { readinessForClient, readinessForProvider, readinessForBacker, readinessForEvaluator, blockers } from '../onboarding/index.js';
|
|
16
|
+
// ── Phases ────────────────────────────────────────────────────────────────────
|
|
17
|
+
export const PHASES = ['discover', 'quote', 'fund', 'submit', 'judge', 'settle', 'trail'];
|
|
18
|
+
export const LAUNCH_ROLES = ['client', 'provider', 'backer', 'evaluator'];
|
|
19
|
+
/** What a phase means, in the words the surface uses. */
|
|
20
|
+
export const PHASE_MEANING = Object.freeze({
|
|
21
|
+
discover: { title: 'Discover', what: 'Find who can do the work: registered agents with a live endpoint and a record you can read.' },
|
|
22
|
+
quote: { title: 'Quote', what: 'Price the job and its guarantee from the seller’s own record: an interval, never a point estimate.' },
|
|
23
|
+
fund: { title: 'Fund', what: 'Lock the price and premium in escrow; the seller locks its deposit. Nothing moves until both are in.' },
|
|
24
|
+
submit: { title: 'Submit', what: 'The seller delivers and pins a digest of the deliverable on chain.' },
|
|
25
|
+
judge: { title: 'Judge', what: 'Decide the ending: from the trail when the chain can show it, from a graded verdict when it cannot.' },
|
|
26
|
+
settle: { title: 'Settle', what: 'The ending moves the money: seller paid or buyer refunded, deposit returned or held.' },
|
|
27
|
+
trail: { title: 'Trail', what: 'The grade, its question and its distribution are pinned by digest where anyone can recompute them.' },
|
|
28
|
+
});
|
|
29
|
+
/** The phase a party acts in, and what they do there. `null` = they watch. */
|
|
30
|
+
export const ROLE_STEPS = Object.freeze({
|
|
31
|
+
client: {
|
|
32
|
+
discover: 'Pick a seller from its record, not its rank.',
|
|
33
|
+
quote: 'Read the premium interval; a thin record is priced as unknown, never refused.',
|
|
34
|
+
fund: 'Sign the escrow lock: price plus premium.',
|
|
35
|
+
submit: null,
|
|
36
|
+
judge: 'If the work declared a check, re-run it. Otherwise the grade decides; you sign what it fills in.',
|
|
37
|
+
settle: null,
|
|
38
|
+
trail: 'Keep the digest; it is your receipt.',
|
|
39
|
+
},
|
|
40
|
+
provider: {
|
|
41
|
+
discover: 'Be findable: a card with a live endpoint and the skills you actually deliver.',
|
|
42
|
+
quote: 'Your record sets the premium. Every settled job narrows it.',
|
|
43
|
+
fund: 'Approve and lock your deposit; it must exceed the price.',
|
|
44
|
+
submit: 'Deliver, and pin the deliverable’s digest.',
|
|
45
|
+
judge: null,
|
|
46
|
+
settle: 'Paid on a settled ending; deposit returned on any honest ending.',
|
|
47
|
+
trail: 'Your grades accumulate where the next buyer looks.',
|
|
48
|
+
},
|
|
49
|
+
backer: {
|
|
50
|
+
discover: 'Read a seller’s record before writing cover for it.',
|
|
51
|
+
quote: 'Cover is priced from the record; you earn the premium only on settled receipts.',
|
|
52
|
+
fund: 'Nothing of yours moves at funding.',
|
|
53
|
+
submit: null,
|
|
54
|
+
judge: 'A grade never touches a pool. Only a proven cheat can draw on cover.',
|
|
55
|
+
settle: 'Premium on a settled receipt; cover drawn only on an adjudicated loss, capped at what you wrote.',
|
|
56
|
+
trail: 'Every draw and every premium is on chain with the job it came from.',
|
|
57
|
+
},
|
|
58
|
+
evaluator: {
|
|
59
|
+
discover: null,
|
|
60
|
+
quote: null,
|
|
61
|
+
fund: null,
|
|
62
|
+
submit: null,
|
|
63
|
+
judge: 'Answer one closed question over the sealed evidence with a distribution, or abstain.',
|
|
64
|
+
settle: 'Your digest drives the ending through the adapter; an abstention refunds the buyer and lands on your record.',
|
|
65
|
+
trail: 'Model version, question and answer list pinned with the grade.',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
/** The readiness checks for the role, then the phase list with what this party does in each. */
|
|
69
|
+
export function launchFor(l) {
|
|
70
|
+
const readiness = l.role === 'client' ? readinessForClient(l.intent)
|
|
71
|
+
: l.role === 'provider' ? readinessForProvider(l.intent)
|
|
72
|
+
: l.role === 'backer' ? readinessForBacker(l.intent)
|
|
73
|
+
: readinessForEvaluator(l.intent);
|
|
74
|
+
const canStart = blockers(readiness).length === 0;
|
|
75
|
+
const steps = PHASES.map((phase) => {
|
|
76
|
+
const you = ROLE_STEPS[l.role][phase];
|
|
77
|
+
const status = you === null ? 'watch' : canStart ? 'ready' : 'blocked';
|
|
78
|
+
return { phase, title: PHASE_MEANING[phase].title, what: PHASE_MEANING[phase].what, you, status };
|
|
79
|
+
});
|
|
80
|
+
return { role: l.role, readiness, canStart, steps };
|
|
81
|
+
}
|
|
82
|
+
export const ENDINGS = ['delivered_as_specified', 'delivered_with_defects', 'not_delivered', 'cannot_determine'];
|
|
83
|
+
/**
|
|
84
|
+
* The deterministic decoder. The same rules on every chain, in this order:
|
|
85
|
+
* JobCompleted or PaymentReleased → delivered as specified (the buyer accepted and the escrow paid)
|
|
86
|
+
* JobSubmitted then Refunded/JobRejected → delivered with defects (work arrived and was refused)
|
|
87
|
+
* no submission, then Refunded/Expired → not delivered (nothing arrived)
|
|
88
|
+
* JobSubmitted then JobExpired → the trail cannot say; a grade is needed
|
|
89
|
+
* anything still open → the trail cannot say yet
|
|
90
|
+
* A trail decides the money; it never decides whether the work was good. That is why every
|
|
91
|
+
* undecided case is routed to the judge instead of guessed.
|
|
92
|
+
*/
|
|
93
|
+
export function endingFromTrail(events) {
|
|
94
|
+
const has = (e) => events.includes(e);
|
|
95
|
+
if (has('JobCompleted') || has('PaymentReleased'))
|
|
96
|
+
return { ending: 'delivered_as_specified', decidedBy: 'trail', basis: 'JobCompleted / PaymentReleased fired: the buyer accepted and the escrow paid the seller' };
|
|
97
|
+
if (has('JobSubmitted') && (has('Refunded') || has('JobRejected')))
|
|
98
|
+
return { ending: 'delivered_with_defects', decidedBy: 'trail', basis: 'JobSubmitted then Refunded without JobCompleted: work arrived and the buyer refused it' };
|
|
99
|
+
if (!has('JobSubmitted') && (has('Refunded') || has('JobExpired')))
|
|
100
|
+
return { ending: 'not_delivered', decidedBy: 'trail', basis: 'Refunded or JobExpired with no JobSubmitted: nothing arrived' };
|
|
101
|
+
if (has('JobSubmitted') && has('JobExpired'))
|
|
102
|
+
return { ending: 'cannot_determine', decidedBy: 'judge', basis: 'JobSubmitted then JobExpired: work arrived and nobody ruled; the trail cannot say whether it was good' };
|
|
103
|
+
return { ending: 'cannot_determine', decidedBy: 'judge', basis: events.length ? 'the job is still open on chain' : 'no events' };
|
|
104
|
+
}
|
|
105
|
+
export const GRADE_BAR = 0.8;
|
|
106
|
+
/** DET against the grade, the comparison the study makes for every real job. */
|
|
107
|
+
export function compare(events, grade, bar = GRADE_BAR) {
|
|
108
|
+
const trail = endingFromTrail(events);
|
|
109
|
+
const abstained = grade.value === 'cannot_determine';
|
|
110
|
+
return { trail, grade, agree: trail.decidedBy === 'trail' && grade.value === trail.ending, abstained, clearsBar: grade.confidence >= bar && (grade.probabilities[grade.value] ?? 0) >= bar };
|
|
111
|
+
}
|
|
112
|
+
/** The ending's effect on the money, in the launcher's words (mirrors the settlement rules; a grade never touches a pool). */
|
|
113
|
+
export const ENDING_EFFECT = Object.freeze({
|
|
114
|
+
delivered_as_specified: 'Settled. The seller is paid and gets its deposit back.',
|
|
115
|
+
delivered_with_defects: 'Rejected. The buyer is refunded from escrow. The seller gets its deposit back; bad work is not cheating.',
|
|
116
|
+
not_delivered: 'Rejected. Same as above. The pool pays nothing.',
|
|
117
|
+
cannot_determine: 'No grade. The buyer is refunded, nobody is paid, and the miss lands on the evaluator’s record, not the seller’s.',
|
|
118
|
+
});
|
|
119
|
+
/** Fold a job row (its events and, if present, its grade) into a case the surface can render. */
|
|
120
|
+
export function caseFor(row) {
|
|
121
|
+
const decision = endingFromTrail(row.events);
|
|
122
|
+
const comparison = row.grade ? compare(row.events, row.grade) : undefined;
|
|
123
|
+
const kind = row.grade && decision.decidedBy === 'judge' ? 'graded' : 'trail';
|
|
124
|
+
const base = { id: row.id, chainId: row.chainId, kind, title: row.title ?? `job #${row.id} on chain ${row.chainId}`, decision };
|
|
125
|
+
return { ...base, ...(row.grade ? { grade: row.grade } : {}), ...(comparison ? { comparison } : {}) };
|
|
126
|
+
}
|
|
127
|
+
/** Counts the surface prints above a case list. */
|
|
128
|
+
export function summarise(cases) {
|
|
129
|
+
const byKind = { trail: 0, graded: 0, attested: 0 };
|
|
130
|
+
let agree = 0, abstained = 0, disagree = 0;
|
|
131
|
+
for (const c of cases) {
|
|
132
|
+
byKind[c.kind]++;
|
|
133
|
+
if (c.comparison) {
|
|
134
|
+
if (c.comparison.abstained)
|
|
135
|
+
abstained++;
|
|
136
|
+
else if (c.comparison.agree)
|
|
137
|
+
agree++;
|
|
138
|
+
else
|
|
139
|
+
disagree++;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { total: cases.length, byKind, agree, abstained, disagree };
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/launcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvI,iFAAiF;AAEjF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC;AAGnG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAU,CAAC;AAGnF,yDAAyD;AACzD,MAAM,CAAC,MAAM,aAAa,GAA6D,MAAM,CAAC,MAAM,CAAC;IACnG,QAAQ,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,6FAA6F,E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have never met arrive at terms.
|
|
3
|
+
*
|
|
4
|
+
* The rest of this SDK starts at `settle()`, which takes `JobTerms` as given.
|
|
5
|
+
* This module is the step before: it is the pure state machine that turns an
|
|
6
|
+
* open intent into terms both sides are bound by, and it exists because the
|
|
7
|
+
* alternative on the floor today is that a buyer simply *names* a worker and
|
|
8
|
+
* funds the job directly. Naming works. It does not discover a price, it does
|
|
9
|
+
* not let an unknown counterparty compete, and it gives neither side a record
|
|
10
|
+
* of what was agreed before the work started.
|
|
11
|
+
*
|
|
12
|
+
* The design rule, and the reason this is not just a message bus: **a bid is an
|
|
13
|
+
* offer to be bound, so it must be checkable before it is accepted.** Every bid
|
|
14
|
+
* that enters this machine is validated against the invariants `settle()` will
|
|
15
|
+
* later assume — the deposit outweighs the job, cover is residual behind that
|
|
16
|
+
* deposit, the pool can actually pay what it promises. A bid that fails is
|
|
17
|
+
* refused by name, at the moment it is made, rather than accepted and then
|
|
18
|
+
* discovered to be unsettleable when money is already locked.
|
|
19
|
+
*
|
|
20
|
+
* That is the whole difference between negotiation and haggling: at the end of
|
|
21
|
+
* this machine you hold terms that the settlement core can already price, and
|
|
22
|
+
* an acceptance digest that neither side can quietly edit afterwards.
|
|
23
|
+
*
|
|
24
|
+
* Pure by construction: no clock, no chain, no I/O. The caller supplies the
|
|
25
|
+
* epoch. Nothing here signs anything or sends anything, so the invariants are
|
|
26
|
+
* properties you can test rather than claims you have to trust.
|
|
27
|
+
*/
|
|
28
|
+
import type { Money } from '../core/money.js';
|
|
29
|
+
import type { JobTerms } from '../core/types.js';
|
|
30
|
+
/**
|
|
31
|
+
* What a buyer publishes when it wants work done and does not yet know by whom.
|
|
32
|
+
*
|
|
33
|
+
* `capabilities` is matched against what an agent published on registration, so
|
|
34
|
+
* discovery and negotiation speak the same vocabulary rather than two.
|
|
35
|
+
*/
|
|
36
|
+
export interface Intent {
|
|
37
|
+
/** Stable id for this intent. The caller supplies it; this module never invents one. */
|
|
38
|
+
readonly id: string;
|
|
39
|
+
/** What the work is, as a digest. The spec itself lives off-chain. */
|
|
40
|
+
readonly specDigest: string;
|
|
41
|
+
/** What the buyer will accept, as a digest, sealed before any bid arrives. */
|
|
42
|
+
readonly acceptanceDigest: string;
|
|
43
|
+
/** Capabilities a bidder must have published to be eligible. */
|
|
44
|
+
readonly capabilities: readonly string[];
|
|
45
|
+
/** The most the buyer will pay for the work itself, excluding cover. */
|
|
46
|
+
readonly maxPay: Money;
|
|
47
|
+
/** What the buyer stands to lose if the work is bad. Sets the cover a bid must carry. */
|
|
48
|
+
readonly damage: Money;
|
|
49
|
+
/** Epoch after which the intent is no longer open. */
|
|
50
|
+
readonly closesAt: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* An offer to do the work on stated terms.
|
|
54
|
+
*
|
|
55
|
+
* A bid names its own bond. That is deliberate: the worker, not the buyer,
|
|
56
|
+
* decides how much it is willing to put behind its own reliability, and the
|
|
57
|
+
* floor prices that choice. A bidder that will not outweigh the job it is
|
|
58
|
+
* bidding on is telling you something, and this module makes it say it out loud
|
|
59
|
+
* rather than discovering it at settlement.
|
|
60
|
+
*/
|
|
61
|
+
export interface Bid {
|
|
62
|
+
readonly intentId: string;
|
|
63
|
+
/** The bidding agent's id, as registered. */
|
|
64
|
+
readonly agent: string;
|
|
65
|
+
/** What it will do the work for. */
|
|
66
|
+
readonly pay: Money;
|
|
67
|
+
/** What it will bond behind that work. */
|
|
68
|
+
readonly deposit: Money;
|
|
69
|
+
/** Capabilities this agent published on registration. */
|
|
70
|
+
readonly capabilities: readonly string[];
|
|
71
|
+
/** Epoch the bid was made. */
|
|
72
|
+
readonly at: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* What the cover side offers behind a given bid: the premium it charges and the
|
|
76
|
+
* capital it commits. Supplied by the caller because pricing cover is the
|
|
77
|
+
* pool's business, not this module's.
|
|
78
|
+
*/
|
|
79
|
+
export interface CoverQuote {
|
|
80
|
+
readonly premium: Money;
|
|
81
|
+
readonly poolCapital: Money;
|
|
82
|
+
readonly evaluatorBond: Money;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Why a bid cannot be accepted.
|
|
86
|
+
*
|
|
87
|
+
* Typed refusals rather than thrown strings, in the same register the rest of
|
|
88
|
+
* the protocol uses: each names the thing that caused it, so a caller can act
|
|
89
|
+
* on it without a support conversation.
|
|
90
|
+
*/
|
|
91
|
+
export type RefusalCode = 'INTENT_CLOSED' | 'WRONG_INTENT' | 'CAPABILITY_MISSING' | 'ABOVE_MAX_PAY' | 'DEPOSIT_BELOW_JOB' | 'COVER_CANNOT_PAY';
|
|
92
|
+
export interface Refusal {
|
|
93
|
+
readonly code: RefusalCode;
|
|
94
|
+
/** Plain-language reason, safe to show a person. */
|
|
95
|
+
readonly reason: string;
|
|
96
|
+
}
|
|
97
|
+
/** Where an intent is in its life. */
|
|
98
|
+
export type NegotiationPhase = 'open' | 'agreed' | 'expired';
|
|
99
|
+
export interface Negotiation {
|
|
100
|
+
readonly intent: Intent;
|
|
101
|
+
readonly phase: NegotiationPhase;
|
|
102
|
+
/** Bids that passed validation, in the order they arrived. */
|
|
103
|
+
readonly bids: readonly Bid[];
|
|
104
|
+
/** Bids that were refused, each with its reason. */
|
|
105
|
+
readonly refused: readonly (Refusal & {
|
|
106
|
+
readonly bid: Bid;
|
|
107
|
+
})[];
|
|
108
|
+
/** The winning bid, once one has been accepted. */
|
|
109
|
+
readonly accepted?: Bid;
|
|
110
|
+
}
|
|
111
|
+
/** Open an intent for bidding. */
|
|
112
|
+
export declare function open(intent: Intent): Negotiation;
|
|
113
|
+
/**
|
|
114
|
+
* Check a bid against the invariants settlement will later assume.
|
|
115
|
+
*
|
|
116
|
+
* Exported on its own so a bidder can check its own bid before making it, and
|
|
117
|
+
* get the same answer the floor will give.
|
|
118
|
+
*/
|
|
119
|
+
export declare function checkBid(intent: Intent, bid: Bid, cover: CoverQuote, now: number): Refusal | null;
|
|
120
|
+
/** Record a bid, or record why it was refused. Never throws. */
|
|
121
|
+
export declare function bid(n: Negotiation, b: Bid, cover: CoverQuote, now: number): Negotiation;
|
|
122
|
+
/** Close an intent whose window has passed, with no winner. */
|
|
123
|
+
export declare function expire(n: Negotiation, now: number): Negotiation;
|
|
124
|
+
/**
|
|
125
|
+
* The cheapest bid that also cleared every check.
|
|
126
|
+
*
|
|
127
|
+
* Cheapest, not "best": ranking on anything softer than price would need a
|
|
128
|
+
* reputation model this layer does not have, and inventing one here would hide
|
|
129
|
+
* a judgement call inside a function that looks like arithmetic. A caller with
|
|
130
|
+
* its own ranking can read `bids` and choose.
|
|
131
|
+
*/
|
|
132
|
+
export declare function bestBid(n: Negotiation): Bid | null;
|
|
133
|
+
/**
|
|
134
|
+
* Accept a bid and produce the terms settlement will price.
|
|
135
|
+
*
|
|
136
|
+
* This is the join between the two halves of the SDK: everything before it is
|
|
137
|
+
* discovery and agreement, everything after it is `settle()`. The terms that
|
|
138
|
+
* come out are complete, so no field is filled in later by anybody.
|
|
139
|
+
*/
|
|
140
|
+
export declare function accept(n: Negotiation, winner: Bid, cover: CoverQuote): {
|
|
141
|
+
negotiation: Negotiation;
|
|
142
|
+
terms: JobTerms;
|
|
143
|
+
} | Refusal;
|
|
144
|
+
/**
|
|
145
|
+
* What the buyer locks when the job opens: the work, plus cover.
|
|
146
|
+
*
|
|
147
|
+
* Stated as its parts rather than a total. A single summed figure mixes the
|
|
148
|
+
* purchase with the fee and drifts whenever the illustration does; the parts
|
|
149
|
+
* are what a reader can actually act on.
|
|
150
|
+
*/
|
|
151
|
+
export declare function lockedByBuyer(terms: JobTerms): {
|
|
152
|
+
pay: Money;
|
|
153
|
+
premium: Money;
|
|
154
|
+
total: Money;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* How much of `damage` the bond covers, and how much the pool would.
|
|
158
|
+
*
|
|
159
|
+
* The same split `settle()` applies, exposed before anyone commits, so a buyer
|
|
160
|
+
* can see where its cover actually comes from while it still has a choice.
|
|
161
|
+
*/
|
|
162
|
+
export declare function coverSplit(terms: JobTerms): {
|
|
163
|
+
fromDeposit: Money;
|
|
164
|
+
fromPool: Money;
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/negotiate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAKjD;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACrB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,yFAAyF;IACzF,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAID;;;;;;;;GAQG;AACH,MAAM,WAAW,GAAG;IAClB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,oCAAoC;IACpC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IACxB,yDAAyD;IACzD,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,8BAA8B;IAC9B,QAAQ,CAAC,EAAE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