@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.mjs CHANGED
@@ -28,7 +28,7 @@ var require_package = __commonJS({
28
28
  "package.json"(exports, module) {
29
29
  module.exports = {
30
30
  name: "@virtuals-protocol/acp-node",
31
- version: "0.3.0-beta.3",
31
+ version: "0.3.0-beta.5",
32
32
  main: "./dist/index.js",
33
33
  module: "./dist/index.mjs",
34
34
  types: "./dist/index.d.ts",
@@ -43,9 +43,9 @@ var require_package = __commonJS({
43
43
  typescript: "^5.8.3"
44
44
  },
45
45
  dependencies: {
46
- "@aa-sdk/core": "^4.30.0",
47
- "@account-kit/infra": "^4.30.0",
48
- "@account-kit/smart-contracts": "^4.30.0",
46
+ "@aa-sdk/core": "^4.73.0",
47
+ "@account-kit/infra": "^4.73.0",
48
+ "@account-kit/smart-contracts": "^4.73.0",
49
49
  ajv: "^8.17.1",
50
50
  "socket.io-client": "^4.8.1",
51
51
  tsup: "^8.5.0",
@@ -1832,6 +1832,7 @@ var ACP_ABI = [
1832
1832
  var acpAbi_default = ACP_ABI;
1833
1833
 
1834
1834
  // src/acpClient.ts
1835
+ import { zeroAddress as zeroAddress2 } from "viem";
1835
1836
  import { io } from "socket.io-client";
1836
1837
 
1837
1838
  // src/contractClients/baseAcpContractClient.ts
@@ -3014,171 +3015,160 @@ var BaseAcpContractClient = class {
3014
3015
  return this.agentWalletAddress;
3015
3016
  }
3016
3017
  createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
3017
- return __async(this, null, function* () {
3018
- try {
3019
- const data = encodeFunctionData({
3020
- abi: this.abi,
3021
- functionName: "createJobWithAccount",
3022
- args: [
3023
- accountId,
3024
- evaluatorAddress,
3025
- budgetBaseUnit,
3026
- paymentTokenAddress,
3027
- Math.floor(expiredAt.getTime() / 1e3)
3028
- ]
3029
- });
3030
- const hash = yield this.handleOperation(data, this.contractAddress);
3031
- const jobId = yield this.getJobId(
3032
- hash,
3033
- this.agentWalletAddress,
3034
- providerAddress
3035
- );
3036
- return { txHash: hash, jobId };
3037
- } catch (error) {
3038
- throw new acpError_default("Failed to create job with account", error);
3039
- }
3040
- });
3018
+ try {
3019
+ const data = encodeFunctionData({
3020
+ abi: this.abi,
3021
+ functionName: "createJobWithAccount",
3022
+ args: [
3023
+ accountId,
3024
+ evaluatorAddress,
3025
+ budgetBaseUnit,
3026
+ paymentTokenAddress,
3027
+ Math.floor(expiredAt.getTime() / 1e3)
3028
+ ]
3029
+ });
3030
+ const payload = {
3031
+ data,
3032
+ contractAddress: this.contractAddress
3033
+ };
3034
+ return payload;
3035
+ } catch (error) {
3036
+ throw new acpError_default("Failed to create job with account", error);
3037
+ }
3041
3038
  }
3042
3039
  createJob(providerAddress, evaluatorAddress, expiredAt, paymentTokenAddress, budgetBaseUnit, metadata) {
3043
- return __async(this, null, function* () {
3044
- try {
3045
- const data = encodeFunctionData({
3046
- abi: this.abi,
3047
- functionName: "createJob",
3048
- args: [
3049
- providerAddress,
3050
- evaluatorAddress,
3051
- Math.floor(expiredAt.getTime() / 1e3),
3052
- paymentTokenAddress,
3053
- budgetBaseUnit,
3054
- metadata
3055
- ]
3056
- });
3057
- const hash = yield this.handleOperation(data, this.contractAddress);
3058
- const jobId = yield this.getJobId(
3059
- hash,
3060
- this.agentWalletAddress,
3061
- providerAddress
3062
- );
3063
- return { txHash: hash, jobId };
3064
- } catch (error) {
3065
- throw new acpError_default("Failed to create job", error);
3066
- }
3067
- });
3040
+ try {
3041
+ const data = encodeFunctionData({
3042
+ abi: this.abi,
3043
+ functionName: "createJob",
3044
+ args: [
3045
+ providerAddress,
3046
+ evaluatorAddress,
3047
+ Math.floor(expiredAt.getTime() / 1e3),
3048
+ paymentTokenAddress,
3049
+ budgetBaseUnit,
3050
+ metadata
3051
+ ]
3052
+ });
3053
+ const payload = {
3054
+ data,
3055
+ contractAddress: this.contractAddress
3056
+ };
3057
+ return payload;
3058
+ } catch (error) {
3059
+ throw new acpError_default("Failed to create job", error);
3060
+ }
3068
3061
  }
3069
- approveAllowance(_0) {
3070
- return __async(this, arguments, function* (amountBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3071
- try {
3072
- const data = encodeFunctionData({
3073
- abi: erc20Abi2,
3074
- functionName: "approve",
3075
- args: [this.contractAddress, amountBaseUnit]
3076
- });
3077
- return yield this.handleOperation(data, paymentTokenAddress);
3078
- } catch (error) {
3079
- throw new acpError_default("Failed to approve allowance", error);
3080
- }
3081
- });
3062
+ approveAllowance(amountBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3063
+ try {
3064
+ const data = encodeFunctionData({
3065
+ abi: erc20Abi2,
3066
+ functionName: "approve",
3067
+ args: [this.contractAddress, amountBaseUnit]
3068
+ });
3069
+ const payload = {
3070
+ data,
3071
+ contractAddress: paymentTokenAddress
3072
+ };
3073
+ return payload;
3074
+ } catch (error) {
3075
+ throw new acpError_default("Failed to approve allowance", error);
3076
+ }
3082
3077
  }
3083
- createPayableMemo(_0, _1, _2, _3, _4, _5, _6, _7, _8) {
3084
- return __async(this, arguments, function* (jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
3085
- try {
3086
- const data = encodeFunctionData({
3087
- abi: this.abi,
3088
- functionName: "createPayableMemo",
3089
- args: [
3090
- jobId,
3091
- content,
3092
- token,
3093
- amountBaseUnit,
3094
- recipient,
3095
- feeAmountBaseUnit,
3096
- feeType,
3097
- type,
3098
- Math.floor(expiredAt.getTime() / 1e3),
3099
- secured,
3100
- nextPhase
3101
- ]
3102
- });
3103
- return yield this.handleOperation(data, this.contractAddress);
3104
- } catch (error) {
3105
- throw new acpError_default("Failed to create payable memo", error);
3106
- }
3107
- });
3078
+ createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
3079
+ try {
3080
+ const data = encodeFunctionData({
3081
+ abi: this.abi,
3082
+ functionName: "createPayableMemo",
3083
+ args: [
3084
+ jobId,
3085
+ content,
3086
+ token,
3087
+ amountBaseUnit,
3088
+ recipient,
3089
+ feeAmountBaseUnit,
3090
+ feeType,
3091
+ type,
3092
+ Math.floor(expiredAt.getTime() / 1e3),
3093
+ secured,
3094
+ nextPhase
3095
+ ]
3096
+ });
3097
+ const payload = {
3098
+ data,
3099
+ contractAddress: this.contractAddress
3100
+ };
3101
+ return payload;
3102
+ } catch (error) {
3103
+ throw new acpError_default("Failed to create payable memo", error);
3104
+ }
3108
3105
  }
3109
3106
  createMemo(jobId, content, type, isSecured, nextPhase) {
3110
- return __async(this, null, function* () {
3111
- try {
3112
- const data = encodeFunctionData({
3113
- abi: this.abi,
3114
- functionName: "createMemo",
3115
- args: [jobId, content, type, isSecured, nextPhase]
3116
- });
3117
- return yield this.handleOperation(data, this.contractAddress);
3118
- } catch (error) {
3119
- throw new acpError_default("Failed to create memo", error);
3120
- }
3121
- });
3107
+ try {
3108
+ const data = encodeFunctionData({
3109
+ abi: this.abi,
3110
+ functionName: "createMemo",
3111
+ args: [jobId, content, type, isSecured, nextPhase]
3112
+ });
3113
+ const payload = {
3114
+ data,
3115
+ contractAddress: this.contractAddress
3116
+ };
3117
+ return payload;
3118
+ } catch (error) {
3119
+ throw new acpError_default("Failed to create memo", error);
3120
+ }
3122
3121
  }
3123
3122
  signMemo(memoId, isApproved, reason) {
3124
- return __async(this, null, function* () {
3125
- try {
3126
- const data = encodeFunctionData({
3127
- abi: this.abi,
3128
- functionName: "signMemo",
3129
- args: [memoId, isApproved, reason]
3130
- });
3131
- const hash = yield this.handleOperation(data, this.contractAddress);
3132
- return hash;
3133
- } catch (error) {
3134
- throw new acpError_default("Failed to sign memo", error);
3135
- }
3136
- });
3123
+ try {
3124
+ const data = encodeFunctionData({
3125
+ abi: this.abi,
3126
+ functionName: "signMemo",
3127
+ args: [memoId, isApproved, reason]
3128
+ });
3129
+ const payload = {
3130
+ data,
3131
+ contractAddress: this.contractAddress
3132
+ };
3133
+ return payload;
3134
+ } catch (error) {
3135
+ throw new acpError_default("Failed to sign memo", error);
3136
+ }
3137
3137
  }
3138
- setBudgetWithPaymentToken(_0, _1) {
3139
- return __async(this, arguments, function* (jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3140
- try {
3141
- const data = encodeFunctionData({
3142
- abi: this.abi,
3143
- functionName: "setBudgetWithPaymentToken",
3144
- args: [jobId, budgetBaseUnit, paymentTokenAddress]
3145
- });
3146
- return yield this.handleOperation(data, this.contractAddress);
3147
- } catch (error) {
3148
- throw new acpError_default("Failed to set budget", error);
3149
- }
3150
- });
3138
+ setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
3139
+ return void 0;
3151
3140
  }
3152
3141
  updateAccountMetadata(accountId, metadata) {
3153
- return __async(this, null, function* () {
3154
- try {
3155
- const data = encodeFunctionData({
3156
- abi: this.abi,
3157
- functionName: "updateAccountMetadata",
3158
- args: [accountId, metadata]
3159
- });
3160
- return yield this.handleOperation(data, this.contractAddress);
3161
- } catch (error) {
3162
- throw new acpError_default("Failed to update account metadata", error);
3163
- }
3164
- });
3142
+ try {
3143
+ const data = encodeFunctionData({
3144
+ abi: this.abi,
3145
+ functionName: "updateAccountMetadata",
3146
+ args: [accountId, metadata]
3147
+ });
3148
+ const payload = {
3149
+ data,
3150
+ contractAddress: this.contractAddress
3151
+ };
3152
+ return payload;
3153
+ } catch (error) {
3154
+ throw new acpError_default("Failed to update account metadata", error);
3155
+ }
3165
3156
  }
3166
3157
  wrapEth(amountBaseUnit) {
3167
- return __async(this, null, function* () {
3168
- try {
3169
- const data = encodeFunctionData({
3170
- abi: wethAbi_default,
3171
- functionName: "deposit"
3172
- });
3173
- return yield this.handleOperation(
3174
- data,
3175
- wethFare.contractAddress,
3176
- amountBaseUnit
3177
- );
3178
- } catch (error) {
3179
- throw new acpError_default("Failed to wrap eth", error);
3180
- }
3181
- });
3158
+ try {
3159
+ const data = encodeFunctionData({
3160
+ abi: wethAbi_default,
3161
+ functionName: "deposit"
3162
+ });
3163
+ const payload = {
3164
+ data,
3165
+ contractAddress: wethFare.contractAddress,
3166
+ value: amountBaseUnit
3167
+ };
3168
+ return payload;
3169
+ } catch (error) {
3170
+ throw new acpError_default("Failed to wrap eth", error);
3171
+ }
3182
3172
  }
3183
3173
  };
3184
3174
  var baseAcpContractClient_default = BaseAcpContractClient;
@@ -3292,9 +3282,7 @@ var AcpJob = class {
3292
3282
  if (requestMemo) {
3293
3283
  return requestMemo.signedReason;
3294
3284
  }
3295
- return (_a = this.memos.find(
3296
- (m) => m.nextPhase === 5 /* REJECTED */
3297
- )) == null ? void 0 : _a.content;
3285
+ return (_a = this.memos.find((m) => m.nextPhase === 5 /* REJECTED */)) == null ? void 0 : _a.content;
3298
3286
  }
3299
3287
  get providerAgent() {
3300
3288
  return this.acpClient.getAgent(this.providerAddress);
@@ -3313,36 +3301,46 @@ var AcpJob = class {
3313
3301
  }
3314
3302
  createRequirement(content) {
3315
3303
  return __async(this, null, function* () {
3316
- return yield this.acpContractClient.createMemo(
3317
- this.id,
3318
- content,
3319
- 0 /* MESSAGE */,
3320
- true,
3321
- 2 /* TRANSACTION */
3304
+ const operations = [];
3305
+ operations.push(
3306
+ this.acpContractClient.createMemo(
3307
+ this.id,
3308
+ content,
3309
+ 0 /* MESSAGE */,
3310
+ true,
3311
+ 2 /* TRANSACTION */
3312
+ )
3322
3313
  );
3314
+ return yield this.acpContractClient.handleOperation(operations);
3323
3315
  });
3324
3316
  }
3325
3317
  createPayableRequirement(_0, _1, _2, _3) {
3326
3318
  return __async(this, arguments, function* (content, type, amount, recipient, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3319
+ const operations = [];
3327
3320
  if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
3328
- yield this.acpContractClient.approveAllowance(
3329
- amount.amount,
3330
- amount.fare.contractAddress
3321
+ operations.push(
3322
+ this.acpContractClient.approveAllowance(
3323
+ amount.amount,
3324
+ amount.fare.contractAddress
3325
+ )
3331
3326
  );
3332
3327
  }
3333
3328
  const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3334
- return yield this.acpContractClient.createPayableMemo(
3335
- this.id,
3336
- content,
3337
- amount.amount,
3338
- recipient,
3339
- feeAmount.amount,
3340
- 0 /* NO_FEE */,
3341
- 2 /* TRANSACTION */,
3342
- type,
3343
- expiredAt,
3344
- amount.fare.contractAddress
3329
+ operations.push(
3330
+ this.acpContractClient.createPayableMemo(
3331
+ this.id,
3332
+ content,
3333
+ amount.amount,
3334
+ recipient,
3335
+ feeAmount.amount,
3336
+ 0 /* NO_FEE */,
3337
+ 2 /* TRANSACTION */,
3338
+ type,
3339
+ expiredAt,
3340
+ amount.fare.contractAddress
3341
+ )
3345
3342
  );
3343
+ return yield this.acpContractClient.handleOperation(operations);
3346
3344
  });
3347
3345
  }
3348
3346
  payAndAcceptRequirement(reason) {
@@ -3351,8 +3349,9 @@ var AcpJob = class {
3351
3349
  (m) => m.nextPhase === 2 /* TRANSACTION */
3352
3350
  );
3353
3351
  if (!memo) {
3354
- throw new acpError_default("No transaction memo found");
3352
+ throw new acpError_default("No notification memo found");
3355
3353
  }
3354
+ const operations = [];
3356
3355
  const baseFareAmount = new FareAmount(this.price, this.baseFare);
3357
3356
  const transferAmount = memo.payableDetails ? yield FareAmountBase.fromContractAddress(
3358
3357
  memo.payableDetails.amount,
@@ -3360,24 +3359,31 @@ var AcpJob = class {
3360
3359
  this.config
3361
3360
  ) : new FareAmount(0, this.baseFare);
3362
3361
  const totalAmount = baseFareAmount.fare.contractAddress === transferAmount.fare.contractAddress ? baseFareAmount.add(transferAmount) : baseFareAmount;
3363
- yield this.acpContractClient.approveAllowance(
3364
- totalAmount.amount,
3365
- this.baseFare.contractAddress
3362
+ operations.push(
3363
+ this.acpContractClient.approveAllowance(
3364
+ totalAmount.amount,
3365
+ this.baseFare.contractAddress
3366
+ )
3366
3367
  );
3367
3368
  if (baseFareAmount.fare.contractAddress !== transferAmount.fare.contractAddress) {
3368
- yield this.acpContractClient.approveAllowance(
3369
- transferAmount.amount,
3370
- transferAmount.fare.contractAddress
3369
+ operations.push(
3370
+ this.acpContractClient.approveAllowance(
3371
+ transferAmount.amount,
3372
+ transferAmount.fare.contractAddress
3373
+ )
3371
3374
  );
3372
3375
  }
3373
- yield memo.sign(true, reason);
3374
- return yield this.acpContractClient.createMemo(
3375
- this.id,
3376
- `Payment made. ${reason != null ? reason : ""}`.trim(),
3377
- 0 /* MESSAGE */,
3378
- true,
3379
- 3 /* EVALUATION */
3376
+ operations.push(this.acpContractClient.signMemo(memo.id, true, reason));
3377
+ operations.push(
3378
+ this.acpContractClient.createMemo(
3379
+ this.id,
3380
+ `Payment made. ${reason != null ? reason : ""}`.trim(),
3381
+ 0 /* MESSAGE */,
3382
+ true,
3383
+ 3 /* EVALUATION */
3384
+ )
3380
3385
  );
3386
+ return yield this.acpContractClient.handleOperation(operations);
3381
3387
  });
3382
3388
  }
3383
3389
  respond(accept, reason) {
@@ -3385,7 +3391,7 @@ var AcpJob = class {
3385
3391
  const memoContent = `${reason || `Job ${this.id} ${accept ? "accepted" : "rejected"}.`}`;
3386
3392
  if (accept) {
3387
3393
  yield this.accept(memoContent);
3388
- return this.createRequirement(memoContent);
3394
+ return yield this.createRequirement(memoContent);
3389
3395
  }
3390
3396
  return yield this.reject(memoContent);
3391
3397
  });
@@ -3394,31 +3400,42 @@ var AcpJob = class {
3394
3400
  return __async(this, null, function* () {
3395
3401
  var _a;
3396
3402
  const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
3403
+ const operations = [];
3397
3404
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3398
- throw new acpError_default("No negotiation memo found");
3405
+ throw new acpError_default("No request memo found");
3399
3406
  }
3400
3407
  const memo = this.latestMemo;
3401
- yield memo.sign(true, memoContent);
3408
+ operations.push(
3409
+ this.acpContractClient.signMemo(memo.id, true, memoContent)
3410
+ );
3411
+ return yield this.acpContractClient.handleOperation(operations);
3402
3412
  });
3403
3413
  }
3404
3414
  reject(reason) {
3405
3415
  return __async(this, null, function* () {
3406
3416
  var _a;
3407
3417
  const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
3418
+ const operations = [];
3408
3419
  if (this.phase === 0 /* REQUEST */) {
3409
3420
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3410
3421
  throw new acpError_default("No request memo found");
3411
3422
  }
3412
3423
  const memo = this.latestMemo;
3413
- return yield this.acpContractClient.signMemo(memo.id, false, memoContent);
3424
+ operations.push(
3425
+ this.acpContractClient.signMemo(memo.id, false, memoContent)
3426
+ );
3427
+ return yield this.acpContractClient.handleOperation(operations);
3414
3428
  }
3415
- return yield this.acpContractClient.createMemo(
3416
- this.id,
3417
- memoContent,
3418
- 0 /* MESSAGE */,
3419
- true,
3420
- 5 /* REJECTED */
3429
+ operations.push(
3430
+ this.acpContractClient.createMemo(
3431
+ this.id,
3432
+ memoContent,
3433
+ 0 /* MESSAGE */,
3434
+ true,
3435
+ 5 /* REJECTED */
3436
+ )
3421
3437
  );
3438
+ return yield this.acpContractClient.handleOperation(operations);
3422
3439
  });
3423
3440
  }
3424
3441
  deliver(deliverable) {
@@ -3427,13 +3444,17 @@ var AcpJob = class {
3427
3444
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3428
3445
  throw new acpError_default("No transaction memo found");
3429
3446
  }
3430
- return yield this.acpContractClient.createMemo(
3431
- this.id,
3432
- preparePayload(deliverable),
3433
- 0 /* MESSAGE */,
3434
- true,
3435
- 4 /* COMPLETED */
3447
+ const operations = [];
3448
+ operations.push(
3449
+ this.acpContractClient.createMemo(
3450
+ this.id,
3451
+ preparePayload(deliverable),
3452
+ 0 /* MESSAGE */,
3453
+ true,
3454
+ 4 /* COMPLETED */
3455
+ )
3436
3456
  );
3457
+ return yield this.acpContractClient.handleOperation(operations);
3437
3458
  });
3438
3459
  }
3439
3460
  deliverPayable(_0, _1) {
@@ -3442,23 +3463,29 @@ var AcpJob = class {
3442
3463
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3443
3464
  throw new acpError_default("No transaction memo found");
3444
3465
  }
3445
- yield this.acpContractClient.approveAllowance(
3446
- amount.amount,
3447
- amount.fare.contractAddress
3466
+ const operations = [];
3467
+ operations.push(
3468
+ this.acpContractClient.approveAllowance(
3469
+ amount.amount,
3470
+ amount.fare.contractAddress
3471
+ )
3448
3472
  );
3449
3473
  const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3450
- return yield this.acpContractClient.createPayableMemo(
3451
- this.id,
3452
- preparePayload(deliverable),
3453
- amount.amount,
3454
- this.clientAddress,
3455
- feeAmount.amount,
3456
- 0 /* NO_FEE */,
3457
- 4 /* COMPLETED */,
3458
- 7 /* PAYABLE_TRANSFER */,
3459
- expiredAt,
3460
- amount.fare.contractAddress
3474
+ operations.push(
3475
+ this.acpContractClient.createPayableMemo(
3476
+ this.id,
3477
+ preparePayload(deliverable),
3478
+ amount.amount,
3479
+ this.clientAddress,
3480
+ feeAmount.amount,
3481
+ 0 /* NO_FEE */,
3482
+ 4 /* COMPLETED */,
3483
+ 7 /* PAYABLE_TRANSFER */,
3484
+ expiredAt,
3485
+ amount.fare.contractAddress
3486
+ )
3461
3487
  );
3488
+ return yield this.acpContractClient.handleOperation(operations);
3462
3489
  });
3463
3490
  }
3464
3491
  evaluate(accept, reason) {
@@ -3471,419 +3498,46 @@ var AcpJob = class {
3471
3498
  yield memo.sign(accept, reason);
3472
3499
  });
3473
3500
  }
3474
- pay(reason) {
3475
- return __async(this, null, function* () {
3476
- const memo = this.memos.find(
3477
- (m) => m.nextPhase === 2 /* TRANSACTION */
3478
- );
3479
- if (!memo) {
3480
- throw new acpError_default("No transaction memo found");
3481
- }
3482
- return yield this.acpClient.payJob(
3483
- this.id,
3484
- this.baseFare.formatAmount(this.price),
3485
- memo.id,
3486
- reason
3487
- );
3488
- });
3489
- }
3490
3501
  createNotification(content) {
3491
3502
  return __async(this, null, function* () {
3492
- return yield this.acpContractClient.createMemo(
3493
- this.id,
3494
- content,
3495
- 9 /* NOTIFICATION */,
3496
- true,
3497
- 4 /* COMPLETED */
3503
+ const operations = [];
3504
+ operations.push(
3505
+ this.acpContractClient.createMemo(
3506
+ this.id,
3507
+ content,
3508
+ 9 /* NOTIFICATION */,
3509
+ true,
3510
+ 4 /* COMPLETED */
3511
+ )
3498
3512
  );
3513
+ return yield this.acpContractClient.handleOperation(operations);
3499
3514
  });
3500
3515
  }
3501
3516
  createPayableNotification(_0, _1) {
3502
3517
  return __async(this, arguments, function* (content, amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3503
- yield this.acpContractClient.approveAllowance(
3504
- amount.amount,
3505
- amount.fare.contractAddress
3518
+ const operations = [];
3519
+ operations.push(
3520
+ this.acpContractClient.approveAllowance(
3521
+ amount.amount,
3522
+ amount.fare.contractAddress
3523
+ )
3506
3524
  );
3507
3525
  const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3508
- return yield this.acpContractClient.createPayableMemo(
3509
- this.id,
3510
- content,
3511
- amount.amount,
3512
- this.clientAddress,
3513
- feeAmount.amount,
3514
- 0 /* NO_FEE */,
3515
- 4 /* COMPLETED */,
3516
- 10 /* PAYABLE_NOTIFICATION */,
3517
- expiredAt,
3518
- amount.fare.contractAddress
3519
- );
3520
- });
3521
- }
3522
- // to be deprecated
3523
- /**
3524
- * @deprecated The method should not be used
3525
- */
3526
- openPosition(_0, _1) {
3527
- return __async(this, arguments, function* (payload, feeAmount, expiredAt = new Date(Date.now() + 1e3 * 60 * 3), walletAddress) {
3528
- if (payload.length === 0) {
3529
- throw new acpError_default("No positions to open");
3530
- }
3531
- const sumAmount = payload.reduce((acc, curr) => acc + curr.amount, 0);
3532
- return yield this.acpClient.transferFunds(
3533
- this.id,
3534
- new FareAmount(sumAmount, this.baseFare),
3535
- walletAddress || this.providerAddress,
3536
- new FareAmount(feeAmount, this.baseFare),
3537
- 1 /* IMMEDIATE_FEE */,
3538
- {
3539
- type: "open_position" /* OPEN_POSITION */,
3540
- data: payload
3541
- },
3542
- 2 /* TRANSACTION */,
3543
- expiredAt
3544
- );
3545
- });
3546
- }
3547
- /**
3548
- * @deprecated The method should not be used
3549
- */
3550
- swapToken(payload, decimals, feeAmount, walletAddress) {
3551
- return __async(this, null, function* () {
3552
- return yield this.acpClient.transferFunds(
3553
- this.id,
3554
- new FareAmount(
3555
- payload.amount,
3556
- new Fare(payload.fromContractAddress, decimals)
3557
- ),
3558
- walletAddress || this.providerAddress,
3559
- new FareAmount(feeAmount, this.baseFare),
3560
- 1 /* IMMEDIATE_FEE */,
3561
- {
3562
- type: "swap_token" /* SWAP_TOKEN */,
3563
- data: payload
3564
- },
3565
- 2 /* TRANSACTION */,
3566
- new Date(Date.now() + 1e3 * 60 * 30)
3567
- );
3568
- });
3569
- }
3570
- /**
3571
- * @deprecated The method should not be used
3572
- */
3573
- responseSwapToken(memoId, accept, reason) {
3574
- return __async(this, null, function* () {
3575
- const memo = this.memos.find((m) => m.id === memoId);
3576
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3577
- throw new acpError_default("No swap token memo found");
3578
- }
3579
- const payload = tryParseJson(
3580
- memo.content
3581
- );
3582
- if ((payload == null ? void 0 : payload.type) !== "swap_token" /* SWAP_TOKEN */) {
3583
- throw new acpError_default("Invalid swap token memo");
3584
- }
3585
- return yield memo.sign(accept, reason);
3586
- });
3587
- }
3588
- /**
3589
- * @deprecated The method should not be used
3590
- */
3591
- transferFunds(_0, _1, _2) {
3592
- return __async(this, arguments, function* (payload, fareAmount, walletAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 30)) {
3593
- return yield this.acpClient.transferFunds(
3594
- this.id,
3595
- fareAmount,
3596
- walletAddress || this.clientAddress,
3597
- new FareAmount(0, this.baseFare),
3598
- 0 /* NO_FEE */,
3599
- payload,
3600
- 2 /* TRANSACTION */,
3601
- expiredAt
3602
- );
3603
- });
3604
- }
3605
- /**
3606
- * @deprecated The method should not be used
3607
- */
3608
- responseOpenPosition(memoId, accept, reason) {
3609
- return __async(this, null, function* () {
3610
- const memo = this.memos.find((m) => m.id === memoId);
3611
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3612
- throw new acpError_default("No open position memo found");
3613
- }
3614
- const payload = tryParseJson(
3615
- memo.content
3616
- );
3617
- if ((payload == null ? void 0 : payload.type) !== "open_position" /* OPEN_POSITION */) {
3618
- throw new acpError_default("Invalid open position memo");
3619
- }
3620
- return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
3621
- });
3622
- }
3623
- /**
3624
- * @deprecated The method should not be used
3625
- */
3626
- closePartialPosition(_0) {
3627
- return __async(this, arguments, function* (payload, expireAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3628
- return yield this.acpClient.requestFunds(
3629
- this.id,
3630
- new FareAmount(payload.amount, this.baseFare),
3631
- this.clientAddress,
3632
- new FareAmount(0, this.baseFare),
3633
- 0 /* NO_FEE */,
3634
- {
3635
- type: "close_partial_position" /* CLOSE_PARTIAL_POSITION */,
3636
- data: payload
3637
- },
3638
- 2 /* TRANSACTION */,
3639
- expireAt
3640
- );
3641
- });
3642
- }
3643
- /**
3644
- * @deprecated The method should not be used
3645
- */
3646
- responseClosePartialPosition(memoId, accept, reason) {
3647
- return __async(this, null, function* () {
3648
- const memo = this.memos.find((m) => m.id === memoId);
3649
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 6 /* PAYABLE_REQUEST */) {
3650
- throw new acpError_default("No close position memo found");
3651
- }
3652
- const payload = tryParseJson(
3653
- memo.content
3654
- );
3655
- if ((payload == null ? void 0 : payload.type) !== "close_partial_position" /* CLOSE_PARTIAL_POSITION */) {
3656
- throw new acpError_default("Invalid close position memo");
3657
- }
3658
- return yield this.acpClient.responseFundsRequest(
3659
- memo.id,
3660
- accept,
3661
- this.baseFare.formatAmount(payload.data.amount),
3662
- reason
3663
- );
3664
- });
3665
- }
3666
- /**
3667
- * @deprecated The method should not be used
3668
- */
3669
- requestClosePosition(payload) {
3670
- return __async(this, null, function* () {
3671
- return yield this.acpClient.sendMessage(
3672
- this.id,
3673
- {
3674
- type: "close_position" /* CLOSE_POSITION */,
3675
- data: payload
3676
- },
3677
- 2 /* TRANSACTION */
3678
- );
3679
- });
3680
- }
3681
- /**
3682
- * @deprecated The method should not be used
3683
- */
3684
- responseRequestClosePosition(_0, _1, _2, _3) {
3685
- return __async(this, arguments, function* (memoId, accept, payload, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3686
- const memo = this.memos.find((m) => m.id === memoId);
3687
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
3688
- throw new acpError_default("No message memo found");
3689
- }
3690
- const messagePayload = tryParseJson(memo.content);
3691
- if ((messagePayload == null ? void 0 : messagePayload.type) !== "close_position" /* CLOSE_POSITION */) {
3692
- throw new acpError_default("Invalid close position memo");
3693
- }
3694
- yield memo.sign(accept, reason);
3695
- if (accept) {
3696
- return yield this.acpClient.transferFunds(
3526
+ operations.push(
3527
+ this.acpContractClient.createPayableMemo(
3697
3528
  this.id,
3698
- new FareAmount(payload.amount, this.baseFare),
3529
+ content,
3530
+ amount.amount,
3699
3531
  this.clientAddress,
3700
- new FareAmount(0, this.baseFare),
3532
+ feeAmount.amount,
3701
3533
  0 /* NO_FEE */,
3702
- {
3703
- type: "close_position" /* CLOSE_POSITION */,
3704
- data: payload
3705
- },
3706
- 2 /* TRANSACTION */,
3707
- expiredAt
3708
- );
3709
- }
3710
- });
3711
- }
3712
- /**
3713
- * @deprecated The method should not be used
3714
- */
3715
- confirmClosePosition(memoId, accept, reason) {
3716
- return __async(this, null, function* () {
3717
- const memo = this.memos.find((m) => m.id === memoId);
3718
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3719
- throw new acpError_default("No payable transfer memo found");
3720
- }
3721
- const payload = tryParseJson(
3722
- memo.content
3723
- );
3724
- if ((payload == null ? void 0 : payload.type) !== "close_position" /* CLOSE_POSITION */) {
3725
- throw new acpError_default("Invalid close position memo");
3726
- }
3727
- yield memo.sign(accept, reason);
3728
- });
3729
- }
3730
- /**
3731
- * @deprecated The method should not be used
3732
- */
3733
- positionFulfilled(_0) {
3734
- return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3735
- return yield this.acpClient.transferFunds(
3736
- this.id,
3737
- new FareAmount(payload.amount, this.baseFare),
3738
- this.clientAddress,
3739
- new FareAmount(0, this.baseFare),
3740
- 0 /* NO_FEE */,
3741
- {
3742
- type: "position_fulfilled" /* POSITION_FULFILLED */,
3743
- data: payload
3744
- },
3745
- 2 /* TRANSACTION */,
3746
- expiredAt
3747
- );
3748
- });
3749
- }
3750
- /**
3751
- * @deprecated The method should not be used
3752
- */
3753
- unfulfilledPosition(_0) {
3754
- return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3755
- return yield this.acpClient.transferFunds(
3756
- this.id,
3757
- new FareAmount(payload.amount, this.baseFare),
3758
- this.clientAddress,
3759
- new FareAmount(0, this.baseFare),
3760
- 0 /* NO_FEE */,
3761
- {
3762
- type: "unfulfilled_position" /* UNFULFILLED_POSITION */,
3763
- data: payload
3764
- },
3765
- 2 /* TRANSACTION */,
3766
- expiredAt
3767
- );
3768
- });
3769
- }
3770
- /**
3771
- * @deprecated The method should not be used
3772
- */
3773
- responseUnfulfilledPosition(memoId, accept, reason) {
3774
- return __async(this, null, function* () {
3775
- const memo = this.memos.find((m) => m.id === memoId);
3776
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3777
- throw new acpError_default("No unfulfilled position memo found");
3778
- }
3779
- const payload = tryParseJson(
3780
- memo.content
3781
- );
3782
- if ((payload == null ? void 0 : payload.type) !== "unfulfilled_position" /* UNFULFILLED_POSITION */) {
3783
- throw new acpError_default("Invalid unfulfilled position memo");
3784
- }
3785
- return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
3786
- });
3787
- }
3788
- /**
3789
- * @deprecated The method should not be used
3790
- */
3791
- responsePositionFulfilled(memoId, accept, reason) {
3792
- return __async(this, null, function* () {
3793
- const memo = this.memos.find((m) => m.id === memoId);
3794
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
3795
- throw new acpError_default("No position fulfilled memo found");
3796
- }
3797
- const payload = tryParseJson(
3798
- memo.content
3799
- );
3800
- if ((payload == null ? void 0 : payload.type) !== "position_fulfilled" /* POSITION_FULFILLED */) {
3801
- throw new acpError_default("Invalid position fulfilled memo");
3802
- }
3803
- return yield this.acpClient.responseFundsTransfer(memo.id, accept, reason);
3804
- });
3805
- }
3806
- /**
3807
- * @deprecated The method should not be used
3808
- */
3809
- closeJob(message = "Close job and withdraw all") {
3810
- return __async(this, null, function* () {
3811
- return yield this.acpClient.sendMessage(
3812
- this.id,
3813
- {
3814
- type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
3815
- data: {
3816
- message
3817
- }
3818
- },
3819
- 2 /* TRANSACTION */
3820
- );
3821
- });
3822
- }
3823
- /**
3824
- * @deprecated The method should not be used
3825
- */
3826
- responseCloseJob(_0, _1, _2, _3) {
3827
- return __async(this, arguments, function* (memoId, accept, fulfilledPositions, reason, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3828
- const memo = this.memos.find((m) => m.id === memoId);
3829
- if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 0 /* MESSAGE */) {
3830
- throw new acpError_default("No message memo found");
3831
- }
3832
- const payload = tryParseJson(
3833
- memo.content
3834
- );
3835
- if ((payload == null ? void 0 : payload.type) !== "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */) {
3836
- throw new acpError_default("Invalid close job and withdraw memo");
3837
- }
3838
- yield memo.sign(accept, reason);
3839
- if (!accept) {
3840
- return;
3841
- }
3842
- const totalAmount = fulfilledPositions.reduce(
3843
- (acc, curr) => acc + curr.amount,
3844
- 0
3845
- );
3846
- if (totalAmount === 0) {
3847
- return yield this.acpClient.sendMessage(
3848
- this.id,
3849
- {
3850
- type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
3851
- data: fulfilledPositions
3852
- },
3853
- 4 /* COMPLETED */
3854
- );
3855
- }
3856
- return yield this.acpClient.transferFunds(
3857
- this.id,
3858
- new FareAmount(totalAmount, this.baseFare),
3859
- this.clientAddress,
3860
- new FareAmount(0, this.baseFare),
3861
- 0 /* NO_FEE */,
3862
- {
3863
- type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
3864
- data: fulfilledPositions
3865
- },
3866
- 4 /* COMPLETED */,
3867
- expiredAt
3868
- );
3869
- });
3870
- }
3871
- /**
3872
- * @deprecated The method should not be used
3873
- */
3874
- confirmJobClosure(memoId, accept, reason) {
3875
- return __async(this, null, function* () {
3876
- const memo = this.memos.find((m) => m.id === memoId);
3877
- if (!memo) {
3878
- throw new acpError_default("Memo not found");
3879
- }
3880
- const payload = tryParseJson(
3881
- memo.content
3534
+ 4 /* COMPLETED */,
3535
+ 10 /* PAYABLE_NOTIFICATION */,
3536
+ expiredAt,
3537
+ amount.fare.contractAddress
3538
+ )
3882
3539
  );
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);
3540
+ return yield this.acpContractClient.handleOperation(operations);
3887
3541
  });
