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