@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.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.4",
31
+ version: "0.3.0-beta.6",
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) {
@@ -3392,33 +3398,63 @@ var AcpJob = class {
3392
3398
  }
3393
3399
  accept(reason) {
3394
3400
  return __async(this, null, function* () {
3395
- var _a;
3396
3401
  const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
3397
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3398
- throw new acpError_default("No negotiation memo found");
3402
+ const latestMemo = this.latestMemo;
3403
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3404
+ throw new acpError_default("No request memo found");
3399
3405
  }
3400
- const memo = this.latestMemo;
3401
- yield memo.sign(true, memoContent);
3406
+ return yield latestMemo.sign(true, memoContent);
3402
3407
  });
3403
3408
  }
3404
3409
  reject(reason) {
3405
3410
  return __async(this, null, function* () {
3406
- var _a;
3407
3411
  const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
3408
3412
  if (this.phase === 0 /* REQUEST */) {
3409
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3413
+ const latestMemo = this.latestMemo;
3414
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3410
3415
  throw new acpError_default("No request memo found");
3411
3416
  }
3412
- const memo = this.latestMemo;
3413
- return yield this.acpContractClient.signMemo(memo.id, false, memoContent);
3417
+ return yield latestMemo.sign(false, memoContent);
3414
3418
  }
3415
- return yield this.acpContractClient.createMemo(
3416
- this.id,
3417
- memoContent,
3418
- 0 /* MESSAGE */,
3419
- true,
3420
- 5 /* REJECTED */
3419
+ const operations = [];
3420
+ operations.push(
3421
+ this.acpContractClient.createMemo(
3422
+ this.id,
3423
+ memoContent,
3424
+ 0 /* MESSAGE */,
3425
+ true,
3426
+ 5 /* REJECTED */
3427
+ )
3421
3428
  );
3429
+ return yield this.acpContractClient.handleOperation(operations);
3430
+ });
3431
+ }
3432
+ rejectPayable() {
3433
+ return __async(this, arguments, function* (reason = "", amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3434
+ const memoContent = `Job ${this.id} rejected. ${reason}`;
3435
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3436
+ const operations = [];
3437
+ operations.push(
3438
+ this.acpContractClient.approveAllowance(
3439
+ amount.amount,
3440
+ amount.fare.contractAddress
3441
+ )
3442
+ );
3443
+ operations.push(
3444
+ this.acpContractClient.createPayableMemo(
3445
+ this.id,
3446
+ memoContent,
3447
+ amount.amount,
3448
+ this.clientAddress,
3449
+ feeAmount.amount,
3450
+ 0 /* NO_FEE */,
3451
+ 5 /* REJECTED */,
3452
+ 7 /* PAYABLE_TRANSFER */,
3453
+ expiredAt,
3454
+ amount.fare.contractAddress
3455
+ )
3456
+ );
3457
+ return yield this.acpContractClient.handleOperation(operations);
3422
3458
  });
3423
3459
  }
3424
3460
  deliver(deliverable) {
@@ -3427,13 +3463,17 @@ var AcpJob = class {
3427
3463
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3428
3464
  throw new acpError_default("No transaction memo found");
3429
3465
  }
3430
- return yield this.acpContractClient.createMemo(
3431
- this.id,
3432
- preparePayload(deliverable),
3433
- 0 /* MESSAGE */,
3434
- true,
3435
- 4 /* COMPLETED */
3466
+ const operations = [];
3467
+ operations.push(
3468
+ this.acpContractClient.createMemo(
3469
+ this.id,
3470
+ preparePayload(deliverable),
3471
+ 0 /* MESSAGE */,
3472
+ true,
3473
+ 4 /* COMPLETED */
3474
+ )
3436
3475
  );
3476
+ return yield this.acpContractClient.handleOperation(operations);
3437
3477
  });
3438
3478
  }
3439
3479
  deliverPayable(_0, _1) {
@@ -3442,23 +3482,29 @@ var AcpJob = class {
3442
3482
  if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3443
3483
  throw new acpError_default("No transaction memo found");
3444
3484
  }
3445
- yield this.acpContractClient.approveAllowance(
3446
- amount.amount,
3447
- amount.fare.contractAddress
3485
+ const operations = [];
3486
+ operations.push(
3487
+ this.acpContractClient.approveAllowance(
3488
+ amount.amount,
3489
+ amount.fare.contractAddress
3490
+ )
3448
3491
  );
3449
3492
  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
3493
+ operations.push(
3494
+ this.acpContractClient.createPayableMemo(
3495
+ this.id,
3496
+ preparePayload(deliverable),
3497
+ amount.amount,
3498
+ this.clientAddress,
3499
+ feeAmount.amount,
3500
+ 0 /* NO_FEE */,
3501
+ 4 /* COMPLETED */,
3502
+ 7 /* PAYABLE_TRANSFER */,
3503
+ expiredAt,
3504
+ amount.fare.contractAddress
3505
+ )
3461
3506
  );
3507
+ return yield this.acpContractClient.handleOperation(operations);
3462
3508
  });