3888
3542
  }
3889
3543
  };
@@ -3928,7 +3582,8 @@ var AcpMemo = class {
3928
3582
  }
3929
3583
  sign(approved, reason) {
3930
3584
  return __async(this, null, function* () {
3931
- return yield this.contractClient.signMemo(this.id, approved, reason);
3585
+ const payload = this.contractClient.signMemo(this.id, approved, reason);
3586
+ return yield this.contractClient.handleOperation([payload]);
3932
3587
  });
3933
3588
  }
3934
3589
  };
@@ -3969,7 +3624,7 @@ var AcpJobOffering = class {
3969
3624
  this.providerAddress,
3970
3625
  this.acpContractClient
3971
3626
  );
3972
- const { jobId, txHash } = [
3627
+ const createJobPayload = [
3973
3628
  baseSepoliaAcpConfig.contractAddress,
3974
3629
  baseAcpConfig.contractAddress
3975
3630
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
@@ -3987,13 +3642,33 @@ var AcpJobOffering = class {
3987
3642
  fareAmount.fare.contractAddress,
3988
3643
  expiredAt
3989
3644
  );
3990
- yield this.acpContractClient.createMemo(
3645
+ const createJobTxnHash = yield this.acpContractClient.handleOperation([
3646
+ createJobPayload
3647
+ ]);
3648
+ const jobId = yield this.acpContractClient.getJobId(
3649
+ createJobTxnHash,
3650
+ this.acpContractClient.walletAddress,
3651
+ this.providerAddress
3652
+ );
3653
+ const payloads = [];
3654
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3991
3655
  jobId,
3992
- JSON.stringify(finalServiceRequirement),
3993
- 0 /* MESSAGE */,
3994
- true,
3995
- 1 /* NEGOTIATION */
3656
+ fareAmount.amount,
3657
+ fareAmount.fare.contractAddress
3996
3658
  );
3659
+ if (setBudgetWithPaymentTokenPayload) {
3660
+ payloads.push(setBudgetWithPaymentTokenPayload);
3661
+ }
3662
+ payloads.push(
3663
+ this.acpContractClient.createMemo(
3664
+ jobId,
3665
+ JSON.stringify(finalServiceRequirement),
3666
+ 0 /* MESSAGE */,
3667
+ true,
3668
+ 1 /* NEGOTIATION */
3669
+ )
3670
+ );
3671
+ yield this.acpContractClient.handleOperation(payloads);
3997
3672
  return jobId;
3998
3673
  });
