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