3463
3509
  }
3464
3510
  evaluate(accept, reason) {
@@ -3471,419 +3517,46 @@ var AcpJob = class {
3471
3517
  yield memo.sign(accept, reason);
3472
3518
  });
3473
3519
  }
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
3520
  createNotification(content) {
3491
3521
  return __async(this, null, function* () {
3492
- return yield this.acpContractClient.createMemo(
3493
- this.id,
3494
- content,
3495
- 9 /* NOTIFICATION */,
3496
- true,
3497
- 4 /* COMPLETED */
3522
+ const operations = [];
3523
+ operations.push(
3524
+ this.acpContractClient.createMemo(
3525
+ this.id,
3526
+ content,
3527
+ 9 /* NOTIFICATION */,
3528
+ true,
3529
+ 4 /* COMPLETED */
3530
+ )
3498
3531
  );
3532
+ return yield this.acpContractClient.handleOperation(operations);
3499
3533
  });
3500
3534
  }
3501
3535
  createPayableNotification(_0, _1) {
3502
3536
  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
3537
+ const operations = [];
3538
+ operations.push(
3539
+ this.acpContractClient.approveAllowance(
3540
+ amount.amount,
3541
+ amount.fare.contractAddress
3542
+ )
3506
3543
  );
3507
3544
  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(
3545
+ operations.push(
3546
+ this.acpContractClient.createPayableMemo(
3697
3547
  this.id,
3698
- new FareAmount(payload.amount, this.baseFare),
3548
+ content,
3549
+ amount.amount,
3699
3550
  this.clientAddress,
3700
- new FareAmount(0, this.baseFare),
3551
+ feeAmount.amount,
3701
3552
  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
3553
+ 4 /* COMPLETED */,
3554
+ 10 /* PAYABLE_NOTIFICATION */,
3555
+ expiredAt,
3556
+ amount.fare.contractAddress
3557
+ )
3882
3558
  );
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);
3559
+ return yield this.acpContractClient.handleOperation(operations);
3887
3560
  });
3888
3561
  }
3889
3562
  };
@@ -3928,7 +3601,8 @@ var AcpMemo = class {
3928
3601
  }
3929
3602
  sign(approved, reason) {
3930
3603
  return __async(this, null, function* () {
3931
- return yield this.contractClient.signMemo(this.id, approved, reason);
3604
+ const payload = this.contractClient.signMemo(this.id, approved, reason);
3605
+ return yield this.contractClient.handleOperation([payload]);
3932
3606
  });
3933
3607
  }
3934
3608
  };
@@ -3969,7 +3643,7 @@ var AcpJobOffering = class {
3969
3643
  this.providerAddress,
3970
3644
  this.acpContractClient
3971
3645
  );
3972
- const { jobId, txHash } = [
3646
+ const createJobPayload = [
3973
3647
  baseSepoliaAcpConfig.contractAddress,
3974
3648
  baseAcpConfig.contractAddress
3975
3649
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
@@ -3987,13 +3661,33 @@ var AcpJobOffering = class {
3987
3661
  fareAmount.fare.contractAddress,
3988
3662
  expiredAt
3989
3663
  );
3990
- yield this.acpContractClient.createMemo(
3664
+ const createJobTxnHash = yield this.acpContractClient.handleOperation([
3665
+ createJobPayload
3666
+ ]);
3667
+ const jobId = yield this.acpContractClient.getJobId(
3668
+ createJobTxnHash,
3669
+ this.acpContractClient.walletAddress,
3670
+ this.providerAddress
3671
+ );
3672
+ const payloads = [];
3673
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3991
3674
  jobId,
3992
- JSON.stringify(finalServiceRequirement),
3993
- 0 /* MESSAGE */,
3994
- true,
3995
- 1 /* NEGOTIATION */
3675
+ fareAmount.amount,
3676
+ fareAmount.fare.contractAddress
3677
+ );
3678
+ if (setBudgetWithPaymentTokenPayload) {
3679
+ payloads.push(setBudgetWithPaymentTokenPayload);
3680
+ }
3681
+ payloads.push(
3682
+ this.acpContractClient.createMemo(
3683
+ jobId,
3684
+ JSON.stringify(finalServiceRequirement),
3685
+ 0 /* MESSAGE */,
3686
+ true,
3687
+ 1 /* NEGOTIATION */
3688
+ )
3996
3689
  );
3690
+ yield this.acpContractClient.handleOperation(payloads);
3997
3691
  return jobId;
3998
3692
  });
