@virtuals-protocol/acp-node 0.3.0-beta.4 → 0.3.0-beta.6

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.4",
58
+ version: "0.3.0-beta.6",
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) {
@@ -3440,33 +3446,63 @@ var AcpJob = class {
3440
3446
  }
3441
3447
  accept(reason) {
3442
3448
  return __async(this, null, function* () {
3443
- var _a;
3444
3449
  const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
3445
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3446
- throw new acpError_default("No negotiation memo found");
3450
+ const latestMemo = this.latestMemo;
3451
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3452
+ throw new acpError_default("No request memo found");
3447
3453
  }
3448
- const memo = this.latestMemo;
3449
- yield memo.sign(true, memoContent);
3454
+ return yield latestMemo.sign(true, memoContent);
3450
3455
  });
3451
3456
  }
3452
3457
  reject(reason) {
3453
3458
  return __async(this, null, function* () {
3454
- var _a;
3455
3459
  const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
3456
3460
  if (this.phase === 0 /* REQUEST */) {
3457
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3461
+ const latestMemo = this.latestMemo;
3462
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3458
3463
  throw new acpError_default("No request memo found");
3459
3464
  }
3460
- const memo = this.latestMemo;
3461
- return yield this.acpContractClient.signMemo(memo.id, false, memoContent);
3465
+ return yield latestMemo.sign(false, memoContent);
3462
3466
  }
3463
- return yield this.acpContractClient.createMemo(
3464
- this.id,
3465
- memoContent,
3466
- 0 /* MESSAGE */,
3467
- true,
3468
- 5 /* REJECTED */
3467
+ const operations = [];
3468
+ operations.push(
3469
+ this.acpContractClient.createMemo(
3470
+ this.id,
3471
+ memoContent,
3472
+ 0 /* MESSAGE */,
3473
+ true,
3474
+ 5 /* REJECTED */
3475
+ )
3469
3476
  );
3477
+ return yield this.acpContractClient.handleOperation(operations);
3478
+ });
3479
+ }
3480
+ rejectPayable() {
3481
+ return __async(this, arguments, function* (reason = "", amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3482
+ const memoContent = `Job ${this.id} rejected. ${reason}`;
3483
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3484
+ const operations = [];
3485
+ operations.push(
3486
+ this.acpContractClient.approveAllowance(
3487
+ amount.amount,
3488
+ amount.fare.contractAddress
3489
+ )
3490
+ );
3491
+ operations.push(
3492
+ this.acpContractClient.createPayableMemo(
3493
+ this.id,
3494
+ memoContent,
3495
+ amount.amount,
3496
+ this.clientAddress,
3497
+ feeAmount.amount,
3498
+ 0 /* NO_FEE */,
3499
+ 5 /* REJECTED */,
3500
+ 7 /* PAYABLE_TRANSFER */,
3501
+ expiredAt,
3502
+ amount.fare.contractAddress
3503
+ )
3504
+ );
3505
+ return yield this.acpContractClient.handleOperation(operations);
3470
3506
  });
3471
3507
  }
3472
3508
  deliver(deliverable) {
@@ -3475,13 +3511,17 @@ var AcpJob = class {
3475
3511
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3476
3512
  throw new acpError_default("No transaction memo found");
3477
3513
  }
3478
- return yield this.acpContractClient.createMemo(
3479
- this.id,
3480
- preparePayload(deliverable),
3481
- 0 /* MESSAGE */,
3482
- true,
3483
- 4 /* COMPLETED */
3514
+ const operations = [];
3515
+ operations.push(
3516
+ this.acpContractClient.createMemo(
3517
+ this.id,
3518
+ preparePayload(deliverable),
3519
+ 0 /* MESSAGE */,
3520
+ true,
3521
+ 4 /* COMPLETED */
3522
+ )
3484
3523
  );
3524
+ return yield this.acpContractClient.handleOperation(operations);
3485
3525
  });
3486
3526
  }
