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