3999
3693
  }
@@ -4245,12 +3939,16 @@ var AcpClient = class {
4245
3939
  providerAddress,
4246
3940
  this.acpContractClient
4247
3941
  );
4248
- const { jobId, txHash } = [
3942
+ const defaultEvaluatorAddress = [
3943
+ baseSepoliaAcpConfig.contractAddress,
3944
+ baseAcpConfig.contractAddress
3945
+ ].includes(this.acpContractClient.config.contractAddress) && !evaluatorAddress ? this.walletAddress : zeroAddress2;
3946
+ const createJobPayload = [
4249
3947
  baseSepoliaAcpConfig.contractAddress,
4250
3948
  baseAcpConfig.contractAddress
4251
3949
  ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
4252
3950
  providerAddress,
4253
- evaluatorAddress || this.walletAddress,
3951
+ evaluatorAddress || defaultEvaluatorAddress,
4254
3952
  expiredAt,
4255
3953
  fareAmount.fare.contractAddress,
4256
3954
  fareAmount.amount,
@@ -4258,182 +3956,39 @@ var AcpClient = class {
4258
3956
  ) : yield this.acpContractClient.createJobWithAccount(
4259
3957
  account.id,
4260
3958
  providerAddress,
4261
- evaluatorAddress || this.walletAddress,
3959
+ evaluatorAddress || defaultEvaluatorAddress,
4262
3960
  fareAmount.amount,
4263
3961
  fareAmount.fare.contractAddress,
4264
3962
  expiredAt
4265
3963
  );
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 */
3964
+ const txHash = yield this.acpContractClient.handleOperation([
3965
+ createJobPayload
3966
+ ]);
3967
+ const jobId = yield this.acpContractClient.getJobId(
3968
+ txHash,
3969
+ this.walletAddress,
3970
+ providerAddress
4337
3971
  );
4338
- });
4339
- }
4340
- requestFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
4341
- return __async(this, null, function* () {
4342
- return yield this.acpContractClient.createPayableMemo(
3972
+ const payloads = [];
3973
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4343
3974
  jobId,
4344
- JSON.stringify(reason),
4345
- transferFareAmount.amount,
4346
- recipient,
4347
- feeFareAmount.amount,
4348
- feeType,
4349
- nextPhase,
4350
- 6 /* PAYABLE_REQUEST */,
4351
- expiredAt
3975
+ fareAmount.amount,
3976
+ fareAmount.fare.contractAddress
4352
3977
  );
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);
3978
+ if (setBudgetWithPaymentTokenPayload) {
3979
+ payloads.push(setBudgetWithPaymentTokenPayload);
4359
3980
  }
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
- );
4381
- }
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 */
3981
+ payloads.push(
3982
+ this.acpContractClient.createMemo(
3983
+ jobId,
3984
+ preparePayload(serviceRequirement),
3985
+ 0 /* MESSAGE */,
3986
+ true,
3987
+ 1 /* NEGOTIATION */
3988
+ )
4436
3989
  );
3990
+ yield this.acpContractClient.handleOperation(payloads);
3991
+ return jobId;
4437
3992
  });
4438
3993
  }
4439
3994
  getActiveJobs(page = 1, pageSize = 10) {
@@ -4820,14 +4375,14 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4820
4375
  return finalMaxFeePerGas;
4821
4376
  });
4822
4377
  }
