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