3487
3527
  deliverPayable(_0, _1) {
@@ -3490,23 +3530,29 @@ var AcpJob = class {
3490
3530
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3491
3531
  throw new acpError_default("No transaction memo found");
3492
3532
  }
3493
- yield this.acpContractClient.approveAllowance(
3494
- amount.amount,
3495
- amount.fare.contractAddress
3533
+ const operations = [];
3534
+ operations.push(
3535
+ this.acpContractClient.approveAllowance(
3536
+ amount.amount,
3537
+ amount.fare.contractAddress
3538
+ )
3496
3539
  );
3497
3540
  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
3541
+ operations.push(
3542
+ this.acpContractClient.createPayableMemo(
3543
+ this.id,
3544
+ preparePayload(deliverable),
3545
+ amount.amount,
3546
+ this.clientAddress,
3547
+ feeAmount.amount,
3548
+ 0 /* NO_FEE */,
3549
+ 4 /* COMPLETED */,
3550
+ 7 /* PAYABLE_TRANSFER */,
3551
+ expiredAt,
3552
+ amount.fare.contractAddress
3553
+ )
3509
3554
  );
3555
+ return yield this.acpContractClient.handleOperation(operations);
3510
3556
  });
3511
3557
  }
3512
3558
  evaluate(accept, reason) {
@@ -3519,419 +3565,46 @@ var AcpJob = class {
3519
3565
  yield memo.sign(accept, reason);
3520
3566
  });
3521
3567
  }
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
3568
  createNotification(content) {
3539
3569
  return __async(this, null, function* () {
3540
- return yield this.acpContractClient.createMemo(
3541
- this.id,
3542
- content,
3543
- 9 /* NOTIFICATION */,
3544
- true,
3545
- 4 /* COMPLETED */
3570
+ const operations = [];
3571
+ operations.push(
3572
+ this.acpContractClient.createMemo(
3573
+ this.id,
3574
+ content,
3575
+ 9 /* NOTIFICATION */,
3576
+ true,
3577
+ 4 /* COMPLETED */
3578
+ )
3546
3579
  );
3580
+ return yield this.acpContractClient.handleOperation(operations);
3547
3581
  });
3548
3582
  }
3549
3583
  createPayableNotification(_0, _1) {
3550
3584
  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
3585
+ const operations = [];
3586
+ operations.push(
3587
+ this.acpContractClient.approveAllowance(
3588
+ amount.amount,
3589
+ amount.fare.contractAddress
3590
+ )
3554
3591
  );
3555
3592
  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(
3593
+ operations.push(
3594
+ this.acpContractClient.createPayableMemo(
3745
3595
  this.id,
3746
- new FareAmount(payload.amount, this.baseFare),
3596
+ content,
3597
+ amount.amount,
3747
3598
  this.clientAddress,
3748
- new FareAmount(0, this.baseFare),
3599
+ feeAmount.amount,
3749
3600
  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
3601
+ 4 /* COMPLETED */,
3602
+ 10 /* PAYABLE_NOTIFICATION */,
3603
+ expiredAt,
3604
+ amount.fare.contractAddress
3605
+ )
3930
3606
  );
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);
3607
+ return yield this.acpContractClient.handleOperation(operations);
3935
3608
  });
3936
3609
  }
3937
3610
  };
@@ -3976,7 +3649,8 @@ var AcpMemo = class {
3976
3649
  }
3977
3650
  sign(approved, reason) {
3978
3651
  return __async(this, null, function* () {
3979
- return yield this.contractClient.signMemo(this.id, approved, reason);
3652
+ const payload = this.contractClient.signMemo(this.id, approved, reason);
3653
+ return yield this.contractClient.handleOperation([payload]);
3980
3654
  });
3981
3655
  }
3982
3656
  };
@@ -4017,7 +3691,7 @@ var AcpJobOffering = class {
4017
3691
  this.providerAddress,
4018
3692
  this.acpContractClient
4019
3693
  );