4823
- handleOperation(_0) {
4824
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
4378
+ handleOperation(operations) {
4379
+ return __async(this, null, function* () {
4825
4380
  const payload = {
4826
- uo: {
4827
- target: contractAddress,
4828
- data,
4829
- value
4830
- },
4381
+ uo: operations.map((op) => ({
4382
+ target: op.contractAddress,
4383
+ data: op.data,
4384
+ value: op.value
4385
+ })),
4831
4386
  overrides: {
4832
4387
  nonceKey: this.getRandomNonce()
4833
4388
  }
@@ -4884,68 +4439,73 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4884
4439
  });
4885
4440
  }
4886
4441
  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
- });
4442
+ try {
4443
+ const data = encodeFunctionData2({
4444
+ abi: this.abi,
4445
+ functionName: "createJob",
4446
+ args: [
4447
+ providerAddress,
4448
+ evaluatorAddress,
4449
+ Math.floor(expireAt.getTime() / 1e3)
4450
+ ]
4451
+ });
4452
+ const payload = {
4453
+ data,
4454
+ contractAddress: this.contractAddress
4455
+ };
4456
+ return payload;
4457
+ } catch (error) {
4458
+ throw new acpError_default("Failed to create job", error);
4459
+ }
4914
4460
  }
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
- });
4461
+ setBudgetWithPaymentToken(jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
4462
+ try {
4463
+ const data = encodeFunctionData2({
4464
+ abi: this.abi,
4465
+ functionName: "setBudgetWithPaymentToken",
4466
+ args: [jobId, budgetBaseUnit, paymentTokenAddress]
4467
+ });
4468
+ const payload = {
4469
+ data,
4470
+ contractAddress: this.contractAddress
4471
+ };
4472
+ return payload;
4473
+ } catch (error) {
4474
+ throw new acpError_default("Failed to set budget", error);
4475
+ }
4476
+ }
4477
+ createPayableMemo(jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress, secured = true) {
4478
+ try {
4479
+ const data = encodeFunctionData2({
4480
+ abi: this.abi,
4481
+ functionName: "createPayableMemo",
4482
+ args: [
4483
+ jobId,
4484
+ content,
4485
+ token,
4486
+ amountBaseUnit,
4487
+ recipient,
4488
+ feeAmountBaseUnit,
4489
+ feeType,
4490
+ type,
4491
+ nextPhase,
4492
+ Math.floor(expiredAt.getTime() / 1e3)
4493
+ ]
4494
+ });
4495
+ const payload = {
4496
+ data,
4497
+ contractAddress: this.contractAddress
4498
+ };
4499
+ return payload;
4500
+ } catch (error) {
4501
+ throw new acpError_default("Failed to create payable memo", error);
4502
+ }
4939
4503
  }
4940
4504
  createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4941
- return __async(this, null, function* () {
4942
- throw new acpError_default("Not Supported");
4943
- });
4505
+ throw new acpError_default("Not Supported");
4944
4506
  }
4945
4507
  updateAccountMetadata(accountId, metadata) {
4946
- return __async(this, null, function* () {
4947
- throw new acpError_default("Not Supported");
4948
- });
4508
+ throw new acpError_default("Not Supported");
4949
4509
  }
4950
4510
  };
4951
4511
  var acpContractClient_default = AcpContractClient;
@@ -5908,14 +5468,14 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5908
5468
  return finalMaxFeePerGas;
5909
5469
  });
5910
5470
  }
5911
- handleOperation(_0) {
5912
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
5471
+ handleOperation(operations) {
5472
+ return __async(this, null, function* () {
5913
5473
  const payload = {
5914
- uo: {
5915
- target: contractAddress,
5916
- data,
5917
- value
5918
- },
5474
+ uo: operations.map((operation) => ({
5475
+ target: operation.contractAddress,
5476
+ data: operation.data,
5477
+ value: operation.value
5478
+ })),
5919
5479
  overrides: {
5920
5480
  nonceKey: this.getRandomNonce()
5921
5481
  }
@@ -5932,7 +5492,13 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5932
5492
  }
5933
5493
  const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
5934
5494
  yield this.sessionKeyClient.waitForUserOperationTransaction({
5935
- hash
5495
+ hash,
5496
+ tag: "pending",
5497
+ retries: {
5498
+ intervalMs: 200,
5499
+ multiplier: 1.1,
5500
+ maxRetries: 10
5501
+ }
5936
5502
  });
5937
5503
  return hash;
5938
5504
  } catch (error) {
@@ -5949,7 +5515,10 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5949
5515
  }
5950
5516
  getJobId(hash, clientAddress, providerAddress) {
5951
5517
  return __async(this, null, function* () {
5952
- const result = yield this.sessionKeyClient.getUserOperationReceipt(hash);
5518
+ const result = yield this.sessionKeyClient.getUserOperationReceipt(
5519
+ hash,
5520
+ "pending"
5521
+ );
5953
5522
  if (!result) {
5954
5523
  throw new acpError_default("Failed to get user operation receipt");
5955
5524
  }