@virtuals-protocol/acp-node 0.3.0-beta.3 → 0.3.0-beta.5

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.js CHANGED
@@ -55,7 +55,7 @@ var require_package = __commonJS({
55
55
  "package.json"(exports2, module2) {
56
56
  module2.exports = {
57
57
  name: "@virtuals-protocol/acp-node",
58
- version: "0.3.0-beta.3",
58
+ version: "0.3.0-beta.5",
59
59
  main: "./dist/index.js",
60
60
  module: "./dist/index.mjs",
61
61
  types: "./dist/index.d.ts",
@@ -70,9 +70,9 @@ var require_package = __commonJS({
70
70
  typescript: "^5.8.3"
71
71
  },
72
72
  dependencies: {
73
- "@aa-sdk/core": "^4.30.0",
74
- "@account-kit/infra": "^4.30.0",
75
- "@account-kit/smart-contracts": "^4.30.0",
73
+ "@aa-sdk/core": "^4.73.0",
74
+ "@account-kit/infra": "^4.73.0",
75
+ "@account-kit/smart-contracts": "^4.73.0",
76
76
  ajv: "^8.17.1",
77
77
  "socket.io-client": "^4.8.1",
78
78
  tsup: "^8.5.0",
@@ -1892,6 +1892,7 @@ var ACP_ABI = [
1892
1892
  var acpAbi_default = ACP_ABI;
1893
1893
 
1894
1894
  // src/acpClient.ts
1895
+ var import_viem4 = require("viem");
1895
1896
  var import_socket = require("socket.io-client");
1896
1897
 
1897
1898
  // src/contractClients/baseAcpContractClient.ts
@@ -3062,171 +3063,160 @@ var BaseAcpContractClient = class {
3062
3063
  return this.agentWalletAddress;
3063
3064
  }
3064
3065
  createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
3065
- return __async(this, null, function* () {
3066
- try {
3067
- const data = (0, import_viem2.encodeFunctionData)({
3068
- abi: this.abi,
3069
- functionName: "createJobWithAccount",
3070
- args: [
3071
- accountId,
3072
- evaluatorAddress,
3073
- budgetBaseUnit,
3074
- paymentTokenAddress,
3075
- Math.floor(expiredAt.getTime() / 1e3)
3076
- ]
3077
- });
3078
- const hash = yield this.handleOperation(data, this.contractAddress);
3079
- const jobId = yield this.getJobId(
3080
- hash,
3081
- this.agentWalletAddress,
3082
- providerAddress
3083
- );
3084
- return { txHash: hash, jobId };
3085
- } catch (error) {
3086
- throw new acpError_default("Failed to create job with account", error);
3087
- }
3088
- });
3066
+ try {
3067
+ const data = (0, import_viem2.encodeFunctionData)({
3068
+ abi: this.abi,
3069
+ functionName: "createJobWithAccount",
3070
+ args: [
3071
+ accountId,
3072
+ evaluatorAddress,
3073
+ budgetBaseUnit,
3074
+ paymentTokenAddress,
3075
+ Math.floor(expiredAt.getTime() / 1e3)
3076
+ ]
3077
+ });
3078
+ const payload = {
3079
+ data,
3080
+ contractAddress: this.contractAddress
3081
+ };
3082
+ return payload;
3083
+ } catch (error) {
3084
+ throw new acpError_default("Failed to create job with account", error);
3085
+ }
3089
3086
  }
3090
3087
  createJob(providerAddress, evaluatorAddress, expiredAt, paymentTokenAddress, budgetBaseUnit, metadata) {
3091
- return __async(this, null, function* () {
3092
- try {
3093
- const data = (0, import_viem2.encodeFunctionData)({
3094
- abi: this.abi,
3095
- functionName: "createJob",
3096
- args: [
3097
- providerAddress,
3098
- evaluatorAddress,
3099
- Math.floor(expiredAt.getTime() / 1e3),
3100
- paymentTokenAddress,
3101
- budgetBaseUnit,
3102
- metadata
3103
- ]
3104
- });
3105
- const hash = yield this.handleOperation(data, this.contractAddress);
3106
- const jobId = yield this.getJobId(
3107
- hash,
3108
- this.agentWalletAddress,
3109
- providerAddress
3110
- );
3111
- return { txHash: hash, jobId };
3112
- } catch (error) {
3113
- throw new acpError_default("Failed to create job", error);
3114
- }
3115
- });
3088
+ try {
3089
+ const data = (0, import_viem2.encodeFunctionData)({
3090
+ abi: this.abi,
3091
+ functionName: "createJob",
3092
+ args: [
3093
+ providerAddress,
3094
+ evaluatorAddress,
3095
+ Math.floor(expiredAt.getTime() / 1e3),
3096
+ paymentTokenAddress,
3097
+ budgetBaseUnit,
3098
+ metadata
3099
+ ]
3100
+ });
3101
+ const payload = {
3102
+ data,
3103
+ contractAddress: this.contractAddress
3104
+ };
3105
+ return payload;
3106
+ } catch (error) {
3107
+ throw new acpError_default("Failed to create job", error);
3108
+ }
3116
3109
  }
3117
- approveAllowance(_0) {
3118
- return __async(this, arguments, function* (amountBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3119
- try {
3120
- const data = (0, import_viem2.encodeFunctionData)({
3121
- abi: import_viem2.erc20Abi,
3122
- functionName: "approve",
3123
- args: [this.contractAddress, amountBaseUnit]
3124
- });
3125
- return yield this.handleOperation(data, paymentTokenAddress);
3126
- } catch (error) {
3127
- throw new acpError_default("Failed to approve allowance", error);
3128
- }
3129
- });
3110
+ approveAllowance(amountBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3111
+ try {
3112
+ const data = (0, import_viem2.encodeFunctionData)({
3113
+ abi: import_viem2.erc20Abi,
3114
+ functionName: "approve",
3115
+ args: [this.contractAddress, amountBaseUnit]
3116
+ });
3117
+ const payload = {
3118
+ data,
3119
+ contractAddress: paymentTokenAddress
3120
+ };
3121
+ return payload;
3122
+ } catch (error) {
3123
+ throw new acpError_default("Failed to approve allowance", error);
3124
+ }
3130
3125
  }
3131
- createPayableMemo(_0, _1, _2, _3, _4, _5, _6, _7, _8) {
3132
- return __async(this, arguments, function* (jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
3133
- try {
3134
- const data = (0, import_viem2.encodeFunctionData)({
3135
- abi: this.abi,
3136
- functionName: "createPayableMemo",
3137
- args: [
3138
- jobId,
3139
- content,
3140
- token,
3141
- amountBaseUnit,
3142
- recipient,
3143
- feeAmountBaseUnit,
3144
- feeType,
3145
- type,
3146
- Math.floor(expiredAt.getTime() / 1e3),
3147
- secured,
3148
- nextPhase
3149
- ]
3150
- });
3151
- return yield this.handleOperation(data, this.contractAddress);
3152
- } catch (error) {
3153
- throw new acpError_default("Failed to create payable memo", error);
3154
- }
3155
- });
3126
+ createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
3127
+ try {
3128
+ const data = (0, import_viem2.encodeFunctionData)({
3129
+ abi: this.abi,
3130
+ functionName: "createPayableMemo",
3131
+ args: [
3132
+ jobId,
3133
+ content,
3134
+ token,
3135
+ amountBaseUnit,
3136
+ recipient,
3137
+ feeAmountBaseUnit,
3138
+ feeType,
3139
+ type,
3140
+ Math.floor(expiredAt.getTime() / 1e3),
3141
+ secured,
3142
+ nextPhase
3143
+ ]
3144
+ });
3145
+ const payload = {
3146
+ data,
3147
+ contractAddress: this.contractAddress
3148
+ };
3149
+ return payload;
3150
+ } catch (error) {
3151
+ throw new acpError_default("Failed to create payable memo", error);
3152
+ }
3156
3153
  }
3157
3154
  createMemo(jobId, content, type, isSecured, nextPhase) {
3158
- return __async(this, null, function* () {
3159
- try {
3160
- const data = (0, import_viem2.encodeFunctionData)({
3161
- abi: this.abi,
3162
- functionName: "createMemo",
3163
- args: [jobId, content, type, isSecured, nextPhase]
3164
- });
3165
- return yield this.handleOperation(data, this.contractAddress);
3166
- } catch (error) {
3167
- throw new acpError_default("Failed to create memo", error);
3168
- }
3169
- });
3155
+ try {
3156
+ const data = (0, import_viem2.encodeFunctionData)({
3157
+ abi: this.abi,
3158
+ functionName: "createMemo",
3159
+ args: [jobId, content, type, isSecured, nextPhase]
3160
+ });
3161
+ const payload = {
3162
+ data,
3163
+ contractAddress: this.contractAddress
3164
+ };
3165
+ return payload;
3166
+ } catch (error) {
3167
+ throw new acpError_default("Failed to create memo", error);
3168
+ }
3170
3169
  }
3171
3170
  signMemo(memoId, isApproved, reason) {
3172
- return __async(this, null, function* () {
3173
- try {
3174
- const data = (0, import_viem2.encodeFunctionData)({
3175
- abi: this.abi,
3176
- functionName: "signMemo",
3177
- args: [memoId, isApproved, reason]
3178
- });
3179
- const hash = yield this.handleOperation(data, this.contractAddress);
3180
- return hash;
3181
- } catch (error) {
3182
- throw new acpError_default("Failed to sign memo", error);
3183
- }
3184
- });
3171
+ try {
3172
+ const data = (0, import_viem2.encodeFunctionData)({
3173
+ abi: this.abi,
3174
+ functionName: "signMemo",
3175
+ args: [memoId, isApproved, reason]
3176
+ });
3177
+ const payload = {
3178
+ data,
3179
+ contractAddress: this.contractAddress
3180
+ };
3181
+ return payload;
3182
+ } catch (error) {
3183
+ throw new acpError_default("Failed to sign memo", error);
3184
+ }
3185
3185
  }
3186
- setBudgetWithPaymentToken(_0, _1) {
3187
- return __async(this, arguments, function* (jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3188
- try {
3189
- const data = (0, import_viem2.encodeFunctionData)({
3190
- abi: this.abi,
3191
- functionName: "setBudgetWithPaymentToken",
3192
- args: [jobId, budgetBaseUnit, paymentTokenAddress]
3193
- });
3194
- return yield this.handleOperation(data, this.contractAddress);
3195
- } catch (error) {
3196
- throw new acpError_default("Failed to set budget", error);
3197
- }
3198
- });
3186
+ setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3187
+ return void 0;
3199
3188
  }
3200
3189
  updateAccountMetadata(accountId, metadata) {
3201
- return __async(this, null, function* () {
3202
- try {
3203
- const data = (0, import_viem2.encodeFunctionData)({
3204
- abi: this.abi,
3205
- functionName: "updateAccountMetadata",
3206
- args: [accountId, metadata]
3207
- });
3208
- return yield this.handleOperation(data, this.contractAddress);
3209
- } catch (error) {
3210
- throw new acpError_default("Failed to update account metadata", error);
3211
- }
3212
- });
3190
+ try {
3191
+ const data = (0, import_viem2.encodeFunctionData)({
3192
+ abi: this.abi,
3193
+ functionName: "updateAccountMetadata",
3194
+ args: [accountId, metadata]
3195
+ });
3196
+ const payload = {
3197
+ data,
3198
+ contractAddress: this.contractAddress
3199
+ };
3200
+ return payload;
3201
+ } catch (error) {
3202
+ throw new acpError_default("Failed to update account metadata", error);
3203
+ }
3213
3204
  }
3214
3205
  wrapEth(amountBaseUnit) {
3215
- return __async(this, null, function* () {
3216
- try {
3217
- const data = (0, import_viem2.encodeFunctionData)({
3218
- abi: wethAbi_default,
3219
- functionName: "deposit"
3220
- });
3221
- return yield this.handleOperation(
3222
- data,
3223
- wethFare.contractAddress,
3224
- amountBaseUnit
3225
- );
3226
- } catch (error) {
3227
- throw new acpError_default("Failed to wrap eth", error);
3228
- }
3229
- });
3206
+ try {
3207
+ const data = (0, import_viem2.encodeFunctionData)({
3208
+ abi: wethAbi_default,
3209
+ functionName: "deposit"
3210
+ });
3211
+ const payload = {
3212
+ data,
3213
+ contractAddress: wethFare.contractAddress,
3214
+ value: amountBaseUnit
3215
+ };
3216
+ return payload;
3217
+ } catch (error) {
3218
+ throw new acpError_default("Failed to wrap eth", error);
3219
+ }
3230
3220
  }
3231
3221
  };
3232
3222
  var baseAcpContractClient_default = BaseAcpContractClient;
@@ -3340,9 +3330,7 @@ var AcpJob = class {
3340
3330
  if (requestMemo) {
3341
3331
  return requestMemo.signedReason;
3342
3332
  }
3343
- return (_a = this.memos.find(
3344
- (m) => m.nextPhase === 5 /* REJECTED */
3345
- )) == null ? void 0 : _a.content;
3333
+ return (_a = this.memos.find((m) => m.nextPhase === 5 /* REJECTED */)) == null ? void 0 : _a.content;
3346
3334
  }
3347
3335
  get providerAgent() {
3348
3336
  return this.acpClient.getAgent(this.providerAddress);
@@ -3361,36 +3349,46 @@ var AcpJob = class {
3361
3349
  }
3362
3350
  createRequirement(content) {
3363
3351
  return __async(this, null, function* () {
3364
- return yield this.acpContractClient.createMemo(
3365
- this.id,
3366
- content,
3367
- 0 /* MESSAGE */,
3368
- true,
3369
- 2 /* TRANSACTION */
3352
+ const operations = [];
3353
+ operations.push(
3354
+ this.acpContractClient.createMemo(
3355
+ this.id,
3356
+ content,
3357
+ 0 /* MESSAGE */,
3358
+ true,
3359
+ 2 /* TRANSACTION */
3360
+ )
3370
3361
  );
3362
+ return yield this.acpContractClient.handleOperation(operations);
3371
3363
  });
3372
3364
  }
3373
3365
  createPayableRequirement(_0, _1, _2, _3) {
3374
3366
  return __async(this, arguments, function* (content, type, amount, recipient, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3367
+ const operations = [];
3375
3368
  if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
3376
- yield this.acpContractClient.approveAllowance(
3377
- amount.amount,
3378
- amount.fare.contractAddress
3369
+ operations.push(
3370
+ this.acpContractClient.approveAllowance(
3371
+ amount.amount,
3372
+ amount.fare.contractAddress
3373
+ )
3379
3374
  );
3380
3375
  }
3381
3376
  const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3382
- return yield this.acpContractClient.createPayableMemo(
3383
- this.id,
3384
- content,
3385
- amount.amount,
3386
- recipient,
3387
- feeAmount.amount,
3388
- 0 /* NO_FEE */,
3389
- 2 /* TRANSACTION */,
3390
- type,
3391
- expiredAt,
3392
- amount.fare.contractAddress
3377
+ operations.push(
3378
+ this.acpContractClient.createPayableMemo(
3379
+ this.id,
3380
+ content,
3381
+ amount.amount,
3382
+ recipient,
3383
+ feeAmount.amount,
3384
+ 0 /* NO_FEE */,
3385
+ 2 /* TRANSACTION */,
3386
+ type,
3387
+ expiredAt,
3388
+ amount.fare.contractAddress
3389
+ )
3393
3390
  );
3391
+ return yield this.acpContractClient.handleOperation(operations);
3394
3392
  });
3395
3393
  }
3396
3394
  payAndAcceptRequirement(reason) {
@@ -3399,8 +3397,9 @@ var AcpJob = class {
3399
3397
  (m) => m.nextPhase === 2 /* TRANSACTION */
3400
3398
  );
3401
3399
  if (!memo) {
3402
- throw new acpError_default("No transaction memo found");
3400
+ throw new acpError_default("No notification memo found");
3403
3401
  }
3402
+ const operations = [];
3404
3403
  const baseFareAmount = new FareAmount(this.price, this.baseFare);
3405
3404
  const transferAmount = memo.payableDetails ? yield FareAmountBase.fromContractAddress(
3406
3405
  memo.payableDetails.amount,
@@ -3408,24 +3407,31 @@ var AcpJob = class {
3408
3407
  this.config
3409
3408
  ) : new FareAmount(0, this.baseFare);
3410
3409
  const totalAmount = baseFareAmount.fare.contractAddress === transferAmount.fare.contractAddress ? baseFareAmount.add(transferAmount) : baseFareAmount;
3411
- yield this.acpContractClient.approveAllowance(
3412
- totalAmount.amount,
3413
- this.baseFare.contractAddress
3410
+ operations.push(
3411
+ this.acpContractClient.approveAllowance(
3412
+ totalAmount.amount,
3413
+ this.baseFare.contractAddress
3414
+ )
3414
3415
  );
3415
3416
  if (baseFareAmount.fare.contractAddress !== transferAmount.fare.contractAddress) {
3416
- yield this.acpContractClient.approveAllowance(
3417
- transferAmount.amount,
3418
- transferAmount.fare.contractAddress
3417
+ operations.push(
3418
+ this.acpContractClient.approveAllowance(
3419
+ transferAmount.amount,
3420
+ transferAmount.fare.contractAddress
3421
+ )
3419
3422
  );
3420
3423
  }
3421
- yield memo.sign(true, reason);
3422
- return yield this.acpContractClient.createMemo(
3423
- this.id,
3424
- `Payment made. ${reason != null ? reason : ""}`.trim(),
3425
- 0 /* MESSAGE */,
3426
- true,
3427
- 3 /* EVALUATION */
3424
+ operations.push(this.acpContractClient.signMemo(memo.id, true, reason));
3425
+ operations.push(
3426
+ this.acpContractClient.createMemo(
3427
+ this.id,
3428
+ `Payment made. ${reason != null ? reason : ""}`.trim(),
3429
+ 0 /* MESSAGE */,
3430
+ true,
3431
+ 3 /* EVALUATION */
3432
+ )
3428
3433
  );
3434
+ return yield this.acpContractClient.handleOperation(operations);
3429
3435
  });
3430
3436
  }
3431
3437
  respond(accept, reason) {
@@ -3433,7 +3439,7 @@ var AcpJob = class {
3433
3439
  const memoContent = `${reason || `Job ${this.id} ${accept ? "accepted" : "rejected"}.`}`;
3434
3440
  if (accept) {
3435
3441
  yield this.accept(memoContent);
3436
- return this.createRequirement(memoContent);
3442
+ return yield this.createRequirement(memoContent);
3437
3443
  }
3438
3444
  return yield this.reject(memoContent);
3439
3445
  });
@@ -3442,31 +3448,42 @@ var AcpJob = class {
3442
3448
  return __async(this, null, function* () {
3443
3449
  var _a;
3444
3450
  const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
3451
+ const operations = [];
3445
3452
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3446
- throw new acpError_default("No negotiation memo found");
3453
+ throw new acpError_default("No request memo found");
3447
3454
  }
3448
3455
  const memo = this.latestMemo;
3449
- yield memo.sign(true, memoContent);
3456
+ operations.push(
3457
+ this.acpContractClient.signMemo(memo.id, true, memoContent)
3458
+ );
3459
+ return yield this.acpContractClient.handleOperation(operations);
3450
3460
  });
3451
3461
  }
3452
3462
  reject(reason) {
3453
3463
  return __async(this, null, function* () {
3454
3464
  var _a;
3455
3465
  const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
3466
+ const operations = [];
3456
3467
  if (this.phase === 0 /* REQUEST */) {
3457
3468
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3458
3469
  throw new acpError_default("No request memo found");
3459
3470
  }
3460
3471
  const memo = this.latestMemo;
3461
- return yield this.acpContractClient.signMemo(memo.id, false, memoContent);
3472
+ operations.push(
3473
+ this.acpContractClient.signMemo(memo.id, false, memoContent)
3474
+ );
3475
+ return yield this.acpContractClient.handleOperation(operations);
3462
3476
  }
3463
- return yield this.acpContractClient.createMemo(
3464
- this.id,
3465
- memoContent,
3466
- 0 /* MESSAGE */,
3467
- true,
3468
- 5 /* REJECTED */
3477
+ operations.push(
3478
+ this.acpContractClient.createMemo(
3479
+ this.id,
3480
+ memoContent,
3481
+ 0 /* MESSAGE */,
3482
+ true,
3483
+ 5 /* REJECTED */
3484
+ )
3469
3485
  );
3486
+ return yield this.acpContractClient.handleOperation(operations);
3470
3487
  });
3471
3488
  }
3472
3489
  deliver(deliverable) {
@@ -3475,13 +3492,17 @@ var AcpJob = class {
3475
3492
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3476
3493
  throw new acpError_default("No transaction memo found");
3477
3494
  }
3478
- return yield this.acpContractClient.createMemo(
3479
- this.id,
3480
- preparePayload(deliverable),
3481
- 0 /* MESSAGE */,
3482
- true,
3483
- 4 /* COMPLETED */
3495
+ const operations = [];
3496
+ operations.push(
3497
+ this.acpContractClient.createMemo(
3498
+ this.id,
3499
+ preparePayload(deliverable),
3500
+ 0 /* MESSAGE */,
3501
+ true,
3502
+ 4 /* COMPLETED */
3503
+ )
3484
3504
  );
3505
+ return yield this.acpContractClient.handleOperation(operations);
3485
3506
  });
3486
3507
  }
3487
3508
  deliverPayable(_0, _1) {
@@ -3490,23 +3511,29 @@ var AcpJob = class {
3490
3511
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3491
3512
  throw new acpError_default("No transaction memo found");
3492
3513
  }
3493
- yield this.acpContractClient.approveAllowance(
3494
- amount.amount,
3495
- amount.fare.contractAddress
3514
+ const operations = [];
3515
+ operations.push(
3516
+ this.acpContractClient.approveAllowance(
3517
+ amount.amount,
3518
+ amount.fare.contractAddress
3519
+ )
3496
3520
  );
3497
3521
  const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3498
- return yield this.acpContractClient.createPayableMemo(
3499
- this.id,
3500
- preparePayload(deliverable),
3501
- amount.amount,
3502
- this.clientAddress,
3503
- feeAmount.amount,
3504
- 0 /* NO_FEE */,
3505
- 4 /* COMPLETED */,
3506
- 7 /* PAYABLE_TRANSFER */,
3507
- expiredAt,
3508
- amount.fare.contractAddress
3522
+ operations.push(
3523
+ this.acpContractClient.createPayableMemo(
3524
+ this.id,
3525
+ preparePayload(deliverable),
3526
+ amount.amount,
3527
+ this.clientAddress,
3528
+ feeAmount.amount,
3529
+ 0 /* NO_FEE */,
3530
+ 4 /* COMPLETED */,
3531
+ 7 /* PAYABLE_TRANSFER */,
3532
+ expiredAt,
3533
+ amount.fare.contractAddress
3534
+ )
3509
3535
  );
3536
+ return yield this.acpContractClient.handleOperation(operations);
3510
3537
  });
3511
3538
  }
3512
3539
  evaluate(accept, reason) {
@@ -3519,419 +3546,46 @@ var AcpJob = class {
3519
3546
  yield memo.sign(accept, reason);
3520
3547
  });
3521
3548
  }
3522
- pay(reason) {
3523
- return __async(this, null, function* () {
3524
- const memo = this.memos.find(
3525
- (m) => m.nextPhase === 2 /* TRANSACTION */
3526
- );
3527
- if (!memo) {
3528
- throw new acpError_default("No transaction memo found");
3529
- }
3530
- return yield this.acpClient.payJob(
3531
- this.id,
3532
- this.baseFare.formatAmount(this.price),
3533
- memo.id,
3534
- reason
3535
- );
3536
- });
3537
- }
3538
3549
  createNotification(content) {
3539
3550
  return __async(this, null, function* () {
3540
- return yield this.acpContractClient.createMemo(
3541
- this.id,
3542
- content,
3543
- 9 /* NOTIFICATION */,
3544
- true,
3545
- 4 /* COMPLETED */
3551
+ const operations = [];
3552
+ operations.push(
3553
+ this.acpContractClient.createMemo(
3554
+ this.id,
3555
+ content,
3556
+ 9 /* NOTIFICATION */,
3557
+ true,
3558
+ 4 /* COMPLETED */
3559
+ )
3546
3560
  );
3561
+ return yield this.acpContractClient.handleOperation(operations);
3547
3562
  });
3548
3563
  }
3549
3564
  createPayableNotification(_0, _1) {
3550
3565
  return __async(this, arguments, function* (content, amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3551
- yield this.acpContractClient.approveAllowance(
3552
- amount.amount,
3553
- amount.fare.contractAddress
3566
+ const operations = [];
3567
+ operations.push(
3568
+ this.acpContractClient.approveAllowance(
3569
+ amount.amount,
3570
+ amount.fare.contractAddress
3571
+ )
3554
3572
  );
3555
3573
  const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3556
- return yield this.acpContractClient.createPayableMemo(
3557
- this.id,
3558
- content,
3559
- amount.amount,
3560
- this.clientAddress,
3561
- feeAmount.amount,
3562
- 0 /* NO_FEE */,
3563
- 4 /* COMPLETED */,
3564
- 10 /* PAYABLE_NOTIFICATION */,
3565
- expiredAt,
3566
- amount.fare.contractAddress
3567
- );
3568
- });
3569
- }
3570
- // to be deprecated
3571
- /**
3572
- * @deprecated The method should not be used
3573
- */
3574
- openPosition(_0, _1) {
3575
- return __async(this, arguments, function* (payload, feeAmount, expiredAt = new Date(Date.now() + 1e3 * 60 * 3), walletAddress) {
3576
- if (payload.length === 0) {
3577
- throw new acpError_default("No positions to open");
3578
- }
3579
- const sumAmount = payload.reduce((acc, curr) => acc + curr.amount, 0);
3580
- return yield this.acpClient.transferFunds(
3581
- this.id,
3582
- new FareAmount(sumAmount, this.baseFare),
3583
- walletAddress || this.providerAddress,
3584
- new FareAmount(feeAmount, this.baseFare),
3585
- 1 /* IMMEDIATE_FEE */,
3586
- {
3587
- type: "open_position" /* OPEN_POSITION */,
3588
- data: payload
3589
- },
3590
- 2 /* TRANSACTION */,
3591
- expiredAt
3592
- );
3593
- });
3594
- }
3595
- /**
3596
- * @deprecated The method should not be used
3597
- */
3598
- swapToken(payload, decimals, feeAmount, walletAddress) {
3599
- return __async(this, null, function* () {
3600
- return yield this.acpClient.transferFunds(
3601
- this.id,
3602
- new FareAmount(
3603
- payload.amount,
3604
- new Fare(payload.fromContractAddress, decimals)
3605
- ),
3606
- walletAddress || this.providerAddress,
3607
- new FareAmount(feeAmount, this.baseFare),
3608
- 1 /* IMMEDIATE_FEE */,
3609
- {
3610
- type: "swap_token" /* SWAP_TOKEN */,
3611
- data: payload
3612
- },
3613
- 2 /* TRANSACTION */,
3614
- new Date(Date.now() + 1e3 * 60 * 30)
3615
- );
3616
- });
3617
- }
3618
- /**
3619
- * @deprecated The method should not be used
3620
- */
3621
- responseSwapToken(memoId, accept, reason) {
3622
- return __async(this, null, function* () {
3623
- const memo = this.memos.find((m) => m.id === memoId);
3624
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3625
- throw new acpError_default("No swap token memo found");
3626
- }
3627
- const payload = tryParseJson(
3628
- memo.content
3629
- );
3630
- if ((payload == null ? void 0 : payload.type) !== "swap_token" /* SWAP_TOKEN */) {
3631
- throw new acpError_default("Invalid swap token memo");
3632
- }
3633
- return yield memo.sign(accept, reason);
3634
- });
3635
- }
3636
- /**
3637
- * @deprecated The method should not be used
3638
- */
3639
- transferFunds(_0, _1, _2) {
3640
- return __async(this, arguments, function* (payload, fareAmount, walletAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 30)) {
3641
- return yield this.acpClient.transferFunds(
3642
- this.id,
3643
- fareAmount,
3644
- walletAddress || this.clientAddress,
3645
- new FareAmount(0, this.baseFare),
3646
- 0 /* NO_FEE */,
3647
- payload,
3648
- 2 /* TRANSACTION */,
3649
- expiredAt
3650
- );
3651
- });
3652
- }
3653
- /**
3654
- * @deprecated The method should not be used
3655
- */
3656
- responseOpenPosition(memoId, accept, reason) {
3657
- return __async(this, null, function* () {
3658
- const memo = this.memos.find((m) => m.id === memoId);
3659
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3660
- throw new acpError_default("No open position memo found");
3661
- }
3662
- const payload = tryParseJson(
3663
- memo.content
3664
- );
3665
- if ((payload == null ? void 0 : payload.type) !== "open_position" /* OPEN_POSITION */) {
3666
- throw new acpError_default("Invalid open position memo");
3667
- }
3668
- return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
3669
- });
3670
- }
3671
- /**
3672
- * @deprecated The method should not be used
3673
- */
3674
- closePartialPosition(_0) {
3675
- return __async(this, arguments, function* (payload, expireAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3676
- return yield this.acpClient.requestFunds(
3677
- this.id,
3678
- new FareAmount(payload.amount, this.baseFare),
3679
- this.clientAddress,
3680
- new FareAmount(0, this.baseFare),
3681
- 0 /* NO_FEE */,
3682
- {
3683
- type: "close_partial_position" /* CLOSE_PARTIAL_POSITION */,
3684
- data: payload
3685
- },
3686
- 2 /* TRANSACTION */,
3687
- expireAt
3688
- );
3689
- });
3690
- }
3691
- /**
3692
- * @deprecated The method should not be used
3693
- */
3694
- responseClosePartialPosition(memoId, accept, reason) {
3695
- return __async(this, null, function* () {
3696
- const memo = this.memos.find((m) => m.id === memoId);
3697
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 6 /* PAYABLE_REQUEST */) {
3698
- throw new acpError_default("No close position memo found");
3699
- }
3700
- const payload = tryParseJson(
3701
- memo.content
3702
- );
3703
- if ((payload == null ? void 0 : payload.type) !== "close_partial_position" /* CLOSE_PARTIAL_POSITION */) {
3704
- throw new acpError_default("Invalid close position memo");
3705
- }
3706
- return yield this.acpClient.responseFundsRequest(
3707
- memo.id,
3708
- accept,
3709
- this.baseFare.formatAmount(payload.data.amount),
3710
- reason
3711
- );
3712
- });
3713
- }
3714
- /**
3715
- * @deprecated The method should not be used
3716
- */
3717
- requestClosePosition(payload) {
3718
- return __async(this, null, function* () {
3719
- return yield this.acpClient.sendMessage(
3720
- this.id,
3721
- {
3722
- type: "close_position" /* CLOSE_POSITION */,
3723
- data: payload
3724
- },
3725
- 2 /* TRANSACTION */
3726
- );
3727
- });
3728
- }
3729
- /**
3730
- * @deprecated The method should not be used
3731
- */
3732
- responseRequestClosePosition(_0, _1, _2, _3) {
3733
- return __async(this, arguments, function* (memoId, accept, payload, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3734
- const memo = this.memos.find((m) => m.id === memoId);
3735
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
3736
- throw new acpError_default("No message memo found");
3737
- }
3738
- const messagePayload = tryParseJson(memo.content);
3739
- if ((messagePayload == null ? void 0 : messagePayload.type) !== "close_position" /* CLOSE_POSITION */) {
3740
- throw new acpError_default("Invalid close position memo");
3741
- }
3742
- yield memo.sign(accept, reason);
3743
- if (accept) {
3744
- return yield this.acpClient.transferFunds(
3574
+ operations.push(
3575
+ this.acpContractClient.createPayableMemo(
3745
3576
  this.id,
3746
- new FareAmount(payload.amount, this.baseFare),
3577
+ content,
3578
+ amount.amount,
3747
3579
  this.clientAddress,
3748
- new FareAmount(0, this.baseFare),
3580
+ feeAmount.amount,
3749
3581
  0 /* NO_FEE */,
3750
- {
3751
- type: "close_position" /* CLOSE_POSITION */,
3752
- data: payload
3753
- },
3754
- 2 /* TRANSACTION */,
3755
- expiredAt
3756
- );
3757
- }
3758
- });
3759
- }
3760
- /**
3761
- * @deprecated The method should not be used
3762
- */
3763
- confirmClosePosition(memoId, accept, reason) {
3764
- return __async(this, null, function* () {
3765
- const memo = this.memos.find((m) => m.id === memoId);
3766
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3767
- throw new acpError_default("No payable transfer memo found");
3768
- }
3769
- const payload = tryParseJson(
3770
- memo.content
3771
- );
3772
- if ((payload == null ? void 0 : payload.type) !== "close_position" /* CLOSE_POSITION */) {
3773
- throw new acpError_default("Invalid close position memo");
3774
- }
3775
- yield memo.sign(accept, reason);
3776
- });
3777
- }
3778
- /**
3779
- * @deprecated The method should not be used
3780
- */
3781
- positionFulfilled(_0) {
3782
- return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3783
- return yield this.acpClient.transferFunds(
3784
- this.id,
3785
- new FareAmount(payload.amount, this.baseFare),
3786
- this.clientAddress,
3787
- new FareAmount(0, this.baseFare),
3788
- 0 /* NO_FEE */,
3789
- {
3790
- type: "position_fulfilled" /* POSITION_FULFILLED */,
3791
- data: payload
3792
- },
3793
- 2 /* TRANSACTION */,
3794
- expiredAt
3795
- );
3796
- });
3797
- }
3798
- /**
3799
- * @deprecated The method should not be used
3800
- */
3801
- unfulfilledPosition(_0) {
3802
- return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3803
- return yield this.acpClient.transferFunds(
3804
- this.id,
3805
- new FareAmount(payload.amount, this.baseFare),
3806
- this.clientAddress,
3807
- new FareAmount(0, this.baseFare),
3808
- 0 /* NO_FEE */,
3809
- {
3810
- type: "unfulfilled_position" /* UNFULFILLED_POSITION */,
3811
- data: payload
3812
- },
3813
- 2 /* TRANSACTION */,
3814
- expiredAt
3815
- );
3816
- });
3817
- }
3818
- /**
3819
- * @deprecated The method should not be used
3820
- */
3821
- responseUnfulfilledPosition(memoId, accept, reason) {
3822
- return __async(this, null, function* () {
3823
- const memo = this.memos.find((m) => m.id === memoId);
3824
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3825
- throw new acpError_default("No unfulfilled position memo found");
3826
- }
3827
- const payload = tryParseJson(
3828
- memo.content
3829
- );
3830
- if ((payload == null ? void 0 : payload.type) !== "unfulfilled_position" /* UNFULFILLED_POSITION */) {
3831
- throw new acpError_default("Invalid unfulfilled position memo");
3832
- }
3833
- return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
3834
- });
3835
- }
3836
- /**
3837
- * @deprecated The method should not be used
3838
- */
3839
- responsePositionFulfilled(memoId, accept, reason) {
3840
- return __async(this, null, function* () {
3841
- const memo = this.memos.find((m) => m.id === memoId);
3842
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3843
- throw new acpError_default("No position fulfilled memo found");
3844
- }
3845
- const payload = tryParseJson(
3846
- memo.content
3847
- );
3848
- if ((payload == null ? void 0 : payload.type) !== "position_fulfilled" /* POSITION_FULFILLED */) {
3849
- throw new acpError_default("Invalid position fulfilled memo");
3850
- }
3851
- return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
3852
- });
3853
- }
3854
- /**
3855
- * @deprecated The method should not be used
3856
- */
3857
- closeJob(message = "Close job and withdraw all") {
3858
- return __async(this, null, function* () {
3859
- return yield this.acpClient.sendMessage(
3860
- this.id,
3861
- {
3862
- type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
3863
- data: {
3864
- message
3865
- }
3866
- },
3867
- 2 /* TRANSACTION */
3868
- );
3869
- });
3870
- }
3871
- /**
3872
- * @deprecated The method should not be used
3873
- */
3874
- responseCloseJob(_0, _1, _2, _3) {
3875
- return __async(this, arguments, function* (memoId, accept, fulfilledPositions, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3876
- const memo = this.memos.find((m) => m.id === memoId);
3877
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
3878
- throw new acpError_default("No message memo found");
3879
- }
3880
- const payload = tryParseJson(
3881
- memo.content
3882
- );
3883
- if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
3884
- throw new acpError_default("Invalid close job and withdraw memo");
3885
- }
3886
- yield memo.sign(accept, reason);
3887
- if (!accept) {
3888
- return;
3889
- }
3890
- const totalAmount = fulfilledPositions.reduce(
3891
- (acc, curr) => acc + curr.amount,
3892
- 0
3893
- );
3894
- if (totalAmount === 0) {
3895
- return yield this.acpClient.sendMessage(
3896
- this.id,
3897
- {
3898
- type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
3899
- data: fulfilledPositions
3900
- },
3901
- 4 /* COMPLETED */
3902
- );
3903
- }
3904
- return yield this.acpClient.transferFunds(
3905
- this.id,
3906
- new FareAmount(totalAmount, this.baseFare),
3907
- this.clientAddress,
3908
- new FareAmount(0, this.baseFare),
3909
- 0 /* NO_FEE */,
3910
- {
3911
- type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
3912
- data: fulfilledPositions
3913
- },
3914
- 4 /* COMPLETED */,
3915
- expiredAt
3916
- );
3917
- });
3918
- }
3919
- /**
3920
- * @deprecated The method should not be used
3921
- */
3922
- confirmJobClosure(memoId, accept, reason) {
3923
- return __async(this, null, function* () {
3924
- const memo = this.memos.find((m) => m.id === memoId);
3925
- if (!memo) {
3926
- throw new acpError_default("Memo not found");
3927
- }
3928
- const payload = tryParseJson(
3929
- memo.content
3582
+ 4 /* COMPLETED */,
3583
+ 10 /* PAYABLE_NOTIFICATION */,
3584
+ expiredAt,
3585
+ amount.fare.contractAddress
3586
+ )
3930
3587
  );
3931
- if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
3932
- throw new acpError_default("Invalid close job and withdraw memo");
3933
- }
3934
- yield memo.sign(accept, reason);
3588
+ return yield this.acpContractClient.handleOperation(operations);
3935
3589
  });
