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