@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.
package/dist/index.js ADDED
@@ -0,0 +1,3382 @@
1
+ 'use strict';
2
+
3
+ var ethers = require('ethers');
4
+
5
+ // src/AgentXPayClient.ts
6
+
7
+ // src/abi/ServiceRegistry.json
8
+ var ServiceRegistry_default = [
9
+ {
10
+ type: "constructor",
11
+ inputs: [],
12
+ stateMutability: "nonpayable"
13
+ },
14
+ {
15
+ type: "function",
16
+ name: "activateService",
17
+ inputs: [
18
+ {
19
+ name: "serviceId",
20
+ type: "uint256",
21
+ internalType: "uint256"
22
+ }
23
+ ],
24
+ outputs: [],
25
+ stateMutability: "nonpayable"
26
+ },
27
+ {
28
+ type: "function",
29
+ name: "addSubscriptionPlan",
30
+ inputs: [
31
+ {
32
+ name: "serviceId",
33
+ type: "uint256",
34
+ internalType: "uint256"
35
+ },
36
+ {
37
+ name: "name",
38
+ type: "string",
39
+ internalType: "string"
40
+ },
41
+ {
42
+ name: "price",
43
+ type: "uint256",
44
+ internalType: "uint256"
45
+ },
46
+ {
47
+ name: "duration",
48
+ type: "uint256",
49
+ internalType: "uint256"
50
+ }
51
+ ],
52
+ outputs: [
53
+ {
54
+ name: "planId",
55
+ type: "uint256",
56
+ internalType: "uint256"
57
+ }
58
+ ],
59
+ stateMutability: "nonpayable"
60
+ },
61
+ {
62
+ type: "function",
63
+ name: "deactivateService",
64
+ inputs: [
65
+ {
66
+ name: "serviceId",
67
+ type: "uint256",
68
+ internalType: "uint256"
69
+ }
70
+ ],
71
+ outputs: [],
72
+ stateMutability: "nonpayable"
73
+ },
74
+ {
75
+ type: "function",
76
+ name: "getServiceCount",
77
+ inputs: [],
78
+ outputs: [
79
+ {
80
+ name: "",
81
+ type: "uint256",
82
+ internalType: "uint256"
83
+ }
84
+ ],
85
+ stateMutability: "view"
86
+ },
87
+ {
88
+ type: "function",
89
+ name: "getServiceDetails",
90
+ inputs: [
91
+ {
92
+ name: "serviceId",
93
+ type: "uint256",
94
+ internalType: "uint256"
95
+ }
96
+ ],
97
+ outputs: [
98
+ {
99
+ name: "",
100
+ type: "tuple",
101
+ internalType: "struct IServiceRegistry.Service",
102
+ components: [
103
+ {
104
+ name: "id",
105
+ type: "uint256",
106
+ internalType: "uint256"
107
+ },
108
+ {
109
+ name: "provider",
110
+ type: "address",
111
+ internalType: "address"
112
+ },
113
+ {
114
+ name: "name",
115
+ type: "string",
116
+ internalType: "string"
117
+ },
118
+ {
119
+ name: "description",
120
+ type: "string",
121
+ internalType: "string"
122
+ },
123
+ {
124
+ name: "endpoint",
125
+ type: "string",
126
+ internalType: "string"
127
+ },
128
+ {
129
+ name: "category",
130
+ type: "string",
131
+ internalType: "string"
132
+ },
133
+ {
134
+ name: "pricePerCall",
135
+ type: "uint256",
136
+ internalType: "uint256"
137
+ },
138
+ {
139
+ name: "isActive",
140
+ type: "bool",
141
+ internalType: "bool"
142
+ },
143
+ {
144
+ name: "createdAt",
145
+ type: "uint256",
146
+ internalType: "uint256"
147
+ }
148
+ ]
149
+ }
150
+ ],
151
+ stateMutability: "view"
152
+ },
153
+ {
154
+ type: "function",
155
+ name: "getServicesByCategory",
156
+ inputs: [
157
+ {
158
+ name: "category",
159
+ type: "string",
160
+ internalType: "string"
161
+ }
162
+ ],
163
+ outputs: [
164
+ {
165
+ name: "",
166
+ type: "tuple[]",
167
+ internalType: "struct IServiceRegistry.Service[]",
168
+ components: [
169
+ {
170
+ name: "id",
171
+ type: "uint256",
172
+ internalType: "uint256"
173
+ },
174
+ {
175
+ name: "provider",
176
+ type: "address",
177
+ internalType: "address"
178
+ },
179
+ {
180
+ name: "name",
181
+ type: "string",
182
+ internalType: "string"
183
+ },
184
+ {
185
+ name: "description",
186
+ type: "string",
187
+ internalType: "string"
188
+ },
189
+ {
190
+ name: "endpoint",
191
+ type: "string",
192
+ internalType: "string"
193
+ },
194
+ {
195
+ name: "category",
196
+ type: "string",
197
+ internalType: "string"
198
+ },
199
+ {
200
+ name: "pricePerCall",
201
+ type: "uint256",
202
+ internalType: "uint256"
203
+ },
204
+ {
205
+ name: "isActive",
206
+ type: "bool",
207
+ internalType: "bool"
208
+ },
209
+ {
210
+ name: "createdAt",
211
+ type: "uint256",
212
+ internalType: "uint256"
213
+ }
214
+ ]
215
+ }
216
+ ],
217
+ stateMutability: "view"
218
+ },
219
+ {
220
+ type: "function",
221
+ name: "getServicesByProvider",
222
+ inputs: [
223
+ {
224
+ name: "provider",
225
+ type: "address",
226
+ internalType: "address"
227
+ }
228
+ ],
229
+ outputs: [
230
+ {
231
+ name: "",
232
+ type: "uint256[]",
233
+ internalType: "uint256[]"
234
+ }
235
+ ],
236
+ stateMutability: "view"
237
+ },
238
+ {
239
+ type: "function",
240
+ name: "getSubscriptionPlan",
241
+ inputs: [
242
+ {
243
+ name: "serviceId",
244
+ type: "uint256",
245
+ internalType: "uint256"
246
+ },
247
+ {
248
+ name: "planId",
249
+ type: "uint256",
250
+ internalType: "uint256"
251
+ }
252
+ ],
253
+ outputs: [
254
+ {
255
+ name: "",
256
+ type: "tuple",
257
+ internalType: "struct IServiceRegistry.SubscriptionPlan",
258
+ components: [
259
+ {
260
+ name: "planId",
261
+ type: "uint256",
262
+ internalType: "uint256"
263
+ },
264
+ {
265
+ name: "serviceId",
266
+ type: "uint256",
267
+ internalType: "uint256"
268
+ },
269
+ {
270
+ name: "price",
271
+ type: "uint256",
272
+ internalType: "uint256"
273
+ },
274
+ {
275
+ name: "duration",
276
+ type: "uint256",
277
+ internalType: "uint256"
278
+ },
279
+ {
280
+ name: "name",
281
+ type: "string",
282
+ internalType: "string"
283
+ }
284
+ ]
285
+ }
286
+ ],
287
+ stateMutability: "view"
288
+ },
289
+ {
290
+ type: "function",
291
+ name: "getSubscriptionPlans",
292
+ inputs: [
293
+ {
294
+ name: "serviceId",
295
+ type: "uint256",
296
+ internalType: "uint256"
297
+ }
298
+ ],
299
+ outputs: [
300
+ {
301
+ name: "",
302
+ type: "tuple[]",
303
+ internalType: "struct IServiceRegistry.SubscriptionPlan[]",
304
+ components: [
305
+ {
306
+ name: "planId",
307
+ type: "uint256",
308
+ internalType: "uint256"
309
+ },
310
+ {
311
+ name: "serviceId",
312
+ type: "uint256",
313
+ internalType: "uint256"
314
+ },
315
+ {
316
+ name: "price",
317
+ type: "uint256",
318
+ internalType: "uint256"
319
+ },
320
+ {
321
+ name: "duration",
322
+ type: "uint256",
323
+ internalType: "uint256"
324
+ },
325
+ {
326
+ name: "name",
327
+ type: "string",
328
+ internalType: "string"
329
+ }
330
+ ]
331
+ }
332
+ ],
333
+ stateMutability: "view"
334
+ },
335
+ {
336
+ type: "function",
337
+ name: "isServiceActive",
338
+ inputs: [
339
+ {
340
+ name: "serviceId",
341
+ type: "uint256",
342
+ internalType: "uint256"
343
+ }
344
+ ],
345
+ outputs: [
346
+ {
347
+ name: "",
348
+ type: "bool",
349
+ internalType: "bool"
350
+ }
351
+ ],
352
+ stateMutability: "view"
353
+ },
354
+ {
355
+ type: "function",
356
+ name: "owner",
357
+ inputs: [],
358
+ outputs: [
359
+ {
360
+ name: "",
361
+ type: "address",
362
+ internalType: "address"
363
+ }
364
+ ],
365
+ stateMutability: "view"
366
+ },
367
+ {
368
+ type: "function",
369
+ name: "pause",
370
+ inputs: [],
371
+ outputs: [],
372
+ stateMutability: "nonpayable"
373
+ },
374
+ {
375
+ type: "function",
376
+ name: "paused",
377
+ inputs: [],
378
+ outputs: [
379
+ {
380
+ name: "",
381
+ type: "bool",
382
+ internalType: "bool"
383
+ }
384
+ ],
385
+ stateMutability: "view"
386
+ },
387
+ {
388
+ type: "function",
389
+ name: "registerService",
390
+ inputs: [
391
+ {
392
+ name: "name",
393
+ type: "string",
394
+ internalType: "string"
395
+ },
396
+ {
397
+ name: "description",
398
+ type: "string",
399
+ internalType: "string"
400
+ },
401
+ {
402
+ name: "endpoint",
403
+ type: "string",
404
+ internalType: "string"
405
+ },
406
+ {
407
+ name: "category",
408
+ type: "string",
409
+ internalType: "string"
410
+ },
411
+ {
412
+ name: "pricePerCall",
413
+ type: "uint256",
414
+ internalType: "uint256"
415
+ }
416
+ ],
417
+ outputs: [
418
+ {
419
+ name: "serviceId",
420
+ type: "uint256",
421
+ internalType: "uint256"
422
+ }
423
+ ],
424
+ stateMutability: "nonpayable"
425
+ },
426
+ {
427
+ type: "function",
428
+ name: "renounceOwnership",
429
+ inputs: [],
430
+ outputs: [],
431
+ stateMutability: "nonpayable"
432
+ },
433
+ {
434
+ type: "function",
435
+ name: "transferOwnership",
436
+ inputs: [
437
+ {
438
+ name: "newOwner",
439
+ type: "address",
440
+ internalType: "address"
441
+ }
442
+ ],
443
+ outputs: [],
444
+ stateMutability: "nonpayable"
445
+ },
446
+ {
447
+ type: "function",
448
+ name: "unpause",
449
+ inputs: [],
450
+ outputs: [],
451
+ stateMutability: "nonpayable"
452
+ },
453
+ {
454
+ type: "function",
455
+ name: "updateService",
456
+ inputs: [
457
+ {
458
+ name: "serviceId",
459
+ type: "uint256",
460
+ internalType: "uint256"
461
+ },
462
+ {
463
+ name: "name",
464
+ type: "string",
465
+ internalType: "string"
466
+ },
467
+ {
468
+ name: "description",
469
+ type: "string",
470
+ internalType: "string"
471
+ },
472
+ {
473
+ name: "endpoint",
474
+ type: "string",
475
+ internalType: "string"
476
+ },
477
+ {
478
+ name: "pricePerCall",
479
+ type: "uint256",
480
+ internalType: "uint256"
481
+ }
482
+ ],
483
+ outputs: [],
484
+ stateMutability: "nonpayable"
485
+ },
486
+ {
487
+ type: "event",
488
+ name: "OwnershipTransferred",
489
+ inputs: [
490
+ {
491
+ name: "previousOwner",
492
+ type: "address",
493
+ indexed: true,
494
+ internalType: "address"
495
+ },
496
+ {
497
+ name: "newOwner",
498
+ type: "address",
499
+ indexed: true,
500
+ internalType: "address"
501
+ }
502
+ ],
503
+ anonymous: false
504
+ },
505
+ {
506
+ type: "event",
507
+ name: "Paused",
508
+ inputs: [
509
+ {
510
+ name: "account",
511
+ type: "address",
512
+ indexed: false,
513
+ internalType: "address"
514
+ }
515
+ ],
516
+ anonymous: false
517
+ },
518
+ {
519
+ type: "event",
520
+ name: "ServiceActivated",
521
+ inputs: [
522
+ {
523
+ name: "serviceId",
524
+ type: "uint256",
525
+ indexed: true,
526
+ internalType: "uint256"
527
+ }
528
+ ],
529
+ anonymous: false
530
+ },
531
+ {
532
+ type: "event",
533
+ name: "ServiceDeactivated",
534
+ inputs: [
535
+ {
536
+ name: "serviceId",
537
+ type: "uint256",
538
+ indexed: true,
539
+ internalType: "uint256"
540
+ }
541
+ ],
542
+ anonymous: false
543
+ },
544
+ {
545
+ type: "event",
546
+ name: "ServiceRegistered",
547
+ inputs: [
548
+ {
549
+ name: "serviceId",
550
+ type: "uint256",
551
+ indexed: true,
552
+ internalType: "uint256"
553
+ },
554
+ {
555
+ name: "provider",
556
+ type: "address",
557
+ indexed: true,
558
+ internalType: "address"
559
+ },
560
+ {
561
+ name: "name",
562
+ type: "string",
563
+ indexed: false,
564
+ internalType: "string"
565
+ },
566
+ {
567
+ name: "pricePerCall",
568
+ type: "uint256",
569
+ indexed: false,
570
+ internalType: "uint256"
571
+ }
572
+ ],
573
+ anonymous: false
574
+ },
575
+ {
576
+ type: "event",
577
+ name: "ServiceUpdated",
578
+ inputs: [
579
+ {
580
+ name: "serviceId",
581
+ type: "uint256",
582
+ indexed: true,
583
+ internalType: "uint256"
584
+ }
585
+ ],
586
+ anonymous: false
587
+ },
588
+ {
589
+ type: "event",
590
+ name: "SubscriptionPlanAdded",
591
+ inputs: [
592
+ {
593
+ name: "serviceId",
594
+ type: "uint256",
595
+ indexed: true,
596
+ internalType: "uint256"
597
+ },
598
+ {
599
+ name: "planId",
600
+ type: "uint256",
601
+ indexed: true,
602
+ internalType: "uint256"
603
+ },
604
+ {
605
+ name: "name",
606
+ type: "string",
607
+ indexed: false,
608
+ internalType: "string"
609
+ },
610
+ {
611
+ name: "price",
612
+ type: "uint256",
613
+ indexed: false,
614
+ internalType: "uint256"
615
+ },
616
+ {
617
+ name: "duration",
618
+ type: "uint256",
619
+ indexed: false,
620
+ internalType: "uint256"
621
+ }
622
+ ],
623
+ anonymous: false
624
+ },
625
+ {
626
+ type: "event",
627
+ name: "Unpaused",
628
+ inputs: [
629
+ {
630
+ name: "account",
631
+ type: "address",
632
+ indexed: false,
633
+ internalType: "address"
634
+ }
635
+ ],
636
+ anonymous: false
637
+ },
638
+ {
639
+ type: "error",
640
+ name: "EnforcedPause",
641
+ inputs: []
642
+ },
643
+ {
644
+ type: "error",
645
+ name: "ExpectedPause",
646
+ inputs: []
647
+ },
648
+ {
649
+ type: "error",
650
+ name: "InvalidEndpoint",
651
+ inputs: []
652
+ },
653
+ {
654
+ type: "error",
655
+ name: "InvalidPrice",
656
+ inputs: []
657
+ },
658
+ {
659
+ type: "error",
660
+ name: "InvalidServiceName",
661
+ inputs: []
662
+ },
663
+ {
664
+ type: "error",
665
+ name: "NotServiceProvider",
666
+ inputs: [
667
+ {
668
+ name: "serviceId",
669
+ type: "uint256",
670
+ internalType: "uint256"
671
+ },
672
+ {
673
+ name: "caller",
674
+ type: "address",
675
+ internalType: "address"
676
+ }
677
+ ]
678
+ },
679
+ {
680
+ type: "error",
681
+ name: "OwnableInvalidOwner",
682
+ inputs: [
683
+ {
684
+ name: "owner",
685
+ type: "address",
686
+ internalType: "address"
687
+ }
688
+ ]
689
+ },
690
+ {
691
+ type: "error",
692
+ name: "OwnableUnauthorizedAccount",
693
+ inputs: [
694
+ {
695
+ name: "account",
696
+ type: "address",
697
+ internalType: "address"
698
+ }
699
+ ]
700
+ },
701
+ {
702
+ type: "error",
703
+ name: "PlanNotFound",
704
+ inputs: [
705
+ {
706
+ name: "serviceId",
707
+ type: "uint256",
708
+ internalType: "uint256"
709
+ },
710
+ {
711
+ name: "planId",
712
+ type: "uint256",
713
+ internalType: "uint256"
714
+ }
715
+ ]
716
+ },
717
+ {
718
+ type: "error",
719
+ name: "ReentrancyGuardReentrantCall",
720
+ inputs: []
721
+ },
722
+ {
723
+ type: "error",
724
+ name: "ServiceAlreadyActive",
725
+ inputs: [
726
+ {
727
+ name: "serviceId",
728
+ type: "uint256",
729
+ internalType: "uint256"
730
+ }
731
+ ]
732
+ },
733
+ {
734
+ type: "error",
735
+ name: "ServiceAlreadyInactive",
736
+ inputs: [
737
+ {
738
+ name: "serviceId",
739
+ type: "uint256",
740
+ internalType: "uint256"
741
+ }
742
+ ]
743
+ },
744
+ {
745
+ type: "error",
746
+ name: "ServiceNotFound",
747
+ inputs: [
748
+ {
749
+ name: "serviceId",
750
+ type: "uint256",
751
+ internalType: "uint256"
752
+ }
753
+ ]
754
+ }
755
+ ];
756
+
757
+ // src/modules/services.ts
758
+ var ServicesModule = class {
759
+ constructor(address, signerOrProvider) {
760
+ this.contract = new ethers.ethers.Contract(address, ServiceRegistry_default, signerOrProvider);
761
+ }
762
+ async registerService(name, description, endpoint, category, pricePerCall) {
763
+ const tx = await this.contract.registerService(name, description, endpoint, category, pricePerCall);
764
+ const receipt = await tx.wait();
765
+ const event = receipt.logs.find(
766
+ (log) => this.contract.interface.parseLog(log)?.name === "ServiceRegistered"
767
+ );
768
+ const parsed = event ? this.contract.interface.parseLog(event) : null;
769
+ const serviceId = parsed ? parsed.args[0] : 0n;
770
+ return { txHash: receipt.hash, serviceId };
771
+ }
772
+ async addSubscriptionPlan(serviceId, name, price, duration) {
773
+ const tx = await this.contract.addSubscriptionPlan(serviceId, name, price, duration);
774
+ const receipt = await tx.wait();
775
+ return { txHash: receipt.hash, planId: 0n };
776
+ }
777
+ async getServiceDetails(serviceId) {
778
+ const s = await this.contract.getServiceDetails(serviceId);
779
+ return this._mapService(s);
780
+ }
781
+ async discoverServices(filter) {
782
+ if (filter?.category) {
783
+ const services2 = await this.contract.getServicesByCategory(filter.category);
784
+ let result = services2.map((s) => this._mapService(s));
785
+ if (filter.maxPrice) {
786
+ result = result.filter((s) => s.pricePerCall <= filter.maxPrice);
787
+ }
788
+ return result;
789
+ }
790
+ const count = await this.contract.getServiceCount();
791
+ const services = [];
792
+ for (let i = 1n; i <= count; i++) {
793
+ const s = await this.contract.getServiceDetails(i).catch(() => null);
794
+ if (s && s.isActive) {
795
+ const service = this._mapService(s);
796
+ if (!filter?.maxPrice || service.pricePerCall <= filter.maxPrice) {
797
+ services.push(service);
798
+ }
799
+ }
800
+ }
801
+ return services;
802
+ }
803
+ async getSubscriptionPlans(serviceId) {
804
+ const plans = await this.contract.getSubscriptionPlans(serviceId);
805
+ return plans.map((p) => ({
806
+ planId: p.planId,
807
+ serviceId: p.serviceId,
808
+ price: p.price,
809
+ duration: p.duration,
810
+ name: p.name
811
+ }));
812
+ }
813
+ async getServiceCount() {
814
+ return this.contract.getServiceCount();
815
+ }
816
+ _mapService(s) {
817
+ return {
818
+ id: s.id,
819
+ provider: s.provider,
820
+ name: s.name,
821
+ description: s.description,
822
+ endpoint: s.endpoint,
823
+ category: s.category,
824
+ pricePerCall: s.pricePerCall,
825
+ isActive: s.isActive,
826
+ createdAt: s.createdAt
827
+ };
828
+ }
829
+ };
830
+
831
+ // src/abi/PaymentManager.json
832
+ var PaymentManager_default = [
833
+ {
834
+ type: "constructor",
835
+ inputs: [
836
+ {
837
+ name: "_serviceRegistry",
838
+ type: "address",
839
+ internalType: "address"
840
+ },
841
+ {
842
+ name: "_platformFeeRate",
843
+ type: "uint256",
844
+ internalType: "uint256"
845
+ },
846
+ {
847
+ name: "_feeCollector",
848
+ type: "address",
849
+ internalType: "address"
850
+ }
851
+ ],
852
+ stateMutability: "nonpayable"
853
+ },
854
+ {
855
+ type: "function",
856
+ name: "batchPay",
857
+ inputs: [
858
+ {
859
+ name: "serviceIds",
860
+ type: "uint256[]",
861
+ internalType: "uint256[]"
862
+ }
863
+ ],
864
+ outputs: [],
865
+ stateMutability: "payable"
866
+ },
867
+ {
868
+ type: "function",
869
+ name: "deposit",
870
+ inputs: [],
871
+ outputs: [],
872
+ stateMutability: "payable"
873
+ },
874
+ {
875
+ type: "function",
876
+ name: "feeCollector",
877
+ inputs: [],
878
+ outputs: [
879
+ {
880
+ name: "",
881
+ type: "address",
882
+ internalType: "address"
883
+ }
884
+ ],
885
+ stateMutability: "view"
886
+ },
887
+ {
888
+ type: "function",
889
+ name: "getPaymentCount",
890
+ inputs: [
891
+ {
892
+ name: "user",
893
+ type: "address",
894
+ internalType: "address"
895
+ }
896
+ ],
897
+ outputs: [
898
+ {
899
+ name: "",
900
+ type: "uint256",
901
+ internalType: "uint256"
902
+ }
903
+ ],
904
+ stateMutability: "view"
905
+ },
906
+ {
907
+ type: "function",
908
+ name: "getTotalSpent",
909
+ inputs: [
910
+ {
911
+ name: "user",
912
+ type: "address",
913
+ internalType: "address"
914
+ }
915
+ ],
916
+ outputs: [
917
+ {
918
+ name: "",
919
+ type: "uint256",
920
+ internalType: "uint256"
921
+ }
922
+ ],
923
+ stateMutability: "view"
924
+ },
925
+ {
926
+ type: "function",
927
+ name: "getPlatformFeeRate",
928
+ inputs: [],
929
+ outputs: [
930
+ {
931
+ name: "",
932
+ type: "uint256",
933
+ internalType: "uint256"
934
+ }
935
+ ],
936
+ stateMutability: "view"
937
+ },
938
+ {
939
+ type: "function",
940
+ name: "getProviderEarnings",
941
+ inputs: [
942
+ {
943
+ name: "provider",
944
+ type: "address",
945
+ internalType: "address"
946
+ }
947
+ ],
948
+ outputs: [
949
+ {
950
+ name: "",
951
+ type: "uint256",
952
+ internalType: "uint256"
953
+ }
954
+ ],
955
+ stateMutability: "view"
956
+ },
957
+ {
958
+ type: "function",
959
+ name: "getUserBalance",
960
+ inputs: [
961
+ {
962
+ name: "user",
963
+ type: "address",
964
+ internalType: "address"
965
+ }
966
+ ],
967
+ outputs: [
968
+ {
969
+ name: "",
970
+ type: "uint256",
971
+ internalType: "uint256"
972
+ }
973
+ ],
974
+ stateMutability: "view"
975
+ },
976
+ {
977
+ type: "function",
978
+ name: "owner",
979
+ inputs: [],
980
+ outputs: [
981
+ {
982
+ name: "",
983
+ type: "address",
984
+ internalType: "address"
985
+ }
986
+ ],
987
+ stateMutability: "view"
988
+ },
989
+ {
990
+ type: "function",
991
+ name: "pause",
992
+ inputs: [],
993
+ outputs: [],
994
+ stateMutability: "nonpayable"
995
+ },
996
+ {
997
+ type: "function",
998
+ name: "paused",
999
+ inputs: [],
1000
+ outputs: [
1001
+ {
1002
+ name: "",
1003
+ type: "bool",
1004
+ internalType: "bool"
1005
+ }
1006
+ ],
1007
+ stateMutability: "view"
1008
+ },
1009
+ {
1010
+ type: "function",
1011
+ name: "payFromBalance",
1012
+ inputs: [
1013
+ {
1014
+ name: "serviceId",
1015
+ type: "uint256",
1016
+ internalType: "uint256"
1017
+ }
1018
+ ],
1019
+ outputs: [],
1020
+ stateMutability: "nonpayable"
1021
+ },
1022
+ {
1023
+ type: "function",
1024
+ name: "payPerUse",
1025
+ inputs: [
1026
+ {
1027
+ name: "serviceId",
1028
+ type: "uint256",
1029
+ internalType: "uint256"
1030
+ }
1031
+ ],
1032
+ outputs: [],
1033
+ stateMutability: "payable"
1034
+ },
1035
+ {
1036
+ type: "function",
1037
+ name: "platformFeeRate",
1038
+ inputs: [],
1039
+ outputs: [
1040
+ {
1041
+ name: "",
1042
+ type: "uint256",
1043
+ internalType: "uint256"
1044
+ }
1045
+ ],
1046
+ stateMutability: "view"
1047
+ },
1048
+ {
1049
+ type: "function",
1050
+ name: "renounceOwnership",
1051
+ inputs: [],
1052
+ outputs: [],
1053
+ stateMutability: "nonpayable"
1054
+ },
1055
+ {
1056
+ type: "function",
1057
+ name: "serviceRegistry",
1058
+ inputs: [],
1059
+ outputs: [
1060
+ {
1061
+ name: "",
1062
+ type: "address",
1063
+ internalType: "contract IServiceRegistry"
1064
+ }
1065
+ ],
1066
+ stateMutability: "view"
1067
+ },
1068
+ {
1069
+ type: "function",
1070
+ name: "setFeeCollector",
1071
+ inputs: [
1072
+ {
1073
+ name: "newCollector",
1074
+ type: "address",
1075
+ internalType: "address"
1076
+ }
1077
+ ],
1078
+ outputs: [],
1079
+ stateMutability: "nonpayable"
1080
+ },
1081
+ {
1082
+ type: "function",
1083
+ name: "setPlatformFeeRate",
1084
+ inputs: [
1085
+ {
1086
+ name: "newRate",
1087
+ type: "uint256",
1088
+ internalType: "uint256"
1089
+ }
1090
+ ],
1091
+ outputs: [],
1092
+ stateMutability: "nonpayable"
1093
+ },
1094
+ {
1095
+ type: "function",
1096
+ name: "transferOwnership",
1097
+ inputs: [
1098
+ {
1099
+ name: "newOwner",
1100
+ type: "address",
1101
+ internalType: "address"
1102
+ }
1103
+ ],
1104
+ outputs: [],
1105
+ stateMutability: "nonpayable"
1106
+ },
1107
+ {
1108
+ type: "function",
1109
+ name: "unpause",
1110
+ inputs: [],
1111
+ outputs: [],
1112
+ stateMutability: "nonpayable"
1113
+ },
1114
+ {
1115
+ type: "function",
1116
+ name: "withdraw",
1117
+ inputs: [
1118
+ {
1119
+ name: "amount",
1120
+ type: "uint256",
1121
+ internalType: "uint256"
1122
+ }
1123
+ ],
1124
+ outputs: [],
1125
+ stateMutability: "nonpayable"
1126
+ },
1127
+ {
1128
+ type: "function",
1129
+ name: "withdrawPlatformFees",
1130
+ inputs: [],
1131
+ outputs: [],
1132
+ stateMutability: "nonpayable"
1133
+ },
1134
+ {
1135
+ type: "function",
1136
+ name: "withdrawProviderEarnings",
1137
+ inputs: [],
1138
+ outputs: [],
1139
+ stateMutability: "nonpayable"
1140
+ },
1141
+ {
1142
+ type: "event",
1143
+ name: "BalanceDeposited",
1144
+ inputs: [
1145
+ {
1146
+ name: "user",
1147
+ type: "address",
1148
+ indexed: true,
1149
+ internalType: "address"
1150
+ },
1151
+ {
1152
+ name: "amount",
1153
+ type: "uint256",
1154
+ indexed: false,
1155
+ internalType: "uint256"
1156
+ }
1157
+ ],
1158
+ anonymous: false
1159
+ },
1160
+ {
1161
+ type: "event",
1162
+ name: "BalanceWithdrawn",
1163
+ inputs: [
1164
+ {
1165
+ name: "user",
1166
+ type: "address",
1167
+ indexed: true,
1168
+ internalType: "address"
1169
+ },
1170
+ {
1171
+ name: "amount",
1172
+ type: "uint256",
1173
+ indexed: false,
1174
+ internalType: "uint256"
1175
+ }
1176
+ ],
1177
+ anonymous: false
1178
+ },
1179
+ {
1180
+ type: "event",
1181
+ name: "BatchPaymentMade",
1182
+ inputs: [
1183
+ {
1184
+ name: "payer",
1185
+ type: "address",
1186
+ indexed: true,
1187
+ internalType: "address"
1188
+ },
1189
+ {
1190
+ name: "totalAmount",
1191
+ type: "uint256",
1192
+ indexed: false,
1193
+ internalType: "uint256"
1194
+ },
1195
+ {
1196
+ name: "count",
1197
+ type: "uint256",
1198
+ indexed: false,
1199
+ internalType: "uint256"
1200
+ }
1201
+ ],
1202
+ anonymous: false
1203
+ },
1204
+ {
1205
+ type: "event",
1206
+ name: "OwnershipTransferred",
1207
+ inputs: [
1208
+ {
1209
+ name: "previousOwner",
1210
+ type: "address",
1211
+ indexed: true,
1212
+ internalType: "address"
1213
+ },
1214
+ {
1215
+ name: "newOwner",
1216
+ type: "address",
1217
+ indexed: true,
1218
+ internalType: "address"
1219
+ }
1220
+ ],
1221
+ anonymous: false
1222
+ },
1223
+ {
1224
+ type: "event",
1225
+ name: "Paused",
1226
+ inputs: [
1227
+ {
1228
+ name: "account",
1229
+ type: "address",
1230
+ indexed: false,
1231
+ internalType: "address"
1232
+ }
1233
+ ],
1234
+ anonymous: false
1235
+ },
1236
+ {
1237
+ type: "event",
1238
+ name: "PaymentMade",
1239
+ inputs: [
1240
+ {
1241
+ name: "serviceId",
1242
+ type: "uint256",
1243
+ indexed: true,
1244
+ internalType: "uint256"
1245
+ },
1246
+ {
1247
+ name: "payer",
1248
+ type: "address",
1249
+ indexed: true,
1250
+ internalType: "address"
1251
+ },
1252
+ {
1253
+ name: "provider",
1254
+ type: "address",
1255
+ indexed: true,
1256
+ internalType: "address"
1257
+ },
1258
+ {
1259
+ name: "amount",
1260
+ type: "uint256",
1261
+ indexed: false,
1262
+ internalType: "uint256"
1263
+ },
1264
+ {
1265
+ name: "platformFee",
1266
+ type: "uint256",
1267
+ indexed: false,
1268
+ internalType: "uint256"
1269
+ }
1270
+ ],
1271
+ anonymous: false
1272
+ },
1273
+ {
1274
+ type: "event",
1275
+ name: "ProviderWithdrawn",
1276
+ inputs: [
1277
+ {
1278
+ name: "provider",
1279
+ type: "address",
1280
+ indexed: true,
1281
+ internalType: "address"
1282
+ },
1283
+ {
1284
+ name: "amount",
1285
+ type: "uint256",
1286
+ indexed: false,
1287
+ internalType: "uint256"
1288
+ }
1289
+ ],
1290
+ anonymous: false
1291
+ },
1292
+ {
1293
+ type: "event",
1294
+ name: "Unpaused",
1295
+ inputs: [
1296
+ {
1297
+ name: "account",
1298
+ type: "address",
1299
+ indexed: false,
1300
+ internalType: "address"
1301
+ }
1302
+ ],
1303
+ anonymous: false
1304
+ },
1305
+ {
1306
+ type: "error",
1307
+ name: "ArrayLengthMismatch",
1308
+ inputs: []
1309
+ },
1310
+ {
1311
+ type: "error",
1312
+ name: "EnforcedPause",
1313
+ inputs: []
1314
+ },
1315
+ {
1316
+ type: "error",
1317
+ name: "ExpectedPause",
1318
+ inputs: []
1319
+ },
1320
+ {
1321
+ type: "error",
1322
+ name: "InsufficientBalance",
1323
+ inputs: [
1324
+ {
1325
+ name: "required",
1326
+ type: "uint256",
1327
+ internalType: "uint256"
1328
+ },
1329
+ {
1330
+ name: "available",
1331
+ type: "uint256",
1332
+ internalType: "uint256"
1333
+ }
1334
+ ]
1335
+ },
1336
+ {
1337
+ type: "error",
1338
+ name: "InsufficientPayment",
1339
+ inputs: [
1340
+ {
1341
+ name: "required",
1342
+ type: "uint256",
1343
+ internalType: "uint256"
1344
+ },
1345
+ {
1346
+ name: "provided",
1347
+ type: "uint256",
1348
+ internalType: "uint256"
1349
+ }
1350
+ ]
1351
+ },
1352
+ {
1353
+ type: "error",
1354
+ name: "InvalidFeeRate",
1355
+ inputs: [
1356
+ {
1357
+ name: "feeRate",
1358
+ type: "uint256",
1359
+ internalType: "uint256"
1360
+ }
1361
+ ]
1362
+ },
1363
+ {
1364
+ type: "error",
1365
+ name: "NoEarningsToWithdraw",
1366
+ inputs: []
1367
+ },
1368
+ {
1369
+ type: "error",
1370
+ name: "OwnableInvalidOwner",
1371
+ inputs: [
1372
+ {
1373
+ name: "owner",
1374
+ type: "address",
1375
+ internalType: "address"
1376
+ }
1377
+ ]
1378
+ },
1379
+ {
1380
+ type: "error",
1381
+ name: "OwnableUnauthorizedAccount",
1382
+ inputs: [
1383
+ {
1384
+ name: "account",
1385
+ type: "address",
1386
+ internalType: "address"
1387
+ }
1388
+ ]
1389
+ },
1390
+ {
1391
+ type: "error",
1392
+ name: "ReentrancyGuardReentrantCall",
1393
+ inputs: []
1394
+ },
1395
+ {
1396
+ type: "error",
1397
+ name: "ServiceNotActive",
1398
+ inputs: [
1399
+ {
1400
+ name: "serviceId",
1401
+ type: "uint256",
1402
+ internalType: "uint256"
1403
+ }
1404
+ ]
1405
+ },
1406
+ {
1407
+ type: "error",
1408
+ name: "TransferFailed",
1409
+ inputs: [
1410
+ {
1411
+ name: "to",
1412
+ type: "address",
1413
+ internalType: "address"
1414
+ },
1415
+ {
1416
+ name: "amount",
1417
+ type: "uint256",
1418
+ internalType: "uint256"
1419
+ }
1420
+ ]
1421
+ },
1422
+ {
1423
+ type: "error",
1424
+ name: "ZeroAmount",
1425
+ inputs: []
1426
+ }
1427
+ ];
1428
+
1429
+ // src/modules/payments.ts
1430
+ var PaymentsModule = class {
1431
+ constructor(address, signerOrProvider) {
1432
+ this.contract = null;
1433
+ this.address = address;
1434
+ this.signerOrProvider = signerOrProvider;
1435
+ if (address && address !== "") {
1436
+ this.contract = new ethers.ethers.Contract(address, PaymentManager_default, signerOrProvider);
1437
+ }
1438
+ }
1439
+ getContract() {
1440
+ if (!this.contract) {
1441
+ throw new Error("PaymentManager contract address not configured");
1442
+ }
1443
+ return this.contract;
1444
+ }
1445
+ async payPerUse(serviceId, amount) {
1446
+ const contract = this.getContract();
1447
+ const tx = await contract.payPerUse(serviceId, { value: amount });
1448
+ const receipt = await tx.wait();
1449
+ return {
1450
+ txHash: receipt.hash,
1451
+ serviceId,
1452
+ amount,
1453
+ provider: ""
1454
+ };
1455
+ }
1456
+ async batchPay(serviceIds, totalAmount) {
1457
+ const contract = this.getContract();
1458
+ const tx = await contract.batchPay(serviceIds, { value: totalAmount });
1459
+ const receipt = await tx.wait();
1460
+ return receipt.hash;
1461
+ }
1462
+ async deposit(amount) {
1463
+ const contract = this.getContract();
1464
+ const tx = await contract.deposit({ value: amount });
1465
+ const receipt = await tx.wait();
1466
+ return receipt.hash;
1467
+ }
1468
+ async withdraw(amount) {
1469
+ const contract = this.getContract();
1470
+ const tx = await contract.withdraw(amount);
1471
+ const receipt = await tx.wait();
1472
+ return receipt.hash;
1473
+ }
1474
+ async payFromBalance(serviceId) {
1475
+ const contract = this.getContract();
1476
+ const tx = await contract.payFromBalance(serviceId);
1477
+ const receipt = await tx.wait();
1478
+ return receipt.hash;
1479
+ }
1480
+ async withdrawProviderEarnings() {
1481
+ const contract = this.getContract();
1482
+ const tx = await contract.withdrawProviderEarnings();
1483
+ const receipt = await tx.wait();
1484
+ return receipt.hash;
1485
+ }
1486
+ async getUserBalance(address) {
1487
+ const contract = this.getContract();
1488
+ return contract.getUserBalance(address);
1489
+ }
1490
+ async getProviderEarnings(address) {
1491
+ const contract = this.getContract();
1492
+ return contract.getProviderEarnings(address);
1493
+ }
1494
+ async getPaymentCount(address) {
1495
+ const contract = this.getContract();
1496
+ return contract.getPaymentCount(address);
1497
+ }
1498
+ async getTotalSpent(address) {
1499
+ const contract = this.getContract();
1500
+ return contract.getTotalSpent(address);
1501
+ }
1502
+ getContractAddress() {
1503
+ const contract = this.getContract();
1504
+ return contract.target;
1505
+ }
1506
+ };
1507
+
1508
+ // src/abi/SubscriptionManager.json
1509
+ var SubscriptionManager_default = [
1510
+ {
1511
+ type: "constructor",
1512
+ inputs: [
1513
+ {
1514
+ name: "_serviceRegistry",
1515
+ type: "address",
1516
+ internalType: "address"
1517
+ }
1518
+ ],
1519
+ stateMutability: "nonpayable"
1520
+ },
1521
+ {
1522
+ type: "function",
1523
+ name: "cancelSubscription",
1524
+ inputs: [
1525
+ {
1526
+ name: "subscriptionId",
1527
+ type: "uint256",
1528
+ internalType: "uint256"
1529
+ }
1530
+ ],
1531
+ outputs: [],
1532
+ stateMutability: "nonpayable"
1533
+ },
1534
+ {
1535
+ type: "function",
1536
+ name: "checkAccess",
1537
+ inputs: [
1538
+ {
1539
+ name: "user",
1540
+ type: "address",
1541
+ internalType: "address"
1542
+ },
1543
+ {
1544
+ name: "serviceId",
1545
+ type: "uint256",
1546
+ internalType: "uint256"
1547
+ }
1548
+ ],
1549
+ outputs: [
1550
+ {
1551
+ name: "",
1552
+ type: "bool",
1553
+ internalType: "bool"
1554
+ }
1555
+ ],
1556
+ stateMutability: "view"
1557
+ },
1558
+ {
1559
+ type: "function",
1560
+ name: "getSubscription",
1561
+ inputs: [
1562
+ {
1563
+ name: "subscriptionId",
1564
+ type: "uint256",
1565
+ internalType: "uint256"
1566
+ }
1567
+ ],
1568
+ outputs: [
1569
+ {
1570
+ name: "",
1571
+ type: "tuple",
1572
+ internalType: "struct ISubscriptionManager.Subscription",
1573
+ components: [
1574
+ {
1575
+ name: "subscriptionId",
1576
+ type: "uint256",
1577
+ internalType: "uint256"
1578
+ },
1579
+ {
1580
+ name: "serviceId",
1581
+ type: "uint256",
1582
+ internalType: "uint256"
1583
+ },
1584
+ {
1585
+ name: "planId",
1586
+ type: "uint256",
1587
+ internalType: "uint256"
1588
+ },
1589
+ {
1590
+ name: "subscriber",
1591
+ type: "address",
1592
+ internalType: "address"
1593
+ },
1594
+ {
1595
+ name: "startTime",
1596
+ type: "uint256",
1597
+ internalType: "uint256"
1598
+ },
1599
+ {
1600
+ name: "endTime",
1601
+ type: "uint256",
1602
+ internalType: "uint256"
1603
+ },
1604
+ {
1605
+ name: "autoRenew",
1606
+ type: "bool",
1607
+ internalType: "bool"
1608
+ },
1609
+ {
1610
+ name: "isActive",
1611
+ type: "bool",
1612
+ internalType: "bool"
1613
+ }
1614
+ ]
1615
+ }
1616
+ ],
1617
+ stateMutability: "view"
1618
+ },
1619
+ {
1620
+ type: "function",
1621
+ name: "getUserSubscriptions",
1622
+ inputs: [
1623
+ {
1624
+ name: "user",
1625
+ type: "address",
1626
+ internalType: "address"
1627
+ }
1628
+ ],
1629
+ outputs: [
1630
+ {
1631
+ name: "",
1632
+ type: "uint256[]",
1633
+ internalType: "uint256[]"
1634
+ }
1635
+ ],
1636
+ stateMutability: "view"
1637
+ },
1638
+ {
1639
+ type: "function",
1640
+ name: "isSubscriptionActive",
1641
+ inputs: [
1642
+ {
1643
+ name: "subscriptionId",
1644
+ type: "uint256",
1645
+ internalType: "uint256"
1646
+ }
1647
+ ],
1648
+ outputs: [
1649
+ {
1650
+ name: "",
1651
+ type: "bool",
1652
+ internalType: "bool"
1653
+ }
1654
+ ],
1655
+ stateMutability: "view"
1656
+ },
1657
+ {
1658
+ type: "function",
1659
+ name: "owner",
1660
+ inputs: [],
1661
+ outputs: [
1662
+ {
1663
+ name: "",
1664
+ type: "address",
1665
+ internalType: "address"
1666
+ }
1667
+ ],
1668
+ stateMutability: "view"
1669
+ },
1670
+ {
1671
+ type: "function",
1672
+ name: "pause",
1673
+ inputs: [],
1674
+ outputs: [],
1675
+ stateMutability: "nonpayable"
1676
+ },
1677
+ {
1678
+ type: "function",
1679
+ name: "paused",
1680
+ inputs: [],
1681
+ outputs: [
1682
+ {
1683
+ name: "",
1684
+ type: "bool",
1685
+ internalType: "bool"
1686
+ }
1687
+ ],
1688
+ stateMutability: "view"
1689
+ },
1690
+ {
1691
+ type: "function",
1692
+ name: "renewSubscription",
1693
+ inputs: [
1694
+ {
1695
+ name: "subscriptionId",
1696
+ type: "uint256",
1697
+ internalType: "uint256"
1698
+ }
1699
+ ],
1700
+ outputs: [],
1701
+ stateMutability: "payable"
1702
+ },
1703
+ {
1704
+ type: "function",
1705
+ name: "renounceOwnership",
1706
+ inputs: [],
1707
+ outputs: [],
1708
+ stateMutability: "nonpayable"
1709
+ },
1710
+ {
1711
+ type: "function",
1712
+ name: "serviceRegistry",
1713
+ inputs: [],
1714
+ outputs: [
1715
+ {
1716
+ name: "",
1717
+ type: "address",
1718
+ internalType: "contract IServiceRegistry"
1719
+ }
1720
+ ],
1721
+ stateMutability: "view"
1722
+ },
1723
+ {
1724
+ type: "function",
1725
+ name: "subscribe",
1726
+ inputs: [
1727
+ {
1728
+ name: "serviceId",
1729
+ type: "uint256",
1730
+ internalType: "uint256"
1731
+ },
1732
+ {
1733
+ name: "planId",
1734
+ type: "uint256",
1735
+ internalType: "uint256"
1736
+ }
1737
+ ],
1738
+ outputs: [
1739
+ {
1740
+ name: "subscriptionId",
1741
+ type: "uint256",
1742
+ internalType: "uint256"
1743
+ }
1744
+ ],
1745
+ stateMutability: "payable"
1746
+ },
1747
+ {
1748
+ type: "function",
1749
+ name: "toggleAutoRenew",
1750
+ inputs: [
1751
+ {
1752
+ name: "subscriptionId",
1753
+ type: "uint256",
1754
+ internalType: "uint256"
1755
+ }
1756
+ ],
1757
+ outputs: [],
1758
+ stateMutability: "nonpayable"
1759
+ },
1760
+ {
1761
+ type: "function",
1762
+ name: "transferOwnership",
1763
+ inputs: [
1764
+ {
1765
+ name: "newOwner",
1766
+ type: "address",
1767
+ internalType: "address"
1768
+ }
1769
+ ],
1770
+ outputs: [],
1771
+ stateMutability: "nonpayable"
1772
+ },
1773
+ {
1774
+ type: "function",
1775
+ name: "unpause",
1776
+ inputs: [],
1777
+ outputs: [],
1778
+ stateMutability: "nonpayable"
1779
+ },
1780
+ {
1781
+ type: "event",
1782
+ name: "AutoRenewToggled",
1783
+ inputs: [
1784
+ {
1785
+ name: "subscriptionId",
1786
+ type: "uint256",
1787
+ indexed: true,
1788
+ internalType: "uint256"
1789
+ },
1790
+ {
1791
+ name: "autoRenew",
1792
+ type: "bool",
1793
+ indexed: false,
1794
+ internalType: "bool"
1795
+ }
1796
+ ],
1797
+ anonymous: false
1798
+ },
1799
+ {
1800
+ type: "event",
1801
+ name: "OwnershipTransferred",
1802
+ inputs: [
1803
+ {
1804
+ name: "previousOwner",
1805
+ type: "address",
1806
+ indexed: true,
1807
+ internalType: "address"
1808
+ },
1809
+ {
1810
+ name: "newOwner",
1811
+ type: "address",
1812
+ indexed: true,
1813
+ internalType: "address"
1814
+ }
1815
+ ],
1816
+ anonymous: false
1817
+ },
1818
+ {
1819
+ type: "event",
1820
+ name: "Paused",
1821
+ inputs: [
1822
+ {
1823
+ name: "account",
1824
+ type: "address",
1825
+ indexed: false,
1826
+ internalType: "address"
1827
+ }
1828
+ ],
1829
+ anonymous: false
1830
+ },
1831
+ {
1832
+ type: "event",
1833
+ name: "Subscribed",
1834
+ inputs: [
1835
+ {
1836
+ name: "subscriptionId",
1837
+ type: "uint256",
1838
+ indexed: true,
1839
+ internalType: "uint256"
1840
+ },
1841
+ {
1842
+ name: "serviceId",
1843
+ type: "uint256",
1844
+ indexed: true,
1845
+ internalType: "uint256"
1846
+ },
1847
+ {
1848
+ name: "planId",
1849
+ type: "uint256",
1850
+ indexed: true,
1851
+ internalType: "uint256"
1852
+ },
1853
+ {
1854
+ name: "subscriber",
1855
+ type: "address",
1856
+ indexed: false,
1857
+ internalType: "address"
1858
+ },
1859
+ {
1860
+ name: "startTime",
1861
+ type: "uint256",
1862
+ indexed: false,
1863
+ internalType: "uint256"
1864
+ },
1865
+ {
1866
+ name: "endTime",
1867
+ type: "uint256",
1868
+ indexed: false,
1869
+ internalType: "uint256"
1870
+ }
1871
+ ],
1872
+ anonymous: false
1873
+ },
1874
+ {
1875
+ type: "event",
1876
+ name: "SubscriptionCancelled",
1877
+ inputs: [
1878
+ {
1879
+ name: "subscriptionId",
1880
+ type: "uint256",
1881
+ indexed: true,
1882
+ internalType: "uint256"
1883
+ }
1884
+ ],
1885
+ anonymous: false
1886
+ },
1887
+ {
1888
+ type: "event",
1889
+ name: "SubscriptionRenewed",
1890
+ inputs: [
1891
+ {
1892
+ name: "subscriptionId",
1893
+ type: "uint256",
1894
+ indexed: true,
1895
+ internalType: "uint256"
1896
+ },
1897
+ {
1898
+ name: "newEndTime",
1899
+ type: "uint256",
1900
+ indexed: false,
1901
+ internalType: "uint256"
1902
+ }
1903
+ ],
1904
+ anonymous: false
1905
+ },
1906
+ {
1907
+ type: "event",
1908
+ name: "Unpaused",
1909
+ inputs: [
1910
+ {
1911
+ name: "account",
1912
+ type: "address",
1913
+ indexed: false,
1914
+ internalType: "address"
1915
+ }
1916
+ ],
1917
+ anonymous: false
1918
+ },
1919
+ {
1920
+ type: "error",
1921
+ name: "AlreadySubscribed",
1922
+ inputs: [
1923
+ {
1924
+ name: "user",
1925
+ type: "address",
1926
+ internalType: "address"
1927
+ },
1928
+ {
1929
+ name: "serviceId",
1930
+ type: "uint256",
1931
+ internalType: "uint256"
1932
+ }
1933
+ ]
1934
+ },
1935
+ {
1936
+ type: "error",
1937
+ name: "EnforcedPause",
1938
+ inputs: []
1939
+ },
1940
+ {
1941
+ type: "error",
1942
+ name: "ExpectedPause",
1943
+ inputs: []
1944
+ },
1945
+ {
1946
+ type: "error",
1947
+ name: "InsufficientPayment",
1948
+ inputs: [
1949
+ {
1950
+ name: "required",
1951
+ type: "uint256",
1952
+ internalType: "uint256"
1953
+ },
1954
+ {
1955
+ name: "provided",
1956
+ type: "uint256",
1957
+ internalType: "uint256"
1958
+ }
1959
+ ]
1960
+ },
1961
+ {
1962
+ type: "error",
1963
+ name: "InvalidFeeRate",
1964
+ inputs: [
1965
+ {
1966
+ name: "feeRate",
1967
+ type: "uint256",
1968
+ internalType: "uint256"
1969
+ }
1970
+ ]
1971
+ },
1972
+ {
1973
+ type: "error",
1974
+ name: "NotSubscriber",
1975
+ inputs: [
1976
+ {
1977
+ name: "subscriptionId",
1978
+ type: "uint256",
1979
+ internalType: "uint256"
1980
+ }
1981
+ ]
1982
+ },
1983
+ {
1984
+ type: "error",
1985
+ name: "OwnableInvalidOwner",
1986
+ inputs: [
1987
+ {
1988
+ name: "owner",
1989
+ type: "address",
1990
+ internalType: "address"
1991
+ }
1992
+ ]
1993
+ },
1994
+ {
1995
+ type: "error",
1996
+ name: "OwnableUnauthorizedAccount",
1997
+ inputs: [
1998
+ {
1999
+ name: "account",
2000
+ type: "address",
2001
+ internalType: "address"
2002
+ }
2003
+ ]
2004
+ },
2005
+ {
2006
+ type: "error",
2007
+ name: "ReentrancyGuardReentrantCall",
2008
+ inputs: []
2009
+ },
2010
+ {
2011
+ type: "error",
2012
+ name: "ServiceNotActive",
2013
+ inputs: [
2014
+ {
2015
+ name: "serviceId",
2016
+ type: "uint256",
2017
+ internalType: "uint256"
2018
+ }
2019
+ ]
2020
+ },
2021
+ {
2022
+ type: "error",
2023
+ name: "SubscriptionNotActive",
2024
+ inputs: [
2025
+ {
2026
+ name: "subscriptionId",
2027
+ type: "uint256",
2028
+ internalType: "uint256"
2029
+ }
2030
+ ]
2031
+ },
2032
+ {
2033
+ type: "error",
2034
+ name: "SubscriptionNotFound",
2035
+ inputs: [
2036
+ {
2037
+ name: "subscriptionId",
2038
+ type: "uint256",
2039
+ internalType: "uint256"
2040
+ }
2041
+ ]
2042
+ },
2043
+ {
2044
+ type: "error",
2045
+ name: "SubscriptionStillActive",
2046
+ inputs: [
2047
+ {
2048
+ name: "subscriptionId",
2049
+ type: "uint256",
2050
+ internalType: "uint256"
2051
+ }
2052
+ ]
2053
+ },
2054
+ {
2055
+ type: "error",
2056
+ name: "TransferFailed",
2057
+ inputs: [
2058
+ {
2059
+ name: "to",
2060
+ type: "address",
2061
+ internalType: "address"
2062
+ },
2063
+ {
2064
+ name: "amount",
2065
+ type: "uint256",
2066
+ internalType: "uint256"
2067
+ }
2068
+ ]
2069
+ },
2070
+ {
2071
+ type: "error",
2072
+ name: "ZeroAmount",
2073
+ inputs: []
2074
+ }
2075
+ ];
2076
+
2077
+ // src/modules/subscriptions.ts
2078
+ var SubscriptionsModule = class {
2079
+ constructor(address, signerOrProvider) {
2080
+ this.contract = null;
2081
+ if (address && address !== "") {
2082
+ this.contract = new ethers.ethers.Contract(address, SubscriptionManager_default, signerOrProvider);
2083
+ }
2084
+ }
2085
+ getContract() {
2086
+ if (!this.contract) {
2087
+ throw new Error("SubscriptionManager contract address not configured");
2088
+ }
2089
+ return this.contract;
2090
+ }
2091
+ async subscribe(serviceId, planId, amount) {
2092
+ const contract = this.getContract();
2093
+ const tx = await contract.subscribe(serviceId, planId, { value: amount });
2094
+ const receipt = await tx.wait();
2095
+ return { txHash: receipt.hash, subscriptionId: 0n };
2096
+ }
2097
+ async cancelSubscription(subscriptionId) {
2098
+ const contract = this.getContract();
2099
+ const tx = await contract.cancelSubscription(subscriptionId);
2100
+ const receipt = await tx.wait();
2101
+ return receipt.hash;
2102
+ }
2103
+ async renewSubscription(subscriptionId, amount) {
2104
+ const contract = this.getContract();
2105
+ const tx = await contract.renewSubscription(subscriptionId, { value: amount });
2106
+ const receipt = await tx.wait();
2107
+ return receipt.hash;
2108
+ }
2109
+ async toggleAutoRenew(subscriptionId) {
2110
+ const contract = this.getContract();
2111
+ const tx = await contract.toggleAutoRenew(subscriptionId);
2112
+ const receipt = await tx.wait();
2113
+ return receipt.hash;
2114
+ }
2115
+ async getSubscription(subscriptionId) {
2116
+ const contract = this.getContract();
2117
+ const s = await contract.getSubscription(subscriptionId);
2118
+ return {
2119
+ subscriptionId: s.subscriptionId,
2120
+ serviceId: s.serviceId,
2121
+ planId: s.planId,
2122
+ subscriber: s.subscriber,
2123
+ startTime: s.startTime,
2124
+ endTime: s.endTime,
2125
+ autoRenew: s.autoRenew,
2126
+ isActive: s.isActive
2127
+ };
2128
+ }
2129
+ async getUserSubscriptions(address) {
2130
+ const contract = this.getContract();
2131
+ return contract.getUserSubscriptions(address);
2132
+ }
2133
+ async isActive(subscriptionId) {
2134
+ const contract = this.getContract();
2135
+ return contract.isSubscriptionActive(subscriptionId);
2136
+ }
2137
+ async checkAccess(userAddress, serviceId) {
2138
+ const contract = this.getContract();
2139
+ return contract.checkAccess(userAddress, serviceId);
2140
+ }
2141
+ };
2142
+
2143
+ // src/abi/Escrow.json
2144
+ var Escrow_default = [
2145
+ {
2146
+ type: "constructor",
2147
+ inputs: [],
2148
+ stateMutability: "nonpayable"
2149
+ },
2150
+ {
2151
+ type: "function",
2152
+ name: "createEscrow",
2153
+ inputs: [
2154
+ {
2155
+ name: "serviceId",
2156
+ type: "uint256",
2157
+ internalType: "uint256"
2158
+ },
2159
+ {
2160
+ name: "provider",
2161
+ type: "address",
2162
+ internalType: "address"
2163
+ },
2164
+ {
2165
+ name: "deadline",
2166
+ type: "uint256",
2167
+ internalType: "uint256"
2168
+ },
2169
+ {
2170
+ name: "description",
2171
+ type: "string",
2172
+ internalType: "string"
2173
+ }
2174
+ ],
2175
+ outputs: [
2176
+ {
2177
+ name: "escrowId",
2178
+ type: "uint256",
2179
+ internalType: "uint256"
2180
+ }
2181
+ ],
2182
+ stateMutability: "payable"
2183
+ },
2184
+ {
2185
+ type: "function",
2186
+ name: "disputeEscrow",
2187
+ inputs: [
2188
+ {
2189
+ name: "escrowId",
2190
+ type: "uint256",
2191
+ internalType: "uint256"
2192
+ }
2193
+ ],
2194
+ outputs: [],
2195
+ stateMutability: "nonpayable"
2196
+ },
2197
+ {
2198
+ type: "function",
2199
+ name: "getEscrow",
2200
+ inputs: [
2201
+ {
2202
+ name: "escrowId",
2203
+ type: "uint256",
2204
+ internalType: "uint256"
2205
+ }
2206
+ ],
2207
+ outputs: [
2208
+ {
2209
+ name: "",
2210
+ type: "tuple",
2211
+ internalType: "struct IEscrow.EscrowData",
2212
+ components: [
2213
+ {
2214
+ name: "escrowId",
2215
+ type: "uint256",
2216
+ internalType: "uint256"
2217
+ },
2218
+ {
2219
+ name: "serviceId",
2220
+ type: "uint256",
2221
+ internalType: "uint256"
2222
+ },
2223
+ {
2224
+ name: "payer",
2225
+ type: "address",
2226
+ internalType: "address"
2227
+ },
2228
+ {
2229
+ name: "provider",
2230
+ type: "address",
2231
+ internalType: "address"
2232
+ },
2233
+ {
2234
+ name: "amount",
2235
+ type: "uint256",
2236
+ internalType: "uint256"
2237
+ },
2238
+ {
2239
+ name: "status",
2240
+ type: "uint8",
2241
+ internalType: "enum IEscrow.EscrowStatus"
2242
+ },
2243
+ {
2244
+ name: "createdAt",
2245
+ type: "uint256",
2246
+ internalType: "uint256"
2247
+ },
2248
+ {
2249
+ name: "deadline",
2250
+ type: "uint256",
2251
+ internalType: "uint256"
2252
+ },
2253
+ {
2254
+ name: "description",
2255
+ type: "string",
2256
+ internalType: "string"
2257
+ }
2258
+ ]
2259
+ }
2260
+ ],
2261
+ stateMutability: "view"
2262
+ },
2263
+ {
2264
+ type: "function",
2265
+ name: "getUserEscrows",
2266
+ inputs: [
2267
+ {
2268
+ name: "user",
2269
+ type: "address",
2270
+ internalType: "address"
2271
+ }
2272
+ ],
2273
+ outputs: [
2274
+ {
2275
+ name: "",
2276
+ type: "uint256[]",
2277
+ internalType: "uint256[]"
2278
+ }
2279
+ ],
2280
+ stateMutability: "view"
2281
+ },
2282
+ {
2283
+ type: "function",
2284
+ name: "owner",
2285
+ inputs: [],
2286
+ outputs: [
2287
+ {
2288
+ name: "",
2289
+ type: "address",
2290
+ internalType: "address"
2291
+ }
2292
+ ],
2293
+ stateMutability: "view"
2294
+ },
2295
+ {
2296
+ type: "function",
2297
+ name: "refundEscrow",
2298
+ inputs: [
2299
+ {
2300
+ name: "escrowId",
2301
+ type: "uint256",
2302
+ internalType: "uint256"
2303
+ }
2304
+ ],
2305
+ outputs: [],
2306
+ stateMutability: "nonpayable"
2307
+ },
2308
+ {
2309
+ type: "function",
2310
+ name: "releaseEscrow",
2311
+ inputs: [
2312
+ {
2313
+ name: "escrowId",
2314
+ type: "uint256",
2315
+ internalType: "uint256"
2316
+ }
2317
+ ],
2318
+ outputs: [],
2319
+ stateMutability: "nonpayable"
2320
+ },
2321
+ {
2322
+ type: "function",
2323
+ name: "renounceOwnership",
2324
+ inputs: [],
2325
+ outputs: [],
2326
+ stateMutability: "nonpayable"
2327
+ },
2328
+ {
2329
+ type: "function",
2330
+ name: "resolveDispute",
2331
+ inputs: [
2332
+ {
2333
+ name: "escrowId",
2334
+ type: "uint256",
2335
+ internalType: "uint256"
2336
+ },
2337
+ {
2338
+ name: "payerPercent",
2339
+ type: "uint256",
2340
+ internalType: "uint256"
2341
+ }
2342
+ ],
2343
+ outputs: [],
2344
+ stateMutability: "nonpayable"
2345
+ },
2346
+ {
2347
+ type: "function",
2348
+ name: "transferOwnership",
2349
+ inputs: [
2350
+ {
2351
+ name: "newOwner",
2352
+ type: "address",
2353
+ internalType: "address"
2354
+ }
2355
+ ],
2356
+ outputs: [],
2357
+ stateMutability: "nonpayable"
2358
+ },
2359
+ {
2360
+ type: "event",
2361
+ name: "EscrowCreated",
2362
+ inputs: [
2363
+ {
2364
+ name: "escrowId",
2365
+ type: "uint256",
2366
+ indexed: true,
2367
+ internalType: "uint256"
2368
+ },
2369
+ {
2370
+ name: "payer",
2371
+ type: "address",
2372
+ indexed: true,
2373
+ internalType: "address"
2374
+ },
2375
+ {
2376
+ name: "provider",
2377
+ type: "address",
2378
+ indexed: true,
2379
+ internalType: "address"
2380
+ },
2381
+ {
2382
+ name: "amount",
2383
+ type: "uint256",
2384
+ indexed: false,
2385
+ internalType: "uint256"
2386
+ }
2387
+ ],
2388
+ anonymous: false
2389
+ },
2390
+ {
2391
+ type: "event",
2392
+ name: "EscrowDisputed",
2393
+ inputs: [
2394
+ {
2395
+ name: "escrowId",
2396
+ type: "uint256",
2397
+ indexed: true,
2398
+ internalType: "uint256"
2399
+ },
2400
+ {
2401
+ name: "disputedBy",
2402
+ type: "address",
2403
+ indexed: false,
2404
+ internalType: "address"
2405
+ }
2406
+ ],
2407
+ anonymous: false
2408
+ },
2409
+ {
2410
+ type: "event",
2411
+ name: "EscrowFunded",
2412
+ inputs: [
2413
+ {
2414
+ name: "escrowId",
2415
+ type: "uint256",
2416
+ indexed: true,
2417
+ internalType: "uint256"
2418
+ }
2419
+ ],
2420
+ anonymous: false
2421
+ },
2422
+ {
2423
+ type: "event",
2424
+ name: "EscrowRefunded",
2425
+ inputs: [
2426
+ {
2427
+ name: "escrowId",
2428
+ type: "uint256",
2429
+ indexed: true,
2430
+ internalType: "uint256"
2431
+ }
2432
+ ],
2433
+ anonymous: false
2434
+ },
2435
+ {
2436
+ type: "event",
2437
+ name: "EscrowReleased",
2438
+ inputs: [
2439
+ {
2440
+ name: "escrowId",
2441
+ type: "uint256",
2442
+ indexed: true,
2443
+ internalType: "uint256"
2444
+ }
2445
+ ],
2446
+ anonymous: false
2447
+ },
2448
+ {
2449
+ type: "event",
2450
+ name: "EscrowResolved",
2451
+ inputs: [
2452
+ {
2453
+ name: "escrowId",
2454
+ type: "uint256",
2455
+ indexed: true,
2456
+ internalType: "uint256"
2457
+ },
2458
+ {
2459
+ name: "payerAmount",
2460
+ type: "uint256",
2461
+ indexed: false,
2462
+ internalType: "uint256"
2463
+ },
2464
+ {
2465
+ name: "providerAmount",
2466
+ type: "uint256",
2467
+ indexed: false,
2468
+ internalType: "uint256"
2469
+ }
2470
+ ],
2471
+ anonymous: false
2472
+ },
2473
+ {
2474
+ type: "event",
2475
+ name: "OwnershipTransferred",
2476
+ inputs: [
2477
+ {
2478
+ name: "previousOwner",
2479
+ type: "address",
2480
+ indexed: true,
2481
+ internalType: "address"
2482
+ },
2483
+ {
2484
+ name: "newOwner",
2485
+ type: "address",
2486
+ indexed: true,
2487
+ internalType: "address"
2488
+ }
2489
+ ],
2490
+ anonymous: false
2491
+ },
2492
+ {
2493
+ type: "error",
2494
+ name: "DeadlineNotReached",
2495
+ inputs: [
2496
+ {
2497
+ name: "escrowId",
2498
+ type: "uint256",
2499
+ internalType: "uint256"
2500
+ }
2501
+ ]
2502
+ },
2503
+ {
2504
+ type: "error",
2505
+ name: "EscrowNotFound",
2506
+ inputs: [
2507
+ {
2508
+ name: "escrowId",
2509
+ type: "uint256",
2510
+ internalType: "uint256"
2511
+ }
2512
+ ]
2513
+ },
2514
+ {
2515
+ type: "error",
2516
+ name: "InvalidDeadline",
2517
+ inputs: []
2518
+ },
2519
+ {
2520
+ type: "error",
2521
+ name: "InvalidPercent",
2522
+ inputs: []
2523
+ },
2524
+ {
2525
+ type: "error",
2526
+ name: "InvalidStatus",
2527
+ inputs: [
2528
+ {
2529
+ name: "escrowId",
2530
+ type: "uint256",
2531
+ internalType: "uint256"
2532
+ },
2533
+ {
2534
+ name: "current",
2535
+ type: "uint8",
2536
+ internalType: "enum IEscrow.EscrowStatus"
2537
+ },
2538
+ {
2539
+ name: "expected",
2540
+ type: "uint8",
2541
+ internalType: "enum IEscrow.EscrowStatus"
2542
+ }
2543
+ ]
2544
+ },
2545
+ {
2546
+ type: "error",
2547
+ name: "NotParty",
2548
+ inputs: [
2549
+ {
2550
+ name: "escrowId",
2551
+ type: "uint256",
2552
+ internalType: "uint256"
2553
+ }
2554
+ ]
2555
+ },
2556
+ {
2557
+ type: "error",
2558
+ name: "NotPayer",
2559
+ inputs: [
2560
+ {
2561
+ name: "escrowId",
2562
+ type: "uint256",
2563
+ internalType: "uint256"
2564
+ }
2565
+ ]
2566
+ },
2567
+ {
2568
+ type: "error",
2569
+ name: "NotProvider",
2570
+ inputs: [
2571
+ {
2572
+ name: "escrowId",
2573
+ type: "uint256",
2574
+ internalType: "uint256"
2575
+ }
2576
+ ]
2577
+ },
2578
+ {
2579
+ type: "error",
2580
+ name: "OwnableInvalidOwner",
2581
+ inputs: [
2582
+ {
2583
+ name: "owner",
2584
+ type: "address",
2585
+ internalType: "address"
2586
+ }
2587
+ ]
2588
+ },
2589
+ {
2590
+ type: "error",
2591
+ name: "OwnableUnauthorizedAccount",
2592
+ inputs: [
2593
+ {
2594
+ name: "account",
2595
+ type: "address",
2596
+ internalType: "address"
2597
+ }
2598
+ ]
2599
+ },
2600
+ {
2601
+ type: "error",
2602
+ name: "ReentrancyGuardReentrantCall",
2603
+ inputs: []
2604
+ },
2605
+ {
2606
+ type: "error",
2607
+ name: "TransferFailed",
2608
+ inputs: [
2609
+ {
2610
+ name: "to",
2611
+ type: "address",
2612
+ internalType: "address"
2613
+ },
2614
+ {
2615
+ name: "amount",
2616
+ type: "uint256",
2617
+ internalType: "uint256"
2618
+ }
2619
+ ]
2620
+ },
2621
+ {
2622
+ type: "error",
2623
+ name: "ZeroAmount",
2624
+ inputs: []
2625
+ }
2626
+ ];
2627
+
2628
+ // src/modules/escrow.ts
2629
+ var EscrowModule = class {
2630
+ constructor(address, signerOrProvider) {
2631
+ this.contract = null;
2632
+ if (address && address !== "") {
2633
+ this.contract = new ethers.ethers.Contract(address, Escrow_default, signerOrProvider);
2634
+ }
2635
+ }
2636
+ getContract() {
2637
+ if (!this.contract) {
2638
+ throw new Error("Escrow contract address not configured");
2639
+ }
2640
+ return this.contract;
2641
+ }
2642
+ async createEscrow(serviceId, provider, deadline, description, amount) {
2643
+ const contract = this.getContract();
2644
+ const tx = await contract.createEscrow(serviceId, provider, deadline, description, { value: amount });
2645
+ const receipt = await tx.wait();
2646
+ return { txHash: receipt.hash, escrowId: 0n };
2647
+ }
2648
+ async releaseEscrow(escrowId) {
2649
+ const contract = this.getContract();
2650
+ const tx = await contract.releaseEscrow(escrowId);
2651
+ const receipt = await tx.wait();
2652
+ return receipt.hash;
2653
+ }
2654
+ async disputeEscrow(escrowId) {
2655
+ const contract = this.getContract();
2656
+ const tx = await contract.disputeEscrow(escrowId);
2657
+ const receipt = await tx.wait();
2658
+ return receipt.hash;
2659
+ }
2660
+ async refundEscrow(escrowId) {
2661
+ const contract = this.getContract();
2662
+ const tx = await contract.refundEscrow(escrowId);
2663
+ const receipt = await tx.wait();
2664
+ return receipt.hash;
2665
+ }
2666
+ async getEscrow(escrowId) {
2667
+ const contract = this.getContract();
2668
+ const e = await contract.getEscrow(escrowId);
2669
+ return {
2670
+ escrowId: e.escrowId,
2671
+ serviceId: e.serviceId,
2672
+ payer: e.payer,
2673
+ provider: e.provider,
2674
+ amount: e.amount,
2675
+ status: Number(e.status),
2676
+ createdAt: e.createdAt,
2677
+ deadline: e.deadline,
2678
+ description: e.description
2679
+ };
2680
+ }
2681
+ async getUserEscrows(address) {
2682
+ const contract = this.getContract();
2683
+ return contract.getUserEscrows(address);
2684
+ }
2685
+ };
2686
+
2687
+ // src/abi/AgentWallet.json
2688
+ var AgentWallet_default = [
2689
+ {
2690
+ type: "constructor",
2691
+ inputs: [
2692
+ {
2693
+ name: "owner_",
2694
+ type: "address",
2695
+ internalType: "address"
2696
+ },
2697
+ {
2698
+ name: "dailyLimit",
2699
+ type: "uint256",
2700
+ internalType: "uint256"
2701
+ }
2702
+ ],
2703
+ stateMutability: "nonpayable"
2704
+ },
2705
+ {
2706
+ type: "receive",
2707
+ stateMutability: "payable"
2708
+ },
2709
+ {
2710
+ type: "function",
2711
+ name: "authorizeAgent",
2712
+ inputs: [
2713
+ {
2714
+ name: "agent",
2715
+ type: "address",
2716
+ internalType: "address"
2717
+ }
2718
+ ],
2719
+ outputs: [],
2720
+ stateMutability: "nonpayable"
2721
+ },
2722
+ {
2723
+ type: "function",
2724
+ name: "execute",
2725
+ inputs: [
2726
+ {
2727
+ name: "to",
2728
+ type: "address",
2729
+ internalType: "address"
2730
+ },
2731
+ {
2732
+ name: "value",
2733
+ type: "uint256",
2734
+ internalType: "uint256"
2735
+ },
2736
+ {
2737
+ name: "data",
2738
+ type: "bytes",
2739
+ internalType: "bytes"
2740
+ }
2741
+ ],
2742
+ outputs: [
2743
+ {
2744
+ name: "",
2745
+ type: "bytes",
2746
+ internalType: "bytes"
2747
+ }
2748
+ ],
2749
+ stateMutability: "nonpayable"
2750
+ },
2751
+ {
2752
+ type: "function",
2753
+ name: "getDailySpendingLimit",
2754
+ inputs: [],
2755
+ outputs: [
2756
+ {
2757
+ name: "",
2758
+ type: "uint256",
2759
+ internalType: "uint256"
2760
+ }
2761
+ ],
2762
+ stateMutability: "view"
2763
+ },
2764
+ {
2765
+ type: "function",
2766
+ name: "getDailySpent",
2767
+ inputs: [],
2768
+ outputs: [
2769
+ {
2770
+ name: "",
2771
+ type: "uint256",
2772
+ internalType: "uint256"
2773
+ }
2774
+ ],
2775
+ stateMutability: "view"
2776
+ },
2777
+ {
2778
+ type: "function",
2779
+ name: "getOwner",
2780
+ inputs: [],
2781
+ outputs: [
2782
+ {
2783
+ name: "",
2784
+ type: "address",
2785
+ internalType: "address"
2786
+ }
2787
+ ],
2788
+ stateMutability: "view"
2789
+ },
2790
+ {
2791
+ type: "function",
2792
+ name: "getRemainingDailyAllowance",
2793
+ inputs: [],
2794
+ outputs: [
2795
+ {
2796
+ name: "",
2797
+ type: "uint256",
2798
+ internalType: "uint256"
2799
+ }
2800
+ ],
2801
+ stateMutability: "view"
2802
+ },
2803
+ {
2804
+ type: "function",
2805
+ name: "isAuthorizedAgent",
2806
+ inputs: [
2807
+ {
2808
+ name: "agent",
2809
+ type: "address",
2810
+ internalType: "address"
2811
+ }
2812
+ ],
2813
+ outputs: [
2814
+ {
2815
+ name: "",
2816
+ type: "bool",
2817
+ internalType: "bool"
2818
+ }
2819
+ ],
2820
+ stateMutability: "view"
2821
+ },
2822
+ {
2823
+ type: "function",
2824
+ name: "revokeAgent",
2825
+ inputs: [
2826
+ {
2827
+ name: "agent",
2828
+ type: "address",
2829
+ internalType: "address"
2830
+ }
2831
+ ],
2832
+ outputs: [],
2833
+ stateMutability: "nonpayable"
2834
+ },
2835
+ {
2836
+ type: "function",
2837
+ name: "setDailySpendingLimit",
2838
+ inputs: [
2839
+ {
2840
+ name: "limit",
2841
+ type: "uint256",
2842
+ internalType: "uint256"
2843
+ }
2844
+ ],
2845
+ outputs: [],
2846
+ stateMutability: "nonpayable"
2847
+ },
2848
+ {
2849
+ type: "function",
2850
+ name: "withdrawFunds",
2851
+ inputs: [
2852
+ {
2853
+ name: "amount",
2854
+ type: "uint256",
2855
+ internalType: "uint256"
2856
+ }
2857
+ ],
2858
+ outputs: [],
2859
+ stateMutability: "nonpayable"
2860
+ },
2861
+ {
2862
+ type: "event",
2863
+ name: "AgentAuthorized",
2864
+ inputs: [
2865
+ {
2866
+ name: "agent",
2867
+ type: "address",
2868
+ indexed: true,
2869
+ internalType: "address"
2870
+ }
2871
+ ],
2872
+ anonymous: false
2873
+ },
2874
+ {
2875
+ type: "event",
2876
+ name: "AgentRevoked",
2877
+ inputs: [
2878
+ {
2879
+ name: "agent",
2880
+ type: "address",
2881
+ indexed: true,
2882
+ internalType: "address"
2883
+ }
2884
+ ],
2885
+ anonymous: false
2886
+ },
2887
+ {
2888
+ type: "event",
2889
+ name: "Deposited",
2890
+ inputs: [
2891
+ {
2892
+ name: "from",
2893
+ type: "address",
2894
+ indexed: true,
2895
+ internalType: "address"
2896
+ },
2897
+ {
2898
+ name: "amount",
2899
+ type: "uint256",
2900
+ indexed: false,
2901
+ internalType: "uint256"
2902
+ }
2903
+ ],
2904
+ anonymous: false
2905
+ },
2906
+ {
2907
+ type: "event",
2908
+ name: "Executed",
2909
+ inputs: [
2910
+ {
2911
+ name: "to",
2912
+ type: "address",
2913
+ indexed: true,
2914
+ internalType: "address"
2915
+ },
2916
+ {
2917
+ name: "value",
2918
+ type: "uint256",
2919
+ indexed: false,
2920
+ internalType: "uint256"
2921
+ },
2922
+ {
2923
+ name: "data",
2924
+ type: "bytes",
2925
+ indexed: false,
2926
+ internalType: "bytes"
2927
+ }
2928
+ ],
2929
+ anonymous: false
2930
+ },
2931
+ {
2932
+ type: "event",
2933
+ name: "SpendingLimitSet",
2934
+ inputs: [
2935
+ {
2936
+ name: "dailyLimit",
2937
+ type: "uint256",
2938
+ indexed: false,
2939
+ internalType: "uint256"
2940
+ }
2941
+ ],
2942
+ anonymous: false
2943
+ },
2944
+ {
2945
+ type: "event",
2946
+ name: "Withdrawn",
2947
+ inputs: [
2948
+ {
2949
+ name: "to",
2950
+ type: "address",
2951
+ indexed: true,
2952
+ internalType: "address"
2953
+ },
2954
+ {
2955
+ name: "amount",
2956
+ type: "uint256",
2957
+ indexed: false,
2958
+ internalType: "uint256"
2959
+ }
2960
+ ],
2961
+ anonymous: false
2962
+ },
2963
+ {
2964
+ type: "error",
2965
+ name: "ExceedsDailyLimit",
2966
+ inputs: [
2967
+ {
2968
+ name: "requested",
2969
+ type: "uint256",
2970
+ internalType: "uint256"
2971
+ },
2972
+ {
2973
+ name: "remaining",
2974
+ type: "uint256",
2975
+ internalType: "uint256"
2976
+ }
2977
+ ]
2978
+ },
2979
+ {
2980
+ type: "error",
2981
+ name: "ExecutionFailed",
2982
+ inputs: [
2983
+ {
2984
+ name: "to",
2985
+ type: "address",
2986
+ internalType: "address"
2987
+ },
2988
+ {
2989
+ name: "data",
2990
+ type: "bytes",
2991
+ internalType: "bytes"
2992
+ }
2993
+ ]
2994
+ },
2995
+ {
2996
+ type: "error",
2997
+ name: "InsufficientFunds",
2998
+ inputs: [
2999
+ {
3000
+ name: "required",
3001
+ type: "uint256",
3002
+ internalType: "uint256"
3003
+ },
3004
+ {
3005
+ name: "available",
3006
+ type: "uint256",
3007
+ internalType: "uint256"
3008
+ }
3009
+ ]
3010
+ },
3011
+ {
3012
+ type: "error",
3013
+ name: "NotAuthorized",
3014
+ inputs: []
3015
+ },
3016
+ {
3017
+ type: "error",
3018
+ name: "NotOwner",
3019
+ inputs: []
3020
+ },
3021
+ {
3022
+ type: "error",
3023
+ name: "ReentrancyGuardReentrantCall",
3024
+ inputs: []
3025
+ },
3026
+ {
3027
+ type: "error",
3028
+ name: "TransferFailed",
3029
+ inputs: [
3030
+ {
3031
+ name: "to",
3032
+ type: "address",
3033
+ internalType: "address"
3034
+ },
3035
+ {
3036
+ name: "amount",
3037
+ type: "uint256",
3038
+ internalType: "uint256"
3039
+ }
3040
+ ]
3041
+ },
3042
+ {
3043
+ type: "error",
3044
+ name: "ZeroAmount",
3045
+ inputs: []
3046
+ }
3047
+ ];
3048
+
3049
+ // src/abi/AgentWalletFactory.json
3050
+ var AgentWalletFactory_default = [
3051
+ {
3052
+ type: "function",
3053
+ name: "createWallet",
3054
+ inputs: [
3055
+ {
3056
+ name: "dailyLimit",
3057
+ type: "uint256",
3058
+ internalType: "uint256"
3059
+ }
3060
+ ],
3061
+ outputs: [
3062
+ {
3063
+ name: "wallet",
3064
+ type: "address",
3065
+ internalType: "address"
3066
+ }
3067
+ ],
3068
+ stateMutability: "nonpayable"
3069
+ },
3070
+ {
3071
+ type: "function",
3072
+ name: "getWalletCount",
3073
+ inputs: [
3074
+ {
3075
+ name: "owner",
3076
+ type: "address",
3077
+ internalType: "address"
3078
+ }
3079
+ ],
3080
+ outputs: [
3081
+ {
3082
+ name: "",
3083
+ type: "uint256",
3084
+ internalType: "uint256"
3085
+ }
3086
+ ],
3087
+ stateMutability: "view"
3088
+ },
3089
+ {
3090
+ type: "function",
3091
+ name: "getWallets",
3092
+ inputs: [
3093
+ {
3094
+ name: "owner",
3095
+ type: "address",
3096
+ internalType: "address"
3097
+ }
3098
+ ],
3099
+ outputs: [
3100
+ {
3101
+ name: "",
3102
+ type: "address[]",
3103
+ internalType: "address[]"
3104
+ }
3105
+ ],
3106
+ stateMutability: "view"
3107
+ },
3108
+ {
3109
+ type: "event",
3110
+ name: "WalletCreated",
3111
+ inputs: [
3112
+ {
3113
+ name: "owner",
3114
+ type: "address",
3115
+ indexed: true,
3116
+ internalType: "address"
3117
+ },
3118
+ {
3119
+ name: "wallet",
3120
+ type: "address",
3121
+ indexed: true,
3122
+ internalType: "address"
3123
+ },
3124
+ {
3125
+ name: "dailyLimit",
3126
+ type: "uint256",
3127
+ indexed: false,
3128
+ internalType: "uint256"
3129
+ }
3130
+ ],
3131
+ anonymous: false
3132
+ }
3133
+ ];
3134
+
3135
+ // src/modules/wallet.ts
3136
+ var WalletModule = class {
3137
+ constructor(factoryAddress, signerOrProvider) {
3138
+ this.factoryContract = null;
3139
+ if (factoryAddress && factoryAddress !== "") {
3140
+ this.factoryContract = new ethers.ethers.Contract(factoryAddress, AgentWalletFactory_default, signerOrProvider);
3141
+ }
3142
+ this.signerOrProvider = signerOrProvider;
3143
+ }
3144
+ getContract() {
3145
+ if (!this.factoryContract) {
3146
+ throw new Error("AgentWalletFactory contract address not configured");
3147
+ }
3148
+ return this.factoryContract;
3149
+ }
3150
+ async createWallet(dailyLimit) {
3151
+ const contract = this.getContract();
3152
+ const tx = await contract.createWallet(dailyLimit);
3153
+ const receipt = await tx.wait();
3154
+ const event = receipt.logs.find(
3155
+ (log) => contract.interface.parseLog(log)?.name === "WalletCreated"
3156
+ );
3157
+ const parsed = event ? contract.interface.parseLog(event) : null;
3158
+ const walletAddress = parsed ? parsed.args[1] : "";
3159
+ return { txHash: receipt.hash, walletAddress };
3160
+ }
3161
+ async getWallets(owner) {
3162
+ const contract = this.getContract();
3163
+ return contract.getWallets(owner);
3164
+ }
3165
+ getWalletInstance(walletAddress) {
3166
+ return new AgentWalletClient(walletAddress, this.signerOrProvider);
3167
+ }
3168
+ };
3169
+ var AgentWalletClient = class {
3170
+ constructor(address, signerOrProvider) {
3171
+ this.contract = new ethers.ethers.Contract(address, AgentWallet_default, signerOrProvider);
3172
+ }
3173
+ async execute(to, value, data = "0x") {
3174
+ const tx = await this.contract.execute(to, value, data);
3175
+ const receipt = await tx.wait();
3176
+ return receipt.hash;
3177
+ }
3178
+ async setDailySpendingLimit(limit) {
3179
+ const tx = await this.contract.setDailySpendingLimit(limit);
3180
+ const receipt = await tx.wait();
3181
+ return receipt.hash;
3182
+ }
3183
+ async authorizeAgent(agent) {
3184
+ const tx = await this.contract.authorizeAgent(agent);
3185
+ const receipt = await tx.wait();
3186
+ return receipt.hash;
3187
+ }
3188
+ async revokeAgent(agent) {
3189
+ const tx = await this.contract.revokeAgent(agent);
3190
+ const receipt = await tx.wait();
3191
+ return receipt.hash;
3192
+ }
3193
+ async withdrawFunds(amount) {
3194
+ const tx = await this.contract.withdrawFunds(amount);
3195
+ const receipt = await tx.wait();
3196
+ return receipt.hash;
3197
+ }
3198
+ async deposit(amount) {
3199
+ const signer = this.contract.runner;
3200
+ const tx = await signer.sendTransaction({
3201
+ to: await this.contract.getAddress(),
3202
+ value: amount
3203
+ });
3204
+ const receipt = await tx.wait();
3205
+ return receipt.hash;
3206
+ }
3207
+ async isAuthorizedAgent(agent) {
3208
+ return this.contract.isAuthorizedAgent(agent);
3209
+ }
3210
+ async getDailySpendingLimit() {
3211
+ return this.contract.getDailySpendingLimit();
3212
+ }
3213
+ async getDailySpent() {
3214
+ return this.contract.getDailySpent();
3215
+ }
3216
+ async getRemainingDailyAllowance() {
3217
+ return this.contract.getRemainingDailyAllowance();
3218
+ }
3219
+ async getOwner() {
3220
+ return this.contract.getOwner();
3221
+ }
3222
+ };
3223
+
3224
+ // src/utils/constants.ts
3225
+ var MONAD_TESTNET_CHAIN_ID = 10143;
3226
+ var MONAD_TESTNET_RPC = "https://testnet-rpc.monad.xyz/";
3227
+ var DEFAULT_CONTRACTS = {
3228
+ local: {
3229
+ serviceRegistry: "",
3230
+ paymentManager: "",
3231
+ subscriptionManager: "",
3232
+ escrow: "",
3233
+ agentWalletFactory: ""
3234
+ },
3235
+ testnet: {
3236
+ serviceRegistry: "",
3237
+ paymentManager: "",
3238
+ subscriptionManager: "",
3239
+ escrow: "",
3240
+ agentWalletFactory: ""
3241
+ }
3242
+ };
3243
+
3244
+ // src/AgentXPayClient.ts
3245
+ var AgentXPayClient = class {
3246
+ constructor(config) {
3247
+ this.signer = null;
3248
+ const rpcUrl = config.rpcUrl || MONAD_TESTNET_RPC;
3249
+ this.provider = new ethers.ethers.JsonRpcProvider(rpcUrl);
3250
+ if (config.signer) {
3251
+ this.signer = config.signer;
3252
+ } else if (config.privateKey) {
3253
+ this.signer = new ethers.ethers.Wallet(config.privateKey, this.provider);
3254
+ }
3255
+ const signerOrProvider = this.signer || this.provider;
3256
+ const network = config.network || "testnet";
3257
+ const defaultContracts = DEFAULT_CONTRACTS[network] || {};
3258
+ const contracts = {
3259
+ serviceRegistry: config.contracts?.serviceRegistry || defaultContracts.serviceRegistry || "",
3260
+ paymentManager: config.contracts?.paymentManager || defaultContracts.paymentManager || "",
3261
+ subscriptionManager: config.contracts?.subscriptionManager || defaultContracts.subscriptionManager || "",
3262
+ escrow: config.contracts?.escrow || defaultContracts.escrow || "",
3263
+ agentWalletFactory: config.contracts?.agentWalletFactory || defaultContracts.agentWalletFactory || ""
3264
+ };
3265
+ if (!contracts.serviceRegistry) {
3266
+ throw new Error("ServiceRegistry address is required");
3267
+ }
3268
+ this.services = new ServicesModule(
3269
+ contracts.serviceRegistry,
3270
+ signerOrProvider
3271
+ );
3272
+ this.payments = new PaymentsModule(
3273
+ contracts.paymentManager,
3274
+ signerOrProvider
3275
+ );
3276
+ this.subscriptions = new SubscriptionsModule(
3277
+ contracts.subscriptionManager,
3278
+ signerOrProvider
3279
+ );
3280
+ this.escrow = new EscrowModule(
3281
+ contracts.escrow,
3282
+ signerOrProvider
3283
+ );
3284
+ this.wallet = new WalletModule(
3285
+ contracts.agentWalletFactory,
3286
+ signerOrProvider
3287
+ );
3288
+ }
3289
+ async discoverServices(filter) {
3290
+ return this.services.discoverServices(filter);
3291
+ }
3292
+ async payAndCall(serviceId, amount) {
3293
+ const result = await this.payments.payPerUse(serviceId, amount);
3294
+ return result.txHash;
3295
+ }
3296
+ async subscribe(serviceId, planId, amount) {
3297
+ return this.subscriptions.subscribe(serviceId, planId, amount);
3298
+ }
3299
+ /**
3300
+ * x402-aware fetch: automatically handles HTTP 402 Payment Required responses
3301
+ */
3302
+ async fetch(url, options) {
3303
+ const autoPayment = options?.autoPayment ?? true;
3304
+ const maxRetries = options?.maxRetries ?? 1;
3305
+ let response = await globalThis.fetch(url, options);
3306
+ if (response.status === 402 && autoPayment) {
3307
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
3308
+ const paymentInfo = this._parsePaymentHeaders(response);
3309
+ if (!paymentInfo) throw new Error("Invalid 402 response: missing payment headers");
3310
+ const result = await this.payments.payPerUse(
3311
+ BigInt(paymentInfo.serviceId),
3312
+ BigInt(paymentInfo.amount)
3313
+ );
3314
+ const retryHeaders = new Headers(options?.headers);
3315
+ retryHeaders.set("X-Payment-TxHash", result.txHash);
3316
+ retryHeaders.set("X-Payment-ChainId", paymentInfo.chainId);
3317
+ response = await globalThis.fetch(url, {
3318
+ ...options,
3319
+ headers: retryHeaders
3320
+ });
3321
+ if (response.status !== 402) break;
3322
+ }
3323
+ }
3324
+ return response;
3325
+ }
3326
+ _parsePaymentHeaders(response) {
3327
+ const address = response.headers.get("X-Payment-Address");
3328
+ const amount = response.headers.get("X-Payment-Amount");
3329
+ const token = response.headers.get("X-Payment-Token") || "native";
3330
+ const serviceId = response.headers.get("X-Payment-ServiceId");
3331
+ const chainId = response.headers.get("X-Payment-ChainId") || "10143";
3332
+ if (!address || !amount || !serviceId) return null;
3333
+ return { address, amount, token, serviceId, chainId };
3334
+ }
3335
+ getProvider() {
3336
+ return this.provider;
3337
+ }
3338
+ getSigner() {
3339
+ return this.signer;
3340
+ }
3341
+ };
3342
+
3343
+ // src/types/index.ts
3344
+ var EscrowStatus = /* @__PURE__ */ ((EscrowStatus2) => {
3345
+ EscrowStatus2[EscrowStatus2["Created"] = 0] = "Created";
3346
+ EscrowStatus2[EscrowStatus2["Funded"] = 1] = "Funded";
3347
+ EscrowStatus2[EscrowStatus2["Released"] = 2] = "Released";
3348
+ EscrowStatus2[EscrowStatus2["Disputed"] = 3] = "Disputed";
3349
+ EscrowStatus2[EscrowStatus2["Refunded"] = 4] = "Refunded";
3350
+ EscrowStatus2[EscrowStatus2["Resolved"] = 5] = "Resolved";
3351
+ return EscrowStatus2;
3352
+ })(EscrowStatus || {});
3353
+ function shortenAddress(address, chars = 4) {
3354
+ return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
3355
+ }
3356
+ function formatEther(wei) {
3357
+ return ethers.ethers.formatEther(wei);
3358
+ }
3359
+ function parseEther(ether) {
3360
+ return ethers.ethers.parseEther(ether);
3361
+ }
3362
+ function isValidAddress(address) {
3363
+ return ethers.ethers.isAddress(address);
3364
+ }
3365
+
3366
+ exports.AgentWalletClient = AgentWalletClient;
3367
+ exports.AgentXPayClient = AgentXPayClient;
3368
+ exports.DEFAULT_CONTRACTS = DEFAULT_CONTRACTS;
3369
+ exports.EscrowModule = EscrowModule;
3370
+ exports.EscrowStatus = EscrowStatus;
3371
+ exports.MONAD_TESTNET_CHAIN_ID = MONAD_TESTNET_CHAIN_ID;
3372
+ exports.MONAD_TESTNET_RPC = MONAD_TESTNET_RPC;
3373
+ exports.PaymentsModule = PaymentsModule;
3374
+ exports.ServicesModule = ServicesModule;
3375
+ exports.SubscriptionsModule = SubscriptionsModule;
3376
+ exports.WalletModule = WalletModule;
3377
+ exports.formatEther = formatEther;
3378
+ exports.isValidAddress = isValidAddress;
3379
+ exports.parseEther = parseEther;
3380
+ exports.shortenAddress = shortenAddress;
3381
+ //# sourceMappingURL=index.js.map
3382
+ //# sourceMappingURL=index.js.map