@gitmyabi/dec 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,798 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Decentr_json = exports.Decentr_jsonAbi = void 0;
4
+ const viem_1 = require("viem");
5
+ /**
6
+ * Decentr_json ABI
7
+ *
8
+ * This ABI is typed using viem's type system for full type safety.
9
+ */
10
+ exports.Decentr_jsonAbi = [
11
+ {
12
+ "inputs": [
13
+ {
14
+ "internalType": "address",
15
+ "name": "saleAddress",
16
+ "type": "address"
17
+ }
18
+ ],
19
+ "stateMutability": "nonpayable",
20
+ "type": "constructor"
21
+ },
22
+ {
23
+ "anonymous": false,
24
+ "inputs": [
25
+ {
26
+ "indexed": true,
27
+ "internalType": "address",
28
+ "name": "owner",
29
+ "type": "address"
30
+ },
31
+ {
32
+ "indexed": true,
33
+ "internalType": "address",
34
+ "name": "spender",
35
+ "type": "address"
36
+ },
37
+ {
38
+ "indexed": false,
39
+ "internalType": "uint256",
40
+ "name": "value",
41
+ "type": "uint256"
42
+ }
43
+ ],
44
+ "name": "Approval",
45
+ "type": "event"
46
+ },
47
+ {
48
+ "anonymous": false,
49
+ "inputs": [
50
+ {
51
+ "indexed": false,
52
+ "internalType": "address",
53
+ "name": "account",
54
+ "type": "address"
55
+ }
56
+ ],
57
+ "name": "Paused",
58
+ "type": "event"
59
+ },
60
+ {
61
+ "anonymous": false,
62
+ "inputs": [
63
+ {
64
+ "indexed": false,
65
+ "internalType": "address",
66
+ "name": "minter",
67
+ "type": "address"
68
+ }
69
+ ],
70
+ "name": "TokenMinterUpdated",
71
+ "type": "event"
72
+ },
73
+ {
74
+ "anonymous": false,
75
+ "inputs": [
76
+ {
77
+ "indexed": true,
78
+ "internalType": "address",
79
+ "name": "from",
80
+ "type": "address"
81
+ },
82
+ {
83
+ "indexed": true,
84
+ "internalType": "address",
85
+ "name": "to",
86
+ "type": "address"
87
+ },
88
+ {
89
+ "indexed": false,
90
+ "internalType": "uint256",
91
+ "name": "value",
92
+ "type": "uint256"
93
+ }
94
+ ],
95
+ "name": "Transfer",
96
+ "type": "event"
97
+ },
98
+ {
99
+ "anonymous": false,
100
+ "inputs": [
101
+ {
102
+ "indexed": false,
103
+ "internalType": "address",
104
+ "name": "account",
105
+ "type": "address"
106
+ }
107
+ ],
108
+ "name": "Unpaused",
109
+ "type": "event"
110
+ },
111
+ {
112
+ "inputs": [
113
+ {
114
+ "internalType": "address",
115
+ "name": "owner",
116
+ "type": "address"
117
+ },
118
+ {
119
+ "internalType": "address",
120
+ "name": "spender",
121
+ "type": "address"
122
+ }
123
+ ],
124
+ "name": "allowance",
125
+ "outputs": [
126
+ {
127
+ "internalType": "uint256",
128
+ "name": "",
129
+ "type": "uint256"
130
+ }
131
+ ],
132
+ "stateMutability": "view",
133
+ "type": "function"
134
+ },
135
+ {
136
+ "inputs": [
137
+ {
138
+ "internalType": "address",
139
+ "name": "spender",
140
+ "type": "address"
141
+ },
142
+ {
143
+ "internalType": "uint256",
144
+ "name": "amount",
145
+ "type": "uint256"
146
+ }
147
+ ],
148
+ "name": "approve",
149
+ "outputs": [
150
+ {
151
+ "internalType": "bool",
152
+ "name": "",
153
+ "type": "bool"
154
+ }
155
+ ],
156
+ "stateMutability": "nonpayable",
157
+ "type": "function"
158
+ },
159
+ {
160
+ "inputs": [
161
+ {
162
+ "internalType": "address",
163
+ "name": "account",
164
+ "type": "address"
165
+ }
166
+ ],
167
+ "name": "balanceOf",
168
+ "outputs": [
169
+ {
170
+ "internalType": "uint256",
171
+ "name": "",
172
+ "type": "uint256"
173
+ }
174
+ ],
175
+ "stateMutability": "view",
176
+ "type": "function"
177
+ },
178
+ {
179
+ "inputs": [],
180
+ "name": "decimals",
181
+ "outputs": [
182
+ {
183
+ "internalType": "uint8",
184
+ "name": "",
185
+ "type": "uint8"
186
+ }
187
+ ],
188
+ "stateMutability": "view",
189
+ "type": "function"
190
+ },
191
+ {
192
+ "inputs": [
193
+ {
194
+ "internalType": "address",
195
+ "name": "spender",
196
+ "type": "address"
197
+ },
198
+ {
199
+ "internalType": "uint256",
200
+ "name": "subtractedValue",
201
+ "type": "uint256"
202
+ }
203
+ ],
204
+ "name": "decreaseAllowance",
205
+ "outputs": [
206
+ {
207
+ "internalType": "bool",
208
+ "name": "",
209
+ "type": "bool"
210
+ }
211
+ ],
212
+ "stateMutability": "nonpayable",
213
+ "type": "function"
214
+ },
215
+ {
216
+ "inputs": [
217
+ {
218
+ "internalType": "address",
219
+ "name": "spender",
220
+ "type": "address"
221
+ },
222
+ {
223
+ "internalType": "uint256",
224
+ "name": "addedValue",
225
+ "type": "uint256"
226
+ }
227
+ ],
228
+ "name": "increaseAllowance",
229
+ "outputs": [
230
+ {
231
+ "internalType": "bool",
232
+ "name": "",
233
+ "type": "bool"
234
+ }
235
+ ],
236
+ "stateMutability": "nonpayable",
237
+ "type": "function"
238
+ },
239
+ {
240
+ "inputs": [
241
+ {
242
+ "internalType": "address",
243
+ "name": "receiver",
244
+ "type": "address"
245
+ },
246
+ {
247
+ "internalType": "uint256",
248
+ "name": "amount",
249
+ "type": "uint256"
250
+ }
251
+ ],
252
+ "name": "mintToken",
253
+ "outputs": [
254
+ {
255
+ "internalType": "bool",
256
+ "name": "success",
257
+ "type": "bool"
258
+ }
259
+ ],
260
+ "stateMutability": "nonpayable",
261
+ "type": "function"
262
+ },
263
+ {
264
+ "inputs": [],
265
+ "name": "name",
266
+ "outputs": [
267
+ {
268
+ "internalType": "string",
269
+ "name": "",
270
+ "type": "string"
271
+ }
272
+ ],
273
+ "stateMutability": "view",
274
+ "type": "function"
275
+ },
276
+ {
277
+ "inputs": [],
278
+ "name": "pause",
279
+ "outputs": [],
280
+ "stateMutability": "nonpayable",
281
+ "type": "function"
282
+ },
283
+ {
284
+ "inputs": [],
285
+ "name": "paused",
286
+ "outputs": [
287
+ {
288
+ "internalType": "bool",
289
+ "name": "",
290
+ "type": "bool"
291
+ }
292
+ ],
293
+ "stateMutability": "view",
294
+ "type": "function"
295
+ },
296
+ {
297
+ "inputs": [
298
+ {
299
+ "internalType": "address",
300
+ "name": "_minter",
301
+ "type": "address"
302
+ }
303
+ ],
304
+ "name": "setMiter",
305
+ "outputs": [],
306
+ "stateMutability": "nonpayable",
307
+ "type": "function"
308
+ },
309
+ {
310
+ "inputs": [],
311
+ "name": "symbol",
312
+ "outputs": [
313
+ {
314
+ "internalType": "string",
315
+ "name": "",
316
+ "type": "string"
317
+ }
318
+ ],
319
+ "stateMutability": "view",
320
+ "type": "function"
321
+ },
322
+ {
323
+ "inputs": [],
324
+ "name": "totalSupply",
325
+ "outputs": [
326
+ {
327
+ "internalType": "uint256",
328
+ "name": "",
329
+ "type": "uint256"
330
+ }
331
+ ],
332
+ "stateMutability": "view",
333
+ "type": "function"
334
+ },
335
+ {
336
+ "inputs": [
337
+ {
338
+ "internalType": "address",
339
+ "name": "recipient",
340
+ "type": "address"
341
+ },
342
+ {
343
+ "internalType": "uint256",
344
+ "name": "amount",
345
+ "type": "uint256"
346
+ }
347
+ ],
348
+ "name": "transfer",
349
+ "outputs": [
350
+ {
351
+ "internalType": "bool",
352
+ "name": "",
353
+ "type": "bool"
354
+ }
355
+ ],
356
+ "stateMutability": "nonpayable",
357
+ "type": "function"
358
+ },
359
+ {
360
+ "inputs": [
361
+ {
362
+ "internalType": "address",
363
+ "name": "sender",
364
+ "type": "address"
365
+ },
366
+ {
367
+ "internalType": "address",
368
+ "name": "recipient",
369
+ "type": "address"
370
+ },
371
+ {
372
+ "internalType": "uint256",
373
+ "name": "amount",
374
+ "type": "uint256"
375
+ }
376
+ ],
377
+ "name": "transferFrom",
378
+ "outputs": [
379
+ {
380
+ "internalType": "bool",
381
+ "name": "",
382
+ "type": "bool"
383
+ }
384
+ ],
385
+ "stateMutability": "nonpayable",
386
+ "type": "function"
387
+ },
388
+ {
389
+ "inputs": [],
390
+ "name": "unpause",
391
+ "outputs": [],
392
+ "stateMutability": "nonpayable",
393
+ "type": "function"
394
+ }
395
+ ];
396
+ /**
397
+ * Decentr_json Contract Class
398
+ *
399
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
400
+ *
401
+ * @example
402
+ * ```typescript
403
+ * import { createPublicClient, createWalletClient, http } from 'viem';
404
+ * import { mainnet } from 'viem/chains';
405
+ * import { Decentr_json } from 'Decentr_json';
406
+ *
407
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
408
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
409
+ *
410
+ * const contract = new Decentr_json('0x...', { publicClient, walletClient });
411
+ *
412
+ * // Read functions
413
+ * const result = await contract.balanceOf('0x...');
414
+ *
415
+ * // Write functions
416
+ * const hash = await contract.transfer('0x...', 1000n);
417
+ *
418
+ * // Simulate transactions (dry-run)
419
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
420
+ * console.log('Gas estimate:', simulation.request.gas);
421
+ *
422
+ * // Watch events
423
+ * const unwatch = contract.watch.Transfer((event) => {
424
+ * console.log('Transfer event:', event);
425
+ * });
426
+ * ```
427
+ */
428
+ class Decentr_json {
429
+ constructor(address, clients) {
430
+ this.contractAddress = address;
431
+ this.publicClient = clients.publicClient;
432
+ this.contract = (0, viem_1.getContract)({
433
+ address,
434
+ abi: exports.Decentr_jsonAbi,
435
+ client: {
436
+ public: clients.publicClient,
437
+ wallet: clients.walletClient,
438
+ },
439
+ });
440
+ }
441
+ /**
442
+ * Get the contract address
443
+ */
444
+ get address() {
445
+ return this.contractAddress;
446
+ }
447
+ /**
448
+ * Get the underlying viem contract instance
449
+ */
450
+ getContract() {
451
+ return this.contract;
452
+ }
453
+ /**
454
+ * allowance
455
+ * view
456
+ */
457
+ async allowance(owner, spender) {
458
+ return this.contract.read.allowance([owner, spender]);
459
+ }
460
+ /**
461
+ * balanceOf
462
+ * view
463
+ */
464
+ async balanceOf(account) {
465
+ return this.contract.read.balanceOf([account]);
466
+ }
467
+ /**
468
+ * decimals
469
+ * view
470
+ */
471
+ async decimals() {
472
+ return this.contract.read.decimals();
473
+ }
474
+ /**
475
+ * name
476
+ * view
477
+ */
478
+ async name() {
479
+ return this.contract.read.name();
480
+ }
481
+ /**
482
+ * paused
483
+ * view
484
+ */
485
+ async paused() {
486
+ return this.contract.read.paused();
487
+ }
488
+ /**
489
+ * symbol
490
+ * view
491
+ */
492
+ async symbol() {
493
+ return this.contract.read.symbol();
494
+ }
495
+ /**
496
+ * totalSupply
497
+ * view
498
+ */
499
+ async totalSupply() {
500
+ return this.contract.read.totalSupply();
501
+ }
502
+ /**
503
+ * approve
504
+ * nonpayable
505
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
506
+ */
507
+ async approve(spender, amount, options) {
508
+ if (!this.contract.write) {
509
+ throw new Error('Wallet client is required for write operations');
510
+ }
511
+ return this.contract.write.approve([spender, amount], options);
512
+ }
513
+ /**
514
+ * decreaseAllowance
515
+ * nonpayable
516
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
517
+ */
518
+ async decreaseAllowance(spender, subtractedValue, options) {
519
+ if (!this.contract.write) {
520
+ throw new Error('Wallet client is required for write operations');
521
+ }
522
+ return this.contract.write.decreaseAllowance([spender, subtractedValue], options);
523
+ }
524
+ /**
525
+ * increaseAllowance
526
+ * nonpayable
527
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
528
+ */
529
+ async increaseAllowance(spender, addedValue, options) {
530
+ if (!this.contract.write) {
531
+ throw new Error('Wallet client is required for write operations');
532
+ }
533
+ return this.contract.write.increaseAllowance([spender, addedValue], options);
534
+ }
535
+ /**
536
+ * mintToken
537
+ * nonpayable
538
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
539
+ */
540
+ async mintToken(receiver, amount, options) {
541
+ if (!this.contract.write) {
542
+ throw new Error('Wallet client is required for write operations');
543
+ }
544
+ return this.contract.write.mintToken([receiver, amount], options);
545
+ }
546
+ /**
547
+ * pause
548
+ * nonpayable
549
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
550
+ */
551
+ async pause(options) {
552
+ if (!this.contract.write) {
553
+ throw new Error('Wallet client is required for write operations');
554
+ }
555
+ return this.contract.write.pause(options);
556
+ }
557
+ /**
558
+ * setMiter
559
+ * nonpayable
560
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
561
+ */
562
+ async setMiter(_minter, options) {
563
+ if (!this.contract.write) {
564
+ throw new Error('Wallet client is required for write operations');
565
+ }
566
+ return this.contract.write.setMiter([_minter], options);
567
+ }
568
+ /**
569
+ * transfer
570
+ * nonpayable
571
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
572
+ */
573
+ async transfer(recipient, amount, options) {
574
+ if (!this.contract.write) {
575
+ throw new Error('Wallet client is required for write operations');
576
+ }
577
+ return this.contract.write.transfer([recipient, amount], options);
578
+ }
579
+ /**
580
+ * transferFrom
581
+ * nonpayable
582
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
583
+ */
584
+ async transferFrom(sender, recipient, amount, options) {
585
+ if (!this.contract.write) {
586
+ throw new Error('Wallet client is required for write operations');
587
+ }
588
+ return this.contract.write.transferFrom([sender, recipient, amount], options);
589
+ }
590
+ /**
591
+ * unpause
592
+ * nonpayable
593
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
594
+ */
595
+ async unpause(options) {
596
+ if (!this.contract.write) {
597
+ throw new Error('Wallet client is required for write operations');
598
+ }
599
+ return this.contract.write.unpause(options);
600
+ }
601
+ /**
602
+ * Simulate contract write operations (dry-run without sending transaction)
603
+ *
604
+ * @example
605
+ * const result = await contract.simulate.transfer('0x...', 1000n);
606
+ * console.log('Gas estimate:', result.request.gas);
607
+ * console.log('Would succeed:', result.result);
608
+ */
609
+ get simulate() {
610
+ const contract = this.contract;
611
+ if (!contract.simulate) {
612
+ throw new Error('Public client is required for simulation');
613
+ }
614
+ return {
615
+ /**
616
+ * Simulate approve
617
+ * Returns gas estimate and result without sending transaction
618
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
619
+ */
620
+ async approve(spender, amount, options) {
621
+ return contract.simulate.approve([spender, amount], options);
622
+ },
623
+ /**
624
+ * Simulate decreaseAllowance
625
+ * Returns gas estimate and result without sending transaction
626
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
627
+ */
628
+ async decreaseAllowance(spender, subtractedValue, options) {
629
+ return contract.simulate.decreaseAllowance([spender, subtractedValue], options);
630
+ },
631
+ /**
632
+ * Simulate increaseAllowance
633
+ * Returns gas estimate and result without sending transaction
634
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
635
+ */
636
+ async increaseAllowance(spender, addedValue, options) {
637
+ return contract.simulate.increaseAllowance([spender, addedValue], options);
638
+ },
639
+ /**
640
+ * Simulate mintToken
641
+ * Returns gas estimate and result without sending transaction
642
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
643
+ */
644
+ async mintToken(receiver, amount, options) {
645
+ return contract.simulate.mintToken([receiver, amount], options);
646
+ },
647
+ /**
648
+ * Simulate pause
649
+ * Returns gas estimate and result without sending transaction
650
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
651
+ */
652
+ async pause(options) {
653
+ return contract.simulate.pause(options);
654
+ },
655
+ /**
656
+ * Simulate setMiter
657
+ * Returns gas estimate and result without sending transaction
658
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
659
+ */
660
+ async setMiter(_minter, options) {
661
+ return contract.simulate.setMiter([_minter], options);
662
+ },
663
+ /**
664
+ * Simulate transfer
665
+ * Returns gas estimate and result without sending transaction
666
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
667
+ */
668
+ async transfer(recipient, amount, options) {
669
+ return contract.simulate.transfer([recipient, amount], options);
670
+ },
671
+ /**
672
+ * Simulate transferFrom
673
+ * Returns gas estimate and result without sending transaction
674
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
675
+ */
676
+ async transferFrom(sender, recipient, amount, options) {
677
+ return contract.simulate.transferFrom([sender, recipient, amount], options);
678
+ },
679
+ /**
680
+ * Simulate unpause
681
+ * Returns gas estimate and result without sending transaction
682
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
683
+ */
684
+ async unpause(options) {
685
+ return contract.simulate.unpause(options);
686
+ }
687
+ };
688
+ }
689
+ /**
690
+ * Watch contract events
691
+ *
692
+ * @example
693
+ * // Watch all Transfer events
694
+ * const unwatch = contract.watch.Transfer((event) => {
695
+ * console.log('Transfer:', event);
696
+ * });
697
+ *
698
+ * // Stop watching
699
+ * unwatch();
700
+ */
701
+ get watch() {
702
+ return {
703
+ /**
704
+ * Watch Approval events
705
+ * @param callback Function to call when event is emitted
706
+ * @param filter Optional filter for indexed parameters
707
+ * @returns Unwatch function to stop listening
708
+ */
709
+ Approval: (callback, filter) => {
710
+ return this.publicClient.watchContractEvent({
711
+ address: this.contractAddress,
712
+ abi: exports.Decentr_jsonAbi,
713
+ eventName: 'Approval',
714
+ args: filter,
715
+ onLogs: (logs) => {
716
+ logs.forEach((log) => {
717
+ callback(log.args);
718
+ });
719
+ },
720
+ });
721
+ },
722
+ /**
723
+ * Watch Paused events
724
+ * @param callback Function to call when event is emitted
725
+ * @param filter Optional filter for indexed parameters
726
+ * @returns Unwatch function to stop listening
727
+ */
728
+ Paused: (callback) => {
729
+ return this.publicClient.watchContractEvent({
730
+ address: this.contractAddress,
731
+ abi: exports.Decentr_jsonAbi,
732
+ eventName: 'Paused',
733
+ onLogs: (logs) => {
734
+ logs.forEach((log) => {
735
+ callback(log.args);
736
+ });
737
+ },
738
+ });
739
+ },
740
+ /**
741
+ * Watch TokenMinterUpdated events
742
+ * @param callback Function to call when event is emitted
743
+ * @param filter Optional filter for indexed parameters
744
+ * @returns Unwatch function to stop listening
745
+ */
746
+ TokenMinterUpdated: (callback) => {
747
+ return this.publicClient.watchContractEvent({
748
+ address: this.contractAddress,
749
+ abi: exports.Decentr_jsonAbi,
750
+ eventName: 'TokenMinterUpdated',
751
+ onLogs: (logs) => {
752
+ logs.forEach((log) => {
753
+ callback(log.args);
754
+ });
755
+ },
756
+ });
757
+ },
758
+ /**
759
+ * Watch Transfer events
760
+ * @param callback Function to call when event is emitted
761
+ * @param filter Optional filter for indexed parameters
762
+ * @returns Unwatch function to stop listening
763
+ */
764
+ Transfer: (callback, filter) => {
765
+ return this.publicClient.watchContractEvent({
766
+ address: this.contractAddress,
767
+ abi: exports.Decentr_jsonAbi,
768
+ eventName: 'Transfer',
769
+ args: filter,
770
+ onLogs: (logs) => {
771
+ logs.forEach((log) => {
772
+ callback(log.args);
773
+ });
774
+ },
775
+ });
776
+ },
777
+ /**
778
+ * Watch Unpaused events
779
+ * @param callback Function to call when event is emitted
780
+ * @param filter Optional filter for indexed parameters
781
+ * @returns Unwatch function to stop listening
782
+ */
783
+ Unpaused: (callback) => {
784
+ return this.publicClient.watchContractEvent({
785
+ address: this.contractAddress,
786
+ abi: exports.Decentr_jsonAbi,
787
+ eventName: 'Unpaused',
788
+ onLogs: (logs) => {
789
+ logs.forEach((log) => {
790
+ callback(log.args);
791
+ });
792
+ },
793
+ });
794
+ }
795
+ };
796
+ }
797
+ }
798
+ exports.Decentr_json = Decentr_json;