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