@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,592 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WETH9_json = exports.WETH9_jsonAbi = void 0;
4
+ const viem_1 = require("viem");
5
+ /**
6
+ * WETH9_json ABI
7
+ *
8
+ * This ABI is typed using viem's type system for full type safety.
9
+ */
10
+ exports.WETH9_jsonAbi = [
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": "guy",
30
+ "type": "address"
31
+ },
32
+ {
33
+ "name": "wad",
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": "src",
67
+ "type": "address"
68
+ },
69
+ {
70
+ "name": "dst",
71
+ "type": "address"
72
+ },
73
+ {
74
+ "name": "wad",
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": false,
91
+ "inputs": [
92
+ {
93
+ "name": "wad",
94
+ "type": "uint256"
95
+ }
96
+ ],
97
+ "name": "withdraw",
98
+ "outputs": [],
99
+ "payable": false,
100
+ "stateMutability": "nonpayable",
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
+ {
121
+ "name": "",
122
+ "type": "address"
123
+ }
124
+ ],
125
+ "name": "balanceOf",
126
+ "outputs": [
127
+ {
128
+ "name": "",
129
+ "type": "uint256"
130
+ }
131
+ ],
132
+ "payable": false,
133
+ "stateMutability": "view",
134
+ "type": "function"
135
+ },
136
+ {
137
+ "constant": true,
138
+ "inputs": [],
139
+ "name": "symbol",
140
+ "outputs": [
141
+ {
142
+ "name": "",
143
+ "type": "string"
144
+ }
145
+ ],
146
+ "payable": false,
147
+ "stateMutability": "view",
148
+ "type": "function"
149
+ },
150
+ {
151
+ "constant": false,
152
+ "inputs": [
153
+ {
154
+ "name": "dst",
155
+ "type": "address"
156
+ },
157
+ {
158
+ "name": "wad",
159
+ "type": "uint256"
160
+ }
161
+ ],
162
+ "name": "transfer",
163
+ "outputs": [
164
+ {
165
+ "name": "",
166
+ "type": "bool"
167
+ }
168
+ ],
169
+ "payable": false,
170
+ "stateMutability": "nonpayable",
171
+ "type": "function"
172
+ },
173
+ {
174
+ "constant": false,
175
+ "inputs": [],
176
+ "name": "deposit",
177
+ "outputs": [],
178
+ "payable": true,
179
+ "stateMutability": "payable",
180
+ "type": "function"
181
+ },
182
+ {
183
+ "constant": true,
184
+ "inputs": [
185
+ {
186
+ "name": "",
187
+ "type": "address"
188
+ },
189
+ {
190
+ "name": "",
191
+ "type": "address"
192
+ }
193
+ ],
194
+ "name": "allowance",
195
+ "outputs": [
196
+ {
197
+ "name": "",
198
+ "type": "uint256"
199
+ }
200
+ ],
201
+ "payable": false,
202
+ "stateMutability": "view",
203
+ "type": "function"
204
+ },
205
+ {
206
+ "payable": true,
207
+ "stateMutability": "payable",
208
+ "type": "fallback"
209
+ },
210
+ {
211
+ "anonymous": false,
212
+ "inputs": [
213
+ {
214
+ "indexed": true,
215
+ "name": "src",
216
+ "type": "address"
217
+ },
218
+ {
219
+ "indexed": true,
220
+ "name": "guy",
221
+ "type": "address"
222
+ },
223
+ {
224
+ "indexed": false,
225
+ "name": "wad",
226
+ "type": "uint256"
227
+ }
228
+ ],
229
+ "name": "Approval",
230
+ "type": "event"
231
+ },
232
+ {
233
+ "anonymous": false,
234
+ "inputs": [
235
+ {
236
+ "indexed": true,
237
+ "name": "src",
238
+ "type": "address"
239
+ },
240
+ {
241
+ "indexed": true,
242
+ "name": "dst",
243
+ "type": "address"
244
+ },
245
+ {
246
+ "indexed": false,
247
+ "name": "wad",
248
+ "type": "uint256"
249
+ }
250
+ ],
251
+ "name": "Transfer",
252
+ "type": "event"
253
+ },
254
+ {
255
+ "anonymous": false,
256
+ "inputs": [
257
+ {
258
+ "indexed": true,
259
+ "name": "dst",
260
+ "type": "address"
261
+ },
262
+ {
263
+ "indexed": false,
264
+ "name": "wad",
265
+ "type": "uint256"
266
+ }
267
+ ],
268
+ "name": "Deposit",
269
+ "type": "event"
270
+ },
271
+ {
272
+ "anonymous": false,
273
+ "inputs": [
274
+ {
275
+ "indexed": true,
276
+ "name": "src",
277
+ "type": "address"
278
+ },
279
+ {
280
+ "indexed": false,
281
+ "name": "wad",
282
+ "type": "uint256"
283
+ }
284
+ ],
285
+ "name": "Withdrawal",
286
+ "type": "event"
287
+ }
288
+ ];
289
+ /**
290
+ * WETH9_json Contract Class
291
+ *
292
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * import { createPublicClient, createWalletClient, http } from 'viem';
297
+ * import { mainnet } from 'viem/chains';
298
+ * import { WETH9_json } from 'WETH9_json';
299
+ *
300
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
301
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
302
+ *
303
+ * const contract = new WETH9_json('0x...', { publicClient, walletClient });
304
+ *
305
+ * // Read functions
306
+ * const result = await contract.balanceOf('0x...');
307
+ *
308
+ * // Write functions
309
+ * const hash = await contract.transfer('0x...', 1000n);
310
+ *
311
+ * // Simulate transactions (dry-run)
312
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
313
+ * console.log('Gas estimate:', simulation.request.gas);
314
+ *
315
+ * // Watch events
316
+ * const unwatch = contract.watch.Transfer((event) => {
317
+ * console.log('Transfer event:', event);
318
+ * });
319
+ * ```
320
+ */
321
+ class WETH9_json {
322
+ constructor(address, clients) {
323
+ this.contractAddress = address;
324
+ this.publicClient = clients.publicClient;
325
+ this.contract = (0, viem_1.getContract)({
326
+ address,
327
+ abi: exports.WETH9_jsonAbi,
328
+ client: {
329
+ public: clients.publicClient,
330
+ wallet: clients.walletClient,
331
+ },
332
+ });
333
+ }
334
+ /**
335
+ * Get the contract address
336
+ */
337
+ get address() {
338
+ return this.contractAddress;
339
+ }
340
+ /**
341
+ * Get the underlying viem contract instance
342
+ */
343
+ getContract() {
344
+ return this.contract;
345
+ }
346
+ /**
347
+ * name
348
+ * view
349
+ */
350
+ async name() {
351
+ return this.contract.read.name();
352
+ }
353
+ /**
354
+ * totalSupply
355
+ * view
356
+ */
357
+ async totalSupply() {
358
+ return this.contract.read.totalSupply();
359
+ }
360
+ /**
361
+ * decimals
362
+ * view
363
+ */
364
+ async decimals() {
365
+ return this.contract.read.decimals();
366
+ }
367
+ /**
368
+ * balanceOf
369
+ * view
370
+ */
371
+ async balanceOf(arg0) {
372
+ return this.contract.read.balanceOf([arg0]);
373
+ }
374
+ /**
375
+ * symbol
376
+ * view
377
+ */
378
+ async symbol() {
379
+ return this.contract.read.symbol();
380
+ }
381
+ /**
382
+ * allowance
383
+ * view
384
+ */
385
+ async allowance(arg0, arg1) {
386
+ return this.contract.read.allowance([arg0, arg1]);
387
+ }
388
+ /**
389
+ * approve
390
+ * nonpayable
391
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
392
+ */
393
+ async approve(guy, wad, options) {
394
+ if (!this.contract.write) {
395
+ throw new Error('Wallet client is required for write operations');
396
+ }
397
+ return this.contract.write.approve([guy, wad], options);
398
+ }
399
+ /**
400
+ * transferFrom
401
+ * nonpayable
402
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
403
+ */
404
+ async transferFrom(src, dst, wad, options) {
405
+ if (!this.contract.write) {
406
+ throw new Error('Wallet client is required for write operations');
407
+ }
408
+ return this.contract.write.transferFrom([src, dst, wad], options);
409
+ }
410
+ /**
411
+ * withdraw
412
+ * nonpayable
413
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
414
+ */
415
+ async withdraw(wad, options) {
416
+ if (!this.contract.write) {
417
+ throw new Error('Wallet client is required for write operations');
418
+ }
419
+ return this.contract.write.withdraw([wad], options);
420
+ }
421
+ /**
422
+ * transfer
423
+ * nonpayable
424
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
425
+ */
426
+ async transfer(dst, wad, options) {
427
+ if (!this.contract.write) {
428
+ throw new Error('Wallet client is required for write operations');
429
+ }
430
+ return this.contract.write.transfer([dst, wad], options);
431
+ }
432
+ /**
433
+ * deposit
434
+ * payable
435
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
436
+ */
437
+ async deposit(options) {
438
+ if (!this.contract.write) {
439
+ throw new Error('Wallet client is required for write operations');
440
+ }
441
+ return this.contract.write.deposit(options);
442
+ }
443
+ /**
444
+ * Simulate contract write operations (dry-run without sending transaction)
445
+ *
446
+ * @example
447
+ * const result = await contract.simulate.transfer('0x...', 1000n);
448
+ * console.log('Gas estimate:', result.request.gas);
449
+ * console.log('Would succeed:', result.result);
450
+ */
451
+ get simulate() {
452
+ const contract = this.contract;
453
+ if (!contract.simulate) {
454
+ throw new Error('Public client is required for simulation');
455
+ }
456
+ return {
457
+ /**
458
+ * Simulate approve
459
+ * Returns gas estimate and result without sending transaction
460
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
461
+ */
462
+ async approve(guy, wad, options) {
463
+ return contract.simulate.approve([guy, wad], options);
464
+ },
465
+ /**
466
+ * Simulate transferFrom
467
+ * Returns gas estimate and result without sending transaction
468
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
469
+ */
470
+ async transferFrom(src, dst, wad, options) {
471
+ return contract.simulate.transferFrom([src, dst, wad], options);
472
+ },
473
+ /**
474
+ * Simulate withdraw
475
+ * Returns gas estimate and result without sending transaction
476
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
477
+ */
478
+ async withdraw(wad, options) {
479
+ return contract.simulate.withdraw([wad], options);
480
+ },
481
+ /**
482
+ * Simulate transfer
483
+ * Returns gas estimate and result without sending transaction
484
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
485
+ */
486
+ async transfer(dst, wad, options) {
487
+ return contract.simulate.transfer([dst, wad], options);
488
+ },
489
+ /**
490
+ * Simulate deposit
491
+ * Returns gas estimate and result without sending transaction
492
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
493
+ */
494
+ async deposit(options) {
495
+ return contract.simulate.deposit(options);
496
+ }
497
+ };
498
+ }
499
+ /**
500
+ * Watch contract events
501
+ *
502
+ * @example
503
+ * // Watch all Transfer events
504
+ * const unwatch = contract.watch.Transfer((event) => {
505
+ * console.log('Transfer:', event);
506
+ * });
507
+ *
508
+ * // Stop watching
509
+ * unwatch();
510
+ */
511
+ get watch() {
512
+ return {
513
+ /**
514
+ * Watch Approval events
515
+ * @param callback Function to call when event is emitted
516
+ * @param filter Optional filter for indexed parameters
517
+ * @returns Unwatch function to stop listening
518
+ */
519
+ Approval: (callback, filter) => {
520
+ return this.publicClient.watchContractEvent({
521
+ address: this.contractAddress,
522
+ abi: exports.WETH9_jsonAbi,
523
+ eventName: 'Approval',
524
+ args: filter,
525
+ onLogs: (logs) => {
526
+ logs.forEach((log) => {
527
+ callback(log.args);
528
+ });
529
+ },
530
+ });
531
+ },
532
+ /**
533
+ * Watch Transfer events
534
+ * @param callback Function to call when event is emitted
535
+ * @param filter Optional filter for indexed parameters
536
+ * @returns Unwatch function to stop listening
537
+ */
538
+ Transfer: (callback, filter) => {
539
+ return this.publicClient.watchContractEvent({
540
+ address: this.contractAddress,
541
+ abi: exports.WETH9_jsonAbi,
542
+ eventName: 'Transfer',
543
+ args: filter,
544
+ onLogs: (logs) => {
545
+ logs.forEach((log) => {
546
+ callback(log.args);
547
+ });
548
+ },
549
+ });
550
+ },
551
+ /**
552
+ * Watch Deposit events
553
+ * @param callback Function to call when event is emitted
554
+ * @param filter Optional filter for indexed parameters
555
+ * @returns Unwatch function to stop listening
556
+ */
557
+ Deposit: (callback, filter) => {
558
+ return this.publicClient.watchContractEvent({
559
+ address: this.contractAddress,
560
+ abi: exports.WETH9_jsonAbi,
561
+ eventName: 'Deposit',
562
+ args: filter,
563
+ onLogs: (logs) => {
564
+ logs.forEach((log) => {
565
+ callback(log.args);
566
+ });
567
+ },
568
+ });
569
+ },
570
+ /**
571
+ * Watch Withdrawal events
572
+ * @param callback Function to call when event is emitted
573
+ * @param filter Optional filter for indexed parameters
574
+ * @returns Unwatch function to stop listening
575
+ */
576
+ Withdrawal: (callback, filter) => {
577
+ return this.publicClient.watchContractEvent({
578
+ address: this.contractAddress,
579
+ abi: exports.WETH9_jsonAbi,
580
+ eventName: 'Withdrawal',
581
+ args: filter,
582
+ onLogs: (logs) => {
583
+ logs.forEach((log) => {
584
+ callback(log.args);
585
+ });
586
+ },
587
+ });
588
+ }
589
+ };
590
+ }
591
+ }
592
+ exports.WETH9_json = WETH9_json;