4020
- const { jobId, txHash } = [
3694
+ const createJobPayload = [
4021
3695
  baseSepoliaAcpConfig.contractAddress,
4022
3696
  baseAcpConfig.contractAddress
4023
3697
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
@@ -4035,13 +3709,33 @@ var AcpJobOffering = class {
4035
3709
  fareAmount.fare.contractAddress,
4036
3710
  expiredAt
4037
3711
  );
4038
- yield this.acpContractClient.createMemo(
3712
+ const createJobTxnHash = yield this.acpContractClient.handleOperation([
3713
+ createJobPayload
3714
+ ]);
3715
+ const jobId = yield this.acpContractClient.getJobId(
3716
+ createJobTxnHash,
3717
+ this.acpContractClient.walletAddress,
3718
+ this.providerAddress
3719
+ );
3720
+ const payloads = [];
3721
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4039
3722
  jobId,
4040
- JSON.stringify(finalServiceRequirement),
4041
- 0 /* MESSAGE */,
4042
- true,
4043
- 1 /* NEGOTIATION */
3723
+ fareAmount.amount,
3724
+ fareAmount.fare.contractAddress
4044
3725
  );
3726
+ if (setBudgetWithPaymentTokenPayload) {
3727
+ payloads.push(setBudgetWithPaymentTokenPayload);
3728
+ }
3729
+ payloads.push(
3730
+ this.acpContractClient.createMemo(
3731
+ jobId,
3732
+ JSON.stringify(finalServiceRequirement),
3733
+ 0 /* MESSAGE */,
3734
+ true,
3735
+ 1 /* NEGOTIATION */
3736
+ )
3737
+ );
3738
+ yield this.acpContractClient.handleOperation(payloads);
4045
3739
  return jobId;
4046
3740
  });
4047
3741
  }
@@ -4293,12 +3987,16 @@ var AcpClient = class {
4293
3987
  providerAddress,
4294
3988
  this.acpContractClient
4295
3989
  );
4296
- const { jobId, txHash } = [
3990
+ const defaultEvaluatorAddress = [
3991
+ baseSepoliaAcpConfig.contractAddress,
3992
+ baseAcpConfig.contractAddress
3993
+ ].includes(this.acpContractClient.config.contractAddress) && !evaluatorAddress ? this.walletAddress : import_viem4.zeroAddress;
3994
+ const createJobPayload = [
4297
3995
  baseSepoliaAcpConfig.contractAddress,
4298
3996
  baseAcpConfig.contractAddress
4299
3997
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
4300
3998
  providerAddress,
4301
- evaluatorAddress || this.walletAddress,
3999
+ evaluatorAddress || defaultEvaluatorAddress,
4302
4000
  expiredAt,
4303
4001
  fareAmount.fare.contractAddress,
4304
4002
  fareAmount.amount,
@@ -4306,182 +4004,39 @@ var AcpClient = class {
4306
4004
  ) : yield this.acpContractClient.createJobWithAccount(
4307
4005
  account.id,
4308
4006
  providerAddress,
4309
- evaluatorAddress || this.walletAddress,
4007
+ evaluatorAddress || defaultEvaluatorAddress,
4310
4008
  fareAmount.amount,
4311
4009
  fareAmount.fare.contractAddress,
4312
4010
  expiredAt
4313
4011
  );
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 */
4012
+ const txHash = yield this.acpContractClient.handleOperation([
4013
+ createJobPayload
4014
+ ]);
4015
+ const jobId = yield this.acpContractClient.getJobId(
4016
+ txHash,
4017
+ this.walletAddress,
4018
+ providerAddress
4385
4019
  );
4386
- });
4387
- }
4388
- requestFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
4389
- return __async(this, null, function* () {
4390
- return yield this.acpContractClient.createPayableMemo(
4020
+ const payloads = [];
4021
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4391
4022
  jobId,
4392
- JSON.stringify(reason),
4393
- transferFareAmount.amount,
4394
- recipient,
4395
- feeFareAmount.amount,
4396
- feeType,
4397
- nextPhase,
4398
- 6 /* PAYABLE_REQUEST */,
4399
- expiredAt
4023
+ fareAmount.amount,
4024
+ fareAmount.fare.contractAddress
4400
4025
  );
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);
4026
+ if (setBudgetWithPaymentTokenPayload) {
4027
+ payloads.push(setBudgetWithPaymentTokenPayload);
4407
4028
  }
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 */
4029
+ payloads.push(
4030
+ this.acpContractClient.createMemo(
4031
+ jobId,
4032
+ preparePayload(serviceRequirement),
4033
+ 0 /* MESSAGE */,
4034
+ true,
4035
+ 1 /* NEGOTIATION */
4036
+ )
4484
4037
  );
4038
+ yield this.acpContractClient.handleOperation(payloads);
4039
+ return jobId;
4485
4040
  });