3999
3674
  }
@@ -4245,12 +3920,16 @@ var AcpClient = class {
4245
3920
  providerAddress,
4246
3921
  this.acpContractClient
4247
3922
  );
4248
- const { jobId, txHash } = [
3923
+ const defaultEvaluatorAddress = [
3924
+ baseSepoliaAcpConfig.contractAddress,
3925
+ baseAcpConfig.contractAddress
3926
+ ].includes(this.acpContractClient.config.contractAddress) && !evaluatorAddress ? this.walletAddress : zeroAddress2;
3927
+ const createJobPayload = [
4249
3928
  baseSepoliaAcpConfig.contractAddress,
4250
3929
  baseAcpConfig.contractAddress
4251
3930
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
4252
3931
  providerAddress,
4253
- evaluatorAddress || this.walletAddress,
3932
+ evaluatorAddress || defaultEvaluatorAddress,
4254
3933
  expiredAt,
4255
3934
  fareAmount.fare.contractAddress,
4256
3935
  fareAmount.amount,
@@ -4258,182 +3937,39 @@ var AcpClient = class {
4258
3937
  ) : yield this.acpContractClient.createJobWithAccount(
4259
3938
  account.id,
4260
3939
  providerAddress,
4261
- evaluatorAddress || this.walletAddress,
3940
+ evaluatorAddress || defaultEvaluatorAddress,
4262
3941
  fareAmount.amount,
4263
3942
  fareAmount.fare.contractAddress,
4264
3943
  expiredAt
4265
3944
  );
4266
- yield this.acpContractClient.createMemo(
4267
- jobId,
4268
- preparePayload(serviceRequirement),
4269
- 0 /* MESSAGE */,
4270
- true,
4271
- 1 /* NEGOTIATION */
4272
- );
4273
- return jobId;
4274
- });
4275
- }
4276
- createMemo(jobId, content, nextPhase) {
4277
- return __async(this, null, function* () {
4278
- return yield this.acpContractClient.createMemo(
4279
- jobId,
4280
- content,
4281
- 0 /* MESSAGE */,
4282
- false,
4283
- nextPhase
4284
- );
4285
- });
4286
- }
4287
- createPayableMemo(jobId, content, amount, recipient, nextPhase, type, expiredAt) {
4288
- return __async(this, null, function* () {
4289
- if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
4290
- yield this.acpContractClient.approveAllowance(
4291
- amount.amount,
4292
- amount.fare.contractAddress
4293
- );
4294
- }
4295
- const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4296
- return yield this.acpContractClient.createPayableMemo(
4297
- jobId,
4298
- content,
4299
- amount.amount,
4300
- recipient,
4301
- feeAmount.amount,
4302
- 0 /* NO_FEE */,
4303
- nextPhase,
4304
- type,
4305
- expiredAt,
4306
- amount.fare.contractAddress
4307
- );
4308
- });
4309
- }
4310
- respondJob(jobId, memoId, accept, content, reason) {
4311
- return __async(this, null, function* () {
4312
- yield this.acpContractClient.signMemo(memoId, accept, reason);
4313
- if (!accept) {
4314
- return;
4315
- }
4316
- return yield this.acpContractClient.createMemo(
4317
- jobId,
4318
- content != null ? content : `Job ${jobId} accepted. ${reason != null ? reason : ""}`,
4319
- 0 /* MESSAGE */,
4320
- false,
4321
- 2 /* TRANSACTION */
4322
- );
4323
- });
4324
- }
4325
- payJob(jobId, amountBaseUnit, memoId, reason) {
4326
- return __async(this, null, function* () {
4327
- if (amountBaseUnit > BigInt(0)) {
4328
- yield this.acpContractClient.approveAllowance(amountBaseUnit);
4329
- }
4330
- yield this.acpContractClient.signMemo(memoId, true, reason);
4331
- return yield this.acpContractClient.createMemo(
4332
- jobId,
4333
- `Payment made. ${reason != null ? reason : ""}`,
4334
- 0 /* MESSAGE */,
4335
- false,
4336
- 3 /* EVALUATION */
3945
+ const txHash = yield this.acpContractClient.handleOperation([
3946
+ createJobPayload
3947
+ ]);
3948
+ const jobId = yield this.acpContractClient.getJobId(
3949
+ txHash,
3950
+ this.walletAddress,
3951
+ providerAddress
4337
3952
  );
4338
- });
4339
- }
4340
- requestFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
4341
- return __async(this, null, function* () {
4342
- return yield this.acpContractClient.createPayableMemo(
3953
+ const payloads = [];
3954
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4343
3955
  jobId,
4344
- JSON.stringify(reason),
4345
- transferFareAmount.amount,
4346
- recipient,
4347
- feeFareAmount.amount,
4348
- feeType,
4349
- nextPhase,
4350
- 6 /* PAYABLE_REQUEST */,
4351
- expiredAt
3956
+ fareAmount.amount,
3957
+ fareAmount.fare.contractAddress
4352
3958
  );
4353
- });
4354
- }
4355
- responseFundsRequest(memoId, accept, amountBaseUnit, reason) {
4356
- return __async(this, null, function* () {
4357
- if (!accept) {
4358
- return yield this.acpContractClient.signMemo(memoId, accept, reason);
4359
- }
4360
- if (amountBaseUnit > BigInt(0)) {
4361
- yield this.acpContractClient.approveAllowance(amountBaseUnit);
4362
- }
4363
- return yield this.acpContractClient.signMemo(memoId, true, reason);
4364
- });
4365
- }
4366
- transferFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
4367
- return __async(this, null, function* () {
4368
- if (transferFareAmount.fare.contractAddress === ethFare.contractAddress) {
4369
- yield this.acpContractClient.wrapEth(transferFareAmount.amount);
4370
- transferFareAmount = new FareBigInt(transferFareAmount.amount, wethFare);
4371
- }
4372
- if (feeFareAmount.amount > 0 && feeFareAmount.fare.contractAddress !== this.acpContractClient.config.baseFare.contractAddress) {
4373
- throw new acpError_default("Fee token address is not the same as the base fare");
4374
- }
4375
- const isFeeTokenDifferent = feeFareAmount.fare.contractAddress !== transferFareAmount.fare.contractAddress;
4376
- if (isFeeTokenDifferent) {
4377
- yield this.acpContractClient.approveAllowance(
4378
- feeFareAmount.amount,
4379
- feeFareAmount.fare.contractAddress
4380
- );
3959
+ if (setBudgetWithPaymentTokenPayload) {
3960
+ payloads.push(setBudgetWithPaymentTokenPayload);
4381
3961
  }
4382
- const finalAmount = isFeeTokenDifferent ? transferFareAmount : transferFareAmount.add(feeFareAmount);
4383
- yield this.acpContractClient.approveAllowance(
4384
- finalAmount.amount,
4385
- transferFareAmount.fare.contractAddress
4386
- );
4387
- return yield this.acpContractClient.createPayableMemo(
4388
- jobId,
4389
- JSON.stringify(reason),
4390
- transferFareAmount.amount,
4391
- recipient,
4392
- feeFareAmount.amount,
4393
- feeType,
4394
- nextPhase,
4395
- 8 /* PAYABLE_TRANSFER_ESCROW */,
4396
- expiredAt,
4397
- transferFareAmount.fare.contractAddress
4398
- );
4399
- });
4400
- }
4401
- sendMessage(jobId, message, nextPhase) {
4402
- return __async(this, null, function* () {
4403
- return yield this.acpContractClient.createMemo(
4404
- jobId,
4405
- JSON.stringify(message),
4406
- 0 /* MESSAGE */,
4407
- false,
4408
- nextPhase
4409
- );
4410
- });
4411
- }
4412
- responseFundsTransfer(memoId, accept, reason) {
4413
- return __async(this, null, function* () {
4414
- return yield this.acpContractClient.signMemo(memoId, accept, reason);
4415
- });
4416
- }
4417
- rejectJob(jobId, reason) {
4418
- return __async(this, null, function* () {
4419
- return yield this.acpContractClient.createMemo(
4420
- jobId,
4421
- `Job ${jobId} rejected. ${reason || ""}`,
4422
- 0 /* MESSAGE */,
4423
- false,
4424
- 5 /* REJECTED */
4425
- );
4426
- });
4427
- }
4428
- deliverJob(jobId, deliverable) {
4429
- return __async(this, null, function* () {
4430
- return yield this.acpContractClient.createMemo(
4431
- jobId,
4432
- preparePayload(deliverable),
4433
- 4 /* OBJECT_URL */,
4434
- true,
4435
- 4 /* COMPLETED */
3962
+ payloads.push(
3963
+ this.acpContractClient.createMemo(
3964
+ jobId,
3965
+ preparePayload(serviceRequirement),
3966
+ 0 /* MESSAGE */,
3967
+ true,
3968
+ 1 /* NEGOTIATION */
3969
+ )
4436
3970
  );
3971
+ yield this.acpContractClient.handleOperation(payloads);
3972
+ return jobId;
4437
3973
  });
4438
3974
  }
4439
3975
  getActiveJobs(page = 1, pageSize = 10) {
@@ -4820,14 +4356,14 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4820
4356
  return finalMaxFeePerGas;
4821
4357
  });
