@virtuals-protocol/acp-node 0.3.0-beta.12 → 0.3.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -29,51 +29,41 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  mod
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
32
 
53
33
  // package.json
54
34
  var require_package = __commonJS({
55
35
  "package.json"(exports2, module2) {
56
36
  module2.exports = {
57
37
  name: "@virtuals-protocol/acp-node",
58
- version: "0.3.0-beta.12",
38
+ version: "0.3.0-beta.14",
59
39
  main: "./dist/index.js",
60
40
  module: "./dist/index.mjs",
61
41
  types: "./dist/index.d.ts",
62
42
  scripts: {
63
- test: 'echo "Error: no test specified" && exit 1',
43
+ test: "jest",
44
+ "test:watch": "jest --watch",
45
+ "test:coverage": "jest --coverage",
64
46
  tsup: "tsup src/index.ts --dts --format cjs,esm --out-dir dist"
65
47
  },
66
48
  author: "",
67
49
  license: "ISC",
68
50
  description: "",
69
51
  devDependencies: {
52
+ "@babel/core": "^7.28.5",
53
+ "@babel/preset-env": "^7.28.5",
54
+ "@babel/preset-typescript": "^7.28.5",
55
+ "@types/jest": "^30.0.0",
56
+ "babel-jest": "^30.2.0",
57
+ dotenv: "^17.2.3",
58
+ jest: "^30.2.0",
59
+ "ts-jest": "^29.4.5",
70
60
  typescript: "^5.8.3"
71
61
  },
72
62
  dependencies: {
73
63
  "@aa-sdk/core": "^4.73.0",
74
64
  "@account-kit/infra": "^4.73.0",
75
65
  "@account-kit/smart-contracts": "^4.73.0",
76
- "@virtuals-protocol/acp-node": "^0.3.0-beta.9",
66
+ "@virtuals-protocol/acp-node": "^0.3.0-beta.10",
77
67
  ajv: "^8.17.1",
78
68
  "socket.io-client": "^4.8.1",
79
69
  tsup: "^8.5.0",
@@ -1328,22 +1318,20 @@ var Fare = class _Fare {
1328
1318
  formatAmount(amount) {
1329
1319
  return (0, import_viem.parseUnits)(amount.toString(), this.decimals);
1330
1320
  }
1331
- static fromContractAddress(_0) {
1332
- return __async(this, arguments, function* (contractAddress, config = baseAcpConfig) {
1333
- if (contractAddress === config.baseFare.contractAddress) {
1334
- return config.baseFare;
1335
- }
1336
- const publicClient = (0, import_viem.createPublicClient)({
1337
- chain: config.chain,
1338
- transport: (0, import_viem.http)(config.rpcEndpoint)
1339
- });
1340
- const decimals = yield publicClient.readContract({
1341
- address: contractAddress,
1342
- abi: import_viem.erc20Abi,
1343
- functionName: "decimals"
1344
- });
1345
- return new _Fare(contractAddress, decimals);
1321
+ static async fromContractAddress(contractAddress, config = baseAcpConfig) {
1322
+ if (contractAddress === config.baseFare.contractAddress) {
1323
+ return config.baseFare;
1324
+ }
1325
+ const publicClient = (0, import_viem.createPublicClient)({
1326
+ chain: config.chain,
1327
+ transport: (0, import_viem.http)(config.rpcEndpoint)
1328
+ });
1329
+ const decimals = await publicClient.readContract({
1330
+ address: contractAddress,
1331
+ abi: import_viem.erc20Abi,
1332
+ functionName: "decimals"
1346
1333
  });
1334
+ return new _Fare(contractAddress, decimals);
1347
1335
  }
1348
1336
  };
1349
1337
  var FareAmountBase = class {
@@ -1351,14 +1339,12 @@ var FareAmountBase = class {
1351
1339
  this.amount = amount;
1352
1340
  this.fare = fare;
1353
1341
  }
1354
- static fromContractAddress(_0, _1) {
1355
- return __async(this, arguments, function* (amount, contractAddress, config = baseAcpConfig) {
1356
- const fare = yield Fare.fromContractAddress(contractAddress, config);
1357
- if (typeof amount === "number") {
1358
- return new FareAmount(amount, fare);
1359
- }
1360
- return new FareBigInt(amount, fare);
1361
- });
1342
+ static async fromContractAddress(amount, contractAddress, config = baseAcpConfig) {
1343
+ const fare = await Fare.fromContractAddress(contractAddress, config);
1344
+ if (typeof amount === "number") {
1345
+ return new FareAmount(amount, fare);
1346
+ }
1347
+ return new FareBigInt(amount, fare);
1362
1348
  }
1363
1349
  };
1364
1350
  var FareAmount = class extends FareAmountBase {
@@ -3315,6 +3301,241 @@ var FIAT_TOKEN_V2_ABI = [
3315
3301
  ];
3316
3302
  var fiatTokenV2Abi_default = FIAT_TOKEN_V2_ABI;
3317
3303
 
3304
+ // src/abis/singleSignerValidationModuleAbi.ts
3305
+ var SINGLE_SIGNER_VALIDATION_MODULE_ABI = [
3306
+ { inputs: [], name: "InvalidSignatureType", type: "error" },
3307
+ {
3308
+ inputs: [],
3309
+ name: "NotAuthorized",
3310
+ type: "error"
3311
+ },
3312
+ { inputs: [], name: "NotImplemented", type: "error" },
3313
+ {
3314
+ inputs: [],
3315
+ name: "UnexpectedDataPassed",
3316
+ type: "error"
3317
+ },
3318
+ {
3319
+ anonymous: true,
3320
+ inputs: [
3321
+ {
3322
+ indexed: true,
3323
+ internalType: "address",
3324
+ name: "account",
3325
+ type: "address"
3326
+ },
3327
+ {
3328
+ indexed: true,
3329
+ internalType: "uint32",
3330
+ name: "entityId",
3331
+ type: "uint32"
3332
+ },
3333
+ {
3334
+ indexed: true,
3335
+ internalType: "address",
3336
+ name: "newSigner",
3337
+ type: "address"
3338
+ },
3339
+ {
3340
+ indexed: false,
3341
+ internalType: "address",
3342
+ name: "previousSigner",
3343
+ type: "address"
3344
+ }
3345
+ ],
3346
+ name: "SignerTransferred",
3347
+ type: "event"
3348
+ },
3349
+ {
3350
+ inputs: [],
3351
+ name: "moduleId",
3352
+ outputs: [{ internalType: "string", name: "", type: "string" }],
3353
+ stateMutability: "pure",
3354
+ type: "function"
3355
+ },
3356
+ {
3357
+ inputs: [{ internalType: "bytes", name: "data", type: "bytes" }],
3358
+ name: "onInstall",
3359
+ outputs: [],
3360
+ stateMutability: "nonpayable",
3361
+ type: "function"
3362
+ },
3363
+ {
3364
+ inputs: [{ internalType: "bytes", name: "data", type: "bytes" }],
3365
+ name: "onUninstall",
3366
+ outputs: [],
3367
+ stateMutability: "nonpayable",
3368
+ type: "function"
3369
+ },
3370
+ {
3371
+ inputs: [
3372
+ { internalType: "address", name: "account", type: "address" },
3373
+ {
3374
+ internalType: "bytes32",
3375
+ name: "hash",
3376
+ type: "bytes32"
3377
+ }
3378
+ ],
3379
+ name: "replaySafeHash",
3380
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
3381
+ stateMutability: "view",
3382
+ type: "function"
3383
+ },
3384
+ {
3385
+ inputs: [
3386
+ { internalType: "uint32", name: "entityId", type: "uint32" },
3387
+ {
3388
+ internalType: "address",
3389
+ name: "account",
3390
+ type: "address"
3391
+ }
3392
+ ],
3393
+ name: "signers",
3394
+ outputs: [{ internalType: "address", name: "", type: "address" }],
3395
+ stateMutability: "view",
3396
+ type: "function"
3397
+ },
3398
+ {
3399
+ inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
3400
+ name: "supportsInterface",
3401
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
3402
+ stateMutability: "view",
3403
+ type: "function"
3404
+ },
3405
+ {
3406
+ inputs: [
3407
+ { internalType: "uint32", name: "entityId", type: "uint32" },
3408
+ {
3409
+ internalType: "address",
3410
+ name: "newSigner",
3411
+ type: "address"
3412
+ }
3413
+ ],
3414
+ name: "transferSigner",
3415
+ outputs: [],
3416
+ stateMutability: "nonpayable",
3417
+ type: "function"
3418
+ },
3419
+ {
3420
+ inputs: [
3421
+ { internalType: "address", name: "account", type: "address" },
3422
+ {
3423
+ internalType: "uint32",
3424
+ name: "entityId",
3425
+ type: "uint32"
3426
+ },
3427
+ { internalType: "address", name: "sender", type: "address" },
3428
+ {
3429
+ internalType: "uint256",
3430
+ name: "",
3431
+ type: "uint256"
3432
+ },
3433
+ { internalType: "bytes", name: "", type: "bytes" },
3434
+ {
3435
+ internalType: "bytes",
3436
+ name: "",
3437
+ type: "bytes"
3438
+ }
3439
+ ],
3440
+ name: "validateRuntime",
3441
+ outputs: [],
3442
+ stateMutability: "view",
3443
+ type: "function"
3444
+ },
3445
+ {
3446
+ inputs: [
3447
+ { internalType: "address", name: "account", type: "address" },
3448
+ {
3449
+ internalType: "uint32",
3450
+ name: "entityId",
3451
+ type: "uint32"
3452
+ },
3453
+ { internalType: "address", name: "", type: "address" },
3454
+ {
3455
+ internalType: "bytes32",
3456
+ name: "digest",
3457
+ type: "bytes32"
3458
+ },
3459
+ { internalType: "bytes", name: "signature", type: "bytes" }
3460
+ ],
3461
+ name: "validateSignature",
3462
+ outputs: [{ internalType: "bytes4", name: "", type: "bytes4" }],
3463
+ stateMutability: "view",
3464
+ type: "function"
3465
+ },
3466
+ {
3467
+ inputs: [
3468
+ {
3469
+ internalType: "uint32",
3470
+ name: "entityId",
3471
+ type: "uint32"
3472
+ },
3473
+ {
3474
+ components: [
3475
+ { internalType: "address", name: "sender", type: "address" },
3476
+ {
3477
+ internalType: "uint256",
3478
+ name: "nonce",
3479
+ type: "uint256"
3480
+ },
3481
+ { internalType: "bytes", name: "initCode", type: "bytes" },
3482
+ {
3483
+ internalType: "bytes",
3484
+ name: "callData",
3485
+ type: "bytes"
3486
+ },
3487
+ {
3488
+ internalType: "bytes32",
3489
+ name: "accountGasLimits",
3490
+ type: "bytes32"
3491
+ },
3492
+ {
3493
+ internalType: "uint256",
3494
+ name: "preVerificationGas",
3495
+ type: "uint256"
3496
+ },
3497
+ { internalType: "bytes32", name: "gasFees", type: "bytes32" },
3498
+ {
3499
+ internalType: "bytes",
3500
+ name: "paymasterAndData",
3501
+ type: "bytes"
3502
+ },
3503
+ { internalType: "bytes", name: "signature", type: "bytes" }
3504
+ ],
3505
+ internalType: "struct PackedUserOperation",
3506
+ name: "userOp",
3507
+ type: "tuple"
3508
+ },
3509
+ { internalType: "bytes32", name: "userOpHash", type: "bytes32" }
3510
+ ],
3511
+ name: "validateUserOp",
3512
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3513
+ stateMutability: "view",
3514
+ type: "function"
3515
+ }
3516
+ ];
3517
+ var singleSignerValidationModuleAbi_default = SINGLE_SIGNER_VALIDATION_MODULE_ABI;
3518
+
3519
+ // src/constants.ts
3520
+ var import_chains = require("viem/chains");
3521
+ var USDC_TOKEN_ADDRESS = {
3522
+ [import_chains.baseSepolia.id]: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
3523
+ [import_chains.base.id]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
3524
+ };
3525
+ var X402AuthorizationTypes = [
3526
+ { name: "from", type: "address" },
3527
+ { name: "to", type: "address" },
3528
+ { name: "value", type: "uint256" },
3529
+ { name: "validAfter", type: "uint256" },
3530
+ { name: "validBefore", type: "uint256" },
3531
+ { name: "nonce", type: "bytes32" }
3532
+ ];
3533
+ var HTTP_STATUS_CODES = {
3534
+ OK: 200,
3535
+ PAYMENT_REQUIRED: 402
3536
+ };
3537
+ var SINGLE_SIGNER_VALIDATION_MODULE_ADDRESS = "0x00000000000099DE0BF6fA90dEB851E2A2df7d83";
3538
+
3318
3539
  // src/contractClients/baseAcpContractClient.ts
3319
3540
  var MemoType = /* @__PURE__ */ ((MemoType3) => {
3320
3541
  MemoType3[MemoType3["MESSAGE"] = 0] = "MESSAGE";
@@ -3357,6 +3578,44 @@ var BaseAcpContractClient = class {
3357
3578
  transport: (0, import_viem2.http)(this.config.rpcEndpoint)
3358
3579
  });
3359
3580
  }
3581
+ async validateSessionKeyOnChain(sessionSignerAddress, sessionEntityKeyId) {
3582
+ const onChainSignerAddress = (await this.publicClient.readContract({
3583
+ address: SINGLE_SIGNER_VALIDATION_MODULE_ADDRESS,
3584
+ abi: singleSignerValidationModuleAbi_default,
3585
+ functionName: "signers",
3586
+ args: [sessionEntityKeyId, this.agentWalletAddress]
3587
+ })).toLowerCase();
3588
+ if (onChainSignerAddress === import_viem2.zeroAddress.toLowerCase()) {
3589
+ throw new acpError_default(
3590
+ `ACP Contract Client validation failed:
3591
+ ${JSON.stringify(
3592
+ {
3593
+ reason: "no whitelisted wallet registered on-chain for entity id",
3594
+ entityId: sessionEntityKeyId,
3595
+ agentWalletAddress: this.agentWalletAddress
3596
+ },
3597
+ null,
3598
+ 2
3599
+ )}`
3600
+ );
3601
+ }
3602
+ if (onChainSignerAddress !== sessionSignerAddress.toLowerCase()) {
3603
+ throw new acpError_default(
3604
+ `ACP Contract Client validation failed:
3605
+ ${JSON.stringify(
3606
+ {
3607
+ agentWalletAddress: this.agentWalletAddress,
3608
+ entityId: sessionEntityKeyId,
3609
+ givenWhitelistedWalletAddress: sessionSignerAddress,
3610
+ expectedWhitelistedWalletAddress: onChainSignerAddress,
3611
+ reason: "session signer address mismatch"
3612
+ },
3613
+ null,
3614
+ 2
3615
+ )}`
3616
+ );
3617
+ }
3618
+ }
3360
3619
  get walletAddress() {
3361
3620
  return this.agentWalletAddress;
3362
3621
  }
@@ -3516,43 +3775,39 @@ var BaseAcpContractClient = class {
3516
3775
  throw new acpError_default("Failed to wrap eth", error);
3517
3776
  }
3518
3777
  }
3519
- getX402PaymentDetails(jobId) {
3520
- return __async(this, null, function* () {
3521
- try {
3522
- const result = yield this.publicClient.readContract({
3523
- address: this.contractAddress,
3524
- abi: this.abi,
3525
- functionName: "x402PaymentDetails",
3526
- args: [BigInt(jobId)]
3527
- });
3528
- return {
3529
- isX402: result[0],
3530
- isBudgetReceived: result[1]
3531
- };
3532
- } catch (error) {
3533
- throw new acpError_default("Failed to get X402 payment details", error);
3534
- }
3535
- });
3778
+ async getX402PaymentDetails(jobId) {
3779
+ try {
3780
+ const result = await this.publicClient.readContract({
3781
+ address: this.contractAddress,
3782
+ abi: this.abi,
3783
+ functionName: "x402PaymentDetails",
3784
+ args: [BigInt(jobId)]
3785
+ });
3786
+ return {
3787
+ isX402: result[0],
3788
+ isBudgetReceived: result[1]
3789
+ };
3790
+ } catch (error) {
3791
+ throw new acpError_default("Failed to get X402 payment details", error);
3792
+ }
3536
3793
  }
3537
- submitTransferWithAuthorization(from, to, value, validAfter, validBefore, nonce, signature) {
3538
- return __async(this, null, function* () {
3539
- try {
3540
- const operations = [];
3541
- const data = (0, import_viem2.encodeFunctionData)({
3542
- abi: fiatTokenV2Abi_default,
3543
- functionName: "transferWithAuthorization",
3544
- args: [from, to, value, validAfter, validBefore, nonce, signature]
3545
- });
3546
- const payload = {
3547
- data,
3548
- contractAddress: this.config.baseFare.contractAddress
3549
- };
3550
- operations.push(payload);
3551
- return operations;
3552
- } catch (error) {
3553
- throw new acpError_default("Failed to submit TransferWithAuthorization", error);
3554
- }
3555
- });
3794
+ async submitTransferWithAuthorization(from, to, value, validAfter, validBefore, nonce, signature) {
3795
+ try {
3796
+ const operations = [];
3797
+ const data = (0, import_viem2.encodeFunctionData)({
3798
+ abi: fiatTokenV2Abi_default,
3799
+ functionName: "transferWithAuthorization",
3800
+ args: [from, to, value, validAfter, validBefore, nonce, signature]
3801
+ });
3802
+ const payload = {
3803
+ data,
3804
+ contractAddress: this.config.baseFare.contractAddress
3805
+ };
3806
+ operations.push(payload);
3807
+ return operations;
3808
+ } catch (error) {
3809
+ throw new acpError_default("Failed to submit TransferWithAuthorization", error);
3810
+ }
3556
3811
  }
3557
3812
  };
3558
3813
  var baseAcpContractClient_default = BaseAcpContractClient;
@@ -3622,27 +3877,6 @@ function safeBase64Encode(data) {
3622
3877
  // src/acpJobOffering.ts
3623
3878
  var import_viem3 = require("viem");
3624
3879
  var import_ajv = __toESM(require("ajv"));
3625
-
3626
- // src/constants.ts
3627
- var import_chains = require("viem/chains");
3628
- var USDC_TOKEN_ADDRESS = {
3629
- [import_chains.baseSepolia.id]: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
3630
- [import_chains.base.id]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
3631
- };
3632
- var X402AuthorizationTypes = [
3633
- { name: "from", type: "address" },
3634
- { name: "to", type: "address" },
3635
- { name: "value", type: "uint256" },
3636
- { name: "validAfter", type: "uint256" },
3637
- { name: "validBefore", type: "uint256" },
3638
- { name: "nonce", type: "bytes32" }
3639
- ];
3640
- var HTTP_STATUS_CODES = {
3641
- OK: 200,
3642
- PAYMENT_REQUIRED: 402
3643
- };
3644
-
3645
- // src/acpJobOffering.ts
3646
3880
  var AcpJobOffering = class {
3647
3881
  constructor(acpClient, acpContractClient, providerAddress, name, price, priceType = "fixed" /* FIXED */, requirement) {
3648
3882
  this.acpClient = acpClient;
@@ -3654,89 +3888,87 @@ var AcpJobOffering = class {
3654
3888
  this.requirement = requirement;
3655
3889
  this.ajv = new import_ajv.default({ allErrors: true });
3656
3890
  }
3657
- initiateJob(_0, _1) {
3658
- return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3659
- if (this.requirement && typeof this.requirement === "object") {
3660
- const validator = this.ajv.compile(this.requirement);
3661
- const valid = validator(serviceRequirement);
3662
- if (!valid) {
3663
- throw new acpError_default(this.ajv.errorsText(validator.errors));
3664
- }
3891
+ async initiateJob(serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3892
+ if (this.requirement && typeof this.requirement === "object") {
3893
+ const validator = this.ajv.compile(this.requirement);
3894
+ const valid = validator(serviceRequirement);
3895
+ if (!valid) {
3896
+ throw new acpError_default(this.ajv.errorsText(validator.errors));
3665
3897
  }
3666
- const finalServiceRequirement = {
3667
- name: this.name,
3668
- requirement: serviceRequirement,
3669
- priceValue: this.price,
3670
- priceType: this.priceType
3671
- };
3672
- const fareAmount = new FareAmount(
3673
- this.priceType === "fixed" /* FIXED */ ? this.price : 0,
3674
- this.acpContractClient.config.baseFare
3675
- );
3676
- const account = yield this.acpClient.getByClientAndProvider(
3677
- this.acpContractClient.walletAddress,
3898
+ }
3899
+ const finalServiceRequirement = {
3900
+ name: this.name,
3901
+ requirement: serviceRequirement,
3902
+ priceValue: this.price,
3903
+ priceType: this.priceType
3904
+ };
3905
+ const fareAmount = new FareAmount(
3906
+ this.priceType === "fixed" /* FIXED */ ? this.price : 0,
3907
+ this.acpContractClient.config.baseFare
3908
+ );
3909
+ const account = await this.acpClient.getByClientAndProvider(
3910
+ this.acpContractClient.walletAddress,
3911
+ this.providerAddress,
3912
+ this.acpContractClient
3913
+ );
3914
+ const isV1 = [
3915
+ baseSepoliaAcpConfig.contractAddress,
3916
+ baseSepoliaAcpX402Config.contractAddress,
3917
+ baseAcpConfig.contractAddress,
3918
+ baseAcpX402Config.contractAddress
3919
+ ].includes(this.acpContractClient.config.contractAddress);
3920
+ let createJobPayload;
3921
+ const chainId = this.acpContractClient.config.chain.id;
3922
+ const isUsdcPaymentToken = USDC_TOKEN_ADDRESS[chainId].toLowerCase() === fareAmount.fare.contractAddress.toLowerCase();
3923
+ const isX402Job = this.acpContractClient.config.x402Config && isUsdcPaymentToken;
3924
+ if (isV1 || !account) {
3925
+ createJobPayload = this.acpContractClient.createJob(
3678
3926
  this.providerAddress,
3679
- this.acpContractClient
3927
+ evaluatorAddress || this.acpContractClient.walletAddress,
3928
+ expiredAt,
3929
+ fareAmount.fare.contractAddress,
3930
+ fareAmount.amount,
3931
+ "",
3932
+ isX402Job
3680
3933
  );
3681
- const isV1 = [
3682
- baseSepoliaAcpConfig.contractAddress,
3683
- baseSepoliaAcpX402Config.contractAddress,
3684
- baseAcpConfig.contractAddress,
3685
- baseAcpX402Config.contractAddress
3686
- ].includes(this.acpContractClient.config.contractAddress);
3687
- let createJobPayload;
3688
- const chainId = this.acpContractClient.config.chain.id;
3689
- const isUsdcPaymentToken = USDC_TOKEN_ADDRESS[chainId].toLowerCase() === fareAmount.fare.contractAddress.toLowerCase();
3690
- const isX402Job = this.acpContractClient.config.x402Config && isUsdcPaymentToken;
3691
- if (isV1 || !account) {
3692
- createJobPayload = this.acpContractClient.createJob(
3693
- this.providerAddress,
3694
- evaluatorAddress || this.acpContractClient.walletAddress,
3695
- expiredAt,
3696
- fareAmount.fare.contractAddress,
3697
- fareAmount.amount,
3698
- "",
3699
- isX402Job
3700
- );
3701
- } else {
3702
- createJobPayload = this.acpContractClient.createJobWithAccount(
3703
- account.id,
3704
- evaluatorAddress || import_viem3.zeroAddress,
3705
- fareAmount.amount,
3706
- fareAmount.fare.contractAddress,
3707
- expiredAt,
3708
- isX402Job
3709
- );
3710
- }
3711
- const { userOpHash } = yield this.acpContractClient.handleOperation([
3712
- createJobPayload
3713
- ]);
3714
- const jobId = yield this.acpContractClient.getJobId(
3715
- userOpHash,
3716
- this.acpContractClient.walletAddress,
3717
- this.providerAddress
3718
- );
3719
- const payloads = [];
3720
- const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3721
- jobId,
3934
+ } else {
3935
+ createJobPayload = this.acpContractClient.createJobWithAccount(
3936
+ account.id,
3937
+ evaluatorAddress || import_viem3.zeroAddress,
3722
3938
  fareAmount.amount,
3723
- fareAmount.fare.contractAddress
3724
- );
3725
- if (setBudgetWithPaymentTokenPayload) {
3726
- payloads.push(setBudgetWithPaymentTokenPayload);
3727
- }
3728
- payloads.push(
3729
- this.acpContractClient.createMemo(
3730
- jobId,
3731
- JSON.stringify(finalServiceRequirement),
3732
- 0 /* MESSAGE */,
3733
- true,
3734
- 1 /* NEGOTIATION */
3735
- )
3939
+ fareAmount.fare.contractAddress,
3940
+ expiredAt,
3941
+ isX402Job
3736
3942
  );
3737
- yield this.acpContractClient.handleOperation(payloads);
3738
- return jobId;
3739
- });
3943
+ }
3944
+ const { userOpHash } = await this.acpContractClient.handleOperation([
3945
+ createJobPayload
3946
+ ]);
3947
+ const jobId = await this.acpContractClient.getJobId(
3948
+ userOpHash,
3949
+ this.acpContractClient.walletAddress,
3950
+ this.providerAddress
3951
+ );
3952
+ const payloads = [];
3953
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3954
+ jobId,
3955
+ fareAmount.amount,
3956
+ fareAmount.fare.contractAddress
3957
+ );
3958
+ if (setBudgetWithPaymentTokenPayload) {
3959
+ payloads.push(setBudgetWithPaymentTokenPayload);
3960
+ }
3961
+ payloads.push(
3962
+ this.acpContractClient.createMemo(
3963
+ jobId,
3964
+ JSON.stringify(finalServiceRequirement),
3965
+ 0 /* MESSAGE */,
3966
+ true,
3967
+ 1 /* NEGOTIATION */
3968
+ )
3969
+ );
3970
+ await this.acpContractClient.handleOperation(payloads);
3971
+ return jobId;
3740
3972
  }
3741
3973
  };
3742
3974
  var acpJobOffering_default = AcpJobOffering;
@@ -3758,10 +3990,9 @@ var AcpJob = class {
3758
3990
  this.netPayableAmount = netPayableAmount;
3759
3991
  this.priceType = "fixed" /* FIXED */;
3760
3992
  this.priceValue = 0;
3761
- var _a;
3762
- const content = (_a = this.memos.find(
3993
+ const content = this.memos.find(
3763
3994
  (m) => m.nextPhase === 1 /* NEGOTIATION */
3764
- )) == null ? void 0 : _a.content;
3995
+ )?.content;
3765
3996
  if (!content) {
3766
3997
  return;
3767
3998
  }
@@ -3792,18 +4023,16 @@ var AcpJob = class {
3792
4023
  return this.acpContractClient.config.baseFare;
3793
4024
  }
3794
4025
  get deliverable() {
3795
- var _a;
3796
- return (_a = this.memos.find((m) => m.nextPhase === 4 /* COMPLETED */)) == null ? void 0 : _a.content;
4026
+ return this.memos.find((m) => m.nextPhase === 4 /* COMPLETED */)?.content;
3797
4027
  }
3798
4028
  get rejectionReason() {
3799
- var _a;
3800
4029
  const requestMemo = this.memos.find(
3801
4030
  (m) => m.nextPhase === 1 /* NEGOTIATION */ && m.status === "REJECTED" /* REJECTED */
3802
4031
  );
3803
4032
  if (requestMemo) {
3804
4033
  return requestMemo.signedReason;
3805
4034
  }
3806
- return (_a = this.memos.find((m) => m.nextPhase === 5 /* REJECTED */)) == null ? void 0 : _a.content;
4035
+ return this.memos.find((m) => m.nextPhase === 5 /* REJECTED */)?.content;
3807
4036
  }
3808
4037
  get providerAgent() {
3809
4038
  return this.acpClient.getAgent(this.providerAddress);
@@ -3820,337 +4049,311 @@ var AcpJob = class {
3820
4049
  get latestMemo() {
3821
4050
  return this.memos[this.memos.length - 1];
3822
4051
  }
3823
- createRequirement(content) {
3824
- return __async(this, null, function* () {
3825
- const operations = [];
3826
- operations.push(
3827
- this.acpContractClient.createMemo(
3828
- this.id,
3829
- content,
3830
- 0 /* MESSAGE */,
3831
- true,
3832
- 2 /* TRANSACTION */
3833
- )
3834
- );
3835
- return yield this.acpContractClient.handleOperation(operations);
3836
- });
4052
+ async createRequirement(content) {
4053
+ const operations = [];
4054
+ operations.push(
4055
+ this.acpContractClient.createMemo(
4056
+ this.id,
4057
+ content,
4058
+ 0 /* MESSAGE */,
4059
+ true,
4060
+ 2 /* TRANSACTION */
4061
+ )
4062
+ );
4063
+ return await this.acpContractClient.handleOperation(operations);
3837
4064
  }
3838
- createPayableRequirement(_0, _1, _2, _3) {
3839
- return __async(this, arguments, function* (content, type, amount, recipient, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3840
- const operations = [];
3841
- if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
3842
- operations.push(
3843
- this.acpContractClient.approveAllowance(
3844
- amount.amount,
3845
- amount.fare.contractAddress
3846
- )
3847
- );
3848
- }
3849
- const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4065
+ async createPayableRequirement(content, type, amount, recipient, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
4066
+ const operations = [];
4067
+ if (type === 8 /* PAYABLE_TRANSFER_ESCROW */) {
3850
4068
  operations.push(
3851
- this.acpContractClient.createPayableMemo(
3852
- this.id,
3853
- content,
4069
+ this.acpContractClient.approveAllowance(
3854
4070
  amount.amount,
3855
- recipient,
3856
- this.priceType === "percentage" /* PERCENTAGE */ ? BigInt(Math.round(this.priceValue * 1e4)) : feeAmount.amount,
3857
- this.priceType === "percentage" /* PERCENTAGE */ ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
3858
- 2 /* TRANSACTION */,
3859
- type,
3860
- expiredAt,
3861
4071
  amount.fare.contractAddress
3862
4072
  )
3863
4073
  );
3864
- return yield this.acpContractClient.handleOperation(operations);
3865
- });
4074
+ }
4075
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4076
+ const isPercentagePricing = this.priceType === "percentage" /* PERCENTAGE */;
4077
+ operations.push(
4078
+ this.acpContractClient.createPayableMemo(
4079
+ this.id,
4080
+ content,
4081
+ amount.amount,
4082
+ recipient,
4083
+ isPercentagePricing ? BigInt(Math.round(this.priceValue * 1e4)) : feeAmount.amount,
4084
+ isPercentagePricing ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
4085
+ 2 /* TRANSACTION */,
4086
+ type,
4087
+ expiredAt,
4088
+ amount.fare.contractAddress
4089
+ )
4090
+ );
4091
+ return await this.acpContractClient.handleOperation(operations);
3866
4092
  }
3867
- payAndAcceptRequirement(reason) {
3868
- return __async(this, null, function* () {
3869
- const memo = this.memos.find(
3870
- (m) => m.nextPhase === 2 /* TRANSACTION */
3871
- );
3872
- if (!memo) {
3873
- throw new acpError_default("No notification memo found");
3874
- }
3875
- const operations = [];
3876
- const baseFareAmount = new FareAmount(this.price, this.baseFare);
3877
- const transferAmount = memo.payableDetails ? yield FareAmountBase.fromContractAddress(
3878
- memo.payableDetails.amount,
3879
- memo.payableDetails.token,
3880
- this.config
3881
- ) : new FareAmount(0, this.baseFare);
3882
- const totalAmount = baseFareAmount.fare.contractAddress === transferAmount.fare.contractAddress ? baseFareAmount.add(transferAmount) : baseFareAmount;
4093
+ async payAndAcceptRequirement(reason) {
4094
+ const memo = this.memos.find(
4095
+ (m) => m.nextPhase === 2 /* TRANSACTION */
4096
+ );
4097
+ if (!memo) {
4098
+ throw new acpError_default("No notification memo found");
4099
+ }
4100
+ const operations = [];
4101
+ const baseFareAmount = new FareAmount(this.price, this.baseFare);
4102
+ const transferAmount = memo.payableDetails ? await FareAmountBase.fromContractAddress(
4103
+ memo.payableDetails.amount,
4104
+ memo.payableDetails.token,
4105
+ this.config
4106
+ ) : new FareAmount(0, this.baseFare);
4107
+ const totalAmount = baseFareAmount.fare.contractAddress === transferAmount.fare.contractAddress ? baseFareAmount.add(transferAmount) : baseFareAmount;
4108
+ operations.push(
4109
+ this.acpContractClient.approveAllowance(
4110
+ totalAmount.amount,
4111
+ this.baseFare.contractAddress
4112
+ )
4113
+ );
4114
+ if (baseFareAmount.fare.contractAddress !== transferAmount.fare.contractAddress) {
3883
4115
  operations.push(
3884
4116
  this.acpContractClient.approveAllowance(
3885
- totalAmount.amount,
3886
- this.baseFare.contractAddress
3887
- )
3888
- );
3889
- if (baseFareAmount.fare.contractAddress !== transferAmount.fare.contractAddress) {
3890
- operations.push(
3891
- this.acpContractClient.approveAllowance(
3892
- transferAmount.amount,
3893
- transferAmount.fare.contractAddress
3894
- )
3895
- );
3896
- }
3897
- operations.push(this.acpContractClient.signMemo(memo.id, true, reason));
3898
- operations.push(
3899
- this.acpContractClient.createMemo(
3900
- this.id,
3901
- `Payment made. ${reason != null ? reason : ""}`.trim(),
3902
- 0 /* MESSAGE */,
3903
- true,
3904
- 3 /* EVALUATION */
4117
+ transferAmount.amount,
4118
+ transferAmount.fare.contractAddress
3905
4119
  )
3906
4120
  );
3907
- const x402PaymentDetails = yield this.acpContractClient.getX402PaymentDetails(this.id);
3908
- if (x402PaymentDetails.isX402) {
3909
- yield this.performX402Payment(this.price);
3910
- }
3911
- return yield this.acpContractClient.handleOperation(operations);
3912
- });
4121
+ }
4122
+ operations.push(this.acpContractClient.signMemo(memo.id, true, reason));
4123
+ operations.push(
4124
+ this.acpContractClient.createMemo(
4125
+ this.id,
4126
+ `Payment made. ${reason ?? ""}`.trim(),
4127
+ 0 /* MESSAGE */,
4128
+ true,
4129
+ 3 /* EVALUATION */
4130
+ )
4131
+ );
4132
+ const x402PaymentDetails = await this.acpContractClient.getX402PaymentDetails(this.id);
4133
+ if (x402PaymentDetails.isX402) {
4134
+ await this.performX402Payment(this.price);
4135
+ }
4136
+ return await this.acpContractClient.handleOperation(operations);
3913
4137
  }
3914
- respond(accept, reason) {
3915
- return __async(this, null, function* () {
3916
- const memoContent = `${reason || `Job ${this.id} ${accept ? "accepted" : "rejected"}.`}`;
3917
- if (accept) {
3918
- yield this.accept(memoContent);
3919
- return this.createRequirement(memoContent);
3920
- }
3921
- return yield this.reject(memoContent);
3922
- });
4138
+ async respond(accept, reason) {
4139
+ const memoContent = `${reason || `Job ${this.id} ${accept ? "accepted" : "rejected"}.`}`;
4140
+ if (accept) {
4141
+ await this.accept(memoContent);
4142
+ return this.createRequirement(memoContent);
4143
+ }
4144
+ return await this.reject(memoContent);
3923
4145
  }
3924
- accept(reason) {
3925
- return __async(this, null, function* () {
3926
- const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
4146
+ async accept(reason) {
4147
+ const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
4148
+ const latestMemo = this.latestMemo;
4149
+ if (latestMemo?.nextPhase !== 1 /* NEGOTIATION */) {
4150
+ throw new acpError_default("No request memo found");
4151
+ }
4152
+ return await latestMemo.sign(true, memoContent);
4153
+ }
4154
+ async reject(reason) {
4155
+ const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
4156
+ if (this.phase === 0 /* REQUEST */) {
3927
4157
  const latestMemo = this.latestMemo;
3928
- if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
4158
+ if (latestMemo?.nextPhase !== 1 /* NEGOTIATION */) {
3929
4159
  throw new acpError_default("No request memo found");
3930
4160
  }
3931
- return yield latestMemo.sign(true, memoContent);
3932
- });
3933
- }
3934
- reject(reason) {
3935
- return __async(this, null, function* () {
3936
- const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
3937
- if (this.phase === 0 /* REQUEST */) {
3938
- const latestMemo = this.latestMemo;
3939
- if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3940
- throw new acpError_default("No request memo found");
3941
- }
3942
- return yield latestMemo.sign(false, memoContent);
3943
- }
3944
- const operations = [];
3945
- operations.push(
3946
- this.acpContractClient.createMemo(
3947
- this.id,
3948
- memoContent,
3949
- 0 /* MESSAGE */,
3950
- true,
3951
- 5 /* REJECTED */
3952
- )
3953
- );
3954
- return yield this.acpContractClient.handleOperation(operations);
3955
- });
4161
+ return await latestMemo.sign(false, memoContent);
4162
+ }
4163
+ const operations = [];
4164
+ operations.push(
4165
+ this.acpContractClient.createMemo(
4166
+ this.id,
4167
+ memoContent,
4168
+ 0 /* MESSAGE */,
4169
+ true,
4170
+ 5 /* REJECTED */
4171
+ )
4172
+ );
4173
+ return await this.acpContractClient.handleOperation(operations);
3956
4174
  }
3957
- rejectPayable() {
3958
- return __async(this, arguments, function* (reason = "", amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3959
- const memoContent = `Job ${this.id} rejected. ${reason}`;
3960
- const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3961
- const operations = [];
3962
- operations.push(
3963
- this.acpContractClient.approveAllowance(
3964
- amount.amount,
3965
- amount.fare.contractAddress
3966
- )
3967
- );
3968
- operations.push(
3969
- this.acpContractClient.createPayableMemo(
3970
- this.id,
3971
- memoContent,
3972
- amount.amount,
3973
- this.clientAddress,
3974
- feeAmount.amount,
3975
- 0 /* NO_FEE */,
3976
- 5 /* REJECTED */,
3977
- 7 /* PAYABLE_TRANSFER */,
3978
- expiredAt,
3979
- amount.fare.contractAddress
3980
- )
3981
- );
3982
- return yield this.acpContractClient.handleOperation(operations);
3983
- });
4175
+ async rejectPayable(reason = "", amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
4176
+ const memoContent = `Job ${this.id} rejected. ${reason}`;
4177
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4178
+ const operations = [];
4179
+ operations.push(
4180
+ this.acpContractClient.approveAllowance(
4181
+ amount.amount,
4182
+ amount.fare.contractAddress
4183
+ )
4184
+ );
4185
+ operations.push(
4186
+ this.acpContractClient.createPayableMemo(
4187
+ this.id,
4188
+ memoContent,
4189
+ amount.amount,
4190
+ this.clientAddress,
4191
+ feeAmount.amount,
4192
+ 0 /* NO_FEE */,
4193
+ 5 /* REJECTED */,
4194
+ 7 /* PAYABLE_TRANSFER */,
4195
+ expiredAt,
4196
+ amount.fare.contractAddress
4197
+ )
4198
+ );
4199
+ return await this.acpContractClient.handleOperation(operations);
3984
4200
  }
3985
- deliver(deliverable) {
3986
- return __async(this, null, function* () {
3987
- var _a;
3988
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
3989
- throw new acpError_default("No transaction memo found");
3990
- }
3991
- const operations = [];
3992
- operations.push(
3993
- this.acpContractClient.createMemo(
3994
- this.id,
3995
- preparePayload(deliverable),
3996
- 0 /* MESSAGE */,
3997
- true,
3998
- 4 /* COMPLETED */
3999
- )
4000
- );
4001
- return yield this.acpContractClient.handleOperation(operations);
4002
- });
4201
+ async deliver(deliverable) {
4202
+ if (this.latestMemo?.nextPhase !== 3 /* EVALUATION */) {
4203
+ throw new acpError_default("No transaction memo found");
4204
+ }
4205
+ const operations = [];
4206
+ operations.push(
4207
+ this.acpContractClient.createMemo(
4208
+ this.id,
4209
+ preparePayload(deliverable),
4210
+ 0 /* MESSAGE */,
4211
+ true,
4212
+ 4 /* COMPLETED */
4213
+ )
4214
+ );
4215
+ return await this.acpContractClient.handleOperation(operations);
4003
4216
  }
4004
- deliverPayable(_0, _1) {
4005
- return __async(this, arguments, function* (deliverable, amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
4006
- var _a;
4007
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 3 /* EVALUATION */) {
4008
- throw new acpError_default("No transaction memo found");
4009
- }
4010
- const operations = [];
4011
- operations.push(
4012
- this.acpContractClient.approveAllowance(
4013
- amount.amount,
4014
- amount.fare.contractAddress
4015
- )
4016
- );
4017
- const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4018
- operations.push(
4019
- this.acpContractClient.createPayableMemo(
4020
- this.id,
4021
- preparePayload(deliverable),
4022
- amount.amount,
4023
- this.clientAddress,
4024
- feeAmount.amount,
4025
- 0 /* NO_FEE */,
4026
- 4 /* COMPLETED */,
4027
- 7 /* PAYABLE_TRANSFER */,
4028
- expiredAt,
4029
- amount.fare.contractAddress
4030
- )
4031
- );
4032
- return yield this.acpContractClient.handleOperation(operations);
4033
- });
4217
+ async deliverPayable(deliverable, amount, skipFee = false, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
4218
+ if (this.latestMemo?.nextPhase !== 3 /* EVALUATION */) {
4219
+ throw new acpError_default("No transaction memo found");
4220
+ }
4221
+ const operations = [];
4222
+ operations.push(
4223
+ this.acpContractClient.approveAllowance(
4224
+ amount.amount,
4225
+ amount.fare.contractAddress
4226
+ )
4227
+ );
4228
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4229
+ const isPercentagePricing = this.priceType === "percentage" /* PERCENTAGE */ && !skipFee;
4230
+ operations.push(
4231
+ this.acpContractClient.createPayableMemo(
4232
+ this.id,
4233
+ preparePayload(deliverable),
4234
+ amount.amount,
4235
+ this.clientAddress,
4236
+ isPercentagePricing ? BigInt(Math.round(this.priceValue * 1e4)) : feeAmount.amount,
4237
+ isPercentagePricing ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
4238
+ 4 /* COMPLETED */,
4239
+ 7 /* PAYABLE_TRANSFER */,
4240
+ expiredAt,
4241
+ amount.fare.contractAddress
4242
+ )
4243
+ );
4244
+ return await this.acpContractClient.handleOperation(operations);
4034
4245
  }
4035
- evaluate(accept, reason) {
4036
- return __async(this, null, function* () {
4037
- var _a;
4038
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 4 /* COMPLETED */) {
4039
- throw new acpError_default("No evaluation memo found");
4040
- }
4041
- const memo = this.latestMemo;
4042
- yield memo.sign(accept, reason);
4043
- });
4246
+ async evaluate(accept, reason) {
4247
+ if (this.latestMemo?.nextPhase !== 4 /* COMPLETED */) {
4248
+ throw new acpError_default("No evaluation memo found");
4249
+ }
4250
+ const memo = this.latestMemo;
4251
+ await memo.sign(accept, reason);
4044
4252
  }
4045
- createNotification(content) {
4046
- return __async(this, null, function* () {
4047
- const operations = [];
4048
- operations.push(
4049
- this.acpContractClient.createMemo(
4050
- this.id,
4051
- content,
4052
- 9 /* NOTIFICATION */,
4053
- true,
4054
- 4 /* COMPLETED */
4055
- )
4056
- );
4057
- return yield this.acpContractClient.handleOperation(operations);
4058
- });
4253
+ async createNotification(content) {
4254
+ const operations = [];
4255
+ operations.push(
4256
+ this.acpContractClient.createMemo(
4257
+ this.id,
4258
+ content,
4259
+ 9 /* NOTIFICATION */,
4260
+ true,
4261
+ 4 /* COMPLETED */
4262
+ )
4263
+ );
4264
+ return await this.acpContractClient.handleOperation(operations);
4059
4265
  }
4060
- createPayableNotification(_0, _1) {
4061
- return __async(this, arguments, function* (content, amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
4062
- const operations = [];
4063
- operations.push(
4064
- this.acpContractClient.approveAllowance(
4065
- amount.amount,
4066
- amount.fare.contractAddress
4067
- )
4068
- );
4069
- const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4070
- operations.push(
4071
- this.acpContractClient.createPayableMemo(
4072
- this.id,
4073
- content,
4074
- amount.amount,
4075
- this.clientAddress,
4076
- feeAmount.amount,
4077
- 0 /* NO_FEE */,
4078
- 4 /* COMPLETED */,
4079
- 10 /* PAYABLE_NOTIFICATION */,
4080
- expiredAt,
4081
- amount.fare.contractAddress
4082
- )
4083
- );
4084
- return yield this.acpContractClient.handleOperation(operations);
4085
- });
4266
+ async createPayableNotification(content, amount, skipFee = false, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
4267
+ const operations = [];
4268
+ operations.push(
4269
+ this.acpContractClient.approveAllowance(
4270
+ amount.amount,
4271
+ amount.fare.contractAddress
4272
+ )
4273
+ );
4274
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
4275
+ const isPercentagePricing = this.priceType === "percentage" /* PERCENTAGE */ && !skipFee;
4276
+ operations.push(
4277
+ this.acpContractClient.createPayableMemo(
4278
+ this.id,
4279
+ content,
4280
+ amount.amount,
4281
+ this.clientAddress,
4282
+ isPercentagePricing ? BigInt(Math.round(this.priceValue * 1e4)) : feeAmount.amount,
4283
+ isPercentagePricing ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
4284
+ 4 /* COMPLETED */,
4285
+ 10 /* PAYABLE_NOTIFICATION */,
4286
+ expiredAt,
4287
+ amount.fare.contractAddress
4288
+ )
4289
+ );
4290
+ return await this.acpContractClient.handleOperation(operations);
4086
4291
  }
4087
- performX402Payment(budget) {
4088
- return __async(this, null, function* () {
4089
- const paymentUrl = "/acp-budget";
4090
- const x402PayableREquirements = yield this.acpContractClient.performX402Request(
4091
- paymentUrl,
4092
- this.acpContractClient.getAcpVersion(),
4093
- budget.toString()
4094
- );
4095
- if (!x402PayableREquirements.isPaymentRequired) {
4096
- return;
4097
- }
4098
- if (!x402PayableREquirements.data.accepts.length) {
4099
- throw new acpError_default("No X402 payment requirements found");
4100
- }
4101
- const requirement = x402PayableREquirements.data.accepts[0];
4102
- const { encodedPayment, signature, message } = yield this.acpContractClient.generateX402Payment(
4103
- {
4104
- to: requirement.payTo,
4105
- value: Number(requirement.maxAmountRequired),
4106
- maxTimeoutSeconds: requirement.maxTimeoutSeconds,
4107
- asset: requirement.asset
4108
- },
4109
- x402PayableREquirements.data
4110
- );
4111
- yield this.acpContractClient.updateJobX402Nonce(this.id, message.nonce);
4112
- const x402Response = yield this.acpContractClient.performX402Request(
4113
- paymentUrl,
4114
- this.acpContractClient.getAcpVersion(),
4115
- budget.toString(),
4116
- encodedPayment
4292
+ async performX402Payment(budget) {
4293
+ const paymentUrl = "/acp-budget";
4294
+ const x402PayableREquirements = await this.acpContractClient.performX402Request(
4295
+ paymentUrl,
4296
+ this.acpContractClient.getAcpVersion(),
4297
+ budget.toString()
4298
+ );
4299
+ if (!x402PayableREquirements.isPaymentRequired) {
4300
+ return;
4301
+ }
4302
+ if (!x402PayableREquirements.data.accepts.length) {
4303
+ throw new acpError_default("No X402 payment requirements found");
4304
+ }
4305
+ const requirement = x402PayableREquirements.data.accepts[0];
4306
+ const { encodedPayment, signature, message } = await this.acpContractClient.generateX402Payment(
4307
+ {
4308
+ to: requirement.payTo,
4309
+ value: Number(requirement.maxAmountRequired),
4310
+ maxTimeoutSeconds: requirement.maxTimeoutSeconds,
4311
+ asset: requirement.asset
4312
+ },
4313
+ x402PayableREquirements.data
4314
+ );
4315
+ await this.acpContractClient.updateJobX402Nonce(this.id, message.nonce);
4316
+ const x402Response = await this.acpContractClient.performX402Request(
4317
+ paymentUrl,
4318
+ this.acpContractClient.getAcpVersion(),
4319
+ budget.toString(),
4320
+ encodedPayment
4321
+ );
4322
+ if (x402Response.isPaymentRequired) {
4323
+ const operations = await this.acpContractClient.submitTransferWithAuthorization(
4324
+ message.from,
4325
+ message.to,
4326
+ BigInt(message.value),
4327
+ BigInt(message.validAfter),
4328
+ BigInt(message.validBefore),
4329
+ message.nonce,
4330
+ signature
4117
4331
  );
4118
- if (x402Response.isPaymentRequired) {
4119
- const operations = yield this.acpContractClient.submitTransferWithAuthorization(
4120
- message.from,
4121
- message.to,
4122
- BigInt(message.value),
4123
- BigInt(message.validAfter),
4124
- BigInt(message.validBefore),
4125
- message.nonce,
4126
- signature
4127
- );
4128
- yield this.acpContractClient.handleOperation(operations);
4332
+ await this.acpContractClient.handleOperation(operations);
4333
+ }
4334
+ let waitMs = 2e3;
4335
+ const maxWaitMs = 3e4;
4336
+ let iterationCount = 0;
4337
+ const maxIterations = 10;
4338
+ while (true) {
4339
+ const x402PaymentDetails = await this.acpContractClient.getX402PaymentDetails(this.id);
4340
+ if (x402PaymentDetails.isBudgetReceived) {
4341
+ break;
4129
4342
  }
4130
- let waitMs = 2e3;
4131
- const maxWaitMs = 3e4;
4132
- let iterationCount = 0;
4133
- const maxIterations = 10;
4134
- while (true) {
4135
- const x402PaymentDetails = yield this.acpContractClient.getX402PaymentDetails(this.id);
4136
- if (x402PaymentDetails.isBudgetReceived) {
4137
- break;
4138
- }
4139
- iterationCount++;
4140
- if (iterationCount >= maxIterations) {
4141
- throw new acpError_default("X402 payment timed out");
4142
- }
4143
- yield new Promise((resolve) => setTimeout(resolve, waitMs));
4144
- waitMs = Math.min(waitMs * 2, maxWaitMs);
4343
+ iterationCount++;
4344
+ if (iterationCount >= maxIterations) {
4345
+ throw new acpError_default("X402 payment timed out");
4145
4346
  }
4146
- });
4347
+ await new Promise((resolve) => setTimeout(resolve, waitMs));
4348
+ waitMs = Math.min(waitMs * 2, maxWaitMs);
4349
+ }
4147
4350
  }
4148
4351
  };
4149
4352
  var acpJob_default = AcpJob;
4150
4353
 
4151
4354
  // src/acpMemo.ts
4152
4355
  var AcpMemo = class {
4153
- constructor(contractClient, id, type, content, nextPhase, status, senderAddress, signedReason, expiry, payableDetails) {
4356
+ constructor(contractClient, id, type, content, nextPhase, status, senderAddress, signedReason, expiry, payableDetails, txHash, signedTxHash) {
4154
4357
  this.contractClient = contractClient;
4155
4358
  this.id = id;
4156
4359
  this.type = type;
@@ -4161,6 +4364,8 @@ var AcpMemo = class {
4161
4364
  this.signedReason = signedReason;
4162
4365
  this.expiry = expiry;
4163
4366
  this.payableDetails = payableDetails;
4367
+ this.txHash = txHash;
4368
+ this.signedTxHash = signedTxHash;
4164
4369
  if (this.payableDetails) {
4165
4370
  this.payableDetails.amount = BigInt(this.payableDetails.amount);
4166
4371
  this.payableDetails.feeAmount = BigInt(this.payableDetails.feeAmount);
@@ -4168,28 +4373,23 @@ var AcpMemo = class {
4168
4373
  this.structuredContent = tryParseJson(this.content) || void 0;
4169
4374
  }
4170
4375
  get payloadType() {
4171
- var _a;
4172
- return (_a = this.structuredContent) == null ? void 0 : _a.type;
4376
+ return this.structuredContent?.type;
4173
4377
  }
4174
4378
  getStructuredContent() {
4175
4379
  return this.structuredContent;
4176
4380
  }
4177
- create(jobId, isSecured = true) {
4178
- return __async(this, null, function* () {
4179
- return yield this.contractClient.createMemo(
4180
- jobId,
4181
- this.content,
4182
- this.type,
4183
- isSecured,
4184
- this.nextPhase
4185
- );
4186
- });
4381
+ async create(jobId, isSecured = true) {
4382
+ return await this.contractClient.createMemo(
4383
+ jobId,
4384
+ this.content,
4385
+ this.type,
4386
+ isSecured,
4387
+ this.nextPhase
4388
+ );
4187
4389
  }
4188
- sign(approved, reason) {
4189
- return __async(this, null, function* () {
4190
- const payload = this.contractClient.signMemo(this.id, approved, reason);
4191
- return yield this.contractClient.handleOperation([payload]);
4192
- });
4390
+ async sign(approved, reason) {
4391
+ const payload = this.contractClient.signMemo(this.id, approved, reason);
4392
+ return await this.contractClient.handleOperation([payload]);
4193
4393
  }
4194
4394
  };
4195
4395
  var acpMemo_default = AcpMemo;
@@ -4203,14 +4403,12 @@ var AcpAccount = class {
4203
4403
  this.providerAddress = providerAddress;
4204
4404
  this.metadata = metadata;
4205
4405
  }
4206
- updateMetadata(metadata) {
4207
- return __async(this, null, function* () {
4208
- const hash = yield this.contractClient.updateAccountMetadata(
4209
- this.id,
4210
- JSON.stringify(metadata)
4211
- );
4212
- return hash;
4213
- });
4406
+ async updateMetadata(metadata) {
4407
+ const hash = await this.contractClient.updateAccountMetadata(
4408
+ this.id,
4409
+ JSON.stringify(metadata)
4410
+ );
4411
+ return hash;
4214
4412
  }
4215
4413
  };
4216
4414
 
@@ -4251,10 +4449,8 @@ var AcpClient = class {
4251
4449
  get acpUrl() {
4252
4450
  return this.acpContractClient.config.acpUrl;
4253
4451
  }
4254
- defaultOnEvaluate(job) {
4255
- return __async(this, null, function* () {
4256
- yield job.evaluate(true, "Evaluated by default");
4257
- });
4452
+ async defaultOnEvaluate(job) {
4453
+ await job.evaluate(true, "Evaluated by default");
4258
4454
  }
4259
4455
  get walletAddress() {
4260
4456
  if (Array.isArray(this.acpContractClient)) {
@@ -4262,267 +4458,39 @@ var AcpClient = class {
4262
4458
  }
4263
4459
  return this.acpContractClient.walletAddress;
4264
4460
  }
4265
- init() {
4266
- return __async(this, null, function* () {
4267
- const socket = (0, import_socket.io)(this.acpUrl, {
4268
- auth: {
4269
- walletAddress: this.walletAddress
4270
- },
4271
- extraHeaders: {
4272
- "x-sdk-version": version,
4273
- "x-sdk-language": "node",
4274
- "x-contract-address": this.contractClients[0].contractAddress
4275
- // always prioritize the first client
4276
- },
4277
- transports: ["websocket"]
4278
- });
4279
- socket.on("roomJoined" /* ROOM_JOINED */, (_, callback) => {
4280
- console.log("Joined ACP Room");
4281
- callback(true);
4282
- });
4283
- socket.on(
4284
- "onEvaluate" /* ON_EVALUATE */,
4285
- (data, callback) => __async(this, null, function* () {
4286
- callback(true);
4287
- if (this.onEvaluate) {
4288
- const job = new acpJob_default(
4289
- this,
4290
- data.id,
4291
- data.clientAddress,
4292
- data.providerAddress,
4293
- data.evaluatorAddress,
4294
- data.price,
4295
- data.priceTokenAddress,
4296
- data.memos.map((memo) => {
4297
- return new acpMemo_default(
4298
- this.contractClientByAddress(data.contractAddress),
4299
- memo.id,
4300
- memo.memoType,
4301
- memo.content,
4302
- memo.nextPhase,
4303
- memo.status,
4304
- memo.senderAddress,
4305
- memo.signedReason,
4306
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4307
- memo.payableDetails
4308
- );
4309
- }),
4310
- data.phase,
4311
- data.context,
4312
- data.contractAddress,
4313
- data.netPayableAmount
4314
- );
4315
- this.onEvaluate(job);
4316
- }
4317
- })
4318
- );
4319
- socket.on(
4320
- "onNewTask" /* ON_NEW_TASK */,
4321
- (data, callback) => __async(this, null, function* () {
4322
- callback(true);
4323
- if (this.onNewTask) {
4324
- const job = new acpJob_default(
4325
- this,
4326
- data.id,
4327
- data.clientAddress,
4328
- data.providerAddress,
4329
- data.evaluatorAddress,
4330
- data.price,
4331
- data.priceTokenAddress,
4332
- data.memos.map((memo) => {
4333
- return new acpMemo_default(
4334
- this.contractClientByAddress(data.contractAddress),
4335
- memo.id,
4336
- memo.memoType,
4337
- memo.content,
4338
- memo.nextPhase,
4339
- memo.status,
4340
- memo.senderAddress,
4341
- memo.signedReason,
4342
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4343
- memo.payableDetails
4344
- );
4345
- }),
4346
- data.phase,
4347
- data.context,
4348
- data.contractAddress,
4349
- data.netPayableAmount
4350
- );
4351
- this.onNewTask(
4352
- job,
4353
- job.memos.find((m) => m.id == data.memoToSign)
4354
- );
4355
- }
4356
- })
4357
- );
4358
- const cleanup = () => __async(this, null, function* () {
4359
- if (socket) {
4360
- socket.disconnect();
4361
- }
4362
- process.exit(0);
4363
- });
4364
- process.on("SIGINT", cleanup);
4365
- process.on("SIGTERM", cleanup);
4366
- });
4367
- }
4368
- browseAgents(keyword, options) {
4369
- return __async(this, null, function* () {
4370
- let { cluster, sort_by, top_k, graduationStatus, onlineStatus } = options;
4371
- top_k = top_k != null ? top_k : 5;
4372
- let url = `${this.acpUrl}/api/agents/v3/search?search=${keyword}`;
4373
- if (sort_by && sort_by.length > 0) {
4374
- url += `&sortBy=${sort_by.map((s) => s).join(",")}`;
4375
- }
4376
- if (top_k) {
4377
- url += `&top_k=${top_k}`;
4378
- }
4379
- if (this.walletAddress) {
4380
- url += `&walletAddressesToExclude=${this.walletAddress}`;
4381
- }
4382
- if (cluster) {
4383
- url += `&cluster=${cluster}`;
4384
- }
4385
- if (graduationStatus) {
4386
- url += `&graduationStatus=${graduationStatus}`;
4387
- }
4388
- if (onlineStatus) {
4389
- url += `&onlineStatus=${onlineStatus}`;
4390
- }
4391
- const response = yield fetch(url);
4392
- const data = yield response.json();
4393
- const availableContractClientAddresses = this.contractClients.map(
4394
- (client) => client.contractAddress.toLowerCase()
4395
- );
4396
- return data.data.filter(
4397
- (agent) => agent.walletAddress.toLowerCase() !== this.walletAddress.toLowerCase()
4398
- ).filter(
4399
- (agent) => availableContractClientAddresses.includes(
4400
- agent.contractAddress.toLowerCase()
4401
- )
4402
- ).map((agent) => {
4403
- const acpContractClient = this.contractClients.find(
4404
- (client) => client.contractAddress.toLowerCase() === agent.contractAddress.toLowerCase()
4405
- );
4406
- if (!acpContractClient) {
4407
- throw new acpError_default("ACP contract client not found");
4408
- }
4409
- return {
4410
- id: agent.id,
4411
- name: agent.name,
4412
- description: agent.description,
4413
- jobOfferings: agent.jobs.map((jobs) => {
4414
- return new acpJobOffering_default(
4415
- this,
4416
- acpContractClient,
4417
- agent.walletAddress,
4418
- jobs.name,
4419
- jobs.priceV2.value,
4420
- jobs.priceV2.type,
4421
- jobs.requirement
4422
- );
4423
- }),
4424
- contractAddress: agent.contractAddress,
4425
- twitterHandle: agent.twitterHandle,
4426
- walletAddress: agent.walletAddress,
4427
- metrics: agent.metrics,
4428
- resource: agent.resources
4429
- };
4430
- });
4461
+ async init() {
4462
+ const socket = (0, import_socket.io)(this.acpUrl, {
4463
+ auth: {
4464
+ walletAddress: this.walletAddress
4465
+ },
4466
+ extraHeaders: {
4467
+ "x-sdk-version": version,
4468
+ "x-sdk-language": "node",
4469
+ "x-contract-address": this.contractClients[0].contractAddress
4470
+ // always prioritize the first client
4471
+ },
4472
+ transports: ["websocket"]
4431
4473
  });
4432
- }
4433
- initiateJob(_0, _1, _2, _3) {
4434
- return __async(this, arguments, function* (providerAddress, serviceRequirement, fareAmount, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
4435
- if (providerAddress === this.walletAddress) {
4436
- throw new acpError_default(
4437
- "Provider address cannot be the same as the client address"
4438
- );
4439
- }
4440
- const account = yield this.getByClientAndProvider(
4441
- this.walletAddress,
4442
- providerAddress,
4443
- this.acpContractClient
4444
- );
4445
- const isV1 = [
4446
- baseSepoliaAcpConfig.contractAddress,
4447
- baseSepoliaAcpX402Config.contractAddress,
4448
- baseAcpConfig.contractAddress,
4449
- baseAcpX402Config.contractAddress
4450
- ].includes(this.acpContractClient.config.contractAddress);
4451
- const defaultEvaluatorAddress = isV1 && !evaluatorAddress ? this.walletAddress : import_viem4.zeroAddress;
4452
- const chainId = this.acpContractClient.config.chain.id;
4453
- const isUsdcPaymentToken = USDC_TOKEN_ADDRESS[chainId].toLowerCase() === fareAmount.fare.contractAddress.toLowerCase();
4454
- const isX402Job = this.acpContractClient.config.x402Config && isUsdcPaymentToken;
4455
- const createJobPayload = isV1 || !account ? this.acpContractClient.createJob(
4456
- providerAddress,
4457
- evaluatorAddress || defaultEvaluatorAddress,
4458
- expiredAt,
4459
- fareAmount.fare.contractAddress,
4460
- fareAmount.amount,
4461
- "",
4462
- isX402Job
4463
- ) : this.acpContractClient.createJobWithAccount(
4464
- account.id,
4465
- evaluatorAddress || defaultEvaluatorAddress,
4466
- fareAmount.amount,
4467
- fareAmount.fare.contractAddress,
4468
- expiredAt,
4469
- isX402Job
4470
- );
4471
- const { userOpHash } = yield this.acpContractClient.handleOperation([
4472
- createJobPayload
4473
- ]);
4474
- const jobId = yield this.acpContractClient.getJobId(
4475
- userOpHash,
4476
- this.walletAddress,
4477
- providerAddress
4478
- );
4479
- const payloads = [];
4480
- const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4481
- jobId,
4482
- fareAmount.amount,
4483
- fareAmount.fare.contractAddress
4484
- );
4485
- if (setBudgetWithPaymentTokenPayload) {
4486
- payloads.push(setBudgetWithPaymentTokenPayload);
4487
- }
4488
- payloads.push(
4489
- this.acpContractClient.createMemo(
4490
- jobId,
4491
- preparePayload(serviceRequirement),
4492
- 0 /* MESSAGE */,
4493
- true,
4494
- 1 /* NEGOTIATION */
4495
- )
4496
- );
4497
- yield this.acpContractClient.handleOperation(payloads);
4498
- return jobId;
4474
+ socket.on("roomJoined" /* ROOM_JOINED */, (_, callback) => {
4475
+ console.log("Joined ACP Room");
4476
+ callback(true);
4499
4477
  });
4500
- }
4501
- getActiveJobs(page = 1, pageSize = 10) {
4502
- return __async(this, null, function* () {
4503
- let url = `${this.acpUrl}/api/jobs/active?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4504
- try {
4505
- const response = yield fetch(url, {
4506
- headers: {
4507
- "wallet-address": this.walletAddress
4508
- }
4509
- });
4510
- const data = yield response.json();
4511
- if (data.error) {
4512
- throw new acpError_default(data.error.message);
4513
- }
4514
- return data.data.map((job) => {
4515
- return new acpJob_default(
4478
+ socket.on(
4479
+ "onEvaluate" /* ON_EVALUATE */,
4480
+ async (data, callback) => {
4481
+ callback(true);
4482
+ if (this.onEvaluate) {
4483
+ const job = new acpJob_default(
4516
4484
  this,
4517
- job.id,
4518
- job.clientAddress,
4519
- job.providerAddress,
4520
- job.evaluatorAddress,
4521
- job.price,
4522
- job.priceTokenAddress,
4523
- job.memos.map((memo) => {
4485
+ data.id,
4486
+ data.clientAddress,
4487
+ data.providerAddress,
4488
+ data.evaluatorAddress,
4489
+ data.price,
4490
+ data.priceTokenAddress,
4491
+ data.memos.map((memo) => {
4524
4492
  return new acpMemo_default(
4525
- this.contractClientByAddress(job.contractAddress),
4493
+ this.contractClientByAddress(data.contractAddress),
4526
4494
  memo.id,
4527
4495
  memo.memoType,
4528
4496
  memo.content,
@@ -4531,45 +4499,36 @@ var AcpClient = class {
4531
4499
  memo.senderAddress,
4532
4500
  memo.signedReason,
4533
4501
  memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4534
- memo.payableDetails
4502
+ memo.payableDetails,
4503
+ memo.txHash,
4504
+ memo.signedTxHash
4535
4505
  );
4536
4506
  }),
4537
- job.phase,
4538
- job.context,
4539
- job.contractAddress,
4540
- job.netPayableAmount
4507
+ data.phase,
4508
+ data.context,
4509
+ data.contractAddress,
4510
+ data.netPayableAmount
4541
4511
  );
4542
- });
4543
- } catch (error) {
4544
- throw new acpError_default("Failed to get active jobs", error);
4545
- }
4546
- });
4547
- }
4548
- getPendingMemoJobs(page = 1, pageSize = 10) {
4549
- return __async(this, null, function* () {
4550
- let url = `${this.acpUrl}/api/jobs/pending-memos?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4551
- try {
4552
- const response = yield fetch(url, {
4553
- headers: {
4554
- "wallet-address": this.acpContractClient.walletAddress
4555
- }
4556
- });
4557
- const data = yield response.json();
4558
- if (data.error) {
4559
- throw new acpError_default(data.error.message);
4512
+ this.onEvaluate(job);
4560
4513
  }
4561
- return data.data.map((job) => {
4562
- return new acpJob_default(
4514
+ }
4515
+ );
4516
+ socket.on(
4517
+ "onNewTask" /* ON_NEW_TASK */,
4518
+ async (data, callback) => {
4519
+ callback(true);
4520
+ if (this.onNewTask) {
4521
+ const job = new acpJob_default(
4563
4522
  this,
4564
- job.id,
4565
- job.clientAddress,
4566
- job.providerAddress,
4567
- job.evaluatorAddress,
4568
- job.price,
4569
- job.priceTokenAddress,
4570
- job.memos.map((memo) => {
4523
+ data.id,
4524
+ data.clientAddress,
4525
+ data.providerAddress,
4526
+ data.evaluatorAddress,
4527
+ data.price,
4528
+ data.priceTokenAddress,
4529
+ data.memos.map((memo) => {
4571
4530
  return new acpMemo_default(
4572
- this.contractClientByAddress(job.contractAddress),
4531
+ this.contractClientByAddress(data.contractAddress),
4573
4532
  memo.id,
4574
4533
  memo.memoType,
4575
4534
  memo.content,
@@ -4578,131 +4537,268 @@ var AcpClient = class {
4578
4537
  memo.senderAddress,
4579
4538
  memo.signedReason,
4580
4539
  memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4581
- typeof memo.payableDetails === "string" ? tryParseJson(memo.payableDetails) || void 0 : memo.payableDetails
4540
+ memo.payableDetails,
4541
+ memo.txHash,
4542
+ memo.signedTxHash
4582
4543
  );
4583
4544
  }),
4584
- job.phase,
4585
- job.context,
4586
- job.contractAddress,
4587
- job.netPayableAmount
4545
+ data.phase,
4546
+ data.context,
4547
+ data.contractAddress,
4548
+ data.netPayableAmount
4588
4549
  );
4589
- });
4590
- } catch (error) {
4591
- throw new acpError_default("Failed to get pending memo jobs", error);
4550
+ this.onNewTask(
4551
+ job,
4552
+ job.memos.find((m) => m.id == data.memoToSign)
4553
+ );
4554
+ }
4592
4555
  }
4593
- });
4556
+ );
4557
+ const cleanup = async () => {
4558
+ if (socket) {
4559
+ socket.disconnect();
4560
+ }
4561
+ process.exit(0);
4562
+ };
4563
+ process.on("SIGINT", cleanup);
4564
+ process.on("SIGTERM", cleanup);
4594
4565
  }
4595
- getCompletedJobs(page = 1, pageSize = 10) {
4596
- return __async(this, null, function* () {
4597
- let url = `${this.acpUrl}/api/jobs/completed?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4598
- try {
4599
- const response = yield fetch(url, {
4600
- headers: {
4601
- "wallet-address": this.acpContractClient.walletAddress
4602
- }
4603
- });
4604
- const data = yield response.json();
4605
- if (data.error) {
4606
- throw new acpError_default(data.error.message);
4607
- }
4608
- return data.data.map((job) => {
4609
- return new acpJob_default(
4566
+ async browseAgents(keyword, options) {
4567
+ let { cluster, sort_by, top_k, graduationStatus, onlineStatus } = options;
4568
+ top_k = top_k ?? 5;
4569
+ let url = `${this.acpUrl}/api/agents/v4/search?search=${keyword}`;
4570
+ if (sort_by && sort_by.length > 0) {
4571
+ url += `&sortBy=${sort_by.map((s) => s).join(",")}`;
4572
+ }
4573
+ if (top_k) {
4574
+ url += `&top_k=${top_k}`;
4575
+ }
4576
+ if (this.walletAddress) {
4577
+ url += `&walletAddressesToExclude=${this.walletAddress}`;
4578
+ }
4579
+ if (cluster) {
4580
+ url += `&cluster=${cluster}`;
4581
+ }
4582
+ if (graduationStatus) {
4583
+ url += `&graduationStatus=${graduationStatus}`;
4584
+ }
4585
+ if (onlineStatus) {
4586
+ url += `&onlineStatus=${onlineStatus}`;
4587
+ }
4588
+ const response = await fetch(url);
4589
+ const data = await response.json();
4590
+ const availableContractClientAddresses = this.contractClients.map(
4591
+ (client) => client.contractAddress.toLowerCase()
4592
+ );
4593
+ return data.data.filter(
4594
+ (agent) => agent.walletAddress.toLowerCase() !== this.walletAddress.toLowerCase()
4595
+ ).filter(
4596
+ (agent) => availableContractClientAddresses.includes(
4597
+ agent.contractAddress.toLowerCase()
4598
+ )
4599
+ ).map((agent) => {
4600
+ const acpContractClient = this.contractClients.find(
4601
+ (client) => client.contractAddress.toLowerCase() === agent.contractAddress.toLowerCase()
4602
+ );
4603
+ if (!acpContractClient) {
4604
+ throw new acpError_default("ACP contract client not found");
4605
+ }
4606
+ return {
4607
+ id: agent.id,
4608
+ name: agent.name,
4609
+ description: agent.description,
4610
+ jobOfferings: agent.jobs.map((jobs) => {
4611
+ return new acpJobOffering_default(
4610
4612
  this,
4611
- job.id,
4612
- job.clientAddress,
4613
- job.providerAddress,
4614
- job.evaluatorAddress,
4615
- job.price,
4616
- job.priceTokenAddress,
4617
- job.memos.map((memo) => {
4618
- return new acpMemo_default(
4619
- this.contractClientByAddress(job.contractAddress),
4620
- memo.id,
4621
- memo.memoType,
4622
- memo.content,
4623
- memo.nextPhase,
4624
- memo.status,
4625
- memo.senderAddress,
4626
- memo.signedReason,
4627
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4628
- memo.payableDetails
4629
- );
4630
- }),
4631
- job.phase,
4632
- job.context,
4633
- job.contractAddress,
4634
- job.netPayableAmount
4613
+ acpContractClient,
4614
+ agent.walletAddress,
4615
+ jobs.name,
4616
+ jobs.priceV2.value,
4617
+ jobs.priceV2.type,
4618
+ jobs.requirement
4635
4619
  );
4636
- });
4637
- } catch (error) {
4638
- throw new acpError_default("Failed to get completed jobs", error);
4639
- }
4620
+ }),
4621
+ contractAddress: agent.contractAddress,
4622
+ twitterHandle: agent.twitterHandle,
4623
+ walletAddress: agent.walletAddress,
4624
+ metrics: agent.metrics,
4625
+ resource: agent.resources
4626
+ };
4640
4627
  });
4641
4628
  }
4642
- getCancelledJobs(page = 1, pageSize = 10) {
4643
- return __async(this, null, function* () {
4644
- let url = `${this.acpUrl}/api/jobs/cancelled?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4645
- try {
4646
- const response = yield fetch(url, {
4647
- headers: {
4648
- "wallet-address": this.walletAddress
4649
- }
4650
- });
4651
- const data = yield response.json();
4652
- if (data.error) {
4653
- throw new acpError_default(data.error.message);
4629
+ async initiateJob(providerAddress, serviceRequirement, fareAmount, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
4630
+ if (providerAddress === this.walletAddress) {
4631
+ throw new acpError_default(
4632
+ "Provider address cannot be the same as the client address"
4633
+ );
4634
+ }
4635
+ const account = await this.getByClientAndProvider(
4636
+ this.walletAddress,
4637
+ providerAddress,
4638
+ this.acpContractClient
4639
+ );
4640
+ const isV1 = [
4641
+ baseSepoliaAcpConfig.contractAddress,
4642
+ baseSepoliaAcpX402Config.contractAddress,
4643
+ baseAcpConfig.contractAddress,
4644
+ baseAcpX402Config.contractAddress
4645
+ ].includes(this.acpContractClient.config.contractAddress);
4646
+ const defaultEvaluatorAddress = isV1 && !evaluatorAddress ? this.walletAddress : import_viem4.zeroAddress;
4647
+ const chainId = this.acpContractClient.config.chain.id;
4648
+ const isUsdcPaymentToken = USDC_TOKEN_ADDRESS[chainId].toLowerCase() === fareAmount.fare.contractAddress.toLowerCase();
4649
+ const isX402Job = this.acpContractClient.config.x402Config && isUsdcPaymentToken;
4650
+ const createJobPayload = isV1 || !account ? this.acpContractClient.createJob(
4651
+ providerAddress,
4652
+ evaluatorAddress || defaultEvaluatorAddress,
4653
+ expiredAt,
4654
+ fareAmount.fare.contractAddress,
4655
+ fareAmount.amount,
4656
+ "",
4657
+ isX402Job
4658
+ ) : this.acpContractClient.createJobWithAccount(
4659
+ account.id,
4660
+ evaluatorAddress || defaultEvaluatorAddress,
4661
+ fareAmount.amount,
4662
+ fareAmount.fare.contractAddress,
4663
+ expiredAt,
4664
+ isX402Job
4665
+ );
4666
+ const { userOpHash } = await this.acpContractClient.handleOperation([
4667
+ createJobPayload
4668
+ ]);
4669
+ const jobId = await this.acpContractClient.getJobId(
4670
+ userOpHash,
4671
+ this.walletAddress,
4672
+ providerAddress
4673
+ );
4674
+ const payloads = [];
4675
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
4676
+ jobId,
4677
+ fareAmount.amount,
4678
+ fareAmount.fare.contractAddress
4679
+ );
4680
+ if (setBudgetWithPaymentTokenPayload) {
4681
+ payloads.push(setBudgetWithPaymentTokenPayload);
4682
+ }
4683
+ payloads.push(
4684
+ this.acpContractClient.createMemo(
4685
+ jobId,
4686
+ preparePayload(serviceRequirement),
4687
+ 0 /* MESSAGE */,
4688
+ true,
4689
+ 1 /* NEGOTIATION */
4690
+ )
4691
+ );
4692
+ await this.acpContractClient.handleOperation(payloads);
4693
+ return jobId;
4694
+ }
4695
+ async getActiveJobs(page = 1, pageSize = 10) {
4696
+ let url = `${this.acpUrl}/api/jobs/active?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4697
+ try {
4698
+ const response = await fetch(url, {
4699
+ headers: {
4700
+ "wallet-address": this.walletAddress
4654
4701
  }
4655
- return data.data.map((job) => {
4656
- return new acpJob_default(
4657
- this,
4658
- job.id,
4659
- job.clientAddress,
4660
- job.providerAddress,
4661
- job.evaluatorAddress,
4662
- job.price,
4663
- job.priceTokenAddress,
4664
- job.memos.map((memo) => {
4665
- return new acpMemo_default(
4666
- this.contractClientByAddress(job.contractAddress),
4667
- memo.id,
4668
- memo.memoType,
4669
- memo.content,
4670
- memo.nextPhase,
4671
- memo.status,
4672
- memo.senderAddress,
4673
- memo.signedReason,
4674
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4675
- memo.payableDetails
4676
- );
4677
- }),
4678
- job.phase,
4679
- job.context,
4680
- job.contractAddress,
4681
- job.netPayableAmount
4682
- );
4683
- });
4684
- } catch (error) {
4685
- throw new acpError_default("Failed to get cancelled jobs", error);
4702
+ });
4703
+ const data = await response.json();
4704
+ if (data.error) {
4705
+ throw new acpError_default(data.error.message);
4686
4706
  }
4687
- });
4707
+ return data.data.map((job) => {
4708
+ return new acpJob_default(
4709
+ this,
4710
+ job.id,
4711
+ job.clientAddress,
4712
+ job.providerAddress,
4713
+ job.evaluatorAddress,
4714
+ job.price,
4715
+ job.priceTokenAddress,
4716
+ job.memos.map((memo) => {
4717
+ return new acpMemo_default(
4718
+ this.contractClientByAddress(job.contractAddress),
4719
+ memo.id,
4720
+ memo.memoType,
4721
+ memo.content,
4722
+ memo.nextPhase,
4723
+ memo.status,
4724
+ memo.senderAddress,
4725
+ memo.signedReason,
4726
+ memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4727
+ memo.payableDetails,
4728
+ memo.txHash,
4729
+ memo.signedTxHash
4730
+ );
4731
+ }),
4732
+ job.phase,
4733
+ job.context,
4734
+ job.contractAddress,
4735
+ job.netPayableAmount
4736
+ );
4737
+ });
4738
+ } catch (error) {
4739
+ throw new acpError_default("Failed to get active jobs", error);
4740
+ }
4741
+ }
4742
+ async getPendingMemoJobs(page = 1, pageSize = 10) {
4743
+ let url = `${this.acpUrl}/api/jobs/pending-memos?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4744
+ try {
4745
+ const response = await fetch(url, {
4746
+ headers: {
4747
+ "wallet-address": this.acpContractClient.walletAddress
4748
+ }
4749
+ });
4750
+ const data = await response.json();
4751
+ if (data.error) {
4752
+ throw new acpError_default(data.error.message);
4753
+ }
4754
+ return data.data.map((job) => {
4755
+ return new acpJob_default(
4756
+ this,
4757
+ job.id,
4758
+ job.clientAddress,
4759
+ job.providerAddress,
4760
+ job.evaluatorAddress,
4761
+ job.price,
4762
+ job.priceTokenAddress,
4763
+ job.memos.map((memo) => {
4764
+ return new acpMemo_default(
4765
+ this.contractClientByAddress(job.contractAddress),
4766
+ memo.id,
4767
+ memo.memoType,
4768
+ memo.content,
4769
+ memo.nextPhase,
4770
+ memo.status,
4771
+ memo.senderAddress,
4772
+ memo.signedReason,
4773
+ memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4774
+ typeof memo.payableDetails === "string" ? tryParseJson(memo.payableDetails) || void 0 : memo.payableDetails,
4775
+ memo.txHash,
4776
+ memo.signedTxHash
4777
+ );
4778
+ }),
4779
+ job.phase,
4780
+ job.context,
4781
+ job.contractAddress,
4782
+ job.netPayableAmount
4783
+ );
4784
+ });
4785
+ } catch (error) {
4786
+ throw new acpError_default("Failed to get pending memo jobs", error);
4787
+ }
4688
4788
  }
4689
- getJobById(jobId) {
4690
- return __async(this, null, function* () {
4691
- let url = `${this.acpUrl}/api/jobs/${jobId}`;
4692
- try {
4693
- const response = yield fetch(url, {
4694
- headers: {
4695
- "wallet-address": this.acpContractClient.walletAddress
4696
- }
4697
- });
4698
- const data = yield response.json();
4699
- if (data.error) {
4700
- throw new acpError_default(data.error.message);
4701
- }
4702
- const job = data.data;
4703
- if (!job) {
4704
- return;
4789
+ async getCompletedJobs(page = 1, pageSize = 10) {
4790
+ let url = `${this.acpUrl}/api/jobs/completed?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4791
+ try {
4792
+ const response = await fetch(url, {
4793
+ headers: {
4794
+ "wallet-address": this.acpContractClient.walletAddress
4705
4795
  }
4796
+ });
4797
+ const data = await response.json();
4798
+ if (data.error) {
4799
+ throw new acpError_default(data.error.message);
4800
+ }
4801
+ return data.data.map((job) => {
4706
4802
  return new acpJob_default(
4707
4803
  this,
4708
4804
  job.id,
@@ -4722,7 +4818,9 @@ var AcpClient = class {
4722
4818
  memo.senderAddress,
4723
4819
  memo.signedReason,
4724
4820
  memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4725
- memo.payableDetails
4821
+ memo.payableDetails,
4822
+ memo.txHash,
4823
+ memo.signedTxHash
4726
4824
  );
4727
4825
  }),
4728
4826
  job.phase,
@@ -4730,98 +4828,188 @@ var AcpClient = class {
4730
4828
  job.contractAddress,
4731
4829
  job.netPayableAmount
4732
4830
  );
4733
- } catch (error) {
4734
- throw new acpError_default("Failed to get job by id", error);
4735
- }
4736
- });
4831
+ });
4832
+ } catch (error) {
4833
+ throw new acpError_default("Failed to get completed jobs", error);
4834
+ }
4737
4835
  }
4738
- getMemoById(jobId, memoId) {
4739
- return __async(this, null, function* () {
4740
- let url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
4741
- try {
4742
- const response = yield fetch(url, {
4743
- headers: {
4744
- "wallet-address": this.walletAddress
4745
- }
4746
- });
4747
- const data = yield response.json();
4748
- if (data.error) {
4749
- throw new acpError_default(data.error.message);
4750
- }
4751
- const memo = data.data;
4752
- if (!memo) {
4753
- return;
4836
+ async getCancelledJobs(page = 1, pageSize = 10) {
4837
+ let url = `${this.acpUrl}/api/jobs/cancelled?pagination[page]=${page}&pagination[pageSize]=${pageSize}`;
4838
+ try {
4839
+ const response = await fetch(url, {
4840
+ headers: {
4841
+ "wallet-address": this.walletAddress
4754
4842
  }
4755
- return new acpMemo_default(
4756
- this.contractClientByAddress(memo.contractAddress),
4757
- memo.id,
4758
- memo.memoType,
4759
- memo.content,
4760
- memo.nextPhase,
4761
- memo.status,
4762
- memo.senderAddress,
4763
- memo.signedReason,
4764
- memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4765
- memo.payableDetails
4766
- );
4767
- } catch (error) {
4768
- throw new acpError_default("Failed to get memo by id", error);
4843
+ });
4844
+ const data = await response.json();
4845
+ if (data.error) {
4846
+ throw new acpError_default(data.error.message);
4769
4847
  }
4770
- });
4848
+ return data.data.map((job) => {
4849
+ return new acpJob_default(
4850
+ this,
4851
+ job.id,
4852
+ job.clientAddress,
4853
+ job.providerAddress,
4854
+ job.evaluatorAddress,
4855
+ job.price,
4856
+ job.priceTokenAddress,
4857
+ job.memos.map((memo) => {
4858
+ return new acpMemo_default(
4859
+ this.contractClientByAddress(job.contractAddress),
4860
+ memo.id,
4861
+ memo.memoType,
4862
+ memo.content,
4863
+ memo.nextPhase,
4864
+ memo.status,
4865
+ memo.senderAddress,
4866
+ memo.signedReason,
4867
+ memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4868
+ memo.payableDetails,
4869
+ memo.txHash,
4870
+ memo.signedTxHash
4871
+ );
4872
+ }),
4873
+ job.phase,
4874
+ job.context,
4875
+ job.contractAddress,
4876
+ job.netPayableAmount
4877
+ );
4878
+ });
4879
+ } catch (error) {
4880
+ throw new acpError_default("Failed to get cancelled jobs", error);
4881
+ }
4771
4882
  }
4772
- getAgent(walletAddress) {
4773
- return __async(this, null, function* () {
4774
- const url = `${this.acpUrl}/api/agents?filters[walletAddress]=${walletAddress}`;
4775
- const response = yield fetch(url);
4776
- const data = yield response.json();
4777
- const agents = data.data || [];
4778
- if (agents.length === 0) {
4883
+ async getJobById(jobId) {
4884
+ let url = `${this.acpUrl}/api/jobs/${jobId}`;
4885
+ try {
4886
+ const response = await fetch(url, {
4887
+ headers: {
4888
+ "wallet-address": this.acpContractClient.walletAddress
4889
+ }
4890
+ });
4891
+ const data = await response.json();
4892
+ if (data.error) {
4893
+ throw new acpError_default(data.error.message);
4894
+ }
4895
+ const job = data.data;
4896
+ if (!job) {
4779
4897
  return;
4780
4898
  }
4781
- return agents[0];
4782
- });
4899
+ return new acpJob_default(
4900
+ this,
4901
+ job.id,
4902
+ job.clientAddress,
4903
+ job.providerAddress,
4904
+ job.evaluatorAddress,
4905
+ job.price,
4906
+ job.priceTokenAddress,
4907
+ job.memos.map((memo) => {
4908
+ return new acpMemo_default(
4909
+ this.contractClientByAddress(job.contractAddress),
4910
+ memo.id,
4911
+ memo.memoType,
4912
+ memo.content,
4913
+ memo.nextPhase,
4914
+ memo.status,
4915
+ memo.senderAddress,
4916
+ memo.signedReason,
4917
+ memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4918
+ memo.payableDetails,
4919
+ memo.txHash,
4920
+ memo.signedTxHash
4921
+ );
4922
+ }),
4923
+ job.phase,
4924
+ job.context,
4925
+ job.contractAddress,
4926
+ job.netPayableAmount
4927
+ );
4928
+ } catch (error) {
4929
+ throw new acpError_default("Failed to get job by id", error);
4930
+ }
4783
4931
  }
4784
- getAccountByJobId(jobId, acpContractClient) {
4785
- return __async(this, null, function* () {
4786
- try {
4787
- const url = `${this.acpUrl}/api/accounts/job/${jobId}`;
4788
- const response = yield fetch(url);
4789
- const data = yield response.json();
4790
- if (!data.data) {
4791
- return null;
4932
+ async getMemoById(jobId, memoId) {
4933
+ let url = `${this.acpUrl}/api/jobs/${jobId}/memos/${memoId}`;
4934
+ try {
4935
+ const response = await fetch(url, {
4936
+ headers: {
4937
+ "wallet-address": this.walletAddress
4792
4938
  }
4793
- return new AcpAccount(
4794
- acpContractClient || this.contractClients[0],
4795
- data.data.id,
4796
- data.data.clientAddress,
4797
- data.data.providerAddress,
4798
- data.data.metadata
4799
- );
4800
- } catch (error) {
4801
- throw new acpError_default("Failed to get account by job id", error);
4939
+ });
4940
+ const data = await response.json();
4941
+ if (data.error) {
4942
+ throw new acpError_default(data.error.message);
4802
4943
  }
4803
- });
4944
+ const memo = data.data;
4945
+ if (!memo) {
4946
+ return;
4947
+ }
4948
+ return new acpMemo_default(
4949
+ this.contractClientByAddress(memo.contractAddress),
4950
+ memo.id,
4951
+ memo.memoType,
4952
+ memo.content,
4953
+ memo.nextPhase,
4954
+ memo.status,
4955
+ memo.senderAddress,
4956
+ memo.signedReason,
4957
+ memo.expiry ? new Date(parseInt(memo.expiry) * 1e3) : void 0,
4958
+ memo.payableDetails,
4959
+ memo.txHash,
4960
+ memo.signedTxHash
4961
+ );
4962
+ } catch (error) {
4963
+ throw new acpError_default("Failed to get memo by id", error);
4964
+ }
4804
4965
  }
4805
- getByClientAndProvider(clientAddress, providerAddress, acpContractClient) {
4806
- return __async(this, null, function* () {
4807
- try {
4808
- const url = `${this.acpUrl}/api/accounts/client/${clientAddress}/provider/${providerAddress}`;
4809
- const response = yield fetch(url);
4810
- const data = yield response.json();
4811
- if (!data.data) {
4812
- return null;
4813
- }
4814
- return new AcpAccount(
4815
- acpContractClient || this.contractClients[0],
4816
- data.data.id,
4817
- data.data.clientAddress,
4818
- data.data.providerAddress,
4819
- data.data.metadata
4820
- );
4821
- } catch (error) {
4822
- throw new acpError_default("Failed to get account by client and provider", error);
4966
+ async getAgent(walletAddress) {
4967
+ const url = `${this.acpUrl}/api/agents?filters[walletAddress]=${walletAddress}`;
4968
+ const response = await fetch(url);
4969
+ const data = await response.json();
4970
+ const agents = data.data || [];
4971
+ if (agents.length === 0) {
4972
+ return;
4973
+ }
4974
+ return agents[0];
4975
+ }
4976
+ async getAccountByJobId(jobId, acpContractClient) {
4977
+ try {
4978
+ const url = `${this.acpUrl}/api/accounts/job/${jobId}`;
4979
+ const response = await fetch(url);
4980
+ const data = await response.json();
4981
+ if (!data.data) {
4982
+ return null;
4823
4983
  }
4824
- });
4984
+ return new AcpAccount(
4985
+ acpContractClient || this.contractClients[0],
4986
+ data.data.id,
4987
+ data.data.clientAddress,
4988
+ data.data.providerAddress,
4989
+ data.data.metadata
4990
+ );
4991
+ } catch (error) {
4992
+ throw new acpError_default("Failed to get account by job id", error);
4993
+ }
4994
+ }
4995
+ async getByClientAndProvider(clientAddress, providerAddress, acpContractClient) {
4996
+ try {
4997
+ const url = `${this.acpUrl}/api/accounts/client/${clientAddress}/provider/${providerAddress}`;
4998
+ const response = await fetch(url);
4999
+ const data = await response.json();
5000
+ if (!data.data) {
5001
+ return null;
5002
+ }
5003
+ return new AcpAccount(
5004
+ acpContractClient || this.contractClients[0],
5005
+ data.data.id,
5006
+ data.data.clientAddress,
5007
+ data.data.providerAddress,
5008
+ data.data.metadata
5009
+ );
5010
+ } catch (error) {
5011
+ throw new acpError_default("Failed to get account by client and provider", error);
5012
+ }
4825
5013
  }
4826
5014
  };
4827
5015
  var acpClient_default = AcpClient;
@@ -4844,136 +5032,127 @@ var AcpX402 = class {
4844
5032
  this.sessionKeyClient = sessionKeyClient;
4845
5033
  this.publicClient = publicClient;
4846
5034
  }
4847
- signUpdateJobNonceMessage(jobId, nonce) {
4848
- return __async(this, null, function* () {
4849
- const message = `${jobId}-${nonce}`;
4850
- const signature = yield this.sessionKeyClient.account.getSigner().signMessage(message);
4851
- return signature;
4852
- });
5035
+ async signUpdateJobNonceMessage(jobId, nonce) {
5036
+ const message = `${jobId}-${nonce}`;
5037
+ const signature = await this.sessionKeyClient.account.getSigner().signMessage(message);
5038
+ return signature;
4853
5039
  }
4854
- updateJobNonce(jobId, nonce) {
4855
- return __async(this, null, function* () {
4856
- try {
4857
- const apiUrl = `${this.config.acpUrl}/api/jobs/${jobId}/x402-nonce`;
4858
- const signature = yield this.signUpdateJobNonceMessage(jobId, nonce);
4859
- const response = yield fetch(apiUrl, {
4860
- method: "POST",
4861
- headers: {
4862
- "x-signature": signature,
4863
- "x-nonce": nonce,
4864
- "Content-Type": "application/json"
4865
- },
4866
- body: JSON.stringify({
4867
- data: {
4868
- nonce
4869
- }
4870
- })
4871
- });
4872
- if (!response.ok) {
4873
- throw new acpError_default(
4874
- "Failed to update job X402 nonce",
4875
- response.statusText
4876
- );
4877
- }
4878
- const acpJob = yield response.json();
4879
- return acpJob;
4880
- } catch (error) {
4881
- throw new acpError_default("Failed to update job X402 nonce", error);
5040
+ async updateJobNonce(jobId, nonce) {
5041
+ try {
5042
+ const apiUrl = `${this.config.acpUrl}/api/jobs/${jobId}/x402-nonce`;
5043
+ const signature = await this.signUpdateJobNonceMessage(jobId, nonce);
5044
+ const response = await fetch(apiUrl, {
5045
+ method: "POST",
5046
+ headers: {
5047
+ "x-signature": signature,
5048
+ "x-nonce": nonce,
5049
+ "Content-Type": "application/json"
5050
+ },
5051
+ body: JSON.stringify({
5052
+ data: {
5053
+ nonce
5054
+ }
5055
+ })
5056
+ });
5057
+ if (!response.ok) {
5058
+ throw new acpError_default(
5059
+ "Failed to update job X402 nonce",
5060
+ response.statusText
5061
+ );
4882
5062
  }
4883
- });
5063
+ const acpJob = await response.json();
5064
+ return acpJob;
5065
+ } catch (error) {
5066
+ throw new acpError_default("Failed to update job X402 nonce", error);
5067
+ }
4884
5068
  }
4885
- generatePayment(payableRequest, requirements) {
4886
- return __async(this, null, function* () {
4887
- try {
4888
- const USDC_CONTRACT = this.config.baseFare.contractAddress;
4889
- const timeNow = Math.floor(Date.now() / 1e3);
4890
- const validAfter = timeNow.toString();
4891
- const validBefore = (timeNow + requirements.accepts[0].maxTimeoutSeconds).toString();
4892
- const [tokenName, tokenVersion] = yield this.publicClient.multicall({
4893
- contracts: [
4894
- {
4895
- address: USDC_CONTRACT,
4896
- abi: import_viem5.erc20Abi,
4897
- functionName: "name"
4898
- },
4899
- {
4900
- address: USDC_CONTRACT,
4901
- abi: fiatTokenV2Abi_default,
4902
- functionName: "version"
4903
- }
4904
- ]
4905
- });
4906
- const nonce = `0x${(0, import_crypto.randomBytes)(32).toString("hex")}`;
4907
- const message = {
4908
- from: this.sessionKeyClient.account.address,
4909
- to: payableRequest.to,
4910
- value: payableRequest.value.toString(),
4911
- validAfter: validAfter.toString(),
4912
- validBefore: validBefore.toString(),
4913
- nonce
4914
- };
4915
- const typedData = {
4916
- types: {
4917
- TransferWithAuthorization: X402AuthorizationTypes
4918
- },
4919
- domain: {
4920
- name: tokenName.result,
4921
- version: tokenVersion.result,
4922
- chainId: this.config.chain.id,
4923
- verifyingContract: USDC_CONTRACT
5069
+ async generatePayment(payableRequest, requirements) {
5070
+ try {
5071
+ const USDC_CONTRACT = this.config.baseFare.contractAddress;
5072
+ const timeNow = Math.floor(Date.now() / 1e3);
5073
+ const validAfter = timeNow.toString();
5074
+ const validBefore = (timeNow + requirements.accepts[0].maxTimeoutSeconds).toString();
5075
+ const [tokenName, tokenVersion] = await this.publicClient.multicall({
5076
+ contracts: [
5077
+ {
5078
+ address: USDC_CONTRACT,
5079
+ abi: import_viem5.erc20Abi,
5080
+ functionName: "name"
4924
5081
  },
4925
- primaryType: "TransferWithAuthorization",
4926
- message
4927
- };
4928
- const signature = yield this.sessionKeyClient.signTypedData({
4929
- typedData
4930
- });
4931
- const payload = {
4932
- x402Version: requirements.x402Version,
4933
- scheme: requirements.accepts[0].scheme,
4934
- network: requirements.accepts[0].network,
4935
- payload: {
4936
- signature,
4937
- authorization: message
5082
+ {
5083
+ address: USDC_CONTRACT,
5084
+ abi: fiatTokenV2Abi_default,
5085
+ functionName: "version"
4938
5086
  }
4939
- };
4940
- const encodedPayment = safeBase64Encode(JSON.stringify(payload));
4941
- return {
4942
- encodedPayment,
5087
+ ]
5088
+ });
5089
+ const nonce = `0x${(0, import_crypto.randomBytes)(32).toString("hex")}`;
5090
+ const message = {
5091
+ from: this.sessionKeyClient.account.address,
5092
+ to: payableRequest.to,
5093
+ value: payableRequest.value.toString(),
5094
+ validAfter: validAfter.toString(),
5095
+ validBefore: validBefore.toString(),
5096
+ nonce
5097
+ };
5098
+ const typedData = {
5099
+ types: {
5100
+ TransferWithAuthorization: X402AuthorizationTypes
5101
+ },
5102
+ domain: {
5103
+ name: tokenName.result,
5104
+ version: tokenVersion.result,
5105
+ chainId: this.config.chain.id,
5106
+ verifyingContract: USDC_CONTRACT
5107
+ },
5108
+ primaryType: "TransferWithAuthorization",
5109
+ message
5110
+ };
5111
+ const signature = await this.sessionKeyClient.signTypedData({
5112
+ typedData
5113
+ });
5114
+ const payload = {
5115
+ x402Version: requirements.x402Version,
5116
+ scheme: requirements.accepts[0].scheme,
5117
+ network: requirements.accepts[0].network,
5118
+ payload: {
4943
5119
  signature,
4944
- message
4945
- };
4946
- } catch (error) {
4947
- throw new acpError_default("Failed to generate X402 payment", error);
4948
- }
4949
- });
4950
- }
4951
- performRequest(url, version2, budget, signature) {
4952
- return __async(this, null, function* () {
4953
- var _a;
4954
- const baseUrl = (_a = this.config.x402Config) == null ? void 0 : _a.url;
4955
- if (!baseUrl) throw new acpError_default("X402 URL not configured");
4956
- try {
4957
- const headers = {};
4958
- if (signature) headers["x-payment"] = signature;
4959
- if (budget) headers["x-budget"] = budget.toString();
4960
- headers["x-acp-version"] = version2;
4961
- const res = yield fetch(`${baseUrl}${url}`, { method: "GET", headers });
4962
- const data = yield res.json();
4963
- if (!res.ok && res.status !== HTTP_STATUS_CODES.PAYMENT_REQUIRED) {
4964
- throw new acpError_default(
4965
- "Invalid response status code for X402 request",
4966
- data
4967
- );
5120
+ authorization: message
4968
5121
  }
4969
- return {
4970
- isPaymentRequired: res.status === HTTP_STATUS_CODES.PAYMENT_REQUIRED,
5122
+ };
5123
+ const encodedPayment = safeBase64Encode(JSON.stringify(payload));
5124
+ return {
5125
+ encodedPayment,
5126
+ signature,
5127
+ message
5128
+ };
5129
+ } catch (error) {
5130
+ throw new acpError_default("Failed to generate X402 payment", error);
5131
+ }
5132
+ }
5133
+ async performRequest(url, version2, budget, signature) {
5134
+ const baseUrl = this.config.x402Config?.url;
5135
+ if (!baseUrl) throw new acpError_default("X402 URL not configured");
5136
+ try {
5137
+ const headers = {};
5138
+ if (signature) headers["x-payment"] = signature;
5139
+ if (budget) headers["x-budget"] = budget.toString();
5140
+ headers["x-acp-version"] = version2;
5141
+ const res = await fetch(`${baseUrl}${url}`, { method: "GET", headers });
5142
+ const data = await res.json();
5143
+ if (!res.ok && res.status !== HTTP_STATUS_CODES.PAYMENT_REQUIRED) {
5144
+ throw new acpError_default(
5145
+ "Invalid response status code for X402 request",
4971
5146
  data
4972
- };
4973
- } catch (error) {
4974
- throw new acpError_default("Failed to perform X402 request", error);
5147
+ );
4975
5148
  }
4976
- });
5149
+ return {
5150
+ isPaymentRequired: res.status === HTTP_STATUS_CODES.PAYMENT_REQUIRED,
5151
+ data
5152
+ };
5153
+ } catch (error) {
5154
+ throw new acpError_default("Failed to perform X402 request", error);
5155
+ }
4977
5156
  }
4978
5157
  };
4979
5158
 
@@ -4985,37 +5164,46 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4985
5164
  this.MAX_FEE_PER_GAS = 2e7;
4986
5165
  this.MAX_PRIORITY_FEE_PER_GAS = 21e6;
4987
5166
  }
4988
- static build(_0, _1, _2) {
4989
- return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig) {
4990
- const acpContractClient = new _AcpContractClient(
4991
- agentWalletAddress,
4992
- config
4993
- );
4994
- yield acpContractClient.init(walletPrivateKey, sessionEntityKeyId);
4995
- return acpContractClient;
4996
- });
5167
+ static async build(walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig) {
5168
+ const acpContractClient = new _AcpContractClient(
5169
+ agentWalletAddress,
5170
+ config
5171
+ );
5172
+ await acpContractClient.init(walletPrivateKey, sessionEntityKeyId);
5173
+ return acpContractClient;
4997
5174
  }
4998
- init(privateKey, sessionEntityKeyId) {
4999
- return __async(this, null, function* () {
5000
- const sessionKeySigner = import_core.LocalAccountSigner.privateKeyToAccountSigner(privateKey);
5001
- this._sessionKeyClient = yield (0, import_smart_contracts.createModularAccountV2Client)({
5002
- chain: this.chain,
5003
- transport: (0, import_infra2.alchemy)({
5004
- rpcUrl: this.config.alchemyRpcUrl
5005
- }),
5006
- signer: sessionKeySigner,
5007
- policyId: "186aaa4a-5f57-4156-83fb-e456365a8820",
5008
- accountAddress: this.agentWalletAddress,
5009
- signerEntity: {
5010
- entityId: sessionEntityKeyId,
5011
- isGlobalValidation: true
5012
- }
5013
- });
5014
- this._acpX402 = new AcpX402(
5015
- this.config,
5016
- this.sessionKeyClient,
5017
- this.publicClient
5175
+ async init(privateKey, sessionEntityKeyId) {
5176
+ const sessionKeySigner = import_core.LocalAccountSigner.privateKeyToAccountSigner(privateKey);
5177
+ this._sessionKeyClient = await (0, import_smart_contracts.createModularAccountV2Client)({
5178
+ chain: this.chain,
5179
+ transport: (0, import_infra2.alchemy)({
5180
+ rpcUrl: this.config.alchemyRpcUrl
5181
+ }),
5182
+ signer: sessionKeySigner,
5183
+ policyId: "186aaa4a-5f57-4156-83fb-e456365a8820",
5184
+ accountAddress: this.agentWalletAddress,
5185
+ signerEntity: {
5186
+ entityId: sessionEntityKeyId,
5187
+ isGlobalValidation: true
5188
+ }
5189
+ });
5190
+ this._acpX402 = new AcpX402(
5191
+ this.config,
5192
+ this.sessionKeyClient,
5193
+ this.publicClient
5194
+ );
5195
+ const account = this.sessionKeyClient.account;
5196
+ const sessionSignerAddress = await account.getSigner().getAddress();
5197
+ if (!await account.isAccountDeployed()) {
5198
+ throw new acpError_default(
5199
+ `ACP Contract Client validation failed: agent account ${this.agentWalletAddress} is not deployed on-chain`
5018
5200
  );
5201
+ }
5202
+ await this.validateSessionKeyOnChain(sessionSignerAddress, sessionEntityKeyId);
5203
+ console.log("Connected to ACP:", {
5204
+ agentWalletAddress: this.agentWalletAddress,
5205
+ whitelistedWalletAddress: sessionSignerAddress,
5206
+ entityId: sessionEntityKeyId
5019
5207
  });
5020
5208
  }
5021
5209
  getRandomNonce(bits = 152) {
@@ -5039,74 +5227,68 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
5039
5227
  }
5040
5228
  return this._acpX402;
5041
5229
  }
5042
- calculateGasFees() {
5043
- return __async(this, null, function* () {
5044
- const finalMaxFeePerGas = BigInt(this.MAX_FEE_PER_GAS) + BigInt(this.MAX_PRIORITY_FEE_PER_GAS) * BigInt(Math.max(0, this.PRIORITY_FEE_MULTIPLIER - 1));
5045
- return finalMaxFeePerGas;
5046
- });
5230
+ async calculateGasFees() {
5231
+ const finalMaxFeePerGas = BigInt(this.MAX_FEE_PER_GAS) + BigInt(this.MAX_PRIORITY_FEE_PER_GAS) * BigInt(Math.max(0, this.PRIORITY_FEE_MULTIPLIER - 1));
5232
+ return finalMaxFeePerGas;
5047
5233
  }
5048
- handleOperation(operations) {
5049
- return __async(this, null, function* () {
5050
- const payload = {
5051
- uo: operations.map((op) => ({
5052
- target: op.contractAddress,
5053
- data: op.data,
5054
- value: op.value
5055
- })),
5056
- overrides: {
5057
- nonceKey: this.getRandomNonce()
5234
+ async handleOperation(operations) {
5235
+ const payload = {
5236
+ uo: operations.map((op) => ({
5237
+ target: op.contractAddress,
5238
+ data: op.data,
5239
+ value: op.value
5240
+ })),
5241
+ overrides: {
5242
+ nonceKey: this.getRandomNonce()
5243
+ }
5244
+ };
5245
+ let retries = this.config.maxRetries;
5246
+ let finalError;
5247
+ while (retries > 0) {
5248
+ try {
5249
+ if (this.config.maxRetries > retries) {
5250
+ const gasFees = await this.calculateGasFees();
5251
+ payload["overrides"] = {
5252
+ maxFeePerGas: `0x${gasFees.toString(16)}`
5253
+ };
5058
5254
  }
5059
- };
5060
- let retries = this.config.maxRetries;
5061
- let finalError;
5062
- while (retries > 0) {
5063
- try {
5064
- if (this.config.maxRetries > retries) {
5065
- const gasFees = yield this.calculateGasFees();
5066
- payload["overrides"] = {
5067
- maxFeePerGas: `0x${gasFees.toString(16)}`
5068
- };
5069
- }
5070
- const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
5071
- const txnHash = yield this.sessionKeyClient.waitForUserOperationTransaction({
5072
- hash
5073
- });
5074
- return { userOpHash: hash, txnHash };
5075
- } catch (error) {
5076
- retries -= 1;
5077
- if (retries === 0) {
5078
- finalError = error;
5079
- break;
5080
- }
5081
- yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
5255
+ const { hash } = await this.sessionKeyClient.sendUserOperation(payload);
5256
+ const txnHash = await this.sessionKeyClient.waitForUserOperationTransaction({
5257
+ hash
5258
+ });
5259
+ return { userOpHash: hash, txnHash };
5260
+ } catch (error) {
5261
+ retries -= 1;
5262
+ if (retries === 0) {
5263
+ finalError = error;
5264
+ break;
5082
5265
  }
5266
+ await new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
5083
5267
  }
5084
- throw new acpError_default(`Failed to send user operation`, finalError);
5085
- });
5268
+ }
5269
+ throw new acpError_default(`Failed to send user operation`, finalError);
5086
5270
  }
5087
- getJobId(createJobUserOpHash, clientAddress, providerAddress) {
5088
- return __async(this, null, function* () {
5089
- const result = yield this.sessionKeyClient.getUserOperationReceipt(createJobUserOpHash);
5090
- if (!result) {
5091
- throw new acpError_default("Failed to get user operation receipt");
5092
- }
5093
- const contractLogs = result.logs.filter((log) => {
5094
- return log.address.toLowerCase() === this.contractAddress.toLowerCase();
5095
- }).map(
5096
- (log) => (0, import_viem6.decodeEventLog)({
5097
- abi: this.abi,
5098
- data: log.data,
5099
- topics: log.topics
5100
- })
5101
- );
5102
- const createdJobEvent = contractLogs.find(
5103
- (log) => log.eventName === "JobCreated" && log.args.client.toLowerCase() === clientAddress.toLowerCase() && log.args.provider.toLowerCase() === providerAddress.toLowerCase()
5104
- );
5105
- if (!createdJobEvent) {
5106
- throw new acpError_default("Failed to find created job event");
5107
- }
5108
- return Number(createdJobEvent.args.jobId);
5109
- });
5271
+ async getJobId(createJobUserOpHash, clientAddress, providerAddress) {
5272
+ const result = await this.sessionKeyClient.getUserOperationReceipt(createJobUserOpHash);
5273
+ if (!result) {
5274
+ throw new acpError_default("Failed to get user operation receipt");
5275
+ }
5276
+ const contractLogs = result.logs.filter((log) => {
5277
+ return log.address.toLowerCase() === this.contractAddress.toLowerCase();
5278
+ }).map(
5279
+ (log) => (0, import_viem6.decodeEventLog)({
5280
+ abi: this.abi,
5281
+ data: log.data,
5282
+ topics: log.topics
5283
+ })
5284
+ );
5285
+ const createdJobEvent = contractLogs.find(
5286
+ (log) => log.eventName === "JobCreated" && log.args.client.toLowerCase() === clientAddress.toLowerCase() && log.args.provider.toLowerCase() === providerAddress.toLowerCase()
5287
+ );
5288
+ if (!createdJobEvent) {
5289
+ throw new acpError_default("Failed to find created job event");
5290
+ }
5291
+ return Number(createdJobEvent.args.jobId);
5110
5292
  }
5111
5293
  createJob(providerAddress, evaluatorAddress, expireAt, paymentTokenAddress, budgetBaseUnit, metadata, isX402Job) {
5112
5294
  try {
@@ -5177,20 +5359,14 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
5177
5359
  updateAccountMetadata(accountId, metadata) {
5178
5360
  throw new acpError_default("Not Supported");
5179
5361
  }
5180
- updateJobX402Nonce(jobId, nonce) {
5181
- return __async(this, null, function* () {
5182
- return yield this.acpX402.updateJobNonce(jobId, nonce);
5183
- });
5362
+ async updateJobX402Nonce(jobId, nonce) {
5363
+ return await this.acpX402.updateJobNonce(jobId, nonce);
5184
5364
  }
5185
- generateX402Payment(payableRequest, requirements) {
5186
- return __async(this, null, function* () {
5187
- return yield this.acpX402.generatePayment(payableRequest, requirements);
5188
- });
5365
+ async generateX402Payment(payableRequest, requirements) {
5366
+ return await this.acpX402.generatePayment(payableRequest, requirements);
5189
5367
  }
5190
- performX402Request(url, version2, budget, signature) {
5191
- return __async(this, null, function* () {
5192
- return yield this.acpX402.performRequest(url, version2, budget, signature);
5193
- });
5368
+ async performX402Request(url, version2, budget, signature) {
5369
+ return await this.acpX402.performRequest(url, version2, budget, signature);
5194
5370
  }
5195
5371
  getAcpVersion() {
5196
5372
  return "1";
@@ -5916,68 +6092,77 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
5916
6092
  this.MAX_FEE_PER_GAS = 2e7;
5917
6093
  this.MAX_PRIORITY_FEE_PER_GAS = 21e6;
5918
6094
  }
5919
- static build(_0, _1, _2) {
5920
- return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfigV2) {
5921
- const publicClient = (0, import_viem7.createPublicClient)({
5922
- chain: config.chain,
5923
- transport: (0, import_viem7.http)(config.rpcEndpoint)
5924
- });
5925
- const [jobManagerAddress, memoManagerAddress, accountManagerAddress] = yield publicClient.multicall({
5926
- contracts: [
5927
- {
5928
- address: config.contractAddress,
5929
- abi: config.abi,
5930
- functionName: "jobManager"
5931
- },
5932
- {
5933
- address: config.contractAddress,
5934
- abi: config.abi,
5935
- functionName: "memoManager"
5936
- },
5937
- {
5938
- address: config.contractAddress,
5939
- abi: config.abi,
5940
- functionName: "accountManager"
5941
- }
5942
- ]
5943
- });
5944
- if (!jobManagerAddress || !memoManagerAddress || !accountManagerAddress) {
5945
- throw new acpError_default(
5946
- "Failed to get job manager, memo manager, or account manager address"
5947
- );
5948
- }
5949
- const acpContractClient = new _AcpContractClientV2(
5950
- jobManagerAddress.result,
5951
- memoManagerAddress.result,
5952
- accountManagerAddress.result,
5953
- agentWalletAddress,
5954
- config
5955
- );
5956
- yield acpContractClient.init(walletPrivateKey, sessionEntityKeyId);
5957
- return acpContractClient;
6095
+ static async build(walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfigV2) {
6096
+ const publicClient = (0, import_viem7.createPublicClient)({
6097
+ chain: config.chain,
6098
+ transport: (0, import_viem7.http)(config.rpcEndpoint)
5958
6099
  });
5959
- }
5960
- init(privateKey, sessionEntityKeyId) {
5961
- return __async(this, null, function* () {
5962
- const sessionKeySigner = import_core2.LocalAccountSigner.privateKeyToAccountSigner(privateKey);
5963
- this._sessionKeyClient = yield (0, import_smart_contracts2.createModularAccountV2Client)({
5964
- chain: this.chain,
5965
- transport: (0, import_infra3.alchemy)({
5966
- rpcUrl: this.config.alchemyRpcUrl
5967
- }),
5968
- signer: sessionKeySigner,
5969
- policyId: "186aaa4a-5f57-4156-83fb-e456365a8820",
5970
- accountAddress: this.agentWalletAddress,
5971
- signerEntity: {
5972
- entityId: sessionEntityKeyId,
5973
- isGlobalValidation: true
6100
+ const [jobManagerAddress, memoManagerAddress, accountManagerAddress] = await publicClient.multicall({
6101
+ contracts: [
6102
+ {
6103
+ address: config.contractAddress,
6104
+ abi: config.abi,
6105
+ functionName: "jobManager"
6106
+ },
6107
+ {
6108
+ address: config.contractAddress,
6109
+ abi: config.abi,
6110
+ functionName: "memoManager"
6111
+ },
6112
+ {
6113
+ address: config.contractAddress,
6114
+ abi: config.abi,
6115
+ functionName: "accountManager"
5974
6116
  }
5975
- });
5976
- this._acpX402 = new AcpX402(
5977
- this.config,
5978
- this.sessionKeyClient,
5979
- this.publicClient
6117
+ ]
6118
+ });
6119
+ if (!jobManagerAddress || !memoManagerAddress || !accountManagerAddress) {
6120
+ throw new acpError_default(
6121
+ "Failed to get job manager, memo manager, or account manager address"
6122
+ );
6123
+ }
6124
+ const acpContractClient = new _AcpContractClientV2(
6125
+ jobManagerAddress.result,
6126
+ memoManagerAddress.result,
6127
+ accountManagerAddress.result,
6128
+ agentWalletAddress,
6129
+ config
6130
+ );
6131
+ await acpContractClient.init(walletPrivateKey, sessionEntityKeyId);
6132
+ return acpContractClient;
6133
+ }
6134
+ async init(privateKey, sessionEntityKeyId) {
6135
+ const sessionKeySigner = import_core2.LocalAccountSigner.privateKeyToAccountSigner(privateKey);
6136
+ this._sessionKeyClient = await (0, import_smart_contracts2.createModularAccountV2Client)({
6137
+ chain: this.chain,
6138
+ transport: (0, import_infra3.alchemy)({
6139
+ rpcUrl: this.config.alchemyRpcUrl
6140
+ }),
6141
+ signer: sessionKeySigner,
6142
+ policyId: "186aaa4a-5f57-4156-83fb-e456365a8820",
6143
+ accountAddress: this.agentWalletAddress,
6144
+ signerEntity: {
6145
+ entityId: sessionEntityKeyId,
6146
+ isGlobalValidation: true
6147
+ }
6148
+ });
6149
+ this._acpX402 = new AcpX402(
6150
+ this.config,
6151
+ this.sessionKeyClient,
6152
+ this.publicClient
6153
+ );
6154
+ const account = this.sessionKeyClient.account;
6155
+ const sessionSignerAddress = await account.getSigner().getAddress();
6156
+ if (!await account.isAccountDeployed()) {
6157
+ throw new acpError_default(
6158
+ `ACP Contract Client validation failed: agent account ${this.agentWalletAddress} is not deployed on-chain`
5980
6159
  );
6160
+ }
6161
+ await this.validateSessionKeyOnChain(sessionSignerAddress, sessionEntityKeyId);
6162
+ console.log("Connected to ACP:", {
6163
+ agentWalletAddress: this.agentWalletAddress,
6164
+ whitelistedWalletAddress: sessionSignerAddress,
6165
+ entityId: sessionEntityKeyId
5981
6166
  });
5982
6167
  }
5983
6168
  getRandomNonce(bits = 152) {
@@ -6001,116 +6186,102 @@ var AcpContractClientV2 = class _AcpContractClientV2 extends baseAcpContractClie
6001
6186
  }
6002
6187
  return this._acpX402;
6003
6188
  }
6004
- calculateGasFees() {
6005
- return __async(this, null, function* () {
6006
- const finalMaxFeePerGas = BigInt(this.MAX_FEE_PER_GAS) + BigInt(this.MAX_PRIORITY_FEE_PER_GAS) * BigInt(Math.max(0, this.PRIORITY_FEE_MULTIPLIER - 1));
6007
- return finalMaxFeePerGas;
6008
- });
6189
+ async calculateGasFees() {
6190
+ const finalMaxFeePerGas = BigInt(this.MAX_FEE_PER_GAS) + BigInt(this.MAX_PRIORITY_FEE_PER_GAS) * BigInt(Math.max(0, this.PRIORITY_FEE_MULTIPLIER - 1));
6191
+ return finalMaxFeePerGas;
6009
6192
  }
6010
- handleOperation(operations) {
6011
- return __async(this, null, function* () {
6012
- const payload = {
6013
- uo: operations.map((operation) => ({
6014
- target: operation.contractAddress,
6015
- data: operation.data,
6016
- value: operation.value
6017
- })),
6018
- overrides: {
6019
- nonceKey: this.getRandomNonce()
6193
+ async handleOperation(operations) {
6194
+ const payload = {
6195
+ uo: operations.map((operation) => ({
6196
+ target: operation.contractAddress,
6197
+ data: operation.data,
6198
+ value: operation.value
6199
+ })),
6200
+ overrides: {
6201
+ nonceKey: this.getRandomNonce()
6202
+ }
6203
+ };
6204
+ let retries = this.config.maxRetries;
6205
+ let finalError;
6206
+ while (retries > 0) {
6207
+ try {
6208
+ if (this.config.maxRetries > retries) {
6209
+ const gasFees = await this.calculateGasFees();
6210
+ payload["overrides"] = {
6211
+ maxFeePerGas: `0x${gasFees.toString(16)}`
6212
+ };
6020
6213
  }
6021
- };
6022
- let retries = this.config.maxRetries;
6023
- let finalError;
6024
- while (retries > 0) {
6025
- try {
6026
- if (this.config.maxRetries > retries) {
6027
- const gasFees = yield this.calculateGasFees();
6028
- payload["overrides"] = {
6029
- maxFeePerGas: `0x${gasFees.toString(16)}`
6030
- };
6214
+ const { hash } = await this.sessionKeyClient.sendUserOperation(payload);
6215
+ const txnHash = await this.sessionKeyClient.waitForUserOperationTransaction({
6216
+ hash,
6217
+ tag: "pending",
6218
+ retries: {
6219
+ intervalMs: 200,
6220
+ multiplier: 1.1,
6221
+ maxRetries: 10
6031
6222
  }
6032
- const { hash } = yield this.sessionKeyClient.sendUserOperation(payload);
6033
- const txnHash = yield this.sessionKeyClient.waitForUserOperationTransaction({
6034
- hash,
6035
- tag: "pending",
6036
- retries: {
6037
- intervalMs: 200,
6038
- multiplier: 1.1,
6039
- maxRetries: 10
6040
- }
6041
- });
6042
- return { userOpHash: hash, txnHash };
6043
- } catch (error) {
6044
- retries -= 1;
6045
- if (retries === 0) {
6046
- finalError = error;
6047
- break;
6048
- }
6049
- yield new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
6223
+ });
6224
+ return { userOpHash: hash, txnHash };
6225
+ } catch (error) {
6226
+ retries -= 1;
6227
+ if (retries === 0) {
6228
+ finalError = error;
6229
+ break;
6050
6230
  }
6231
+ await new Promise((resolve) => setTimeout(resolve, 2e3 * retries));
6051
6232
  }
6052
- throw new acpError_default(`Failed to send user operation`, finalError);
6053
- });
6233
+ }
6234
+ throw new acpError_default(`Failed to send user operation`, finalError);
6054
6235
  }
6055
- getJobId(createJobUserOpHash, clientAddress, providerAddress) {
6056
- return __async(this, null, function* () {
6057
- const result = yield this.sessionKeyClient.getUserOperationReceipt(
6058
- createJobUserOpHash,
6059
- "pending"
6060
- );
6061
- if (!result) {
6062
- throw new acpError_default("Failed to get user operation receipt");
6063
- }
6064
- const contractLogs = result.logs.filter((log) => {
6065
- return log.address.toLowerCase() === this.jobManagerAddress.toLowerCase();
6066
- }).map(
6067
- (log) => (0, import_viem7.decodeEventLog)({
6068
- abi: jobManagerAbi_default,
6069
- data: log.data,
6070
- topics: log.topics
6071
- })
6072
- );
6073
- const createdJobEvent = contractLogs.find(
6074
- (log) => log.eventName === "JobCreated" && log.args.client.toLowerCase() === clientAddress.toLowerCase() && log.args.provider.toLowerCase() === providerAddress.toLowerCase()
6075
- );
6076
- if (!createdJobEvent) {
6077
- throw new acpError_default("Failed to find created job event");
6078
- }
6079
- return Number(createdJobEvent.args.jobId);
6080
- });
6236
+ async getJobId(createJobUserOpHash, clientAddress, providerAddress) {
6237
+ const result = await this.sessionKeyClient.getUserOperationReceipt(
6238
+ createJobUserOpHash,
6239
+ "pending"
6240
+ );
6241
+ if (!result) {
6242
+ throw new acpError_default("Failed to get user operation receipt");
6243
+ }
6244
+ const contractLogs = result.logs.filter((log) => {
6245
+ return log.address.toLowerCase() === this.jobManagerAddress.toLowerCase();
6246
+ }).map(
6247
+ (log) => (0, import_viem7.decodeEventLog)({
6248
+ abi: jobManagerAbi_default,
6249
+ data: log.data,
6250
+ topics: log.topics
6251
+ })
6252
+ );
6253
+ const createdJobEvent = contractLogs.find(
6254
+ (log) => log.eventName === "JobCreated" && log.args.client.toLowerCase() === clientAddress.toLowerCase() && log.args.provider.toLowerCase() === providerAddress.toLowerCase()
6255
+ );
6256
+ if (!createdJobEvent) {
6257
+ throw new acpError_default("Failed to find created job event");
6258
+ }
6259
+ return Number(createdJobEvent.args.jobId);
6081
6260
  }
6082
- updateJobX402Nonce(jobId, nonce) {
6083
- return __async(this, null, function* () {
6084
- return yield this.acpX402.updateJobNonce(jobId, nonce);
6085
- });
6261
+ async updateJobX402Nonce(jobId, nonce) {
6262
+ return await this.acpX402.updateJobNonce(jobId, nonce);
6086
6263
  }
6087
- generateX402Payment(payableRequest, requirements) {
6088
- return __async(this, null, function* () {
6089
- return yield this.acpX402.generatePayment(payableRequest, requirements);
6090
- });
6264
+ async generateX402Payment(payableRequest, requirements) {
6265
+ return await this.acpX402.generatePayment(payableRequest, requirements);
6091
6266
  }
6092
- performX402Request(url, version2, budget, signature) {
6093
- return __async(this, null, function* () {
6094
- return yield this.acpX402.performRequest(url, version2, budget, signature);
6095
- });
6267
+ async performX402Request(url, version2, budget, signature) {
6268
+ return await this.acpX402.performRequest(url, version2, budget, signature);
6096
6269
  }
6097
- getX402PaymentDetails(jobId) {
6098
- return __async(this, null, function* () {
6099
- try {
6100
- const result = yield this.publicClient.readContract({
6101
- address: this.jobManagerAddress,
6102
- abi: jobManagerAbi_default,
6103
- functionName: "x402PaymentDetails",
6104
- args: [BigInt(jobId)]
6105
- });
6106
- return {
6107
- isX402: result[0],
6108
- isBudgetReceived: result[1]
6109
- };
6110
- } catch (error) {
6111
- throw new acpError_default("Failed to get X402 payment details", error);
6112
- }
6113
- });
6270
+ async getX402PaymentDetails(jobId) {
6271
+ try {
6272
+ const result = await this.publicClient.readContract({
6273
+ address: this.jobManagerAddress,
6274
+ abi: jobManagerAbi_default,
6275
+ functionName: "x402PaymentDetails",
6276
+ args: [BigInt(jobId)]
6277
+ });
6278
+ return {
6279
+ isX402: result[0],
6280
+ isBudgetReceived: result[1]
6281
+ };
6282
+ } catch (error) {
6283
+ throw new acpError_default("Failed to get X402 payment details", error);
6284
+ }
6114
6285
  }
6115
6286
  getAcpVersion() {
6116
6287
  return "2";