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