4822
4358
  }
4823
- handleOperation(_0) {
4824
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
4359
+ handleOperation(operations) {
4360
+ return __async(this, null, function* () {
4825
4361
  const payload = {
4826
- uo: {
4827
- target: contractAddress,
4828
- data,
4829
- value
4830
- },
4362
+ uo: operations.map((op) => ({
4363
+ target: op.contractAddress,
4364
+ data: op.data,
4365
+ value: op.value
4366
+ })),
4831
4367
  overrides: {
4832
4368
  nonceKey: this.getRandomNonce()
4833
4369
  }
@@ -4884,68 +4420,73 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4884
4420
  });
4885
4421
  }
4886
4422
  createJob(providerAddress, evaluatorAddress, expireAt, paymentTokenAddress, budgetBaseUnit, metadata) {
4887
- return __async(this, null, function* () {
4888
- try {
4889
- const data = encodeFunctionData2({
4890
- abi: this.abi,
4891
- functionName: "createJob",
4892
- args: [
4893
- providerAddress,
4894
- evaluatorAddress,
4895
- Math.floor(expireAt.getTime() / 1e3)
4896
- ]
4897
- });
4898
- const hash = yield this.handleOperation(data, this.contractAddress);
4899
- const jobId = yield this.getJobId(
4900
- hash,
4901
- this.agentWalletAddress,
4902
- providerAddress
4903
- );
4904
- yield this.setBudgetWithPaymentToken(
4905
- jobId,
4906
- budgetBaseUnit,
4907
- paymentTokenAddress
4908
- );
4909
- return { txHash: hash, jobId };
4910
- } catch (error) {
4911
- throw new acpError_default("Failed to create job", error);
4912
- }
4913
- });
4423
+ try {
4424
+ const data = encodeFunctionData2({
4425
+ abi: this.abi,
4426
+ functionName: "createJob",
4427
+ args: [
4428
+ providerAddress,
4429
+ evaluatorAddress,
4430
+ Math.floor(expireAt.getTime() / 1e3)
4431
+ ]
4432
+ });
4433
+ const payload = {
4434
+ data,
4435
+ contractAddress: this.contractAddress
4436
+ };
4437
+ return payload;
4438
+ } catch (error) {
4439
+ throw new acpError_default("Failed to create job", error);
4440
+ }
4914
4441
  }
4915
- createPayableMemo(_0, _1, _2, _3, _4, _5, _6, _7, _8) {
4916
- return __async(this, arguments, function* (jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
4917
- try {
4918
- const data = encodeFunctionData2({
4919
- abi: this.abi,
4920
- functionName: "createPayableMemo",
4921
- args: [
4922
- jobId,
4923
- content,
4924
- token,
4925
- amountBaseUnit,
4926
- recipient,
4927
- feeAmountBaseUnit,
4928
- feeType,
4929
- type,
4930
- nextPhase,
4931
- Math.floor(expiredAt.getTime() / 1e3)
4932
- ]
4933
- });
4934
- return yield this.handleOperation(data, this.contractAddress);
4935
- } catch (error) {
4936
- throw new acpError_default("Failed to create payable memo", error);
4937
- }
4938
- });
4442
+ setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
4443
+ try {
4444
+ const data = encodeFunctionData2({
4445
+ abi: this.abi,
4446
+ functionName: "setBudgetWithPaymentToken",
4447
+ args: [jobId, budgetBaseUnit, paymentTokenAddress]
4448
+ });
4449
+ const payload = {
4450
+ data,
4451
+ contractAddress: this.contractAddress
4452
+ };
4453
+ return payload;
4454
+ } catch (error) {
4455
+ throw new acpError_default("Failed to set budget", error);
4456
+ }
4457
+ }
4458
+ createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
4459
+ try {
4460
+ const data = encodeFunctionData2({
4461
+ abi: this.abi,
4462
+ functionName: "createPayableMemo",
4463
+ args: [
4464
+ jobId,
4465
+ content,
4466
+ token,
4467
+ amountBaseUnit,
4468
+ recipient,
4469
+ feeAmountBaseUnit,
4470
+ feeType,
4471
+ type,
4472
+ nextPhase,
4473
+ Math.floor(expiredAt.getTime() / 1e3)
4474
+ ]
4475
+ });
4476
+ const payload = {
4477
+ data,
4478
+ contractAddress: this.contractAddress
4479
+ };
4480
+ return payload;
4481
+ } catch (error) {
4482
+ throw new acpError_default("Failed to create payable memo", error);
4483
+ }
4939
4484
  }
4940
4485
  createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4941
- return __async(this, null, function* () {
4942
- throw new acpError_default("Not Supported");
4943
- });
4486
+ throw new acpError_default("Not Supported");
4944
4487
  }