3936
3590
  }
3937
3591
  };
@@ -3976,7 +3630,8 @@ var AcpMemo = class {
3976
3630
  }
3977
3631
  sign(approved, reason) {
3978
3632
  return __async(this, null, function* () {
3979
- return yield this.contractClient.signMemo(this.id, approved, reason);
3633
+ const payload = this.contractClient.signMemo(this.id, approved, reason);
3634
+ return yield this.contractClient.handleOperation([payload]);
3980
3635
  });
3981
3636
  }
3982
3637
  };
@@ -4017,7 +3672,7 @@ var AcpJobOffering = class {
4017
3672
  this.providerAddress,
4018
3673
  this.acpContractClient
4019
3674
  );
4020
- const { jobId, txHash } = [
3675
+ const createJobPayload = [
4021
3676
  baseSepoliaAcpConfig.contractAddress,
4022
3677
  baseAcpConfig.contractAddress
4023
3678
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
@@ -4035,13 +3690,33 @@ var AcpJobOffering = class {
4035
3690
  fareAmount.fare.contractAddress,
4036
3691
  expiredAt
4037
3692
  );
4038
- yield this.acpContractClient.createMemo(
3693
+ const createJobTxnHash = yield this.acpContractClient.handleOperation([
3694
+ createJobPayload
3695
+ ]);
3696
+ const jobId = yield this.acpContractClient.getJobId(
3697
+ createJobTxnHash,
3698
+ this.acpContractClient.walletAddress,
3699
+ this.providerAddress
3700
+ );
3701
+ const payloads = [];
3702
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4039
3703
  jobId,
4040
- JSON.stringify(finalServiceRequirement),
4041
- 0 /* MESSAGE */,
4042
- true,
4043
- 1 /* NEGOTIATION */
3704
+ fareAmount.amount,
3705
+ fareAmount.fare.contractAddress
4044
3706
  );
3707
+ if (setBudgetWithPaymentTokenPayload) {
3708
+ payloads.push(setBudgetWithPaymentTokenPayload);
3709
+ }
3710
+ payloads.push(
3711
+ this.acpContractClient.createMemo(
3712
+ jobId,
3713
+ JSON.stringify(finalServiceRequirement),
3714
+ 0 /* MESSAGE */,
3715
+ true,
3716
+ 1 /* NEGOTIATION */
3717
+ )
3718
+ );
3719
+ yield this.acpContractClient.handleOperation(payloads);
4045
3720
  return jobId;
4046
3721
  });
