@agentbadge/circle-payments 0.1.27 → 0.1.28

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.
@@ -387,7 +387,220 @@ export declare const ERC8183_ACP_ABI: readonly [{
387
387
  }];
388
388
  readonly anonymous: false;
389
389
  }];
390
- export type Erc8183Variant = "circle" | "acp";
390
+ export declare const ERC8183_REF_ABI: readonly [{
391
+ readonly type: "function";
392
+ readonly name: "createJob";
393
+ readonly stateMutability: "nonpayable";
394
+ readonly inputs: readonly [{
395
+ readonly name: "provider";
396
+ readonly type: "address";
397
+ }, {
398
+ readonly name: "evaluator";
399
+ readonly type: "address";
400
+ }, {
401
+ readonly name: "expiredAt";
402
+ readonly type: "uint48";
403
+ }, {
404
+ readonly name: "description";
405
+ readonly type: "string";
406
+ }, {
407
+ readonly name: "hook";
408
+ readonly type: "address";
409
+ }, {
410
+ readonly name: "providerAgentId";
411
+ readonly type: "uint256";
412
+ }];
413
+ readonly outputs: readonly [{
414
+ readonly name: "jobId";
415
+ readonly type: "uint256";
416
+ }];
417
+ }, {
418
+ readonly type: "function";
419
+ readonly name: "setProvider";
420
+ readonly stateMutability: "nonpayable";
421
+ readonly inputs: readonly [{
422
+ readonly name: "jobId";
423
+ readonly type: "uint256";
424
+ }, {
425
+ readonly name: "provider";
426
+ readonly type: "address";
427
+ }, {
428
+ readonly name: "agentId";
429
+ readonly type: "uint256";
430
+ }];
431
+ readonly outputs: readonly [];
432
+ }, {
433
+ readonly type: "function";
434
+ readonly name: "setBudget";
435
+ readonly stateMutability: "nonpayable";
436
+ readonly inputs: readonly [{
437
+ readonly name: "jobId";
438
+ readonly type: "uint256";
439
+ }, {
440
+ readonly name: "token";
441
+ readonly type: "address";
442
+ }, {
443
+ readonly name: "amount";
444
+ readonly type: "uint256";
445
+ }, {
446
+ readonly name: "optParams";
447
+ readonly type: "bytes";
448
+ }];
449
+ readonly outputs: readonly [];
450
+ }, {
451
+ readonly type: "function";
452
+ readonly name: "fund";
453
+ readonly stateMutability: "nonpayable";
454
+ readonly inputs: readonly [{
455
+ readonly name: "jobId";
456
+ readonly type: "uint256";
457
+ }, {
458
+ readonly name: "expectedToken";
459
+ readonly type: "address";
460
+ }, {
461
+ readonly name: "expectedBudget";
462
+ readonly type: "uint256";
463
+ }, {
464
+ readonly name: "optParams";
465
+ readonly type: "bytes";
466
+ }];
467
+ readonly outputs: readonly [];
468
+ }, {
469
+ readonly type: "function";
470
+ readonly name: "submit";
471
+ readonly stateMutability: "nonpayable";
472
+ readonly inputs: readonly [{
473
+ readonly name: "jobId";
474
+ readonly type: "uint256";
475
+ }, {
476
+ readonly name: "deliverable";
477
+ readonly type: "bytes32";
478
+ }, {
479
+ readonly name: "optParams";
480
+ readonly type: "bytes";
481
+ }];
482
+ readonly outputs: readonly [];
483
+ }, {
484
+ readonly type: "function";
485
+ readonly name: "complete";
486
+ readonly stateMutability: "nonpayable";
487
+ readonly inputs: readonly [{
488
+ readonly name: "jobId";
489
+ readonly type: "uint256";
490
+ }, {
491
+ readonly name: "reason";
492
+ readonly type: "bytes32";
493
+ }, {
494
+ readonly name: "optParams";
495
+ readonly type: "bytes";
496
+ }];
497
+ readonly outputs: readonly [];
498
+ }, {
499
+ readonly type: "function";
500
+ readonly name: "reject";
501
+ readonly stateMutability: "nonpayable";
502
+ readonly inputs: readonly [{
503
+ readonly name: "jobId";
504
+ readonly type: "uint256";
505
+ }, {
506
+ readonly name: "reason";
507
+ readonly type: "bytes32";
508
+ }, {
509
+ readonly name: "optParams";
510
+ readonly type: "bytes";
511
+ }];
512
+ readonly outputs: readonly [];
513
+ }, {
514
+ readonly type: "function";
515
+ readonly name: "claimRefund";
516
+ readonly stateMutability: "nonpayable";
517
+ readonly inputs: readonly [{
518
+ readonly name: "jobId";
519
+ readonly type: "uint256";
520
+ }];
521
+ readonly outputs: readonly [];
522
+ }, {
523
+ readonly type: "function";
524
+ readonly name: "getJob";
525
+ readonly stateMutability: "view";
526
+ readonly inputs: readonly [{
527
+ readonly name: "jobId";
528
+ readonly type: "uint256";
529
+ }];
530
+ readonly outputs: readonly [{
531
+ readonly type: "tuple";
532
+ readonly components: readonly [{
533
+ readonly name: "client";
534
+ readonly type: "address";
535
+ }, {
536
+ readonly name: "status";
537
+ readonly type: "uint8";
538
+ }, {
539
+ readonly name: "provider";
540
+ readonly type: "address";
541
+ }, {
542
+ readonly name: "expiredAt";
543
+ readonly type: "uint48";
544
+ }, {
545
+ readonly name: "evaluator";
546
+ readonly type: "address";
547
+ }, {
548
+ readonly name: "submittedAt";
549
+ readonly type: "uint48";
550
+ }, {
551
+ readonly name: "budget";
552
+ readonly type: "uint256";
553
+ }, {
554
+ readonly name: "hook";
555
+ readonly type: "address";
556
+ }, {
557
+ readonly name: "paymentToken";
558
+ readonly type: "address";
559
+ }, {
560
+ readonly name: "providerAgentId";
561
+ readonly type: "uint256";
562
+ }, {
563
+ readonly name: "description";
564
+ readonly type: "string";
565
+ }, {
566
+ readonly name: "settledAmount";
567
+ readonly type: "uint256";
568
+ }, {
569
+ readonly name: "payoutReceiver";
570
+ readonly type: "address";
571
+ }];
572
+ }];
573
+ }, {
574
+ readonly type: "event";
575
+ readonly name: "JobCreated";
576
+ readonly inputs: readonly [{
577
+ readonly indexed: true;
578
+ readonly name: "jobId";
579
+ readonly type: "uint256";
580
+ }, {
581
+ readonly indexed: true;
582
+ readonly name: "client";
583
+ readonly type: "address";
584
+ }, {
585
+ readonly indexed: true;
586
+ readonly name: "provider";
587
+ readonly type: "address";
588
+ }, {
589
+ readonly indexed: false;
590
+ readonly name: "evaluator";
591
+ readonly type: "address";
592
+ }, {
593
+ readonly indexed: false;
594
+ readonly name: "expiredAt";
595
+ readonly type: "uint48";
596
+ }, {
597
+ readonly indexed: false;
598
+ readonly name: "hook";
599
+ readonly type: "address";
600
+ }];
601
+ readonly anonymous: false;
602
+ }];
603
+ export type Erc8183Variant = "circle" | "acp" | "ref";
391
604
  export interface WriteClient {
392
605
  writeContract(args: {
393
606
  address: `0x${string}`;
@@ -455,6 +668,7 @@ export declare function createErc8183(cfg: Erc8183Config): {
455
668
  expiredAt: bigint;
456
669
  description: string;
457
670
  hook?: `0x${string}`;
671
+ providerAgentId?: bigint;
458
672
  }): Promise<{
459
673
  jobId: bigint;
460
674
  txHash: Hex;
@@ -256,6 +256,136 @@ export const ERC8183_ACP_ABI = [
256
256
  anonymous: false,
257
257
  },
258
258
  ];
259
+ export const ERC8183_REF_ABI = [
260
+ {
261
+ type: "function",
262
+ name: "createJob",
263
+ stateMutability: "nonpayable",
264
+ inputs: [
265
+ { name: "provider", type: "address" },
266
+ { name: "evaluator", type: "address" },
267
+ { name: "expiredAt", type: "uint48" },
268
+ { name: "description", type: "string" },
269
+ { name: "hook", type: "address" },
270
+ { name: "providerAgentId", type: "uint256" },
271
+ ],
272
+ outputs: [{ name: "jobId", type: "uint256" }],
273
+ },
274
+ {
275
+ type: "function",
276
+ name: "setProvider",
277
+ stateMutability: "nonpayable",
278
+ inputs: [
279
+ { name: "jobId", type: "uint256" },
280
+ { name: "provider", type: "address" },
281
+ { name: "agentId", type: "uint256" },
282
+ ],
283
+ outputs: [],
284
+ },
285
+ {
286
+ type: "function",
287
+ name: "setBudget",
288
+ stateMutability: "nonpayable",
289
+ inputs: [
290
+ { name: "jobId", type: "uint256" },
291
+ { name: "token", type: "address" },
292
+ { name: "amount", type: "uint256" },
293
+ { name: "optParams", type: "bytes" },
294
+ ],
295
+ outputs: [],
296
+ },
297
+ {
298
+ type: "function",
299
+ name: "fund",
300
+ stateMutability: "nonpayable",
301
+ inputs: [
302
+ { name: "jobId", type: "uint256" },
303
+ { name: "expectedToken", type: "address" },
304
+ { name: "expectedBudget", type: "uint256" },
305
+ { name: "optParams", type: "bytes" },
306
+ ],
307
+ outputs: [],
308
+ },
309
+ {
310
+ type: "function",
311
+ name: "submit",
312
+ stateMutability: "nonpayable",
313
+ inputs: [
314
+ { name: "jobId", type: "uint256" },
315
+ { name: "deliverable", type: "bytes32" },
316
+ { name: "optParams", type: "bytes" },
317
+ ],
318
+ outputs: [],
319
+ },
320
+ {
321
+ type: "function",
322
+ name: "complete",
323
+ stateMutability: "nonpayable",
324
+ inputs: [
325
+ { name: "jobId", type: "uint256" },
326
+ { name: "reason", type: "bytes32" },
327
+ { name: "optParams", type: "bytes" },
328
+ ],
329
+ outputs: [],
330
+ },
331
+ {
332
+ type: "function",
333
+ name: "reject",
334
+ stateMutability: "nonpayable",
335
+ inputs: [
336
+ { name: "jobId", type: "uint256" },
337
+ { name: "reason", type: "bytes32" },
338
+ { name: "optParams", type: "bytes" },
339
+ ],
340
+ outputs: [],
341
+ },
342
+ {
343
+ type: "function",
344
+ name: "claimRefund",
345
+ stateMutability: "nonpayable",
346
+ inputs: [{ name: "jobId", type: "uint256" }],
347
+ outputs: [],
348
+ },
349
+ {
350
+ type: "function",
351
+ name: "getJob",
352
+ stateMutability: "view",
353
+ inputs: [{ name: "jobId", type: "uint256" }],
354
+ outputs: [
355
+ {
356
+ type: "tuple",
357
+ components: [
358
+ { name: "client", type: "address" },
359
+ { name: "status", type: "uint8" },
360
+ { name: "provider", type: "address" },
361
+ { name: "expiredAt", type: "uint48" },
362
+ { name: "evaluator", type: "address" },
363
+ { name: "submittedAt", type: "uint48" },
364
+ { name: "budget", type: "uint256" },
365
+ { name: "hook", type: "address" },
366
+ { name: "paymentToken", type: "address" },
367
+ { name: "providerAgentId", type: "uint256" },
368
+ { name: "description", type: "string" },
369
+ { name: "settledAmount", type: "uint256" },
370
+ { name: "payoutReceiver", type: "address" },
371
+ ],
372
+ },
373
+ ],
374
+ },
375
+ {
376
+ type: "event",
377
+ name: "JobCreated",
378
+ inputs: [
379
+ { indexed: true, name: "jobId", type: "uint256" },
380
+ { indexed: true, name: "client", type: "address" },
381
+ { indexed: true, name: "provider", type: "address" },
382
+ { indexed: false, name: "evaluator", type: "address" },
383
+ { indexed: false, name: "expiredAt", type: "uint48" },
384
+ { indexed: false, name: "hook", type: "address" },
385
+ ],
386
+ anonymous: false,
387
+ },
388
+ ];
259
389
  const ERC20_APPROVE_ABI = parseAbi([
260
390
  "function approve(address spender, uint256 amount) returns (bool)",
261
391
  ]);
@@ -278,7 +408,7 @@ export class Erc8183Error extends Error {
278
408
  const EMPTY_PARAMS = "0x";
279
409
  function extractJobId(receipt) {
280
410
  for (const log of receipt.logs) {
281
- for (const abi of [ERC8183_ABI, ERC8183_ACP_ABI]) {
411
+ for (const abi of [ERC8183_ABI, ERC8183_ACP_ABI, ERC8183_REF_ABI]) {
282
412
  try {
283
413
  const decoded = decodeEventLog({
284
414
  abi,
@@ -299,22 +429,36 @@ function extractJobId(receipt) {
299
429
  export function createErc8183(cfg) {
300
430
  const contract = cfg.contract ?? AGENTIC_COMMERCE_ARC_TESTNET;
301
431
  const variant = cfg.variant ?? "circle";
302
- const abi = variant === "acp" ? ERC8183_ACP_ABI : ERC8183_ABI;
432
+ const abi = variant === "acp"
433
+ ? ERC8183_ACP_ABI
434
+ : variant === "ref"
435
+ ? ERC8183_REF_ABI
436
+ : ERC8183_ABI;
303
437
  return {
304
438
  contract,
305
439
  async createJob(wallet, args) {
306
440
  try {
307
- const txHash = await wallet.writeContract({
308
- address: contract,
309
- abi,
310
- functionName: "createJob",
311
- args: [
441
+ const createArgs = variant === "ref"
442
+ ? [
312
443
  args.provider,
313
444
  args.evaluator,
314
445
  args.expiredAt,
315
446
  args.description,
316
447
  args.hook ?? ZERO_HOOK,
317
- ],
448
+ args.providerAgentId ?? 0n,
449
+ ]
450
+ : [
451
+ args.provider,
452
+ args.evaluator,
453
+ args.expiredAt,
454
+ args.description,
455
+ args.hook ?? ZERO_HOOK,
456
+ ];
457
+ const txHash = await wallet.writeContract({
458
+ address: contract,
459
+ abi,
460
+ functionName: "createJob",
461
+ args: createArgs,
318
462
  });
319
463
  const receipt = await awaitReceipt(cfg.read, txHash);
320
464
  return { jobId: extractJobId(receipt), txHash };
@@ -327,11 +471,14 @@ export function createErc8183(cfg) {
327
471
  },
328
472
  async setBudget(wallet, args) {
329
473
  try {
474
+ const args2 = variant === "ref"
475
+ ? [args.jobId, cfg.usdc, args.amount, args.optParams ?? EMPTY_PARAMS]
476
+ : [args.jobId, args.amount, args.optParams ?? EMPTY_PARAMS];
330
477
  return await wallet.writeContract({
331
478
  address: contract,
332
479
  abi,
333
480
  functionName: "setBudget",
334
- args: [args.jobId, args.amount, args.optParams ?? EMPTY_PARAMS],
481
+ args: args2,
335
482
  });
336
483
  }
337
484
  catch (e) {
@@ -347,9 +494,11 @@ export function createErc8183(cfg) {
347
494
  args: [contract, args.amount],
348
495
  });
349
496
  await awaitReceipt(cfg.read, approveTx);
350
- const fundArgs = variant === "acp"
351
- ? [args.jobId, args.amount, args.optParams ?? EMPTY_PARAMS]
352
- : [args.jobId, args.optParams ?? EMPTY_PARAMS];
497
+ const fundArgs = variant === "ref"
498
+ ? [args.jobId, cfg.usdc, args.amount, args.optParams ?? EMPTY_PARAMS]
499
+ : variant === "acp"
500
+ ? [args.jobId, args.amount, args.optParams ?? EMPTY_PARAMS]
501
+ : [args.jobId, args.optParams ?? EMPTY_PARAMS];
353
502
  const fundTx = await wallet.writeContract({
354
503
  address: contract,
355
504
  abi,
@@ -420,6 +569,26 @@ export function createErc8183(cfg) {
420
569
  },
421
570
  async getJob(jobId) {
422
571
  try {
572
+ if (variant === "ref") {
573
+ const raw = (await cfg.read.readContract({
574
+ address: contract,
575
+ abi,
576
+ functionName: "getJob",
577
+ args: [jobId],
578
+ }));
579
+ return {
580
+ id: jobId,
581
+ client: raw.client,
582
+ provider: raw.provider,
583
+ evaluator: raw.evaluator,
584
+ description: raw.description,
585
+ budget: raw.budget,
586
+ expiredAt: raw.expiredAt,
587
+ status: JOB_STATUS[raw.status] ?? "Open",
588
+ hook: raw.hook,
589
+ token: raw.paymentToken,
590
+ };
591
+ }
423
592
  if (variant === "acp") {
424
593
  const raw = (await cfg.read.readContract({
425
594
  address: contract,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentbadge/circle-payments",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "Circle Gateway nanopayments + x402 payment rails (Base Sepolia, Arc) for AgentBadge — trusted agent payments",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",