@gitmyabi/erc20 1.0.0 → 1.0.2

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,399 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERC20Proxy = exports.ERC20ProxyAbi = void 0;
4
+ const viem_1 = require("viem");
5
+ /**
6
+ * ERC20Proxy ABI
7
+ *
8
+ * This ABI is typed using viem's type system for full type safety.
9
+ */
10
+ exports.ERC20ProxyAbi = [
11
+ {
12
+ "inputs": [
13
+ {
14
+ "internalType": "address",
15
+ "name": "_owner",
16
+ "type": "address"
17
+ },
18
+ {
19
+ "internalType": "address",
20
+ "name": "_diamond",
21
+ "type": "address"
22
+ }
23
+ ],
24
+ "stateMutability": "nonpayable",
25
+ "type": "constructor"
26
+ },
27
+ {
28
+ "inputs": [],
29
+ "name": "InvalidAmount",
30
+ "type": "error"
31
+ },
32
+ {
33
+ "inputs": [],
34
+ "name": "LengthMissmatch",
35
+ "type": "error"
36
+ },
37
+ {
38
+ "inputs": [],
39
+ "name": "NoTransferToNullAddress",
40
+ "type": "error"
41
+ },
42
+ {
43
+ "inputs": [],
44
+ "name": "NotInitialized",
45
+ "type": "error"
46
+ },
47
+ {
48
+ "inputs": [],
49
+ "name": "NullAddrIsNotAnERC20Token",
50
+ "type": "error"
51
+ },
52
+ {
53
+ "inputs": [],
54
+ "name": "SliceOutOfBounds",
55
+ "type": "error"
56
+ },
57
+ {
58
+ "inputs": [],
59
+ "name": "SliceOverflow",
60
+ "type": "error"
61
+ },
62
+ {
63
+ "inputs": [],
64
+ "name": "ZeroAddress",
65
+ "type": "error"
66
+ },
67
+ {
68
+ "anonymous": false,
69
+ "inputs": [
70
+ {
71
+ "indexed": false,
72
+ "internalType": "address",
73
+ "name": "diamond",
74
+ "type": "address"
75
+ }
76
+ ],
77
+ "name": "DiamondSet",
78
+ "type": "event"
79
+ },
80
+ {
81
+ "anonymous": false,
82
+ "inputs": [
83
+ {
84
+ "indexed": true,
85
+ "internalType": "address",
86
+ "name": "previousOwner",
87
+ "type": "address"
88
+ },
89
+ {
90
+ "indexed": true,
91
+ "internalType": "address",
92
+ "name": "newOwner",
93
+ "type": "address"
94
+ }
95
+ ],
96
+ "name": "OwnershipTransferred",
97
+ "type": "event"
98
+ },
99
+ {
100
+ "inputs": [],
101
+ "name": "diamond",
102
+ "outputs": [
103
+ {
104
+ "internalType": "address",
105
+ "name": "",
106
+ "type": "address"
107
+ }
108
+ ],
109
+ "stateMutability": "view",
110
+ "type": "function"
111
+ },
112
+ {
113
+ "inputs": [],
114
+ "name": "owner",
115
+ "outputs": [
116
+ {
117
+ "internalType": "address",
118
+ "name": "",
119
+ "type": "address"
120
+ }
121
+ ],
122
+ "stateMutability": "view",
123
+ "type": "function"
124
+ },
125
+ {
126
+ "inputs": [],
127
+ "name": "renounceOwnership",
128
+ "outputs": [],
129
+ "stateMutability": "nonpayable",
130
+ "type": "function"
131
+ },
132
+ {
133
+ "inputs": [
134
+ {
135
+ "internalType": "address",
136
+ "name": "_diamond",
137
+ "type": "address"
138
+ }
139
+ ],
140
+ "name": "setDiamond",
141
+ "outputs": [],
142
+ "stateMutability": "nonpayable",
143
+ "type": "function"
144
+ },
145
+ {
146
+ "inputs": [
147
+ {
148
+ "internalType": "address[]",
149
+ "name": "tokens",
150
+ "type": "address[]"
151
+ },
152
+ {
153
+ "internalType": "uint256[]",
154
+ "name": "amounts",
155
+ "type": "uint256[]"
156
+ },
157
+ {
158
+ "internalType": "bytes",
159
+ "name": "facetCallData",
160
+ "type": "bytes"
161
+ }
162
+ ],
163
+ "name": "startViaRubic",
164
+ "outputs": [],
165
+ "stateMutability": "payable",
166
+ "type": "function"
167
+ },
168
+ {
169
+ "inputs": [
170
+ {
171
+ "internalType": "address",
172
+ "name": "newOwner",
173
+ "type": "address"
174
+ }
175
+ ],
176
+ "name": "transferOwnership",
177
+ "outputs": [],
178
+ "stateMutability": "nonpayable",
179
+ "type": "function"
180
+ }
181
+ ];
182
+ /**
183
+ * ERC20Proxy Contract Class
184
+ *
185
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { createPublicClient, createWalletClient, http } from 'viem';
190
+ * import { mainnet } from 'viem/chains';
191
+ * import { ERC20Proxy } from 'ERC20Proxy';
192
+ *
193
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
194
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
195
+ *
196
+ * const contract = new ERC20Proxy('0x...', { publicClient, walletClient });
197
+ *
198
+ * // Read functions
199
+ * const result = await contract.balanceOf('0x...');
200
+ *
201
+ * // Write functions
202
+ * const hash = await contract.transfer('0x...', 1000n);
203
+ *
204
+ * // Simulate transactions (dry-run)
205
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
206
+ * console.log('Gas estimate:', simulation.request.gas);
207
+ *
208
+ * // Watch events
209
+ * const unwatch = contract.watch.Transfer((event) => {
210
+ * console.log('Transfer event:', event);
211
+ * });
212
+ * ```
213
+ */
214
+ class ERC20Proxy {
215
+ constructor(address, clients) {
216
+ this.contractAddress = address;
217
+ this.publicClient = clients.publicClient;
218
+ this.contract = (0, viem_1.getContract)({
219
+ address,
220
+ abi: exports.ERC20ProxyAbi,
221
+ client: {
222
+ public: clients.publicClient,
223
+ wallet: clients.walletClient,
224
+ },
225
+ });
226
+ }
227
+ /**
228
+ * Get the contract address
229
+ */
230
+ get address() {
231
+ return this.contractAddress;
232
+ }
233
+ /**
234
+ * Get the underlying viem contract instance.
235
+ */
236
+ getContract() {
237
+ return this.contract;
238
+ }
239
+ /**
240
+ * diamond
241
+ * view
242
+ */
243
+ async diamond() {
244
+ return this.contract.read.diamond();
245
+ }
246
+ /**
247
+ * owner
248
+ * view
249
+ */
250
+ async owner() {
251
+ return this.contract.read.owner();
252
+ }
253
+ /**
254
+ * renounceOwnership
255
+ * nonpayable
256
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
257
+ */
258
+ async renounceOwnership(options) {
259
+ if (!this.contract.write) {
260
+ throw new Error('Wallet client is required for write operations');
261
+ }
262
+ return this.contract.write.renounceOwnership(options);
263
+ }
264
+ /**
265
+ * setDiamond
266
+ * nonpayable
267
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
268
+ */
269
+ async setDiamond(_diamond, options) {
270
+ if (!this.contract.write) {
271
+ throw new Error('Wallet client is required for write operations');
272
+ }
273
+ return this.contract.write.setDiamond([_diamond], options);
274
+ }
275
+ /**
276
+ * startViaRubic
277
+ * payable
278
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
279
+ */
280
+ async startViaRubic(tokens, amounts, facetCallData, options) {
281
+ if (!this.contract.write) {
282
+ throw new Error('Wallet client is required for write operations');
283
+ }
284
+ return this.contract.write.startViaRubic([tokens, amounts, facetCallData], options);
285
+ }
286
+ /**
287
+ * transferOwnership
288
+ * nonpayable
289
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
290
+ */
291
+ async transferOwnership(newOwner, options) {
292
+ if (!this.contract.write) {
293
+ throw new Error('Wallet client is required for write operations');
294
+ }
295
+ return this.contract.write.transferOwnership([newOwner], options);
296
+ }
297
+ /**
298
+ * Simulate contract write operations (dry-run without sending transaction)
299
+ *
300
+ * @example
301
+ * const result = await contract.simulate.transfer('0x...', 1000n);
302
+ * console.log('Gas estimate:', result.request.gas);
303
+ * console.log('Would succeed:', result.result);
304
+ */
305
+ get simulate() {
306
+ const contract = this.contract;
307
+ if (!contract.simulate) {
308
+ throw new Error('Public client is required for simulation');
309
+ }
310
+ return {
311
+ /**
312
+ * Simulate renounceOwnership
313
+ * Returns gas estimate and result without sending transaction
314
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
315
+ */
316
+ async renounceOwnership(options) {
317
+ return contract.simulate.renounceOwnership(options);
318
+ },
319
+ /**
320
+ * Simulate setDiamond
321
+ * Returns gas estimate and result without sending transaction
322
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
323
+ */
324
+ async setDiamond(_diamond, options) {
325
+ return contract.simulate.setDiamond([_diamond], options);
326
+ },
327
+ /**
328
+ * Simulate startViaRubic
329
+ * Returns gas estimate and result without sending transaction
330
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
331
+ */
332
+ async startViaRubic(tokens, amounts, facetCallData, options) {
333
+ return contract.simulate.startViaRubic([tokens, amounts, facetCallData], options);
334
+ },
335
+ /**
336
+ * Simulate transferOwnership
337
+ * Returns gas estimate and result without sending transaction
338
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
339
+ */
340
+ async transferOwnership(newOwner, options) {
341
+ return contract.simulate.transferOwnership([newOwner], options);
342
+ }
343
+ };
344
+ }
345
+ /**
346
+ * Watch contract events
347
+ *
348
+ * @example
349
+ * // Watch all Transfer events
350
+ * const unwatch = contract.watch.Transfer((event) => {
351
+ * console.log('Transfer:', event);
352
+ * });
353
+ *
354
+ * // Stop watching
355
+ * unwatch();
356
+ */
357
+ get watch() {
358
+ return {
359
+ /**
360
+ * Watch DiamondSet events
361
+ * @param callback Function to call when event is emitted
362
+ * @param filter Optional filter for indexed parameters
363
+ * @returns Unwatch function to stop listening
364
+ */
365
+ DiamondSet: (callback) => {
366
+ return this.publicClient.watchContractEvent({
367
+ address: this.contractAddress,
368
+ abi: exports.ERC20ProxyAbi,
369
+ eventName: 'DiamondSet',
370
+ onLogs: (logs) => {
371
+ logs.forEach((log) => {
372
+ callback(log.args);
373
+ });
374
+ },
375
+ });
376
+ },
377
+ /**
378
+ * Watch OwnershipTransferred events
379
+ * @param callback Function to call when event is emitted
380
+ * @param filter Optional filter for indexed parameters
381
+ * @returns Unwatch function to stop listening
382
+ */
383
+ OwnershipTransferred: (callback, filter) => {
384
+ return this.publicClient.watchContractEvent({
385
+ address: this.contractAddress,
386
+ abi: exports.ERC20ProxyAbi,
387
+ eventName: 'OwnershipTransferred',
388
+ args: filter,
389
+ onLogs: (logs) => {
390
+ logs.forEach((log) => {
391
+ callback(log.args);
392
+ });
393
+ },
394
+ });
395
+ }
396
+ };
397
+ }
398
+ }
399
+ exports.ERC20Proxy = ERC20Proxy;