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