4945
4488
  updateAccountMetadata(accountId, metadata) {
4946
- return __async(this, null, function* () {
4947
- throw new acpError_default("Not Supported");
4948
- });
4489
+ throw new acpError_default("Not Supported");
4949
4490
  }
4950
4491
  };
4951
4492
  var acpContractClient_default = AcpContractClient;
@@ -5908,14 +5449,14 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5908
5449
  return finalMaxFeePerGas;
5909
5450
  });
5910
5451
  }
5911
- handleOperation(_0) {
5912
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
5452
+ handleOperation(operations) {
5453
+ return __async(this, null, function* () {
5913
5454
  const payload = {
5914
- uo: {
5915
- target: contractAddress,
5916
- data,
5917
- value
5918
- },
5455
+ uo: operations.map((operation) => ({
5456
+ target: operation.contractAddress,
5457
+ data: operation.data,
5458
+ value: operation.value
5459
+ })),
5919
5460
  overrides: {
5920
5461
  nonceKey: this.getRandomNonce()
5921
5462
  }
@@ -5932,7 +5473,13 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5932
5473
  }
5933
5474
  const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
5934
5475
  yield this.sessionKeyClient.waitForUserOperationTransaction({
5935
- hash
5476
+ hash,
5477
+ tag: "pending",
5478
+ retries: {
5479
+ intervalMs: 200,
5480
+ multiplier: 1.1,
5481
+ maxRetries: 10
5482
+ }
5936
5483
  });
5937
5484
  return hash;
5938
5485
  } catch (error) {
@@ -5949,7 +5496,10 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5949
5496
  }
5950
5497
  getJobId(hash, clientAddress, providerAddress) {
5951
5498
  return __async(this, null, function* () {
5952
- const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
5499
+ const result = yield this.sessionKeyClient.getUserOperationReceipt(
5500
+ hash,
5501
+ "pending"
5502
+ );
5953
5503
  if (!result) {
5954
5504
  throw new acpError_default("Failed to get user operation receipt");
5955
5505
  }