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