4486
4041
  }
4487
4042
  getActiveJobs(page = 1, pageSize = 10) {
@@ -4811,7 +4366,7 @@ var acpClient_default = AcpClient;
4811
4366
  var import_core = require("@aa-sdk/core");
4812
4367
  var import_infra2 = require("@account-kit/infra");
4813
4368
  var import_smart_contracts = require("@account-kit/smart-contracts");
4814
- var import_viem4 = require("viem");
4369
+ var import_viem5 = require("viem");
4815
4370
  var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_default {
4816
4371
  constructor(agentWalletAddress, config = baseAcpConfig) {
4817
4372
  super(agentWalletAddress, config);
@@ -4866,14 +4421,14 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4866
4421
  return finalMaxFeePerGas;
4867
4422
  });
4868
4423
  }
4869
- handleOperation(_0) {
4870
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
4424
+ handleOperation(operations) {
4425
+ return __async(this, null, function* () {
4871
4426
  const payload = {
4872
- uo: {
4873
- target: contractAddress,
4874
- data,
4875
- value
4876
- },
4427
+ uo: operations.map((op) => ({
4428
+ target: op.contractAddress,
4429
+ data: op.data,
4430
+ value: op.value
4431
+ })),
4877
4432
  overrides: {
4878
4433
  nonceKey: this.getRandomNonce()
4879
4434
  }
@@ -4914,7 +4469,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4914
4469
  const contractLogs = result.logs.filter((log) => {
4915
4470
  return log.address.toLowerCase() === this.contractAddress.toLowerCase();
4916
4471
  }).map(
4917
- (log) => (0, import_viem4.decodeEventLog)({
4472
+ (log) => (0, import_viem5.decodeEventLog)({
4918
4473
  abi: this.abi,
4919
4474
  data: log.data,
4920
4475
  topics: log.topics
@@ -4930,68 +4485,73 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4930
4485
  });
4931
4486
  }
4932
4487
  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
- });
4488
+ try {
4489
+ const data = (0, import_viem5.encodeFunctionData)({
4490
+ abi: this.abi,
4491
+ functionName: "createJob",
4492
+ args: [
4493
+ providerAddress,
4494
+ evaluatorAddress,
4495
+ Math.floor(expireAt.getTime() / 1e3)
4496
+ ]
4497
+ });
4498
+ const payload = {
4499
+ data,
4500
+ contractAddress: this.contractAddress
4501
+ };
4502
+ return payload;
4503
+ } catch (error) {
4504
+ throw new acpError_default("Failed to create job", error);
4505
+ }
4960
4506
  }
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
- });
4507
+ setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
4508
+ try {
4509
+ const data = (0, import_viem5.encodeFunctionData)({
4510
+ abi: this.abi,
4511
+ functionName: "setBudgetWithPaymentToken",
4512
+ args: [jobId, budgetBaseUnit, paymentTokenAddress]
4513
+ });
4514
+ const payload = {
4515
+ data,
4516
+ contractAddress: this.contractAddress
4517
+ };
4518
+ return payload;
4519
+ } catch (error) {
4520
+ throw new acpError_default("Failed to set budget", error);
4521
+ }
4522
+ }
4523
+ createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
4524
+ try {
4525
+ const data = (0, import_viem5.encodeFunctionData)({
4526
+ abi: this.abi,
4527
+ functionName: "createPayableMemo",
4528
+ args: [
4529
+ jobId,
4530
+ content,
4531
+ token,
4532
+ amountBaseUnit,
4533
+ recipient,
4534
+ feeAmountBaseUnit,
4535
+ feeType,
4536
+ type,
4537
+ nextPhase,
4538
+ Math.floor(expiredAt.getTime() / 1e3)
4539
+ ]
4540
+ });
4541
+ const payload = {
4542
+ data,
4543
+ contractAddress: this.contractAddress
4544
+ };
4545
+ return payload;
4546
+ } catch (error) {
4547
+ throw new acpError_default("Failed to create payable memo", error);
4548
+ }
4985
4549
  }
