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