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