4047
3722
  }
@@ -4293,12 +3968,16 @@ var AcpClient = class {
4293
3968
  providerAddress,
4294
3969
  this.acpContractClient
4295
3970
  );
4296
- const { jobId, txHash } = [
3971
+ const defaultEvaluatorAddress = [
3972
+ baseSepoliaAcpConfig.contractAddress,
3973
+ baseAcpConfig.contractAddress
3974
+ ].includes(this.acpContractClient.config.contractAddress) && !evaluatorAddress ? this.walletAddress : import_viem4.zeroAddress;
3975
+ const createJobPayload = [
4297
3976
  baseSepoliaAcpConfig.contractAddress,
4298
3977
  baseAcpConfig.contractAddress
4299
3978
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
4300
3979
  providerAddress,
4301
- evaluatorAddress || this.walletAddress,
3980
+ evaluatorAddress || defaultEvaluatorAddress,
4302
3981
  expiredAt,
4303
3982
  fareAmount.fare.contractAddress,
4304
3983
  fareAmount.amount,
@@ -4306,182 +3985,39 @@ var AcpClient = class {
4306
3985
  ) : yield this.acpContractClient.createJobWithAccount(
4307
3986
  account.id,
4308
3987
  providerAddress,
4309
- evaluatorAddress || this.walletAddress,
3988
+ evaluatorAddress || defaultEvaluatorAddress,
4310
3989
  fareAmount.amount,
4311
3990
  fareAmount.fare.contractAddress,
4312
3991
  expiredAt
4313
3992
  );
4314
- yield this.acpContractClient.createMemo(
4315
- jobId,
4316
- preparePayload(serviceRequirement),
4317
- 0 /* MESSAGE */,
4318
- true,
4319
- 1 /* NEGOTIATION */
4320
- );
4321
- return jobId;
4322
- });
4323
- }
4324
- createMemo(jobId, content, nextPhase) {
4325
- return __async(this, null, function* () {
4326
- return yield this.acpContractClient.createMemo(
4327
- jobId,
4328
- content,
4329
- 0 /* MESSAGE */,
4330
- false,
4331
- nextPhase
4332
- );
4333
- });
4334
- }
4335
- createPayableMemo(jobId, content, amount, recipient, nextPhase, type, expiredAt) {
4336
- return __async(this, null, function* () {
4337
- if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
4338
- yield this.acpContractClient.approveAllowance(
4339
- amount.amount,
4340
- amount.fare.contractAddress
4341
- );
4342
- }
4343
- const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4344
- return yield this.acpContractClient.createPayableMemo(
4345
- jobId,
4346
- content,
4347
- amount.amount,
4348
- recipient,
4349
- feeAmount.amount,
4350
- 0 /* NO_FEE */,
4351
- nextPhase,
4352
- type,
4353
- expiredAt,
4354
- amount.fare.contractAddress
4355
- );
4356
- });
4357
- }
4358
- respondJob(jobId, memoId, accept, content, reason) {
4359
- return __async(this, null, function* () {
4360
- yield this.acpContractClient.signMemo(memoId, accept, reason);
4361
- if (!accept) {
4362
- return;
4363
- }
4364
- return yield this.acpContractClient.createMemo(
4365
- jobId,
4366
- content != null ? content : `Job ${jobId} accepted. ${reason != null ? reason : ""}`,
4367
- 0 /* MESSAGE */,
4368
- false,
4369
- 2 /* TRANSACTION */
4370
- );
4371
- });
4372
- }
4373
- payJob(jobId, amountBaseUnit, memoId, reason) {
4374
- return __async(this, null, function* () {
4375
- if (amountBaseUnit > BigInt(0)) {
4376
- yield this.acpContractClient.approveAllowance(amountBaseUnit);
4377
- }
4378
- yield this.acpContractClient.signMemo(memoId, true, reason);
4379
- return yield this.acpContractClient.createMemo(
4380
- jobId,
4381
- `Payment made. ${reason != null ? reason : ""}`,
4382
- 0 /* MESSAGE */,
4383
- false,
4384
- 3 /* EVALUATION */
3993
+ const txHash = yield this.acpContractClient.handleOperation([
3994
+ createJobPayload
3995
+ ]);
3996
+ const jobId = yield this.acpContractClient.getJobId(
3997
+ txHash,
3998
+ this.walletAddress,
3999
+ providerAddress
4385
4000
  );
4386
- });
4387
- }
4388
- requestFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
4389
- return __async(this, null, function* () {
4390
- return yield this.acpContractClient.createPayableMemo(
4001
+ const payloads = [];
4002
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4391
4003
  jobId,
4392
- JSON.stringify(reason),
4393
- transferFareAmount.amount,
4394
- recipient,
4395
- feeFareAmount.amount,
4396
- feeType,
4397
- nextPhase,
4398
- 6 /* PAYABLE_REQUEST */,
4399
- expiredAt
4004
+ fareAmount.amount,
4005
+ fareAmount.fare.contractAddress
4400
4006
  );
4401
- });
4402
- }
4403
- responseFundsRequest(memoId, accept, amountBaseUnit, reason) {
4404
- return __async(this, null, function* () {
4405
- if (!accept) {
4406
- return yield this.acpContractClient.signMemo(memoId, accept, reason);
4007
+ if (setBudgetWithPaymentTokenPayload) {
4008
+ payloads.push(setBudgetWithPaymentTokenPayload);
4407
4009
  }
4408
- if (amountBaseUnit > BigInt(0)) {
4409
- yield this.acpContractClient.approveAllowance(amountBaseUnit);
4410
- }
4411
- return yield this.acpContractClient.signMemo(memoId, true, reason);
4412
- });
4413
- }
4414
- transferFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
4415
- return __async(this, null, function* () {
4416
- if (transferFareAmount.fare.contractAddress === ethFare.contractAddress) {
4417
- yield this.acpContractClient.wrapEth(transferFareAmount.amount);
4418
- transferFareAmount = new FareBigInt(transferFareAmount.amount, wethFare);
4419
- }
4420
- if (feeFareAmount.amount > 0 && feeFareAmount.fare.contractAddress !== this.acpContractClient.config.baseFare.contractAddress) {
4421
- throw new acpError_default("Fee token address is not the same as the base fare");
4422
- }
4423
- const isFeeTokenDifferent = feeFareAmount.fare.contractAddress !== transferFareAmount.fare.contractAddress;
4424
- if (isFeeTokenDifferent) {
4425
- yield this.acpContractClient.approveAllowance(
4426
- feeFareAmount.amount,
4427
- feeFareAmount.fare.contractAddress
4428
- );
4429
- }
4430
- const finalAmount = isFeeTokenDifferent ? transferFareAmount : transferFareAmount.add(feeFareAmount);
4431
- yield this.acpContractClient.approveAllowance(
4432
- finalAmount.amount,
4433
- transferFareAmount.fare.contractAddress
4434
- );
4435
- return yield this.acpContractClient.createPayableMemo(
4436
- jobId,
4437
- JSON.stringify(reason),
4438
- transferFareAmount.amount,
4439
- recipient,
4440
- feeFareAmount.amount,
4441
- feeType,
4442
- nextPhase,
4443
- 8 /* PAYABLE_TRANSFER_ESCROW */,
4444
- expiredAt,
4445
- transferFareAmount.fare.contractAddress
4446
- );
4447
- });
4448
- }
4449
- sendMessage(jobId, message, nextPhase) {
4450
- return __async(this, null, function* () {
4451
- return yield this.acpContractClient.createMemo(
4452
- jobId,
4453
- JSON.stringify(message),
4454
- 0 /* MESSAGE */,
4455
- false,
4456
- nextPhase
4457
- );
4458
- });
4459
- }
4460
- responseFundsTransfer(memoId, accept, reason) {
4461
- return __async(this, null, function* () {
4462
- return yield this.acpContractClient.signMemo(memoId, accept, reason);
4463
- });
4464
- }
4465
- rejectJob(jobId, reason) {
4466
- return __async(this, null, function* () {
4467
- return yield this.acpContractClient.createMemo(
4468
- jobId,
4469
- `Job ${jobId} rejected. ${reason || ""}`,
4470
- 0 /* MESSAGE */,
4471
- false,
4472
- 5 /* REJECTED */
4473
- );
4474
- });
4475
- }
4476
- deliverJob(jobId, deliverable) {
4477
- return __async(this, null, function* () {
4478
- return yield this.acpContractClient.createMemo(
4479
- jobId,
4480
- preparePayload(deliverable),
4481
- 4 /* OBJECT_URL */,
4482
- true,
4483
- 4 /* COMPLETED */
4010
+ payloads.push(
4011
+ this.acpContractClient.createMemo(
4012
+ jobId,
4013
+ preparePayload(serviceRequirement),
4014
+ 0 /* MESSAGE */,
4015
+ true,
4016
+ 1 /* NEGOTIATION */
4017
+ )
4484
4018
  );
4019
+ yield this.acpContractClient.handleOperation(payloads);
4020
+ return jobId;
4485
4021
  });
4486
4022
  }
4487
4023
  getActiveJobs(page = 1, pageSize = 10) {
@@ -4811,7 +4347,7 @@ var acpClient_default = AcpClient;
4811
4347
  var import_core = require("@aa-sdk/core");
4812
4348
  var import_infra2 = require("@account-kit/infra");
4813
4349
  var import_smart_contracts = require("@account-kit/smart-contracts");
4814
- var import_viem4 = require("viem");
4350
+ var import_viem5 = require("viem");
4815
4351
  var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_default {
4816
4352
  constructor(agentWalletAddress, config = baseAcpConfig) {
4817
4353
  super(agentWalletAddress, config);
@@ -4866,14 +4402,14 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4866
4402
  return finalMaxFeePerGas;
4867
4403
  });
4868
4404
  }
4869
- handleOperation(_0) {
4870
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
4405
+ handleOperation(operations) {
4406
+ return __async(this, null, function* () {
4871
4407
  const payload = {
4872
- uo: {
4873
- target: contractAddress,
4874
- data,
4875
- value
4876
- },
4408
+ uo: operations.map((op) => ({
4409
+ target: op.contractAddress,
4410
+ data: op.data,
4411
+ value: op.value
4412
+ })),
4877
4413
  overrides: {
4878
4414
  nonceKey: this.getRandomNonce()
4879
4415
  }
@@ -4914,7 +4450,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4914
4450
  const contractLogs = result.logs.filter((log) => {
4915
4451
  return log.address.toLowerCase() === this.contractAddress.toLowerCase();
4916
4452
  }).map(
4917
- (log) => (0, import_viem4.decodeEventLog)({
4453
+ (log) => (0, import_viem5.decodeEventLog)({
4918
4454
  abi: this.abi,
4919
4455
  data: log.data,
4920
4456
  topics: log.topics
@@ -4930,68 +4466,73 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4930
4466
  });
4931
4467
  }
4932
4468
  createJob(providerAddress, evaluatorAddress, expireAt, paymentTokenAddress, budgetBaseUnit, metadata) {
4933
- return __async(this, null, function* () {
4934
- try {
4935
- const data = (0, import_viem4.encodeFunctionData)({
4936
- abi: this.abi,
4937
- functionName: "createJob",
4938
- args: [
4939
- providerAddress,
4940
- evaluatorAddress,
4941
- Math.floor(expireAt.getTime() / 1e3)
4942
- ]
4943
- });
4944
- const hash = yield this.handleOperation(data, this.contractAddress);
4945
- const jobId = yield this.getJobId(
4946
- hash,
4947
- this.agentWalletAddress,
4948
- providerAddress
4949
- );
4950
- yield this.setBudgetWithPaymentToken(
4951
- jobId,
4952
- budgetBaseUnit,
4953
- paymentTokenAddress
4954
- );
4955
- return { txHash: hash, jobId };
4956
- } catch (error) {
4957
- throw new acpError_default("Failed to create job", error);
4958
- }
4959
- });
4469
+ try {
4470
+ const data = (0, import_viem5.encodeFunctionData)({
4471
+ abi: this.abi,
4472
+ functionName: "createJob",
4473
+ args: [
4474
+ providerAddress,
4475
+ evaluatorAddress,
4476
+ Math.floor(expireAt.getTime() / 1e3)
4477
+ ]
4478
+ });
4479
+ const payload = {
4480
+ data,
4481
+ contractAddress: this.contractAddress
4482
+ };
4483
+ return payload;
4484
+ } catch (error) {
4485
+ throw new acpError_default("Failed to create job", error);
4486
+ }
4960
4487
  }
4961
- createPayableMemo(_0, _1, _2, _3, _4, _5, _6, _7, _8) {
4962
- return __async(this, arguments, function* (jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
4963
- try {
4964
- const data = (0, import_viem4.encodeFunctionData)({
4965
- abi: this.abi,
4966
- functionName: "createPayableMemo",
4967
- args: [
4968
- jobId,
4969
- content,
4970
- token,
4971
- amountBaseUnit,
4972
- recipient,
4973
- feeAmountBaseUnit,
4974
- feeType,
4975
- type,
4976
- nextPhase,
4977
- Math.floor(expiredAt.getTime() / 1e3)
4978
- ]
4979
- });
4980
- return yield this.handleOperation(data, this.contractAddress);
4981
- } catch (error) {
4982
- throw new acpError_default("Failed to create payable memo", error);
4983
- }
4984
- });
4488
+ setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
4489
+ try {
4490
+ const data = (0, import_viem5.encodeFunctionData)({
4491
+ abi: this.abi,
4492
+ functionName: "setBudgetWithPaymentToken",
4493
+ args: [jobId, budgetBaseUnit, paymentTokenAddress]
4494
+ });
4495
+ const payload = {
4496
+ data,
4497
+ contractAddress: this.contractAddress
4498
+ };
4499
+ return payload;
4500
+ } catch (error) {
4501
+ throw new acpError_default("Failed to set budget", error);
4502
+ }
4503
+ }
4504
+ createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
4505
+ try {
4506
+ const data = (0, import_viem5.encodeFunctionData)({
4507
+ abi: this.abi,
4508
+ functionName: "createPayableMemo",
4509
+ args: [
4510
+ jobId,
4511
+ content,
4512
+ token,
4513
+ amountBaseUnit,
4514
+ recipient,
4515
+ feeAmountBaseUnit,
4516
+ feeType,
4517
+ type,
4518
+ nextPhase,
4519
+ Math.floor(expiredAt.getTime() / 1e3)
4520
+ ]
4521
+ });
4522
+ const payload = {
4523
+ data,
4524
+ contractAddress: this.contractAddress
4525
+ };
4526
+ return payload;
4527
+ } catch (error) {
4528
+ throw new acpError_default("Failed to create payable memo", error);
4529
+ }
4985
4530
  }
4986
4531
  createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4987
- return __async(this, null, function* () {
4988
- throw new acpError_default("Not Supported");
4989
- });
4532
+ throw new acpError_default("Not Supported");
4990
4533
  }
4991
4534
  updateAccountMetadata(accountId, metadata) {
4992
- return __async(this, null, function* () {
4993
- throw new acpError_default("Not Supported");
4994
- });
4535
+ throw new acpError_default("Not Supported");
4995
4536
  }
4996
4537
  };
4997
4538
  var acpContractClient_default = AcpContractClient;
@@ -5000,7 +4541,7 @@ var acpContractClient_default = AcpContractClient;
5000
4541
  var import_core2 = require("@aa-sdk/core");
5001
4542
  var import_infra3 = require("@account-kit/infra");
5002
4543
  var import_smart_contracts2 = require("@account-kit/smart-contracts");
5003
- var import_viem5 = require("viem");
4544
+ var import_viem6 = require("viem");
5004
4545
 
5005
4546
  // src/abis/jobManagerAbi.ts
5006
4547
  var JOB_MANAGER_ABI = [
@@ -5874,9 +5415,9 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5874
5415
  }
5875
5416
  static build(_0, _1, _2) {
5876
5417
  return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfigV2) {
5877
- const publicClient = (0, import_viem5.createPublicClient)({
5418
+ const publicClient = (0, import_viem6.createPublicClient)({
5878
5419
  chain: config.chain,
5879
- transport: (0, import_viem5.http)(config.rpcEndpoint)
5420
+ transport: (0, import_viem6.http)(config.rpcEndpoint)
5880
5421
  });
5881
5422
  const [jobManagerAddress, memoManagerAddress, accountManagerAddress] = yield publicClient.multicall({
5882
5423
  contracts: [
@@ -5952,14 +5493,14 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5952
5493
  return finalMaxFeePerGas;
5953
5494
  });
5954
5495
  }
5955
- handleOperation(_0) {
5956
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
5496
+ handleOperation(operations) {
5497
+ return __async(this, null, function* () {
5957
5498
  const payload = {
5958
- uo: {
5959
- target: contractAddress,
5960
- data,
5961
- value
5962
- },
5499
+ uo: operations.map((operation) => ({
5500
+ target: operation.contractAddress,
5501
+ data: operation.data,
5502
+ value: operation.value
5503
+ })),
5963
5504
  overrides: {
5964
5505
  nonceKey: this.getRandomNonce()
5965
5506
  }
@@ -5976,7 +5517,13 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5976
5517
  }
5977
5518
  const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
5978
5519
  yield this.sessionKeyClient.waitForUserOperationTransaction({
5979
- hash
5520
+ hash,
5521
+ tag: "pending",
5522
+ retries: {
5523
+ intervalMs: 200,
5524
+ multiplier: 1.1,
5525
+ maxRetries: 10
5526
+ }
5980
5527
  });
5981
5528
  return hash;
5982
5529
  } catch (error) {
@@ -5993,14 +5540,17 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5993
5540
  }
5994
5541
  getJobId(hash, clientAddress, providerAddress) {
5995
5542
  return __async(this, null, function* () {
5996
- const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
5543
+ const result = yield this.sessionKeyClient.getUserOperationReceipt(
5544
+ hash,
5545
+ "pending"
5546
+ );
5997
5547
  if (!result) {
5998
5548
  throw new acpError_default("Failed to get user operation receipt");
5999
5549
  }
6000
5550
  const contractLogs = result.logs.filter((log) => {
6001
5551
  return log.address.toLowerCase() === this.jobManagerAddress.toLowerCase();
6002
5552
  }).map(
6003
- (log) => (0, import_viem5.decodeEventLog)({
5553
+ (log) => (0, import_viem6.decodeEventLog)({
6004
5554
  abi: jobManagerAbi_default,
6005
5555
  data: log.data,
6006
5556
  topics: log.topics