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

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.d.mts CHANGED
@@ -216,7 +216,8 @@ declare enum AcpJobPhases {
216
216
  declare enum FeeType {
217
217
  NO_FEE = 0,
218
218
  IMMEDIATE_FEE = 1,
219
- DEFERRED_FEE = 2
219
+ DEFERRED_FEE = 2,
220
+ PERCENTAGE_FEE = 3
220
221
  }
221
222
  interface OperationPayload {
222
223
  data: `0x${string}`;
@@ -234,7 +235,7 @@ declare abstract class BaseAcpContractClient {
234
235
  abstract handleOperation(operations: OperationPayload[]): Promise<Address>;
235
236
  abstract getJobId(hash: Address, clientAddress: Address, providerAddress: Address): Promise<number>;
236
237
  get walletAddress(): `0x${string}`;
237
- createJobWithAccount(accountId: number, providerAddress: Address, evaluatorAddress: Address, budgetBaseUnit: bigint, paymentTokenAddress: Address, expiredAt: Date): OperationPayload;
238
+ createJobWithAccount(accountId: number, evaluatorAddress: Address, budgetBaseUnit: bigint, paymentTokenAddress: Address, expiredAt: Date): OperationPayload;
238
239
  createJob(providerAddress: Address, evaluatorAddress: Address, expiredAt: Date, paymentTokenAddress: Address, budgetBaseUnit: bigint, metadata: string): OperationPayload;
239
240
  approveAllowance(amountBaseUnit: bigint, paymentTokenAddress?: Address): OperationPayload;
240
241
  createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW | MemoType.PAYABLE_TRANSFER | MemoType.PAYABLE_NOTIFICATION, expiredAt: Date, token?: Address, secured?: boolean): OperationPayload;
@@ -274,6 +275,23 @@ declare class AcpMemo {
274
275
  sign(approved: boolean, reason?: string): Promise<`0x${string}`>;
275
276
  }
276
277
 
278
+ declare enum PriceType {
279
+ FIXED = "fixed",
280
+ PERCENTAGE = "percentage"
281
+ }
282
+ declare class AcpJobOffering {
283
+ private readonly acpClient;
284
+ private readonly acpContractClient;
285
+ providerAddress: Address;
286
+ name: string;
287
+ price: number;
288
+ priceType: PriceType;
289
+ requirement?: (Object | string) | undefined;
290
+ private ajv;
291
+ constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, priceType?: PriceType, requirement?: (Object | string) | undefined);
292
+ initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
293
+ }
294
+
277
295
  type DeliverablePayload = string | Record<string, unknown>;
278
296
  /** @deprecated Use DeliverablePayload instead */
279
297
  type IDeliverable = DeliverablePayload;
@@ -325,7 +343,10 @@ type AcpAgent = {
325
343
  twitterHandle: string;
326
344
  jobs: {
327
345
  name: string;
328
- price: number;
346
+ priceV2: {
347
+ type: PriceType;
348
+ value: number;
349
+ };
329
350
  requirement?: Object | string;
330
351
  deliverable?: Object | string;
331
352
  }[];
@@ -418,6 +439,8 @@ declare class AcpJob {
418
439
  contractAddress: Address;
419
440
  name: string | undefined;
420
441
  requirement: Record<string, any> | string | undefined;
442
+ priceType: PriceType;
443
+ priceValue: number;
421
444
  constructor(acpClient: AcpClient, id: number, clientAddress: Address, providerAddress: Address, evaluatorAddress: Address, price: number, priceTokenAddress: Address, memos: AcpMemo[], phase: AcpJobPhases, context: Record<string, any>, contractAddress: Address);
422
445
  get acpContractClient(): BaseAcpContractClient;
423
446
  get config(): AcpContractConfig;
@@ -435,6 +458,7 @@ declare class AcpJob {
435
458
  respond(accept: boolean, reason?: string): Promise<`0x${string}`>;
436
459
  accept(reason?: string): Promise<`0x${string}`>;
437
460
  reject(reason?: string): Promise<`0x${string}`>;
461
+ rejectPayable(reason: string | undefined, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
438
462
  deliver(deliverable: DeliverablePayload): Promise<`0x${string}`>;
439
463
  deliverPayable(deliverable: DeliverablePayload, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
440
464
  evaluate(accept: boolean, reason?: string): Promise<void>;
@@ -442,18 +466,6 @@ declare class AcpJob {
442
466
  createPayableNotification(content: string, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
443
467
  }
444
468
 
445
- declare class AcpJobOffering {
446
- private readonly acpClient;
447
- private readonly acpContractClient;
448
- providerAddress: Address;
449
- name: string;
450
- price: number;
451
- requirement?: (Object | string) | undefined;
452
- private ajv;
453
- constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, requirement?: (Object | string) | undefined);
454
- initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
455
- }
456
-
457
469
  interface IAcpBrowseAgentsOptions {
458
470
  cluster?: string;
459
471
  sort_by?: AcpAgentSort[];
@@ -8770,7 +8782,7 @@ declare class AcpContractClient extends BaseAcpContractClient {
8770
8782
  createJob(providerAddress: Address$1, evaluatorAddress: Address$1, expireAt: Date, paymentTokenAddress: Address$1, budgetBaseUnit: bigint, metadata: string): OperationPayload;
8771
8783
  setBudgetWithPaymentToken(jobId: number, budgetBaseUnit: bigint, paymentTokenAddress?: Address$1): OperationPayload;
8772
8784
  createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address$1, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW, expiredAt: Date, token?: Address$1, secured?: boolean): OperationPayload;
8773
- createJobWithAccount(accountId: number, providerAddress: Address$1, evaluatorAddress: Address$1, budgetBaseUnit: bigint, paymentTokenAddress: Address$1, expiredAt: Date): OperationPayload;
8785
+ createJobWithAccount(accountId: number, evaluatorAddress: Address$1, budgetBaseUnit: bigint, paymentTokenAddress: Address$1, expiredAt: Date): OperationPayload;
8774
8786
  updateAccountMetadata(accountId: number, metadata: string): OperationPayload;
8775
8787
  }
8776
8788
 
package/dist/index.d.ts CHANGED
@@ -216,7 +216,8 @@ declare enum AcpJobPhases {
216
216
  declare enum FeeType {
217
217
  NO_FEE = 0,
218
218
  IMMEDIATE_FEE = 1,
219
- DEFERRED_FEE = 2
219
+ DEFERRED_FEE = 2,
220
+ PERCENTAGE_FEE = 3
220
221
  }
221
222
  interface OperationPayload {
222
223
  data: `0x${string}`;
@@ -234,7 +235,7 @@ declare abstract class BaseAcpContractClient {
234
235
  abstract handleOperation(operations: OperationPayload[]): Promise<Address>;
235
236
  abstract getJobId(hash: Address, clientAddress: Address, providerAddress: Address): Promise<number>;
236
237
  get walletAddress(): `0x${string}`;
237
- createJobWithAccount(accountId: number, providerAddress: Address, evaluatorAddress: Address, budgetBaseUnit: bigint, paymentTokenAddress: Address, expiredAt: Date): OperationPayload;
238
+ createJobWithAccount(accountId: number, evaluatorAddress: Address, budgetBaseUnit: bigint, paymentTokenAddress: Address, expiredAt: Date): OperationPayload;
238
239
  createJob(providerAddress: Address, evaluatorAddress: Address, expiredAt: Date, paymentTokenAddress: Address, budgetBaseUnit: bigint, metadata: string): OperationPayload;
239
240
  approveAllowance(amountBaseUnit: bigint, paymentTokenAddress?: Address): OperationPayload;
240
241
  createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW | MemoType.PAYABLE_TRANSFER | MemoType.PAYABLE_NOTIFICATION, expiredAt: Date, token?: Address, secured?: boolean): OperationPayload;
@@ -274,6 +275,23 @@ declare class AcpMemo {
274
275
  sign(approved: boolean, reason?: string): Promise<`0x${string}`>;
275
276
  }
276
277
 
278
+ declare enum PriceType {
279
+ FIXED = "fixed",
280
+ PERCENTAGE = "percentage"
281
+ }
282
+ declare class AcpJobOffering {
283
+ private readonly acpClient;
284
+ private readonly acpContractClient;
285
+ providerAddress: Address;
286
+ name: string;
287
+ price: number;
288
+ priceType: PriceType;
289
+ requirement?: (Object | string) | undefined;
290
+ private ajv;
291
+ constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, priceType?: PriceType, requirement?: (Object | string) | undefined);
292
+ initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
293
+ }
294
+
277
295
  type DeliverablePayload = string | Record<string, unknown>;
278
296
  /** @deprecated Use DeliverablePayload instead */
279
297
  type IDeliverable = DeliverablePayload;
@@ -325,7 +343,10 @@ type AcpAgent = {
325
343
  twitterHandle: string;
326
344
  jobs: {
327
345
  name: string;
328
- price: number;
346
+ priceV2: {
347
+ type: PriceType;
348
+ value: number;
349
+ };
329
350
  requirement?: Object | string;
330
351
  deliverable?: Object | string;
331
352
  }[];
@@ -418,6 +439,8 @@ declare class AcpJob {
418
439
  contractAddress: Address;
419
440
  name: string | undefined;
420
441
  requirement: Record<string, any> | string | undefined;
442
+ priceType: PriceType;
443
+ priceValue: number;
421
444
  constructor(acpClient: AcpClient, id: number, clientAddress: Address, providerAddress: Address, evaluatorAddress: Address, price: number, priceTokenAddress: Address, memos: AcpMemo[], phase: AcpJobPhases, context: Record<string, any>, contractAddress: Address);
422
445
  get acpContractClient(): BaseAcpContractClient;
423
446
  get config(): AcpContractConfig;
@@ -435,6 +458,7 @@ declare class AcpJob {
435
458
  respond(accept: boolean, reason?: string): Promise<`0x${string}`>;
436
459
  accept(reason?: string): Promise<`0x${string}`>;
437
460
  reject(reason?: string): Promise<`0x${string}`>;
461
+ rejectPayable(reason: string | undefined, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
438
462
  deliver(deliverable: DeliverablePayload): Promise<`0x${string}`>;
439
463
  deliverPayable(deliverable: DeliverablePayload, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
440
464
  evaluate(accept: boolean, reason?: string): Promise<void>;
@@ -442,18 +466,6 @@ declare class AcpJob {
442
466
  createPayableNotification(content: string, amount: FareAmountBase, expiredAt?: Date): Promise<`0x${string}`>;
443
467
  }
444
468
 
445
- declare class AcpJobOffering {
446
- private readonly acpClient;
447
- private readonly acpContractClient;
448
- providerAddress: Address;
449
- name: string;
450
- price: number;
451
- requirement?: (Object | string) | undefined;
452
- private ajv;
453
- constructor(acpClient: AcpClient, acpContractClient: BaseAcpContractClient, providerAddress: Address, name: string, price: number, requirement?: (Object | string) | undefined);
454
- initiateJob(serviceRequirement: Object | string, evaluatorAddress?: Address, expiredAt?: Date): Promise<number>;
455
- }
456
-
457
469
  interface IAcpBrowseAgentsOptions {
458
470
  cluster?: string;
459
471
  sort_by?: AcpAgentSort[];
@@ -8770,7 +8782,7 @@ declare class AcpContractClient extends BaseAcpContractClient {
8770
8782
  createJob(providerAddress: Address$1, evaluatorAddress: Address$1, expireAt: Date, paymentTokenAddress: Address$1, budgetBaseUnit: bigint, metadata: string): OperationPayload;
8771
8783
  setBudgetWithPaymentToken(jobId: number, budgetBaseUnit: bigint, paymentTokenAddress?: Address$1): OperationPayload;
8772
8784
  createPayableMemo(jobId: number, content: string, amountBaseUnit: bigint, recipient: Address$1, feeAmountBaseUnit: bigint, feeType: FeeType, nextPhase: AcpJobPhases, type: MemoType.PAYABLE_REQUEST | MemoType.PAYABLE_TRANSFER_ESCROW, expiredAt: Date, token?: Address$1, secured?: boolean): OperationPayload;
8773
- createJobWithAccount(accountId: number, providerAddress: Address$1, evaluatorAddress: Address$1, budgetBaseUnit: bigint, paymentTokenAddress: Address$1, expiredAt: Date): OperationPayload;
8785
+ createJobWithAccount(accountId: number, evaluatorAddress: Address$1, budgetBaseUnit: bigint, paymentTokenAddress: Address$1, expiredAt: Date): OperationPayload;
8774
8786
  updateAccountMetadata(accountId: number, metadata: string): OperationPayload;
8775
8787
  }
8776
8788
 
package/dist/index.js CHANGED
@@ -55,7 +55,7 @@ var require_package = __commonJS({
55
55
  "package.json"(exports2, module2) {
56
56
  module2.exports = {
57
57
  name: "@virtuals-protocol/acp-node",
58
- version: "0.3.0-beta.5",
58
+ version: "0.3.0-beta.7",
59
59
  main: "./dist/index.js",
60
60
  module: "./dist/index.mjs",
61
61
  types: "./dist/index.d.ts",
@@ -3062,7 +3062,7 @@ var BaseAcpContractClient = class {
3062
3062
  get walletAddress() {
3063
3063
  return this.agentWalletAddress;
3064
3064
  }
3065
- createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
3065
+ createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
3066
3066
  try {
3067
3067
  const data = (0, import_viem2.encodeFunctionData)({
3068
3068
  abi: this.abi,
@@ -3277,6 +3277,94 @@ function preparePayload(payload) {
3277
3277
  return typeof payload === "string" ? payload : JSON.stringify(payload);
3278
3278
  }
3279
3279
 
3280
+ // src/acpJobOffering.ts
3281
+ var import_viem3 = require("viem");
3282
+ var import_ajv = __toESM(require("ajv"));
3283
+ var AcpJobOffering = class {
3284
+ constructor(acpClient, acpContractClient, providerAddress, name, price, priceType = "fixed" /* FIXED */, requirement) {
3285
+ this.acpClient = acpClient;
3286
+ this.acpContractClient = acpContractClient;
3287
+ this.providerAddress = providerAddress;
3288
+ this.name = name;
3289
+ this.price = price;
3290
+ this.priceType = priceType;
3291
+ this.requirement = requirement;
3292
+ this.ajv = new import_ajv.default({ allErrors: true });
3293
+ }
3294
+ initiateJob(_0, _1) {
3295
+ return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3296
+ if (this.requirement && typeof this.requirement === "object") {
3297
+ const validator = this.ajv.compile(this.requirement);
3298
+ const valid = validator(serviceRequirement);
3299
+ if (!valid) {
3300
+ throw new acpError_default(this.ajv.errorsText(validator.errors));
3301
+ }
3302
+ }
3303
+ const finalServiceRequirement = {
3304
+ name: this.name,
3305
+ requirement: serviceRequirement,
3306
+ priceValue: this.price,
3307
+ priceType: this.priceType
3308
+ };
3309
+ const fareAmount = new FareAmount(
3310
+ this.priceType === "fixed" /* FIXED */ ? this.price : 0,
3311
+ this.acpContractClient.config.baseFare
3312
+ );
3313
+ const account = yield this.acpClient.getByClientAndProvider(
3314
+ this.acpContractClient.walletAddress,
3315
+ this.providerAddress,
3316
+ this.acpContractClient
3317
+ );
3318
+ const createJobPayload = [
3319
+ baseSepoliaAcpConfig.contractAddress,
3320
+ baseAcpConfig.contractAddress
3321
+ ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
3322
+ this.providerAddress,
3323
+ evaluatorAddress || this.acpContractClient.walletAddress,
3324
+ expiredAt,
3325
+ fareAmount.fare.contractAddress,
3326
+ fareAmount.amount,
3327
+ ""
3328
+ ) : yield this.acpContractClient.createJobWithAccount(
3329
+ account.id,
3330
+ evaluatorAddress || import_viem3.zeroAddress,
3331
+ fareAmount.amount,
3332
+ fareAmount.fare.contractAddress,
3333
+ expiredAt
3334
+ );
3335
+ const createJobTxnHash = yield this.acpContractClient.handleOperation([
3336
+ createJobPayload
3337
+ ]);
3338
+ const jobId = yield this.acpContractClient.getJobId(
3339
+ createJobTxnHash,
3340
+ this.acpContractClient.walletAddress,
3341
+ this.providerAddress
3342
+ );
3343
+ const payloads = [];
3344
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3345
+ jobId,
3346
+ fareAmount.amount,
3347
+ fareAmount.fare.contractAddress
3348
+ );
3349
+ if (setBudgetWithPaymentTokenPayload) {
3350
+ payloads.push(setBudgetWithPaymentTokenPayload);
3351
+ }
3352
+ payloads.push(
3353
+ this.acpContractClient.createMemo(
3354
+ jobId,
3355
+ JSON.stringify(finalServiceRequirement),
3356
+ 0 /* MESSAGE */,
3357
+ true,
3358
+ 1 /* NEGOTIATION */
3359
+ )
3360
+ );
3361
+ yield this.acpContractClient.handleOperation(payloads);
3362
+ return jobId;
3363
+ });
3364
+ }
3365
+ };
3366
+ var acpJobOffering_default = AcpJobOffering;
3367
+
3280
3368
  // src/acpJob.ts
3281
3369
  var AcpJob = class {
3282
3370
  constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress) {
@@ -3291,6 +3379,8 @@ var AcpJob = class {
3291
3379
  this.phase = phase;
3292
3380
  this.context = context;
3293
3381
  this.contractAddress = contractAddress;
3382
+ this.priceType = "fixed" /* FIXED */;
3383
+ this.priceValue = 0;
3294
3384
  var _a;
3295
3385
  const content = (_a = this.memos.find(
3296
3386
  (m) => m.nextPhase === 1 /* NEGOTIATION */
@@ -3308,6 +3398,12 @@ var AcpJob = class {
3308
3398
  if (contentObj.serviceName || contentObj.name) {
3309
3399
  this.name = contentObj.name || contentObj.serviceName;
3310
3400
  }
3401
+ if (contentObj.priceType) {
3402
+ this.priceType = contentObj.priceType || "fixed" /* FIXED */;
3403
+ }
3404
+ if (contentObj.priceValue) {
3405
+ this.priceValue = contentObj.priceValue || this.price;
3406
+ }
3311
3407
  }
3312
3408
  get acpContractClient() {
3313
3409
  return this.acpClient.contractClientByAddress(this.contractAddress);
@@ -3380,8 +3476,8 @@ var AcpJob = class {
3380
3476
  content,
3381
3477
  amount.amount,
3382
3478
  recipient,
3383
- feeAmount.amount,
3384
- 0 /* NO_FEE */,
3479
+ this.priceType === "percentage" /* PERCENTAGE */ ? BigInt(this.priceValue * 1e4) : feeAmount.amount,
3480
+ this.priceType === "percentage" /* PERCENTAGE */ ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
3385
3481
  2 /* TRANSACTION */,
3386
3482
  type,
3387
3483
  expiredAt,
@@ -3439,41 +3535,32 @@ var AcpJob = class {
3439
3535
  const memoContent = `${reason || `Job ${this.id} ${accept ? "accepted" : "rejected"}.`}`;
3440
3536
  if (accept) {
3441
3537
  yield this.accept(memoContent);
3442
- return yield this.createRequirement(memoContent);
3538
+ return this.createRequirement(memoContent);
3443
3539
  }
3444
3540
  return yield this.reject(memoContent);
3445
3541
  });
3446
3542
  }
3447
3543
  accept(reason) {
3448
3544
  return __async(this, null, function* () {
3449
- var _a;
3450
3545
  const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
3451
- const operations = [];
3452
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3546
+ const latestMemo = this.latestMemo;
3547
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3453
3548
  throw new acpError_default("No request memo found");
3454
3549
  }
3455
- const memo = this.latestMemo;
3456
- operations.push(
3457
- this.acpContractClient.signMemo(memo.id, true, memoContent)
3458
- );
3459
- return yield this.acpContractClient.handleOperation(operations);
3550
+ return yield latestMemo.sign(true, memoContent);
3460
3551
  });
3461
3552
  }
3462
3553
  reject(reason) {
3463
3554
  return __async(this, null, function* () {
3464
- var _a;
3465
3555
  const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
3466
- const operations = [];
3467
3556
  if (this.phase === 0 /* REQUEST */) {
3468
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3557
+ const latestMemo = this.latestMemo;
3558
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3469
3559
  throw new acpError_default("No request memo found");
3470
3560
  }
3471
- const memo = this.latestMemo;
3472
- operations.push(
3473
- this.acpContractClient.signMemo(memo.id, false, memoContent)
3474
- );
3475
- return yield this.acpContractClient.handleOperation(operations);
3561
+ return yield latestMemo.sign(false, memoContent);
3476
3562
  }
3563
+ const operations = [];
3477
3564
  operations.push(
3478
3565
  this.acpContractClient.createMemo(
3479
3566
  this.id,
@@ -3486,6 +3573,34 @@ var AcpJob = class {
3486
3573
  return yield this.acpContractClient.handleOperation(operations);
3487
3574
  });
3488
3575
  }
3576
+ rejectPayable() {
3577
+ return __async(this, arguments, function* (reason = "", amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3578
+ const memoContent = `Job ${this.id} rejected. ${reason}`;
3579
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3580
+ const operations = [];
3581
+ operations.push(
3582
+ this.acpContractClient.approveAllowance(
3583
+ amount.amount,
3584
+ amount.fare.contractAddress
3585
+ )
3586
+ );
3587
+ operations.push(
3588
+ this.acpContractClient.createPayableMemo(
3589
+ this.id,
3590
+ memoContent,
3591
+ amount.amount,
3592
+ this.clientAddress,
3593
+ feeAmount.amount,
3594
+ 0 /* NO_FEE */,
3595
+ 5 /* REJECTED */,
3596
+ 7 /* PAYABLE_TRANSFER */,
3597
+ expiredAt,
3598
+ amount.fare.contractAddress
3599
+ )
3600
+ );
3601
+ return yield this.acpContractClient.handleOperation(operations);
3602
+ });
3603
+ }
3489
3604
  deliver(deliverable) {
3490
3605
  return __async(this, null, function* () {
3491
3606
  var _a;
@@ -3637,92 +3752,6 @@ var AcpMemo = class {
3637
3752
  };
3638
3753
  var acpMemo_default = AcpMemo;
3639
3754
 
3640
- // src/acpJobOffering.ts
3641
- var import_viem3 = require("viem");
3642
- var import_ajv = __toESM(require("ajv"));
3643
- var AcpJobOffering = class {
3644
- constructor(acpClient, acpContractClient, providerAddress, name, price, requirement) {
3645
- this.acpClient = acpClient;
3646
- this.acpContractClient = acpContractClient;
3647
- this.providerAddress = providerAddress;
3648
- this.name = name;
3649
- this.price = price;
3650
- this.requirement = requirement;
3651
- this.ajv = new import_ajv.default({ allErrors: true });
3652
- }
3653
- initiateJob(_0, _1) {
3654
- return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3655
- if (this.requirement && typeof this.requirement === "object") {
3656
- const validator = this.ajv.compile(this.requirement);
3657
- const valid = validator(serviceRequirement);
3658
- if (!valid) {
3659
- throw new acpError_default(this.ajv.errorsText(validator.errors));
3660
- }
3661
- }
3662
- const finalServiceRequirement = {
3663
- name: this.name,
3664
- requirement: serviceRequirement
3665
- };
3666
- const fareAmount = new FareAmount(
3667
- this.price,
3668
- this.acpContractClient.config.baseFare
3669
- );
3670
- const account = yield this.acpClient.getByClientAndProvider(
3671
- this.acpContractClient.walletAddress,
3672
- this.providerAddress,
3673
- this.acpContractClient
3674
- );
3675
- const createJobPayload = [
3676
- baseSepoliaAcpConfig.contractAddress,
3677
- baseAcpConfig.contractAddress
3678
- ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
3679
- this.providerAddress,
3680
- evaluatorAddress || this.acpContractClient.walletAddress,
3681
- expiredAt,
3682
- fareAmount.fare.contractAddress,
3683
- fareAmount.amount,
3684
- ""
3685
- ) : yield this.acpContractClient.createJobWithAccount(
3686
- account.id,
3687
- this.providerAddress,
3688
- evaluatorAddress || import_viem3.zeroAddress,
3689
- fareAmount.amount,
3690
- fareAmount.fare.contractAddress,
3691
- expiredAt
3692
- );
3693
- const createJobTxnHash = yield this.acpContractClient.handleOperation([
3694
- createJobPayload
3695
- ]);
3696
- const jobId = yield this.acpContractClient.getJobId(
3697
- createJobTxnHash,
3698
- this.acpContractClient.walletAddress,
3699
- this.providerAddress
3700
- );
3701
- const payloads = [];
3702
- const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3703
- jobId,
3704
- fareAmount.amount,
3705
- fareAmount.fare.contractAddress
3706
- );
3707
- if (setBudgetWithPaymentTokenPayload) {
3708
- payloads.push(setBudgetWithPaymentTokenPayload);
3709
- }
3710
- payloads.push(
3711
- this.acpContractClient.createMemo(
3712
- jobId,
3713
- JSON.stringify(finalServiceRequirement),
3714
- 0 /* MESSAGE */,
3715
- true,
3716
- 1 /* NEGOTIATION */
3717
- )
3718
- );
3719
- yield this.acpContractClient.handleOperation(payloads);
3720
- return jobId;
3721
- });
3722
- }
3723
- };
3724
- var acpJobOffering_default = AcpJobOffering;
3725
-
3726
3755
  // src/acpAccount.ts
3727
3756
  var AcpAccount = class {
3728
3757
  constructor(contractClient, id, clientAddress, providerAddress, metadata) {
@@ -3943,7 +3972,8 @@ var AcpClient = class {
3943
3972
  acpContractClient,
3944
3973
  agent.walletAddress,
3945
3974
  jobs.name,
3946
- jobs.price,
3975
+ jobs.priceV2.value,
3976
+ jobs.priceV2.type,
3947
3977
  jobs.requirement
3948
3978
  );
3949
3979
  }),
@@ -3984,7 +4014,6 @@ var AcpClient = class {
3984
4014
  ""
3985
4015
  ) : yield this.acpContractClient.createJobWithAccount(
3986
4016
  account.id,
3987
- providerAddress,
3988
4017
  evaluatorAddress || defaultEvaluatorAddress,
3989
4018
  fareAmount.amount,
3990
4019
  fareAmount.fare.contractAddress,
@@ -4528,7 +4557,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4528
4557
  throw new acpError_default("Failed to create payable memo", error);
4529
4558
  }
4530
4559
  }
4531
- createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4560
+ createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4532
4561
  throw new acpError_default("Not Supported");
4533
4562
  }
4534
4563
  updateAccountMetadata(accountId, metadata) {
package/dist/index.mjs CHANGED
@@ -28,7 +28,7 @@ var require_package = __commonJS({
28
28
  "package.json"(exports, module) {
29
29
  module.exports = {
30
30
  name: "@virtuals-protocol/acp-node",
31
- version: "0.3.0-beta.5",
31
+ version: "0.3.0-beta.7",
32
32
  main: "./dist/index.js",
33
33
  module: "./dist/index.mjs",
34
34
  types: "./dist/index.d.ts",
@@ -3014,7 +3014,7 @@ var BaseAcpContractClient = class {
3014
3014
  get walletAddress() {
3015
3015
  return this.agentWalletAddress;
3016
3016
  }
3017
- createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
3017
+ createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
3018
3018
  try {
3019
3019
  const data = encodeFunctionData({
3020
3020
  abi: this.abi,
@@ -3229,6 +3229,94 @@ function preparePayload(payload) {
3229
3229
  return typeof payload === "string" ? payload : JSON.stringify(payload);
3230
3230
  }
3231
3231
 
3232
+ // src/acpJobOffering.ts
3233
+ import { zeroAddress } from "viem";
3234
+ import Ajv from "ajv";
3235
+ var AcpJobOffering = class {
3236
+ constructor(acpClient, acpContractClient, providerAddress, name, price, priceType = "fixed" /* FIXED */, requirement) {
3237
+ this.acpClient = acpClient;
3238
+ this.acpContractClient = acpContractClient;
3239
+ this.providerAddress = providerAddress;
3240
+ this.name = name;
3241
+ this.price = price;
3242
+ this.priceType = priceType;
3243
+ this.requirement = requirement;
3244
+ this.ajv = new Ajv({ allErrors: true });
3245
+ }
3246
+ initiateJob(_0, _1) {
3247
+ return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3248
+ if (this.requirement && typeof this.requirement === "object") {
3249
+ const validator = this.ajv.compile(this.requirement);
3250
+ const valid = validator(serviceRequirement);
3251
+ if (!valid) {
3252
+ throw new acpError_default(this.ajv.errorsText(validator.errors));
3253
+ }
3254
+ }
3255
+ const finalServiceRequirement = {
3256
+ name: this.name,
3257
+ requirement: serviceRequirement,
3258
+ priceValue: this.price,
3259
+ priceType: this.priceType
3260
+ };
3261
+ const fareAmount = new FareAmount(
3262
+ this.priceType === "fixed" /* FIXED */ ? this.price : 0,
3263
+ this.acpContractClient.config.baseFare
3264
+ );
3265
+ const account = yield this.acpClient.getByClientAndProvider(
3266
+ this.acpContractClient.walletAddress,
3267
+ this.providerAddress,
3268
+ this.acpContractClient
3269
+ );
3270
+ const createJobPayload = [
3271
+ baseSepoliaAcpConfig.contractAddress,
3272
+ baseAcpConfig.contractAddress
3273
+ ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
3274
+ this.providerAddress,
3275
+ evaluatorAddress || this.acpContractClient.walletAddress,
3276
+ expiredAt,
3277
+ fareAmount.fare.contractAddress,
3278
+ fareAmount.amount,
3279
+ ""
3280
+ ) : yield this.acpContractClient.createJobWithAccount(
3281
+ account.id,
3282
+ evaluatorAddress || zeroAddress,
3283
+ fareAmount.amount,
3284
+ fareAmount.fare.contractAddress,
3285
+ expiredAt
3286
+ );
3287
+ const createJobTxnHash = yield this.acpContractClient.handleOperation([
3288
+ createJobPayload
3289
+ ]);
3290
+ const jobId = yield this.acpContractClient.getJobId(
3291
+ createJobTxnHash,
3292
+ this.acpContractClient.walletAddress,
3293
+ this.providerAddress
3294
+ );
3295
+ const payloads = [];
3296
+ const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3297
+ jobId,
3298
+ fareAmount.amount,
3299
+ fareAmount.fare.contractAddress
3300
+ );
3301
+ if (setBudgetWithPaymentTokenPayload) {
3302
+ payloads.push(setBudgetWithPaymentTokenPayload);
3303
+ }
3304
+ payloads.push(
3305
+ this.acpContractClient.createMemo(
3306
+ jobId,
3307
+ JSON.stringify(finalServiceRequirement),
3308
+ 0 /* MESSAGE */,
3309
+ true,
3310
+ 1 /* NEGOTIATION */
3311
+ )
3312
+ );
3313
+ yield this.acpContractClient.handleOperation(payloads);
3314
+ return jobId;
3315
+ });
3316
+ }
3317
+ };
3318
+ var acpJobOffering_default = AcpJobOffering;
3319
+
3232
3320
  // src/acpJob.ts
3233
3321
  var AcpJob = class {
3234
3322
  constructor(acpClient, id, clientAddress, providerAddress, evaluatorAddress, price, priceTokenAddress, memos, phase, context, contractAddress) {
@@ -3243,6 +3331,8 @@ var AcpJob = class {
3243
3331
  this.phase = phase;
3244
3332
  this.context = context;
3245
3333
  this.contractAddress = contractAddress;
3334
+ this.priceType = "fixed" /* FIXED */;
3335
+ this.priceValue = 0;
3246
3336
  var _a;
3247
3337
  const content = (_a = this.memos.find(
3248
3338
  (m) => m.nextPhase === 1 /* NEGOTIATION */
@@ -3260,6 +3350,12 @@ var AcpJob = class {
3260
3350
  if (contentObj.serviceName || contentObj.name) {
3261
3351
  this.name = contentObj.name || contentObj.serviceName;
3262
3352
  }
3353
+ if (contentObj.priceType) {
3354
+ this.priceType = contentObj.priceType || "fixed" /* FIXED */;
3355
+ }
3356
+ if (contentObj.priceValue) {
3357
+ this.priceValue = contentObj.priceValue || this.price;
3358
+ }
3263
3359
  }
3264
3360
  get acpContractClient() {
3265
3361
  return this.acpClient.contractClientByAddress(this.contractAddress);
@@ -3332,8 +3428,8 @@ var AcpJob = class {
3332
3428
  content,
3333
3429
  amount.amount,
3334
3430
  recipient,
3335
- feeAmount.amount,
3336
- 0 /* NO_FEE */,
3431
+ this.priceType === "percentage" /* PERCENTAGE */ ? BigInt(this.priceValue * 1e4) : feeAmount.amount,
3432
+ this.priceType === "percentage" /* PERCENTAGE */ ? 3 /* PERCENTAGE_FEE */ : 0 /* NO_FEE */,
3337
3433
  2 /* TRANSACTION */,
3338
3434
  type,
3339
3435
  expiredAt,
@@ -3391,41 +3487,32 @@ var AcpJob = class {
3391
3487
  const memoContent = `${reason || `Job ${this.id} ${accept ? "accepted" : "rejected"}.`}`;
3392
3488
  if (accept) {
3393
3489
  yield this.accept(memoContent);
3394
- return yield this.createRequirement(memoContent);
3490
+ return this.createRequirement(memoContent);
3395
3491
  }
3396
3492
  return yield this.reject(memoContent);
3397
3493
  });
3398
3494
  }
3399
3495
  accept(reason) {
3400
3496
  return __async(this, null, function* () {
3401
- var _a;
3402
3497
  const memoContent = `Job ${this.id} accepted. ${reason || ""}`;
3403
- const operations = [];
3404
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3498
+ const latestMemo = this.latestMemo;
3499
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3405
3500
  throw new acpError_default("No request memo found");
3406
3501
  }
3407
- const memo = this.latestMemo;
3408
- operations.push(
3409
- this.acpContractClient.signMemo(memo.id, true, memoContent)
3410
- );
3411
- return yield this.acpContractClient.handleOperation(operations);
3502
+ return yield latestMemo.sign(true, memoContent);
3412
3503
  });
3413
3504
  }
3414
3505
  reject(reason) {
3415
3506
  return __async(this, null, function* () {
3416
- var _a;
3417
3507
  const memoContent = `Job ${this.id} rejected. ${reason || ""}`;
3418
- const operations = [];
3419
3508
  if (this.phase === 0 /* REQUEST */) {
3420
- if (((_a = this.latestMemo) == null ? void 0 : _a.nextPhase) !== 1 /* NEGOTIATION */) {
3509
+ const latestMemo = this.latestMemo;
3510
+ if ((latestMemo == null ? void 0 : latestMemo.nextPhase) !== 1 /* NEGOTIATION */) {
3421
3511
  throw new acpError_default("No request memo found");
3422
3512
  }
3423
- const memo = this.latestMemo;
3424
- operations.push(
3425
- this.acpContractClient.signMemo(memo.id, false, memoContent)
3426
- );
3427
- return yield this.acpContractClient.handleOperation(operations);
3513
+ return yield latestMemo.sign(false, memoContent);
3428
3514
  }
3515
+ const operations = [];
3429
3516
  operations.push(
3430
3517
  this.acpContractClient.createMemo(
3431
3518
  this.id,
@@ -3438,6 +3525,34 @@ var AcpJob = class {
3438
3525
  return yield this.acpContractClient.handleOperation(operations);
3439
3526
  });
3440
3527
  }
3528
+ rejectPayable() {
3529
+ return __async(this, arguments, function* (reason = "", amount, expiredAt = new Date(Date.now() + 1e3 * 60 * 5)) {
3530
+ const memoContent = `Job ${this.id} rejected. ${reason}`;
3531
+ const feeAmount = new FareAmount(0, this.acpContractClient.config.baseFare);
3532
+ const operations = [];
3533
+ operations.push(
3534
+ this.acpContractClient.approveAllowance(
3535
+ amount.amount,
3536
+ amount.fare.contractAddress
3537
+ )
3538
+ );
3539
+ operations.push(
3540
+ this.acpContractClient.createPayableMemo(
3541
+ this.id,
3542
+ memoContent,
3543
+ amount.amount,
3544
+ this.clientAddress,
3545
+ feeAmount.amount,
3546
+ 0 /* NO_FEE */,
3547
+ 5 /* REJECTED */,
3548
+ 7 /* PAYABLE_TRANSFER */,
3549
+ expiredAt,
3550
+ amount.fare.contractAddress
3551
+ )
3552
+ );
3553
+ return yield this.acpContractClient.handleOperation(operations);
3554
+ });
3555
+ }
3441
3556
  deliver(deliverable) {
3442
3557
  return __async(this, null, function* () {
3443
3558
  var _a;
@@ -3589,92 +3704,6 @@ var AcpMemo = class {
3589
3704
  };
3590
3705
  var acpMemo_default = AcpMemo;
3591
3706
 
3592
- // src/acpJobOffering.ts
3593
- import { zeroAddress } from "viem";
3594
- import Ajv from "ajv";
3595
- var AcpJobOffering = class {
3596
- constructor(acpClient, acpContractClient, providerAddress, name, price, requirement) {
3597
- this.acpClient = acpClient;
3598
- this.acpContractClient = acpContractClient;
3599
- this.providerAddress = providerAddress;
3600
- this.name = name;
3601
- this.price = price;
3602
- this.requirement = requirement;
3603
- this.ajv = new Ajv({ allErrors: true });
3604
- }
3605
- initiateJob(_0, _1) {
3606
- return __async(this, arguments, function* (serviceRequirement, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3607
- if (this.requirement && typeof this.requirement === "object") {
3608
- const validator = this.ajv.compile(this.requirement);
3609
- const valid = validator(serviceRequirement);
3610
- if (!valid) {
3611
- throw new acpError_default(this.ajv.errorsText(validator.errors));
3612
- }
3613
- }
3614
- const finalServiceRequirement = {
3615
- name: this.name,
3616
- requirement: serviceRequirement
3617
- };
3618
- const fareAmount = new FareAmount(
3619
- this.price,
3620
- this.acpContractClient.config.baseFare
3621
- );
3622
- const account = yield this.acpClient.getByClientAndProvider(
3623
- this.acpContractClient.walletAddress,
3624
- this.providerAddress,
3625
- this.acpContractClient
3626
- );
3627
- const createJobPayload = [
3628
- baseSepoliaAcpConfig.contractAddress,
3629
- baseAcpConfig.contractAddress
3630
- ].includes(this.acpContractClient.config.contractAddress) || !account ? yield this.acpContractClient.createJob(
3631
- this.providerAddress,
3632
- evaluatorAddress || this.acpContractClient.walletAddress,
3633
- expiredAt,
3634
- fareAmount.fare.contractAddress,
3635
- fareAmount.amount,
3636
- ""
3637
- ) : yield this.acpContractClient.createJobWithAccount(
3638
- account.id,
3639
- this.providerAddress,
3640
- evaluatorAddress || zeroAddress,
3641
- fareAmount.amount,
3642
- fareAmount.fare.contractAddress,
3643
- expiredAt
3644
- );
3645
- const createJobTxnHash = yield this.acpContractClient.handleOperation([
3646
- createJobPayload
3647
- ]);
3648
- const jobId = yield this.acpContractClient.getJobId(
3649
- createJobTxnHash,
3650
- this.acpContractClient.walletAddress,
3651
- this.providerAddress
3652
- );
3653
- const payloads = [];
3654
- const setBudgetWithPaymentTokenPayload = this.acpContractClient.setBudgetWithPaymentToken(
3655
- jobId,
3656
- fareAmount.amount,
3657
- fareAmount.fare.contractAddress
3658
- );
3659
- if (setBudgetWithPaymentTokenPayload) {
3660
- payloads.push(setBudgetWithPaymentTokenPayload);
3661
- }
3662
- payloads.push(
3663
- this.acpContractClient.createMemo(
3664
- jobId,
3665
- JSON.stringify(finalServiceRequirement),
3666
- 0 /* MESSAGE */,
3667
- true,
3668
- 1 /* NEGOTIATION */
3669
- )
3670
- );
3671
- yield this.acpContractClient.handleOperation(payloads);
3672
- return jobId;
3673
- });
3674
- }
3675
- };
3676
- var acpJobOffering_default = AcpJobOffering;
3677
-
3678
3707
  // src/acpAccount.ts
3679
3708
  var AcpAccount = class {
3680
3709
  constructor(contractClient, id, clientAddress, providerAddress, metadata) {
@@ -3895,7 +3924,8 @@ var AcpClient = class {
3895
3924
  acpContractClient,
3896
3925
  agent.walletAddress,
3897
3926
  jobs.name,
3898
- jobs.price,
3927
+ jobs.priceV2.value,
3928
+ jobs.priceV2.type,
3899
3929
  jobs.requirement
3900
3930
  );
3901
3931
  }),
@@ -3936,7 +3966,6 @@ var AcpClient = class {
3936
3966
  ""
3937
3967
  ) : yield this.acpContractClient.createJobWithAccount(
3938
3968
  account.id,
3939
- providerAddress,
3940
3969
  evaluatorAddress || defaultEvaluatorAddress,
3941
3970
  fareAmount.amount,
3942
3971
  fareAmount.fare.contractAddress,
@@ -4482,7 +4511,7 @@ var AcpContractClient = class _AcpContractClient extends baseAcpContractClient_d
4482
4511
  throw new acpError_default("Failed to create payable memo", error);
4483
4512
  }
4484
4513
  }
4485
- createJobWithAccount(accountId, providerAddress, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4514
+ createJobWithAccount(accountId, evaluatorAddress, budgetBaseUnit, paymentTokenAddress, expiredAt) {
4486
4515
  throw new acpError_default("Not Supported");
4487
4516
  }
4488
4517
  updateAccountMetadata(accountId, metadata) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virtuals-protocol/acp-node",
3
- "version": "0.3.0-beta.5",
3
+ "version": "0.3.0-beta.7",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",