@gitmyabi/usdt 1.0.0 → 1.0.2

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