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