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