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