@gitmyabi/rolesauthority 0.0.0-stage → 1.0.3
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 +107 -2
- package/contracts/RolesAuthority.d.ts +685 -0
- package/contracts/RolesAuthority.js +758 -0
- package/contracts/RolesAuthority.ts +908 -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 +40 -3
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RolesAuthority = exports.RolesAuthorityAbi = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* RolesAuthority ABI
|
|
7
|
+
*
|
|
8
|
+
* This ABI is typed using viem's type system for full type safety.
|
|
9
|
+
*/
|
|
10
|
+
exports.RolesAuthorityAbi = [
|
|
11
|
+
{
|
|
12
|
+
"inputs": [
|
|
13
|
+
{
|
|
14
|
+
"internalType": "address",
|
|
15
|
+
"name": "_owner",
|
|
16
|
+
"type": "address"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"internalType": "contract Authority",
|
|
20
|
+
"name": "_authority",
|
|
21
|
+
"type": "address"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"stateMutability": "nonpayable",
|
|
25
|
+
"type": "constructor"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"anonymous": false,
|
|
29
|
+
"inputs": [
|
|
30
|
+
{
|
|
31
|
+
"indexed": true,
|
|
32
|
+
"internalType": "address",
|
|
33
|
+
"name": "user",
|
|
34
|
+
"type": "address"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"indexed": true,
|
|
38
|
+
"internalType": "contract Authority",
|
|
39
|
+
"name": "newAuthority",
|
|
40
|
+
"type": "address"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"name": "AuthorityUpdated",
|
|
44
|
+
"type": "event"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"anonymous": false,
|
|
48
|
+
"inputs": [
|
|
49
|
+
{
|
|
50
|
+
"indexed": true,
|
|
51
|
+
"internalType": "address",
|
|
52
|
+
"name": "user",
|
|
53
|
+
"type": "address"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"indexed": true,
|
|
57
|
+
"internalType": "address",
|
|
58
|
+
"name": "newOwner",
|
|
59
|
+
"type": "address"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"name": "OwnershipTransferred",
|
|
63
|
+
"type": "event"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"anonymous": false,
|
|
67
|
+
"inputs": [
|
|
68
|
+
{
|
|
69
|
+
"indexed": true,
|
|
70
|
+
"internalType": "address",
|
|
71
|
+
"name": "target",
|
|
72
|
+
"type": "address"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"indexed": true,
|
|
76
|
+
"internalType": "bytes4",
|
|
77
|
+
"name": "functionSig",
|
|
78
|
+
"type": "bytes4"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"indexed": false,
|
|
82
|
+
"internalType": "bool",
|
|
83
|
+
"name": "enabled",
|
|
84
|
+
"type": "bool"
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"name": "PublicCapabilityUpdated",
|
|
88
|
+
"type": "event"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"anonymous": false,
|
|
92
|
+
"inputs": [
|
|
93
|
+
{
|
|
94
|
+
"indexed": true,
|
|
95
|
+
"internalType": "uint8",
|
|
96
|
+
"name": "role",
|
|
97
|
+
"type": "uint8"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"indexed": true,
|
|
101
|
+
"internalType": "address",
|
|
102
|
+
"name": "target",
|
|
103
|
+
"type": "address"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"indexed": true,
|
|
107
|
+
"internalType": "bytes4",
|
|
108
|
+
"name": "functionSig",
|
|
109
|
+
"type": "bytes4"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"indexed": false,
|
|
113
|
+
"internalType": "bool",
|
|
114
|
+
"name": "enabled",
|
|
115
|
+
"type": "bool"
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
"name": "RoleCapabilityUpdated",
|
|
119
|
+
"type": "event"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"anonymous": false,
|
|
123
|
+
"inputs": [
|
|
124
|
+
{
|
|
125
|
+
"indexed": true,
|
|
126
|
+
"internalType": "address",
|
|
127
|
+
"name": "user",
|
|
128
|
+
"type": "address"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"indexed": true,
|
|
132
|
+
"internalType": "uint8",
|
|
133
|
+
"name": "role",
|
|
134
|
+
"type": "uint8"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"indexed": false,
|
|
138
|
+
"internalType": "bool",
|
|
139
|
+
"name": "enabled",
|
|
140
|
+
"type": "bool"
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
"name": "UserRoleUpdated",
|
|
144
|
+
"type": "event"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"inputs": [],
|
|
148
|
+
"name": "authority",
|
|
149
|
+
"outputs": [
|
|
150
|
+
{
|
|
151
|
+
"internalType": "contract Authority",
|
|
152
|
+
"name": "",
|
|
153
|
+
"type": "address"
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
"stateMutability": "view",
|
|
157
|
+
"type": "function"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"inputs": [
|
|
161
|
+
{
|
|
162
|
+
"internalType": "address",
|
|
163
|
+
"name": "user",
|
|
164
|
+
"type": "address"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"internalType": "address",
|
|
168
|
+
"name": "target",
|
|
169
|
+
"type": "address"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"internalType": "bytes4",
|
|
173
|
+
"name": "functionSig",
|
|
174
|
+
"type": "bytes4"
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
"name": "canCall",
|
|
178
|
+
"outputs": [
|
|
179
|
+
{
|
|
180
|
+
"internalType": "bool",
|
|
181
|
+
"name": "",
|
|
182
|
+
"type": "bool"
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
"stateMutability": "view",
|
|
186
|
+
"type": "function"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"inputs": [
|
|
190
|
+
{
|
|
191
|
+
"internalType": "uint8",
|
|
192
|
+
"name": "role",
|
|
193
|
+
"type": "uint8"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"internalType": "address",
|
|
197
|
+
"name": "target",
|
|
198
|
+
"type": "address"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"internalType": "bytes4",
|
|
202
|
+
"name": "functionSig",
|
|
203
|
+
"type": "bytes4"
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
"name": "doesRoleHaveCapability",
|
|
207
|
+
"outputs": [
|
|
208
|
+
{
|
|
209
|
+
"internalType": "bool",
|
|
210
|
+
"name": "",
|
|
211
|
+
"type": "bool"
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
"stateMutability": "view",
|
|
215
|
+
"type": "function"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"inputs": [
|
|
219
|
+
{
|
|
220
|
+
"internalType": "address",
|
|
221
|
+
"name": "user",
|
|
222
|
+
"type": "address"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"internalType": "uint8",
|
|
226
|
+
"name": "role",
|
|
227
|
+
"type": "uint8"
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"name": "doesUserHaveRole",
|
|
231
|
+
"outputs": [
|
|
232
|
+
{
|
|
233
|
+
"internalType": "bool",
|
|
234
|
+
"name": "",
|
|
235
|
+
"type": "bool"
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
"stateMutability": "view",
|
|
239
|
+
"type": "function"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"inputs": [
|
|
243
|
+
{
|
|
244
|
+
"internalType": "address",
|
|
245
|
+
"name": "",
|
|
246
|
+
"type": "address"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"internalType": "bytes4",
|
|
250
|
+
"name": "",
|
|
251
|
+
"type": "bytes4"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
"name": "getRolesWithCapability",
|
|
255
|
+
"outputs": [
|
|
256
|
+
{
|
|
257
|
+
"internalType": "bytes32",
|
|
258
|
+
"name": "",
|
|
259
|
+
"type": "bytes32"
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
"stateMutability": "view",
|
|
263
|
+
"type": "function"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"inputs": [
|
|
267
|
+
{
|
|
268
|
+
"internalType": "address",
|
|
269
|
+
"name": "",
|
|
270
|
+
"type": "address"
|
|
271
|
+
}
|
|
272
|
+
],
|
|
273
|
+
"name": "getUserRoles",
|
|
274
|
+
"outputs": [
|
|
275
|
+
{
|
|
276
|
+
"internalType": "bytes32",
|
|
277
|
+
"name": "",
|
|
278
|
+
"type": "bytes32"
|
|
279
|
+
}
|
|
280
|
+
],
|
|
281
|
+
"stateMutability": "view",
|
|
282
|
+
"type": "function"
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
"inputs": [
|
|
286
|
+
{
|
|
287
|
+
"internalType": "address",
|
|
288
|
+
"name": "",
|
|
289
|
+
"type": "address"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"internalType": "bytes4",
|
|
293
|
+
"name": "",
|
|
294
|
+
"type": "bytes4"
|
|
295
|
+
}
|
|
296
|
+
],
|
|
297
|
+
"name": "isCapabilityPublic",
|
|
298
|
+
"outputs": [
|
|
299
|
+
{
|
|
300
|
+
"internalType": "bool",
|
|
301
|
+
"name": "",
|
|
302
|
+
"type": "bool"
|
|
303
|
+
}
|
|
304
|
+
],
|
|
305
|
+
"stateMutability": "view",
|
|
306
|
+
"type": "function"
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
"inputs": [],
|
|
310
|
+
"name": "owner",
|
|
311
|
+
"outputs": [
|
|
312
|
+
{
|
|
313
|
+
"internalType": "address",
|
|
314
|
+
"name": "",
|
|
315
|
+
"type": "address"
|
|
316
|
+
}
|
|
317
|
+
],
|
|
318
|
+
"stateMutability": "view",
|
|
319
|
+
"type": "function"
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"inputs": [
|
|
323
|
+
{
|
|
324
|
+
"internalType": "contract Authority",
|
|
325
|
+
"name": "newAuthority",
|
|
326
|
+
"type": "address"
|
|
327
|
+
}
|
|
328
|
+
],
|
|
329
|
+
"name": "setAuthority",
|
|
330
|
+
"outputs": [],
|
|
331
|
+
"stateMutability": "nonpayable",
|
|
332
|
+
"type": "function"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"inputs": [
|
|
336
|
+
{
|
|
337
|
+
"internalType": "address",
|
|
338
|
+
"name": "target",
|
|
339
|
+
"type": "address"
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
"internalType": "bytes4",
|
|
343
|
+
"name": "functionSig",
|
|
344
|
+
"type": "bytes4"
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
"internalType": "bool",
|
|
348
|
+
"name": "enabled",
|
|
349
|
+
"type": "bool"
|
|
350
|
+
}
|
|
351
|
+
],
|
|
352
|
+
"name": "setPublicCapability",
|
|
353
|
+
"outputs": [],
|
|
354
|
+
"stateMutability": "nonpayable",
|
|
355
|
+
"type": "function"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
"inputs": [
|
|
359
|
+
{
|
|
360
|
+
"internalType": "uint8",
|
|
361
|
+
"name": "role",
|
|
362
|
+
"type": "uint8"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
"internalType": "address",
|
|
366
|
+
"name": "target",
|
|
367
|
+
"type": "address"
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
"internalType": "bytes4",
|
|
371
|
+
"name": "functionSig",
|
|
372
|
+
"type": "bytes4"
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"internalType": "bool",
|
|
376
|
+
"name": "enabled",
|
|
377
|
+
"type": "bool"
|
|
378
|
+
}
|
|
379
|
+
],
|
|
380
|
+
"name": "setRoleCapability",
|
|
381
|
+
"outputs": [],
|
|
382
|
+
"stateMutability": "nonpayable",
|
|
383
|
+
"type": "function"
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
"inputs": [
|
|
387
|
+
{
|
|
388
|
+
"internalType": "address",
|
|
389
|
+
"name": "user",
|
|
390
|
+
"type": "address"
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
"internalType": "uint8",
|
|
394
|
+
"name": "role",
|
|
395
|
+
"type": "uint8"
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
"internalType": "bool",
|
|
399
|
+
"name": "enabled",
|
|
400
|
+
"type": "bool"
|
|
401
|
+
}
|
|
402
|
+
],
|
|
403
|
+
"name": "setUserRole",
|
|
404
|
+
"outputs": [],
|
|
405
|
+
"stateMutability": "nonpayable",
|
|
406
|
+
"type": "function"
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
"inputs": [
|
|
410
|
+
{
|
|
411
|
+
"internalType": "address",
|
|
412
|
+
"name": "newOwner",
|
|
413
|
+
"type": "address"
|
|
414
|
+
}
|
|
415
|
+
],
|
|
416
|
+
"name": "transferOwnership",
|
|
417
|
+
"outputs": [],
|
|
418
|
+
"stateMutability": "nonpayable",
|
|
419
|
+
"type": "function"
|
|
420
|
+
}
|
|
421
|
+
];
|
|
422
|
+
/**
|
|
423
|
+
* RolesAuthority Contract Class
|
|
424
|
+
*
|
|
425
|
+
* Provides a class-based API similar to TypeChain for interacting with the contract.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
430
|
+
* import { mainnet } from 'viem/chains';
|
|
431
|
+
* import { RolesAuthority } from 'RolesAuthority';
|
|
432
|
+
*
|
|
433
|
+
* const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
434
|
+
* const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
435
|
+
*
|
|
436
|
+
* const contract = new RolesAuthority('0x...', { publicClient, walletClient });
|
|
437
|
+
*
|
|
438
|
+
* // Read functions
|
|
439
|
+
* const result = await contract.balanceOf('0x...');
|
|
440
|
+
*
|
|
441
|
+
* // Write functions
|
|
442
|
+
* const hash = await contract.transfer('0x...', 1000n);
|
|
443
|
+
*
|
|
444
|
+
* // Simulate transactions (dry-run)
|
|
445
|
+
* const simulation = await contract.simulate.transfer('0x...', 1000n);
|
|
446
|
+
* console.log('Gas estimate:', simulation.request.gas);
|
|
447
|
+
*
|
|
448
|
+
* // Watch events
|
|
449
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
450
|
+
* console.log('Transfer event:', event);
|
|
451
|
+
* });
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
class RolesAuthority {
|
|
455
|
+
constructor(address, clients) {
|
|
456
|
+
this.contractAddress = address;
|
|
457
|
+
this.publicClient = clients.publicClient;
|
|
458
|
+
this.contract = (0, viem_1.getContract)({
|
|
459
|
+
address,
|
|
460
|
+
abi: exports.RolesAuthorityAbi,
|
|
461
|
+
client: {
|
|
462
|
+
public: clients.publicClient,
|
|
463
|
+
wallet: clients.walletClient,
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Get the contract address
|
|
469
|
+
*/
|
|
470
|
+
get address() {
|
|
471
|
+
return this.contractAddress;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Get the underlying viem contract instance.
|
|
475
|
+
*/
|
|
476
|
+
getContract() {
|
|
477
|
+
return this.contract;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* authority
|
|
481
|
+
* view
|
|
482
|
+
*/
|
|
483
|
+
async authority() {
|
|
484
|
+
return this.contract.read.authority();
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* canCall
|
|
488
|
+
* view
|
|
489
|
+
*/
|
|
490
|
+
async canCall(user, target, functionSig) {
|
|
491
|
+
return this.contract.read.canCall([user, target, functionSig]);
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* doesRoleHaveCapability
|
|
495
|
+
* view
|
|
496
|
+
*/
|
|
497
|
+
async doesRoleHaveCapability(role, target, functionSig) {
|
|
498
|
+
return this.contract.read.doesRoleHaveCapability([role, target, functionSig]);
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* doesUserHaveRole
|
|
502
|
+
* view
|
|
503
|
+
*/
|
|
504
|
+
async doesUserHaveRole(user, role) {
|
|
505
|
+
return this.contract.read.doesUserHaveRole([user, role]);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* getRolesWithCapability
|
|
509
|
+
* view
|
|
510
|
+
*/
|
|
511
|
+
async getRolesWithCapability(arg0, arg1) {
|
|
512
|
+
return this.contract.read.getRolesWithCapability([arg0, arg1]);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* getUserRoles
|
|
516
|
+
* view
|
|
517
|
+
*/
|
|
518
|
+
async getUserRoles(arg0) {
|
|
519
|
+
return this.contract.read.getUserRoles([arg0]);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* isCapabilityPublic
|
|
523
|
+
* view
|
|
524
|
+
*/
|
|
525
|
+
async isCapabilityPublic(arg0, arg1) {
|
|
526
|
+
return this.contract.read.isCapabilityPublic([arg0, arg1]);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* owner
|
|
530
|
+
* view
|
|
531
|
+
*/
|
|
532
|
+
async owner() {
|
|
533
|
+
return this.contract.read.owner();
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* setAuthority
|
|
537
|
+
* nonpayable
|
|
538
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
539
|
+
*/
|
|
540
|
+
async setAuthority(newAuthority, options) {
|
|
541
|
+
if (!this.contract.write) {
|
|
542
|
+
throw new Error('Wallet client is required for write operations');
|
|
543
|
+
}
|
|
544
|
+
return this.contract.write.setAuthority([newAuthority], options);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* setPublicCapability
|
|
548
|
+
* nonpayable
|
|
549
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
550
|
+
*/
|
|
551
|
+
async setPublicCapability(target, functionSig, enabled, options) {
|
|
552
|
+
if (!this.contract.write) {
|
|
553
|
+
throw new Error('Wallet client is required for write operations');
|
|
554
|
+
}
|
|
555
|
+
return this.contract.write.setPublicCapability([target, functionSig, enabled], options);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* setRoleCapability
|
|
559
|
+
* nonpayable
|
|
560
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
561
|
+
*/
|
|
562
|
+
async setRoleCapability(role, target, functionSig, enabled, options) {
|
|
563
|
+
if (!this.contract.write) {
|
|
564
|
+
throw new Error('Wallet client is required for write operations');
|
|
565
|
+
}
|
|
566
|
+
return this.contract.write.setRoleCapability([role, target, functionSig, enabled], options);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* setUserRole
|
|
570
|
+
* nonpayable
|
|
571
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
572
|
+
*/
|
|
573
|
+
async setUserRole(user, role, enabled, options) {
|
|
574
|
+
if (!this.contract.write) {
|
|
575
|
+
throw new Error('Wallet client is required for write operations');
|
|
576
|
+
}
|
|
577
|
+
return this.contract.write.setUserRole([user, role, enabled], options);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* transferOwnership
|
|
581
|
+
* nonpayable
|
|
582
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
583
|
+
*/
|
|
584
|
+
async transferOwnership(newOwner, options) {
|
|
585
|
+
if (!this.contract.write) {
|
|
586
|
+
throw new Error('Wallet client is required for write operations');
|
|
587
|
+
}
|
|
588
|
+
return this.contract.write.transferOwnership([newOwner], options);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Simulate contract write operations (dry-run without sending transaction)
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* const result = await contract.simulate.transfer('0x...', 1000n);
|
|
595
|
+
* console.log('Gas estimate:', result.request.gas);
|
|
596
|
+
* console.log('Would succeed:', result.result);
|
|
597
|
+
*/
|
|
598
|
+
get simulate() {
|
|
599
|
+
const contract = this.contract;
|
|
600
|
+
if (!contract.simulate) {
|
|
601
|
+
throw new Error('Public client is required for simulation');
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
/**
|
|
605
|
+
* Simulate setAuthority
|
|
606
|
+
* Returns gas estimate and result without sending transaction
|
|
607
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
608
|
+
*/
|
|
609
|
+
async setAuthority(newAuthority, options) {
|
|
610
|
+
return contract.simulate.setAuthority([newAuthority], options);
|
|
611
|
+
},
|
|
612
|
+
/**
|
|
613
|
+
* Simulate setPublicCapability
|
|
614
|
+
* Returns gas estimate and result without sending transaction
|
|
615
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
616
|
+
*/
|
|
617
|
+
async setPublicCapability(target, functionSig, enabled, options) {
|
|
618
|
+
return contract.simulate.setPublicCapability([target, functionSig, enabled], options);
|
|
619
|
+
},
|
|
620
|
+
/**
|
|
621
|
+
* Simulate setRoleCapability
|
|
622
|
+
* Returns gas estimate and result without sending transaction
|
|
623
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
624
|
+
*/
|
|
625
|
+
async setRoleCapability(role, target, functionSig, enabled, options) {
|
|
626
|
+
return contract.simulate.setRoleCapability([role, target, functionSig, enabled], options);
|
|
627
|
+
},
|
|
628
|
+
/**
|
|
629
|
+
* Simulate setUserRole
|
|
630
|
+
* Returns gas estimate and result without sending transaction
|
|
631
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
632
|
+
*/
|
|
633
|
+
async setUserRole(user, role, enabled, options) {
|
|
634
|
+
return contract.simulate.setUserRole([user, role, enabled], options);
|
|
635
|
+
},
|
|
636
|
+
/**
|
|
637
|
+
* Simulate transferOwnership
|
|
638
|
+
* Returns gas estimate and result without sending transaction
|
|
639
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
640
|
+
*/
|
|
641
|
+
async transferOwnership(newOwner, options) {
|
|
642
|
+
return contract.simulate.transferOwnership([newOwner], options);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Watch contract events
|
|
648
|
+
*
|
|
649
|
+
* @example
|
|
650
|
+
* // Watch all Transfer events
|
|
651
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
652
|
+
* console.log('Transfer:', event);
|
|
653
|
+
* });
|
|
654
|
+
*
|
|
655
|
+
* // Stop watching
|
|
656
|
+
* unwatch();
|
|
657
|
+
*/
|
|
658
|
+
get watch() {
|
|
659
|
+
return {
|
|
660
|
+
/**
|
|
661
|
+
* Watch AuthorityUpdated events
|
|
662
|
+
* @param callback Function to call when event is emitted
|
|
663
|
+
* @param filter Optional filter for indexed parameters
|
|
664
|
+
* @returns Unwatch function to stop listening
|
|
665
|
+
*/
|
|
666
|
+
AuthorityUpdated: (callback, filter) => {
|
|
667
|
+
return this.publicClient.watchContractEvent({
|
|
668
|
+
address: this.contractAddress,
|
|
669
|
+
abi: exports.RolesAuthorityAbi,
|
|
670
|
+
eventName: 'AuthorityUpdated',
|
|
671
|
+
args: filter,
|
|
672
|
+
onLogs: (logs) => {
|
|
673
|
+
logs.forEach((log) => {
|
|
674
|
+
callback(log.args);
|
|
675
|
+
});
|
|
676
|
+
},
|
|
677
|
+
});
|
|
678
|
+
},
|
|
679
|
+
/**
|
|
680
|
+
* Watch OwnershipTransferred events
|
|
681
|
+
* @param callback Function to call when event is emitted
|
|
682
|
+
* @param filter Optional filter for indexed parameters
|
|
683
|
+
* @returns Unwatch function to stop listening
|
|
684
|
+
*/
|
|
685
|
+
OwnershipTransferred: (callback, filter) => {
|
|
686
|
+
return this.publicClient.watchContractEvent({
|
|
687
|
+
address: this.contractAddress,
|
|
688
|
+
abi: exports.RolesAuthorityAbi,
|
|
689
|
+
eventName: 'OwnershipTransferred',
|
|
690
|
+
args: filter,
|
|
691
|
+
onLogs: (logs) => {
|
|
692
|
+
logs.forEach((log) => {
|
|
693
|
+
callback(log.args);
|
|
694
|
+
});
|
|
695
|
+
},
|
|
696
|
+
});
|
|
697
|
+
},
|
|
698
|
+
/**
|
|
699
|
+
* Watch PublicCapabilityUpdated events
|
|
700
|
+
* @param callback Function to call when event is emitted
|
|
701
|
+
* @param filter Optional filter for indexed parameters
|
|
702
|
+
* @returns Unwatch function to stop listening
|
|
703
|
+
*/
|
|
704
|
+
PublicCapabilityUpdated: (callback, filter) => {
|
|
705
|
+
return this.publicClient.watchContractEvent({
|
|
706
|
+
address: this.contractAddress,
|
|
707
|
+
abi: exports.RolesAuthorityAbi,
|
|
708
|
+
eventName: 'PublicCapabilityUpdated',
|
|
709
|
+
args: filter,
|
|
710
|
+
onLogs: (logs) => {
|
|
711
|
+
logs.forEach((log) => {
|
|
712
|
+
callback(log.args);
|
|
713
|
+
});
|
|
714
|
+
},
|
|
715
|
+
});
|
|
716
|
+
},
|
|
717
|
+
/**
|
|
718
|
+
* Watch RoleCapabilityUpdated events
|
|
719
|
+
* @param callback Function to call when event is emitted
|
|
720
|
+
* @param filter Optional filter for indexed parameters
|
|
721
|
+
* @returns Unwatch function to stop listening
|
|
722
|
+
*/
|
|
723
|
+
RoleCapabilityUpdated: (callback, filter) => {
|
|
724
|
+
return this.publicClient.watchContractEvent({
|
|
725
|
+
address: this.contractAddress,
|
|
726
|
+
abi: exports.RolesAuthorityAbi,
|
|
727
|
+
eventName: 'RoleCapabilityUpdated',
|
|
728
|
+
args: filter,
|
|
729
|
+
onLogs: (logs) => {
|
|
730
|
+
logs.forEach((log) => {
|
|
731
|
+
callback(log.args);
|
|
732
|
+
});
|
|
733
|
+
},
|
|
734
|
+
});
|
|
735
|
+
},
|
|
736
|
+
/**
|
|
737
|
+
* Watch UserRoleUpdated events
|
|
738
|
+
* @param callback Function to call when event is emitted
|
|
739
|
+
* @param filter Optional filter for indexed parameters
|
|
740
|
+
* @returns Unwatch function to stop listening
|
|
741
|
+
*/
|
|
742
|
+
UserRoleUpdated: (callback, filter) => {
|
|
743
|
+
return this.publicClient.watchContractEvent({
|
|
744
|
+
address: this.contractAddress,
|
|
745
|
+
abi: exports.RolesAuthorityAbi,
|
|
746
|
+
eventName: 'UserRoleUpdated',
|
|
747
|
+
args: filter,
|
|
748
|
+
onLogs: (logs) => {
|
|
749
|
+
logs.forEach((log) => {
|
|
750
|
+
callback(log.args);
|
|
751
|
+
});
|
|
752
|
+
},
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
exports.RolesAuthority = RolesAuthority;
|