@vapi-network/cli 0.16.0 → 0.16.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/dist/cli.d.ts +1 -1
- package/dist/cli.js +1681 -1170
- package/dist/cli.js.map +3 -3
- package/dist/index.js +1681 -1170
- package/dist/index.js.map +3 -3
- package/dist/task.d.ts +3 -2
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -47434,6 +47434,10 @@ var DEFAULT_SPEND_CAPS = {
|
|
|
47434
47434
|
};
|
|
47435
47435
|
var DEFAULT_MAX_PER_TASK_USD = 100;
|
|
47436
47436
|
var DEFAULT_AUTO_RELEASE_BELOW_USD = 25;
|
|
47437
|
+
var walletTaskPolicySchema = external_exports.object({
|
|
47438
|
+
maxPerTaskUsd: external_exports.number().min(0).optional(),
|
|
47439
|
+
approveAboveUsd: external_exports.number().min(0).optional()
|
|
47440
|
+
});
|
|
47437
47441
|
var DEFAULT_CEILING_ATOMIC = 5000000n;
|
|
47438
47442
|
var atomicString = external_exports.string().regex(/^\d+$/, "Expected non-negative atomic units.");
|
|
47439
47443
|
var spendCapsSchema = external_exports.object({
|
|
@@ -71451,10 +71455,21 @@ function readSecretBackend(home = getVapiPaths().directory) {
|
|
|
71451
71455
|
}
|
|
71452
71456
|
async function chooseSecretBackend(options) {
|
|
71453
71457
|
const env = options.env ?? process.env;
|
|
71454
|
-
const osWorks =
|
|
71458
|
+
const osWorks = await osStoreUsable(options.os);
|
|
71455
71459
|
const path = secretBackendPath(options.home);
|
|
71456
71460
|
return await withVaultLock(path, async () => {
|
|
71457
|
-
if (await fileExists(path))
|
|
71461
|
+
if (await fileExists(path)) {
|
|
71462
|
+
const pinned = readSecretBackend(options.home);
|
|
71463
|
+
if (pinned === "os" && !hasOsStore(options.os.platform)) {
|
|
71464
|
+
throw new KeystoreError(
|
|
71465
|
+
[
|
|
71466
|
+
`This vAPI home is set to use the OS secret store, which ${options.os.platform} does not have.`,
|
|
71467
|
+
`If vapi setup never finished here, delete ${path}, set ${FILE_SECRET_STORE_PASSWORD_ENV} (at least ${FILE_SECRET_STORE_MIN_PASSWORD} characters) and run vapi setup again.`
|
|
71468
|
+
].join(" ")
|
|
71469
|
+
);
|
|
71470
|
+
}
|
|
71471
|
+
return pinned;
|
|
71472
|
+
}
|
|
71458
71473
|
if (await fileExists(join6(options.home, "vault.json"))) return "os";
|
|
71459
71474
|
let backend;
|
|
71460
71475
|
if (osWorks) {
|
|
@@ -71484,6 +71499,13 @@ async function fileExists(path) {
|
|
|
71484
71499
|
throw error61;
|
|
71485
71500
|
}
|
|
71486
71501
|
}
|
|
71502
|
+
function hasOsStore(platform2) {
|
|
71503
|
+
return platform2 === "darwin" || platform2 === "win32" || platform2 === "linux";
|
|
71504
|
+
}
|
|
71505
|
+
async function osStoreUsable(store) {
|
|
71506
|
+
if (store.platform === "linux") return await osStoreWorks(store);
|
|
71507
|
+
return hasOsStore(store.platform);
|
|
71508
|
+
}
|
|
71487
71509
|
async function osStoreWorks(store) {
|
|
71488
71510
|
if (!store.available) return false;
|
|
71489
71511
|
try {
|
|
@@ -72778,6 +72800,8 @@ var walletEntrySchema = external_exports.object({
|
|
|
72778
72800
|
ceilingAtomic: external_exports.string().regex(/^\d+$/).nullable().optional(),
|
|
72779
72801
|
ceilingSweepAttemptedAt: external_exports.iso.datetime().optional(),
|
|
72780
72802
|
ceilingSweepPending: ceilingSweepPendingSchema.optional(),
|
|
72803
|
+
// Task limits for an account without an agent profile; absent means the defaults.
|
|
72804
|
+
taskPolicy: walletTaskPolicySchema.optional(),
|
|
72781
72805
|
routerRefill: routerRefillSchema.optional(),
|
|
72782
72806
|
routerPendingPurchase: routerPendingPurchaseSchema.optional(),
|
|
72783
72807
|
link: agentLinkSchema.optional()
|
|
@@ -73126,6 +73150,30 @@ var WalletStore = class _WalletStore {
|
|
|
73126
73150
|
return structuredClone(entry);
|
|
73127
73151
|
});
|
|
73128
73152
|
}
|
|
73153
|
+
/**
|
|
73154
|
+
* Stores task limits for an account without an agent profile, from the latest registry value
|
|
73155
|
+
* while holding its write lock. Returning undefined removes them, so the defaults apply.
|
|
73156
|
+
*/
|
|
73157
|
+
async updateTaskPolicy(name, update) {
|
|
73158
|
+
const walletName = assertWalletName(name);
|
|
73159
|
+
return await withRegistryLock(this.registryPath, async () => {
|
|
73160
|
+
const registry2 = await this.readRegistry();
|
|
73161
|
+
const entry = ownWalletEntry(registry2.wallets, walletName);
|
|
73162
|
+
if (!entry) {
|
|
73163
|
+
throw new KeystoreError(unknownWalletMessage(walletName, Object.keys(registry2.wallets)));
|
|
73164
|
+
}
|
|
73165
|
+
const next = update(entry.taskPolicy === void 0 ? void 0 : { ...entry.taskPolicy });
|
|
73166
|
+
const parsed = next === void 0 ? void 0 : walletTaskPolicySchema.parse(next);
|
|
73167
|
+
if (JSON.stringify(parsed) !== JSON.stringify(entry.taskPolicy)) {
|
|
73168
|
+
if (parsed === void 0) delete entry.taskPolicy;
|
|
73169
|
+
else entry.taskPolicy = parsed;
|
|
73170
|
+
await this.writeRegistry(registry2);
|
|
73171
|
+
} else {
|
|
73172
|
+
this.registry = registry2;
|
|
73173
|
+
}
|
|
73174
|
+
return structuredClone(entry);
|
|
73175
|
+
});
|
|
73176
|
+
}
|
|
73129
73177
|
/** Reads the configured ceiling and the per-day-cap floor for one wallet. */
|
|
73130
73178
|
ceilingCaps(name) {
|
|
73131
73179
|
const entry = this.resolve({ name }).entry;
|
|
@@ -74533,6 +74581,14 @@ function secretsAllowed(env, streams) {
|
|
|
74533
74581
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
74534
74582
|
import { mkdir as mkdir11, readFile as readFile13, readdir as readdir4, rename as rename8, unlink as unlink8, writeFile as writeFile5 } from "node:fs/promises";
|
|
74535
74583
|
import { join as join11 } from "node:path";
|
|
74584
|
+
var DEFAULT_APPROVE_ABOVE_USD = 0.5;
|
|
74585
|
+
function accountTaskLimitsUnderProfile(current) {
|
|
74586
|
+
const kept = {
|
|
74587
|
+
...current?.maxPerTaskUsd !== void 0 && current.maxPerTaskUsd < DEFAULT_MAX_PER_TASK_USD ? { maxPerTaskUsd: current.maxPerTaskUsd } : {},
|
|
74588
|
+
...current?.approveAboveUsd !== void 0 && current.approveAboveUsd < DEFAULT_APPROVE_ABOVE_USD ? { approveAboveUsd: current.approveAboveUsd } : {}
|
|
74589
|
+
};
|
|
74590
|
+
return Object.keys(kept).length === 0 ? void 0 : kept;
|
|
74591
|
+
}
|
|
74536
74592
|
var DEFAULT_AGENT_TOOLS = ["call.search", "call.inspect", "call.pay"];
|
|
74537
74593
|
var AGENT_GRANTS = ["read", "delegate", "allocate"];
|
|
74538
74594
|
var agentProfileShape = {
|
|
@@ -74542,7 +74598,7 @@ var agentProfileShape = {
|
|
|
74542
74598
|
model: external_exports.string().min(1),
|
|
74543
74599
|
instructions: external_exports.string().max(2e4),
|
|
74544
74600
|
verifiedOnly: external_exports.boolean().default(true),
|
|
74545
|
-
approveAboveUsd: external_exports.number().min(0).default(
|
|
74601
|
+
approveAboveUsd: external_exports.number().min(0).default(DEFAULT_APPROVE_ABOVE_USD),
|
|
74546
74602
|
maxPerTaskUsd: external_exports.number().min(0).default(DEFAULT_MAX_PER_TASK_USD),
|
|
74547
74603
|
autoReleaseBelowUsd: external_exports.number().min(0).default(DEFAULT_AUTO_RELEASE_BELOW_USD),
|
|
74548
74604
|
maxSteps: external_exports.number().int().min(1).max(50).default(12),
|
|
@@ -78323,6 +78379,7 @@ async function provisionSwarm(opts, home, swarm, accounts) {
|
|
|
78323
78379
|
}
|
|
78324
78380
|
if (member !== void 0) {
|
|
78325
78381
|
if (!await profileExists(home, member.account)) {
|
|
78382
|
+
const stricter = (await opts.store.updateTaskPolicy(member.account, accountTaskLimitsUnderProfile)).taskPolicy;
|
|
78326
78383
|
await writeAgentProfile(home, {
|
|
78327
78384
|
version: 1,
|
|
78328
78385
|
name: member.account,
|
|
@@ -78332,7 +78389,8 @@ async function provisionSwarm(opts, home, swarm, accounts) {
|
|
|
78332
78389
|
tools: [...DEFAULT_AGENT_TOOLS],
|
|
78333
78390
|
grants: roleGrants(member.role),
|
|
78334
78391
|
verifiedOnly: true,
|
|
78335
|
-
approveAboveUsd: 0.5,
|
|
78392
|
+
approveAboveUsd: stricter?.approveAboveUsd ?? 0.5,
|
|
78393
|
+
...stricter?.maxPerTaskUsd === void 0 ? {} : { maxPerTaskUsd: stricter.maxPerTaskUsd },
|
|
78336
78394
|
maxSteps: 12,
|
|
78337
78395
|
paused: false,
|
|
78338
78396
|
createdAt: (opts.now?.() ?? /* @__PURE__ */ new Date()).toISOString()
|
|
@@ -78668,7 +78726,7 @@ function createRunBudget(args) {
|
|
|
78668
78726
|
import { mkdir as mkdir15, writeFile as writeFile7 } from "node:fs/promises";
|
|
78669
78727
|
import { arch, platform, release } from "node:os";
|
|
78670
78728
|
import { join as join14 } from "node:path";
|
|
78671
|
-
var VAPI_CLIENT_VERSION = "0.16.
|
|
78729
|
+
var VAPI_CLIENT_VERSION = "0.16.2";
|
|
78672
78730
|
async function createSupportReport(options) {
|
|
78673
78731
|
const message = options.message.trim();
|
|
78674
78732
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
@@ -82211,9 +82269,11 @@ var taskV2OperationSchema = external_exports.object({
|
|
|
82211
82269
|
step: taskV2StepSchema,
|
|
82212
82270
|
expectedActor: address2,
|
|
82213
82271
|
transactionHash: hash4.nullable(),
|
|
82214
|
-
plan
|
|
82272
|
+
// The API returns the plan only while the step is prepared and re-validated; once the
|
|
82273
|
+
// transaction is submitted or confirmed, and while a recovery scan runs, it sends null.
|
|
82274
|
+
plan: taskV2PlanSchema.nullable()
|
|
82215
82275
|
}).refine(
|
|
82216
|
-
(v) => v.plan.operationId === v.id && v.plan.step === v.step && v.plan.from === v.expectedActor,
|
|
82276
|
+
(v) => v.plan === null || v.plan.operationId === v.id && v.plan.step === v.step && v.plan.from === v.expectedActor,
|
|
82217
82277
|
"Operation plan binding mismatch"
|
|
82218
82278
|
).refine(
|
|
82219
82279
|
(v) => !["submitted", "confirmed"].includes(v.state) || v.transactionHash !== null,
|
|
@@ -83111,934 +83171,383 @@ function taskFundingIntentNonce(intent, expected) {
|
|
|
83111
83171
|
return message.nonce.toLowerCase();
|
|
83112
83172
|
}
|
|
83113
83173
|
|
|
83114
|
-
// ../core/src/tasks/
|
|
83115
|
-
import {
|
|
83116
|
-
|
|
83117
|
-
if (amount4 < 0n) throw new Error("Dispute amount must be nonnegative.");
|
|
83118
|
-
const fee = amount4 * 1000n / 10000n;
|
|
83119
|
-
return fee < 20000000n ? 20000000n : fee > 500000000n ? 500000000n : fee;
|
|
83120
|
-
}
|
|
83121
|
-
function taskFeeReservationKey(milestoneId2, action) {
|
|
83122
|
-
const bytes = createHash3("sha256").update(JSON.stringify([milestoneId2, action])).digest().subarray(0, 16);
|
|
83123
|
-
bytes[6] = bytes[6] & 15 | 80;
|
|
83124
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
83125
|
-
const hex5 = bytes.toString("hex");
|
|
83126
|
-
return `${hex5.slice(0, 8)}-${hex5.slice(8, 12)}-${hex5.slice(12, 16)}-${hex5.slice(16, 20)}-${hex5.slice(20)}`;
|
|
83127
|
-
}
|
|
83128
|
-
|
|
83129
|
-
// ../core/src/tasks/money.ts
|
|
83130
|
-
function formatBaseUnitsUsd(baseUnits2) {
|
|
83131
|
-
const [whole, fraction = ""] = formatUsdc(parseBaseUnits(baseUnits2)).split(".");
|
|
83132
|
-
return `${whole}.${fraction.padEnd(2, "0")}`;
|
|
83133
|
-
}
|
|
83134
|
-
function parseUsdToBaseUnits(text) {
|
|
83135
|
-
if (!/^\d+(?:\.\d{1,6})?$/u.test(text)) {
|
|
83136
|
-
throw new Error(
|
|
83137
|
-
"Task USD amount must be a non-negative decimal with at most six decimal places."
|
|
83138
|
-
);
|
|
83139
|
-
}
|
|
83140
|
-
const [whole = "0", fraction = ""] = text.split(".");
|
|
83141
|
-
return BigInt(whole) * 1000000n + BigInt(fraction.padEnd(6, "0"));
|
|
83142
|
-
}
|
|
83143
|
-
function parseFeeBp(deploymentOrReadiness) {
|
|
83144
|
-
if (typeof deploymentOrReadiness !== "object" || deploymentOrReadiness === null || !("feeBp" in deploymentOrReadiness)) {
|
|
83145
|
-
return null;
|
|
83146
|
-
}
|
|
83147
|
-
const feeBp = deploymentOrReadiness.feeBp;
|
|
83148
|
-
if (feeBp === void 0 || feeBp === null) return null;
|
|
83149
|
-
validateFeeBp(feeBp);
|
|
83150
|
-
return feeBp;
|
|
83151
|
-
}
|
|
83152
|
-
function taskMoney(grossBaseUnits, feeBp) {
|
|
83153
|
-
const atomic = parseBaseUnits(grossBaseUnits);
|
|
83154
|
-
const gross = amount3(atomic);
|
|
83155
|
-
if (feeBp === null) {
|
|
83156
|
-
return { gross, fee: null, net: null, feeBp, line: `$${gross.usd} gross \xB7 fee unavailable` };
|
|
83157
|
-
}
|
|
83158
|
-
validateFeeBp(feeBp);
|
|
83159
|
-
const feeAtomic = atomic * BigInt(feeBp) / 10000n;
|
|
83160
|
-
const fee = amount3(feeAtomic);
|
|
83161
|
-
const net = amount3(atomic - feeAtomic);
|
|
83162
|
-
return {
|
|
83163
|
-
gross,
|
|
83164
|
-
fee,
|
|
83165
|
-
net,
|
|
83166
|
-
feeBp,
|
|
83167
|
-
line: `$${gross.usd} gross \xB7 $${fee.usd} fee \xB7 $${net.usd} net`
|
|
83168
|
-
};
|
|
83169
|
-
}
|
|
83170
|
-
function amount3(atomic) {
|
|
83171
|
-
return { usd: formatBaseUnitsUsd(atomic), baseUnits: atomic.toString() };
|
|
83172
|
-
}
|
|
83173
|
-
function validateFeeBp(value) {
|
|
83174
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 1e4) {
|
|
83175
|
-
throw new Error("Task fee basis points must be an integer from 0 to 10000.");
|
|
83176
|
-
}
|
|
83177
|
-
}
|
|
83178
|
-
function parseBaseUnits(value) {
|
|
83179
|
-
if (typeof value === "string" && !/^\d+$/u.test(value) || typeof value !== "bigint" && typeof value !== "string") {
|
|
83180
|
-
throw new Error("Task base units must be a non-negative integer.");
|
|
83181
|
-
}
|
|
83182
|
-
const atomic = BigInt(value);
|
|
83183
|
-
if (atomic < 0n) throw new Error("Task base units must be a non-negative integer.");
|
|
83184
|
-
return atomic;
|
|
83185
|
-
}
|
|
83186
|
-
function taskPolicyAtomic(value) {
|
|
83187
|
-
if (!Number.isFinite(value) || value < 0)
|
|
83188
|
-
throw new Error("Task policy USD amounts must be finite and non-negative.");
|
|
83189
|
-
const [mantissa = "0", exponent = "0"] = value.toString().split("e");
|
|
83190
|
-
const [whole = "0", fraction = ""] = mantissa.split(".");
|
|
83191
|
-
const digits = BigInt(whole + fraction);
|
|
83192
|
-
const scale = 6 + Number(exponent) - fraction.length;
|
|
83193
|
-
return scale >= 0 ? digits * 10n ** BigInt(scale) : digits / 10n ** BigInt(-scale);
|
|
83194
|
-
}
|
|
83174
|
+
// ../core/src/tasks/operation-support.ts
|
|
83175
|
+
import { readFile as readFile18, stat as stat15 } from "node:fs/promises";
|
|
83176
|
+
import { basename as basename2, extname, join as join16 } from "node:path";
|
|
83195
83177
|
|
|
83196
|
-
// ../core/src/tasks/
|
|
83197
|
-
var
|
|
83178
|
+
// ../core/src/tasks/v2-abi.generated.ts
|
|
83179
|
+
var escrowFactoryV2Abi = [
|
|
83198
83180
|
{
|
|
83199
|
-
type: "
|
|
83200
|
-
name: "createEscrow",
|
|
83201
|
-
stateMutability: "nonpayable",
|
|
83181
|
+
type: "constructor",
|
|
83202
83182
|
inputs: [
|
|
83203
|
-
{ name: "
|
|
83204
|
-
{ name: "
|
|
83205
|
-
{ name: "
|
|
83206
|
-
{ name: "
|
|
83207
|
-
{ name: "
|
|
83208
|
-
{ name: "
|
|
83209
|
-
{ name: "
|
|
83183
|
+
{ name: "initialOwner", type: "address", internalType: "address" },
|
|
83184
|
+
{ name: "feeRouter", type: "address", internalType: "address" },
|
|
83185
|
+
{ name: "disputeResolver", type: "address", internalType: "address" },
|
|
83186
|
+
{ name: "outcomeRegistry", type: "address", internalType: "address" },
|
|
83187
|
+
{ name: "usdc", type: "address", internalType: "address" },
|
|
83188
|
+
{ name: "initialFeeBp", type: "uint16", internalType: "uint16" },
|
|
83189
|
+
{ name: "maxFeeBp_", type: "uint16", internalType: "uint16" },
|
|
83190
|
+
{ name: "maxEscrowAmount_", type: "uint256", internalType: "uint256" },
|
|
83191
|
+
{ name: "cancelGrace", type: "uint64", internalType: "uint64" },
|
|
83192
|
+
{ name: "lateWindow", type: "uint64", internalType: "uint64" },
|
|
83193
|
+
{ name: "minWorkTime", type: "uint64", internalType: "uint64" }
|
|
83210
83194
|
],
|
|
83211
|
-
|
|
83195
|
+
stateMutability: "nonpayable"
|
|
83212
83196
|
},
|
|
83213
83197
|
{
|
|
83214
83198
|
type: "function",
|
|
83215
|
-
name: "
|
|
83216
|
-
|
|
83199
|
+
name: "bountyImplementation",
|
|
83200
|
+
inputs: [],
|
|
83201
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83202
|
+
stateMutability: "view"
|
|
83203
|
+
},
|
|
83204
|
+
{
|
|
83205
|
+
type: "function",
|
|
83206
|
+
name: "createAndFundWithAuthorization",
|
|
83217
83207
|
inputs: [
|
|
83218
|
-
{
|
|
83219
|
-
|
|
83220
|
-
|
|
83221
|
-
|
|
83208
|
+
{
|
|
83209
|
+
name: "terms_",
|
|
83210
|
+
type: "tuple",
|
|
83211
|
+
internalType: "struct IEscrowV2.Terms",
|
|
83212
|
+
components: [
|
|
83213
|
+
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83214
|
+
{ name: "poster", type: "address", internalType: "address" },
|
|
83215
|
+
{ name: "worker", type: "address", internalType: "address" },
|
|
83216
|
+
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83217
|
+
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83218
|
+
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83219
|
+
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83220
|
+
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83221
|
+
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83222
|
+
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83223
|
+
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83224
|
+
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83225
|
+
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83226
|
+
]
|
|
83227
|
+
},
|
|
83228
|
+
{
|
|
83229
|
+
name: "milestones",
|
|
83230
|
+
type: "tuple[]",
|
|
83231
|
+
internalType: "struct IEscrowV2.Milestone[]",
|
|
83232
|
+
components: [
|
|
83233
|
+
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83234
|
+
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83235
|
+
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83236
|
+
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83237
|
+
]
|
|
83238
|
+
},
|
|
83239
|
+
{ name: "salt", type: "bytes32", internalType: "bytes32" },
|
|
83240
|
+
{ name: "from", type: "address", internalType: "address" },
|
|
83241
|
+
{ name: "validAfter", type: "uint256", internalType: "uint256" },
|
|
83242
|
+
{ name: "validBefore", type: "uint256", internalType: "uint256" },
|
|
83243
|
+
{ name: "nonce", type: "bytes32", internalType: "bytes32" },
|
|
83244
|
+
{ name: "signature", type: "bytes", internalType: "bytes" }
|
|
83222
83245
|
],
|
|
83223
|
-
outputs: []
|
|
83246
|
+
outputs: [{ name: "escrow", type: "address", internalType: "address" }],
|
|
83247
|
+
stateMutability: "nonpayable"
|
|
83224
83248
|
},
|
|
83225
83249
|
{
|
|
83226
83250
|
type: "function",
|
|
83227
|
-
name: "
|
|
83228
|
-
stateMutability: "nonpayable",
|
|
83251
|
+
name: "createEscrow",
|
|
83229
83252
|
inputs: [
|
|
83230
|
-
{
|
|
83231
|
-
|
|
83253
|
+
{
|
|
83254
|
+
name: "terms_",
|
|
83255
|
+
type: "tuple",
|
|
83256
|
+
internalType: "struct IEscrowV2.Terms",
|
|
83257
|
+
components: [
|
|
83258
|
+
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83259
|
+
{ name: "poster", type: "address", internalType: "address" },
|
|
83260
|
+
{ name: "worker", type: "address", internalType: "address" },
|
|
83261
|
+
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83262
|
+
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83263
|
+
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83264
|
+
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83265
|
+
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83266
|
+
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83267
|
+
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83268
|
+
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83269
|
+
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83270
|
+
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83271
|
+
]
|
|
83272
|
+
},
|
|
83273
|
+
{
|
|
83274
|
+
name: "milestones",
|
|
83275
|
+
type: "tuple[]",
|
|
83276
|
+
internalType: "struct IEscrowV2.Milestone[]",
|
|
83277
|
+
components: [
|
|
83278
|
+
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83279
|
+
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83280
|
+
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83281
|
+
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83282
|
+
]
|
|
83283
|
+
},
|
|
83284
|
+
{ name: "salt", type: "bytes32", internalType: "bytes32" }
|
|
83232
83285
|
],
|
|
83233
|
-
outputs: [{ name: "
|
|
83286
|
+
outputs: [{ name: "escrow", type: "address", internalType: "address" }],
|
|
83287
|
+
stateMutability: "nonpayable"
|
|
83234
83288
|
},
|
|
83235
83289
|
{
|
|
83236
83290
|
type: "function",
|
|
83237
|
-
name: "
|
|
83238
|
-
stateMutability: "nonpayable",
|
|
83291
|
+
name: "feeBp",
|
|
83239
83292
|
inputs: [],
|
|
83240
|
-
outputs: []
|
|
83293
|
+
outputs: [{ name: "", type: "uint16", internalType: "uint16" }],
|
|
83294
|
+
stateMutability: "view"
|
|
83241
83295
|
},
|
|
83242
83296
|
{
|
|
83243
83297
|
type: "function",
|
|
83244
|
-
name: "
|
|
83245
|
-
|
|
83246
|
-
|
|
83247
|
-
|
|
83298
|
+
name: "implementation",
|
|
83299
|
+
inputs: [],
|
|
83300
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83301
|
+
stateMutability: "view"
|
|
83248
83302
|
},
|
|
83249
83303
|
{
|
|
83250
83304
|
type: "function",
|
|
83251
|
-
name: "
|
|
83252
|
-
|
|
83305
|
+
name: "isEscrow",
|
|
83306
|
+
inputs: [{ name: "escrow", type: "address", internalType: "address" }],
|
|
83307
|
+
outputs: [{ name: "registered", type: "bool", internalType: "bool" }],
|
|
83308
|
+
stateMutability: "view"
|
|
83309
|
+
},
|
|
83310
|
+
{
|
|
83311
|
+
type: "function",
|
|
83312
|
+
name: "maxEscrowAmount",
|
|
83253
83313
|
inputs: [],
|
|
83254
|
-
outputs: []
|
|
83314
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
83315
|
+
stateMutability: "view"
|
|
83255
83316
|
},
|
|
83256
|
-
{ type: "function", name: "refundBuyer", stateMutability: "nonpayable", inputs: [], outputs: [] },
|
|
83257
83317
|
{
|
|
83258
83318
|
type: "function",
|
|
83259
|
-
name: "
|
|
83260
|
-
|
|
83261
|
-
|
|
83262
|
-
|
|
83319
|
+
name: "maxFeeBp",
|
|
83320
|
+
inputs: [],
|
|
83321
|
+
outputs: [{ name: "", type: "uint16", internalType: "uint16" }],
|
|
83322
|
+
stateMutability: "view"
|
|
83263
83323
|
},
|
|
83264
83324
|
{
|
|
83265
83325
|
type: "function",
|
|
83266
|
-
name: "
|
|
83267
|
-
|
|
83268
|
-
|
|
83269
|
-
|
|
83326
|
+
name: "owner",
|
|
83327
|
+
inputs: [],
|
|
83328
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83329
|
+
stateMutability: "view"
|
|
83270
83330
|
},
|
|
83331
|
+
{ type: "function", name: "pause", inputs: [], outputs: [], stateMutability: "nonpayable" },
|
|
83271
83332
|
{
|
|
83272
83333
|
type: "function",
|
|
83273
|
-
name: "
|
|
83274
|
-
stateMutability: "nonpayable",
|
|
83334
|
+
name: "paused",
|
|
83275
83335
|
inputs: [],
|
|
83276
|
-
outputs: []
|
|
83336
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
83337
|
+
stateMutability: "view"
|
|
83277
83338
|
},
|
|
83278
83339
|
{
|
|
83279
83340
|
type: "function",
|
|
83280
|
-
name: "
|
|
83281
|
-
stateMutability: "nonpayable",
|
|
83341
|
+
name: "paymentToken",
|
|
83282
83342
|
inputs: [],
|
|
83283
|
-
outputs: []
|
|
83343
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83344
|
+
stateMutability: "view"
|
|
83284
83345
|
},
|
|
83285
|
-
{ type: "function", name: "finalize", stateMutability: "nonpayable", inputs: [], outputs: [] },
|
|
83286
83346
|
{
|
|
83287
83347
|
type: "function",
|
|
83288
|
-
name: "
|
|
83289
|
-
|
|
83348
|
+
name: "predictBountyEscrow",
|
|
83349
|
+
inputs: [
|
|
83350
|
+
{
|
|
83351
|
+
name: "terms_",
|
|
83352
|
+
type: "tuple",
|
|
83353
|
+
internalType: "struct IEscrowV2.Terms",
|
|
83354
|
+
components: [
|
|
83355
|
+
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83356
|
+
{ name: "poster", type: "address", internalType: "address" },
|
|
83357
|
+
{ name: "worker", type: "address", internalType: "address" },
|
|
83358
|
+
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83359
|
+
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83360
|
+
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83361
|
+
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83362
|
+
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83363
|
+
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83364
|
+
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83365
|
+
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83366
|
+
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83367
|
+
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83368
|
+
]
|
|
83369
|
+
},
|
|
83370
|
+
{
|
|
83371
|
+
name: "milestones",
|
|
83372
|
+
type: "tuple[]",
|
|
83373
|
+
internalType: "struct IEscrowV2.Milestone[]",
|
|
83374
|
+
components: [
|
|
83375
|
+
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83376
|
+
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83377
|
+
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83378
|
+
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83379
|
+
]
|
|
83380
|
+
},
|
|
83381
|
+
{ name: "salt", type: "bytes32", internalType: "bytes32" }
|
|
83382
|
+
],
|
|
83383
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83384
|
+
stateMutability: "view"
|
|
83385
|
+
},
|
|
83386
|
+
{
|
|
83387
|
+
type: "function",
|
|
83388
|
+
name: "predictEscrow",
|
|
83389
|
+
inputs: [
|
|
83390
|
+
{
|
|
83391
|
+
name: "terms_",
|
|
83392
|
+
type: "tuple",
|
|
83393
|
+
internalType: "struct IEscrowV2.Terms",
|
|
83394
|
+
components: [
|
|
83395
|
+
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83396
|
+
{ name: "poster", type: "address", internalType: "address" },
|
|
83397
|
+
{ name: "worker", type: "address", internalType: "address" },
|
|
83398
|
+
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83399
|
+
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83400
|
+
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83401
|
+
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83402
|
+
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83403
|
+
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83404
|
+
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83405
|
+
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83406
|
+
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83407
|
+
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83408
|
+
]
|
|
83409
|
+
},
|
|
83410
|
+
{
|
|
83411
|
+
name: "milestones",
|
|
83412
|
+
type: "tuple[]",
|
|
83413
|
+
internalType: "struct IEscrowV2.Milestone[]",
|
|
83414
|
+
components: [
|
|
83415
|
+
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83416
|
+
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83417
|
+
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83418
|
+
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83419
|
+
]
|
|
83420
|
+
},
|
|
83421
|
+
{ name: "salt", type: "bytes32", internalType: "bytes32" }
|
|
83422
|
+
],
|
|
83423
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83424
|
+
stateMutability: "view"
|
|
83425
|
+
},
|
|
83426
|
+
{
|
|
83427
|
+
type: "function",
|
|
83428
|
+
name: "renounceOwnership",
|
|
83290
83429
|
inputs: [],
|
|
83291
|
-
outputs: [
|
|
83430
|
+
outputs: [],
|
|
83431
|
+
stateMutability: "nonpayable"
|
|
83292
83432
|
},
|
|
83293
83433
|
{
|
|
83294
83434
|
type: "function",
|
|
83295
|
-
name: "
|
|
83296
|
-
|
|
83435
|
+
name: "setFeeBp",
|
|
83436
|
+
inputs: [{ name: "newFeeBp", type: "uint16", internalType: "uint16" }],
|
|
83437
|
+
outputs: [],
|
|
83438
|
+
stateMutability: "nonpayable"
|
|
83439
|
+
},
|
|
83440
|
+
{
|
|
83441
|
+
type: "function",
|
|
83442
|
+
name: "setMaxEscrowAmount",
|
|
83443
|
+
inputs: [{ name: "newAmount", type: "uint256", internalType: "uint256" }],
|
|
83444
|
+
outputs: [],
|
|
83445
|
+
stateMutability: "nonpayable"
|
|
83446
|
+
},
|
|
83447
|
+
{
|
|
83448
|
+
type: "function",
|
|
83449
|
+
name: "transferOwnership",
|
|
83450
|
+
inputs: [{ name: "newOwner", type: "address", internalType: "address" }],
|
|
83451
|
+
outputs: [],
|
|
83452
|
+
stateMutability: "nonpayable"
|
|
83453
|
+
},
|
|
83454
|
+
{ type: "function", name: "unpause", inputs: [], outputs: [], stateMutability: "nonpayable" },
|
|
83455
|
+
{
|
|
83456
|
+
type: "event",
|
|
83457
|
+
name: "EscrowCreated",
|
|
83297
83458
|
inputs: [
|
|
83298
|
-
{ name: "
|
|
83299
|
-
{ name: "
|
|
83459
|
+
{ name: "escrow", type: "address", indexed: true, internalType: "address" },
|
|
83460
|
+
{ name: "poster", type: "address", indexed: true, internalType: "address" },
|
|
83461
|
+
{ name: "termsHash", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
83462
|
+
{ name: "salt", type: "bytes32", indexed: false, internalType: "bytes32" },
|
|
83463
|
+
{ name: "feeBp", type: "uint16", indexed: false, internalType: "uint16" }
|
|
83300
83464
|
],
|
|
83301
|
-
|
|
83302
|
-
}
|
|
83303
|
-
|
|
83304
|
-
|
|
83305
|
-
|
|
83306
|
-
|
|
83307
|
-
|
|
83308
|
-
|
|
83309
|
-
|
|
83310
|
-
|
|
83311
|
-
|
|
83312
|
-
|
|
83313
|
-
|
|
83314
|
-
|
|
83315
|
-
|
|
83316
|
-
|
|
83317
|
-
|
|
83318
|
-
|
|
83319
|
-
|
|
83320
|
-
|
|
83321
|
-
|
|
83322
|
-
|
|
83323
|
-
|
|
83324
|
-
|
|
83325
|
-
|
|
83326
|
-
|
|
83327
|
-
|
|
83328
|
-
|
|
83329
|
-
|
|
83330
|
-
|
|
83331
|
-
|
|
83332
|
-
|
|
83333
|
-
|
|
83334
|
-
|
|
83335
|
-
|
|
83336
|
-
|
|
83337
|
-
|
|
83338
|
-
|
|
83339
|
-
|
|
83340
|
-
|
|
83341
|
-
|
|
83342
|
-
|
|
83343
|
-
|
|
83344
|
-
|
|
83345
|
-
|
|
83346
|
-
|
|
83347
|
-
|
|
83348
|
-
|
|
83349
|
-
|
|
83350
|
-
|
|
83351
|
-
|
|
83352
|
-
|
|
83353
|
-
|
|
83354
|
-
|
|
83355
|
-
|
|
83356
|
-
|
|
83357
|
-
|
|
83358
|
-
|
|
83359
|
-
|
|
83360
|
-
}
|
|
83361
|
-
|
|
83362
|
-
|
|
83363
|
-
|
|
83364
|
-
|
|
83365
|
-
|
|
83366
|
-
|
|
83367
|
-
|
|
83368
|
-
|
|
83369
|
-
|
|
83370
|
-
|
|
83371
|
-
|
|
83372
|
-
|
|
83373
|
-
|
|
83374
|
-
|
|
83375
|
-
|
|
83376
|
-
|
|
83377
|
-
|
|
83378
|
-
|
|
83379
|
-
|
|
83380
|
-
|
|
83381
|
-
|
|
83382
|
-
|
|
83383
|
-
|
|
83384
|
-
|
|
83385
|
-
|
|
83386
|
-
|
|
83387
|
-
throw new TasksChainError("Unsafe transaction plan: missing local authorization", false);
|
|
83388
|
-
requireArgs([BigInt(a.validAfter), BigInt(a.validBefore), a.nonce, a.signature]);
|
|
83389
|
-
} else if (plan.step === "approve-usdc") {
|
|
83390
|
-
if (expectation.approveAmount === void 0) fail2("missing verified approval amount");
|
|
83391
|
-
requireArgs([expectation.milestone.escrowContract, expectation.approveAmount]);
|
|
83392
|
-
} else if (plan.step === "submit-delivery") {
|
|
83393
|
-
if (!expectation.manifestHash) fail2("missing manifest hash");
|
|
83394
|
-
requireArgs([expectation.manifestHash]);
|
|
83395
|
-
} else if (plan.step === "raise-dispute" || plan.step === "submit-counter-evidence") {
|
|
83396
|
-
if (!expectation.evidenceHash) fail2("missing evidence hash");
|
|
83397
|
-
requireArgs([expectation.evidenceHash]);
|
|
83398
|
-
} else requireArgs([]);
|
|
83399
|
-
}
|
|
83400
|
-
|
|
83401
|
-
// ../core/src/tasks/chain-verification.ts
|
|
83402
|
-
var TasksPartiesNotBoundError = class extends TasksValidationError {
|
|
83403
|
-
constructor() {
|
|
83404
|
-
super(
|
|
83405
|
-
"The task parties are not bound on this machine. Sign the scope with `vapi task sign` on this machine first; an explicit --counterparty only confirms an existing binding."
|
|
83406
|
-
);
|
|
83407
|
-
this.name = "TasksPartiesNotBoundError";
|
|
83408
|
-
}
|
|
83409
|
-
};
|
|
83410
|
-
async function verifyDeployment(ready, rpc, overrides) {
|
|
83411
|
-
const factory = getTrustedTasksFactory(ready.chainId, overrides);
|
|
83412
|
-
if (!factory)
|
|
83413
|
-
throw new TasksChainError(
|
|
83414
|
-
`No trusted Tasks escrow factory is configured for chain ${ready.chainId}. Set VAPI_TASKS_ESCROW_FACTORY_${ready.chainId}.`,
|
|
83415
|
-
false,
|
|
83416
|
-
{ authorizationExposed: false }
|
|
83417
|
-
);
|
|
83418
|
-
if (!isAddressEqual(factory, ready.escrowContract))
|
|
83419
|
-
throw new TasksValidationError(
|
|
83420
|
-
"The Tasks readiness factory does not match the trusted factory."
|
|
83421
|
-
);
|
|
83422
|
-
if (await rpc.getChainId() !== ready.chainId)
|
|
83423
|
-
throw new TasksValidationError("The RPC chain ID does not match the task deployment.");
|
|
83424
|
-
const token = await rpc.readContract({
|
|
83425
|
-
address: factory,
|
|
83426
|
-
abi: TASKS_READ_ABI,
|
|
83427
|
-
functionName: "paymentToken"
|
|
83428
|
-
});
|
|
83429
|
-
if (!isAddressEqual(token, ready.usdc))
|
|
83430
|
-
throw new TasksValidationError(
|
|
83431
|
-
"The Tasks readiness token does not match the trusted factory payment token."
|
|
83432
|
-
);
|
|
83433
|
-
const [name, version5] = await Promise.all([
|
|
83434
|
-
rpc.readContract({ address: token, abi: TASKS_READ_ABI, functionName: "name" }),
|
|
83435
|
-
rpc.readContract({ address: token, abi: TASKS_READ_ABI, functionName: "version" })
|
|
83436
|
-
]);
|
|
83437
|
-
const domain2 = { name, version: version5, chainId: ready.chainId, verifyingContract: getAddress(token) };
|
|
83438
|
-
if (ready.eip3009Domain && (ready.eip3009Domain.name !== name || ready.eip3009Domain.version !== version5 || ready.eip3009Domain.chainId !== ready.chainId || !isAddressEqual(ready.eip3009Domain.verifyingContract, token)))
|
|
83439
|
-
throw new TasksValidationError(
|
|
83440
|
-
"The funding authorization domain does not match the onchain token domain."
|
|
83441
|
-
);
|
|
83442
|
-
return {
|
|
83443
|
-
...ready,
|
|
83444
|
-
escrowContract: getAddress(factory),
|
|
83445
|
-
usdc: getAddress(token),
|
|
83446
|
-
eip3009Domain: domain2
|
|
83447
|
-
};
|
|
83448
|
-
}
|
|
83449
|
-
async function verifyScope(client, signer, selected, ready, verb, steps, options = {}) {
|
|
83450
|
-
const { scopes } = await client.getScopes(selected.workOrderId);
|
|
83451
|
-
const matches = scopes.filter(
|
|
83452
|
-
(scope2) => scope2.state === "accepted" && scope2.milestoneId === selected.id
|
|
83453
|
-
);
|
|
83454
|
-
if (matches.length !== 1)
|
|
83455
|
-
throw new TasksValidationError("The task milestone requires one accepted signed scope.");
|
|
83456
|
-
const scope = matches[0];
|
|
83457
|
-
const payload = scope.signingPayload;
|
|
83458
|
-
const frozen = freezeScopeTerms(scope.structuredTerms, scope.brief);
|
|
83459
|
-
if (scope.workOrderId !== selected.workOrderId || payload.workOrderId !== selected.workOrderId || payload.trancheOrdinal !== selected.ordinal || scope.trancheOrdinal !== selected.ordinal || payload.scopeVersion !== scope.version || frozen.termsHash !== scope.termsHash || frozen.termsHash !== payload.termsHash || frozen.termsHash !== selected.termsHash)
|
|
83460
|
-
throw new TasksValidationError(
|
|
83461
|
-
"The accepted task scope does not match its locally verified terms hash and milestone."
|
|
83462
|
-
);
|
|
83463
|
-
if (!scope.counterpartyAddress || !scope.counterpartySignature || isAddressEqual(scope.proposerAddress, scope.counterpartyAddress) || !(isAddressEqual(signer, scope.proposerAddress) || isAddressEqual(signer, scope.counterpartyAddress)))
|
|
83464
|
-
throw new TasksValidationError(
|
|
83465
|
-
"The local signer is not one of the two accepted scope parties."
|
|
83466
|
-
);
|
|
83467
|
-
const message = canonicalJson(payload);
|
|
83468
|
-
const signatures = await Promise.all([
|
|
83469
|
-
verifyMessage({
|
|
83470
|
-
address: scope.proposerAddress,
|
|
83471
|
-
message,
|
|
83472
|
-
signature: scope.proposerSignature
|
|
83473
|
-
}),
|
|
83474
|
-
verifyMessage({
|
|
83475
|
-
address: scope.counterpartyAddress,
|
|
83476
|
-
message,
|
|
83477
|
-
signature: scope.counterpartySignature
|
|
83478
|
-
})
|
|
83479
|
-
]);
|
|
83480
|
-
if (signatures.some((valid) => !valid))
|
|
83481
|
-
throw new TasksValidationError("Both accepted task scope signatures must verify.");
|
|
83482
|
-
const terms = frozen.structured;
|
|
83483
|
-
if (terms.budget.network !== ready.network || terms.budget.asset.toLowerCase() !== `${ready.network}/erc20:${ready.usdc}`.toLowerCase() || !isAddressEqual(terms.escrow.contract, ready.escrowContract) || selected.network !== terms.budget.network || selected.asset.toLowerCase() !== terms.budget.asset.toLowerCase() || selected.amountBaseUnits !== terms.budget.amountBaseUnits)
|
|
83484
|
-
throw new TasksValidationError(
|
|
83485
|
-
"The signed task scope asset, factory or amount does not match the deployment and milestone."
|
|
83486
|
-
);
|
|
83487
|
-
const identity = {
|
|
83488
|
-
orderId: selected.workOrderId,
|
|
83489
|
-
trancheOrdinal: selected.ordinal,
|
|
83490
|
-
scopeVersion: scope.version,
|
|
83491
|
-
termsHash: frozen.termsHash,
|
|
83492
|
-
self: getAddress(signer)
|
|
83493
|
-
};
|
|
83494
|
-
const binding = await options.bindings?.get(identity);
|
|
83495
|
-
if (!binding) throw new TasksPartiesNotBoundError();
|
|
83496
|
-
if (options.counterparty && !isAddressEqual(binding.counterparty, options.counterparty))
|
|
83497
|
-
throw new TasksValidationError(
|
|
83498
|
-
"The confirmed counterparty differs from the locally bound parties."
|
|
83499
|
-
);
|
|
83500
|
-
if (!isAddressEqual(binding.self, signer) || binding.orderId !== identity.orderId || binding.trancheOrdinal !== identity.trancheOrdinal || binding.scopeVersion !== identity.scopeVersion || binding.termsHash.toLowerCase() !== identity.termsHash.toLowerCase() || ![scope.proposerAddress, scope.counterpartyAddress].every(
|
|
83501
|
-
(address10) => isAddressEqual(address10, binding.self) || isAddressEqual(address10, binding.counterparty)
|
|
83502
|
-
))
|
|
83503
|
-
throw new TasksValidationError(
|
|
83504
|
-
"The accepted scope parties do not match the locally bound parties."
|
|
83505
|
-
);
|
|
83506
|
-
const buyer = getAddress(binding.role === "client" ? binding.self : binding.counterparty);
|
|
83507
|
-
const seller = getAddress(binding.role === "provider" ? binding.self : binding.counterparty);
|
|
83508
|
-
if (verb === "createEscrow" && !isAddressEqual(signer, seller))
|
|
83509
|
-
throw new TasksValidationError("Task createEscrow requires the locally bound seller's wallet.");
|
|
83510
|
-
const workDurationSeconds = terms.workDurationSeconds ?? getTrustedTasksDurations(ready.chainId, options.trustedDurations).workDurationSeconds;
|
|
83511
|
-
if (workDurationSeconds === void 0)
|
|
83512
|
-
throw new TasksValidationError(
|
|
83513
|
-
"The signed task scope has no work duration and no trusted default is configured."
|
|
83514
|
-
);
|
|
83515
|
-
return {
|
|
83516
|
-
signer,
|
|
83517
|
-
buyer,
|
|
83518
|
-
seller,
|
|
83519
|
-
parties: [buyer, seller],
|
|
83520
|
-
workDurationSeconds,
|
|
83521
|
-
...verb === "fund" ? { approveAmount: BigInt(terms.budget.amountBaseUnits) } : {},
|
|
83522
|
-
reviewWindowSeconds: terms.acceptanceWindowSeconds,
|
|
83523
|
-
nowSeconds: BigInt(Math.floor((options.now ?? (() => /* @__PURE__ */ new Date()))().getTime() / 1e3)),
|
|
83524
|
-
verb,
|
|
83525
|
-
deployment: ready,
|
|
83526
|
-
milestone: {
|
|
83527
|
-
...selected,
|
|
83528
|
-
terms,
|
|
83529
|
-
termsHash: frozen.termsHash,
|
|
83530
|
-
amountBaseUnits: terms.budget.amountBaseUnits
|
|
83531
|
-
},
|
|
83532
|
-
steps
|
|
83533
|
-
};
|
|
83534
|
-
}
|
|
83535
|
-
async function verifyClone(rpc, expected, checkState) {
|
|
83536
|
-
if (expected.verb === "createEscrow") return;
|
|
83537
|
-
const clone2 = expected.milestone.escrowContract;
|
|
83538
|
-
const registered = await rpc.readContract({
|
|
83539
|
-
address: expected.deployment.escrowContract,
|
|
83540
|
-
abi: TASKS_READ_ABI,
|
|
83541
|
-
functionName: "isEscrow",
|
|
83542
|
-
args: [clone2]
|
|
83543
|
-
});
|
|
83544
|
-
if (!registered)
|
|
83545
|
-
throw new TasksValidationError(
|
|
83546
|
-
"The task escrow clone is not registered by the trusted factory."
|
|
83547
|
-
);
|
|
83548
|
-
const predicted = await rpc.readContract({
|
|
83549
|
-
address: expected.deployment.escrowContract,
|
|
83550
|
-
abi: TASKS_READ_ABI,
|
|
83551
|
-
functionName: "predictEscrow",
|
|
83552
|
-
args: [expected.seller, keccak256(stringToHex(expected.milestone.id))]
|
|
83553
|
-
});
|
|
83554
|
-
if (!isAddressEqual(predicted, clone2))
|
|
83555
|
-
throw new TasksValidationError(
|
|
83556
|
-
"The escrow clone does not match the signed milestone salt and bound seller."
|
|
83557
|
-
);
|
|
83558
|
-
const read = (functionName) => rpc.readContract({ address: clone2, abi: TASKS_READ_ABI, functionName });
|
|
83559
|
-
const [
|
|
83560
|
-
buyer,
|
|
83561
|
-
seller,
|
|
83562
|
-
token,
|
|
83563
|
-
amount4,
|
|
83564
|
-
termsHash,
|
|
83565
|
-
state,
|
|
83566
|
-
resolution,
|
|
83567
|
-
offerDeadline,
|
|
83568
|
-
workDeadline,
|
|
83569
|
-
reviewDeadline,
|
|
83570
|
-
disputedAt,
|
|
83571
|
-
counterEvidenceDeadline,
|
|
83572
|
-
slot0,
|
|
83573
|
-
slot6,
|
|
83574
|
-
slot7
|
|
83575
|
-
] = await Promise.all([
|
|
83576
|
-
read("buyer"),
|
|
83577
|
-
read("seller"),
|
|
83578
|
-
read("token"),
|
|
83579
|
-
read("amount"),
|
|
83580
|
-
read("termsHash"),
|
|
83581
|
-
read("state"),
|
|
83582
|
-
read("resolution"),
|
|
83583
|
-
read("offerDeadline"),
|
|
83584
|
-
read("workDeadline"),
|
|
83585
|
-
read("reviewDeadline"),
|
|
83586
|
-
read("disputedAt"),
|
|
83587
|
-
read("counterEvidenceDeadline"),
|
|
83588
|
-
rpc.getStorageAt({ address: clone2, slot: "0x0" }),
|
|
83589
|
-
rpc.getStorageAt({ address: clone2, slot: "0x6" }),
|
|
83590
|
-
rpc.getStorageAt({ address: clone2, slot: "0x7" })
|
|
83591
|
-
]);
|
|
83592
|
-
if (isAddressEqual(buyer, seller) || !isAddressEqual(buyer, expected.buyer) || !isAddressEqual(seller, expected.seller) || !isAddressEqual(token, expected.deployment.usdc) || amount4 !== BigInt(expected.milestone.amountBaseUnits) || termsHash.toLowerCase() !== expected.milestone.termsHash.toLowerCase())
|
|
83593
|
-
throw new TasksValidationError(
|
|
83594
|
-
"The onchain escrow parties, token, amount or terms hash do not match the signed scope."
|
|
83595
|
-
);
|
|
83596
|
-
const s0 = storageWord(slot0);
|
|
83597
|
-
const s6 = storageWord(slot6);
|
|
83598
|
-
const s7 = storageWord(slot7);
|
|
83599
|
-
if (field(s0, 0, 1) !== BigInt(state) || field(s0, 1, 1) !== BigInt(resolution) || !isAddressEqual(storageAddress(s0, 2), buyer) || field(s6, 0, 8) !== offerDeadline || field(s6, 8, 8) !== workDeadline || field(s6, 16, 8) !== reviewDeadline || field(s6, 24, 8) !== disputedAt || field(s7, 0, 8) !== counterEvidenceDeadline)
|
|
83600
|
-
throw new TasksValidationError("unsupported escrow layout");
|
|
83601
|
-
if (field(s7, 8, 8) !== BigInt(expected.workDurationSeconds) || field(s7, 16, 8) !== BigInt(expected.reviewWindowSeconds))
|
|
83602
|
-
throw new TasksValidationError(
|
|
83603
|
-
"The onchain escrow durations do not match the signed terms and trusted defaults."
|
|
83604
|
-
);
|
|
83605
|
-
const actor = expected.verb === "fund" || expected.verb === "release" ? buyer : expected.verb === "deliver" || expected.verb === "refund" ? seller : expected.signer;
|
|
83606
|
-
if (!isAddressEqual(actor, expected.signer))
|
|
83607
|
-
throw new TasksValidationError(
|
|
83608
|
-
`Task ${expected.verb} requires the onchain escrow party's local wallet.`
|
|
83609
|
-
);
|
|
83610
|
-
const states = {
|
|
83611
|
-
fund: [1],
|
|
83612
|
-
deliver: [2],
|
|
83613
|
-
release: [3],
|
|
83614
|
-
refund: [2, 3],
|
|
83615
|
-
dispute: [2, 3],
|
|
83616
|
-
"counter-evidence": [4],
|
|
83617
|
-
"resolve-unmatched": [4]
|
|
83618
|
-
};
|
|
83619
|
-
if (checkState && !states[expected.verb]?.includes(state))
|
|
83620
|
-
throw new TasksValidationError(
|
|
83621
|
-
`The onchain escrow state is not eligible for task ${expected.verb}.`
|
|
83622
|
-
);
|
|
83623
|
-
if (["dispute", "counter-evidence"].includes(expected.verb)) {
|
|
83624
|
-
const fee = disputeFeeBaseUnits(amount4);
|
|
83625
|
-
if (await read("disputeFee") !== fee)
|
|
83626
|
-
throw new TasksValidationError(
|
|
83627
|
-
"The onchain dispute fee does not match the verified amount fee rule."
|
|
83628
|
-
);
|
|
83629
|
-
expected.disputeFee = fee;
|
|
83630
|
-
expected.approveAmount = fee;
|
|
83631
|
-
}
|
|
83632
|
-
if (checkState && ["counter-evidence", "resolve-unmatched"].includes(expected.verb)) {
|
|
83633
|
-
const slot8 = storageWord(await rpc.getStorageAt({ address: clone2, slot: "0x8" }));
|
|
83634
|
-
const opener = storageAddress(slot8, 0);
|
|
83635
|
-
const submitted = field(slot8, 20, 1);
|
|
83636
|
-
if (!isAddressEqual(opener, buyer) && !isAddressEqual(opener, seller) || submitted > 1n || field(slot8, 21, 11) !== 0n)
|
|
83637
|
-
throw new TasksValidationError("unsupported escrow layout");
|
|
83638
|
-
const now = expected.nowSeconds;
|
|
83639
|
-
if (now === void 0)
|
|
83640
|
-
throw new TasksValidationError("A trusted clock is required for dispute eligibility.");
|
|
83641
|
-
if (submitted === 1n)
|
|
83642
|
-
throw new TasksValidationError(
|
|
83643
|
-
"Counter-evidence has already been submitted for this dispute."
|
|
83644
|
-
);
|
|
83645
|
-
if (expected.verb === "counter-evidence") {
|
|
83646
|
-
if (isAddressEqual(opener, expected.signer))
|
|
83647
|
-
throw new TasksValidationError("Only the non-opener party can submit counter-evidence.");
|
|
83648
|
-
if (now >= counterEvidenceDeadline)
|
|
83649
|
-
throw new TasksValidationError("The counter-evidence deadline has passed.");
|
|
83650
|
-
} else if (now <= counterEvidenceDeadline)
|
|
83651
|
-
throw new TasksValidationError(
|
|
83652
|
-
"The counter-evidence deadline has not passed; unmatched resolution is unavailable."
|
|
83653
|
-
);
|
|
83654
|
-
}
|
|
83655
|
-
expected.offerDeadline = offerDeadline;
|
|
83656
|
-
}
|
|
83657
|
-
function storageWord(value) {
|
|
83658
|
-
if (!value || !/^0x[0-9a-fA-F]{64}$/.test(value))
|
|
83659
|
-
throw new TasksValidationError("unsupported escrow layout");
|
|
83660
|
-
return BigInt(value);
|
|
83661
|
-
}
|
|
83662
|
-
function field(word, offset, bytes) {
|
|
83663
|
-
return word >> BigInt(offset * 8) & (1n << BigInt(bytes * 8)) - 1n;
|
|
83664
|
-
}
|
|
83665
|
-
function storageAddress(word, offset) {
|
|
83666
|
-
return getAddress(`0x${field(word, offset, 20).toString(16).padStart(40, "0")}`);
|
|
83667
|
-
}
|
|
83668
|
-
|
|
83669
|
-
// ../core/src/tasks/v2-abi.generated.ts
|
|
83670
|
-
var escrowFactoryV2Abi = [
|
|
83671
|
-
{
|
|
83672
|
-
type: "constructor",
|
|
83673
|
-
inputs: [
|
|
83674
|
-
{ name: "initialOwner", type: "address", internalType: "address" },
|
|
83675
|
-
{ name: "feeRouter", type: "address", internalType: "address" },
|
|
83676
|
-
{ name: "disputeResolver", type: "address", internalType: "address" },
|
|
83677
|
-
{ name: "outcomeRegistry", type: "address", internalType: "address" },
|
|
83678
|
-
{ name: "usdc", type: "address", internalType: "address" },
|
|
83679
|
-
{ name: "initialFeeBp", type: "uint16", internalType: "uint16" },
|
|
83680
|
-
{ name: "maxFeeBp_", type: "uint16", internalType: "uint16" },
|
|
83681
|
-
{ name: "maxEscrowAmount_", type: "uint256", internalType: "uint256" },
|
|
83682
|
-
{ name: "cancelGrace", type: "uint64", internalType: "uint64" },
|
|
83683
|
-
{ name: "lateWindow", type: "uint64", internalType: "uint64" },
|
|
83684
|
-
{ name: "minWorkTime", type: "uint64", internalType: "uint64" }
|
|
83685
|
-
],
|
|
83686
|
-
stateMutability: "nonpayable"
|
|
83687
|
-
},
|
|
83688
|
-
{
|
|
83689
|
-
type: "function",
|
|
83690
|
-
name: "bountyImplementation",
|
|
83691
|
-
inputs: [],
|
|
83692
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83693
|
-
stateMutability: "view"
|
|
83694
|
-
},
|
|
83695
|
-
{
|
|
83696
|
-
type: "function",
|
|
83697
|
-
name: "createAndFundWithAuthorization",
|
|
83698
|
-
inputs: [
|
|
83699
|
-
{
|
|
83700
|
-
name: "terms_",
|
|
83701
|
-
type: "tuple",
|
|
83702
|
-
internalType: "struct IEscrowV2.Terms",
|
|
83703
|
-
components: [
|
|
83704
|
-
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83705
|
-
{ name: "poster", type: "address", internalType: "address" },
|
|
83706
|
-
{ name: "worker", type: "address", internalType: "address" },
|
|
83707
|
-
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83708
|
-
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83709
|
-
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83710
|
-
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83711
|
-
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83712
|
-
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83713
|
-
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83714
|
-
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83715
|
-
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83716
|
-
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83717
|
-
]
|
|
83718
|
-
},
|
|
83719
|
-
{
|
|
83720
|
-
name: "milestones",
|
|
83721
|
-
type: "tuple[]",
|
|
83722
|
-
internalType: "struct IEscrowV2.Milestone[]",
|
|
83723
|
-
components: [
|
|
83724
|
-
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83725
|
-
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83726
|
-
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83727
|
-
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83728
|
-
]
|
|
83729
|
-
},
|
|
83730
|
-
{ name: "salt", type: "bytes32", internalType: "bytes32" },
|
|
83731
|
-
{ name: "from", type: "address", internalType: "address" },
|
|
83732
|
-
{ name: "validAfter", type: "uint256", internalType: "uint256" },
|
|
83733
|
-
{ name: "validBefore", type: "uint256", internalType: "uint256" },
|
|
83734
|
-
{ name: "nonce", type: "bytes32", internalType: "bytes32" },
|
|
83735
|
-
{ name: "signature", type: "bytes", internalType: "bytes" }
|
|
83736
|
-
],
|
|
83737
|
-
outputs: [{ name: "escrow", type: "address", internalType: "address" }],
|
|
83738
|
-
stateMutability: "nonpayable"
|
|
83739
|
-
},
|
|
83740
|
-
{
|
|
83741
|
-
type: "function",
|
|
83742
|
-
name: "createEscrow",
|
|
83743
|
-
inputs: [
|
|
83744
|
-
{
|
|
83745
|
-
name: "terms_",
|
|
83746
|
-
type: "tuple",
|
|
83747
|
-
internalType: "struct IEscrowV2.Terms",
|
|
83748
|
-
components: [
|
|
83749
|
-
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83750
|
-
{ name: "poster", type: "address", internalType: "address" },
|
|
83751
|
-
{ name: "worker", type: "address", internalType: "address" },
|
|
83752
|
-
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83753
|
-
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83754
|
-
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83755
|
-
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83756
|
-
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83757
|
-
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83758
|
-
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83759
|
-
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83760
|
-
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83761
|
-
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83762
|
-
]
|
|
83763
|
-
},
|
|
83764
|
-
{
|
|
83765
|
-
name: "milestones",
|
|
83766
|
-
type: "tuple[]",
|
|
83767
|
-
internalType: "struct IEscrowV2.Milestone[]",
|
|
83768
|
-
components: [
|
|
83769
|
-
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83770
|
-
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83771
|
-
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83772
|
-
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83773
|
-
]
|
|
83774
|
-
},
|
|
83775
|
-
{ name: "salt", type: "bytes32", internalType: "bytes32" }
|
|
83776
|
-
],
|
|
83777
|
-
outputs: [{ name: "escrow", type: "address", internalType: "address" }],
|
|
83778
|
-
stateMutability: "nonpayable"
|
|
83779
|
-
},
|
|
83780
|
-
{
|
|
83781
|
-
type: "function",
|
|
83782
|
-
name: "feeBp",
|
|
83783
|
-
inputs: [],
|
|
83784
|
-
outputs: [{ name: "", type: "uint16", internalType: "uint16" }],
|
|
83785
|
-
stateMutability: "view"
|
|
83786
|
-
},
|
|
83787
|
-
{
|
|
83788
|
-
type: "function",
|
|
83789
|
-
name: "implementation",
|
|
83790
|
-
inputs: [],
|
|
83791
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83792
|
-
stateMutability: "view"
|
|
83793
|
-
},
|
|
83794
|
-
{
|
|
83795
|
-
type: "function",
|
|
83796
|
-
name: "isEscrow",
|
|
83797
|
-
inputs: [{ name: "escrow", type: "address", internalType: "address" }],
|
|
83798
|
-
outputs: [{ name: "registered", type: "bool", internalType: "bool" }],
|
|
83799
|
-
stateMutability: "view"
|
|
83800
|
-
},
|
|
83801
|
-
{
|
|
83802
|
-
type: "function",
|
|
83803
|
-
name: "maxEscrowAmount",
|
|
83804
|
-
inputs: [],
|
|
83805
|
-
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
83806
|
-
stateMutability: "view"
|
|
83807
|
-
},
|
|
83808
|
-
{
|
|
83809
|
-
type: "function",
|
|
83810
|
-
name: "maxFeeBp",
|
|
83811
|
-
inputs: [],
|
|
83812
|
-
outputs: [{ name: "", type: "uint16", internalType: "uint16" }],
|
|
83813
|
-
stateMutability: "view"
|
|
83814
|
-
},
|
|
83815
|
-
{
|
|
83816
|
-
type: "function",
|
|
83817
|
-
name: "owner",
|
|
83818
|
-
inputs: [],
|
|
83819
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83820
|
-
stateMutability: "view"
|
|
83821
|
-
},
|
|
83822
|
-
{ type: "function", name: "pause", inputs: [], outputs: [], stateMutability: "nonpayable" },
|
|
83823
|
-
{
|
|
83824
|
-
type: "function",
|
|
83825
|
-
name: "paused",
|
|
83826
|
-
inputs: [],
|
|
83827
|
-
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
83828
|
-
stateMutability: "view"
|
|
83829
|
-
},
|
|
83830
|
-
{
|
|
83831
|
-
type: "function",
|
|
83832
|
-
name: "paymentToken",
|
|
83833
|
-
inputs: [],
|
|
83834
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83835
|
-
stateMutability: "view"
|
|
83836
|
-
},
|
|
83837
|
-
{
|
|
83838
|
-
type: "function",
|
|
83839
|
-
name: "predictBountyEscrow",
|
|
83840
|
-
inputs: [
|
|
83841
|
-
{
|
|
83842
|
-
name: "terms_",
|
|
83843
|
-
type: "tuple",
|
|
83844
|
-
internalType: "struct IEscrowV2.Terms",
|
|
83845
|
-
components: [
|
|
83846
|
-
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83847
|
-
{ name: "poster", type: "address", internalType: "address" },
|
|
83848
|
-
{ name: "worker", type: "address", internalType: "address" },
|
|
83849
|
-
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83850
|
-
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83851
|
-
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83852
|
-
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83853
|
-
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83854
|
-
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83855
|
-
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83856
|
-
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83857
|
-
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83858
|
-
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83859
|
-
]
|
|
83860
|
-
},
|
|
83861
|
-
{
|
|
83862
|
-
name: "milestones",
|
|
83863
|
-
type: "tuple[]",
|
|
83864
|
-
internalType: "struct IEscrowV2.Milestone[]",
|
|
83865
|
-
components: [
|
|
83866
|
-
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83867
|
-
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83868
|
-
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83869
|
-
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83870
|
-
]
|
|
83871
|
-
},
|
|
83872
|
-
{ name: "salt", type: "bytes32", internalType: "bytes32" }
|
|
83873
|
-
],
|
|
83874
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83875
|
-
stateMutability: "view"
|
|
83876
|
-
},
|
|
83877
|
-
{
|
|
83878
|
-
type: "function",
|
|
83879
|
-
name: "predictEscrow",
|
|
83880
|
-
inputs: [
|
|
83881
|
-
{
|
|
83882
|
-
name: "terms_",
|
|
83883
|
-
type: "tuple",
|
|
83884
|
-
internalType: "struct IEscrowV2.Terms",
|
|
83885
|
-
components: [
|
|
83886
|
-
{ name: "shape", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83887
|
-
{ name: "poster", type: "address", internalType: "address" },
|
|
83888
|
-
{ name: "worker", type: "address", internalType: "address" },
|
|
83889
|
-
{ name: "termsHash", type: "bytes32", internalType: "bytes32" },
|
|
83890
|
-
{ name: "offerTtl", type: "uint64", internalType: "uint64" },
|
|
83891
|
-
{ name: "reviewWindow", type: "uint64", internalType: "uint64" },
|
|
83892
|
-
{ name: "choiceWindow", type: "uint64", internalType: "uint64" },
|
|
83893
|
-
{ name: "bountyDeadline", type: "uint64", internalType: "uint64" },
|
|
83894
|
-
{ name: "objectionWindow", type: "uint64", internalType: "uint64" },
|
|
83895
|
-
{ name: "workerBondBp", type: "uint16", internalType: "uint16" },
|
|
83896
|
-
{ name: "feeBp", type: "uint16", internalType: "uint16" },
|
|
83897
|
-
{ name: "winners", type: "uint8", internalType: "uint8" },
|
|
83898
|
-
{ name: "rewardPerWinner", type: "uint96", internalType: "uint96" }
|
|
83899
|
-
]
|
|
83900
|
-
},
|
|
83901
|
-
{
|
|
83902
|
-
name: "milestones",
|
|
83903
|
-
type: "tuple[]",
|
|
83904
|
-
internalType: "struct IEscrowV2.Milestone[]",
|
|
83905
|
-
components: [
|
|
83906
|
-
{ name: "amount", type: "uint96", internalType: "uint96" },
|
|
83907
|
-
{ name: "deadline", type: "uint64", internalType: "uint64" },
|
|
83908
|
-
{ name: "status", type: "uint8", internalType: "uint8" },
|
|
83909
|
-
{ name: "deliveryHash", type: "bytes32", internalType: "bytes32" }
|
|
83910
|
-
]
|
|
83911
|
-
},
|
|
83912
|
-
{ name: "salt", type: "bytes32", internalType: "bytes32" }
|
|
83913
|
-
],
|
|
83914
|
-
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
83915
|
-
stateMutability: "view"
|
|
83916
|
-
},
|
|
83917
|
-
{
|
|
83918
|
-
type: "function",
|
|
83919
|
-
name: "renounceOwnership",
|
|
83920
|
-
inputs: [],
|
|
83921
|
-
outputs: [],
|
|
83922
|
-
stateMutability: "nonpayable"
|
|
83923
|
-
},
|
|
83924
|
-
{
|
|
83925
|
-
type: "function",
|
|
83926
|
-
name: "setFeeBp",
|
|
83927
|
-
inputs: [{ name: "newFeeBp", type: "uint16", internalType: "uint16" }],
|
|
83928
|
-
outputs: [],
|
|
83929
|
-
stateMutability: "nonpayable"
|
|
83930
|
-
},
|
|
83931
|
-
{
|
|
83932
|
-
type: "function",
|
|
83933
|
-
name: "setMaxEscrowAmount",
|
|
83934
|
-
inputs: [{ name: "newAmount", type: "uint256", internalType: "uint256" }],
|
|
83935
|
-
outputs: [],
|
|
83936
|
-
stateMutability: "nonpayable"
|
|
83937
|
-
},
|
|
83938
|
-
{
|
|
83939
|
-
type: "function",
|
|
83940
|
-
name: "transferOwnership",
|
|
83941
|
-
inputs: [{ name: "newOwner", type: "address", internalType: "address" }],
|
|
83942
|
-
outputs: [],
|
|
83943
|
-
stateMutability: "nonpayable"
|
|
83944
|
-
},
|
|
83945
|
-
{ type: "function", name: "unpause", inputs: [], outputs: [], stateMutability: "nonpayable" },
|
|
83946
|
-
{
|
|
83947
|
-
type: "event",
|
|
83948
|
-
name: "EscrowCreated",
|
|
83949
|
-
inputs: [
|
|
83950
|
-
{ name: "escrow", type: "address", indexed: true, internalType: "address" },
|
|
83951
|
-
{ name: "poster", type: "address", indexed: true, internalType: "address" },
|
|
83952
|
-
{ name: "termsHash", type: "bytes32", indexed: true, internalType: "bytes32" },
|
|
83953
|
-
{ name: "salt", type: "bytes32", indexed: false, internalType: "bytes32" },
|
|
83954
|
-
{ name: "feeBp", type: "uint16", indexed: false, internalType: "uint16" }
|
|
83955
|
-
],
|
|
83956
|
-
anonymous: false
|
|
83957
|
-
},
|
|
83958
|
-
{
|
|
83959
|
-
type: "event",
|
|
83960
|
-
name: "FeeBpSet",
|
|
83961
|
-
inputs: [
|
|
83962
|
-
{ name: "previousFeeBp", type: "uint16", indexed: false, internalType: "uint16" },
|
|
83963
|
-
{ name: "newFeeBp", type: "uint16", indexed: false, internalType: "uint16" }
|
|
83964
|
-
],
|
|
83965
|
-
anonymous: false
|
|
83966
|
-
},
|
|
83967
|
-
{
|
|
83968
|
-
type: "event",
|
|
83969
|
-
name: "MaxEscrowAmountSet",
|
|
83970
|
-
inputs: [
|
|
83971
|
-
{ name: "previousAmount", type: "uint256", indexed: false, internalType: "uint256" },
|
|
83972
|
-
{ name: "newAmount", type: "uint256", indexed: false, internalType: "uint256" }
|
|
83973
|
-
],
|
|
83974
|
-
anonymous: false
|
|
83975
|
-
},
|
|
83976
|
-
{
|
|
83977
|
-
type: "event",
|
|
83978
|
-
name: "OwnershipTransferred",
|
|
83979
|
-
inputs: [
|
|
83980
|
-
{ name: "previousOwner", type: "address", indexed: true, internalType: "address" },
|
|
83981
|
-
{ name: "newOwner", type: "address", indexed: true, internalType: "address" }
|
|
83982
|
-
],
|
|
83983
|
-
anonymous: false
|
|
83984
|
-
},
|
|
83985
|
-
{
|
|
83986
|
-
type: "event",
|
|
83987
|
-
name: "PauseSet",
|
|
83988
|
-
inputs: [{ name: "paused", type: "bool", indexed: false, internalType: "bool" }],
|
|
83989
|
-
anonymous: false
|
|
83990
|
-
},
|
|
83991
|
-
{
|
|
83992
|
-
type: "error",
|
|
83993
|
-
name: "EscrowAlreadyExists",
|
|
83994
|
-
inputs: [{ name: "escrow", type: "address", internalType: "address" }]
|
|
83995
|
-
},
|
|
83996
|
-
{
|
|
83997
|
-
type: "error",
|
|
83998
|
-
name: "EscrowAmountAboveCap",
|
|
83999
|
-
inputs: [
|
|
84000
|
-
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
84001
|
-
{ name: "cap", type: "uint256", internalType: "uint256" }
|
|
84002
|
-
]
|
|
84003
|
-
},
|
|
84004
|
-
{ type: "error", name: "FactoryPaused", inputs: [] },
|
|
84005
|
-
{ type: "error", name: "FailedDeployment", inputs: [] },
|
|
84006
|
-
{
|
|
84007
|
-
type: "error",
|
|
84008
|
-
name: "InsufficientBalance",
|
|
84009
|
-
inputs: [
|
|
84010
|
-
{ name: "balance", type: "uint256", internalType: "uint256" },
|
|
84011
|
-
{ name: "needed", type: "uint256", internalType: "uint256" }
|
|
84012
|
-
]
|
|
84013
|
-
},
|
|
84014
|
-
{ type: "error", name: "InvalidAddress", inputs: [] },
|
|
84015
|
-
{ type: "error", name: "InvalidFee", inputs: [] },
|
|
84016
|
-
{ type: "error", name: "InvalidToken", inputs: [] },
|
|
84017
|
-
{
|
|
84018
|
-
type: "error",
|
|
84019
|
-
name: "OwnableInvalidOwner",
|
|
84020
|
-
inputs: [{ name: "owner", type: "address", internalType: "address" }]
|
|
84021
|
-
},
|
|
84022
|
-
{
|
|
84023
|
-
type: "error",
|
|
84024
|
-
name: "OwnableUnauthorizedAccount",
|
|
84025
|
-
inputs: [{ name: "account", type: "address", internalType: "address" }]
|
|
84026
|
-
},
|
|
84027
|
-
{
|
|
84028
|
-
type: "error",
|
|
84029
|
-
name: "ShapeMismatch",
|
|
84030
|
-
inputs: [
|
|
84031
|
-
{ name: "expected", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
84032
|
-
{ name: "supplied", type: "uint8", internalType: "enum IEscrowV2.Shape" }
|
|
84033
|
-
]
|
|
84034
|
-
},
|
|
84035
|
-
{
|
|
84036
|
-
type: "error",
|
|
84037
|
-
name: "TermsFeeMismatch",
|
|
84038
|
-
inputs: [
|
|
84039
|
-
{ name: "expected", type: "uint16", internalType: "uint16" },
|
|
84040
|
-
{ name: "supplied", type: "uint16", internalType: "uint16" }
|
|
84041
|
-
]
|
|
83465
|
+
anonymous: false
|
|
83466
|
+
},
|
|
83467
|
+
{
|
|
83468
|
+
type: "event",
|
|
83469
|
+
name: "FeeBpSet",
|
|
83470
|
+
inputs: [
|
|
83471
|
+
{ name: "previousFeeBp", type: "uint16", indexed: false, internalType: "uint16" },
|
|
83472
|
+
{ name: "newFeeBp", type: "uint16", indexed: false, internalType: "uint16" }
|
|
83473
|
+
],
|
|
83474
|
+
anonymous: false
|
|
83475
|
+
},
|
|
83476
|
+
{
|
|
83477
|
+
type: "event",
|
|
83478
|
+
name: "MaxEscrowAmountSet",
|
|
83479
|
+
inputs: [
|
|
83480
|
+
{ name: "previousAmount", type: "uint256", indexed: false, internalType: "uint256" },
|
|
83481
|
+
{ name: "newAmount", type: "uint256", indexed: false, internalType: "uint256" }
|
|
83482
|
+
],
|
|
83483
|
+
anonymous: false
|
|
83484
|
+
},
|
|
83485
|
+
{
|
|
83486
|
+
type: "event",
|
|
83487
|
+
name: "OwnershipTransferred",
|
|
83488
|
+
inputs: [
|
|
83489
|
+
{ name: "previousOwner", type: "address", indexed: true, internalType: "address" },
|
|
83490
|
+
{ name: "newOwner", type: "address", indexed: true, internalType: "address" }
|
|
83491
|
+
],
|
|
83492
|
+
anonymous: false
|
|
83493
|
+
},
|
|
83494
|
+
{
|
|
83495
|
+
type: "event",
|
|
83496
|
+
name: "PauseSet",
|
|
83497
|
+
inputs: [{ name: "paused", type: "bool", indexed: false, internalType: "bool" }],
|
|
83498
|
+
anonymous: false
|
|
83499
|
+
},
|
|
83500
|
+
{
|
|
83501
|
+
type: "error",
|
|
83502
|
+
name: "EscrowAlreadyExists",
|
|
83503
|
+
inputs: [{ name: "escrow", type: "address", internalType: "address" }]
|
|
83504
|
+
},
|
|
83505
|
+
{
|
|
83506
|
+
type: "error",
|
|
83507
|
+
name: "EscrowAmountAboveCap",
|
|
83508
|
+
inputs: [
|
|
83509
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
83510
|
+
{ name: "cap", type: "uint256", internalType: "uint256" }
|
|
83511
|
+
]
|
|
83512
|
+
},
|
|
83513
|
+
{ type: "error", name: "FactoryPaused", inputs: [] },
|
|
83514
|
+
{ type: "error", name: "FailedDeployment", inputs: [] },
|
|
83515
|
+
{
|
|
83516
|
+
type: "error",
|
|
83517
|
+
name: "InsufficientBalance",
|
|
83518
|
+
inputs: [
|
|
83519
|
+
{ name: "balance", type: "uint256", internalType: "uint256" },
|
|
83520
|
+
{ name: "needed", type: "uint256", internalType: "uint256" }
|
|
83521
|
+
]
|
|
83522
|
+
},
|
|
83523
|
+
{ type: "error", name: "InvalidAddress", inputs: [] },
|
|
83524
|
+
{ type: "error", name: "InvalidFee", inputs: [] },
|
|
83525
|
+
{ type: "error", name: "InvalidToken", inputs: [] },
|
|
83526
|
+
{
|
|
83527
|
+
type: "error",
|
|
83528
|
+
name: "OwnableInvalidOwner",
|
|
83529
|
+
inputs: [{ name: "owner", type: "address", internalType: "address" }]
|
|
83530
|
+
},
|
|
83531
|
+
{
|
|
83532
|
+
type: "error",
|
|
83533
|
+
name: "OwnableUnauthorizedAccount",
|
|
83534
|
+
inputs: [{ name: "account", type: "address", internalType: "address" }]
|
|
83535
|
+
},
|
|
83536
|
+
{
|
|
83537
|
+
type: "error",
|
|
83538
|
+
name: "ShapeMismatch",
|
|
83539
|
+
inputs: [
|
|
83540
|
+
{ name: "expected", type: "uint8", internalType: "enum IEscrowV2.Shape" },
|
|
83541
|
+
{ name: "supplied", type: "uint8", internalType: "enum IEscrowV2.Shape" }
|
|
83542
|
+
]
|
|
83543
|
+
},
|
|
83544
|
+
{
|
|
83545
|
+
type: "error",
|
|
83546
|
+
name: "TermsFeeMismatch",
|
|
83547
|
+
inputs: [
|
|
83548
|
+
{ name: "expected", type: "uint16", internalType: "uint16" },
|
|
83549
|
+
{ name: "supplied", type: "uint16", internalType: "uint16" }
|
|
83550
|
+
]
|
|
84042
83551
|
}
|
|
84043
83552
|
];
|
|
84044
83553
|
var escrowV2Abi = [
|
|
@@ -86659,10 +86168,6 @@ var TASK_V2_CASE_STATE = {
|
|
|
86659
86168
|
Snapshotting: 6
|
|
86660
86169
|
};
|
|
86661
86170
|
|
|
86662
|
-
// ../core/src/tasks/operation-support.ts
|
|
86663
|
-
import { readFile as readFile18, stat as stat15 } from "node:fs/promises";
|
|
86664
|
-
import { basename as basename2, extname } from "node:path";
|
|
86665
|
-
|
|
86666
86171
|
// ../core/src/tasks/v2-events.ts
|
|
86667
86172
|
var TASK_V2_NO_VERDICT_SUMMARY = "Disputed: status quo final after round 2 without a verdict; no dispute winner.";
|
|
86668
86173
|
var TASK_V2_REVIEWER_GUIDANCE = "mayVote reports jury membership only. Do not touch your stake until you have revealed; even a cancelled unstake can cost the vote.";
|
|
@@ -86697,6 +86202,73 @@ function taskV2OutcomeLines(value) {
|
|
|
86697
86202
|
return [...new Set(Object.values(source).flatMap(taskV2OutcomeLines))];
|
|
86698
86203
|
}
|
|
86699
86204
|
|
|
86205
|
+
// ../core/src/tasks/money.ts
|
|
86206
|
+
function formatBaseUnitsUsd(baseUnits2) {
|
|
86207
|
+
const [whole, fraction = ""] = formatUsdc(parseBaseUnits(baseUnits2)).split(".");
|
|
86208
|
+
return `${whole}.${fraction.padEnd(2, "0")}`;
|
|
86209
|
+
}
|
|
86210
|
+
function parseUsdToBaseUnits(text) {
|
|
86211
|
+
if (!/^\d+(?:\.\d{1,6})?$/u.test(text)) {
|
|
86212
|
+
throw new Error(
|
|
86213
|
+
"Task USD amount must be a non-negative decimal with at most six decimal places."
|
|
86214
|
+
);
|
|
86215
|
+
}
|
|
86216
|
+
const [whole = "0", fraction = ""] = text.split(".");
|
|
86217
|
+
return BigInt(whole) * 1000000n + BigInt(fraction.padEnd(6, "0"));
|
|
86218
|
+
}
|
|
86219
|
+
function parseFeeBp(deploymentOrReadiness) {
|
|
86220
|
+
if (typeof deploymentOrReadiness !== "object" || deploymentOrReadiness === null || !("feeBp" in deploymentOrReadiness)) {
|
|
86221
|
+
return null;
|
|
86222
|
+
}
|
|
86223
|
+
const feeBp = deploymentOrReadiness.feeBp;
|
|
86224
|
+
if (feeBp === void 0 || feeBp === null) return null;
|
|
86225
|
+
validateFeeBp(feeBp);
|
|
86226
|
+
return feeBp;
|
|
86227
|
+
}
|
|
86228
|
+
function taskMoney(grossBaseUnits, feeBp) {
|
|
86229
|
+
const atomic = parseBaseUnits(grossBaseUnits);
|
|
86230
|
+
const gross = amount3(atomic);
|
|
86231
|
+
if (feeBp === null) {
|
|
86232
|
+
return { gross, fee: null, net: null, feeBp, line: `$${gross.usd} gross \xB7 fee unavailable` };
|
|
86233
|
+
}
|
|
86234
|
+
validateFeeBp(feeBp);
|
|
86235
|
+
const feeAtomic = atomic * BigInt(feeBp) / 10000n;
|
|
86236
|
+
const fee = amount3(feeAtomic);
|
|
86237
|
+
const net = amount3(atomic - feeAtomic);
|
|
86238
|
+
return {
|
|
86239
|
+
gross,
|
|
86240
|
+
fee,
|
|
86241
|
+
net,
|
|
86242
|
+
feeBp,
|
|
86243
|
+
line: `$${gross.usd} gross \xB7 $${fee.usd} fee \xB7 $${net.usd} net`
|
|
86244
|
+
};
|
|
86245
|
+
}
|
|
86246
|
+
function amount3(atomic) {
|
|
86247
|
+
return { usd: formatBaseUnitsUsd(atomic), baseUnits: atomic.toString() };
|
|
86248
|
+
}
|
|
86249
|
+
function validateFeeBp(value) {
|
|
86250
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 1e4) {
|
|
86251
|
+
throw new Error("Task fee basis points must be an integer from 0 to 10000.");
|
|
86252
|
+
}
|
|
86253
|
+
}
|
|
86254
|
+
function parseBaseUnits(value) {
|
|
86255
|
+
if (typeof value === "string" && !/^\d+$/u.test(value) || typeof value !== "bigint" && typeof value !== "string") {
|
|
86256
|
+
throw new Error("Task base units must be a non-negative integer.");
|
|
86257
|
+
}
|
|
86258
|
+
const atomic = BigInt(value);
|
|
86259
|
+
if (atomic < 0n) throw new Error("Task base units must be a non-negative integer.");
|
|
86260
|
+
return atomic;
|
|
86261
|
+
}
|
|
86262
|
+
function taskPolicyAtomic(value) {
|
|
86263
|
+
if (!Number.isFinite(value) || value < 0)
|
|
86264
|
+
throw new Error("Task policy USD amounts must be finite and non-negative.");
|
|
86265
|
+
const [mantissa = "0", exponent = "0"] = value.toString().split("e");
|
|
86266
|
+
const [whole = "0", fraction = ""] = mantissa.split(".");
|
|
86267
|
+
const digits = BigInt(whole + fraction);
|
|
86268
|
+
const scale = 6 + Number(exponent) - fraction.length;
|
|
86269
|
+
return scale >= 0 ? digits * 10n ** BigInt(scale) : digits / 10n ** BigInt(-scale);
|
|
86270
|
+
}
|
|
86271
|
+
|
|
86700
86272
|
// ../core/src/tasks/operation-support.ts
|
|
86701
86273
|
var TaskOperationError = class extends Error {
|
|
86702
86274
|
constructor(code, message, manifestHash, details) {
|
|
@@ -86973,121 +86545,667 @@ function nextTaskEvents(page, cursor2) {
|
|
|
86973
86545
|
"invalid_response",
|
|
86974
86546
|
"The task event cursor regressed or is malformed."
|
|
86975
86547
|
);
|
|
86976
|
-
for (const event of page.events)
|
|
86977
|
-
if (!Number.isSafeInteger(event.sequence) || event.sequence < 0)
|
|
86978
|
-
throw new TaskOperationError("invalid_response", "A task event sequence is malformed.");
|
|
86979
|
-
const seen = /* @__PURE__ */ new Set();
|
|
86980
|
-
const events = [...page.events].sort((a, b) => a.sequence - b.sequence).filter((event) => {
|
|
86981
|
-
if (event.sequence <= cursor2 || seen.has(event.sequence)) return false;
|
|
86982
|
-
seen.add(event.sequence);
|
|
86983
|
-
return true;
|
|
86548
|
+
for (const event of page.events)
|
|
86549
|
+
if (!Number.isSafeInteger(event.sequence) || event.sequence < 0)
|
|
86550
|
+
throw new TaskOperationError("invalid_response", "A task event sequence is malformed.");
|
|
86551
|
+
const seen = /* @__PURE__ */ new Set();
|
|
86552
|
+
const events = [...page.events].sort((a, b) => a.sequence - b.sequence).filter((event) => {
|
|
86553
|
+
if (event.sequence <= cursor2 || seen.has(event.sequence)) return false;
|
|
86554
|
+
seen.add(event.sequence);
|
|
86555
|
+
return true;
|
|
86556
|
+
});
|
|
86557
|
+
return {
|
|
86558
|
+
events,
|
|
86559
|
+
nextCursor: Math.max(cursor2, page.nextAfter, ...page.events.map((e3) => e3.sequence))
|
|
86560
|
+
};
|
|
86561
|
+
}
|
|
86562
|
+
async function accountTaskPolicy(directory, wallet, warn) {
|
|
86563
|
+
let raw;
|
|
86564
|
+
try {
|
|
86565
|
+
raw = await readFile18(join16(directory, "wallets.json"), "utf8");
|
|
86566
|
+
} catch {
|
|
86567
|
+
return void 0;
|
|
86568
|
+
}
|
|
86569
|
+
try {
|
|
86570
|
+
const wallets = JSON.parse(raw).wallets;
|
|
86571
|
+
const stored = wallets && Object.hasOwn(wallets, wallet) ? wallets[wallet]?.taskPolicy : void 0;
|
|
86572
|
+
return stored === void 0 ? void 0 : walletTaskPolicySchema.parse(stored);
|
|
86573
|
+
} catch {
|
|
86574
|
+
warn?.(`The task limits stored for account ${wallet} are unreadable; using the defaults.`);
|
|
86575
|
+
return void 0;
|
|
86576
|
+
}
|
|
86577
|
+
}
|
|
86578
|
+
async function taskPolicyForWallet(args) {
|
|
86579
|
+
let invalid = false;
|
|
86580
|
+
const profiles = await listAgentProfiles(args.directory, {
|
|
86581
|
+
schema: args.schema,
|
|
86582
|
+
...args.warn ? { warn: args.warn } : {},
|
|
86583
|
+
onInvalid: () => {
|
|
86584
|
+
invalid = true;
|
|
86585
|
+
}
|
|
86586
|
+
});
|
|
86587
|
+
if (invalid) throw new TaskInputError("An invalid agent profile prevents task policy selection.");
|
|
86588
|
+
const matches = profiles.filter((profile2) => profile2.wallet === args.wallet);
|
|
86589
|
+
if (matches.length > 1)
|
|
86590
|
+
throw new TaskInputError(
|
|
86591
|
+
`More than one agent profile uses wallet ${args.wallet}; task policy is ambiguous.`
|
|
86592
|
+
);
|
|
86593
|
+
const profile = matches[0];
|
|
86594
|
+
if (profile)
|
|
86595
|
+
return {
|
|
86596
|
+
maxPerTaskUsd: profile.maxPerTaskUsd,
|
|
86597
|
+
approveAboveUsd: profile.approveAboveUsd,
|
|
86598
|
+
autoReleaseBelowUsd: profile.autoReleaseBelowUsd,
|
|
86599
|
+
source: "agent-profile"
|
|
86600
|
+
};
|
|
86601
|
+
const account = await accountTaskPolicy(args.directory, args.wallet, args.warn);
|
|
86602
|
+
const stored = account?.maxPerTaskUsd !== void 0 || account?.approveAboveUsd !== void 0;
|
|
86603
|
+
return {
|
|
86604
|
+
maxPerTaskUsd: account?.maxPerTaskUsd ?? DEFAULT_MAX_PER_TASK_USD,
|
|
86605
|
+
approveAboveUsd: account?.approveAboveUsd ?? agentProfileSchema.shape.approveAboveUsd.parse(void 0),
|
|
86606
|
+
autoReleaseBelowUsd: DEFAULT_AUTO_RELEASE_BELOW_USD,
|
|
86607
|
+
source: stored ? "account" : "defaults"
|
|
86608
|
+
};
|
|
86609
|
+
}
|
|
86610
|
+
async function taskMoneySnapshot(client, orderId, escrowId, options = { signInHint: "" }) {
|
|
86611
|
+
const order = await taskRequest(
|
|
86612
|
+
"task money",
|
|
86613
|
+
"getOrder",
|
|
86614
|
+
() => client.getOrder(orderId),
|
|
86615
|
+
options
|
|
86616
|
+
), workOrder = order.workOrder;
|
|
86617
|
+
if (workOrder.id !== orderId || workOrder.version !== "work-order-view-v1")
|
|
86618
|
+
throw new TaskOperationError(
|
|
86619
|
+
"invalid_response",
|
|
86620
|
+
"A private task order matching the requested ID is required."
|
|
86621
|
+
);
|
|
86622
|
+
const matches = escrowId ? workOrder.milestones.filter((m) => m.id === escrowId) : workOrder.milestones;
|
|
86623
|
+
if (matches.length !== 1)
|
|
86624
|
+
throw new TaskOperationError("invalid_response", "Select one task milestone by escrow ID.");
|
|
86625
|
+
const milestone = matches[0];
|
|
86626
|
+
if (milestone.workOrderId !== orderId)
|
|
86627
|
+
throw new TaskOperationError("invalid_response", "The milestone belongs to a different task.");
|
|
86628
|
+
let readiness;
|
|
86629
|
+
try {
|
|
86630
|
+
readiness = { ok: true, value: await client.deployment() };
|
|
86631
|
+
} catch (error61) {
|
|
86632
|
+
readiness = { ok: false, error: error61 };
|
|
86633
|
+
}
|
|
86634
|
+
return {
|
|
86635
|
+
order,
|
|
86636
|
+
escrowId: milestone.id,
|
|
86637
|
+
money: taskMoney(milestone.amountBaseUnits, readiness.ok ? parseFeeBp(readiness.value) : null),
|
|
86638
|
+
readiness
|
|
86639
|
+
};
|
|
86640
|
+
}
|
|
86641
|
+
function cachedMoneyClient(client, snapshot) {
|
|
86642
|
+
return new Proxy(client, {
|
|
86643
|
+
get(target, property) {
|
|
86644
|
+
if (property === "getOrder")
|
|
86645
|
+
return async (id2) => {
|
|
86646
|
+
if (id2 !== snapshot.order.workOrder.id)
|
|
86647
|
+
throw new Error("The cached task order does not match the requested ID.");
|
|
86648
|
+
return snapshot.order;
|
|
86649
|
+
};
|
|
86650
|
+
if (property === "deployment")
|
|
86651
|
+
return async () => {
|
|
86652
|
+
if (snapshot.readiness.ok) return snapshot.readiness.value;
|
|
86653
|
+
throw snapshot.readiness.error;
|
|
86654
|
+
};
|
|
86655
|
+
const value = Reflect.get(target, property, target);
|
|
86656
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
86657
|
+
}
|
|
86658
|
+
});
|
|
86659
|
+
}
|
|
86660
|
+
function fundingRefusalReason(error61) {
|
|
86661
|
+
if (error61 instanceof Error && error61.name === "SpendCapExceededError") {
|
|
86662
|
+
const fromCause = fundingRefusalReason(error61.cause);
|
|
86663
|
+
if (fromCause) return fromCause;
|
|
86664
|
+
return "cap" in error61 && error61.cap === "per_day" ? "policy.perDay" : void 0;
|
|
86665
|
+
}
|
|
86666
|
+
if (!(error61 instanceof SpendCapError || error61 instanceof Error && error61.name === "SpendCapError"))
|
|
86667
|
+
return void 0;
|
|
86668
|
+
const code = "code" in error61 ? error61.code : void 0;
|
|
86669
|
+
return code === "per_task_cap_exceeded" ? "policy.perTask" : code === "per_day_cap_exceeded" ? "policy.perDay" : void 0;
|
|
86670
|
+
}
|
|
86671
|
+
function taskEventLine(event) {
|
|
86672
|
+
const label2 = event.type === "task.judging" ? `deadline passed, ${event.payload.submissionCount} submissions, pick winners` : event.type === "task.claimed" ? "first submission received" : event.type === "task.checkin" ? `check-in: ${event.payload.status ?? "received"}` : event.type === "task.stalled" ? "task stalled" : event.type === "task.milestone" ? "milestone updated" : event.type === "task.released" ? "escrow released" : event.type;
|
|
86673
|
+
return `${event.sequence}: ${[label2, ...taskV2OutcomeLines(event.payload)].join(" \xB7 ")}`;
|
|
86674
|
+
}
|
|
86675
|
+
function requireTaskMethod(client, name) {
|
|
86676
|
+
const method = client[name];
|
|
86677
|
+
if (typeof method !== "function")
|
|
86678
|
+
throw new TaskOperationError(
|
|
86679
|
+
"not_supported",
|
|
86680
|
+
`Task method ${name} is not supported by this SDK adapter.`
|
|
86681
|
+
);
|
|
86682
|
+
return method.bind(client);
|
|
86683
|
+
}
|
|
86684
|
+
|
|
86685
|
+
// ../core/src/tasks/availability.ts
|
|
86686
|
+
var TASK_V2_NEW_WORK_ACTIONS = [
|
|
86687
|
+
"fund",
|
|
86688
|
+
"approve-bond",
|
|
86689
|
+
"award",
|
|
86690
|
+
"award-consent"
|
|
86691
|
+
];
|
|
86692
|
+
var NETWORK_NAMES = {
|
|
86693
|
+
8453: "Base",
|
|
86694
|
+
84532: "Base Sepolia",
|
|
86695
|
+
5042002: "Arc testnet"
|
|
86696
|
+
};
|
|
86697
|
+
function taskNetworkName(chainId) {
|
|
86698
|
+
return NETWORK_NAMES[chainId] ?? `chain ${chainId}`;
|
|
86699
|
+
}
|
|
86700
|
+
function tasksUnavailableError(chainId, untouched = "Nothing was signed and no money moved.", code = "tasks_unavailable") {
|
|
86701
|
+
return new TaskOperationError(
|
|
86702
|
+
code,
|
|
86703
|
+
`vAPI reports Tasks as unavailable on ${taskNetworkName(chainId)} right now. ${untouched} Try again later.`
|
|
86704
|
+
);
|
|
86705
|
+
}
|
|
86706
|
+
async function readTasksReadiness(client) {
|
|
86707
|
+
try {
|
|
86708
|
+
return await client.deployment();
|
|
86709
|
+
} catch {
|
|
86710
|
+
return void 0;
|
|
86711
|
+
}
|
|
86712
|
+
}
|
|
86713
|
+
function requireTasksAvailable(action, readiness, untouched) {
|
|
86714
|
+
if (!TASK_V2_NEW_WORK_ACTIONS.includes(action)) return;
|
|
86715
|
+
if (!readiness)
|
|
86716
|
+
throw new TaskOperationError(
|
|
86717
|
+
"tasks_unavailable",
|
|
86718
|
+
`vAPI's Tasks status could not be read. ${untouched ?? "Nothing was signed and no money moved."} Try again later.`
|
|
86719
|
+
);
|
|
86720
|
+
if (!readiness.configured) throw tasksUnavailableError(readiness.chainId, untouched);
|
|
86721
|
+
}
|
|
86722
|
+
|
|
86723
|
+
// ../core/src/tasks/dispute-fee.ts
|
|
86724
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
86725
|
+
function disputeFeeBaseUnits(amount4) {
|
|
86726
|
+
if (amount4 < 0n) throw new Error("Dispute amount must be nonnegative.");
|
|
86727
|
+
const fee = amount4 * 1000n / 10000n;
|
|
86728
|
+
return fee < 20000000n ? 20000000n : fee > 500000000n ? 500000000n : fee;
|
|
86729
|
+
}
|
|
86730
|
+
function taskFeeReservationKey(milestoneId2, action) {
|
|
86731
|
+
const bytes = createHash3("sha256").update(JSON.stringify([milestoneId2, action])).digest().subarray(0, 16);
|
|
86732
|
+
bytes[6] = bytes[6] & 15 | 80;
|
|
86733
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
86734
|
+
const hex5 = bytes.toString("hex");
|
|
86735
|
+
return `${hex5.slice(0, 8)}-${hex5.slice(8, 12)}-${hex5.slice(12, 16)}-${hex5.slice(16, 20)}-${hex5.slice(20)}`;
|
|
86736
|
+
}
|
|
86737
|
+
|
|
86738
|
+
// ../core/src/tasks/plan-guard.ts
|
|
86739
|
+
var TASKS_CHAIN_ABI = [
|
|
86740
|
+
{
|
|
86741
|
+
type: "function",
|
|
86742
|
+
name: "createEscrow",
|
|
86743
|
+
stateMutability: "nonpayable",
|
|
86744
|
+
inputs: [
|
|
86745
|
+
{ name: "buyer", type: "address" },
|
|
86746
|
+
{ name: "token", type: "address" },
|
|
86747
|
+
{ name: "amount", type: "uint256" },
|
|
86748
|
+
{ name: "workDuration", type: "uint64" },
|
|
86749
|
+
{ name: "acceptanceWindow", type: "uint64" },
|
|
86750
|
+
{ name: "termsHash", type: "bytes32" },
|
|
86751
|
+
{ name: "salt", type: "bytes32" }
|
|
86752
|
+
],
|
|
86753
|
+
outputs: [{ name: "escrow", type: "address" }]
|
|
86754
|
+
},
|
|
86755
|
+
{
|
|
86756
|
+
type: "function",
|
|
86757
|
+
name: "fundWithAuthorization",
|
|
86758
|
+
stateMutability: "nonpayable",
|
|
86759
|
+
inputs: [
|
|
86760
|
+
{ name: "validAfter", type: "uint256" },
|
|
86761
|
+
{ name: "validBefore", type: "uint256" },
|
|
86762
|
+
{ name: "nonce", type: "bytes32" },
|
|
86763
|
+
{ name: "signature", type: "bytes" }
|
|
86764
|
+
],
|
|
86765
|
+
outputs: []
|
|
86766
|
+
},
|
|
86767
|
+
{
|
|
86768
|
+
type: "function",
|
|
86769
|
+
name: "approve",
|
|
86770
|
+
stateMutability: "nonpayable",
|
|
86771
|
+
inputs: [
|
|
86772
|
+
{ name: "spender", type: "address" },
|
|
86773
|
+
{ name: "amount", type: "uint256" }
|
|
86774
|
+
],
|
|
86775
|
+
outputs: [{ name: "ok", type: "bool" }]
|
|
86776
|
+
},
|
|
86777
|
+
{
|
|
86778
|
+
type: "function",
|
|
86779
|
+
name: "depositFunds",
|
|
86780
|
+
stateMutability: "nonpayable",
|
|
86781
|
+
inputs: [],
|
|
86782
|
+
outputs: []
|
|
86783
|
+
},
|
|
86784
|
+
{
|
|
86785
|
+
type: "function",
|
|
86786
|
+
name: "submitDelivery",
|
|
86787
|
+
stateMutability: "nonpayable",
|
|
86788
|
+
inputs: [{ name: "manifestHash", type: "bytes32" }],
|
|
86789
|
+
outputs: []
|
|
86790
|
+
},
|
|
86791
|
+
{
|
|
86792
|
+
type: "function",
|
|
86793
|
+
name: "releaseFunds",
|
|
86794
|
+
stateMutability: "nonpayable",
|
|
86795
|
+
inputs: [],
|
|
86796
|
+
outputs: []
|
|
86797
|
+
},
|
|
86798
|
+
{ type: "function", name: "refundBuyer", stateMutability: "nonpayable", inputs: [], outputs: [] },
|
|
86799
|
+
{
|
|
86800
|
+
type: "function",
|
|
86801
|
+
name: "raiseDispute",
|
|
86802
|
+
stateMutability: "nonpayable",
|
|
86803
|
+
inputs: [{ name: "evidenceHash", type: "bytes32" }],
|
|
86804
|
+
outputs: []
|
|
86805
|
+
},
|
|
86806
|
+
{
|
|
86807
|
+
type: "function",
|
|
86808
|
+
name: "submitCounterEvidence",
|
|
86809
|
+
stateMutability: "nonpayable",
|
|
86810
|
+
inputs: [{ name: "evidenceHash", type: "bytes32" }],
|
|
86811
|
+
outputs: []
|
|
86812
|
+
},
|
|
86813
|
+
{
|
|
86814
|
+
type: "function",
|
|
86815
|
+
name: "resolveUnmatchedDispute",
|
|
86816
|
+
stateMutability: "nonpayable",
|
|
86817
|
+
inputs: [],
|
|
86818
|
+
outputs: []
|
|
86819
|
+
},
|
|
86820
|
+
{
|
|
86821
|
+
type: "function",
|
|
86822
|
+
name: "timeoutRefund",
|
|
86823
|
+
stateMutability: "nonpayable",
|
|
86824
|
+
inputs: [],
|
|
86825
|
+
outputs: []
|
|
86826
|
+
},
|
|
86827
|
+
{ type: "function", name: "finalize", stateMutability: "nonpayable", inputs: [], outputs: [] },
|
|
86828
|
+
{
|
|
86829
|
+
type: "function",
|
|
86830
|
+
name: "disputeFee",
|
|
86831
|
+
stateMutability: "view",
|
|
86832
|
+
inputs: [],
|
|
86833
|
+
outputs: [{ name: "fee", type: "uint256" }]
|
|
86834
|
+
},
|
|
86835
|
+
{
|
|
86836
|
+
type: "function",
|
|
86837
|
+
name: "allowance",
|
|
86838
|
+
stateMutability: "view",
|
|
86839
|
+
inputs: [
|
|
86840
|
+
{ name: "owner", type: "address" },
|
|
86841
|
+
{ name: "spender", type: "address" }
|
|
86842
|
+
],
|
|
86843
|
+
outputs: [{ name: "amount", type: "uint256" }]
|
|
86844
|
+
}
|
|
86845
|
+
];
|
|
86846
|
+
var TASKS_READ_ABI = parseAbi([
|
|
86847
|
+
"function paymentToken() view returns (address)",
|
|
86848
|
+
"function isEscrow(address escrow) view returns (bool)",
|
|
86849
|
+
"function name() view returns (string)",
|
|
86850
|
+
"function version() view returns (string)",
|
|
86851
|
+
"function buyer() view returns (address)",
|
|
86852
|
+
"function seller() view returns (address)",
|
|
86853
|
+
"function token() view returns (address)",
|
|
86854
|
+
"function amount() view returns (uint256)",
|
|
86855
|
+
"function termsHash() view returns (bytes32)",
|
|
86856
|
+
"function state() view returns (uint8)",
|
|
86857
|
+
"function offerDeadline() view returns (uint64)",
|
|
86858
|
+
"function workDeadline() view returns (uint64)",
|
|
86859
|
+
"function reviewDeadline() view returns (uint64)",
|
|
86860
|
+
"function disputedAt() view returns (uint64)",
|
|
86861
|
+
"function counterEvidenceDeadline() view returns (uint64)",
|
|
86862
|
+
"function resolution() view returns (uint8)",
|
|
86863
|
+
"function disputeFee() view returns (uint256)",
|
|
86864
|
+
"function predictEscrow(address seller, bytes32 salt) view returns (address)"
|
|
86865
|
+
]);
|
|
86866
|
+
function verifyPlan(operation, expectation) {
|
|
86867
|
+
const fail2 = (message) => {
|
|
86868
|
+
throw new TasksChainError(`Unsafe transaction plan: ${message}`, false);
|
|
86869
|
+
};
|
|
86870
|
+
const plan = operation.plan;
|
|
86871
|
+
if (!plan) throw new TasksChainError("Unsafe transaction plan: missing plan", false);
|
|
86872
|
+
if (plan.operationId !== operation.id || plan.step !== operation.step) fail2("operation mismatch");
|
|
86873
|
+
if (!expectation.steps.includes(plan.step)) fail2("unexpected step");
|
|
86874
|
+
if (!operation.expectedActor || getAddress(operation.expectedActor) !== getAddress(expectation.signer) || getAddress(plan.from) !== getAddress(expectation.signer))
|
|
86875
|
+
fail2("unexpected signer");
|
|
86876
|
+
if (plan.chainId !== expectation.deployment.chainId || plan.network !== expectation.deployment.network || plan.network !== `eip155:${plan.chainId}` || plan.value !== "0")
|
|
86877
|
+
fail2("unexpected network or value");
|
|
86878
|
+
if (expectation.milestone.network !== plan.network || expectation.milestone.asset.toLowerCase() !== `${plan.network}/erc20:${expectation.deployment.usdc}`.toLowerCase())
|
|
86879
|
+
fail2("milestone asset mismatch");
|
|
86880
|
+
const target = plan.step === "create-escrow" ? expectation.deployment.escrowContract : plan.step === "approve-usdc" ? expectation.deployment.usdc : expectation.milestone.escrowContract;
|
|
86881
|
+
if (getAddress(plan.to) !== getAddress(target)) fail2("unexpected target");
|
|
86882
|
+
const decoded = (() => {
|
|
86883
|
+
try {
|
|
86884
|
+
return decodeFunctionData({ abi: TASKS_CHAIN_ABI, data: plan.data });
|
|
86885
|
+
} catch {
|
|
86886
|
+
return fail2("invalid calldata");
|
|
86887
|
+
}
|
|
86888
|
+
})();
|
|
86889
|
+
const expectedName = {
|
|
86890
|
+
"create-escrow": "createEscrow",
|
|
86891
|
+
"fund-with-authorization": "fundWithAuthorization",
|
|
86892
|
+
"approve-usdc": "approve",
|
|
86893
|
+
"deposit-funds": "depositFunds",
|
|
86894
|
+
"submit-delivery": "submitDelivery",
|
|
86895
|
+
"release-funds": "releaseFunds",
|
|
86896
|
+
"refund-buyer": "refundBuyer",
|
|
86897
|
+
"raise-dispute": "raiseDispute",
|
|
86898
|
+
"submit-counter-evidence": "submitCounterEvidence",
|
|
86899
|
+
"resolve-unmatched-dispute": "resolveUnmatchedDispute",
|
|
86900
|
+
"timeout-refund": "timeoutRefund",
|
|
86901
|
+
finalize: "finalize"
|
|
86902
|
+
};
|
|
86903
|
+
if (decoded.functionName !== expectedName[plan.step]) fail2("unexpected selector");
|
|
86904
|
+
const args = [...decoded.args ?? []];
|
|
86905
|
+
const eq = (a, b) => typeof a === "string" && typeof b === "string" ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
86906
|
+
const requireArgs = (values) => {
|
|
86907
|
+
if (args.length !== values.length || args.some((v, i2) => !eq(v, values[i2])))
|
|
86908
|
+
fail2("unexpected arguments");
|
|
86909
|
+
};
|
|
86910
|
+
if (plan.step === "create-escrow") {
|
|
86911
|
+
if (!expectation.seller || getAddress(expectation.signer) !== getAddress(expectation.seller))
|
|
86912
|
+
fail2("createEscrow requires the locally bound seller");
|
|
86913
|
+
const workDuration = expectation.workDurationSeconds ?? expectation.milestone.terms.workDurationSeconds ?? getTrustedTasksDurations(expectation.deployment.chainId).workDurationSeconds;
|
|
86914
|
+
if (workDuration === void 0) fail2("missing trusted work duration");
|
|
86915
|
+
requireArgs([
|
|
86916
|
+
expectation.buyer,
|
|
86917
|
+
expectation.deployment.usdc,
|
|
86918
|
+
BigInt(expectation.milestone.amountBaseUnits),
|
|
86919
|
+
BigInt(workDuration),
|
|
86920
|
+
BigInt(
|
|
86921
|
+
expectation.reviewWindowSeconds ?? expectation.milestone.terms.acceptanceWindowSeconds
|
|
86922
|
+
),
|
|
86923
|
+
expectation.milestone.termsHash,
|
|
86924
|
+
keccak256(stringToHex(expectation.milestone.id))
|
|
86925
|
+
]);
|
|
86926
|
+
} else if (plan.step === "fund-with-authorization") {
|
|
86927
|
+
const a = expectation.authorization;
|
|
86928
|
+
if (!a)
|
|
86929
|
+
throw new TasksChainError("Unsafe transaction plan: missing local authorization", false);
|
|
86930
|
+
requireArgs([BigInt(a.validAfter), BigInt(a.validBefore), a.nonce, a.signature]);
|
|
86931
|
+
} else if (plan.step === "approve-usdc") {
|
|
86932
|
+
if (expectation.approveAmount === void 0) fail2("missing verified approval amount");
|
|
86933
|
+
requireArgs([expectation.milestone.escrowContract, expectation.approveAmount]);
|
|
86934
|
+
} else if (plan.step === "submit-delivery") {
|
|
86935
|
+
if (!expectation.manifestHash) fail2("missing manifest hash");
|
|
86936
|
+
requireArgs([expectation.manifestHash]);
|
|
86937
|
+
} else if (plan.step === "raise-dispute" || plan.step === "submit-counter-evidence") {
|
|
86938
|
+
if (!expectation.evidenceHash) fail2("missing evidence hash");
|
|
86939
|
+
requireArgs([expectation.evidenceHash]);
|
|
86940
|
+
} else requireArgs([]);
|
|
86941
|
+
}
|
|
86942
|
+
|
|
86943
|
+
// ../core/src/tasks/chain-verification.ts
|
|
86944
|
+
var TasksPartiesNotBoundError = class extends TasksValidationError {
|
|
86945
|
+
constructor() {
|
|
86946
|
+
super(
|
|
86947
|
+
"The task parties are not bound on this machine. Sign the scope with `vapi task sign` on this machine first; an explicit --counterparty only confirms an existing binding."
|
|
86948
|
+
);
|
|
86949
|
+
this.name = "TasksPartiesNotBoundError";
|
|
86950
|
+
}
|
|
86951
|
+
};
|
|
86952
|
+
async function verifyDeployment(ready, rpc, overrides) {
|
|
86953
|
+
const factory = getTrustedTasksFactory(ready.chainId, overrides);
|
|
86954
|
+
if (!factory)
|
|
86955
|
+
throw new TasksChainError(
|
|
86956
|
+
`No trusted Tasks escrow factory is configured for chain ${ready.chainId}. Set VAPI_TASKS_ESCROW_FACTORY_${ready.chainId}.`,
|
|
86957
|
+
false,
|
|
86958
|
+
{ authorizationExposed: false }
|
|
86959
|
+
);
|
|
86960
|
+
if (!isAddressEqual(factory, ready.escrowContract))
|
|
86961
|
+
throw new TasksValidationError(
|
|
86962
|
+
"The Tasks readiness factory does not match the trusted factory."
|
|
86963
|
+
);
|
|
86964
|
+
if (await rpc.getChainId() !== ready.chainId)
|
|
86965
|
+
throw new TasksValidationError("The RPC chain ID does not match the task deployment.");
|
|
86966
|
+
const token = await rpc.readContract({
|
|
86967
|
+
address: factory,
|
|
86968
|
+
abi: TASKS_READ_ABI,
|
|
86969
|
+
functionName: "paymentToken"
|
|
86984
86970
|
});
|
|
86971
|
+
if (!isAddressEqual(token, ready.usdc))
|
|
86972
|
+
throw new TasksValidationError(
|
|
86973
|
+
"The Tasks readiness token does not match the trusted factory payment token."
|
|
86974
|
+
);
|
|
86975
|
+
const [name, version5] = await Promise.all([
|
|
86976
|
+
rpc.readContract({ address: token, abi: TASKS_READ_ABI, functionName: "name" }),
|
|
86977
|
+
rpc.readContract({ address: token, abi: TASKS_READ_ABI, functionName: "version" })
|
|
86978
|
+
]);
|
|
86979
|
+
const domain2 = { name, version: version5, chainId: ready.chainId, verifyingContract: getAddress(token) };
|
|
86980
|
+
if (ready.eip3009Domain && (ready.eip3009Domain.name !== name || ready.eip3009Domain.version !== version5 || ready.eip3009Domain.chainId !== ready.chainId || !isAddressEqual(ready.eip3009Domain.verifyingContract, token)))
|
|
86981
|
+
throw new TasksValidationError(
|
|
86982
|
+
"The funding authorization domain does not match the onchain token domain."
|
|
86983
|
+
);
|
|
86985
86984
|
return {
|
|
86986
|
-
|
|
86987
|
-
|
|
86985
|
+
...ready,
|
|
86986
|
+
escrowContract: getAddress(factory),
|
|
86987
|
+
usdc: getAddress(token),
|
|
86988
|
+
eip3009Domain: domain2
|
|
86988
86989
|
};
|
|
86989
86990
|
}
|
|
86990
|
-
async function
|
|
86991
|
-
|
|
86992
|
-
const
|
|
86993
|
-
|
|
86994
|
-
|
|
86995
|
-
|
|
86996
|
-
|
|
86997
|
-
|
|
86998
|
-
|
|
86999
|
-
|
|
87000
|
-
|
|
87001
|
-
|
|
87002
|
-
|
|
87003
|
-
`More than one agent profile uses wallet ${args.wallet}; task policy is ambiguous.`
|
|
86991
|
+
async function verifyScope(client, signer, selected, ready, verb, steps, options = {}) {
|
|
86992
|
+
const { scopes } = await client.getScopes(selected.workOrderId);
|
|
86993
|
+
const matches = scopes.filter(
|
|
86994
|
+
(scope2) => scope2.state === "accepted" && scope2.milestoneId === selected.id
|
|
86995
|
+
);
|
|
86996
|
+
if (matches.length !== 1)
|
|
86997
|
+
throw new TasksValidationError("The task milestone requires one accepted signed scope.");
|
|
86998
|
+
const scope = matches[0];
|
|
86999
|
+
const payload = scope.signingPayload;
|
|
87000
|
+
const frozen = freezeScopeTerms(scope.structuredTerms, scope.brief);
|
|
87001
|
+
if (scope.workOrderId !== selected.workOrderId || payload.workOrderId !== selected.workOrderId || payload.trancheOrdinal !== selected.ordinal || scope.trancheOrdinal !== selected.ordinal || payload.scopeVersion !== scope.version || frozen.termsHash !== scope.termsHash || frozen.termsHash !== payload.termsHash || frozen.termsHash !== selected.termsHash)
|
|
87002
|
+
throw new TasksValidationError(
|
|
87003
|
+
"The accepted task scope does not match its locally verified terms hash and milestone."
|
|
87004
87004
|
);
|
|
87005
|
-
|
|
87006
|
-
|
|
87007
|
-
|
|
87008
|
-
|
|
87009
|
-
|
|
87010
|
-
|
|
87011
|
-
|
|
87012
|
-
|
|
87013
|
-
|
|
87014
|
-
|
|
87015
|
-
|
|
87005
|
+
if (!scope.counterpartyAddress || !scope.counterpartySignature || isAddressEqual(scope.proposerAddress, scope.counterpartyAddress) || !(isAddressEqual(signer, scope.proposerAddress) || isAddressEqual(signer, scope.counterpartyAddress)))
|
|
87006
|
+
throw new TasksValidationError(
|
|
87007
|
+
"The local signer is not one of the two accepted scope parties."
|
|
87008
|
+
);
|
|
87009
|
+
const message = canonicalJson(payload);
|
|
87010
|
+
const signatures = await Promise.all([
|
|
87011
|
+
verifyMessage({
|
|
87012
|
+
address: scope.proposerAddress,
|
|
87013
|
+
message,
|
|
87014
|
+
signature: scope.proposerSignature
|
|
87015
|
+
}),
|
|
87016
|
+
verifyMessage({
|
|
87017
|
+
address: scope.counterpartyAddress,
|
|
87018
|
+
message,
|
|
87019
|
+
signature: scope.counterpartySignature
|
|
87020
|
+
})
|
|
87021
|
+
]);
|
|
87022
|
+
if (signatures.some((valid) => !valid))
|
|
87023
|
+
throw new TasksValidationError("Both accepted task scope signatures must verify.");
|
|
87024
|
+
const terms = frozen.structured;
|
|
87025
|
+
if (terms.budget.network !== ready.network || terms.budget.asset.toLowerCase() !== `${ready.network}/erc20:${ready.usdc}`.toLowerCase() || !isAddressEqual(terms.escrow.contract, ready.escrowContract) || selected.network !== terms.budget.network || selected.asset.toLowerCase() !== terms.budget.asset.toLowerCase() || selected.amountBaseUnits !== terms.budget.amountBaseUnits)
|
|
87026
|
+
throw new TasksValidationError(
|
|
87027
|
+
"The signed task scope asset, factory or amount does not match the deployment and milestone."
|
|
87028
|
+
);
|
|
87029
|
+
const identity = {
|
|
87030
|
+
orderId: selected.workOrderId,
|
|
87031
|
+
trancheOrdinal: selected.ordinal,
|
|
87032
|
+
scopeVersion: scope.version,
|
|
87033
|
+
termsHash: frozen.termsHash,
|
|
87034
|
+
self: getAddress(signer)
|
|
87016
87035
|
};
|
|
87017
|
-
|
|
87018
|
-
|
|
87019
|
-
|
|
87020
|
-
|
|
87021
|
-
|
|
87022
|
-
|
|
87023
|
-
|
|
87024
|
-
|
|
87025
|
-
|
|
87026
|
-
throw new
|
|
87027
|
-
"
|
|
87028
|
-
|
|
87036
|
+
const binding = await options.bindings?.get(identity);
|
|
87037
|
+
if (!binding) throw new TasksPartiesNotBoundError();
|
|
87038
|
+
if (options.counterparty && !isAddressEqual(binding.counterparty, options.counterparty))
|
|
87039
|
+
throw new TasksValidationError(
|
|
87040
|
+
"The confirmed counterparty differs from the locally bound parties."
|
|
87041
|
+
);
|
|
87042
|
+
if (!isAddressEqual(binding.self, signer) || binding.orderId !== identity.orderId || binding.trancheOrdinal !== identity.trancheOrdinal || binding.scopeVersion !== identity.scopeVersion || binding.termsHash.toLowerCase() !== identity.termsHash.toLowerCase() || ![scope.proposerAddress, scope.counterpartyAddress].every(
|
|
87043
|
+
(address10) => isAddressEqual(address10, binding.self) || isAddressEqual(address10, binding.counterparty)
|
|
87044
|
+
))
|
|
87045
|
+
throw new TasksValidationError(
|
|
87046
|
+
"The accepted scope parties do not match the locally bound parties."
|
|
87047
|
+
);
|
|
87048
|
+
const buyer = getAddress(binding.role === "client" ? binding.self : binding.counterparty);
|
|
87049
|
+
const seller = getAddress(binding.role === "provider" ? binding.self : binding.counterparty);
|
|
87050
|
+
if (verb === "createEscrow" && !isAddressEqual(signer, seller))
|
|
87051
|
+
throw new TasksValidationError("Task createEscrow requires the locally bound seller's wallet.");
|
|
87052
|
+
const workDurationSeconds = terms.workDurationSeconds ?? getTrustedTasksDurations(ready.chainId, options.trustedDurations).workDurationSeconds;
|
|
87053
|
+
if (workDurationSeconds === void 0)
|
|
87054
|
+
throw new TasksValidationError(
|
|
87055
|
+
"The signed task scope has no work duration and no trusted default is configured."
|
|
87029
87056
|
);
|
|
87030
|
-
const matches = escrowId ? workOrder.milestones.filter((m) => m.id === escrowId) : workOrder.milestones;
|
|
87031
|
-
if (matches.length !== 1)
|
|
87032
|
-
throw new TaskOperationError("invalid_response", "Select one task milestone by escrow ID.");
|
|
87033
|
-
const milestone = matches[0];
|
|
87034
|
-
if (milestone.workOrderId !== orderId)
|
|
87035
|
-
throw new TaskOperationError("invalid_response", "The milestone belongs to a different task.");
|
|
87036
|
-
let readiness;
|
|
87037
|
-
try {
|
|
87038
|
-
readiness = { ok: true, value: await client.deployment() };
|
|
87039
|
-
} catch (error61) {
|
|
87040
|
-
readiness = { ok: false, error: error61 };
|
|
87041
|
-
}
|
|
87042
87057
|
return {
|
|
87043
|
-
|
|
87044
|
-
|
|
87045
|
-
|
|
87046
|
-
|
|
87058
|
+
signer,
|
|
87059
|
+
buyer,
|
|
87060
|
+
seller,
|
|
87061
|
+
parties: [buyer, seller],
|
|
87062
|
+
workDurationSeconds,
|
|
87063
|
+
...verb === "fund" ? { approveAmount: BigInt(terms.budget.amountBaseUnits) } : {},
|
|
87064
|
+
reviewWindowSeconds: terms.acceptanceWindowSeconds,
|
|
87065
|
+
nowSeconds: BigInt(Math.floor((options.now ?? (() => /* @__PURE__ */ new Date()))().getTime() / 1e3)),
|
|
87066
|
+
verb,
|
|
87067
|
+
deployment: ready,
|
|
87068
|
+
milestone: {
|
|
87069
|
+
...selected,
|
|
87070
|
+
terms,
|
|
87071
|
+
termsHash: frozen.termsHash,
|
|
87072
|
+
amountBaseUnits: terms.budget.amountBaseUnits
|
|
87073
|
+
},
|
|
87074
|
+
steps
|
|
87047
87075
|
};
|
|
87048
87076
|
}
|
|
87049
|
-
function
|
|
87050
|
-
|
|
87051
|
-
|
|
87052
|
-
|
|
87053
|
-
|
|
87054
|
-
|
|
87055
|
-
|
|
87056
|
-
|
|
87057
|
-
};
|
|
87058
|
-
if (property === "deployment")
|
|
87059
|
-
return async () => {
|
|
87060
|
-
if (snapshot.readiness.ok) return snapshot.readiness.value;
|
|
87061
|
-
throw snapshot.readiness.error;
|
|
87062
|
-
};
|
|
87063
|
-
const value = Reflect.get(target, property, target);
|
|
87064
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
87065
|
-
}
|
|
87077
|
+
async function verifyClone(rpc, expected, checkState) {
|
|
87078
|
+
if (expected.verb === "createEscrow") return;
|
|
87079
|
+
const clone2 = expected.milestone.escrowContract;
|
|
87080
|
+
const registered = await rpc.readContract({
|
|
87081
|
+
address: expected.deployment.escrowContract,
|
|
87082
|
+
abi: TASKS_READ_ABI,
|
|
87083
|
+
functionName: "isEscrow",
|
|
87084
|
+
args: [clone2]
|
|
87066
87085
|
});
|
|
87067
|
-
|
|
87068
|
-
|
|
87069
|
-
|
|
87070
|
-
|
|
87071
|
-
|
|
87072
|
-
|
|
87086
|
+
if (!registered)
|
|
87087
|
+
throw new TasksValidationError(
|
|
87088
|
+
"The task escrow clone is not registered by the trusted factory."
|
|
87089
|
+
);
|
|
87090
|
+
const predicted = await rpc.readContract({
|
|
87091
|
+
address: expected.deployment.escrowContract,
|
|
87092
|
+
abi: TASKS_READ_ABI,
|
|
87093
|
+
functionName: "predictEscrow",
|
|
87094
|
+
args: [expected.seller, keccak256(stringToHex(expected.milestone.id))]
|
|
87095
|
+
});
|
|
87096
|
+
if (!isAddressEqual(predicted, clone2))
|
|
87097
|
+
throw new TasksValidationError(
|
|
87098
|
+
"The escrow clone does not match the signed milestone salt and bound seller."
|
|
87099
|
+
);
|
|
87100
|
+
const read = (functionName) => rpc.readContract({ address: clone2, abi: TASKS_READ_ABI, functionName });
|
|
87101
|
+
const [
|
|
87102
|
+
buyer,
|
|
87103
|
+
seller,
|
|
87104
|
+
token,
|
|
87105
|
+
amount4,
|
|
87106
|
+
termsHash,
|
|
87107
|
+
state,
|
|
87108
|
+
resolution,
|
|
87109
|
+
offerDeadline,
|
|
87110
|
+
workDeadline,
|
|
87111
|
+
reviewDeadline,
|
|
87112
|
+
disputedAt,
|
|
87113
|
+
counterEvidenceDeadline,
|
|
87114
|
+
slot0,
|
|
87115
|
+
slot6,
|
|
87116
|
+
slot7
|
|
87117
|
+
] = await Promise.all([
|
|
87118
|
+
read("buyer"),
|
|
87119
|
+
read("seller"),
|
|
87120
|
+
read("token"),
|
|
87121
|
+
read("amount"),
|
|
87122
|
+
read("termsHash"),
|
|
87123
|
+
read("state"),
|
|
87124
|
+
read("resolution"),
|
|
87125
|
+
read("offerDeadline"),
|
|
87126
|
+
read("workDeadline"),
|
|
87127
|
+
read("reviewDeadline"),
|
|
87128
|
+
read("disputedAt"),
|
|
87129
|
+
read("counterEvidenceDeadline"),
|
|
87130
|
+
rpc.getStorageAt({ address: clone2, slot: "0x0" }),
|
|
87131
|
+
rpc.getStorageAt({ address: clone2, slot: "0x6" }),
|
|
87132
|
+
rpc.getStorageAt({ address: clone2, slot: "0x7" })
|
|
87133
|
+
]);
|
|
87134
|
+
if (isAddressEqual(buyer, seller) || !isAddressEqual(buyer, expected.buyer) || !isAddressEqual(seller, expected.seller) || !isAddressEqual(token, expected.deployment.usdc) || amount4 !== BigInt(expected.milestone.amountBaseUnits) || termsHash.toLowerCase() !== expected.milestone.termsHash.toLowerCase())
|
|
87135
|
+
throw new TasksValidationError(
|
|
87136
|
+
"The onchain escrow parties, token, amount or terms hash do not match the signed scope."
|
|
87137
|
+
);
|
|
87138
|
+
const s0 = storageWord(slot0);
|
|
87139
|
+
const s6 = storageWord(slot6);
|
|
87140
|
+
const s7 = storageWord(slot7);
|
|
87141
|
+
if (field(s0, 0, 1) !== BigInt(state) || field(s0, 1, 1) !== BigInt(resolution) || !isAddressEqual(storageAddress(s0, 2), buyer) || field(s6, 0, 8) !== offerDeadline || field(s6, 8, 8) !== workDeadline || field(s6, 16, 8) !== reviewDeadline || field(s6, 24, 8) !== disputedAt || field(s7, 0, 8) !== counterEvidenceDeadline)
|
|
87142
|
+
throw new TasksValidationError("unsupported escrow layout");
|
|
87143
|
+
if (field(s7, 8, 8) !== BigInt(expected.workDurationSeconds) || field(s7, 16, 8) !== BigInt(expected.reviewWindowSeconds))
|
|
87144
|
+
throw new TasksValidationError(
|
|
87145
|
+
"The onchain escrow durations do not match the signed terms and trusted defaults."
|
|
87146
|
+
);
|
|
87147
|
+
const actor = expected.verb === "fund" || expected.verb === "release" ? buyer : expected.verb === "deliver" || expected.verb === "refund" ? seller : expected.signer;
|
|
87148
|
+
if (!isAddressEqual(actor, expected.signer))
|
|
87149
|
+
throw new TasksValidationError(
|
|
87150
|
+
`Task ${expected.verb} requires the onchain escrow party's local wallet.`
|
|
87151
|
+
);
|
|
87152
|
+
const states = {
|
|
87153
|
+
fund: [1],
|
|
87154
|
+
deliver: [2],
|
|
87155
|
+
release: [3],
|
|
87156
|
+
refund: [2, 3],
|
|
87157
|
+
dispute: [2, 3],
|
|
87158
|
+
"counter-evidence": [4],
|
|
87159
|
+
"resolve-unmatched": [4]
|
|
87160
|
+
};
|
|
87161
|
+
if (checkState && !states[expected.verb]?.includes(state))
|
|
87162
|
+
throw new TasksValidationError(
|
|
87163
|
+
`The onchain escrow state is not eligible for task ${expected.verb}.`
|
|
87164
|
+
);
|
|
87165
|
+
if (["dispute", "counter-evidence"].includes(expected.verb)) {
|
|
87166
|
+
const fee = disputeFeeBaseUnits(amount4);
|
|
87167
|
+
if (await read("disputeFee") !== fee)
|
|
87168
|
+
throw new TasksValidationError(
|
|
87169
|
+
"The onchain dispute fee does not match the verified amount fee rule."
|
|
87170
|
+
);
|
|
87171
|
+
expected.disputeFee = fee;
|
|
87172
|
+
expected.approveAmount = fee;
|
|
87073
87173
|
}
|
|
87074
|
-
if (
|
|
87075
|
-
|
|
87076
|
-
|
|
87077
|
-
|
|
87174
|
+
if (checkState && ["counter-evidence", "resolve-unmatched"].includes(expected.verb)) {
|
|
87175
|
+
const slot8 = storageWord(await rpc.getStorageAt({ address: clone2, slot: "0x8" }));
|
|
87176
|
+
const opener = storageAddress(slot8, 0);
|
|
87177
|
+
const submitted = field(slot8, 20, 1);
|
|
87178
|
+
if (!isAddressEqual(opener, buyer) && !isAddressEqual(opener, seller) || submitted > 1n || field(slot8, 21, 11) !== 0n)
|
|
87179
|
+
throw new TasksValidationError("unsupported escrow layout");
|
|
87180
|
+
const now = expected.nowSeconds;
|
|
87181
|
+
if (now === void 0)
|
|
87182
|
+
throw new TasksValidationError("A trusted clock is required for dispute eligibility.");
|
|
87183
|
+
if (submitted === 1n)
|
|
87184
|
+
throw new TasksValidationError(
|
|
87185
|
+
"Counter-evidence has already been submitted for this dispute."
|
|
87186
|
+
);
|
|
87187
|
+
if (expected.verb === "counter-evidence") {
|
|
87188
|
+
if (isAddressEqual(opener, expected.signer))
|
|
87189
|
+
throw new TasksValidationError("Only the non-opener party can submit counter-evidence.");
|
|
87190
|
+
if (now >= counterEvidenceDeadline)
|
|
87191
|
+
throw new TasksValidationError("The counter-evidence deadline has passed.");
|
|
87192
|
+
} else if (now <= counterEvidenceDeadline)
|
|
87193
|
+
throw new TasksValidationError(
|
|
87194
|
+
"The counter-evidence deadline has not passed; unmatched resolution is unavailable."
|
|
87195
|
+
);
|
|
87196
|
+
}
|
|
87197
|
+
expected.offerDeadline = offerDeadline;
|
|
87078
87198
|
}
|
|
87079
|
-
function
|
|
87080
|
-
|
|
87081
|
-
|
|
87199
|
+
function storageWord(value) {
|
|
87200
|
+
if (!value || !/^0x[0-9a-fA-F]{64}$/.test(value))
|
|
87201
|
+
throw new TasksValidationError("unsupported escrow layout");
|
|
87202
|
+
return BigInt(value);
|
|
87082
87203
|
}
|
|
87083
|
-
function
|
|
87084
|
-
|
|
87085
|
-
|
|
87086
|
-
|
|
87087
|
-
|
|
87088
|
-
`Task method ${name} is not supported by this SDK adapter.`
|
|
87089
|
-
);
|
|
87090
|
-
return method.bind(client);
|
|
87204
|
+
function field(word, offset, bytes) {
|
|
87205
|
+
return word >> BigInt(offset * 8) & (1n << BigInt(bytes * 8)) - 1n;
|
|
87206
|
+
}
|
|
87207
|
+
function storageAddress(word, offset) {
|
|
87208
|
+
return getAddress(`0x${field(word, offset, 20).toString(16).padStart(40, "0")}`);
|
|
87091
87209
|
}
|
|
87092
87210
|
|
|
87093
87211
|
// ../core/src/tasks/v2-trust.ts
|
|
@@ -87180,12 +87298,65 @@ function getTrustedTasksV2Deployment(chainId, options = {}) {
|
|
|
87180
87298
|
return normalized2;
|
|
87181
87299
|
}
|
|
87182
87300
|
|
|
87301
|
+
// ../core/src/tasks/v2-limits.ts
|
|
87302
|
+
var feeBpSchema = external_exports.union([external_exports.number(), external_exports.bigint()]).transform(Number).pipe(external_exports.number().int().min(0).max(2e3));
|
|
87303
|
+
var capSchema = external_exports.bigint().positive();
|
|
87304
|
+
async function readTaskV2Limits(input2) {
|
|
87305
|
+
const read = async () => {
|
|
87306
|
+
const pin = getTrustedTasksV2Deployment(input2.chainId, {
|
|
87307
|
+
...input2.trustedV2Deployments ? { overrides: input2.trustedV2Deployments } : {},
|
|
87308
|
+
...input2.env ? { env: input2.env } : {},
|
|
87309
|
+
// Display and pre-check only; the signing path prints the override notice.
|
|
87310
|
+
notice: input2.onV2UntrustedOverride ?? (() => {
|
|
87311
|
+
})
|
|
87312
|
+
});
|
|
87313
|
+
const rpc = input2.rpcFor(input2.chainId);
|
|
87314
|
+
if (await rpc.getChainId() !== input2.chainId) throw new Error("RPC chain mismatch");
|
|
87315
|
+
const pool = input2.shape === "pool";
|
|
87316
|
+
const address10 = pool ? pin.bountyPoolFactoryV1 : pin.escrowFactoryV2;
|
|
87317
|
+
const abi2 = pool ? bountyPoolFactoryV1Abi : escrowFactoryV2Abi;
|
|
87318
|
+
const [feeBp, cap] = await Promise.all([
|
|
87319
|
+
rpc.readContract({ address: address10, abi: abi2, functionName: "feeBp" }),
|
|
87320
|
+
rpc.readContract({
|
|
87321
|
+
address: address10,
|
|
87322
|
+
abi: abi2,
|
|
87323
|
+
functionName: pool ? "maxPoolBudget" : "maxEscrowAmount"
|
|
87324
|
+
})
|
|
87325
|
+
]);
|
|
87326
|
+
return {
|
|
87327
|
+
chainId: input2.chainId,
|
|
87328
|
+
shape: input2.shape,
|
|
87329
|
+
feeBp: feeBpSchema.parse(feeBp),
|
|
87330
|
+
maxBaseUnits: capSchema.parse(cap)
|
|
87331
|
+
};
|
|
87332
|
+
};
|
|
87333
|
+
let timer;
|
|
87334
|
+
try {
|
|
87335
|
+
return await Promise.race([
|
|
87336
|
+
read(),
|
|
87337
|
+
new Promise((resolve3) => {
|
|
87338
|
+
timer = setTimeout(() => resolve3(void 0), input2.timeoutMs ?? 5e3);
|
|
87339
|
+
})
|
|
87340
|
+
]);
|
|
87341
|
+
} catch {
|
|
87342
|
+
return void 0;
|
|
87343
|
+
} finally {
|
|
87344
|
+
if (timer) clearTimeout(timer);
|
|
87345
|
+
}
|
|
87346
|
+
}
|
|
87347
|
+
function assertWithinTaskV2Limit(totalBaseUnits, limits, untouched = "Nothing was signed and no money moved.") {
|
|
87348
|
+
if (totalBaseUnits <= limits.maxBaseUnits) return;
|
|
87349
|
+
throw new TaskInputError(
|
|
87350
|
+
`The total of $${formatBaseUnitsUsd(totalBaseUnits)} USDC is above the live limit of $${formatBaseUnitsUsd(limits.maxBaseUnits)} USDC per ${limits.shape} on ${taskNetworkName(limits.chainId)}. ${untouched}`
|
|
87351
|
+
);
|
|
87352
|
+
}
|
|
87353
|
+
|
|
87183
87354
|
// ../core/src/tasks/v2-plan-guard.ts
|
|
87184
87355
|
var address5 = external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/u).transform((v) => getAddress(v));
|
|
87185
87356
|
var hash5 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/u).transform((v) => v.toLowerCase());
|
|
87186
87357
|
var uint2 = external_exports.union([external_exports.bigint(), external_exports.number().int().nonnegative(), external_exports.string().regex(/^\d+$/u)]).transform(BigInt);
|
|
87187
87358
|
var small = (max) => external_exports.union([external_exports.number(), external_exports.bigint()]).transform(Number).pipe(external_exports.number().int().min(0).max(max));
|
|
87188
|
-
var
|
|
87359
|
+
var feeBpSchema2 = small(2e3);
|
|
87189
87360
|
var escrowTermsSchema = external_exports.object({
|
|
87190
87361
|
shape: small(1),
|
|
87191
87362
|
poster: address5,
|
|
@@ -87197,7 +87368,7 @@ var escrowTermsSchema = external_exports.object({
|
|
|
87197
87368
|
bountyDeadline: uint2,
|
|
87198
87369
|
objectionWindow: uint2,
|
|
87199
87370
|
workerBondBp: small(2e3),
|
|
87200
|
-
feeBp:
|
|
87371
|
+
feeBp: feeBpSchema2,
|
|
87201
87372
|
winners: small(255),
|
|
87202
87373
|
rewardPerWinner: uint2
|
|
87203
87374
|
});
|
|
@@ -87461,7 +87632,7 @@ function verifyActor(action, signer, poster, worker, verifier) {
|
|
|
87461
87632
|
);
|
|
87462
87633
|
}
|
|
87463
87634
|
async function creationPolicy(rpc, pin, pool) {
|
|
87464
|
-
const feeBp =
|
|
87635
|
+
const feeBp = feeBpSchema2.parse(
|
|
87465
87636
|
await v2Read(
|
|
87466
87637
|
rpc,
|
|
87467
87638
|
pool ? pin.bountyPoolFactoryV1 : pin.escrowFactoryV2,
|
|
@@ -87480,10 +87651,13 @@ async function verifyFundingDeadlines(rpc, contract, deadlines, timestamp) {
|
|
|
87480
87651
|
`Every milestone deadline must leave at least MIN_WORK_TIME (${minimum} seconds) from the trusted chain clock before creation or funding so the task can be awarded.`
|
|
87481
87652
|
);
|
|
87482
87653
|
}
|
|
87483
|
-
async function verifyV2Target(options, current, view, action, knownTarget) {
|
|
87654
|
+
async function verifyV2Target(options, current, view, action, knownTarget, fundingMined = false) {
|
|
87484
87655
|
const operation = taskV2OperationResponseSchema.safeParse(current);
|
|
87485
87656
|
const intent = taskV2IntentSchema.safeParse(current);
|
|
87486
|
-
const
|
|
87657
|
+
const plan = operation.success ? operation.data.operation.plan : null;
|
|
87658
|
+
if (operation.success && !plan)
|
|
87659
|
+
return v2GuardFailure("The hosted operation carries no plan to verify.");
|
|
87660
|
+
const chainId = plan ? plan.chainId : intent.success ? intent.data.typedData.domain.chainId : external_exports.object({ chainId: external_exports.number().int().positive() }).parse(current).chainId;
|
|
87487
87661
|
const binding = await options.pending.v2Target?.(view.workOrder.id);
|
|
87488
87662
|
if (action.action === "bump-consent-nonce" && !binding)
|
|
87489
87663
|
return v2GuardFailure("Revocation requires a locally accepted consent target binding.");
|
|
@@ -87515,11 +87689,8 @@ async function verifyV2Target(options, current, view, action, knownTarget) {
|
|
|
87515
87689
|
let candidate = knownTarget ?? external_exports.object({ escrow: address5 }).safeParse(order.v2State).data?.escrow ?? (intent.success ? external_exports.object({ escrow: address5 }).safeParse(intent.data).data?.escrow : void 0);
|
|
87516
87690
|
let creationArgs;
|
|
87517
87691
|
let fresh;
|
|
87518
|
-
if (action.action === "fund" &&
|
|
87519
|
-
const decoded = decodeFunctionData({
|
|
87520
|
-
abi: factoryAbi,
|
|
87521
|
-
data: operation.data.operation.plan.data
|
|
87522
|
-
});
|
|
87692
|
+
if (action.action === "fund" && plan && same(plan.to, factory)) {
|
|
87693
|
+
const decoded = decodeFunctionData({ abi: factoryAbi, data: plan.data });
|
|
87523
87694
|
const names = pool ? ["createPool"] : ["createEscrow", "createAndFundWithAuthorization"];
|
|
87524
87695
|
if (!names.includes(decoded.functionName))
|
|
87525
87696
|
return v2GuardFailure("Unexpected V2 factory funding selector.");
|
|
@@ -87529,7 +87700,7 @@ async function verifyV2Target(options, current, view, action, knownTarget) {
|
|
|
87529
87700
|
verifyAcceptedCreation(options, view, pin, creationArgs, pool, chainId, fresh);
|
|
87530
87701
|
candidate = await predict(creationArgs);
|
|
87531
87702
|
}
|
|
87532
|
-
if (action.action === "fund" &&
|
|
87703
|
+
if (action.action === "fund" && plan?.step === "v2-approve-usdc" && (!candidate || !await isRegistered(candidate))) {
|
|
87533
87704
|
fresh = await creationPolicy(rpc, pin, pool);
|
|
87534
87705
|
creationArgs = acceptedCreationArgs(options, view, pin, chainId, fresh);
|
|
87535
87706
|
verifyAcceptedCreation(options, view, pin, creationArgs, pool, chainId, fresh);
|
|
@@ -87545,7 +87716,7 @@ async function verifyV2Target(options, current, view, action, knownTarget) {
|
|
|
87545
87716
|
"The V2 target cannot be independently verified from this response. A registered target or verifiable funding creation terms are required."
|
|
87546
87717
|
);
|
|
87547
87718
|
if (!await isRegistered(candidate)) {
|
|
87548
|
-
if (action.action !== "fund" || !
|
|
87719
|
+
if (action.action !== "fund" || !plan || !creationArgs || !fresh)
|
|
87549
87720
|
return v2GuardFailure("The V2 target is not registered by the locally pinned factory.");
|
|
87550
87721
|
const expectedCreation = acceptedCreationArgs(options, view, pin, chainId, fresh);
|
|
87551
87722
|
if (canon(creationArgs) !== canon(expectedCreation))
|
|
@@ -87597,7 +87768,7 @@ async function verifyV2Target(options, current, view, action, knownTarget) {
|
|
|
87597
87768
|
poster = address5.parse(await read("poster"));
|
|
87598
87769
|
verifier = address5.parse(await read("verifier"));
|
|
87599
87770
|
total = uint2.parse(await read("budget"));
|
|
87600
|
-
feeBp =
|
|
87771
|
+
feeBp = feeBpSchema2.parse(await read("feeBp"));
|
|
87601
87772
|
termsHash = hash5.parse(await read("termsHash"));
|
|
87602
87773
|
creationArgs = [
|
|
87603
87774
|
poster,
|
|
@@ -87661,7 +87832,7 @@ async function verifyV2Target(options, current, view, action, knownTarget) {
|
|
|
87661
87832
|
"The V2 target differs from the pinned factory's prediction for the requested order."
|
|
87662
87833
|
);
|
|
87663
87834
|
verifyBinding(candidate, termsHash);
|
|
87664
|
-
if (action.action === "fund" && !pool && !bounty)
|
|
87835
|
+
if (action.action === "fund" && !pool && !bounty && !fundingMined)
|
|
87665
87836
|
await verifyFundingDeadlines(
|
|
87666
87837
|
rpc,
|
|
87667
87838
|
candidate,
|
|
@@ -87765,6 +87936,7 @@ function acceptedV2WorkerBond(target, view) {
|
|
|
87765
87936
|
}
|
|
87766
87937
|
async function verifyV2Plan(target, op, action, pays, fundingAuthorization) {
|
|
87767
87938
|
const plan = op.plan;
|
|
87939
|
+
if (!plan) return v2GuardFailure("The hosted operation carries no plan to verify.");
|
|
87768
87940
|
if (plan.value !== "0" || plan.chainId !== target.chainId)
|
|
87769
87941
|
return v2GuardFailure("V2 plan value or chain mismatch.");
|
|
87770
87942
|
const authorizationArgs = fundingAuthorization ? [
|
|
@@ -88031,7 +88203,8 @@ function isTaskV2SecretAction(action) {
|
|
|
88031
88203
|
return action.action === "commit-vote" || action.action === "reveal-vote";
|
|
88032
88204
|
}
|
|
88033
88205
|
function publicTaskV2Operation(op, secret = false) {
|
|
88034
|
-
const
|
|
88206
|
+
const plan = op.plan;
|
|
88207
|
+
const reveal = secret || op.step === "v2-reveal-vote" || plan?.step === "v2-reveal-vote" || plan?.data.toLowerCase().startsWith(REVEAL_SELECTOR) === true;
|
|
88035
88208
|
return {
|
|
88036
88209
|
id: op.id,
|
|
88037
88210
|
kind: op.kind,
|
|
@@ -88039,16 +88212,17 @@ function publicTaskV2Operation(op, secret = false) {
|
|
|
88039
88212
|
step: op.step,
|
|
88040
88213
|
expectedActor: op.expectedActor,
|
|
88041
88214
|
transactionHash: op.transactionHash,
|
|
88042
|
-
|
|
88043
|
-
|
|
88044
|
-
|
|
88045
|
-
|
|
88046
|
-
|
|
88047
|
-
|
|
88048
|
-
|
|
88049
|
-
|
|
88050
|
-
|
|
88051
|
-
|
|
88215
|
+
// Null once the transaction is submitted or confirmed: the API no longer returns the plan.
|
|
88216
|
+
plan: plan && {
|
|
88217
|
+
version: plan.version,
|
|
88218
|
+
operationId: plan.operationId,
|
|
88219
|
+
step: plan.step,
|
|
88220
|
+
chainId: plan.chainId,
|
|
88221
|
+
network: plan.network,
|
|
88222
|
+
from: plan.from,
|
|
88223
|
+
to: plan.to,
|
|
88224
|
+
data: reveal ? TASK_V2_REDACTED_CALLDATA : plan.data,
|
|
88225
|
+
value: plan.value
|
|
88052
88226
|
}
|
|
88053
88227
|
};
|
|
88054
88228
|
}
|
|
@@ -88069,7 +88243,7 @@ var shownOperationSchema = external_exports.object({
|
|
|
88069
88243
|
to: external_exports.string(),
|
|
88070
88244
|
data: external_exports.string(),
|
|
88071
88245
|
value: external_exports.literal("0")
|
|
88072
|
-
})
|
|
88246
|
+
}).nullable()
|
|
88073
88247
|
});
|
|
88074
88248
|
function publicTaskV2OperationOf(value, secret = false) {
|
|
88075
88249
|
const parsed = shownOperationSchema.safeParse(value);
|
|
@@ -88289,6 +88463,9 @@ function bufferedV2Gas(estimate) {
|
|
|
88289
88463
|
var fail = (message) => {
|
|
88290
88464
|
throw new TaskOperationError("invalid_response", message);
|
|
88291
88465
|
};
|
|
88466
|
+
var balanceAbi = parseAbi(["function balanceOf(address account) view returns (uint256)"]);
|
|
88467
|
+
var PAID_NOW_ACTIONS = ["fund", "raise-dispute", "counter-evidence"];
|
|
88468
|
+
var RESERVING_ACTIONS = [...PAID_NOW_ACTIONS, "approve-bond"];
|
|
88292
88469
|
async function taskUsesV2(context, id2) {
|
|
88293
88470
|
if (!context.client.prepareV2) return false;
|
|
88294
88471
|
const { workOrder } = await context.client.getOrder(id2);
|
|
@@ -88316,6 +88493,7 @@ async function executeTaskV2(context, input2) {
|
|
|
88316
88493
|
}
|
|
88317
88494
|
const saved = journal.preparedV2;
|
|
88318
88495
|
if (saved) return saved;
|
|
88496
|
+
requireTasksAvailable(action.action, await readTasksReadiness(context.client));
|
|
88319
88497
|
const result = await (input2.consent ? context.client.signV2(input2.id, input2.consent, journal) : context.client.prepareV2(input2.id, input2.write, journal));
|
|
88320
88498
|
await context.pending?.bindPreparedV2?.(input2.id, verb, result);
|
|
88321
88499
|
return result;
|
|
@@ -88349,17 +88527,76 @@ function createTaskV2Executor(options) {
|
|
|
88349
88527
|
journal = { idempotencyKey: input2.preparationKey ?? randomUUID4(), inputs: action };
|
|
88350
88528
|
await pending.putPreparation(input2.id, verb, journal);
|
|
88351
88529
|
}
|
|
88352
|
-
let current = taskV2PreparedSchema.parse(
|
|
88353
|
-
input2.prepared ?? journal.preparedV2 ?? await (input2.consent ? sign2(input2.id, input2.consent, journal) : prepare(input2.id, input2.write, journal))
|
|
88354
|
-
);
|
|
88355
88530
|
if (!pending.bindPreparedV2) fail("Durable V2 preparation storage is unavailable.");
|
|
88356
|
-
|
|
88531
|
+
const supplied = input2.prepared ?? journal.preparedV2;
|
|
88532
|
+
let current = supplied === void 0 ? void 0 : taskV2PreparedSchema.parse(supplied);
|
|
88533
|
+
if (current) await pending.bindPreparedV2(input2.id, verb, current);
|
|
88534
|
+
const finalStep = action.action === "approve-bond" ? "v2-approve-usdc" : `v2-${action.action}`;
|
|
88535
|
+
const allowedSteps = action.action === "fund" ? ["v2-create-escrow", "v2-create-pool", "v2-approve-usdc", "v2-fund"] : action.action === "raise-dispute" || action.action === "counter-evidence" ? ["v2-approve-usdc", finalStep] : [finalStep];
|
|
88536
|
+
const reservedForTask = (excludeReservationId) => taskReservedAtomic({
|
|
88537
|
+
ledgerPath: input2.ledgerPath,
|
|
88538
|
+
wallet: input2.wallet,
|
|
88539
|
+
taskKey: input2.id,
|
|
88540
|
+
now: now(),
|
|
88541
|
+
...excludeReservationId === void 0 ? {} : { excludeReservationId }
|
|
88542
|
+
});
|
|
88543
|
+
const savedOperation = journal.operationId;
|
|
88544
|
+
const savedTransaction = savedOperation !== void 0 && (await Promise.all(allowedSteps.map((step2) => pending.get(savedOperation, step2)))).some(
|
|
88545
|
+
(entry) => entry !== void 0
|
|
88546
|
+
);
|
|
88547
|
+
const signedBefore = journal.signed === true;
|
|
88548
|
+
const started = savedTransaction || RESERVING_ACTIONS.includes(action.action) && (signedBefore || await reservedForTask() !== await reservedForTask(journal.idempotencyKey));
|
|
88549
|
+
const savedFinal = savedOperation === void 0 ? void 0 : await pending.get(savedOperation, finalStep);
|
|
88550
|
+
const mined = savedFinal && isAddressEqual(savedFinal.signer, account.address) && (await Promise.resolve().then(
|
|
88551
|
+
() => rpcFor(savedFinal.chainId).getTransactionReceipt({ hash: savedFinal.txHash })
|
|
88552
|
+
).catch(() => void 0))?.status === "success" ? savedFinal : void 0;
|
|
88553
|
+
if (current && !started && action.action === "fund" && "kind" in current && current.kind === "eip712") {
|
|
88554
|
+
const end = external_exports.object({ validBefore: uint3 }).safeParse(taskV2IntentSchema.parse(current).typedData.message);
|
|
88555
|
+
if (end.success && BigInt(end.data.validBefore) * 1000n <= BigInt(now().getTime())) {
|
|
88556
|
+
await pending.completePreparation(input2.id, verb);
|
|
88557
|
+
journal = { idempotencyKey: randomUUID4(), inputs: action };
|
|
88558
|
+
await pending.putPreparation(input2.id, verb, journal);
|
|
88559
|
+
current = void 0;
|
|
88560
|
+
}
|
|
88561
|
+
}
|
|
88562
|
+
const readiness = await readTasksReadiness(client);
|
|
88563
|
+
if (!started)
|
|
88564
|
+
requireTasksAvailable(
|
|
88565
|
+
action.action,
|
|
88566
|
+
readiness,
|
|
88567
|
+
input2.consent && journal.preparedV2 ? `This run signed nothing and moved no money. A consent this wallet signed earlier for this task may still be valid until it expires; vapi task bump-consent-nonce ${input2.id} --new-nonce <n> revokes it.` : void 0
|
|
88568
|
+
);
|
|
88569
|
+
if (!current) {
|
|
88570
|
+
current = taskV2PreparedSchema.parse(
|
|
88571
|
+
await (input2.consent ? sign2(input2.id, input2.consent, journal) : prepare(input2.id, input2.write, journal))
|
|
88572
|
+
);
|
|
88573
|
+
await pending.bindPreparedV2(input2.id, verb, current);
|
|
88574
|
+
}
|
|
88357
88575
|
const view = await client.getOrder(input2.id);
|
|
88358
88576
|
if (view.workOrder.id !== input2.id) fail("The money view belongs to another task.");
|
|
88359
88577
|
const terms = view.workOrder.terms;
|
|
88360
88578
|
const state = stateSchema.safeParse(view.workOrder.v2State);
|
|
88361
|
-
const
|
|
88362
|
-
|
|
88579
|
+
const resumed = taskV2OperationResponseSchema.safeParse(current);
|
|
88580
|
+
let resumedChainId;
|
|
88581
|
+
if (resumed.success && !resumed.data.operation.plan) {
|
|
88582
|
+
resumedChainId = (await pending.v2Target?.(input2.id))?.chainId ?? readiness?.chainId;
|
|
88583
|
+
if (resumedChainId === void 0)
|
|
88584
|
+
fail("The hosted operation carries no plan and its chain cannot be read.");
|
|
88585
|
+
}
|
|
88586
|
+
const target = await verifyV2Target(
|
|
88587
|
+
options,
|
|
88588
|
+
resumedChainId === void 0 ? current : { chainId: resumedChainId },
|
|
88589
|
+
view,
|
|
88590
|
+
action,
|
|
88591
|
+
void 0,
|
|
88592
|
+
mined !== void 0
|
|
88593
|
+
);
|
|
88594
|
+
if (mined && mined.chainId !== target.chainId)
|
|
88595
|
+
fail("The saved transaction is for another chain than the verified task.");
|
|
88596
|
+
if (readiness && target.chainId !== readiness.chainId)
|
|
88597
|
+
fail(
|
|
88598
|
+
`The prepared step is for ${taskNetworkName(target.chainId)}, but vAPI serves Tasks on ${taskNetworkName(readiness.chainId)}. ${started ? "No new step was signed." : "Nothing was signed."}`
|
|
88599
|
+
);
|
|
88363
88600
|
if (state.success && (BigInt(state.data.totalBaseUnits) !== target.total || state.data.feeBp !== target.feeBp))
|
|
88364
88601
|
v2GuardFailure("Hosted money snapshot differs from the verified V2 target.");
|
|
88365
88602
|
let gross = 0n, pays = 0n;
|
|
@@ -88403,8 +88640,7 @@ function createTaskV2Executor(options) {
|
|
|
88403
88640
|
else gross = total ?? 0n;
|
|
88404
88641
|
feeBp = 0;
|
|
88405
88642
|
} else if (action.action === "raise-dispute" || action.action === "counter-evidence") {
|
|
88406
|
-
if (!state.success
|
|
88407
|
-
fail("Hosted dispute binding is unavailable.");
|
|
88643
|
+
if (!state.success) fail("Hosted dispute binding is unavailable.");
|
|
88408
88644
|
pays = gross = await target.rpc.readContract({
|
|
88409
88645
|
address: target.escrow,
|
|
88410
88646
|
abi: escrowV2Abi,
|
|
@@ -88462,6 +88698,44 @@ function createTaskV2Executor(options) {
|
|
|
88462
88698
|
}
|
|
88463
88699
|
};
|
|
88464
88700
|
await input2.onMoney?.(money2);
|
|
88701
|
+
if (action.action === "fund" && !started) {
|
|
88702
|
+
const cap = await v2Read(
|
|
88703
|
+
target.rpc,
|
|
88704
|
+
target.factory,
|
|
88705
|
+
target.pool ? bountyPoolFactoryV1Abi : escrowFactoryV2Abi,
|
|
88706
|
+
target.pool ? "maxPoolBudget" : "maxEscrowAmount"
|
|
88707
|
+
).catch(() => void 0);
|
|
88708
|
+
if (typeof cap === "bigint" && cap > 0n)
|
|
88709
|
+
assertWithinTaskV2Limit(gross, {
|
|
88710
|
+
chainId: target.chainId,
|
|
88711
|
+
shape: target.pool ? "pool" : target.bounty ? "bounty" : "task",
|
|
88712
|
+
feeBp: target.feeBp,
|
|
88713
|
+
maxBaseUnits: cap
|
|
88714
|
+
});
|
|
88715
|
+
}
|
|
88716
|
+
if (pays > 0n && PAID_NOW_ACTIONS.includes(action.action) && !started) {
|
|
88717
|
+
const balance = await target.rpc.readContract({
|
|
88718
|
+
address: target.pin.usdc,
|
|
88719
|
+
abi: balanceAbi,
|
|
88720
|
+
functionName: "balanceOf",
|
|
88721
|
+
args: [account.address]
|
|
88722
|
+
}).catch(() => void 0);
|
|
88723
|
+
if (typeof balance === "bigint" && balance < pays)
|
|
88724
|
+
throw new TaskOperationError(
|
|
88725
|
+
"insufficient_usdc",
|
|
88726
|
+
`This step pays $${formatBaseUnitsUsd(pays)} USDC, but the wallet holds $${formatBaseUnitsUsd(balance)} on ${taskNetworkName(target.chainId)}. Nothing was signed and no money moved.`,
|
|
88727
|
+
void 0,
|
|
88728
|
+
progress
|
|
88729
|
+
);
|
|
88730
|
+
const gas = await Promise.resolve().then(() => target.rpc.getBalance({ address: account.address })).catch(() => void 0);
|
|
88731
|
+
if (gas === 0n)
|
|
88732
|
+
throw new TaskOperationError(
|
|
88733
|
+
"insufficient_gas",
|
|
88734
|
+
`The wallet holds no ETH on ${taskNetworkName(target.chainId)} to pay for the transaction. Nothing was signed and no money moved.`,
|
|
88735
|
+
void 0,
|
|
88736
|
+
progress
|
|
88737
|
+
);
|
|
88738
|
+
}
|
|
88465
88739
|
const reservationKey = journal.idempotencyKey;
|
|
88466
88740
|
const remaining2 = pays > 0n ? await escrowFundingDayRemainingAtomic({
|
|
88467
88741
|
caps: input2.caps,
|
|
@@ -88477,11 +88751,11 @@ function createTaskV2Executor(options) {
|
|
|
88477
88751
|
now: now(),
|
|
88478
88752
|
excludeReservationId: reservationKey
|
|
88479
88753
|
}) : 0n;
|
|
88480
|
-
if (pays + alreadyReserved > taskPolicyAtomic(input2.policy.maxPerTaskUsd))
|
|
88754
|
+
if (!mined && pays + alreadyReserved > taskPolicyAtomic(input2.policy.maxPerTaskUsd))
|
|
88481
88755
|
return { ok: false, reason: "policy.perTask", money: money2, ...progress };
|
|
88482
|
-
if (pays > remaining2)
|
|
88756
|
+
if (!mined && pays > remaining2)
|
|
88483
88757
|
return { ok: false, reason: "policy.perDay", money: money2, ...progress };
|
|
88484
|
-
if (pays > taskPolicyAtomic(input2.policy.approveAboveUsd)) {
|
|
88758
|
+
if (!mined && pays > taskPolicyAtomic(input2.policy.approveAboveUsd)) {
|
|
88485
88759
|
if (input2.approval && "ask" in input2.approval) {
|
|
88486
88760
|
if (!await input2.approval.ask({
|
|
88487
88761
|
money: taskMoney(pays, 0),
|
|
@@ -88517,13 +88791,24 @@ function createTaskV2Executor(options) {
|
|
|
88517
88791
|
};
|
|
88518
88792
|
let fundingAuthorization;
|
|
88519
88793
|
try {
|
|
88794
|
+
if (mined && "kind" in current)
|
|
88795
|
+
current = taskV2OperationResponseSchema.parse(
|
|
88796
|
+
await operationCall(savedOperation, "recover", { step: finalStep }, key2())
|
|
88797
|
+
);
|
|
88520
88798
|
if ("kind" in current && current.kind === "eip712") {
|
|
88521
88799
|
const intent = taskV2IntentSchema.parse(current);
|
|
88522
88800
|
const typed = intent.typedData;
|
|
88801
|
+
if (started && !savedTransaction && !signedBefore)
|
|
88802
|
+
requireTasksAvailable(
|
|
88803
|
+
action.action,
|
|
88804
|
+
readiness,
|
|
88805
|
+
"No new signature was made. An authorization signed earlier stays valid until it expires."
|
|
88806
|
+
);
|
|
88523
88807
|
await verifyV2TypedData(target, intent, action, account.address, pays);
|
|
88524
88808
|
await bindTarget();
|
|
88525
88809
|
await beforeSign();
|
|
88526
88810
|
const signature = await account.signTypedData(typed);
|
|
88811
|
+
await pending.markPreparationSigned?.(input2.id, verb);
|
|
88527
88812
|
if (action.action === "fund")
|
|
88528
88813
|
fundingAuthorization = { message: typed.message, signature };
|
|
88529
88814
|
const response = await confirmSignature(input2.id, intent.operationId, signature, key2());
|
|
@@ -88549,8 +88834,6 @@ function createTaskV2Executor(options) {
|
|
|
88549
88834
|
}
|
|
88550
88835
|
let result = taskV2OperationResponseSchema.parse(current);
|
|
88551
88836
|
const operationId = result.operation.id;
|
|
88552
|
-
const finalStep = action.action === "approve-bond" ? "v2-approve-usdc" : `v2-${action.action}`;
|
|
88553
|
-
const allowedSteps = action.action === "fund" ? ["v2-create-escrow", "v2-create-pool", "v2-approve-usdc", "v2-fund"] : action.action === "raise-dispute" || action.action === "counter-evidence" ? ["v2-approve-usdc", finalStep] : [finalStep];
|
|
88554
88837
|
const validate7 = (value) => {
|
|
88555
88838
|
if (value.orderId !== input2.id || value.operation.id !== operationId || !isAddressEqual(value.operation.expectedActor, account.address) || !allowedSteps.includes(value.operation.step))
|
|
88556
88839
|
fail("Hosted operation does not match the requested task, wallet or action.");
|
|
@@ -88569,10 +88852,17 @@ function createTaskV2Executor(options) {
|
|
|
88569
88852
|
fail("Hosted sequence moved backwards.");
|
|
88570
88853
|
return { parsed, complete: !("scanComplete" in response) || response.scanComplete };
|
|
88571
88854
|
};
|
|
88855
|
+
let waiting;
|
|
88572
88856
|
for (let poll2 = 0; poll2 < 256; poll2++) {
|
|
88573
88857
|
validate7(result);
|
|
88574
88858
|
progress = { ...progress, operation: publicTaskV2Operation(result.operation, secret) };
|
|
88575
88859
|
const op = result.operation;
|
|
88860
|
+
if (op.state !== "prepared" || waiting?.step !== op.step) waiting = void 0;
|
|
88861
|
+
if (op.state === "prepared" && op.plan) {
|
|
88862
|
+
const shown = canonicalJson(op.plan);
|
|
88863
|
+
if (waiting && waiting.plan !== shown) fail("Recovery changed the prepared plan.");
|
|
88864
|
+
waiting = { step: op.step, plan: shown };
|
|
88865
|
+
}
|
|
88576
88866
|
if (op.state === "confirmed") {
|
|
88577
88867
|
if (op.step !== finalStep)
|
|
88578
88868
|
fail("An approval alone cannot complete the requested action.");
|
|
@@ -88602,14 +88892,26 @@ function createTaskV2Executor(options) {
|
|
|
88602
88892
|
result = recovered.parsed;
|
|
88603
88893
|
continue;
|
|
88604
88894
|
}
|
|
88605
|
-
if (
|
|
88895
|
+
if (mined) {
|
|
88896
|
+
if (op.step !== finalStep)
|
|
88897
|
+
fail(
|
|
88898
|
+
"vAPI asks for an earlier step although the last step of this operation is mined. Nothing was signed."
|
|
88899
|
+
);
|
|
88900
|
+
result = (await call2("transaction", op.step, mined.txHash)).parsed;
|
|
88901
|
+
if (result.operation.state === "prepared") await sleep(1e3);
|
|
88902
|
+
continue;
|
|
88903
|
+
}
|
|
88904
|
+
const plan = recovered.parsed.operation.plan;
|
|
88905
|
+
if (!plan) return fail("The hosted operation is prepared but carries no plan to sign.");
|
|
88906
|
+
if (waiting && waiting.plan !== canonicalJson(plan))
|
|
88606
88907
|
fail("Recovery changed the prepared plan.");
|
|
88607
|
-
|
|
88608
|
-
|
|
88609
|
-
|
|
88908
|
+
waiting = void 0;
|
|
88909
|
+
const step2 = { ...op, plan };
|
|
88910
|
+
if (plan.chainId !== target.chainId)
|
|
88911
|
+
fail("The hosted plan names another chain than the verified task.");
|
|
88610
88912
|
const refreshed = await verifyV2Target(
|
|
88611
88913
|
options,
|
|
88612
|
-
{ orderId: input2.id, operation:
|
|
88914
|
+
{ orderId: input2.id, operation: step2 },
|
|
88613
88915
|
view,
|
|
88614
88916
|
action,
|
|
88615
88917
|
target.escrow
|
|
@@ -88617,7 +88919,7 @@ function createTaskV2Executor(options) {
|
|
|
88617
88919
|
if (!isAddressEqual(refreshed.escrow, target.escrow))
|
|
88618
88920
|
v2GuardFailure("The continuation changed the verified V2 target.");
|
|
88619
88921
|
try {
|
|
88620
|
-
await verifyV2Plan(refreshed,
|
|
88922
|
+
await verifyV2Plan(refreshed, step2, action, pays, fundingAuthorization);
|
|
88621
88923
|
} catch (error61) {
|
|
88622
88924
|
if (error61 instanceof TaskOperationError) throw error61;
|
|
88623
88925
|
v2GuardFailure("Unknown V2 selector or malformed ABI arguments.");
|
|
@@ -88626,7 +88928,6 @@ function createTaskV2Executor(options) {
|
|
|
88626
88928
|
if (await rpc.getChainId() !== plan.chainId) fail("Transaction chain mismatch.");
|
|
88627
88929
|
await input2.beforeSigning?.();
|
|
88628
88930
|
await bindTarget();
|
|
88629
|
-
await beforeSign();
|
|
88630
88931
|
const saved = await pending.withStepLock(
|
|
88631
88932
|
op.id,
|
|
88632
88933
|
op.step,
|
|
@@ -88641,8 +88942,15 @@ function createTaskV2Executor(options) {
|
|
|
88641
88942
|
account.address
|
|
88642
88943
|
))
|
|
88643
88944
|
fail("Saved transaction differs from the hosted plan.");
|
|
88945
|
+
await beforeSign();
|
|
88644
88946
|
return existing;
|
|
88645
88947
|
}
|
|
88948
|
+
if (started)
|
|
88949
|
+
requireTasksAvailable(
|
|
88950
|
+
action.action,
|
|
88951
|
+
readiness,
|
|
88952
|
+
"This step was not signed. Anything this operation signed earlier stands."
|
|
88953
|
+
);
|
|
88646
88954
|
const nonce = Math.max(
|
|
88647
88955
|
await rpc.getTransactionCount({ address: account.address, blockTag: "pending" }),
|
|
88648
88956
|
await pending.nextNonce(plan.chainId, account.address)
|
|
@@ -88657,6 +88965,7 @@ function createTaskV2Executor(options) {
|
|
|
88657
88965
|
nonce
|
|
88658
88966
|
});
|
|
88659
88967
|
if (request.gas === void 0) fail("The V2 transaction has no gas estimate.");
|
|
88968
|
+
await beforeSign();
|
|
88660
88969
|
const raw = await account.signTransaction({
|
|
88661
88970
|
...request,
|
|
88662
88971
|
gas: bufferedV2Gas(request.gas)
|
|
@@ -88761,7 +89070,7 @@ import { randomBytes as nodeRandomBytes } from "node:crypto";
|
|
|
88761
89070
|
|
|
88762
89071
|
// ../core/src/tasks/ballots.ts
|
|
88763
89072
|
import { readdir as readdir7, readFile as readFile19 } from "node:fs/promises";
|
|
88764
|
-
import { join as
|
|
89073
|
+
import { join as join17 } from "node:path";
|
|
88765
89074
|
var address6 = external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/u).transform((v) => v.toLowerCase());
|
|
88766
89075
|
var hash6 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/u).transform((v) => v.toLowerCase());
|
|
88767
89076
|
var TASK_V2_VOTE_OUTCOMES = ["worker", "poster", "split"];
|
|
@@ -88781,7 +89090,7 @@ var taskV2BallotSchema = external_exports.strictObject({
|
|
|
88781
89090
|
createdAt: external_exports.iso.datetime()
|
|
88782
89091
|
});
|
|
88783
89092
|
function taskV2BallotDirectory(home, key2) {
|
|
88784
|
-
return
|
|
89093
|
+
return join17(
|
|
88785
89094
|
home,
|
|
88786
89095
|
"tasks",
|
|
88787
89096
|
"ballots",
|
|
@@ -88791,7 +89100,7 @@ function taskV2BallotDirectory(home, key2) {
|
|
|
88791
89100
|
);
|
|
88792
89101
|
}
|
|
88793
89102
|
function taskV2BallotPath(home, key2) {
|
|
88794
|
-
return
|
|
89103
|
+
return join17(taskV2BallotDirectory(home, key2), `${hash6.parse(key2.commitment)}.json`);
|
|
88795
89104
|
}
|
|
88796
89105
|
async function writeTaskV2Ballot(home, ballot) {
|
|
88797
89106
|
const parsed = taskV2BallotSchema.parse(ballot);
|
|
@@ -88827,7 +89136,7 @@ async function listTaskV2Ballots(home, key2) {
|
|
|
88827
89136
|
}
|
|
88828
89137
|
const ballots = [];
|
|
88829
89138
|
for (const name of names.filter((n) => /^0x[0-9a-f]{64}\.json$/u.test(n)).sort()) {
|
|
88830
|
-
const ballot = await readBallotFile(
|
|
89139
|
+
const ballot = await readBallotFile(join17(directory, name));
|
|
88831
89140
|
if (ballot && `${ballot.commitment}.json` === name) ballots.push(ballot);
|
|
88832
89141
|
}
|
|
88833
89142
|
return ballots.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
@@ -88894,13 +89203,16 @@ function createTaskV2Jury(options) {
|
|
|
88894
89203
|
};
|
|
88895
89204
|
async function voteCase(id2, i2) {
|
|
88896
89205
|
taskV2IndexSchema.parse(i2);
|
|
88897
|
-
const
|
|
88898
|
-
if (
|
|
88899
|
-
throw new TaskOperationError(
|
|
89206
|
+
const chainId = (await readTasksReadiness(client))?.chainId ?? (await options.pending.v2Target?.(id2))?.chainId;
|
|
89207
|
+
if (chainId === void 0)
|
|
89208
|
+
throw new TaskOperationError(
|
|
89209
|
+
"v2_resolver_unavailable",
|
|
89210
|
+
"vAPI's Tasks status could not be read, so the chain of this dispute is unknown. Nothing was signed. Try again later."
|
|
89211
|
+
);
|
|
88900
89212
|
const view = await client.getOrder(id2);
|
|
88901
89213
|
if (view.workOrder.id !== id2)
|
|
88902
89214
|
throw new TaskOperationError("invalid_response", "The order view belongs to another task.");
|
|
88903
|
-
const target = await verifyV2Target(options, { chainId
|
|
89215
|
+
const target = await verifyV2Target(options, { chainId }, view, {
|
|
88904
89216
|
action: "open-jury",
|
|
88905
89217
|
i: i2
|
|
88906
89218
|
});
|
|
@@ -89311,7 +89623,9 @@ function createTasksChain(options) {
|
|
|
89311
89623
|
});
|
|
89312
89624
|
async function deployment() {
|
|
89313
89625
|
const value = await client.deployment();
|
|
89314
|
-
if (!value.configured
|
|
89626
|
+
if (!value.configured)
|
|
89627
|
+
throw new TasksValidationError(tasksUnavailableError(value.chainId).message);
|
|
89628
|
+
if (value.network !== `eip155:${value.chainId}`)
|
|
89315
89629
|
throw new TasksValidationError("The Tasks chain deployment is unavailable.");
|
|
89316
89630
|
if (!getTrustedTasksFactory(value.chainId, options.trustedFactories))
|
|
89317
89631
|
throw new TasksChainError(
|
|
@@ -90266,7 +90580,7 @@ function createTasksRpcFor(config2, options = {}) {
|
|
|
90266
90580
|
|
|
90267
90581
|
// ../core/src/tasks/pending-transactions.ts
|
|
90268
90582
|
import { readFile as readFile20 } from "node:fs/promises";
|
|
90269
|
-
import { join as
|
|
90583
|
+
import { join as join18 } from "node:path";
|
|
90270
90584
|
var hex4 = external_exports.string().regex(/^0x(?:[0-9a-fA-F]{2})+$/).transform((v) => v);
|
|
90271
90585
|
var hash8 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((v) => v);
|
|
90272
90586
|
var step = external_exports.union([
|
|
@@ -90331,7 +90645,8 @@ var stateSchema2 = external_exports.object({
|
|
|
90331
90645
|
idempotencyKey: external_exports.uuid(),
|
|
90332
90646
|
inputs: external_exports.unknown(),
|
|
90333
90647
|
operationId: external_exports.uuid().optional(),
|
|
90334
|
-
preparedV2: taskV2PreparedSchema.optional()
|
|
90648
|
+
preparedV2: taskV2PreparedSchema.optional(),
|
|
90649
|
+
signed: external_exports.boolean().optional()
|
|
90335
90650
|
}).strict()
|
|
90336
90651
|
).default({})
|
|
90337
90652
|
}).strict();
|
|
@@ -90355,7 +90670,7 @@ function validCheckpointStep(storedStep, response) {
|
|
|
90355
90670
|
}[response.operation.kind];
|
|
90356
90671
|
}
|
|
90357
90672
|
function createPendingTransactions(home) {
|
|
90358
|
-
const path =
|
|
90673
|
+
const path = join18(home, "tasks", "pending.json");
|
|
90359
90674
|
const lockPath = `${path}.lock`;
|
|
90360
90675
|
const read = async () => {
|
|
90361
90676
|
try {
|
|
@@ -90442,7 +90757,7 @@ function createPendingTransactions(home) {
|
|
|
90442
90757
|
},
|
|
90443
90758
|
withStepLock(operationId, step2, fn) {
|
|
90444
90759
|
return withFileLock(
|
|
90445
|
-
|
|
90760
|
+
join18(
|
|
90446
90761
|
home,
|
|
90447
90762
|
"tasks",
|
|
90448
90763
|
`step-${encodeURIComponent(operationId)}-${encodeURIComponent(step2)}.lock`
|
|
@@ -90454,13 +90769,13 @@ function createPendingTransactions(home) {
|
|
|
90454
90769
|
external_exports.number().int().positive().parse(chainId);
|
|
90455
90770
|
address8.parse(signer);
|
|
90456
90771
|
return withFileLock(
|
|
90457
|
-
|
|
90772
|
+
join18(home, "tasks", `signer-${chainId}-${signer.toLowerCase()}.lock`),
|
|
90458
90773
|
fn
|
|
90459
90774
|
);
|
|
90460
90775
|
},
|
|
90461
90776
|
withFundingLock(milestoneId2, fn) {
|
|
90462
90777
|
milestoneKey(milestoneId2);
|
|
90463
|
-
return withFileLock(
|
|
90778
|
+
return withFileLock(join18(home, "tasks", `fund-${milestoneId2}.lock`), fn);
|
|
90464
90779
|
},
|
|
90465
90780
|
async nextNonce(chainId, signer) {
|
|
90466
90781
|
external_exports.number().int().positive().parse(chainId);
|
|
@@ -90521,7 +90836,8 @@ function createPendingTransactions(home) {
|
|
|
90521
90836
|
idempotencyKey: external_exports.uuid(),
|
|
90522
90837
|
inputs: external_exports.unknown(),
|
|
90523
90838
|
operationId: external_exports.uuid().optional(),
|
|
90524
|
-
preparedV2: taskV2PreparedSchema.optional()
|
|
90839
|
+
preparedV2: taskV2PreparedSchema.optional(),
|
|
90840
|
+
signed: external_exports.boolean().optional()
|
|
90525
90841
|
}).strict().parse(preparation);
|
|
90526
90842
|
const existing = state.preparations[key2];
|
|
90527
90843
|
if (existing && (existing.idempotencyKey !== parsed.idempotencyKey || canonicalJson(existing.inputs) !== canonicalJson(parsed.inputs)))
|
|
@@ -90563,6 +90879,14 @@ function createPendingTransactions(home) {
|
|
|
90563
90879
|
}
|
|
90564
90880
|
});
|
|
90565
90881
|
},
|
|
90882
|
+
async markPreparationSigned(milestoneId2, verb) {
|
|
90883
|
+
await locked(async (state) => {
|
|
90884
|
+
const existing = state.preparations[preparationKey(milestoneId2, verb)];
|
|
90885
|
+
if (!existing || existing.signed) return;
|
|
90886
|
+
existing.signed = true;
|
|
90887
|
+
await save(state);
|
|
90888
|
+
});
|
|
90889
|
+
},
|
|
90566
90890
|
async completePreparation(milestoneId2, verb) {
|
|
90567
90891
|
await locked(async (state) => {
|
|
90568
90892
|
const key2 = preparationKey(milestoneId2, verb);
|
|
@@ -90702,7 +91026,7 @@ function validateAmount(amountUsd) {
|
|
|
90702
91026
|
// ../core/src/tasks/funding-attempts.ts
|
|
90703
91027
|
import { createHash as createHash5 } from "node:crypto";
|
|
90704
91028
|
import { readFile as readFile21, unlink as unlink13 } from "node:fs/promises";
|
|
90705
|
-
import { dirname as dirname10, join as
|
|
91029
|
+
import { dirname as dirname10, join as join19 } from "node:path";
|
|
90706
91030
|
var coordinates = external_exports.object({
|
|
90707
91031
|
network: external_exports.string().regex(/^eip155:[1-9][0-9]*$/u),
|
|
90708
91032
|
asset: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/u),
|
|
@@ -90730,7 +91054,7 @@ var attemptSchema = external_exports.object({
|
|
|
90730
91054
|
);
|
|
90731
91055
|
async function withFundingAttempt(input2, operation) {
|
|
90732
91056
|
const key2 = createHash5("sha256").update(`${input2.taskId}:${input2.milestoneId}`).digest("hex");
|
|
90733
|
-
const path =
|
|
91057
|
+
const path = join19(dirname10(input2.ledgerPath), "tasks", `funding-${key2}.json`);
|
|
90734
91058
|
return withFileLock(
|
|
90735
91059
|
`${path}.lock`,
|
|
90736
91060
|
async () => {
|
|
@@ -91494,7 +91818,14 @@ async function postTask(context, input2) {
|
|
|
91494
91818
|
"The Tasks deployment is unavailable, so the market network cannot be selected."
|
|
91495
91819
|
);
|
|
91496
91820
|
}
|
|
91497
|
-
|
|
91821
|
+
if (input2.fund)
|
|
91822
|
+
requireTasksAvailable("fund", deployment, "Nothing was posted or signed and no money moved.");
|
|
91823
|
+
const declared = input2.order;
|
|
91824
|
+
const shape = declared.shape ?? (input2.intake === "submissions" ? "bounty" : "task");
|
|
91825
|
+
const total = input2.amount * BigInt(shape === "bounty" ? declared.bounty?.winners ?? input2.maxAwards ?? 1 : 1);
|
|
91826
|
+
const limits = typeof deployment.chainId === "number" ? await context.limitsV2?.(deployment.chainId, shape).catch(() => void 0) : void 0;
|
|
91827
|
+
if (limits) assertWithinTaskV2Limit(total, limits, "Nothing was posted and no money moved.");
|
|
91828
|
+
const feeBp = limits?.feeBp ?? parseFeeBp(deployment);
|
|
91498
91829
|
const feeUnavailable = feeBp === null;
|
|
91499
91830
|
if (feeUnavailable) input2.onFeeUnavailable?.();
|
|
91500
91831
|
const money2 = taskMoney(input2.amount, feeBp);
|
|
@@ -91573,7 +91904,11 @@ async function proposeTask(context, input2) {
|
|
|
91573
91904
|
context
|
|
91574
91905
|
);
|
|
91575
91906
|
if (!deployment.configured)
|
|
91576
|
-
throw
|
|
91907
|
+
throw tasksUnavailableError(
|
|
91908
|
+
deployment.chainId,
|
|
91909
|
+
"No proposal was signed or sent.",
|
|
91910
|
+
"not_available"
|
|
91911
|
+
);
|
|
91577
91912
|
const account = await input2.unlock();
|
|
91578
91913
|
const terms = {
|
|
91579
91914
|
title: workOrder.title,
|
|
@@ -91654,7 +91989,11 @@ async function submitTask(context, input2) {
|
|
|
91654
91989
|
context
|
|
91655
91990
|
);
|
|
91656
91991
|
if (!deployment.configured)
|
|
91657
|
-
throw
|
|
91992
|
+
throw tasksUnavailableError(
|
|
91993
|
+
deployment.chainId,
|
|
91994
|
+
"No entry was signed or sent.",
|
|
91995
|
+
"not_available"
|
|
91996
|
+
);
|
|
91658
91997
|
if (task.amount === null) {
|
|
91659
91998
|
throw new TaskInputError("Task amount is unavailable.");
|
|
91660
91999
|
}
|
|
@@ -92154,6 +92493,9 @@ async function resolveUnmatchedTaskOperation(context, input2) {
|
|
|
92154
92493
|
}
|
|
92155
92494
|
|
|
92156
92495
|
// ../core/src/tasks/post-options.ts
|
|
92496
|
+
var TASK_POST_DEADLINE_LEAD_MS = 3 * 36e5;
|
|
92497
|
+
var TASK_POST_DEADLINE_MARGIN_MS = 6e4;
|
|
92498
|
+
var TASK_DEADLINE_TOO_SOON = "must be at least 3 hours from now when vAPI receives the post, so the task can still be funded and awarded. Use 181m or more.";
|
|
92157
92499
|
function positive(text, name) {
|
|
92158
92500
|
if (text === void 0) throw new TaskInputError(`${name} is required.`);
|
|
92159
92501
|
try {
|
|
@@ -92251,17 +92593,16 @@ function prepareTaskPost(input2, now) {
|
|
|
92251
92593
|
"An open pool requires --open-check allowlist|invite (configure participants separately)."
|
|
92252
92594
|
);
|
|
92253
92595
|
} else {
|
|
92254
|
-
|
|
92255
|
-
|
|
92256
|
-
|
|
92257
|
-
);
|
|
92596
|
+
const lead = input2.shape === void 0 && input2.intake === "submissions" && !input2.milestones && !input2.proofSpec && !input2.checkin ? TASK_LIMITS.postDeadlineMinMs : TASK_POST_DEADLINE_LEAD_MS + TASK_POST_DEADLINE_MARGIN_MS;
|
|
92597
|
+
if (!input2.milestones?.length && duration3 < lead)
|
|
92598
|
+
throw new TaskInputError(`Task deadlines ${TASK_DEADLINE_TOO_SOON}`);
|
|
92258
92599
|
const sum = input2.milestones?.reduce((total, item) => total + BigInt(item.amountBaseUnits), 0n);
|
|
92259
92600
|
amount4 = input2.amountUsd === void 0 && sum !== void 0 ? sum : positive(input2.amountUsd, "--amount");
|
|
92260
92601
|
if (sum !== void 0 && sum !== amount4)
|
|
92261
92602
|
throw new TaskInputError("Milestone amounts must sum to --amount.");
|
|
92262
|
-
if (input2.milestones?.some((item) => Date.parse(item.deadlineAt) - now.getTime() <
|
|
92603
|
+
if (input2.milestones?.some((item) => Date.parse(item.deadlineAt) - now.getTime() < lead))
|
|
92263
92604
|
throw new TaskInputError(
|
|
92264
|
-
|
|
92605
|
+
`Milestone deadlines ${TASK_DEADLINE_TOO_SOON} Creation and funding also check the contract's MIN_WORK_TIME against the chain clock.`
|
|
92265
92606
|
);
|
|
92266
92607
|
}
|
|
92267
92608
|
if (input2.amountUsd !== void 0 && positive(input2.amountUsd, "--amount") !== amount4)
|
|
@@ -93472,7 +93813,7 @@ function csvCell(value) {
|
|
|
93472
93813
|
// ../core/src/swarm-capital.ts
|
|
93473
93814
|
import { createHash as createHash6, randomBytes as randomBytes16 } from "node:crypto";
|
|
93474
93815
|
import { readFile as readFile24, unlink as unlink14 } from "node:fs/promises";
|
|
93475
|
-
import { join as
|
|
93816
|
+
import { join as join21 } from "node:path";
|
|
93476
93817
|
|
|
93477
93818
|
// ../core/src/payment-warning.ts
|
|
93478
93819
|
var PAYMENT_WARNING_CODES = [
|
|
@@ -93489,7 +93830,7 @@ var PAYMENT_WARNING_CODES = [
|
|
|
93489
93830
|
|
|
93490
93831
|
// ../core/src/swarm-workers.ts
|
|
93491
93832
|
import { readFile as readFile23, readdir as readdir8 } from "node:fs/promises";
|
|
93492
|
-
import { join as
|
|
93833
|
+
import { join as join20 } from "node:path";
|
|
93493
93834
|
var runSchema = external_exports.object({
|
|
93494
93835
|
v: external_exports.literal(1),
|
|
93495
93836
|
runId: external_exports.string(),
|
|
@@ -93519,7 +93860,7 @@ var sidecarSchema = external_exports.object({
|
|
|
93519
93860
|
state: external_exports.string().optional()
|
|
93520
93861
|
});
|
|
93521
93862
|
async function assertSwarmWorkersStopped(home, swarm) {
|
|
93522
|
-
const directory =
|
|
93863
|
+
const directory = join20(home, "runs");
|
|
93523
93864
|
let files;
|
|
93524
93865
|
try {
|
|
93525
93866
|
files = await readdir8(directory);
|
|
@@ -93535,7 +93876,7 @@ async function assertSwarmWorkersStopped(home, swarm) {
|
|
|
93535
93876
|
for (const file2 of files.sort()) {
|
|
93536
93877
|
const match = /^(run_[0-9a-f]{24})\.json$/u.exec(file2);
|
|
93537
93878
|
if (match === null) continue;
|
|
93538
|
-
const value = await readWorkerFile(
|
|
93879
|
+
const value = await readWorkerFile(join20(directory, file2));
|
|
93539
93880
|
if (value === void 0) continue;
|
|
93540
93881
|
const parsed = runSchema.safeParse(value);
|
|
93541
93882
|
if (!parsed.success || parsed.data.runId !== match[1]) {
|
|
@@ -93557,7 +93898,7 @@ async function assertSwarmWorkersStopped(home, swarm) {
|
|
|
93557
93898
|
for (const file2 of files) {
|
|
93558
93899
|
const match = /^(run_[0-9a-f]{24})\.railway\.json$/u.exec(file2);
|
|
93559
93900
|
if (match === null) continue;
|
|
93560
|
-
const value = await readWorkerFile(
|
|
93901
|
+
const value = await readWorkerFile(join20(directory, file2));
|
|
93561
93902
|
if (value === void 0) continue;
|
|
93562
93903
|
const parsed = sidecarSchema.safeParse(value);
|
|
93563
93904
|
if (!parsed.success) {
|
|
@@ -94554,13 +94895,13 @@ function runRecordMovementId(value) {
|
|
|
94554
94895
|
return parsed.data;
|
|
94555
94896
|
}
|
|
94556
94897
|
function treasuryRequestRecordPath(home, movementId) {
|
|
94557
|
-
return
|
|
94898
|
+
return join21(home, "runs", "requests", `${movementId}.json`);
|
|
94558
94899
|
}
|
|
94559
94900
|
function delegationRecordPath(home, movementId) {
|
|
94560
|
-
return
|
|
94901
|
+
return join21(home, "runs", "delegations", `${movementId}.json`);
|
|
94561
94902
|
}
|
|
94562
94903
|
function legacyFundingProgressPath(home, name) {
|
|
94563
|
-
return
|
|
94904
|
+
return join21(home, "swarms", `.${name}.funding`);
|
|
94564
94905
|
}
|
|
94565
94906
|
async function readLegacyFundingProgress(home, name) {
|
|
94566
94907
|
try {
|
|
@@ -95210,7 +95551,7 @@ async function removeMemberLocked(home, swarm, account) {
|
|
|
95210
95551
|
}
|
|
95211
95552
|
|
|
95212
95553
|
// ../core/src/status.ts
|
|
95213
|
-
import { join as
|
|
95554
|
+
import { join as join22 } from "node:path";
|
|
95214
95555
|
var STATUS_TIMEOUT_MS = 2e3;
|
|
95215
95556
|
async function buildStatus(deps) {
|
|
95216
95557
|
const timers = deps.timers ?? { setTimeout, clearTimeout };
|
|
@@ -95266,7 +95607,7 @@ function formatUsdAmount(value) {
|
|
|
95266
95607
|
}
|
|
95267
95608
|
async function readVaultStatus(deps) {
|
|
95268
95609
|
const store = deps.secrets.description.replace(/^the /u, "");
|
|
95269
|
-
const path =
|
|
95610
|
+
const path = join22(deps.home, "vault.json");
|
|
95270
95611
|
let file2;
|
|
95271
95612
|
try {
|
|
95272
95613
|
file2 = await readVaultFileUnlocked(path);
|
|
@@ -95699,7 +96040,7 @@ function isRecord4(value) {
|
|
|
95699
96040
|
}
|
|
95700
96041
|
|
|
95701
96042
|
// src/cli.ts
|
|
95702
|
-
import { join as
|
|
96043
|
+
import { join as join35 } from "node:path";
|
|
95703
96044
|
|
|
95704
96045
|
// src/platform.ts
|
|
95705
96046
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -95759,7 +96100,7 @@ function output2(io, json2, value, human) {
|
|
|
95759
96100
|
}
|
|
95760
96101
|
|
|
95761
96102
|
// src/wallet-session.ts
|
|
95762
|
-
import { join as
|
|
96103
|
+
import { join as join23 } from "node:path";
|
|
95763
96104
|
|
|
95764
96105
|
// src/args.ts
|
|
95765
96106
|
var UsageError = class extends Error {
|
|
@@ -96008,7 +96349,7 @@ async function confirmWalletName(name, prompt, refusal, dependencies) {
|
|
|
96008
96349
|
if (typed.trim() !== name) throw new KeystoreError(refusal);
|
|
96009
96350
|
}
|
|
96010
96351
|
async function deviceVaultKey(store, dependencies) {
|
|
96011
|
-
const path =
|
|
96352
|
+
const path = join23(store.home, "vault.json");
|
|
96012
96353
|
const metadata = await readVaultFileUnlocked(path);
|
|
96013
96354
|
const secrets = getSecretStore(dependencies);
|
|
96014
96355
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -98696,7 +99037,7 @@ function exactPriceFact(value) {
|
|
|
98696
99037
|
|
|
98697
99038
|
// ../mcp/src/agent/runtime.ts
|
|
98698
99039
|
import { mkdir as mkdir17, readFile as readFile25, readdir as readdir9, rm as rm2 } from "node:fs/promises";
|
|
98699
|
-
import { join as
|
|
99040
|
+
import { join as join24 } from "node:path";
|
|
98700
99041
|
|
|
98701
99042
|
// ../mcp/src/agent/run.ts
|
|
98702
99043
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -100035,19 +100376,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
100035
100376
|
}
|
|
100036
100377
|
);
|
|
100037
100378
|
function runsDirectory(home) {
|
|
100038
|
-
return
|
|
100379
|
+
return join24(home, "runs");
|
|
100039
100380
|
}
|
|
100040
100381
|
function runRecordPath(home, runId) {
|
|
100041
100382
|
assertRunId(runId);
|
|
100042
|
-
return
|
|
100383
|
+
return join24(runsDirectory(home), `${runId}.json`);
|
|
100043
100384
|
}
|
|
100044
100385
|
function runLogPath(home, runId) {
|
|
100045
100386
|
assertRunId(runId);
|
|
100046
|
-
return
|
|
100387
|
+
return join24(runsDirectory(home), `${runId}.log`);
|
|
100047
100388
|
}
|
|
100048
100389
|
function runResultPath(home, runId) {
|
|
100049
100390
|
assertRunId(runId);
|
|
100050
|
-
return
|
|
100391
|
+
return join24(runsDirectory(home), `${runId}.result.json`);
|
|
100051
100392
|
}
|
|
100052
100393
|
async function writeRunRecord(home, record3) {
|
|
100053
100394
|
const path = runRecordPath(home, record3.runId);
|
|
@@ -100078,7 +100419,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
100078
100419
|
if (match === null) continue;
|
|
100079
100420
|
try {
|
|
100080
100421
|
const record3 = runRecordSchema.parse(
|
|
100081
|
-
JSON.parse(await readFile25(
|
|
100422
|
+
JSON.parse(await readFile25(join24(runsDirectory(home), file2), "utf8"))
|
|
100082
100423
|
);
|
|
100083
100424
|
if (record3.runId !== match[1]) continue;
|
|
100084
100425
|
if (filter.swarm !== void 0 && record3.member.swarm !== filter.swarm) continue;
|
|
@@ -100457,7 +100798,7 @@ async function stopRun(args) {
|
|
|
100457
100798
|
}
|
|
100458
100799
|
}
|
|
100459
100800
|
function memberRunLockPath(home, account) {
|
|
100460
|
-
return
|
|
100801
|
+
return join24(runsDirectory(home), `.member-${account}.lock`);
|
|
100461
100802
|
}
|
|
100462
100803
|
async function withMemberRunLock(home, account, operation) {
|
|
100463
100804
|
if (!WALLET_NAME_PATTERN.test(account))
|
|
@@ -101876,6 +102217,11 @@ function createTasksTools(options) {
|
|
|
101876
102217
|
const client = typeof injected === "function" ? injected(clientOptions) : injected ?? createHostedTasksClient(clientOptions);
|
|
101877
102218
|
return {
|
|
101878
102219
|
client,
|
|
102220
|
+
limitsV2: (async (chainId, shape) => readTaskV2Limits({
|
|
102221
|
+
chainId,
|
|
102222
|
+
shape,
|
|
102223
|
+
rpcFor: options.rpcFor ?? createTasksRpcFor(await loadConfig(getVapiPaths(home).config), { fetch: guardedFetch2 })
|
|
102224
|
+
})),
|
|
101879
102225
|
chain: options.chain ?? (selected === void 0 ? missingTasksChain : lazyTasksChain(async () => {
|
|
101880
102226
|
const { account } = await options.session.payment(selected.name);
|
|
101881
102227
|
const config2 = await loadConfig(getVapiPaths(home).config);
|
|
@@ -104937,7 +105283,7 @@ function assertKeyMatchesAddress(bundle) {
|
|
|
104937
105283
|
}
|
|
104938
105284
|
|
|
104939
105285
|
// src/vault.ts
|
|
104940
|
-
import { join as
|
|
105286
|
+
import { join as join29 } from "node:path";
|
|
104941
105287
|
|
|
104942
105288
|
// src/balance-reader.ts
|
|
104943
105289
|
function baseUsdcBalanceReader(config2, dependencies) {
|
|
@@ -104961,10 +105307,10 @@ function baseUsdcBalanceReader(config2, dependencies) {
|
|
|
104961
105307
|
}
|
|
104962
105308
|
|
|
104963
105309
|
// src/cloud-backup.ts
|
|
104964
|
-
import { join as
|
|
105310
|
+
import { join as join27 } from "node:path";
|
|
104965
105311
|
|
|
104966
105312
|
// ../core/src/cloud-backup.ts
|
|
104967
|
-
import { join as
|
|
105313
|
+
import { join as join26 } from "node:path";
|
|
104968
105314
|
|
|
104969
105315
|
// ../core/src/backup.ts
|
|
104970
105316
|
import {
|
|
@@ -104991,7 +105337,7 @@ import {
|
|
|
104991
105337
|
readdir as readdir10,
|
|
104992
105338
|
rm as rm3
|
|
104993
105339
|
} from "node:fs/promises";
|
|
104994
|
-
import { dirname as dirname12, join as
|
|
105340
|
+
import { dirname as dirname12, join as join25 } from "node:path";
|
|
104995
105341
|
var ERROR_MESSAGES = {
|
|
104996
105342
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
104997
105343
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -105469,7 +105815,7 @@ async function exportBackupSource(options) {
|
|
|
105469
105815
|
var BackupSnapshotChangedError = class extends Error {
|
|
105470
105816
|
};
|
|
105471
105817
|
async function exportBackupSourceAttempt(options, networks) {
|
|
105472
|
-
const path =
|
|
105818
|
+
const path = join25(options.store.home, "vault.json");
|
|
105473
105819
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
105474
105820
|
const [phrase2, vault, file3] = await Promise.all([
|
|
105475
105821
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -105605,16 +105951,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
105605
105951
|
} catch {
|
|
105606
105952
|
throw new BackupError("backup_invalid_input");
|
|
105607
105953
|
}
|
|
105608
|
-
const vaultPath2 =
|
|
105609
|
-
const registryPath =
|
|
105954
|
+
const vaultPath2 = join25(options.home, "vault.json");
|
|
105955
|
+
const registryPath = join25(options.home, "wallets.json");
|
|
105610
105956
|
let stagingHome;
|
|
105611
105957
|
let beforePublishError;
|
|
105612
105958
|
let afterPublishError;
|
|
105613
105959
|
try {
|
|
105614
105960
|
await mkdir18(options.home, { recursive: true, mode: 448 });
|
|
105615
|
-
stagingHome = await mkdtemp(
|
|
105616
|
-
const stagedVaultPath =
|
|
105617
|
-
const stagedRegistryPath =
|
|
105961
|
+
stagingHome = await mkdtemp(join25(options.home, ".backup-restore-"));
|
|
105962
|
+
const stagedVaultPath = join25(stagingHome, "vault.json");
|
|
105963
|
+
const stagedRegistryPath = join25(stagingHome, "wallets.json");
|
|
105618
105964
|
await createVault({
|
|
105619
105965
|
path: stagedVaultPath,
|
|
105620
105966
|
key: options.vaultKey,
|
|
@@ -105673,7 +106019,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
105673
106019
|
protected: plaintext.protected,
|
|
105674
106020
|
networks: [...plaintext.registry.networks]
|
|
105675
106021
|
};
|
|
105676
|
-
const markerPath =
|
|
106022
|
+
const markerPath = join25(options.home, RESTORE_MARKER_FILE);
|
|
105677
106023
|
const fingerprint = restoreFingerprint(
|
|
105678
106024
|
plaintext,
|
|
105679
106025
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -105884,13 +106230,13 @@ async function stageV2Restore(options) {
|
|
|
105884
106230
|
}
|
|
105885
106231
|
const agents = [];
|
|
105886
106232
|
for (const profile of validAgents) {
|
|
105887
|
-
const stagedPath =
|
|
106233
|
+
const stagedPath = join25(options.stagingHome, "agents", `${profile.name}.json`);
|
|
105888
106234
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
105889
106235
|
agents.push({
|
|
105890
106236
|
kind: "agent",
|
|
105891
106237
|
name: profile.name,
|
|
105892
106238
|
stagedPath,
|
|
105893
|
-
targetPath:
|
|
106239
|
+
targetPath: join25(options.home, "agents", `${profile.name}.json`)
|
|
105894
106240
|
});
|
|
105895
106241
|
} else {
|
|
105896
106242
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -105910,13 +106256,13 @@ async function stageV2Restore(options) {
|
|
|
105910
106256
|
if (restoreDevice !== void 0) {
|
|
105911
106257
|
for (const value of validSwarms) {
|
|
105912
106258
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
105913
|
-
const stagedPath =
|
|
106259
|
+
const stagedPath = join25(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
105914
106260
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
105915
106261
|
swarms.push({
|
|
105916
106262
|
kind: "swarm",
|
|
105917
106263
|
name: swarm.name,
|
|
105918
106264
|
stagedPath,
|
|
105919
|
-
targetPath:
|
|
106265
|
+
targetPath: join25(options.home, "swarms", `${swarm.name}.json`)
|
|
105920
106266
|
});
|
|
105921
106267
|
} else {
|
|
105922
106268
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -105926,13 +106272,13 @@ async function stageV2Restore(options) {
|
|
|
105926
106272
|
const movements = [];
|
|
105927
106273
|
for (const movement of validMovements) {
|
|
105928
106274
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
105929
|
-
const stagedPath =
|
|
106275
|
+
const stagedPath = join25(options.stagingHome, "movements", `${restored.id}.json`);
|
|
105930
106276
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
105931
106277
|
movements.push({
|
|
105932
106278
|
kind: "movement",
|
|
105933
106279
|
name: restored.id,
|
|
105934
106280
|
stagedPath,
|
|
105935
|
-
targetPath:
|
|
106281
|
+
targetPath: join25(options.home, "movements", `${restored.id}.json`),
|
|
105936
106282
|
movement: restored
|
|
105937
106283
|
});
|
|
105938
106284
|
} else {
|
|
@@ -106091,7 +106437,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
106091
106437
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
106092
106438
|
let files;
|
|
106093
106439
|
try {
|
|
106094
|
-
files = await readdir10(
|
|
106440
|
+
files = await readdir10(join25(home, "movements"));
|
|
106095
106441
|
} catch (error61) {
|
|
106096
106442
|
if (isMissingFile4(error61)) return;
|
|
106097
106443
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -107000,7 +107346,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
107000
107346
|
try {
|
|
107001
107347
|
let vaultFile;
|
|
107002
107348
|
try {
|
|
107003
|
-
vaultFile = await readVaultFileUnlocked(
|
|
107349
|
+
vaultFile = await readVaultFileUnlocked(join26(options.store.home, "vault.json"));
|
|
107004
107350
|
} catch (error61) {
|
|
107005
107351
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
107006
107352
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -107009,7 +107355,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
107009
107355
|
}
|
|
107010
107356
|
try {
|
|
107011
107357
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
107012
|
-
path:
|
|
107358
|
+
path: join26(options.store.home, "vault.json"),
|
|
107013
107359
|
secrets: options.secrets,
|
|
107014
107360
|
env: options.env,
|
|
107015
107361
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -108530,7 +108876,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
108530
108876
|
}
|
|
108531
108877
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
108532
108878
|
const paths = getVapiPaths();
|
|
108533
|
-
if (!await fileExists3(
|
|
108879
|
+
if (!await fileExists3(join27(paths.directory, "vault.json"))) {
|
|
108534
108880
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
108535
108881
|
}
|
|
108536
108882
|
const context = await cloudContext(io, dependencies);
|
|
@@ -108642,7 +108988,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
108642
108988
|
}
|
|
108643
108989
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
108644
108990
|
const paths = getVapiPaths();
|
|
108645
|
-
if (await fileExists3(
|
|
108991
|
+
if (await fileExists3(join27(paths.directory, "vault.json")) && !await fileExists3(join27(paths.directory, ".backup-restore.json"))) {
|
|
108646
108992
|
throw new Error(
|
|
108647
108993
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
108648
108994
|
);
|
|
@@ -109033,7 +109379,7 @@ function writeSkippedWarnings(io, skipped2) {
|
|
|
109033
109379
|
|
|
109034
109380
|
// src/setup.ts
|
|
109035
109381
|
import { rm as rm4 } from "node:fs/promises";
|
|
109036
|
-
import { join as
|
|
109382
|
+
import { join as join28 } from "node:path";
|
|
109037
109383
|
|
|
109038
109384
|
// src/identity.ts
|
|
109039
109385
|
async function fetchWalletIdentity(options) {
|
|
@@ -109813,7 +110159,7 @@ async function readProcessStdin() {
|
|
|
109813
110159
|
}
|
|
109814
110160
|
|
|
109815
110161
|
// src/version.ts
|
|
109816
|
-
var CLI_VERSION = "0.16.
|
|
110162
|
+
var CLI_VERSION = "0.16.2";
|
|
109817
110163
|
|
|
109818
110164
|
// src/status.ts
|
|
109819
110165
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -110028,7 +110374,7 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
110028
110374
|
steps.push("config");
|
|
110029
110375
|
}
|
|
110030
110376
|
const config2 = await readConfig(paths.config, humanIo);
|
|
110031
|
-
if (!await fileExists3(
|
|
110377
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
110032
110378
|
const os = dependencies.secretBackendProbe ?? (dependencies.secretStore === void 0 ? osSecretStore() : void 0);
|
|
110033
110379
|
if (os !== void 0) {
|
|
110034
110380
|
await chooseSecretBackend({ home: paths.directory, os, env: getEnvironment(dependencies) });
|
|
@@ -110040,7 +110386,7 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
110040
110386
|
let changedAccount = false;
|
|
110041
110387
|
let changedLink = false;
|
|
110042
110388
|
let scannedAddresses;
|
|
110043
|
-
if (!await fileExists3(
|
|
110389
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
110044
110390
|
const choice = await vaultChoice(dependencies);
|
|
110045
110391
|
if (choice === "restore") {
|
|
110046
110392
|
if (!isInteractive(dependencies)) {
|
|
@@ -110128,7 +110474,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
110128
110474
|
let scannedAddresses = 0;
|
|
110129
110475
|
try {
|
|
110130
110476
|
const restored = await restoreVault({
|
|
110131
|
-
path:
|
|
110477
|
+
path: join28(paths.directory, "vault.json"),
|
|
110132
110478
|
key: key2,
|
|
110133
110479
|
phrase: validatedPhrase,
|
|
110134
110480
|
probe: async (address10) => await readBalance3(address10) > 0n,
|
|
@@ -110139,7 +110485,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
110139
110485
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
110140
110486
|
});
|
|
110141
110487
|
names = restored.accounts().map((account) => account.name);
|
|
110142
|
-
await rm4(
|
|
110488
|
+
await rm4(join28(paths.directory, "wallets.json"), { force: true });
|
|
110143
110489
|
} finally {
|
|
110144
110490
|
key2.fill(0);
|
|
110145
110491
|
}
|
|
@@ -110222,7 +110568,7 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
110222
110568
|
}
|
|
110223
110569
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
110224
110570
|
const paths = getVapiPaths();
|
|
110225
|
-
const path =
|
|
110571
|
+
const path = join29(paths.directory, "vault.json");
|
|
110226
110572
|
if (await fileExists3(path)) {
|
|
110227
110573
|
throw new Error(
|
|
110228
110574
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
@@ -110379,7 +110725,7 @@ function requireNoArguments2(argv) {
|
|
|
110379
110725
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
110380
110726
|
}
|
|
110381
110727
|
function vaultPath() {
|
|
110382
|
-
return
|
|
110728
|
+
return join29(getVapiPaths().directory, "vault.json");
|
|
110383
110729
|
}
|
|
110384
110730
|
function quietIo(io) {
|
|
110385
110731
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -110473,7 +110819,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
110473
110819
|
const target = await targetWallet(parsed, dependencies);
|
|
110474
110820
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
110475
110821
|
if (vaultAccount) {
|
|
110476
|
-
const vault = await readVaultFileUnlocked(
|
|
110822
|
+
const vault = await readVaultFileUnlocked(join29(target.store.home, "vault.json"));
|
|
110477
110823
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
110478
110824
|
throw new KeystoreError(
|
|
110479
110825
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -110550,7 +110896,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
110550
110896
|
const existed = store.has(name);
|
|
110551
110897
|
if (existed && !parsed.has("--replace")) {
|
|
110552
110898
|
const address10 = await store.readAddress(name);
|
|
110553
|
-
const location = await store.hasVaultAccount(name) ?
|
|
110899
|
+
const location = await store.hasVaultAccount(name) ? join29(store.home, "vault.json") : store.pathFor(name);
|
|
110554
110900
|
throw new Error(
|
|
110555
110901
|
[
|
|
110556
110902
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -110586,7 +110932,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
110586
110932
|
const result = {
|
|
110587
110933
|
address: account.address,
|
|
110588
110934
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
110589
|
-
vault:
|
|
110935
|
+
vault: join29(paths.directory, "vault.json"),
|
|
110590
110936
|
...previousKeystore ? { previousKeystore } : {},
|
|
110591
110937
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
110592
110938
|
};
|
|
@@ -110787,7 +111133,8 @@ async function retireStoredPassphrase(target, dependencies, io) {
|
|
|
110787
111133
|
|
|
110788
111134
|
// src/accounts.ts
|
|
110789
111135
|
import { readFile as readFile28, stat as stat18 } from "node:fs/promises";
|
|
110790
|
-
import { join as
|
|
111136
|
+
import { join as join30 } from "node:path";
|
|
111137
|
+
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
110791
111138
|
|
|
110792
111139
|
// src/dashboard.ts
|
|
110793
111140
|
import { resolve as resolve2 } from "node:path";
|
|
@@ -111182,10 +111529,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
111182
111529
|
{
|
|
111183
111530
|
previous: from16,
|
|
111184
111531
|
...address10 === void 0 ? {} : { address: address10 },
|
|
111185
|
-
vault:
|
|
111532
|
+
vault: join30(store.home, "vault.json"),
|
|
111186
111533
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
111187
111534
|
},
|
|
111188
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
111535
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join30(store.home, "vault.json")}`].join(
|
|
111189
111536
|
"\n"
|
|
111190
111537
|
)
|
|
111191
111538
|
);
|
|
@@ -111294,33 +111641,44 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
111294
111641
|
{ name: restored.name, ...address10 === void 0 ? {} : { address: address10 } },
|
|
111295
111642
|
{
|
|
111296
111643
|
...address10 === void 0 ? {} : { address: address10 },
|
|
111297
|
-
vault:
|
|
111644
|
+
vault: join30(store.home, "vault.json"),
|
|
111298
111645
|
spendCaps: restored.entry.spendCaps,
|
|
111299
111646
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
111300
111647
|
},
|
|
111301
111648
|
[
|
|
111302
111649
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
111303
|
-
`Vault: ${
|
|
111650
|
+
`Vault: ${join30(store.home, "vault.json")}`
|
|
111304
111651
|
].join("\n")
|
|
111305
111652
|
);
|
|
111306
111653
|
}
|
|
111307
111654
|
async function accountsCapsCommand(argv, json2, io, dependencies) {
|
|
111308
111655
|
const parsed = parseArguments(argv, {
|
|
111309
|
-
valueOptions: /* @__PURE__ */ new Set([
|
|
111656
|
+
valueOptions: /* @__PURE__ */ new Set([
|
|
111657
|
+
"--per-call",
|
|
111658
|
+
"--per-day",
|
|
111659
|
+
"--ceiling",
|
|
111660
|
+
"--max-per-task",
|
|
111661
|
+
"--approve-above"
|
|
111662
|
+
]),
|
|
111663
|
+
booleanOptions: /* @__PURE__ */ new Set(["--yes"]),
|
|
111310
111664
|
maximumPositionals: 1
|
|
111311
111665
|
});
|
|
111312
|
-
const name = requiredPositional(
|
|
111313
|
-
parsed.positionals[0],
|
|
111314
|
-
"<name>",
|
|
111315
|
-
"Usage: vapi accounts caps <name> [--per-call <usd>] [--per-day <usd>] [--ceiling <usd|off>] [--json]"
|
|
111316
|
-
);
|
|
111666
|
+
const name = requiredPositional(parsed.positionals[0], "<name>", CAPS_USAGE);
|
|
111317
111667
|
const perCall = parsed.one("--per-call");
|
|
111318
111668
|
const perDay = parsed.one("--per-day");
|
|
111319
111669
|
const ceiling = parsed.one("--ceiling");
|
|
111670
|
+
const maxPerTask = parsed.one("--max-per-task");
|
|
111671
|
+
const approveAbove = parsed.one("--approve-above");
|
|
111320
111672
|
const store = await openWalletStore(dependencies);
|
|
111321
111673
|
const account = store.resolve({ name, env: {} });
|
|
111322
111674
|
const address10 = await store.readAddress(account.name);
|
|
111323
|
-
|
|
111675
|
+
let taskPolicy = await taskPolicyForWallet({
|
|
111676
|
+
directory: store.home,
|
|
111677
|
+
wallet: account.name,
|
|
111678
|
+
schema: registeredAgentProfileSchema,
|
|
111679
|
+
warn: io.stderr
|
|
111680
|
+
});
|
|
111681
|
+
if (perCall === void 0 && perDay === void 0 && ceiling === void 0 && maxPerTask === void 0 && approveAbove === void 0) {
|
|
111324
111682
|
const caps2 = capsOutput(account.entry.spendCaps, store.ceilingCaps(account.name));
|
|
111325
111683
|
outputForWallet2(
|
|
111326
111684
|
io,
|
|
@@ -111329,13 +111687,15 @@ async function accountsCapsCommand(argv, json2, io, dependencies) {
|
|
|
111329
111687
|
{
|
|
111330
111688
|
...address10 === void 0 ? {} : { address: address10 },
|
|
111331
111689
|
spendCaps: account.entry.spendCaps,
|
|
111332
|
-
...caps2
|
|
111690
|
+
...caps2,
|
|
111691
|
+
taskLimits: taskLimitsJson(taskPolicy)
|
|
111333
111692
|
},
|
|
111334
111693
|
[
|
|
111335
111694
|
walletHeader2({ name: account.name, ...address10 === void 0 ? {} : { address: address10 } }),
|
|
111336
111695
|
`Spend caps: ${formatCaps(account.entry.spendCaps)}`,
|
|
111337
111696
|
`Ceiling: ${caps2.ceilingUsd === "off" ? "off" : `${caps2.ceilingUsd} USDC`}`,
|
|
111338
|
-
|
|
111697
|
+
`Task limits: ${formatTaskLimits(taskPolicy)}`,
|
|
111698
|
+
"Change them with --per-call <usd>, --per-day <usd>, --ceiling <usd|off>, --max-per-task <usd>, or --approve-above <usd>."
|
|
111339
111699
|
].join("\n")
|
|
111340
111700
|
);
|
|
111341
111701
|
return;
|
|
@@ -111348,17 +111708,72 @@ async function accountsCapsCommand(argv, json2, io, dependencies) {
|
|
|
111348
111708
|
throw new UsageError("The per-call cap cannot be larger than the per-day cap.");
|
|
111349
111709
|
}
|
|
111350
111710
|
const ceilingAtomic = ceiling === void 0 ? void 0 : ceiling === "off" ? null : BigInt(capAtomic(ceiling, "--ceiling"));
|
|
111711
|
+
const taskLimits = maxPerTask === void 0 && approveAbove === void 0 ? void 0 : {
|
|
111712
|
+
maxPerTaskUsd: maxPerTask === void 0 ? taskPolicy.maxPerTaskUsd : taskLimitUsd(maxPerTask, "--max-per-task"),
|
|
111713
|
+
approveAboveUsd: approveAbove === void 0 ? taskPolicy.approveAboveUsd : taskLimitUsd(approveAbove, "--approve-above")
|
|
111714
|
+
};
|
|
111715
|
+
const profile = taskLimits === void 0 || taskPolicy.source !== "agent-profile" ? void 0 : (await listAgentProfiles(store.home, {
|
|
111716
|
+
schema: registeredAgentProfileSchema,
|
|
111717
|
+
warn: () => {
|
|
111718
|
+
}
|
|
111719
|
+
})).find((candidate) => candidate.wallet === account.name);
|
|
111720
|
+
if (taskLimits !== void 0 && taskPolicy.source === "agent-profile" && !profile)
|
|
111721
|
+
throw new Error(`The agent profile of ${account.name} is unreadable.`);
|
|
111722
|
+
if (taskLimits !== void 0 && (taskLimits.maxPerTaskUsd > taskPolicy.maxPerTaskUsd || taskLimits.approveAboveUsd > taskPolicy.approveAboveUsd)) {
|
|
111723
|
+
const command = `vapi accounts caps ${account.name}${maxPerTask === void 0 ? "" : ` --max-per-task ${maxPerTask}`}${approveAbove === void 0 ? "" : ` --approve-above ${approveAbove}`}`;
|
|
111724
|
+
const marker = activeAgentMarker(getEnvironment(dependencies));
|
|
111725
|
+
if (marker !== void 0 || !isStdinInteractive(dependencies))
|
|
111726
|
+
throw new UsageError(
|
|
111727
|
+
`Raising a task limit is a decision for a person. Nothing was changed. ${marker === void 0 ? "Standard input is not a terminal." : `${marker} is set, so this is an agent session.`} Run it yourself in a terminal: ${command}`
|
|
111728
|
+
);
|
|
111729
|
+
if (maxPerTask !== void 0 && taskLimits.maxPerTaskUsd > taskPolicy.maxPerTaskUsd) {
|
|
111730
|
+
const liveUsd = await liveTaskLimitUsd(dependencies);
|
|
111731
|
+
if (liveUsd !== void 0 && taskLimits.maxPerTaskUsd > liveUsd)
|
|
111732
|
+
io.stderr(
|
|
111733
|
+
`Note: one task on Base holds at most ${liveUsd} USDC today, so a per-task limit above that changes nothing until the contract's limit is raised.`
|
|
111734
|
+
);
|
|
111735
|
+
}
|
|
111736
|
+
if (!parsed.has("--yes")) {
|
|
111737
|
+
const question = `Raise the task limits of ${account.name} from ${formatTaskLimits(taskPolicy, false)} to ${formatTaskLimits(taskLimits, false)}? Type yes to confirm: `;
|
|
111738
|
+
if (json2 || !isInteractive(dependencies))
|
|
111739
|
+
throw new UsageError(
|
|
111740
|
+
`Raising a task limit needs your confirmation. Nothing was changed. Run it again with --yes: ${command} --yes`
|
|
111741
|
+
);
|
|
111742
|
+
if ((await visibleLine(question, dependencies)).trim().toLowerCase() !== "yes")
|
|
111743
|
+
throw new UsageError("Not confirmed. Nothing was changed.");
|
|
111744
|
+
}
|
|
111745
|
+
}
|
|
111351
111746
|
let entry = account.entry;
|
|
111352
111747
|
if (perCall !== void 0 || perDay !== void 0) {
|
|
111353
111748
|
entry = await store.setSpendCaps(account.name, spendCaps);
|
|
111354
111749
|
}
|
|
111355
111750
|
if (ceilingAtomic !== void 0) entry = await store.setCeiling(account.name, ceilingAtomic);
|
|
111751
|
+
if (taskLimits !== void 0) {
|
|
111752
|
+
if (profile) {
|
|
111753
|
+
await writeAgentProfile(
|
|
111754
|
+
store.home,
|
|
111755
|
+
{ ...profile, ...taskLimits },
|
|
111756
|
+
{ schema: registeredAgentProfileSchema }
|
|
111757
|
+
);
|
|
111758
|
+
taskPolicy = { ...taskPolicy, ...taskLimits };
|
|
111759
|
+
} else {
|
|
111760
|
+
entry = await store.updateTaskPolicy(account.name, (current) => ({
|
|
111761
|
+
...current,
|
|
111762
|
+
...maxPerTask === void 0 ? {} : { maxPerTaskUsd: taskLimits.maxPerTaskUsd },
|
|
111763
|
+
...approveAbove === void 0 ? {} : { approveAboveUsd: taskLimits.approveAboveUsd }
|
|
111764
|
+
}));
|
|
111765
|
+
taskPolicy = { ...taskPolicy, ...taskLimits, source: "account" };
|
|
111766
|
+
}
|
|
111767
|
+
}
|
|
111768
|
+
const taskLimitsChanged = taskLimits !== void 0;
|
|
111356
111769
|
const caps = capsOutput(entry.spendCaps, store.ceilingCaps(account.name));
|
|
111357
111770
|
await recordAudit(dependencies, "wallet.caps", {
|
|
111358
111771
|
wallet: account.name,
|
|
111359
|
-
detail: `${formatCaps(entry.spendCaps)}, ceiling ${caps.ceilingUsd === "off" ? "off" : `${caps.ceilingUsd} USDC`}`
|
|
111772
|
+
detail: `${formatCaps(entry.spendCaps)}, ceiling ${caps.ceilingUsd === "off" ? "off" : `${caps.ceilingUsd} USDC`}${taskLimitsChanged ? `, task limits ${formatTaskLimits(taskPolicy, false)}` : ""}`
|
|
111360
111773
|
});
|
|
111361
|
-
const message = perCall !== void 0 || perDay !== void 0 ? `Spend caps updated for ${account.name}.` : `Ceiling updated for ${account.name}.`;
|
|
111774
|
+
const message = perCall !== void 0 || perDay !== void 0 ? `Spend caps updated for ${account.name}.` : ceilingAtomic !== void 0 ? `Ceiling updated for ${account.name}.` : `Task limits updated for ${account.name}.`;
|
|
111775
|
+
const perDayUsd = Number(formatUsdc(BigInt(entry.spendCaps.perDayAtomic)));
|
|
111776
|
+
const perDayHint = taskLimitsChanged && taskPolicy.maxPerTaskUsd > perDayUsd ? `The per-day cap of ${formatUsdc(BigInt(entry.spendCaps.perDayAtomic))} USD still applies to task funding. Raise it with: vapi accounts caps ${account.name} --per-day <usd>` : void 0;
|
|
111362
111777
|
outputForWallet2(
|
|
111363
111778
|
io,
|
|
111364
111779
|
json2,
|
|
@@ -111367,15 +111782,67 @@ async function accountsCapsCommand(argv, json2, io, dependencies) {
|
|
|
111367
111782
|
...address10 === void 0 ? {} : { address: address10 },
|
|
111368
111783
|
spendCaps: entry.spendCaps,
|
|
111369
111784
|
...caps,
|
|
111370
|
-
|
|
111785
|
+
taskLimits: taskLimitsJson(taskPolicy),
|
|
111786
|
+
message,
|
|
111787
|
+
...perDayHint === void 0 ? {} : { hint: perDayHint }
|
|
111371
111788
|
},
|
|
111372
111789
|
[
|
|
111373
111790
|
message,
|
|
111374
111791
|
`Spend caps: ${formatCaps(entry.spendCaps)}`,
|
|
111375
|
-
`Ceiling: ${caps.ceilingUsd === "off" ? "off" : `${caps.ceilingUsd} USDC`}
|
|
111792
|
+
`Ceiling: ${caps.ceilingUsd === "off" ? "off" : `${caps.ceilingUsd} USDC`}`,
|
|
111793
|
+
`Task limits: ${formatTaskLimits(taskPolicy)}`,
|
|
111794
|
+
...perDayHint === void 0 ? [] : [perDayHint]
|
|
111376
111795
|
].join("\n")
|
|
111377
111796
|
);
|
|
111378
111797
|
}
|
|
111798
|
+
var CAPS_USAGE = "Usage: vapi accounts caps <name> [--per-call <usd>] [--per-day <usd>] [--ceiling <usd|off>] [--max-per-task <usd>] [--approve-above <usd>] [--yes] [--json]";
|
|
111799
|
+
function taskLimitsJson(policy) {
|
|
111800
|
+
return {
|
|
111801
|
+
maxPerTaskUsd: policy.maxPerTaskUsd,
|
|
111802
|
+
approveAboveUsd: policy.approveAboveUsd,
|
|
111803
|
+
source: policy.source
|
|
111804
|
+
};
|
|
111805
|
+
}
|
|
111806
|
+
function formatTaskLimits(policy, withSource = true) {
|
|
111807
|
+
const source = policy.source === "agent-profile" ? "agent profile" : policy.source === "account" ? "set for this account" : "defaults";
|
|
111808
|
+
return `${policy.maxPerTaskUsd} USD per task, approval above ${policy.approveAboveUsd} USD${withSource && policy.source ? ` (${source})` : ""}`;
|
|
111809
|
+
}
|
|
111810
|
+
async function visibleLine(prompt, dependencies) {
|
|
111811
|
+
const line = getPrompts(dependencies).line;
|
|
111812
|
+
if (line) return await line(prompt);
|
|
111813
|
+
const reader = createInterface3({ input: process.stdin, output: process.stderr });
|
|
111814
|
+
try {
|
|
111815
|
+
return await reader.question(prompt);
|
|
111816
|
+
} finally {
|
|
111817
|
+
reader.close();
|
|
111818
|
+
}
|
|
111819
|
+
}
|
|
111820
|
+
var MAX_TASK_LIMIT_USD = 1e6;
|
|
111821
|
+
function taskLimitUsd(value, option) {
|
|
111822
|
+
const usd3 = Number(formatUsdc(BigInt(capAtomic(value, option))));
|
|
111823
|
+
if (!Number.isFinite(usd3) || usd3 > MAX_TASK_LIMIT_USD)
|
|
111824
|
+
throw new UsageError(`${option} must be at most ${MAX_TASK_LIMIT_USD} USD.`);
|
|
111825
|
+
return usd3;
|
|
111826
|
+
}
|
|
111827
|
+
async function liveTaskLimitUsd(dependencies) {
|
|
111828
|
+
try {
|
|
111829
|
+
const env = getEnvironment(dependencies);
|
|
111830
|
+
const rpcFor = dependencies.tasks?.rpcFor ?? createTasksRpcFor(await accountsConfig(dependencies), {
|
|
111831
|
+
env,
|
|
111832
|
+
...dependencies.fetchImpl === void 0 ? {} : { fetch: dependencies.fetchImpl }
|
|
111833
|
+
});
|
|
111834
|
+
const limits = await readTaskV2Limits({
|
|
111835
|
+
chainId: 8453,
|
|
111836
|
+
shape: "task",
|
|
111837
|
+
rpcFor,
|
|
111838
|
+
env,
|
|
111839
|
+
timeoutMs: 2e3
|
|
111840
|
+
});
|
|
111841
|
+
return limits === void 0 ? void 0 : Number(formatUsdc(limits.maxBaseUnits));
|
|
111842
|
+
} catch {
|
|
111843
|
+
return void 0;
|
|
111844
|
+
}
|
|
111845
|
+
}
|
|
111379
111846
|
var DISTRIBUTE_USAGE = "Usage: vapi accounts distribute <amount> --from <account> [--to <a,b,c>] [--network base|arc] [--json]\n vapi accounts distribute --resume <id> [--replace-expired-restored] [--bind-legacy-addresses] [--json]\n vapi accounts distribute --cancel <id> [--replace-expired-restored] [--json]";
|
|
111380
111847
|
async function accountsDistributeCommand(argv, json2, io, dependencies) {
|
|
111381
111848
|
const parsed = parseArguments(argv, {
|
|
@@ -111631,19 +112098,19 @@ function formatNetworkAccounts(accounts) {
|
|
|
111631
112098
|
|
|
111632
112099
|
// src/agent.ts
|
|
111633
112100
|
import { readFile as readFile30, stat as stat19 } from "node:fs/promises";
|
|
111634
|
-
import { join as
|
|
111635
|
-
import { createInterface as
|
|
112101
|
+
import { join as join33 } from "node:path";
|
|
112102
|
+
import { createInterface as createInterface4 } from "node:readline/promises";
|
|
111636
112103
|
|
|
111637
112104
|
// src/headless.ts
|
|
111638
112105
|
import { rmSync } from "node:fs";
|
|
111639
112106
|
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm5, writeFile as writeFile9 } from "node:fs/promises";
|
|
111640
112107
|
import { tmpdir as osTmpdir } from "node:os";
|
|
111641
|
-
import { join as
|
|
112108
|
+
import { join as join31 } from "node:path";
|
|
111642
112109
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
111643
112110
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
111644
112111
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
111645
112112
|
async function createHeadlessHome(bundle, options = {}) {
|
|
111646
|
-
const home = await mkdtemp2(
|
|
112113
|
+
const home = await mkdtemp2(join31(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
111647
112114
|
const cleanup = async () => {
|
|
111648
112115
|
await rm5(home, { recursive: true, force: true });
|
|
111649
112116
|
};
|
|
@@ -111855,7 +112322,7 @@ import {
|
|
|
111855
112322
|
writeFile as nodeWriteFile
|
|
111856
112323
|
} from "node:fs/promises";
|
|
111857
112324
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
111858
|
-
import { basename as basename4, dirname as dirname14, join as
|
|
112325
|
+
import { basename as basename4, dirname as dirname14, join as join32 } from "node:path";
|
|
111859
112326
|
var RAILWAY_CLI = {
|
|
111860
112327
|
binary: "railway",
|
|
111861
112328
|
create: (options) => [
|
|
@@ -112046,7 +112513,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
112046
112513
|
}
|
|
112047
112514
|
function railwaySidecarPath(home, runId) {
|
|
112048
112515
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
112049
|
-
return
|
|
112516
|
+
return join32(runsDirectory(home), `${runId}.railway.json`);
|
|
112050
112517
|
}
|
|
112051
112518
|
function createRailwayRuntime(options) {
|
|
112052
112519
|
const { home } = options;
|
|
@@ -112407,10 +112874,10 @@ ${destroyedInstruction}
|
|
|
112407
112874
|
let createError;
|
|
112408
112875
|
let cleanupError;
|
|
112409
112876
|
try {
|
|
112410
|
-
directory = await fs.mkdtemp(
|
|
112877
|
+
directory = await fs.mkdtemp(join32(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
112411
112878
|
assertNotInterrupted();
|
|
112412
112879
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
112413
|
-
envFile =
|
|
112880
|
+
envFile = join32(directory, "member.env");
|
|
112414
112881
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
112415
112882
|
`, {
|
|
112416
112883
|
encoding: "utf8",
|
|
@@ -112771,7 +113238,7 @@ Destroy it yourself with: railway sandbox destroy ${id2}`
|
|
|
112771
113238
|
return { runId, sandboxId: id2, destroyed: true };
|
|
112772
113239
|
};
|
|
112773
113240
|
if (account !== void 0) return await withMemberRunLock(home, account, destroy);
|
|
112774
|
-
return await withFileLock(
|
|
113241
|
+
return await withFileLock(join32(runsDirectory(home), `.sidecar-${runId}.lock`), destroy, {
|
|
112775
113242
|
timeoutMs: 5e3,
|
|
112776
113243
|
lockedMessage: `Run ${runId} is changing sidecar state.`
|
|
112777
113244
|
});
|
|
@@ -112993,7 +113460,7 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
112993
113460
|
function writeSidecarSync(path, sidecar) {
|
|
112994
113461
|
const directory = dirname14(path);
|
|
112995
113462
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
112996
|
-
const temporary =
|
|
113463
|
+
const temporary = join32(
|
|
112997
113464
|
directory,
|
|
112998
113465
|
`.${basename4(path)}.${process.pid}.${randomBytes17(6).toString("hex")}.tmp`
|
|
112999
113466
|
);
|
|
@@ -113091,7 +113558,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
113091
113558
|
}
|
|
113092
113559
|
}
|
|
113093
113560
|
async function deviceVaultKey2(home, secrets, now) {
|
|
113094
|
-
const path =
|
|
113561
|
+
const path = join32(home, "vault.json");
|
|
113095
113562
|
const metadata = await readVaultFileUnlocked(path);
|
|
113096
113563
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
113097
113564
|
path,
|
|
@@ -113462,24 +113929,42 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
113462
113929
|
const callBudget = usdOption(parsed.one("--call-budget") ?? "1", "--call-budget", true);
|
|
113463
113930
|
const maxPerCall = usdOption(parsed.one("--max-per-call") ?? "0.05", "--max-per-call");
|
|
113464
113931
|
const routerBudget = usdOption(parsed.one("--router-budget") ?? "1", "--router-budget", true);
|
|
113465
|
-
const
|
|
113932
|
+
const initialStore = await openWalletStore(dependencies);
|
|
113933
|
+
const owned = initialStore.entry(name);
|
|
113934
|
+
const stricter = accountTaskLimitsUnderProfile(owned?.taskPolicy);
|
|
113935
|
+
const defaultMaxPerTask = stricter?.maxPerTaskUsd ?? DEFAULT_MAX_PER_TASK_USD;
|
|
113936
|
+
const approveAbove = usdOption(
|
|
113937
|
+
parsed.one("--approve-above") ?? String(stricter?.approveAboveUsd ?? 0.5),
|
|
113938
|
+
"--approve-above"
|
|
113939
|
+
);
|
|
113466
113940
|
const maxSteps = boundedInteger(parsed.one("--max-steps") ?? "12", "--max-steps", 1, 50);
|
|
113467
113941
|
const interactive = !json2 && (dependencies.interactive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY));
|
|
113468
113942
|
const promptForTaskPolicy = interactive && !parsed.has("--yes");
|
|
113469
113943
|
const maxPerTask = usdOption(
|
|
113470
|
-
parsed.one("--max-per-task") ?? ((promptForTaskPolicy ? await
|
|
113944
|
+
parsed.one("--max-per-task") ?? ((promptForTaskPolicy ? await visibleLine2(`Max per task in USD [${defaultMaxPerTask}]: `, dependencies) : "") || String(defaultMaxPerTask)),
|
|
113471
113945
|
"--max-per-task"
|
|
113472
113946
|
);
|
|
113473
113947
|
const autoReleaseBelow = usdOption(
|
|
113474
|
-
parsed.one("--auto-release-below") ?? ((promptForTaskPolicy ? await
|
|
113948
|
+
parsed.one("--auto-release-below") ?? ((promptForTaskPolicy ? await visibleLine2(
|
|
113475
113949
|
`Auto-release below in USD [${DEFAULT_AUTO_RELEASE_BELOW_USD}]: `,
|
|
113476
113950
|
dependencies
|
|
113477
113951
|
) : "") || String(DEFAULT_AUTO_RELEASE_BELOW_USD)),
|
|
113478
113952
|
"--auto-release-below"
|
|
113479
113953
|
);
|
|
113954
|
+
if (owned !== void 0) {
|
|
113955
|
+
const raised = [
|
|
113956
|
+
...maxPerTask.number > (owned.taskPolicy?.maxPerTaskUsd ?? DEFAULT_MAX_PER_TASK_USD) ? [`--max-per-task ${maxPerTask.text}`] : [],
|
|
113957
|
+
...approveAbove.number > (owned.taskPolicy?.approveAboveUsd ?? 0.5) ? [`--approve-above ${approveAbove.text}`] : [],
|
|
113958
|
+
...BigInt(callBudget.atomic) > BigInt(owned.spendCaps.perDayAtomic) ? [`--call-budget ${callBudget.text}`] : []
|
|
113959
|
+
];
|
|
113960
|
+
const marker = activeAgentMarker(getEnvironment(dependencies));
|
|
113961
|
+
if (raised.length > 0 && (marker !== void 0 || !isStdinInteractive(dependencies)))
|
|
113962
|
+
throw new UsageError(
|
|
113963
|
+
`Account ${name} already exists, and ${raised.join(", ")} would raise what it has now: ${owned.taskPolicy?.maxPerTaskUsd ?? DEFAULT_MAX_PER_TASK_USD} USD per task, approval above ${owned.taskPolicy?.approveAboveUsd ?? 0.5} USD, ${formatUsdc(BigInt(owned.spendCaps.perDayAtomic))} USD per day. Raising a limit is a decision for a person. Nothing was changed. ${marker === void 0 ? "Standard input is not a terminal." : `${marker} is set, so this is an agent session.`} Run the command yourself in a terminal, or leave these values at or below the account's.`
|
|
113964
|
+
);
|
|
113965
|
+
}
|
|
113480
113966
|
const commandIo = json2 ? { stdout: () => void 0, stderr: io.stderr } : io;
|
|
113481
|
-
|
|
113482
|
-
if (!initialStore.has(name)) {
|
|
113967
|
+
if (owned === void 0) {
|
|
113483
113968
|
await walletCreateCommand([name, "--label", name], json2, commandIo, dependencies);
|
|
113484
113969
|
}
|
|
113485
113970
|
await walletCapsCommand(
|
|
@@ -113504,6 +113989,20 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
113504
113989
|
paused: false,
|
|
113505
113990
|
createdAt: (dependencies.now?.() ?? /* @__PURE__ */ new Date()).toISOString()
|
|
113506
113991
|
};
|
|
113992
|
+
let clearedAccountTaskLimits = false;
|
|
113993
|
+
const keptAccountTaskLimits = (await initialStore.updateTaskPolicy(name, (current) => {
|
|
113994
|
+
const kept = accountTaskLimitsUnderProfile(current);
|
|
113995
|
+
clearedAccountTaskLimits = JSON.stringify(kept) !== JSON.stringify(current);
|
|
113996
|
+
return kept;
|
|
113997
|
+
})).taskPolicy;
|
|
113998
|
+
if (keptAccountTaskLimits)
|
|
113999
|
+
io.stderr(
|
|
114000
|
+
`Account ${name} keeps the task limits its owner set below the defaults. When the agent profile is removed it returns to ${keptAccountTaskLimits.maxPerTaskUsd ?? DEFAULT_MAX_PER_TASK_USD} USD per task and approval above ${keptAccountTaskLimits.approveAboveUsd ?? 0.5} USD. The agent profile holds the limits now: ${profile.maxPerTaskUsd} USD per task, approval above ${profile.approveAboveUsd} USD.`
|
|
114001
|
+
);
|
|
114002
|
+
else if (clearedAccountTaskLimits)
|
|
114003
|
+
io.stderr(
|
|
114004
|
+
`The task limits set for account ${name} with vapi accounts caps were cleared. The agent profile holds them now: ${profile.maxPerTaskUsd} USD per task, approval above ${profile.approveAboveUsd} USD.`
|
|
114005
|
+
);
|
|
113507
114006
|
const writeProfile = dependencies.agent?.writeAgentProfile ?? writeAgentProfile;
|
|
113508
114007
|
await writeProfile(paths.directory, profile, agentProfileOptions2);
|
|
113509
114008
|
await runLoginFlow(["--account", name, "--label", name], json2, commandIo, dependencies, {
|
|
@@ -113531,6 +114030,7 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
113531
114030
|
perDayAtomic: callBudget.atomic
|
|
113532
114031
|
},
|
|
113533
114032
|
routerAllowanceUsd: routerBudget.number,
|
|
114033
|
+
...clearedAccountTaskLimits ? { clearedAccountTaskLimits: true } : {},
|
|
113534
114034
|
fundingHint
|
|
113535
114035
|
})
|
|
113536
114036
|
);
|
|
@@ -113783,7 +114283,7 @@ async function buildAgentRunDeps(input2) {
|
|
|
113783
114283
|
};
|
|
113784
114284
|
const approve2 = async ({ ref, priceUsd, reason }) => {
|
|
113785
114285
|
if (approvals === "decline" || !tty) return false;
|
|
113786
|
-
const answer = await
|
|
114286
|
+
const answer = await visibleLine2(
|
|
113787
114287
|
`Pay ${usd(priceUsd)} to ${ref}? ${reason} [y/N] `,
|
|
113788
114288
|
dependencies
|
|
113789
114289
|
);
|
|
@@ -114056,10 +114556,10 @@ function searchQuery(argumentsJson) {
|
|
|
114056
114556
|
return void 0;
|
|
114057
114557
|
}
|
|
114058
114558
|
}
|
|
114059
|
-
async function
|
|
114559
|
+
async function visibleLine2(prompt, dependencies) {
|
|
114060
114560
|
if (dependencies.prompts?.line)
|
|
114061
114561
|
return (await dependencies.prompts.line(prompt)).trim().toLowerCase();
|
|
114062
|
-
const reader =
|
|
114562
|
+
const reader = createInterface4({ input: process.stdin, output: process.stderr });
|
|
114063
114563
|
try {
|
|
114064
114564
|
return (await reader.question(prompt)).trim().toLowerCase();
|
|
114065
114565
|
} finally {
|
|
@@ -114071,7 +114571,7 @@ function explicitWallet(name) {
|
|
|
114071
114571
|
}
|
|
114072
114572
|
async function profileFileExists(directory, name) {
|
|
114073
114573
|
try {
|
|
114074
|
-
await stat19(
|
|
114574
|
+
await stat19(join33(directory, `${name}.json`));
|
|
114075
114575
|
return true;
|
|
114076
114576
|
} catch (error61) {
|
|
114077
114577
|
if (isMissingFile(error61)) return false;
|
|
@@ -114788,7 +115288,7 @@ import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
|
114788
115288
|
import { constants as constants2 } from "node:fs";
|
|
114789
115289
|
import { access, mkdir as mkdir20, readFile as readFile31, realpath, unlink as unlink15, writeFile as writeFile10 } from "node:fs/promises";
|
|
114790
115290
|
import { homedir as homedir3 } from "node:os";
|
|
114791
|
-
import { basename as basename5, dirname as dirname15, join as
|
|
115291
|
+
import { basename as basename5, dirname as dirname15, join as join34, posix, win32 as win322 } from "node:path";
|
|
114792
115292
|
|
|
114793
115293
|
// src/toml-config.ts
|
|
114794
115294
|
function removeTomlTables(contents, isTarget) {
|
|
@@ -114868,7 +115368,7 @@ var VAPI_CODEX_PROFILE = "vapi";
|
|
|
114868
115368
|
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
114869
115369
|
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
114870
115370
|
function codexConfigPath(env, home) {
|
|
114871
|
-
return
|
|
115371
|
+
return join34(env.CODEX_HOME || join34(home, ".codex"), "config.toml");
|
|
114872
115372
|
}
|
|
114873
115373
|
function hasVapiCodexProfile(contents) {
|
|
114874
115374
|
const roots = new Set(
|
|
@@ -114984,7 +115484,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
114984
115484
|
const env = getEnvironment(dependencies);
|
|
114985
115485
|
const home = dependencies.code?.homedir ?? homedir3();
|
|
114986
115486
|
const config2 = codexConfigPath(env, home);
|
|
114987
|
-
const rcPaths = [
|
|
115487
|
+
const rcPaths = [join34(home, ".zshrc"), join34(home, ".bashrc")];
|
|
114988
115488
|
if (command === "uninstall") {
|
|
114989
115489
|
const removed = [];
|
|
114990
115490
|
const previous = await readOptional(config2);
|
|
@@ -117230,7 +117730,8 @@ async function taskV2Command(verb, id2, parsed, json2, io, dependencies) {
|
|
|
117230
117730
|
const policy = await taskPolicyForWallet({
|
|
117231
117731
|
directory: getVapiPaths().directory,
|
|
117232
117732
|
wallet: target.name,
|
|
117233
|
-
schema: registeredAgentProfileSchema
|
|
117733
|
+
schema: registeredAgentProfileSchema,
|
|
117734
|
+
warn: io.stderr
|
|
117234
117735
|
});
|
|
117235
117736
|
try {
|
|
117236
117737
|
const result = await executeTaskV2(context, {
|
|
@@ -117332,7 +117833,8 @@ async function taskJuryCommand(verb, id2, parsed, json2, io, dependencies) {
|
|
|
117332
117833
|
policy: await taskPolicyForWallet({
|
|
117333
117834
|
directory: getVapiPaths().directory,
|
|
117334
117835
|
wallet: target.name,
|
|
117335
|
-
schema: registeredAgentProfileSchema
|
|
117836
|
+
schema: registeredAgentProfileSchema,
|
|
117837
|
+
warn: io.stderr
|
|
117336
117838
|
}),
|
|
117337
117839
|
caps: await spendCapsForWallet(target.store, target.name),
|
|
117338
117840
|
wallet: target.name,
|
|
@@ -117431,12 +117933,13 @@ var TASK_HELP = `Usage:
|
|
|
117431
117933
|
vapi task watch <id> [--until <state>] [--auto-release] [--timeout 7d] [--interval 5s] [--counterparty <0x\u2026>] [--account <name>] [--json]
|
|
117432
117934
|
vapi task status <id> [--operation <uuid> --step <v2-step> --recover|--abandon] [--account <name>] [--json]
|
|
117433
117935
|
|
|
117434
|
-
Durations: 5s, 10m, 48h, 7d, or an ISO-8601 timestamp.
|
|
117936
|
+
Durations: 5s, 10m, 48h, 7d, or an ISO-8601 timestamp. A task deadline and every task milestone deadline must be at least 3 hours ahead when vAPI receives the post (one hour of work time, one to award, one to fund); use 181m or more. Bounty and pool posting and proposal terms require at least 10 minutes.
|
|
117435
117937
|
V1 dispute accepts a precomputed evidence hash. V2 dispute accepts --index with --evidence text. Milestone action indices are zero-based; declared milestone indices remain one-based.
|
|
117436
117938
|
Jury: ${TASK_V2_JURY_RULES} ${TASK_V2_REVIEWER_GUIDANCE} Jury open repeats while the case is Snapshotting.
|
|
117437
117939
|
Vote --commit seals the salt in a local ballot under VAPI_HOME before vAPI sees the commitment; --reveal reads that ballot back by the onchain commitment, so reveal from the machine that committed. --to-worker is USDC base units and only for split.
|
|
117438
117940
|
Watch requires an interval of at least 1s and a positive timeout. Auto-release uses the acting wallet's agent profile, or defaults, and releases only amounts strictly below the threshold.
|
|
117439
|
-
Posting without --fund moves no money. --fund applies task and daily caps before signing.
|
|
117941
|
+
Posting without --fund moves no money. --fund applies task and daily caps before signing. Fund, post --fund, approve-bond, sign --action award-consent and award --worker need vAPI to report Tasks as available and stop before signing when it does not; a rerun of an operation that already signed something is resumed instead. Show or raise task limits with vapi accounts caps <name> [--max-per-task <usd>] [--approve-above <usd>].
|
|
117942
|
+
Base mainnet runs V2 only: the worker runs sign --action award-consent, then the poster runs award --worker <addr>. propose sends an offer the poster can read. award <proposalId> and sign without --action are V1 only. Task reads require tasks:read and writes require tasks:write; write access includes reads.
|
|
117440
117943
|
The thread cursor is the previous page's nextBeforeSeq; --after reads older messages using beforeSeq.
|
|
117441
117944
|
Every command accepts --json. Watch and a partially completed sign may write more than one JSON value. Human diagnostics go to stderr.
|
|
117442
117945
|
|
|
@@ -117619,6 +118122,10 @@ async function taskContext(parsed, io, dependencies, publicOnly = false) {
|
|
|
117619
118122
|
const injected = dependencies.tasks?.client;
|
|
117620
118123
|
const client = typeof injected === "function" ? injected(options) : injected ?? createHostedTasksClient(options);
|
|
117621
118124
|
const pending = createPendingTransactions(getVapiPaths().directory);
|
|
118125
|
+
const readRpcFor = dependencies.tasks?.rpcFor ?? createTasksRpcFor(config2, {
|
|
118126
|
+
env,
|
|
118127
|
+
...dependencies.fetchImpl === void 0 ? {} : { fetch: dependencies.fetchImpl }
|
|
118128
|
+
});
|
|
117622
118129
|
const chain2 = dependencies.tasks?.chain ?? (publicOnly || target === void 0 ? missingTasksChain : lazyTasksChain2(
|
|
117623
118130
|
async () => {
|
|
117624
118131
|
const { account } = await unlockTarget(target, dependencies);
|
|
@@ -117645,6 +118152,7 @@ async function taskContext(parsed, io, dependencies, publicOnly = false) {
|
|
|
117645
118152
|
));
|
|
117646
118153
|
return {
|
|
117647
118154
|
client,
|
|
118155
|
+
limitsV2: (chainId, shape) => readTaskV2Limits({ chainId, shape, rpcFor: readRpcFor, env }),
|
|
117648
118156
|
baseUrl,
|
|
117649
118157
|
...target === void 0 ? {} : { target },
|
|
117650
118158
|
...token === void 0 ? {} : { token },
|
|
@@ -117858,7 +118366,8 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
117858
118366
|
budget: parsed.one("--budget"),
|
|
117859
118367
|
gate: enumOption(parsed.one("--gate"), ["open", "proven"], "--gate"),
|
|
117860
118368
|
verifier: enumOption(parsed.one("--verifier"), ["poster", "vapi"], "--verifier"),
|
|
117861
|
-
openCheck: enumOption(parsed.one("--open-check"), ["allowlist", "invite"], "--open-check")
|
|
118369
|
+
openCheck: enumOption(parsed.one("--open-check"), ["allowlist", "invite"], "--open-check"),
|
|
118370
|
+
intake: enumOption(parsed.one("--intake"), ["proposals", "submissions"], "--intake")
|
|
117862
118371
|
},
|
|
117863
118372
|
now
|
|
117864
118373
|
);
|
|
@@ -117891,7 +118400,9 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
117891
118400
|
...intake === void 0 ? {} : { intake },
|
|
117892
118401
|
...maxAwards === void 0 ? {} : { maxAwards },
|
|
117893
118402
|
...parsed.one("--webhook") === void 0 ? {} : { webhook: parsed.one("--webhook") },
|
|
117894
|
-
onFeeUnavailable: () => io.stderr(
|
|
118403
|
+
onFeeUnavailable: () => io.stderr(
|
|
118404
|
+
"The fee could not be read from the Tasks contract or from vAPI. Funding shows it before anything is signed."
|
|
118405
|
+
)
|
|
117895
118406
|
});
|
|
117896
118407
|
if (parsed.has("--fund")) {
|
|
117897
118408
|
if (outcome.funding?.error) {
|
|
@@ -118758,7 +119269,7 @@ Usage:
|
|
|
118758
119269
|
vapi accounts use <name> [--json]
|
|
118759
119270
|
vapi accounts remove <name> [--force] [--json]
|
|
118760
119271
|
vapi accounts restore <name> [--json]
|
|
118761
|
-
vapi accounts caps <name> [--per-call <usd>] [--per-day <usd>] [--ceiling <usd|off>] [--json]
|
|
119272
|
+
vapi accounts caps <name> [--per-call <usd>] [--per-day <usd>] [--ceiling <usd|off>] [--max-per-task <usd>] [--approve-above <usd>] [--yes] [--json]
|
|
118762
119273
|
vapi accounts distribute <amount> --from <account> [--to <a,b,c>] [--network base|arc] [--json]
|
|
118763
119274
|
vapi accounts distribute --resume <id> [--replace-expired-restored] [--bind-legacy-addresses] [--json]
|
|
118764
119275
|
vapi accounts distribute --cancel <id> [--replace-expired-restored] [--json]
|
|
@@ -119074,7 +119585,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
119074
119585
|
break;
|
|
119075
119586
|
case "unlock":
|
|
119076
119587
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
119077
|
-
if (await fileExists3(
|
|
119588
|
+
if (await fileExists3(join35(getVapiPaths().directory, "vault.json"))) {
|
|
119078
119589
|
parseArguments(args.slice(1), {
|
|
119079
119590
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION]),
|
|
119080
119591
|
maximumPositionals: 0
|
|
@@ -119274,7 +119785,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
119274
119785
|
address: account.address,
|
|
119275
119786
|
accounts,
|
|
119276
119787
|
config: paths.config,
|
|
119277
|
-
vault:
|
|
119788
|
+
vault: join35(paths.directory, "vault.json"),
|
|
119278
119789
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
119279
119790
|
custody: "self",
|
|
119280
119791
|
warning: CUSTODY_NOTICE,
|
|
@@ -119413,7 +119924,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
119413
119924
|
const result = {
|
|
119414
119925
|
address: account.address,
|
|
119415
119926
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
119416
|
-
vault:
|
|
119927
|
+
vault: join35(paths.directory, "vault.json"),
|
|
119417
119928
|
...label2 === void 0 ? {} : { label: label2 },
|
|
119418
119929
|
spendCaps: created.entry.spendCaps,
|
|
119419
119930
|
isDefault,
|
|
@@ -119453,7 +119964,7 @@ function formatCaps2(caps) {
|
|
|
119453
119964
|
function walletListResult(store, wallets, unlocked) {
|
|
119454
119965
|
return {
|
|
119455
119966
|
default: store.defaultName ?? null,
|
|
119456
|
-
vault:
|
|
119967
|
+
vault: join35(store.home, "vault.json"),
|
|
119457
119968
|
wallets: wallets.map((wallet) => ({
|
|
119458
119969
|
name: wallet.name,
|
|
119459
119970
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|