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