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