4986
4550
  createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4987
- return __async(this, null, function* () {
4988
- throw new acpError_default("Not Supported");
4989
- });
4551
+ throw new acpError_default("Not Supported");
4990
4552
  }
4991
4553
  updateAccountMetadata(accountId, metadata) {
4992
- return __async(this, null, function* () {
4993
- throw new acpError_default("Not Supported");
4994
- });
4554
+ throw new acpError_default("Not Supported");
4995
4555
  }
4996
4556
  };
4997
4557
  var acpContractClient_default = AcpContractClient;
@@ -5000,7 +4560,7 @@ var acpContractClient_default = AcpContractClient;
5000
4560
  var import_core2 = require("@aa-sdk/core");
5001
4561
  var import_infra3 = require("@account-kit/infra");
5002
4562
  var import_smart_contracts2 = require("@account-kit/smart-contracts");
5003
- var import_viem5 = require("viem");
4563
+ var import_viem6 = require("viem");
5004
4564
 
5005
4565
  // src/abis/jobManagerAbi.ts
5006
4566
  var JOB_MANAGER_ABI = [
@@ -5874,9 +5434,9 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5874
5434
  }
5875
5435
  static build(_0, _1, _2) {
5876
5436
  return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfigV2) {
5877
- const publicClient = (0, import_viem5.createPublicClient)({
5437
+ const publicClient = (0, import_viem6.createPublicClient)({
5878
5438
  chain: config.chain,
5879
- transport: (0, import_viem5.http)(config.rpcEndpoint)
5439
+ transport: (0, import_viem6.http)(config.rpcEndpoint)
5880
5440
  });
5881
5441
  const [jobManagerAddress, memoManagerAddress, accountManagerAddress] = yield publicClient.multicall({
5882
5442
  contracts: [
@@ -5952,14 +5512,14 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5952
5512
  return finalMaxFeePerGas;
5953
5513
  });
5954
5514
  }
5955
- handleOperation(_0) {
5956
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
5515
+ handleOperation(operations) {
5516
+ return __async(this, null, function* () {
5957
5517
  const payload = {
5958
- uo: {
5959
- target: contractAddress,
5960
- data,
5961
- value
5962
- },
5518
+ uo: operations.map((operation) => ({
5519
+ target: operation.contractAddress,
5520
+ data: operation.data,
5521
+ value: operation.value
5522
+ })),
5963
5523
  overrides: {
5964
5524
  nonceKey: this.getRandomNonce()
5965
5525
  }
@@ -5976,7 +5536,13 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5976
5536
  }
5977
5537
  const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
5978
5538
  yield this.sessionKeyClient.waitForUserOperationTransaction({
5979
- hash
5539
+ hash,
5540
+ tag: "pending",
5541
+ retries: {
5542
+ intervalMs: 200,
5543
+ multiplier: 1.1,
5544
+ maxRetries: 10
5545
+ }
5980
5546
  });
5981
5547
  return hash;
5982
5548
  } catch (error) {
@@ -5993,14 +5559,17 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5993
5559
  }
5994
5560
  getJobId(hash, clientAddress, providerAddress) {
5995
5561
  return __async(this, null, function* () {
5996
- const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
5562
+ const result = yield this.sessionKeyClient.getUserOperationReceipt(
5563
+ hash,
5564
+ "pending"
5565
+ );
5997
5566
  if (!result) {
5998
5567
  throw new acpError_default("Failed to get user operation receipt");
5999
5568
  }
6000
5569
  const contractLogs = result.logs.filter((log) => {
6001
5570
  return log.address.toLowerCase() === this.jobManagerAddress.toLowerCase();
6002
5571
  }).map(
6003
- (log) => (0, import_viem5.decodeEventLog)({
5572
+ (log) => (0, import_viem6.decodeEventLog)({
6004
5573
  abi: jobManagerAbi_default,
6005
5574
  data: log.data,
6006
5575
  topics: log.topics