@agentxpay/sdk 0.1.0

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.
@@ -0,0 +1,567 @@
1
+ [
2
+ {
3
+ "type": "constructor",
4
+ "inputs": [
5
+ {
6
+ "name": "_serviceRegistry",
7
+ "type": "address",
8
+ "internalType": "address"
9
+ }
10
+ ],
11
+ "stateMutability": "nonpayable"
12
+ },
13
+ {
14
+ "type": "function",
15
+ "name": "cancelSubscription",
16
+ "inputs": [
17
+ {
18
+ "name": "subscriptionId",
19
+ "type": "uint256",
20
+ "internalType": "uint256"
21
+ }
22
+ ],
23
+ "outputs": [],
24
+ "stateMutability": "nonpayable"
25
+ },
26
+ {
27
+ "type": "function",
28
+ "name": "checkAccess",
29
+ "inputs": [
30
+ {
31
+ "name": "user",
32
+ "type": "address",
33
+ "internalType": "address"
34
+ },
35
+ {
36
+ "name": "serviceId",
37
+ "type": "uint256",
38
+ "internalType": "uint256"
39
+ }
40
+ ],
41
+ "outputs": [
42
+ {
43
+ "name": "",
44
+ "type": "bool",
45
+ "internalType": "bool"
46
+ }
47
+ ],
48
+ "stateMutability": "view"
49
+ },
50
+ {
51
+ "type": "function",
52
+ "name": "getSubscription",
53
+ "inputs": [
54
+ {
55
+ "name": "subscriptionId",
56
+ "type": "uint256",
57
+ "internalType": "uint256"
58
+ }
59
+ ],
60
+ "outputs": [
61
+ {
62
+ "name": "",
63
+ "type": "tuple",
64
+ "internalType": "struct ISubscriptionManager.Subscription",
65
+ "components": [
66
+ {
67
+ "name": "subscriptionId",
68
+ "type": "uint256",
69
+ "internalType": "uint256"
70
+ },
71
+ {
72
+ "name": "serviceId",
73
+ "type": "uint256",
74
+ "internalType": "uint256"
75
+ },
76
+ {
77
+ "name": "planId",
78
+ "type": "uint256",
79
+ "internalType": "uint256"
80
+ },
81
+ {
82
+ "name": "subscriber",
83
+ "type": "address",
84
+ "internalType": "address"
85
+ },
86
+ {
87
+ "name": "startTime",
88
+ "type": "uint256",
89
+ "internalType": "uint256"
90
+ },
91
+ {
92
+ "name": "endTime",
93
+ "type": "uint256",
94
+ "internalType": "uint256"
95
+ },
96
+ {
97
+ "name": "autoRenew",
98
+ "type": "bool",
99
+ "internalType": "bool"
100
+ },
101
+ {
102
+ "name": "isActive",
103
+ "type": "bool",
104
+ "internalType": "bool"
105
+ }
106
+ ]
107
+ }
108
+ ],
109
+ "stateMutability": "view"
110
+ },
111
+ {
112
+ "type": "function",
113
+ "name": "getUserSubscriptions",
114
+ "inputs": [
115
+ {
116
+ "name": "user",
117
+ "type": "address",
118
+ "internalType": "address"
119
+ }
120
+ ],
121
+ "outputs": [
122
+ {
123
+ "name": "",
124
+ "type": "uint256[]",
125
+ "internalType": "uint256[]"
126
+ }
127
+ ],
128
+ "stateMutability": "view"
129
+ },
130
+ {
131
+ "type": "function",
132
+ "name": "isSubscriptionActive",
133
+ "inputs": [
134
+ {
135
+ "name": "subscriptionId",
136
+ "type": "uint256",
137
+ "internalType": "uint256"
138
+ }
139
+ ],
140
+ "outputs": [
141
+ {
142
+ "name": "",
143
+ "type": "bool",
144
+ "internalType": "bool"
145
+ }
146
+ ],
147
+ "stateMutability": "view"
148
+ },
149
+ {
150
+ "type": "function",
151
+ "name": "owner",
152
+ "inputs": [],
153
+ "outputs": [
154
+ {
155
+ "name": "",
156
+ "type": "address",
157
+ "internalType": "address"
158
+ }
159
+ ],
160
+ "stateMutability": "view"
161
+ },
162
+ {
163
+ "type": "function",
164
+ "name": "pause",
165
+ "inputs": [],
166
+ "outputs": [],
167
+ "stateMutability": "nonpayable"
168
+ },
169
+ {
170
+ "type": "function",
171
+ "name": "paused",
172
+ "inputs": [],
173
+ "outputs": [
174
+ {
175
+ "name": "",
176
+ "type": "bool",
177
+ "internalType": "bool"
178
+ }
179
+ ],
180
+ "stateMutability": "view"
181
+ },
182
+ {
183
+ "type": "function",
184
+ "name": "renewSubscription",
185
+ "inputs": [
186
+ {
187
+ "name": "subscriptionId",
188
+ "type": "uint256",
189
+ "internalType": "uint256"
190
+ }
191
+ ],
192
+ "outputs": [],
193
+ "stateMutability": "payable"
194
+ },
195
+ {
196
+ "type": "function",
197
+ "name": "renounceOwnership",
198
+ "inputs": [],
199
+ "outputs": [],
200
+ "stateMutability": "nonpayable"
201
+ },
202
+ {
203
+ "type": "function",
204
+ "name": "serviceRegistry",
205
+ "inputs": [],
206
+ "outputs": [
207
+ {
208
+ "name": "",
209
+ "type": "address",
210
+ "internalType": "contract IServiceRegistry"
211
+ }
212
+ ],
213
+ "stateMutability": "view"
214
+ },
215
+ {
216
+ "type": "function",
217
+ "name": "subscribe",
218
+ "inputs": [
219
+ {
220
+ "name": "serviceId",
221
+ "type": "uint256",
222
+ "internalType": "uint256"
223
+ },
224
+ {
225
+ "name": "planId",
226
+ "type": "uint256",
227
+ "internalType": "uint256"
228
+ }
229
+ ],
230
+ "outputs": [
231
+ {
232
+ "name": "subscriptionId",
233
+ "type": "uint256",
234
+ "internalType": "uint256"
235
+ }
236
+ ],
237
+ "stateMutability": "payable"
238
+ },
239
+ {
240
+ "type": "function",
241
+ "name": "toggleAutoRenew",
242
+ "inputs": [
243
+ {
244
+ "name": "subscriptionId",
245
+ "type": "uint256",
246
+ "internalType": "uint256"
247
+ }
248
+ ],
249
+ "outputs": [],
250
+ "stateMutability": "nonpayable"
251
+ },
252
+ {
253
+ "type": "function",
254
+ "name": "transferOwnership",
255
+ "inputs": [
256
+ {
257
+ "name": "newOwner",
258
+ "type": "address",
259
+ "internalType": "address"
260
+ }
261
+ ],
262
+ "outputs": [],
263
+ "stateMutability": "nonpayable"
264
+ },
265
+ {
266
+ "type": "function",
267
+ "name": "unpause",
268
+ "inputs": [],
269
+ "outputs": [],
270
+ "stateMutability": "nonpayable"
271
+ },
272
+ {
273
+ "type": "event",
274
+ "name": "AutoRenewToggled",
275
+ "inputs": [
276
+ {
277
+ "name": "subscriptionId",
278
+ "type": "uint256",
279
+ "indexed": true,
280
+ "internalType": "uint256"
281
+ },
282
+ {
283
+ "name": "autoRenew",
284
+ "type": "bool",
285
+ "indexed": false,
286
+ "internalType": "bool"
287
+ }
288
+ ],
289
+ "anonymous": false
290
+ },
291
+ {
292
+ "type": "event",
293
+ "name": "OwnershipTransferred",
294
+ "inputs": [
295
+ {
296
+ "name": "previousOwner",
297
+ "type": "address",
298
+ "indexed": true,
299
+ "internalType": "address"
300
+ },
301
+ {
302
+ "name": "newOwner",
303
+ "type": "address",
304
+ "indexed": true,
305
+ "internalType": "address"
306
+ }
307
+ ],
308
+ "anonymous": false
309
+ },
310
+ {
311
+ "type": "event",
312
+ "name": "Paused",
313
+ "inputs": [
314
+ {
315
+ "name": "account",
316
+ "type": "address",
317
+ "indexed": false,
318
+ "internalType": "address"
319
+ }
320
+ ],
321
+ "anonymous": false
322
+ },
323
+ {
324
+ "type": "event",
325
+ "name": "Subscribed",
326
+ "inputs": [
327
+ {
328
+ "name": "subscriptionId",
329
+ "type": "uint256",
330
+ "indexed": true,
331
+ "internalType": "uint256"
332
+ },
333
+ {
334
+ "name": "serviceId",
335
+ "type": "uint256",
336
+ "indexed": true,
337
+ "internalType": "uint256"
338
+ },
339
+ {
340
+ "name": "planId",
341
+ "type": "uint256",
342
+ "indexed": true,
343
+ "internalType": "uint256"
344
+ },
345
+ {
346
+ "name": "subscriber",
347
+ "type": "address",
348
+ "indexed": false,
349
+ "internalType": "address"
350
+ },
351
+ {
352
+ "name": "startTime",
353
+ "type": "uint256",
354
+ "indexed": false,
355
+ "internalType": "uint256"
356
+ },
357
+ {
358
+ "name": "endTime",
359
+ "type": "uint256",
360
+ "indexed": false,
361
+ "internalType": "uint256"
362
+ }
363
+ ],
364
+ "anonymous": false
365
+ },
366
+ {
367
+ "type": "event",
368
+ "name": "SubscriptionCancelled",
369
+ "inputs": [
370
+ {
371
+ "name": "subscriptionId",
372
+ "type": "uint256",
373
+ "indexed": true,
374
+ "internalType": "uint256"
375
+ }
376
+ ],
377
+ "anonymous": false
378
+ },
379
+ {
380
+ "type": "event",
381
+ "name": "SubscriptionRenewed",
382
+ "inputs": [
383
+ {
384
+ "name": "subscriptionId",
385
+ "type": "uint256",
386
+ "indexed": true,
387
+ "internalType": "uint256"
388
+ },
389
+ {
390
+ "name": "newEndTime",
391
+ "type": "uint256",
392
+ "indexed": false,
393
+ "internalType": "uint256"
394
+ }
395
+ ],
396
+ "anonymous": false
397
+ },
398
+ {
399
+ "type": "event",
400
+ "name": "Unpaused",
401
+ "inputs": [
402
+ {
403
+ "name": "account",
404
+ "type": "address",
405
+ "indexed": false,
406
+ "internalType": "address"
407
+ }
408
+ ],
409
+ "anonymous": false
410
+ },
411
+ {
412
+ "type": "error",
413
+ "name": "AlreadySubscribed",
414
+ "inputs": [
415
+ {
416
+ "name": "user",
417
+ "type": "address",
418
+ "internalType": "address"
419
+ },
420
+ {
421
+ "name": "serviceId",
422
+ "type": "uint256",
423
+ "internalType": "uint256"
424
+ }
425
+ ]
426
+ },
427
+ {
428
+ "type": "error",
429
+ "name": "EnforcedPause",
430
+ "inputs": []
431
+ },
432
+ {
433
+ "type": "error",
434
+ "name": "ExpectedPause",
435
+ "inputs": []
436
+ },
437
+ {
438
+ "type": "error",
439
+ "name": "InsufficientPayment",
440
+ "inputs": [
441
+ {
442
+ "name": "required",
443
+ "type": "uint256",
444
+ "internalType": "uint256"
445
+ },
446
+ {
447
+ "name": "provided",
448
+ "type": "uint256",
449
+ "internalType": "uint256"
450
+ }
451
+ ]
452
+ },
453
+ {
454
+ "type": "error",
455
+ "name": "InvalidFeeRate",
456
+ "inputs": [
457
+ {
458
+ "name": "feeRate",
459
+ "type": "uint256",
460
+ "internalType": "uint256"
461
+ }
462
+ ]
463
+ },
464
+ {
465
+ "type": "error",
466
+ "name": "NotSubscriber",
467
+ "inputs": [
468
+ {
469
+ "name": "subscriptionId",
470
+ "type": "uint256",
471
+ "internalType": "uint256"
472
+ }
473
+ ]
474
+ },
475
+ {
476
+ "type": "error",
477
+ "name": "OwnableInvalidOwner",
478
+ "inputs": [
479
+ {
480
+ "name": "owner",
481
+ "type": "address",
482
+ "internalType": "address"
483
+ }
484
+ ]
485
+ },
486
+ {
487
+ "type": "error",
488
+ "name": "OwnableUnauthorizedAccount",
489
+ "inputs": [
490
+ {
491
+ "name": "account",
492
+ "type": "address",
493
+ "internalType": "address"
494
+ }
495
+ ]
496
+ },
497
+ {
498
+ "type": "error",
499
+ "name": "ReentrancyGuardReentrantCall",
500
+ "inputs": []
501
+ },
502
+ {
503
+ "type": "error",
504
+ "name": "ServiceNotActive",
505
+ "inputs": [
506
+ {
507
+ "name": "serviceId",
508
+ "type": "uint256",
509
+ "internalType": "uint256"
510
+ }
511
+ ]
512
+ },
513
+ {
514
+ "type": "error",
515
+ "name": "SubscriptionNotActive",
516
+ "inputs": [
517
+ {
518
+ "name": "subscriptionId",
519
+ "type": "uint256",
520
+ "internalType": "uint256"
521
+ }
522
+ ]
523
+ },
524
+ {
525
+ "type": "error",
526
+ "name": "SubscriptionNotFound",
527
+ "inputs": [
528
+ {
529
+ "name": "subscriptionId",
530
+ "type": "uint256",
531
+ "internalType": "uint256"
532
+ }
533
+ ]
534
+ },
535
+ {
536
+ "type": "error",
537
+ "name": "SubscriptionStillActive",
538
+ "inputs": [
539
+ {
540
+ "name": "subscriptionId",
541
+ "type": "uint256",
542
+ "internalType": "uint256"
543
+ }
544
+ ]
545
+ },
546
+ {
547
+ "type": "error",
548
+ "name": "TransferFailed",
549
+ "inputs": [
550
+ {
551
+ "name": "to",
552
+ "type": "address",
553
+ "internalType": "address"
554
+ },
555
+ {
556
+ "name": "amount",
557
+ "type": "uint256",
558
+ "internalType": "uint256"
559
+ }
560
+ ]
561
+ },
562
+ {
563
+ "type": "error",
564
+ "name": "ZeroAmount",
565
+ "inputs": []
566
+ }
567
+ ]
package/src/index.ts ADDED
@@ -0,0 +1,34 @@
1
+ export { AgentXPayClient } from "./AgentXPayClient";
2
+ export { ServicesModule } from "./modules/services";
3
+ export { PaymentsModule } from "./modules/payments";
4
+ export { SubscriptionsModule } from "./modules/subscriptions";
5
+ export { EscrowModule } from "./modules/escrow";
6
+ export { WalletModule, AgentWalletClient } from "./modules/wallet";
7
+
8
+ export type {
9
+ AgentXPayConfig,
10
+ ContractAddresses,
11
+ Service,
12
+ SubscriptionPlan,
13
+ Subscription,
14
+ EscrowData,
15
+ DiscoverFilter,
16
+ PaymentResult,
17
+ X402PaymentInfo,
18
+ X402FetchOptions,
19
+ } from "./types";
20
+
21
+ export { EscrowStatus } from "./types";
22
+
23
+ export {
24
+ MONAD_TESTNET_CHAIN_ID,
25
+ MONAD_TESTNET_RPC,
26
+ DEFAULT_CONTRACTS,
27
+ } from "./utils/constants";
28
+
29
+ export {
30
+ shortenAddress,
31
+ formatEther,
32
+ parseEther,
33
+ isValidAddress,
34
+ } from "./utils/helpers";
@@ -0,0 +1,75 @@
1
+ import { ethers } from "ethers";
2
+ import EscrowABI from "../abi/Escrow.json";
3
+ import { EscrowData, EscrowStatus } from "../types";
4
+
5
+ export class EscrowModule {
6
+ private contract: ethers.Contract | null = null;
7
+
8
+ constructor(address: string, signerOrProvider: ethers.Signer | ethers.Provider) {
9
+ if (address && address !== "") {
10
+ this.contract = new ethers.Contract(address, EscrowABI, signerOrProvider);
11
+ }
12
+ }
13
+
14
+ private getContract(): ethers.Contract {
15
+ if (!this.contract) {
16
+ throw new Error("Escrow contract address not configured");
17
+ }
18
+ return this.contract;
19
+ }
20
+
21
+ async createEscrow(
22
+ serviceId: bigint,
23
+ provider: string,
24
+ deadline: bigint,
25
+ description: string,
26
+ amount: bigint
27
+ ): Promise<{ txHash: string; escrowId: bigint }> {
28
+ const contract = this.getContract();
29
+ const tx = await contract.createEscrow(serviceId, provider, deadline, description, { value: amount });
30
+ const receipt = await tx.wait();
31
+ return { txHash: receipt.hash, escrowId: 0n };
32
+ }
33
+
34
+ async releaseEscrow(escrowId: bigint): Promise<string> {
35
+ const contract = this.getContract();
36
+ const tx = await contract.releaseEscrow(escrowId);
37
+ const receipt = await tx.wait();
38
+ return receipt.hash;
39
+ }
40
+
41
+ async disputeEscrow(escrowId: bigint): Promise<string> {
42
+ const contract = this.getContract();
43
+ const tx = await contract.disputeEscrow(escrowId);
44
+ const receipt = await tx.wait();
45
+ return receipt.hash;
46
+ }
47
+
48
+ async refundEscrow(escrowId: bigint): Promise<string> {
49
+ const contract = this.getContract();
50
+ const tx = await contract.refundEscrow(escrowId);
51
+ const receipt = await tx.wait();
52
+ return receipt.hash;
53
+ }
54
+
55
+ async getEscrow(escrowId: bigint): Promise<EscrowData> {
56
+ const contract = this.getContract();
57
+ const e = await contract.getEscrow(escrowId);
58
+ return {
59
+ escrowId: e.escrowId,
60
+ serviceId: e.serviceId,
61
+ payer: e.payer,
62
+ provider: e.provider,
63
+ amount: e.amount,
64
+ status: Number(e.status) as EscrowStatus,
65
+ createdAt: e.createdAt,
66
+ deadline: e.deadline,
67
+ description: e.description,
68
+ };
69
+ }
70
+
71
+ async getUserEscrows(address: string): Promise<bigint[]> {
72
+ const contract = this.getContract();
73
+ return contract.getUserEscrows(address);
74
+ }
75
+ }