@agentbadge/circle-payments 0.1.25 → 0.1.27

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.
@@ -256,136 +256,6 @@ 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
- ];
389
259
  const ERC20_APPROVE_ABI = parseAbi([
390
260
  "function approve(address spender, uint256 amount) returns (bool)",
391
261
  ]);
@@ -408,7 +278,7 @@ export class Erc8183Error extends Error {
408
278
  const EMPTY_PARAMS = "0x";
409
279
  function extractJobId(receipt) {
410
280
  for (const log of receipt.logs) {
411
- for (const abi of [ERC8183_ABI, ERC8183_ACP_ABI, ERC8183_REF_ABI]) {
281
+ for (const abi of [ERC8183_ABI, ERC8183_ACP_ABI]) {
412
282
  try {
413
283
  const decoded = decodeEventLog({
414
284
  abi,
@@ -429,36 +299,22 @@ function extractJobId(receipt) {
429
299
  export function createErc8183(cfg) {
430
300
  const contract = cfg.contract ?? AGENTIC_COMMERCE_ARC_TESTNET;
431
301
  const variant = cfg.variant ?? "circle";
432
- const abi = variant === "acp"
433
- ? ERC8183_ACP_ABI
434
- : variant === "ref"
435
- ? ERC8183_REF_ABI
436
- : ERC8183_ABI;
302
+ const abi = variant === "acp" ? ERC8183_ACP_ABI : ERC8183_ABI;
437
303
  return {
438
304
  contract,
439
305
  async createJob(wallet, args) {
440
306
  try {
441
- const createArgs = variant === "ref"
442
- ? [
443
- args.provider,
444
- args.evaluator,
445
- args.expiredAt,
446
- args.description,
447
- args.hook ?? ZERO_HOOK,
448
- args.providerAgentId ?? 0n,
449
- ]
450
- : [
307
+ const txHash = await wallet.writeContract({
308
+ address: contract,
309
+ abi,
310
+ functionName: "createJob",
311
+ args: [
451
312
  args.provider,
452
313
  args.evaluator,
453
314
  args.expiredAt,
454
315
  args.description,
455
316
  args.hook ?? ZERO_HOOK,
456
- ];
457
- const txHash = await wallet.writeContract({
458
- address: contract,
459
- abi,
460
- functionName: "createJob",
461
- args: createArgs,
317
+ ],
462
318
  });
463
319
  const receipt = await awaitReceipt(cfg.read, txHash);
464
320
  return { jobId: extractJobId(receipt), txHash };
@@ -471,14 +327,11 @@ export function createErc8183(cfg) {
471
327
  },
472
328
  async setBudget(wallet, args) {
473
329
  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];
477
330
  return await wallet.writeContract({
478
331
  address: contract,
479
332
  abi,
480
333
  functionName: "setBudget",
481
- args: args2,
334
+ args: [args.jobId, args.amount, args.optParams ?? EMPTY_PARAMS],
482
335
  });
483
336
  }
484
337
  catch (e) {
@@ -494,11 +347,9 @@ export function createErc8183(cfg) {
494
347
  args: [contract, args.amount],
495
348
  });
496
349
  await awaitReceipt(cfg.read, approveTx);
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];
350
+ const fundArgs = variant === "acp"
351
+ ? [args.jobId, args.amount, args.optParams ?? EMPTY_PARAMS]
352
+ : [args.jobId, args.optParams ?? EMPTY_PARAMS];
502
353
  const fundTx = await wallet.writeContract({
503
354
  address: contract,
504
355
  abi,
@@ -569,26 +420,6 @@ export function createErc8183(cfg) {
569
420
  },
570
421
  async getJob(jobId) {
571
422
  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
- }
592
423
  if (variant === "acp") {
593
424
  const raw = (await cfg.read.readContract({
594
425
  address: contract,
@@ -10,15 +10,6 @@ export interface DepositWalletClient {
10
10
  functionName: string;
11
11
  args: readonly unknown[];
12
12
  }): Promise<`0x${string}`>;
13
- readContract?(args: {
14
- address: `0x${string}`;
15
- abi: unknown;
16
- functionName: string;
17
- args: readonly unknown[];
18
- }): Promise<unknown>;
19
- waitForTransactionReceipt?(args: {
20
- hash: `0x${string}`;
21
- }): Promise<unknown>;
22
13
  }
23
14
  export interface DepositResult {
24
15
  txHash: `0x${string}`;
@@ -50,45 +50,18 @@ export async function depositToGateway(args) {
50
50
  if (amount <= 0n) {
51
51
  throw new Error(`deposit amount must be > 0 (got ${args.amountUsd})`);
52
52
  }
53
- const depositor = typeof wallet.account === "string"
54
- ? wallet.account
55
- : wallet.account?.address;
56
- let needsApproval = true;
57
- if (wallet.readContract && depositor) {
58
- try {
59
- const allowance = (await wallet.readContract({
60
- address: chain.usdc,
61
- abi: erc20Abi,
62
- functionName: "allowance",
63
- args: [depositor, chain.gatewayWallet],
64
- }));
65
- needsApproval = allowance < amount;
66
- }
67
- catch {
68
- needsApproval = true;
69
- }
70
- }
71
- let approvalTxHash;
72
- if (needsApproval) {
73
- approvalTxHash = await wallet.writeContract({
74
- address: chain.usdc,
75
- abi: erc20Abi,
76
- functionName: "approve",
77
- args: [chain.gatewayWallet, amount],
78
- });
79
- if (wallet.waitForTransactionReceipt) {
80
- await wallet.waitForTransactionReceipt({ hash: approvalTxHash });
81
- }
82
- }
53
+ const approvalTxHash = await wallet.writeContract({
54
+ address: chain.usdc,
55
+ abi: erc20Abi,
56
+ functionName: "approve",
57
+ args: [chain.gatewayWallet, amount],
58
+ });
83
59
  const txHash = await wallet.writeContract({
84
60
  address: chain.gatewayWallet,
85
61
  abi: GATEWAY_WALLET_ABI,
86
62
  functionName: "deposit",
87
63
  args: [chain.usdc, amount],
88
64
  });
89
- if (wallet.waitForTransactionReceipt) {
90
- await wallet.waitForTransactionReceipt({ hash: txHash });
91
- }
92
65
  const eta = new Date(Date.now() + estimateFor(chain) * 1000);
93
66
  return {
94
67
  txHash,
package/dist/index.d.ts CHANGED
@@ -30,8 +30,6 @@ export * from "./buyer/caps.js";
30
30
  export * from "./buyer/session.js";
31
31
  export * from "./buyer/accepts.js";
32
32
  export * from "./buyer/client.js";
33
- export * from "./buyer/guard.js";
34
- export * from "./buyer/risk-guard.js";
35
33
  export * from "./buyer/paginate.js";
36
34
  export * from "./buyer/counterparty.js";
37
35
  export * from "./counterparty/index.js";
package/dist/index.js CHANGED
@@ -30,8 +30,6 @@ export * from "./buyer/caps.js";
30
30
  export * from "./buyer/session.js";
31
31
  export * from "./buyer/accepts.js";
32
32
  export * from "./buyer/client.js";
33
- export * from "./buyer/guard.js";
34
- export * from "./buyer/risk-guard.js";
35
33
  export * from "./buyer/paginate.js";
36
34
  export * from "./buyer/counterparty.js";
37
35
  export * from "./counterparty/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentbadge/circle-payments",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
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",