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