@virtuals-protocol/acp-node 0.2.0-beta-fund.4 → 0.2.0-beta.10
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/index.d.mts +42 -22
- package/dist/index.d.ts +42 -22
- package/dist/index.js +136 -109
- package/dist/index.mjs +133 -109
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -72,7 +72,7 @@ var require_package = __commonJS({
|
|
|
72
72
|
"package.json"(exports2, module2) {
|
|
73
73
|
module2.exports = {
|
|
74
74
|
name: "@virtuals-protocol/acp-node",
|
|
75
|
-
version: "0.2.0-beta
|
|
75
|
+
version: "0.2.0-beta.10",
|
|
76
76
|
main: "./dist/index.js",
|
|
77
77
|
module: "./dist/index.mjs",
|
|
78
78
|
types: "./dist/index.d.ts",
|
|
@@ -109,6 +109,7 @@ __export(index_exports, {
|
|
|
109
109
|
AcpAgentSort: () => AcpAgentSort,
|
|
110
110
|
AcpContractClient: () => acpContractClient_default,
|
|
111
111
|
AcpContractConfig: () => AcpContractConfig,
|
|
112
|
+
AcpError: () => acpError_default,
|
|
112
113
|
AcpGraduationStatus: () => AcpGraduationStatus,
|
|
113
114
|
AcpJob: () => acpJob_default,
|
|
114
115
|
AcpJobPhases: () => AcpJobPhases,
|
|
@@ -117,8 +118,10 @@ __export(index_exports, {
|
|
|
117
118
|
AcpOnlineStatus: () => AcpOnlineStatus,
|
|
118
119
|
Fare: () => Fare,
|
|
119
120
|
FareAmount: () => FareAmount,
|
|
121
|
+
FareBigInt: () => FareBigInt,
|
|
120
122
|
MemoType: () => MemoType,
|
|
121
123
|
PayloadType: () => PayloadType,
|
|
124
|
+
PositionDirection: () => PositionDirection,
|
|
122
125
|
baseAcpConfig: () => baseAcpConfig,
|
|
123
126
|
baseSepoliaAcpConfig: () => baseSepoliaAcpConfig,
|
|
124
127
|
default: () => index_default,
|
|
@@ -1914,6 +1917,23 @@ var import_infra = require("@account-kit/infra");
|
|
|
1914
1917
|
|
|
1915
1918
|
// src/acpFare.ts
|
|
1916
1919
|
var import_viem = require("viem");
|
|
1920
|
+
|
|
1921
|
+
// src/acpError.ts
|
|
1922
|
+
var AcpError = class _AcpError extends Error {
|
|
1923
|
+
constructor(message, originalError) {
|
|
1924
|
+
super();
|
|
1925
|
+
this.message = message;
|
|
1926
|
+
this.name = "AcpError";
|
|
1927
|
+
if (originalError && typeof originalError === "object" && "stack" in originalError) {
|
|
1928
|
+
this.stack += `
|
|
1929
|
+
Caused by: ${originalError.stack}`;
|
|
1930
|
+
}
|
|
1931
|
+
Object.setPrototypeOf(this, _AcpError.prototype);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
var acpError_default = AcpError;
|
|
1935
|
+
|
|
1936
|
+
// src/acpFare.ts
|
|
1917
1937
|
var Fare = class {
|
|
1918
1938
|
constructor(contractAddress, decimals) {
|
|
1919
1939
|
this.contractAddress = contractAddress;
|
|
@@ -1924,18 +1944,37 @@ var Fare = class {
|
|
|
1924
1944
|
}
|
|
1925
1945
|
};
|
|
1926
1946
|
var FareAmount = class _FareAmount {
|
|
1947
|
+
constructor(fareAmount, fare) {
|
|
1948
|
+
this.amount = fare.formatAmount(
|
|
1949
|
+
this.truncateTo6Decimals(fareAmount.toString())
|
|
1950
|
+
);
|
|
1951
|
+
this.fare = fare;
|
|
1952
|
+
}
|
|
1953
|
+
truncateTo6Decimals(input) {
|
|
1954
|
+
const [intPart, decPart = ""] = input.split(".");
|
|
1955
|
+
if (decPart === "") {
|
|
1956
|
+
return parseFloat(intPart);
|
|
1957
|
+
}
|
|
1958
|
+
const truncated = decPart.slice(0, 6).padEnd(6, "0");
|
|
1959
|
+
return parseFloat(`${intPart}.${truncated}`);
|
|
1960
|
+
}
|
|
1961
|
+
add(other) {
|
|
1962
|
+
if (this.fare.contractAddress !== other.fare.contractAddress) {
|
|
1963
|
+
throw new acpError_default("Token addresses do not match");
|
|
1964
|
+
}
|
|
1965
|
+
return new _FareAmount(Number(this.amount + other.amount), this.fare);
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
var FareBigInt = class _FareBigInt {
|
|
1927
1969
|
constructor(amount, fare) {
|
|
1928
1970
|
this.amount = amount;
|
|
1929
1971
|
this.fare = fare;
|
|
1930
1972
|
}
|
|
1931
|
-
format() {
|
|
1932
|
-
return this.fare.formatAmount(this.amount);
|
|
1933
|
-
}
|
|
1934
1973
|
add(other) {
|
|
1935
1974
|
if (this.fare.contractAddress !== other.fare.contractAddress) {
|
|
1936
|
-
throw new
|
|
1975
|
+
throw new acpError_default("Token addresses do not match");
|
|
1937
1976
|
}
|
|
1938
|
-
return new
|
|
1977
|
+
return new _FareBigInt(this.amount + other.amount, this.fare);
|
|
1939
1978
|
}
|
|
1940
1979
|
};
|
|
1941
1980
|
var wethFare = new Fare("0x4200000000000000000000000000000000000006", 18);
|
|
@@ -2192,7 +2231,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2192
2231
|
}
|
|
2193
2232
|
get sessionKeyClient() {
|
|
2194
2233
|
if (!this._sessionKeyClient) {
|
|
2195
|
-
throw new
|
|
2234
|
+
throw new acpError_default("Session key client not initialized");
|
|
2196
2235
|
}
|
|
2197
2236
|
return this._sessionKeyClient;
|
|
2198
2237
|
}
|
|
@@ -2231,7 +2270,6 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2231
2270
|
});
|
|
2232
2271
|
return hash;
|
|
2233
2272
|
} catch (error) {
|
|
2234
|
-
console.debug("Failed to send user operation", error);
|
|
2235
2273
|
retries -= 1;
|
|
2236
2274
|
if (retries === 0) {
|
|
2237
2275
|
finalError = error;
|
|
@@ -2240,20 +2278,20 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2240
2278
|
yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
|
|
2241
2279
|
}
|
|
2242
2280
|
}
|
|
2243
|
-
throw new
|
|
2281
|
+
throw new acpError_default(`Failed to send user operation`, finalError);
|
|
2244
2282
|
});
|
|
2245
2283
|
}
|
|
2246
2284
|
getJobId(hash) {
|
|
2247
2285
|
return __async(this, null, function* () {
|
|
2248
2286
|
const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
|
|
2249
2287
|
if (!result) {
|
|
2250
|
-
throw new
|
|
2288
|
+
throw new acpError_default("Failed to get user operation receipt");
|
|
2251
2289
|
}
|
|
2252
2290
|
const contractLogs = result.logs.find(
|
|
2253
2291
|
(log) => log.address.toLowerCase() === this.contractAddress.toLowerCase()
|
|
2254
2292
|
);
|
|
2255
2293
|
if (!contractLogs) {
|
|
2256
|
-
throw new
|
|
2294
|
+
throw new acpError_default("Failed to get contract logs");
|
|
2257
2295
|
}
|
|
2258
2296
|
return (0, import_viem2.fromHex)(contractLogs.data, "number");
|
|
2259
2297
|
});
|
|
@@ -2274,8 +2312,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2274
2312
|
const jobId = yield this.getJobId(hash);
|
|
2275
2313
|
return { txHash: hash, jobId };
|
|
2276
2314
|
} catch (error) {
|
|
2277
|
-
|
|
2278
|
-
throw new Error("Failed to create job");
|
|
2315
|
+
throw new acpError_default("Failed to create job", error);
|
|
2279
2316
|
}
|
|
2280
2317
|
});
|
|
2281
2318
|
}
|
|
@@ -2289,51 +2326,33 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2289
2326
|
});
|
|
2290
2327
|
return yield this.handleSendUserOperation(data, paymentTokenAddress);
|
|
2291
2328
|
} catch (error) {
|
|
2292
|
-
|
|
2293
|
-
throw new Error("Failed to approve allowance");
|
|
2329
|
+
throw new acpError_default("Failed to approve allowance", error);
|
|
2294
2330
|
}
|
|
2295
2331
|
});
|
|
2296
2332
|
}
|
|
2297
2333
|
createPayableMemo(_0, _1, _2, _3, _4, _5, _6, _7, _8) {
|
|
2298
2334
|
return __async(this, arguments, function* (jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress) {
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
uo: {
|
|
2320
|
-
target: this.contractAddress,
|
|
2321
|
-
data
|
|
2322
|
-
}
|
|
2323
|
-
});
|
|
2324
|
-
yield this.sessionKeyClient.waitForUserOperationTransaction({
|
|
2325
|
-
hash
|
|
2326
|
-
});
|
|
2327
|
-
return hash;
|
|
2328
|
-
} catch (error) {
|
|
2329
|
-
console.error(
|
|
2330
|
-
`failed to create payable memo ${jobId} ${content} ${error}`
|
|
2331
|
-
);
|
|
2332
|
-
retries -= 1;
|
|
2333
|
-
yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
|
|
2334
|
-
}
|
|
2335
|
+
try {
|
|
2336
|
+
const data = (0, import_viem2.encodeFunctionData)({
|
|
2337
|
+
abi: acpAbi_default,
|
|
2338
|
+
functionName: "createPayableMemo",
|
|
2339
|
+
args: [
|
|
2340
|
+
jobId,
|
|
2341
|
+
content,
|
|
2342
|
+
token,
|
|
2343
|
+
amountBaseUnit,
|
|
2344
|
+
recipient,
|
|
2345
|
+
feeAmountBaseUnit,
|
|
2346
|
+
feeType,
|
|
2347
|
+
type,
|
|
2348
|
+
nextPhase,
|
|
2349
|
+
Math.floor(expiredAt.getTime() / 1e3)
|
|
2350
|
+
]
|
|
2351
|
+
});
|
|
2352
|
+
return yield this.handleSendUserOperation(data);
|
|
2353
|
+
} catch (error) {
|
|
2354
|
+
throw new acpError_default("Failed to create payable memo", error);
|
|
2335
2355
|
}
|
|
2336
|
-
throw new Error("Failed to create payable memo");
|
|
2337
2356
|
});
|
|
2338
2357
|
}
|
|
2339
2358
|
createMemo(jobId, content, type, isSecured, nextPhase) {
|
|
@@ -2346,8 +2365,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2346
2365
|
});
|
|
2347
2366
|
return yield this.handleSendUserOperation(data);
|
|
2348
2367
|
} catch (error) {
|
|
2349
|
-
|
|
2350
|
-
throw new Error("Failed to create memo");
|
|
2368
|
+
throw new acpError_default("Failed to create memo", error);
|
|
2351
2369
|
}
|
|
2352
2370
|
});
|
|
2353
2371
|
}
|
|
@@ -2355,13 +2373,13 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2355
2373
|
return __async(this, null, function* () {
|
|
2356
2374
|
const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
|
|
2357
2375
|
if (!result) {
|
|
2358
|
-
throw new
|
|
2376
|
+
throw new acpError_default("Failed to get user operation receipt");
|
|
2359
2377
|
}
|
|
2360
2378
|
const contractLogs = result.logs.find(
|
|
2361
2379
|
(log) => log.address.toLowerCase() === this.contractAddress.toLowerCase()
|
|
2362
2380
|
);
|
|
2363
2381
|
if (!contractLogs) {
|
|
2364
|
-
throw new
|
|
2382
|
+
throw new acpError_default("Failed to get contract logs");
|
|
2365
2383
|
}
|
|
2366
2384
|
const decoded = (0, import_viem2.decodeEventLog)({
|
|
2367
2385
|
abi: acpAbi_default,
|
|
@@ -2369,7 +2387,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2369
2387
|
topics: contractLogs.topics
|
|
2370
2388
|
});
|
|
2371
2389
|
if (!decoded.args) {
|
|
2372
|
-
throw new
|
|
2390
|
+
throw new acpError_default("Failed to decode event logs");
|
|
2373
2391
|
}
|
|
2374
2392
|
return parseInt(decoded.args.memoId);
|
|
2375
2393
|
});
|
|
@@ -2384,8 +2402,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2384
2402
|
});
|
|
2385
2403
|
return yield this.handleSendUserOperation(data);
|
|
2386
2404
|
} catch (error) {
|
|
2387
|
-
|
|
2388
|
-
throw new Error("Failed to sign memo");
|
|
2405
|
+
throw new acpError_default("Failed to sign memo", error);
|
|
2389
2406
|
}
|
|
2390
2407
|
});
|
|
2391
2408
|
}
|
|
@@ -2399,8 +2416,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2399
2416
|
});
|
|
2400
2417
|
return yield this.handleSendUserOperation(data);
|
|
2401
2418
|
} catch (error) {
|
|
2402
|
-
|
|
2403
|
-
throw new Error("Failed to set budget");
|
|
2419
|
+
throw new acpError_default("Failed to set budget", error);
|
|
2404
2420
|
}
|
|
2405
2421
|
});
|
|
2406
2422
|
}
|
|
@@ -2414,8 +2430,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2414
2430
|
});
|
|
2415
2431
|
return yield this.handleSendUserOperation(data);
|
|
2416
2432
|
} catch (error) {
|
|
2417
|
-
|
|
2418
|
-
throw new Error("Failed to set budget");
|
|
2433
|
+
throw new acpError_default("Failed to set budget", error);
|
|
2419
2434
|
}
|
|
2420
2435
|
});
|
|
2421
2436
|
}
|
|
@@ -2432,8 +2447,7 @@ var AcpContractClient = class _AcpContractClient {
|
|
|
2432
2447
|
amountBaseUnit
|
|
2433
2448
|
);
|
|
2434
2449
|
} catch (error) {
|
|
2435
|
-
|
|
2436
|
-
throw new Error("Failed to wrap eth");
|
|
2450
|
+
throw new acpError_default("Failed to wrap eth", error);
|
|
2437
2451
|
}
|
|
2438
2452
|
});
|
|
2439
2453
|
}
|
|
@@ -2478,6 +2492,11 @@ var PayloadType = /* @__PURE__ */ ((PayloadType2) => {
|
|
|
2478
2492
|
PayloadType2["UNFULFILLED_POSITION"] = "unfulfilled_position";
|
|
2479
2493
|
return PayloadType2;
|
|
2480
2494
|
})(PayloadType || {});
|
|
2495
|
+
var PositionDirection = /* @__PURE__ */ ((PositionDirection2) => {
|
|
2496
|
+
PositionDirection2["LONG"] = "long";
|
|
2497
|
+
PositionDirection2["SHORT"] = "short";
|
|
2498
|
+
return PositionDirection2;
|
|
2499
|
+
})(PositionDirection || {});
|
|
2481
2500
|
|
|
2482
2501
|
// src/utils.ts
|
|
2483
2502
|
function tryParseJson(content) {
|
|
@@ -2553,7 +2572,7 @@ var AcpJob = class {
|
|
|
2553
2572
|
(m) => m.nextPhase === 2 /* TRANSACTION */
|
|
2554
2573
|
);
|
|
2555
2574
|
if (!memo) {
|
|
2556
|
-
throw new
|
|
2575
|
+
throw new acpError_default("No transaction memo found");
|
|
2557
2576
|
}
|
|
2558
2577
|
return yield this.acpClient.payJob(
|
|
2559
2578
|
this.id,
|
|
@@ -2567,7 +2586,7 @@ var AcpJob = class {
|
|
|
2567
2586
|
return __async(this, null, function* () {
|
|
2568
2587
|
var _a;
|
|
2569
2588
|
if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
|
|
2570
|
-
throw new
|
|
2589
|
+
throw new acpError_default("No negotiation memo found");
|
|
2571
2590
|
}
|
|
2572
2591
|
return yield this.acpClient.respondJob(
|
|
2573
2592
|
this.id,
|
|
@@ -2582,7 +2601,7 @@ var AcpJob = class {
|
|
|
2582
2601
|
return __async(this, null, function* () {
|
|
2583
2602
|
var _a;
|
|
2584
2603
|
if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
|
|
2585
|
-
throw new
|
|
2604
|
+
throw new acpError_default("No transaction memo found");
|
|
2586
2605
|
}
|
|
2587
2606
|
return yield this.acpClient.deliverJob(this.id, deliverable);
|
|
2588
2607
|
});
|
|
@@ -2591,7 +2610,7 @@ var AcpJob = class {
|
|
|
2591
2610
|
return __async(this, null, function* () {
|
|
2592
2611
|
var _a;
|
|
2593
2612
|
if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 4 /* COMPLETED */) {
|
|
2594
|
-
throw new
|
|
2613
|
+
throw new acpError_default("No evaluation memo found");
|
|
2595
2614
|
}
|
|
2596
2615
|
return yield this.acpClient.acpContractClient.signMemo(
|
|
2597
2616
|
this.latestMemo.id,
|
|
@@ -2603,7 +2622,7 @@ var AcpJob = class {
|
|
|
2603
2622
|
openPosition(_0, _1) {
|
|
2604
2623
|
return __async(this, arguments, function* (payload, feeAmount, expiredAt = new Date(Date.now() + 1e3 * 60 * 3), walletAddress) {
|
|
2605
2624
|
if (payload.length === 0) {
|
|
2606
|
-
throw new
|
|
2625
|
+
throw new acpError_default("No positions to open");
|
|
2607
2626
|
}
|
|
2608
2627
|
const sumAmount = payload.reduce((acc, curr) => acc + curr.amount, 0);
|
|
2609
2628
|
return yield this.acpClient.transferFunds(
|
|
@@ -2645,13 +2664,13 @@ var AcpJob = class {
|
|
|
2645
2664
|
return __async(this, null, function* () {
|
|
2646
2665
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2647
2666
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
2648
|
-
throw new
|
|
2667
|
+
throw new acpError_default("No swap token memo found");
|
|
2649
2668
|
}
|
|
2650
2669
|
const payload = tryParseJson(
|
|
2651
2670
|
memo.content
|
|
2652
2671
|
);
|
|
2653
2672
|
if ((payload == null ? void 0 : payload.type) !== "swap_token" /* SWAP_TOKEN */) {
|
|
2654
|
-
throw new
|
|
2673
|
+
throw new acpError_default("Invalid swap token memo");
|
|
2655
2674
|
}
|
|
2656
2675
|
return yield memo.sign(accept, reason);
|
|
2657
2676
|
});
|
|
@@ -2674,13 +2693,13 @@ var AcpJob = class {
|
|
|
2674
2693
|
return __async(this, null, function* () {
|
|
2675
2694
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2676
2695
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
2677
|
-
throw new
|
|
2696
|
+
throw new acpError_default("No open position memo found");
|
|
2678
2697
|
}
|
|
2679
2698
|
const payload = tryParseJson(
|
|
2680
2699
|
memo.content
|
|
2681
2700
|
);
|
|
2682
2701
|
if ((payload == null ? void 0 : payload.type) !== "open_position" /* OPEN_POSITION */) {
|
|
2683
|
-
throw new
|
|
2702
|
+
throw new acpError_default("Invalid open position memo");
|
|
2684
2703
|
}
|
|
2685
2704
|
return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
|
|
2686
2705
|
});
|
|
@@ -2706,13 +2725,13 @@ var AcpJob = class {
|
|
|
2706
2725
|
return __async(this, null, function* () {
|
|
2707
2726
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2708
2727
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 6 /* PAYABLE_REQUEST */) {
|
|
2709
|
-
throw new
|
|
2728
|
+
throw new acpError_default("No close position memo found");
|
|
2710
2729
|
}
|
|
2711
2730
|
const payload = tryParseJson(
|
|
2712
2731
|
memo.content
|
|
2713
2732
|
);
|
|
2714
2733
|
if ((payload == null ? void 0 : payload.type) !== "close_partial_position" /* CLOSE_PARTIAL_POSITION */) {
|
|
2715
|
-
throw new
|
|
2734
|
+
throw new acpError_default("Invalid close position memo");
|
|
2716
2735
|
}
|
|
2717
2736
|
return yield this.acpClient.responseFundsRequest(
|
|
2718
2737
|
memo.id,
|
|
@@ -2738,11 +2757,11 @@ var AcpJob = class {
|
|
|
2738
2757
|
return __async(this, arguments, function* (memoId, accept, payload, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
2739
2758
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2740
2759
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
|
|
2741
|
-
throw new
|
|
2760
|
+
throw new acpError_default("No message memo found");
|
|
2742
2761
|
}
|
|
2743
2762
|
const messagePayload = tryParseJson(memo.content);
|
|
2744
2763
|
if ((messagePayload == null ? void 0 : messagePayload.type) !== "close_position" /* CLOSE_POSITION */) {
|
|
2745
|
-
throw new
|
|
2764
|
+
throw new acpError_default("Invalid close position memo");
|
|
2746
2765
|
}
|
|
2747
2766
|
yield memo.sign(accept, reason);
|
|
2748
2767
|
if (accept) {
|
|
@@ -2766,13 +2785,13 @@ var AcpJob = class {
|
|
|
2766
2785
|
return __async(this, null, function* () {
|
|
2767
2786
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2768
2787
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
2769
|
-
throw new
|
|
2788
|
+
throw new acpError_default("No payable transfer memo found");
|
|
2770
2789
|
}
|
|
2771
2790
|
const payload = tryParseJson(
|
|
2772
2791
|
memo.content
|
|
2773
2792
|
);
|
|
2774
2793
|
if ((payload == null ? void 0 : payload.type) !== "close_position" /* CLOSE_POSITION */) {
|
|
2775
|
-
throw new
|
|
2794
|
+
throw new acpError_default("Invalid close position memo");
|
|
2776
2795
|
}
|
|
2777
2796
|
yield memo.sign(accept, reason);
|
|
2778
2797
|
});
|
|
@@ -2815,13 +2834,13 @@ var AcpJob = class {
|
|
|
2815
2834
|
return __async(this, null, function* () {
|
|
2816
2835
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2817
2836
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
2818
|
-
throw new
|
|
2837
|
+
throw new acpError_default("No unfulfilled position memo found");
|
|
2819
2838
|
}
|
|
2820
2839
|
const payload = tryParseJson(
|
|
2821
2840
|
memo.content
|
|
2822
2841
|
);
|
|
2823
2842
|
if ((payload == null ? void 0 : payload.type) !== "unfulfilled_position" /* UNFULFILLED_POSITION */) {
|
|
2824
|
-
throw new
|
|
2843
|
+
throw new acpError_default("Invalid unfulfilled position memo");
|
|
2825
2844
|
}
|
|
2826
2845
|
return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
|
|
2827
2846
|
});
|
|
@@ -2830,13 +2849,13 @@ var AcpJob = class {
|
|
|
2830
2849
|
return __async(this, null, function* () {
|
|
2831
2850
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2832
2851
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
|
|
2833
|
-
throw new
|
|
2852
|
+
throw new acpError_default("No position fulfilled memo found");
|
|
2834
2853
|
}
|
|
2835
2854
|
const payload = tryParseJson(
|
|
2836
2855
|
memo.content
|
|
2837
2856
|
);
|
|
2838
2857
|
if ((payload == null ? void 0 : payload.type) !== "position_fulfilled" /* POSITION_FULFILLED */) {
|
|
2839
|
-
throw new
|
|
2858
|
+
throw new acpError_default("Invalid position fulfilled memo");
|
|
2840
2859
|
}
|
|
2841
2860
|
return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
|
|
2842
2861
|
});
|
|
@@ -2859,13 +2878,13 @@ var AcpJob = class {
|
|
|
2859
2878
|
return __async(this, arguments, function* (memoId, accept, fulfilledPositions, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
2860
2879
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2861
2880
|
if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
|
|
2862
|
-
throw new
|
|
2881
|
+
throw new acpError_default("No message memo found");
|
|
2863
2882
|
}
|
|
2864
2883
|
const payload = tryParseJson(
|
|
2865
2884
|
memo.content
|
|
2866
2885
|
);
|
|
2867
2886
|
if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
|
|
2868
|
-
throw new
|
|
2887
|
+
throw new acpError_default("Invalid close job and withdraw memo");
|
|
2869
2888
|
}
|
|
2870
2889
|
yield memo.sign(accept, reason);
|
|
2871
2890
|
if (!accept) {
|
|
@@ -2904,13 +2923,13 @@ var AcpJob = class {
|
|
|
2904
2923
|
return __async(this, null, function* () {
|
|
2905
2924
|
const memo = this.memos.find((m) => m.id === memoId);
|
|
2906
2925
|
if (!memo) {
|
|
2907
|
-
throw new
|
|
2926
|
+
throw new acpError_default("Memo not found");
|
|
2908
2927
|
}
|
|
2909
2928
|
const payload = tryParseJson(
|
|
2910
2929
|
memo.content
|
|
2911
2930
|
);
|
|
2912
2931
|
if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
|
|
2913
|
-
throw new
|
|
2932
|
+
throw new acpError_default("Invalid close job and withdraw memo");
|
|
2914
2933
|
}
|
|
2915
2934
|
yield memo.sign(accept, reason);
|
|
2916
2935
|
});
|
|
@@ -2983,7 +3002,7 @@ var AcpJobOffering = class {
|
|
|
2983
3002
|
const validator = this.ajv.compile(this.requirementSchema);
|
|
2984
3003
|
const valid = validator(serviceRequirement);
|
|
2985
3004
|
if (!valid) {
|
|
2986
|
-
throw new
|
|
3005
|
+
throw new acpError_default(this.ajv.errorsText(validator.errors));
|
|
2987
3006
|
}
|
|
2988
3007
|
}
|
|
2989
3008
|
let finalServiceRequirement = {
|
|
@@ -3173,6 +3192,11 @@ var AcpClient = class {
|
|
|
3173
3192
|
}
|
|
3174
3193
|
initiateJob(_0, _1, _2, _3) {
|
|
3175
3194
|
return __async(this, arguments, function* (providerAddress, serviceRequirement, fareAmount, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
|
|
3195
|
+
if (providerAddress === this.acpContractClient.walletAddress) {
|
|
3196
|
+
throw new acpError_default(
|
|
3197
|
+
"Provider address cannot be the same as the client address"
|
|
3198
|
+
);
|
|
3199
|
+
}
|
|
3176
3200
|
const { jobId } = yield this.acpContractClient.createJob(
|
|
3177
3201
|
providerAddress,
|
|
3178
3202
|
evaluatorAddress || this.acpContractClient.walletAddress,
|
|
@@ -3180,7 +3204,7 @@ var AcpClient = class {
|
|
|
3180
3204
|
);
|
|
3181
3205
|
yield this.acpContractClient.setBudgetWithPaymentToken(
|
|
3182
3206
|
jobId,
|
|
3183
|
-
fareAmount.
|
|
3207
|
+
fareAmount.amount,
|
|
3184
3208
|
fareAmount.fare.contractAddress
|
|
3185
3209
|
);
|
|
3186
3210
|
yield this.acpContractClient.createMemo(
|
|
@@ -3228,9 +3252,9 @@ var AcpClient = class {
|
|
|
3228
3252
|
return yield this.acpContractClient.createPayableMemo(
|
|
3229
3253
|
jobId,
|
|
3230
3254
|
JSON.stringify(reason),
|
|
3231
|
-
transferFareAmount.
|
|
3255
|
+
transferFareAmount.amount,
|
|
3232
3256
|
recipient,
|
|
3233
|
-
feeFareAmount.
|
|
3257
|
+
feeFareAmount.amount,
|
|
3234
3258
|
feeType,
|
|
3235
3259
|
nextPhase,
|
|
3236
3260
|
6 /* PAYABLE_REQUEST */,
|
|
@@ -3252,30 +3276,30 @@ var AcpClient = class {
|
|
|
3252
3276
|
transferFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
|
|
3253
3277
|
return __async(this, null, function* () {
|
|
3254
3278
|
if (transferFareAmount.fare.contractAddress === ethFare.contractAddress) {
|
|
3255
|
-
yield this.acpContractClient.wrapEth(transferFareAmount.
|
|
3256
|
-
transferFareAmount = new
|
|
3279
|
+
yield this.acpContractClient.wrapEth(transferFareAmount.amount);
|
|
3280
|
+
transferFareAmount = new FareBigInt(transferFareAmount.amount, wethFare);
|
|
3257
3281
|
}
|
|
3258
3282
|
if (feeFareAmount.amount > 0 && feeFareAmount.fare.contractAddress !== this.acpContractClient.config.baseFare.contractAddress) {
|
|
3259
|
-
throw new
|
|
3283
|
+
throw new acpError_default("Fee token address is not the same as the base fare");
|
|
3260
3284
|
}
|
|
3261
3285
|
const isFeeTokenDifferent = feeFareAmount.fare.contractAddress !== transferFareAmount.fare.contractAddress;
|
|
3262
3286
|
if (isFeeTokenDifferent) {
|
|
3263
3287
|
yield this.acpContractClient.approveAllowance(
|
|
3264
|
-
feeFareAmount.
|
|
3288
|
+
feeFareAmount.amount,
|
|
3265
3289
|
feeFareAmount.fare.contractAddress
|
|
3266
3290
|
);
|
|
3267
3291
|
}
|
|
3268
3292
|
const finalAmount = isFeeTokenDifferent ? transferFareAmount : transferFareAmount.add(feeFareAmount);
|
|
3269
3293
|
yield this.acpContractClient.approveAllowance(
|
|
3270
|
-
finalAmount.
|
|
3294
|
+
finalAmount.amount,
|
|
3271
3295
|
transferFareAmount.fare.contractAddress
|
|
3272
3296
|
);
|
|
3273
3297
|
return yield this.acpContractClient.createPayableMemo(
|
|
3274
3298
|
jobId,
|
|
3275
3299
|
JSON.stringify(reason),
|
|
3276
|
-
transferFareAmount.
|
|
3300
|
+
transferFareAmount.amount,
|
|
3277
3301
|
recipient,
|
|
3278
|
-
feeFareAmount.
|
|
3302
|
+
feeFareAmount.amount,
|
|
3279
3303
|
feeType,
|
|
3280
3304
|
nextPhase,
|
|
3281
3305
|
8 /* PAYABLE_TRANSFER_ESCROW */,
|
|
@@ -3322,7 +3346,7 @@ var AcpClient = class {
|
|
|
3322
3346
|
});
|
|
3323
3347
|
const data = yield response.json();
|
|
3324
3348
|
if (data.error) {
|
|
3325
|
-
throw new
|
|
3349
|
+
throw new acpError_default(data.error.message);
|
|
3326
3350
|
}
|
|
3327
3351
|
return data.data.map((job) => {
|
|
3328
3352
|
return new acpJob_default(
|
|
@@ -3351,7 +3375,7 @@ var AcpClient = class {
|
|
|
3351
3375
|
);
|
|
3352
3376
|
});
|
|
3353
3377
|
} catch (error) {
|
|
3354
|
-
throw error;
|
|
3378
|
+
throw new acpError_default("Failed to get active jobs", error);
|
|
3355
3379
|
}
|
|
3356
3380
|
});
|
|
3357
3381
|
}
|
|
@@ -3366,7 +3390,7 @@ var AcpClient = class {
|
|
|
3366
3390
|
});
|
|
3367
3391
|
const data = yield response.json();
|
|
3368
3392
|
if (data.error) {
|
|
3369
|
-
throw new
|
|
3393
|
+
throw new acpError_default(data.error.message);
|
|
3370
3394
|
}
|
|
3371
3395
|
return data.data.map((job) => {
|
|
3372
3396
|
return new acpJob_default(
|
|
@@ -3395,7 +3419,7 @@ var AcpClient = class {
|
|
|
3395
3419
|
);
|
|
3396
3420
|
});
|
|
3397
3421
|
} catch (error) {
|
|
3398
|
-
throw error;
|
|
3422
|
+
throw new acpError_default("Failed to get completed jobs", error);
|
|
3399
3423
|
}
|
|
3400
3424
|
});
|
|
3401
3425
|
}
|
|
@@ -3410,7 +3434,7 @@ var AcpClient = class {
|
|
|
3410
3434
|
});
|
|
3411
3435
|
const data = yield response.json();
|
|
3412
3436
|
if (data.error) {
|
|
3413
|
-
throw new
|
|
3437
|
+
throw new acpError_default(data.error.message);
|
|
3414
3438
|
}
|
|
3415
3439
|
return data.data.map((job) => {
|
|
3416
3440
|
return new acpJob_default(
|
|
@@ -3439,7 +3463,7 @@ var AcpClient = class {
|
|
|
3439
3463
|
);
|
|
3440
3464
|
});
|
|
3441
3465
|
} catch (error) {
|
|
3442
|
-
throw error;
|
|
3466
|
+
throw new acpError_default("Failed to get cancelled jobs", error);
|
|
3443
3467
|
}
|
|
3444
3468
|
});
|
|
3445
3469
|
}
|
|
@@ -3454,7 +3478,7 @@ var AcpClient = class {
|
|
|
3454
3478
|
});
|
|
3455
3479
|
const data = yield response.json();
|
|
3456
3480
|
if (data.error) {
|
|
3457
|
-
throw new
|
|
3481
|
+
throw new acpError_default(data.error.message);
|
|
3458
3482
|
}
|
|
3459
3483
|
const job = data.data;
|
|
3460
3484
|
if (!job) {
|
|
@@ -3485,7 +3509,7 @@ var AcpClient = class {
|
|
|
3485
3509
|
job.context
|
|
3486
3510
|
);
|
|
3487
3511
|
} catch (error) {
|
|
3488
|
-
throw error;
|
|
3512
|
+
throw new acpError_default("Failed to get job by id", error);
|
|
3489
3513
|
}
|
|
3490
3514
|
});
|
|
3491
3515
|
}
|
|
@@ -3500,7 +3524,7 @@ var AcpClient = class {
|
|
|
3500
3524
|
});
|
|
3501
3525
|
const data = yield response.json();
|
|
3502
3526
|
if (data.error) {
|
|
3503
|
-
throw new
|
|
3527
|
+
throw new acpError_default(data.error.message);
|
|
3504
3528
|
}
|
|
3505
3529
|
const memo = data.data;
|
|
3506
3530
|
if (!memo) {
|
|
@@ -3518,7 +3542,7 @@ var AcpClient = class {
|
|
|
3518
3542
|
memo.payableDetails
|
|
3519
3543
|
);
|
|
3520
3544
|
} catch (error) {
|
|
3521
|
-
throw error;
|
|
3545
|
+
throw new acpError_default("Failed to get memo by id", error);
|
|
3522
3546
|
}
|
|
3523
3547
|
});
|
|
3524
3548
|
}
|
|
@@ -3545,6 +3569,7 @@ var index_default = acpClient_default;
|
|
|
3545
3569
|
AcpAgentSort,
|
|
3546
3570
|
AcpContractClient,
|
|
3547
3571
|
AcpContractConfig,
|
|
3572
|
+
AcpError,
|
|
3548
3573
|
AcpGraduationStatus,
|
|
3549
3574
|
AcpJob,
|
|
3550
3575
|
AcpJobPhases,
|
|
@@ -3553,8 +3578,10 @@ var index_default = acpClient_default;
|
|
|
3553
3578
|
AcpOnlineStatus,
|
|
3554
3579
|
Fare,
|
|
3555
3580
|
FareAmount,
|
|
3581
|
+
FareBigInt,
|
|
3556
3582
|
MemoType,
|
|
3557
3583
|
PayloadType,
|
|
3584
|
+
PositionDirection,
|
|
3558
3585
|
baseAcpConfig,
|
|
3559
3586
|
baseSepoliaAcpConfig,
|
|
3560
3587
|
ethFare,
|