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