@gitmyabi-stg/safe 0.0.1

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