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