@gitmyabi-stg/stpt 0.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 +108 -0
- package/contracts/STPTToken.d.ts +474 -0
- package/contracts/STPTToken.js +511 -0
- package/contracts/STPTToken.ts +636 -0
- package/contracts/index.d.ts +2 -0
- package/contracts/index.js +7 -0
- package/contracts/index.ts +3 -0
- package/index.d.ts +1 -0
- package/index.js +19 -0
- package/package.json +43 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import type { Abi, Address, PublicClient, WalletClient, GetContractReturnType } from 'viem';
|
|
2
|
+
import { getContract } from 'viem';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* STPTToken ABI
|
|
6
|
+
*
|
|
7
|
+
* This ABI is typed using viem's type system for full type safety.
|
|
8
|
+
*/
|
|
9
|
+
export const STPTTokenAbi = [
|
|
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": "tokens",
|
|
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": "tokens",
|
|
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": true,
|
|
104
|
+
"inputs": [
|
|
105
|
+
{
|
|
106
|
+
"name": "tokenOwner",
|
|
107
|
+
"type": "address"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"name": "balanceOf",
|
|
111
|
+
"outputs": [
|
|
112
|
+
{
|
|
113
|
+
"name": "balance",
|
|
114
|
+
"type": "uint256"
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"payable": false,
|
|
118
|
+
"stateMutability": "view",
|
|
119
|
+
"type": "function"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"constant": true,
|
|
123
|
+
"inputs": [],
|
|
124
|
+
"name": "symbol",
|
|
125
|
+
"outputs": [
|
|
126
|
+
{
|
|
127
|
+
"name": "",
|
|
128
|
+
"type": "string"
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"payable": false,
|
|
132
|
+
"stateMutability": "view",
|
|
133
|
+
"type": "function"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"constant": false,
|
|
137
|
+
"inputs": [
|
|
138
|
+
{
|
|
139
|
+
"name": "to",
|
|
140
|
+
"type": "address"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"name": "tokens",
|
|
144
|
+
"type": "uint256"
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
"name": "transfer",
|
|
148
|
+
"outputs": [
|
|
149
|
+
{
|
|
150
|
+
"name": "success",
|
|
151
|
+
"type": "bool"
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
"payable": false,
|
|
155
|
+
"stateMutability": "nonpayable",
|
|
156
|
+
"type": "function"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"constant": false,
|
|
160
|
+
"inputs": [
|
|
161
|
+
{
|
|
162
|
+
"name": "spender",
|
|
163
|
+
"type": "address"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"name": "tokens",
|
|
167
|
+
"type": "uint256"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"name": "data",
|
|
171
|
+
"type": "bytes"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"name": "approveAndCall",
|
|
175
|
+
"outputs": [
|
|
176
|
+
{
|
|
177
|
+
"name": "success",
|
|
178
|
+
"type": "bool"
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
"payable": false,
|
|
182
|
+
"stateMutability": "nonpayable",
|
|
183
|
+
"type": "function"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"constant": true,
|
|
187
|
+
"inputs": [
|
|
188
|
+
{
|
|
189
|
+
"name": "tokenOwner",
|
|
190
|
+
"type": "address"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"name": "spender",
|
|
194
|
+
"type": "address"
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"name": "allowance",
|
|
198
|
+
"outputs": [
|
|
199
|
+
{
|
|
200
|
+
"name": "remaining",
|
|
201
|
+
"type": "uint256"
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
"payable": false,
|
|
205
|
+
"stateMutability": "view",
|
|
206
|
+
"type": "function"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"inputs": [],
|
|
210
|
+
"payable": false,
|
|
211
|
+
"stateMutability": "nonpayable",
|
|
212
|
+
"type": "constructor"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"payable": true,
|
|
216
|
+
"stateMutability": "payable",
|
|
217
|
+
"type": "fallback"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"anonymous": false,
|
|
221
|
+
"inputs": [
|
|
222
|
+
{
|
|
223
|
+
"indexed": true,
|
|
224
|
+
"name": "from",
|
|
225
|
+
"type": "address"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"indexed": true,
|
|
229
|
+
"name": "to",
|
|
230
|
+
"type": "address"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"indexed": false,
|
|
234
|
+
"name": "tokens",
|
|
235
|
+
"type": "uint256"
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
"name": "Transfer",
|
|
239
|
+
"type": "event"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"anonymous": false,
|
|
243
|
+
"inputs": [
|
|
244
|
+
{
|
|
245
|
+
"indexed": true,
|
|
246
|
+
"name": "tokenOwner",
|
|
247
|
+
"type": "address"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"indexed": true,
|
|
251
|
+
"name": "spender",
|
|
252
|
+
"type": "address"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"indexed": false,
|
|
256
|
+
"name": "tokens",
|
|
257
|
+
"type": "uint256"
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
"name": "Approval",
|
|
261
|
+
"type": "event"
|
|
262
|
+
}
|
|
263
|
+
] as const satisfies Abi;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Type-safe ABI for STPTToken
|
|
267
|
+
*/
|
|
268
|
+
export type STPTTokenAbi = typeof STPTTokenAbi;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Contract instance type for STPTToken
|
|
272
|
+
*/
|
|
273
|
+
// Use any for contract type to avoid complex viem type issues
|
|
274
|
+
// The runtime behavior is type-safe through viem's ABI typing
|
|
275
|
+
export type STPTTokenContract = any;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* STPTToken Contract Class
|
|
279
|
+
*
|
|
280
|
+
* Provides a class-based API similar to TypeChain for interacting with the contract.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
285
|
+
* import { mainnet } from 'viem/chains';
|
|
286
|
+
* import { STPTToken } from 'STPTToken';
|
|
287
|
+
*
|
|
288
|
+
* const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
289
|
+
* const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
290
|
+
*
|
|
291
|
+
* const contract = new STPTToken('0x...', { publicClient, walletClient });
|
|
292
|
+
*
|
|
293
|
+
* // Read functions
|
|
294
|
+
* const result = await contract.balanceOf('0x...');
|
|
295
|
+
*
|
|
296
|
+
* // Write functions
|
|
297
|
+
* const hash = await contract.transfer('0x...', 1000n);
|
|
298
|
+
*
|
|
299
|
+
* // Simulate transactions (dry-run)
|
|
300
|
+
* const simulation = await contract.simulate.transfer('0x...', 1000n);
|
|
301
|
+
* console.log('Gas estimate:', simulation.request.gas);
|
|
302
|
+
*
|
|
303
|
+
* // Watch events
|
|
304
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
305
|
+
* console.log('Transfer event:', event);
|
|
306
|
+
* });
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
export class STPTToken {
|
|
310
|
+
private contract: STPTTokenContract;
|
|
311
|
+
private contractAddress: Address;
|
|
312
|
+
private publicClient: PublicClient;
|
|
313
|
+
|
|
314
|
+
constructor(
|
|
315
|
+
address: Address,
|
|
316
|
+
clients: {
|
|
317
|
+
publicClient: PublicClient;
|
|
318
|
+
walletClient?: WalletClient;
|
|
319
|
+
}
|
|
320
|
+
) {
|
|
321
|
+
this.contractAddress = address;
|
|
322
|
+
this.publicClient = clients.publicClient;
|
|
323
|
+
this.contract = getContract({
|
|
324
|
+
address,
|
|
325
|
+
abi: STPTTokenAbi,
|
|
326
|
+
client: {
|
|
327
|
+
public: clients.publicClient,
|
|
328
|
+
wallet: clients.walletClient,
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Get the contract address
|
|
335
|
+
*/
|
|
336
|
+
get address(): Address {
|
|
337
|
+
return this.contractAddress;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Get the underlying viem contract instance.
|
|
342
|
+
*/
|
|
343
|
+
getContract(): STPTTokenContract {
|
|
344
|
+
return this.contract;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* name
|
|
349
|
+
* view
|
|
350
|
+
*/
|
|
351
|
+
async name(): Promise<string> {
|
|
352
|
+
return this.contract.read.name() as Promise<string>;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* totalSupply
|
|
357
|
+
* view
|
|
358
|
+
*/
|
|
359
|
+
async totalSupply(): Promise<bigint> {
|
|
360
|
+
return this.contract.read.totalSupply() as Promise<bigint>;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* decimals
|
|
365
|
+
* view
|
|
366
|
+
*/
|
|
367
|
+
async decimals(): Promise<bigint> {
|
|
368
|
+
return this.contract.read.decimals() as Promise<bigint>;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* balanceOf
|
|
373
|
+
* view
|
|
374
|
+
*/
|
|
375
|
+
async balanceOf(tokenOwner: `0x${string}`): Promise<bigint> {
|
|
376
|
+
return this.contract.read.balanceOf([tokenOwner] as const) as Promise<bigint>;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* symbol
|
|
381
|
+
* view
|
|
382
|
+
*/
|
|
383
|
+
async symbol(): Promise<string> {
|
|
384
|
+
return this.contract.read.symbol() as Promise<string>;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* allowance
|
|
389
|
+
* view
|
|
390
|
+
*/
|
|
391
|
+
async allowance(tokenOwner: `0x${string}`, spender: `0x${string}`): Promise<bigint> {
|
|
392
|
+
return this.contract.read.allowance([tokenOwner, spender] as const) as Promise<bigint>;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* approve
|
|
397
|
+
* nonpayable
|
|
398
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
399
|
+
*/
|
|
400
|
+
async approve(spender: `0x${string}`, tokens: bigint, options?: {
|
|
401
|
+
accessList?: import('viem').AccessList;
|
|
402
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
403
|
+
chain?: import('viem').Chain | null;
|
|
404
|
+
dataSuffix?: `0x${string}`;
|
|
405
|
+
gas?: bigint;
|
|
406
|
+
gasPrice?: bigint;
|
|
407
|
+
maxFeePerGas?: bigint;
|
|
408
|
+
maxPriorityFeePerGas?: bigint;
|
|
409
|
+
nonce?: number;
|
|
410
|
+
value?: bigint;
|
|
411
|
+
}): Promise<`0x${string}`> {
|
|
412
|
+
if (!this.contract.write) {
|
|
413
|
+
throw new Error('Wallet client is required for write operations');
|
|
414
|
+
}
|
|
415
|
+
return this.contract.write.approve([spender, tokens] as const, options) as Promise<`0x${string}`>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* transferFrom
|
|
420
|
+
* nonpayable
|
|
421
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
422
|
+
*/
|
|
423
|
+
async transferFrom(from: `0x${string}`, to: `0x${string}`, tokens: bigint, options?: {
|
|
424
|
+
accessList?: import('viem').AccessList;
|
|
425
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
426
|
+
chain?: import('viem').Chain | null;
|
|
427
|
+
dataSuffix?: `0x${string}`;
|
|
428
|
+
gas?: bigint;
|
|
429
|
+
gasPrice?: bigint;
|
|
430
|
+
maxFeePerGas?: bigint;
|
|
431
|
+
maxPriorityFeePerGas?: bigint;
|
|
432
|
+
nonce?: number;
|
|
433
|
+
value?: bigint;
|
|
434
|
+
}): Promise<`0x${string}`> {
|
|
435
|
+
if (!this.contract.write) {
|
|
436
|
+
throw new Error('Wallet client is required for write operations');
|
|
437
|
+
}
|
|
438
|
+
return this.contract.write.transferFrom([from, to, tokens] as const, options) as Promise<`0x${string}`>;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* transfer
|
|
443
|
+
* nonpayable
|
|
444
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
445
|
+
*/
|
|
446
|
+
async transfer(to: `0x${string}`, tokens: bigint, options?: {
|
|
447
|
+
accessList?: import('viem').AccessList;
|
|
448
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
449
|
+
chain?: import('viem').Chain | null;
|
|
450
|
+
dataSuffix?: `0x${string}`;
|
|
451
|
+
gas?: bigint;
|
|
452
|
+
gasPrice?: bigint;
|
|
453
|
+
maxFeePerGas?: bigint;
|
|
454
|
+
maxPriorityFeePerGas?: bigint;
|
|
455
|
+
nonce?: number;
|
|
456
|
+
value?: bigint;
|
|
457
|
+
}): Promise<`0x${string}`> {
|
|
458
|
+
if (!this.contract.write) {
|
|
459
|
+
throw new Error('Wallet client is required for write operations');
|
|
460
|
+
}
|
|
461
|
+
return this.contract.write.transfer([to, tokens] as const, options) as Promise<`0x${string}`>;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* approveAndCall
|
|
466
|
+
* nonpayable
|
|
467
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
468
|
+
*/
|
|
469
|
+
async approveAndCall(spender: `0x${string}`, tokens: bigint, data: `0x${string}`, options?: {
|
|
470
|
+
accessList?: import('viem').AccessList;
|
|
471
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
472
|
+
chain?: import('viem').Chain | null;
|
|
473
|
+
dataSuffix?: `0x${string}`;
|
|
474
|
+
gas?: bigint;
|
|
475
|
+
gasPrice?: bigint;
|
|
476
|
+
maxFeePerGas?: bigint;
|
|
477
|
+
maxPriorityFeePerGas?: bigint;
|
|
478
|
+
nonce?: number;
|
|
479
|
+
value?: bigint;
|
|
480
|
+
}): Promise<`0x${string}`> {
|
|
481
|
+
if (!this.contract.write) {
|
|
482
|
+
throw new Error('Wallet client is required for write operations');
|
|
483
|
+
}
|
|
484
|
+
return this.contract.write.approveAndCall([spender, tokens, data] as const, options) as Promise<`0x${string}`>;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Simulate contract write operations (dry-run without sending transaction)
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* const result = await contract.simulate.transfer('0x...', 1000n);
|
|
494
|
+
* console.log('Gas estimate:', result.request.gas);
|
|
495
|
+
* console.log('Would succeed:', result.result);
|
|
496
|
+
*/
|
|
497
|
+
get simulate() {
|
|
498
|
+
const contract = this.contract;
|
|
499
|
+
if (!contract.simulate) {
|
|
500
|
+
throw new Error('Public client is required for simulation');
|
|
501
|
+
}
|
|
502
|
+
return {
|
|
503
|
+
/**
|
|
504
|
+
* Simulate approve
|
|
505
|
+
* Returns gas estimate and result without sending transaction
|
|
506
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
507
|
+
*/
|
|
508
|
+
async approve(spender: `0x${string}`, tokens: bigint, options?: {
|
|
509
|
+
accessList?: import('viem').AccessList;
|
|
510
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
511
|
+
chain?: import('viem').Chain | null;
|
|
512
|
+
dataSuffix?: `0x${string}`;
|
|
513
|
+
gas?: bigint;
|
|
514
|
+
gasPrice?: bigint;
|
|
515
|
+
maxFeePerGas?: bigint;
|
|
516
|
+
maxPriorityFeePerGas?: bigint;
|
|
517
|
+
nonce?: number;
|
|
518
|
+
value?: bigint;
|
|
519
|
+
}): Promise<boolean> {
|
|
520
|
+
return contract.simulate.approve([spender, tokens] as const, options) as Promise<boolean>;
|
|
521
|
+
},
|
|
522
|
+
/**
|
|
523
|
+
* Simulate transferFrom
|
|
524
|
+
* Returns gas estimate and result without sending transaction
|
|
525
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
526
|
+
*/
|
|
527
|
+
async transferFrom(from: `0x${string}`, to: `0x${string}`, tokens: bigint, options?: {
|
|
528
|
+
accessList?: import('viem').AccessList;
|
|
529
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
530
|
+
chain?: import('viem').Chain | null;
|
|
531
|
+
dataSuffix?: `0x${string}`;
|
|
532
|
+
gas?: bigint;
|
|
533
|
+
gasPrice?: bigint;
|
|
534
|
+
maxFeePerGas?: bigint;
|
|
535
|
+
maxPriorityFeePerGas?: bigint;
|
|
536
|
+
nonce?: number;
|
|
537
|
+
value?: bigint;
|
|
538
|
+
}): Promise<boolean> {
|
|
539
|
+
return contract.simulate.transferFrom([from, to, tokens] as const, options) as Promise<boolean>;
|
|
540
|
+
},
|
|
541
|
+
/**
|
|
542
|
+
* Simulate transfer
|
|
543
|
+
* Returns gas estimate and result without sending transaction
|
|
544
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
545
|
+
*/
|
|
546
|
+
async transfer(to: `0x${string}`, tokens: bigint, options?: {
|
|
547
|
+
accessList?: import('viem').AccessList;
|
|
548
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
549
|
+
chain?: import('viem').Chain | null;
|
|
550
|
+
dataSuffix?: `0x${string}`;
|
|
551
|
+
gas?: bigint;
|
|
552
|
+
gasPrice?: bigint;
|
|
553
|
+
maxFeePerGas?: bigint;
|
|
554
|
+
maxPriorityFeePerGas?: bigint;
|
|
555
|
+
nonce?: number;
|
|
556
|
+
value?: bigint;
|
|
557
|
+
}): Promise<boolean> {
|
|
558
|
+
return contract.simulate.transfer([to, tokens] as const, options) as Promise<boolean>;
|
|
559
|
+
},
|
|
560
|
+
/**
|
|
561
|
+
* Simulate approveAndCall
|
|
562
|
+
* Returns gas estimate and result without sending transaction
|
|
563
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
564
|
+
*/
|
|
565
|
+
async approveAndCall(spender: `0x${string}`, tokens: bigint, data: `0x${string}`, options?: {
|
|
566
|
+
accessList?: import('viem').AccessList;
|
|
567
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
568
|
+
chain?: import('viem').Chain | null;
|
|
569
|
+
dataSuffix?: `0x${string}`;
|
|
570
|
+
gas?: bigint;
|
|
571
|
+
gasPrice?: bigint;
|
|
572
|
+
maxFeePerGas?: bigint;
|
|
573
|
+
maxPriorityFeePerGas?: bigint;
|
|
574
|
+
nonce?: number;
|
|
575
|
+
value?: bigint;
|
|
576
|
+
}): Promise<boolean> {
|
|
577
|
+
return contract.simulate.approveAndCall([spender, tokens, data] as const, options) as Promise<boolean>;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Watch contract events
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
* // Watch all Transfer events
|
|
587
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
588
|
+
* console.log('Transfer:', event);
|
|
589
|
+
* });
|
|
590
|
+
*
|
|
591
|
+
* // Stop watching
|
|
592
|
+
* unwatch();
|
|
593
|
+
*/
|
|
594
|
+
get watch() {
|
|
595
|
+
return {
|
|
596
|
+
/**
|
|
597
|
+
* Watch Transfer events
|
|
598
|
+
* @param callback Function to call when event is emitted
|
|
599
|
+
* @param filter Optional filter for indexed parameters
|
|
600
|
+
* @returns Unwatch function to stop listening
|
|
601
|
+
*/
|
|
602
|
+
Transfer: (callback: (event: { from: `0x${string}`; to: `0x${string}`; tokens: bigint }) => void, filter?: { from?: `0x${string}` | `0x${string}`[] | null; to?: `0x${string}` | `0x${string}`[] | null }) => {
|
|
603
|
+
return this.publicClient.watchContractEvent({
|
|
604
|
+
address: this.contractAddress,
|
|
605
|
+
abi: STPTTokenAbi,
|
|
606
|
+
eventName: 'Transfer',
|
|
607
|
+
args: filter as any,
|
|
608
|
+
onLogs: (logs: any[]) => {
|
|
609
|
+
logs.forEach((log: any) => {
|
|
610
|
+
callback(log.args as any);
|
|
611
|
+
});
|
|
612
|
+
},
|
|
613
|
+
}) as () => void;
|
|
614
|
+
},
|
|
615
|
+
/**
|
|
616
|
+
* Watch Approval events
|
|
617
|
+
* @param callback Function to call when event is emitted
|
|
618
|
+
* @param filter Optional filter for indexed parameters
|
|
619
|
+
* @returns Unwatch function to stop listening
|
|
620
|
+
*/
|
|
621
|
+
Approval: (callback: (event: { tokenOwner: `0x${string}`; spender: `0x${string}`; tokens: bigint }) => void, filter?: { tokenOwner?: `0x${string}` | `0x${string}`[] | null; spender?: `0x${string}` | `0x${string}`[] | null }) => {
|
|
622
|
+
return this.publicClient.watchContractEvent({
|
|
623
|
+
address: this.contractAddress,
|
|
624
|
+
abi: STPTTokenAbi,
|
|
625
|
+
eventName: 'Approval',
|
|
626
|
+
args: filter as any,
|
|
627
|
+
onLogs: (logs: any[]) => {
|
|
628
|
+
logs.forEach((log: any) => {
|
|
629
|
+
callback(log.args as any);
|
|
630
|
+
});
|
|
631
|
+
},
|
|
632
|
+
}) as () => void;
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STPTToken = exports.STPTTokenAbi = void 0;
|
|
4
|
+
// Auto-generated exports for all contracts
|
|
5
|
+
var STPTToken_1 = require("./STPTToken");
|
|
6
|
+
Object.defineProperty(exports, "STPTTokenAbi", { enumerable: true, get: function () { return STPTToken_1.STPTTokenAbi; } });
|
|
7
|
+
Object.defineProperty(exports, "STPTToken", { enumerable: true, get: function () { return STPTToken_1.STPTToken; } });
|
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);
|