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