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