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