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