@gitmyabi/usdc 1.0.1 → 1.0.3

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