@gitmyabi/lwc 0.0.0-stage → 1.0.0

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