arl-protocol-sdk 0.1.0 → 0.2.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/README.md +23 -3
- package/package.json +5 -5
- package/protocol/src/canonical.d.ts +7 -0
- package/protocol/src/canonical.js +35 -0
- package/protocol/src/deployments.d.ts +17 -0
- package/protocol/src/deployments.js +24 -0
- package/protocol/src/evidence.d.ts +67 -0
- package/protocol/src/evidence.js +123 -0
- package/protocol/src/index.d.ts +14 -0
- package/protocol/src/index.js +9 -0
- package/protocol/src/policies.d.ts +5 -0
- package/protocol/src/policies.js +110 -0
- package/protocol/src/policy.d.ts +65 -0
- package/protocol/src/policy.js +202 -0
- package/protocol/src/prepare.d.ts +176 -0
- package/protocol/src/prepare.js +104 -0
- package/protocol/src/proof.d.ts +70 -0
- package/protocol/src/proof.js +239 -0
- package/protocol/src/reputation.d.ts +47 -0
- package/protocol/src/reputation.js +74 -0
- package/protocol/src/task.d.ts +121 -0
- package/protocol/src/task.js +322 -0
- package/{index.d.ts → sdk/src/index.d.ts} +3 -1
- package/{index.js → sdk/src/index.js} +4 -1
- package/{jobs.d.ts → sdk/src/jobs.d.ts} +2 -2
- package/{jobs.js → sdk/src/jobs.js} +7 -2
- package/sdk/src/openTask.d.ts +23 -0
- package/sdk/src/openTask.js +116 -0
- package/{verified.d.ts → sdk/src/verified.d.ts} +54 -2
- package/{verified.js → sdk/src/verified.js} +46 -6
- /package/{abi.d.ts → sdk/src/abi.d.ts} +0 -0
- /package/{abi.js → sdk/src/abi.js} +0 -0
- /package/{acquireArl.d.ts → sdk/src/acquireArl.d.ts} +0 -0
- /package/{acquireArl.js → sdk/src/acquireArl.js} +0 -0
- /package/{escrowProvider.d.ts → sdk/src/escrowProvider.d.ts} +0 -0
- /package/{escrowProvider.js → sdk/src/escrowProvider.js} +0 -0
- /package/{payVerified.d.ts → sdk/src/payVerified.d.ts} +0 -0
- /package/{payVerified.js → sdk/src/payVerified.js} +0 -0
- /package/{streaming.d.ts → sdk/src/streaming.d.ts} +0 -0
- /package/{streaming.js → sdk/src/streaming.js} +0 -0
|
@@ -18,8 +18,8 @@ import { parseAbi, parseEventLogs, } from "viem";
|
|
|
18
18
|
export const BASE_MAINNET_VERIFIED = {
|
|
19
19
|
chainId: 8453,
|
|
20
20
|
token: "0xde91E6f39D50bBd875f831dcc1134A3D7f3aaDb4",
|
|
21
|
-
jobs: "
|
|
22
|
-
evaluator: "
|
|
21
|
+
jobs: "0x9aE99bF9a59aF47E81346B7c0b93Cd2B610455fC",
|
|
22
|
+
evaluator: "0x0D160C869bd2a7AaEDd29e11fc60fdAEf21c3E28",
|
|
23
23
|
arbiterSafe: "0x8FF6c3aD0991Ac848BFf5d0acD78BBc5e190466f",
|
|
24
24
|
};
|
|
25
25
|
const ALLOWED = [8453, 31_337];
|
|
@@ -41,10 +41,12 @@ export const verifiedJobsAbi = parseAbi([
|
|
|
41
41
|
]);
|
|
42
42
|
export const verifiedEvaluatorAbi = parseAbi([
|
|
43
43
|
"struct Config { uint8 tier; uint8 threshold; uint64 voteWindow; uint64 challengeWindow; uint96 bond; uint256 providerAgentId; bytes32 specHash; address[] committee; }",
|
|
44
|
-
"struct Verdict { uint8 phase; bool providerApproved; uint8 approvals; uint8 rejections; uint64 voteEnds; uint64 challengeEnds; address challenger; uint256 bond; bytes32 deliverable; bytes32 voteHash; }",
|
|
44
|
+
"struct Verdict { uint8 phase; bool providerApproved; uint8 approvals; uint8 rejections; uint8 topApprovals; uint64 voteEnds; uint64 challengeEnds; address challenger; uint256 bond; bytes32 deliverable; bytes32 voteHash; }",
|
|
45
45
|
"function configure(uint256 jobId, Config cfg)",
|
|
46
46
|
"function getVerdict(uint256 jobId) view returns (Verdict)",
|
|
47
|
+
"function outcomesOf(uint256 agentId) view returns (uint64 approved, uint64 rejected)",
|
|
47
48
|
"function finalize(uint256 jobId)",
|
|
49
|
+
"function minChallengeWindow() view returns (uint64)",
|
|
48
50
|
]);
|
|
49
51
|
/** ARLVerifiedEvaluator.Phase, by index. */
|
|
50
52
|
export const VERDICT_PHASES = [
|
|
@@ -116,6 +118,21 @@ export function checkOpenParams(p) {
|
|
|
116
118
|
if (!/^0x[0-9a-fA-F]{64}$/.test(p.specHash))
|
|
117
119
|
throw new VerifiedJobError("specHash must be 32 bytes");
|
|
118
120
|
}
|
|
121
|
+
/** Time left after the windows for the committee to accept before voting starts (one day). */
|
|
122
|
+
const ACCEPT_SLACK = 86400n;
|
|
123
|
+
/**
|
|
124
|
+
* The windows and lifetime openVerifiedJob uses when the caller gives none. The challenge window
|
|
125
|
+
* defaults to the evaluator's minimum (one day on Base Mainnet) and the job lives long enough for
|
|
126
|
+
* the evaluator's own check at configure and at voting start (`_checkFits`: the vote window plus
|
|
127
|
+
* two challenge windows), with a day to spare for the committee to accept.
|
|
128
|
+
*/
|
|
129
|
+
export function defaultWindows(minChallengeWindow, p) {
|
|
130
|
+
const voteWindow = p.voteWindow ?? 3600n;
|
|
131
|
+
const challengeWindow = p.challengeWindow ?? (minChallengeWindow > 3600n ? minChallengeWindow : 3600n);
|
|
132
|
+
const needed = voteWindow + 2n * challengeWindow + ACCEPT_SLACK;
|
|
133
|
+
const expiresIn = p.expiresIn ?? (needed > 86400n ? needed : 86400n);
|
|
134
|
+
return { voteWindow, challengeWindow, expiresIn };
|
|
135
|
+
}
|
|
119
136
|
/**
|
|
120
137
|
* Creates the job (the caller is its client) and configures the committee in two transactions.
|
|
121
138
|
* The provider then approves the committee and sets the budget; the client funds the job.
|
|
@@ -130,10 +147,14 @@ export async function openVerifiedJob({ publicClient, walletClient }, p) {
|
|
|
130
147
|
throw new VerifiedJobError("jobs and evaluator are required locally");
|
|
131
148
|
await requireCode(publicClient, jobs, "jobs escrow");
|
|
132
149
|
await requireCode(publicClient, evaluator, "evaluator");
|
|
133
|
-
const
|
|
134
|
-
|
|
150
|
+
const minChallengeWindow = await publicClient.readContract({
|
|
151
|
+
address: evaluator,
|
|
152
|
+
abi: verifiedEvaluatorAbi,
|
|
153
|
+
functionName: "minChallengeWindow",
|
|
154
|
+
});
|
|
155
|
+
const { voteWindow, challengeWindow, expiresIn } = defaultWindows(minChallengeWindow, p);
|
|
135
156
|
const { timestamp } = await publicClient.getBlock();
|
|
136
|
-
const expiredAt = timestamp +
|
|
157
|
+
const expiredAt = timestamp + expiresIn;
|
|
137
158
|
const from = walletAccount(walletClient);
|
|
138
159
|
const createTx = await walletClient.writeContract({
|
|
139
160
|
account: from,
|
|
@@ -199,6 +220,25 @@ export async function getVerdict(publicClient, jobId, evaluator) {
|
|
|
199
220
|
});
|
|
200
221
|
return { ...v, phaseName: VERDICT_PHASES[v.phase] ?? `Phase ${String(v.phase)}` };
|
|
201
222
|
}
|
|
223
|
+
export async function getOutcomes(publicClient, evaluatorOrAgentId, agentIdOrEvaluator) {
|
|
224
|
+
const chainId = await checkVerifiedChain(publicClient);
|
|
225
|
+
const [evaluator, agentId] = typeof evaluatorOrAgentId === "bigint"
|
|
226
|
+
? [agentIdOrEvaluator, evaluatorOrAgentId]
|
|
227
|
+
: [evaluatorOrAgentId, agentIdOrEvaluator];
|
|
228
|
+
if (typeof agentId !== "bigint" || agentId < 0n) {
|
|
229
|
+
throw new VerifiedJobError("agentId must be a non-negative bigint");
|
|
230
|
+
}
|
|
231
|
+
const address = evaluator ?? verifiedDeployment(chainId)?.evaluator;
|
|
232
|
+
if (!address)
|
|
233
|
+
throw new VerifiedJobError("evaluator is required locally");
|
|
234
|
+
const [approved, rejected] = await publicClient.readContract({
|
|
235
|
+
address,
|
|
236
|
+
abi: verifiedEvaluatorAbi,
|
|
237
|
+
functionName: "outcomesOf",
|
|
238
|
+
args: [agentId],
|
|
239
|
+
});
|
|
240
|
+
return { approved, rejected };
|
|
241
|
+
}
|
|
202
242
|
/** Pays out after the challenge window: anyone may call it. */
|
|
203
243
|
export async function finalizeJob({ publicClient, walletClient }, jobId, evaluator) {
|
|
204
244
|
const chainId = await checkVerifiedChain(publicClient);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|