@aastar/core 0.16.8 → 0.16.12

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.
Files changed (60) hide show
  1. package/dist/abis/PaymasterV4_2.json +1193 -0
  2. package/dist/abis/SuperPaymaster.json +1 -1
  3. package/dist/abis/aPNTs.json +1160 -0
  4. package/dist/abis/abi.config.json +3 -3
  5. package/dist/abis/index.d.ts +15 -104
  6. package/dist/abis/index.js +22 -46
  7. package/dist/actions/account.d.ts +0 -15
  8. package/dist/actions/account.js +143 -108
  9. package/dist/actions/aggregator.d.ts +68 -7
  10. package/dist/actions/aggregator.js +328 -28
  11. package/dist/actions/dvt.d.ts +33 -5
  12. package/dist/actions/dvt.js +238 -38
  13. package/dist/actions/entryPoint.d.ts +3 -63
  14. package/dist/actions/entryPoint.js +52 -184
  15. package/dist/actions/factory.d.ts +48 -115
  16. package/dist/actions/factory.js +638 -438
  17. package/dist/actions/faucet.d.ts +23 -27
  18. package/dist/actions/faucet.js +150 -289
  19. package/dist/actions/index.d.ts +1 -2
  20. package/dist/actions/index.js +2 -4
  21. package/dist/actions/paymaster.d.ts +147 -0
  22. package/dist/actions/paymaster.js +706 -0
  23. package/dist/actions/paymasterV4.d.ts +26 -95
  24. package/dist/actions/paymasterV4.js +28 -121
  25. package/dist/actions/registry.d.ts +116 -165
  26. package/dist/actions/registry.js +855 -654
  27. package/dist/actions/reputation.d.ts +74 -52
  28. package/dist/actions/reputation.js +548 -242
  29. package/dist/actions/sbt.d.ts +90 -100
  30. package/dist/actions/sbt.js +801 -518
  31. package/dist/actions/staking.d.ts +45 -32
  32. package/dist/actions/staking.js +431 -260
  33. package/dist/actions/superPaymaster.d.ts +140 -158
  34. package/dist/actions/superPaymaster.js +965 -631
  35. package/dist/actions/tokens.d.ts +130 -108
  36. package/dist/actions/tokens.js +470 -414
  37. package/dist/actions/validators.d.ts +0 -73
  38. package/dist/actions/validators.js +0 -94
  39. package/dist/clients/BaseClient.d.ts +3 -3
  40. package/dist/clients/BundlerClient.d.ts +55 -0
  41. package/dist/clients/BundlerClient.js +92 -0
  42. package/dist/communities.js +2 -2
  43. package/dist/constants.js +1 -28
  44. package/dist/contract-addresses.d.ts +5 -14
  45. package/dist/contract-addresses.js +3 -9
  46. package/dist/contract-versions.d.ts +138 -0
  47. package/dist/contract-versions.js +328 -0
  48. package/dist/contracts.d.ts +6 -24
  49. package/dist/contracts.js +2 -2
  50. package/dist/errors/index.d.ts +57 -0
  51. package/dist/errors/index.js +123 -0
  52. package/dist/index.d.ts +2 -1
  53. package/dist/index.js +2 -1
  54. package/dist/requirementChecker.d.ts +35 -1
  55. package/dist/requirementChecker.js +39 -1
  56. package/dist/roles.d.ts +50 -61
  57. package/dist/roles.js +50 -61
  58. package/dist/validators/index.d.ts +35 -0
  59. package/dist/validators/index.js +60 -0
  60. package/package.json +5 -13
@@ -1,667 +1,868 @@
1
1
  import { RegistryABI } from '../abis/index.js';
2
+ import { validateAddress, validateRequired, validateAmount } from '../validators/index.js';
3
+ import { AAStarError } from '../errors/index.js';
2
4
  export const registryActions = (address) => (client) => ({
3
5
  // Role Management
4
- async registryConfigureRole({ roleId, config, account }) {
5
- return client.writeContract({
6
- address,
7
- abi: RegistryABI,
8
- functionName: 'configureRole',
9
- args: [roleId, config],
10
- account: account,
11
- chain: client.chain
12
- });
13
- },
14
- async registryRegisterRole({ roleId, user, data, account }) {
15
- return client.writeContract({
16
- address,
17
- abi: RegistryABI,
18
- functionName: 'registerRole',
19
- args: [roleId, user, data],
20
- account: account,
21
- chain: client.chain
22
- });
23
- },
24
- async registryRegisterRoleSelf({ roleId, data, account }) {
25
- return client.writeContract({
26
- address,
27
- abi: RegistryABI,
28
- functionName: 'registerRoleSelf',
29
- args: [roleId, data],
30
- account: account,
31
- chain: client.chain
32
- });
33
- },
34
- async registryHasRole({ user, roleId }) {
35
- return client.readContract({
36
- address,
37
- abi: RegistryABI,
38
- functionName: 'hasRole',
39
- args: [roleId, user]
40
- });
41
- },
42
- async registryUnRegisterRole({ user, roleId, account }) {
43
- return client.writeContract({
44
- address,
45
- abi: RegistryABI,
46
- functionName: 'unregisterRole',
47
- args: [user, roleId],
48
- account: account,
49
- chain: client.chain
50
- });
51
- },
52
- async registryGetRoleConfig({ roleId }) {
53
- return client.readContract({
54
- address,
55
- abi: RegistryABI,
56
- functionName: 'getRoleConfig',
57
- args: [roleId]
58
- });
59
- },
60
- async registrySetRoleLockDuration({ roleId, duration, account }) {
61
- return client.writeContract({
62
- address,
63
- abi: RegistryABI,
64
- functionName: 'setRoleLockDuration',
65
- args: [roleId, duration],
66
- account: account,
67
- chain: client.chain
68
- });
69
- },
70
- async registrySetRoleOwner({ roleId, newOwner, account }) {
71
- return client.writeContract({
72
- address,
73
- abi: RegistryABI,
74
- functionName: 'setRoleOwner',
75
- args: [roleId, newOwner],
76
- account: account,
77
- chain: client.chain
78
- });
79
- },
80
- async registryIsCommunityMember({ community, user }) {
81
- const ROLE_ENDUSER = await this.registryROLE_ENDUSER();
82
- return this.registryHasRole({ user, roleId: ROLE_ENDUSER });
6
+ async configureRole({ roleId, config, account }) {
7
+ try {
8
+ validateRequired(roleId, 'roleId');
9
+ validateRequired(config, 'config');
10
+ return await client.writeContract({
11
+ address,
12
+ abi: RegistryABI,
13
+ functionName: 'configureRole',
14
+ args: [roleId, config],
15
+ account: account,
16
+ chain: client.chain
17
+ });
18
+ }
19
+ catch (error) {
20
+ throw AAStarError.fromViemError(error, 'configureRole');
21
+ }
22
+ },
23
+ async adminConfigureRole({ roleId, minStake, entryBurn, exitFeePercent, minExitFee, account }) {
24
+ try {
25
+ validateRequired(roleId, 'roleId');
26
+ return await client.writeContract({
27
+ address,
28
+ abi: RegistryABI,
29
+ functionName: 'adminConfigureRole',
30
+ args: [roleId, minStake, entryBurn, exitFeePercent, minExitFee],
31
+ account: account,
32
+ chain: client.chain
33
+ });
34
+ }
35
+ catch (error) {
36
+ throw AAStarError.fromViemError(error, 'adminConfigureRole');
37
+ }
38
+ },
39
+ async createNewRole({ roleId, config, roleOwner, account }) {
40
+ try {
41
+ validateRequired(roleId, 'roleId');
42
+ validateRequired(config, 'config');
43
+ validateAddress(roleOwner, 'roleOwner');
44
+ return await client.writeContract({
45
+ address,
46
+ abi: RegistryABI,
47
+ functionName: 'createNewRole',
48
+ args: [roleId, config, roleOwner],
49
+ account: account,
50
+ chain: client.chain
51
+ });
52
+ }
53
+ catch (error) {
54
+ throw AAStarError.fromViemError(error, 'createNewRole');
55
+ }
56
+ },
57
+ async registerRole({ roleId, user, data, account }) {
58
+ try {
59
+ validateRequired(roleId, 'roleId');
60
+ validateAddress(user, 'user');
61
+ return await client.writeContract({
62
+ address,
63
+ abi: RegistryABI,
64
+ functionName: 'registerRole',
65
+ args: [roleId, user, data],
66
+ account: account,
67
+ chain: client.chain
68
+ });
69
+ }
70
+ catch (error) {
71
+ throw AAStarError.fromViemError(error, 'registerRole');
72
+ }
73
+ },
74
+ async registerRoleSelf({ roleId, data, account }) {
75
+ try {
76
+ validateRequired(roleId, 'roleId');
77
+ return await client.writeContract({
78
+ address,
79
+ abi: RegistryABI,
80
+ functionName: 'registerRoleSelf',
81
+ args: [roleId, data],
82
+ account: account,
83
+ chain: client.chain
84
+ });
85
+ }
86
+ catch (error) {
87
+ throw AAStarError.fromViemError(error, 'registerRoleSelf');
88
+ }
89
+ },
90
+ async safeMintForRole({ roleId, user, data, account }) {
91
+ try {
92
+ validateRequired(roleId, 'roleId');
93
+ validateAddress(user, 'user');
94
+ return await client.writeContract({
95
+ address,
96
+ abi: RegistryABI,
97
+ functionName: 'safeMintForRole',
98
+ args: [roleId, user, data],
99
+ account: account,
100
+ chain: client.chain
101
+ });
102
+ }
103
+ catch (error) {
104
+ throw AAStarError.fromViemError(error, 'safeMintForRole');
105
+ }
106
+ },
107
+ async hasRole({ roleId, user }) {
108
+ try {
109
+ validateRequired(roleId, 'roleId');
110
+ validateAddress(user, 'user');
111
+ return await client.readContract({
112
+ address,
113
+ abi: RegistryABI,
114
+ functionName: 'hasRole',
115
+ args: [roleId, user]
116
+ });
117
+ }
118
+ catch (error) {
119
+ throw AAStarError.fromViemError(error, 'hasRole');
120
+ }
121
+ },
122
+ async getRoleConfig({ roleId }) {
123
+ try {
124
+ validateRequired(roleId, 'roleId');
125
+ const result = await client.readContract({
126
+ address,
127
+ abi: RegistryABI,
128
+ functionName: 'getRoleConfig',
129
+ args: [roleId]
130
+ });
131
+ if (Array.isArray(result)) {
132
+ return {
133
+ minStake: result[0],
134
+ entryBurn: result[1],
135
+ slashThreshold: result[2],
136
+ slashBase: result[3],
137
+ slashInc: result[4],
138
+ slashMax: result[5],
139
+ exitFeePercent: result[6],
140
+ isActive: result[7],
141
+ minExitFee: result[8],
142
+ description: result[9],
143
+ owner: result[10],
144
+ roleLockDuration: result[11]
145
+ };
146
+ }
147
+ return result;
148
+ }
149
+ catch (error) {
150
+ throw AAStarError.fromViemError(error, 'getRoleConfig');
151
+ }
152
+ },
153
+ async setRoleLockDuration({ roleId, duration, account }) {
154
+ try {
155
+ validateRequired(roleId, 'roleId');
156
+ validateRequired(duration, 'duration');
157
+ return await client.writeContract({
158
+ address,
159
+ abi: RegistryABI,
160
+ functionName: 'setRoleLockDuration',
161
+ args: [roleId, duration],
162
+ account: account,
163
+ chain: client.chain
164
+ });
165
+ }
166
+ catch (error) {
167
+ throw AAStarError.fromViemError(error, 'setRoleLockDuration');
168
+ }
169
+ },
170
+ async setRoleOwner({ roleId, newOwner, account }) {
171
+ try {
172
+ validateRequired(roleId, 'roleId');
173
+ validateAddress(newOwner, 'newOwner');
174
+ return await client.writeContract({
175
+ address,
176
+ abi: RegistryABI,
177
+ functionName: 'setRoleOwner',
178
+ args: [roleId, newOwner],
179
+ account: account,
180
+ chain: client.chain
181
+ });
182
+ }
183
+ catch (error) {
184
+ throw AAStarError.fromViemError(error, 'setRoleOwner');
185
+ }
186
+ },
187
+ async exitRole({ roleId, account }) {
188
+ try {
189
+ validateRequired(roleId, 'roleId');
190
+ return await client.writeContract({
191
+ address,
192
+ abi: RegistryABI,
193
+ functionName: 'exitRole',
194
+ args: [roleId],
195
+ account: account,
196
+ chain: client.chain
197
+ });
198
+ }
199
+ catch (error) {
200
+ throw AAStarError.fromViemError(error, 'exitRole');
201
+ }
202
+ },
203
+ // Community Management
204
+ async communityByName({ name }) {
205
+ try {
206
+ validateRequired(name, 'name');
207
+ return await client.readContract({
208
+ address,
209
+ abi: RegistryABI,
210
+ functionName: 'communityByName',
211
+ args: [name]
212
+ });
213
+ }
214
+ catch (error) {
215
+ throw AAStarError.fromViemError(error, 'communityByName');
216
+ }
217
+ },
218
+ async communityByENS({ ensName }) {
219
+ try {
220
+ validateRequired(ensName, 'ensName');
221
+ return await client.readContract({
222
+ address,
223
+ abi: RegistryABI,
224
+ functionName: 'communityByENS',
225
+ args: [ensName]
226
+ });
227
+ }
228
+ catch (error) {
229
+ throw AAStarError.fromViemError(error, 'communityByENS');
230
+ }
83
231
  },
84
232
  // Credit & Reputation
85
- async registryGlobalReputation({ user }) {
86
- return client.readContract({
87
- address,
88
- abi: RegistryABI,
89
- functionName: 'globalReputation',
90
- args: [user]
91
- });
92
- },
93
- async registryBatchUpdateGlobalReputation({ users, scores, epoch, proof, account }) {
94
- return client.writeContract({
95
- address,
96
- abi: RegistryABI,
97
- functionName: 'batchUpdateGlobalReputation',
98
- args: [users, scores, epoch, proof],
99
- account: account,
100
- chain: client.chain
101
- });
102
- },
103
- // Blacklist Management
104
- async registryUpdateOperatorBlacklist({ operator, users, statuses, proof, account }) {
105
- return client.writeContract({
106
- address,
107
- abi: RegistryABI,
108
- functionName: 'updateOperatorBlacklist',
109
- args: [operator, users, statuses, proof],
110
- account: account,
111
- chain: client.chain
112
- });
113
- },
114
- async registryIsOperatorBlacklisted({ operator }) {
115
- return client.readContract({
116
- address,
117
- abi: RegistryABI,
118
- functionName: 'isOperatorBlacklisted',
119
- args: [operator]
120
- });
233
+ async getCreditLimit({ user }) {
234
+ try {
235
+ validateAddress(user, 'user');
236
+ return await client.readContract({
237
+ address,
238
+ abi: RegistryABI,
239
+ functionName: 'getCreditLimit',
240
+ args: [user]
241
+ });
242
+ }
243
+ catch (error) {
244
+ throw AAStarError.fromViemError(error, 'getCreditLimit');
245
+ }
246
+ },
247
+ async globalReputation({ user }) {
248
+ try {
249
+ validateAddress(user, 'user');
250
+ return await client.readContract({
251
+ address,
252
+ abi: RegistryABI,
253
+ functionName: 'globalReputation',
254
+ args: [user]
255
+ });
256
+ }
257
+ catch (error) {
258
+ throw AAStarError.fromViemError(error, 'globalReputation');
259
+ }
260
+ },
261
+ async addLevelThreshold({ threshold, account }) {
262
+ try {
263
+ validateAmount(threshold, 'threshold');
264
+ return await client.writeContract({
265
+ address,
266
+ abi: RegistryABI,
267
+ functionName: 'addLevelThreshold',
268
+ args: [threshold],
269
+ account: account,
270
+ chain: client.chain
271
+ });
272
+ }
273
+ catch (error) {
274
+ throw AAStarError.fromViemError(error, 'addLevelThreshold');
275
+ }
276
+ },
277
+ async batchUpdateGlobalReputation({ proposalId, users, newScores, epoch, proof, account }) {
278
+ try {
279
+ validateAmount(proposalId, 'proposalId');
280
+ validateRequired(users, 'users');
281
+ validateRequired(newScores, 'newScores');
282
+ validateAmount(epoch, 'epoch');
283
+ validateRequired(proof, 'proof');
284
+ return await client.writeContract({
285
+ address,
286
+ abi: RegistryABI,
287
+ functionName: 'batchUpdateGlobalReputation',
288
+ args: [proposalId, users, newScores, epoch, proof],
289
+ account: account,
290
+ chain: client.chain
291
+ });
292
+ }
293
+ catch (error) {
294
+ throw AAStarError.fromViemError(error, 'batchUpdateGlobalReputation');
295
+ }
121
296
  },
122
297
  // Contract References
123
- async registrySetBLSValidator({ validator, account }) {
124
- return client.writeContract({
125
- address,
126
- abi: RegistryABI,
127
- functionName: 'setBLSValidator',
128
- args: [validator],
129
- account: account,
130
- chain: client.chain
131
- });
132
- },
133
- async registrySetBLSAggregator({ aggregator, account }) {
134
- return client.writeContract({
135
- address,
136
- abi: RegistryABI,
137
- functionName: 'setBLSAggregator',
138
- args: [aggregator],
139
- account: account,
140
- chain: client.chain
141
- });
142
- },
143
- async registrySetMySBT({ sbt, account }) {
144
- return client.writeContract({
145
- address,
146
- abi: RegistryABI,
147
- functionName: 'setMySBT',
148
- args: [sbt],
149
- account: account,
150
- chain: client.chain
151
- });
152
- },
153
- async registrySetSuperPaymaster({ paymaster, account }) {
154
- return client.writeContract({
155
- address,
156
- abi: RegistryABI,
157
- functionName: 'setSuperPaymaster',
158
- args: [paymaster],
159
- account: account,
160
- chain: client.chain
161
- });
162
- },
163
- async registrySetStaking({ staking, account }) {
164
- return client.writeContract({
165
- address,
166
- abi: RegistryABI,
167
- functionName: 'setStaking',
168
- args: [staking],
169
- account: account,
170
- chain: client.chain
171
- });
172
- },
173
- async registrySetReputationSource({ source, account }) {
174
- return client.writeContract({
175
- address,
176
- abi: RegistryABI,
177
- functionName: 'setReputationSource',
178
- args: [source],
179
- account: account,
180
- chain: client.chain
181
- });
182
- },
183
- async registryBlsValidator() {
184
- return client.readContract({
185
- address,
186
- abi: RegistryABI,
187
- functionName: 'blsValidator',
188
- args: []
189
- });
190
- },
191
- async registryBlsAggregator() {
192
- return client.readContract({
193
- address,
194
- abi: RegistryABI,
195
- functionName: 'blsAggregator',
196
- args: []
197
- });
198
- },
199
- async registryMySBT() {
200
- return client.readContract({
201
- address,
202
- abi: RegistryABI,
203
- functionName: 'MYSBT',
204
- args: []
205
- });
206
- },
207
- async registrySuperPaymaster() {
208
- return client.readContract({
209
- address,
210
- abi: RegistryABI,
211
- functionName: 'SUPER_PAYMASTER',
212
- args: []
213
- });
214
- },
215
- async registryStaking() {
216
- return client.readContract({
217
- address,
218
- abi: RegistryABI,
219
- functionName: 'GTOKEN_STAKING',
220
- args: []
221
- });
222
- },
223
- async registryReputationSource() {
224
- return client.readContract({
225
- address,
226
- abi: RegistryABI,
227
- functionName: 'reputationSource',
228
- args: []
229
- });
230
- },
231
- // Admin
232
- async registryTransferOwnership({ newOwner, account }) {
233
- return client.writeContract({
234
- address,
235
- abi: RegistryABI,
236
- functionName: 'transferOwnership',
237
- args: [newOwner],
238
- account: account,
239
- chain: client.chain
240
- });
241
- },
242
- async registryOwner() {
243
- return client.readContract({
244
- address,
245
- abi: RegistryABI,
246
- functionName: 'owner',
247
- args: []
248
- });
249
- },
250
- async registryRenounceOwnership({ account }) {
251
- return client.writeContract({
252
- address,
253
- abi: RegistryABI,
254
- functionName: 'renounceOwnership',
255
- args: [],
256
- account: account,
257
- chain: client.chain
258
- });
298
+ async setBLSValidator({ validator, account }) {
299
+ try {
300
+ validateAddress(validator, 'validator');
301
+ return await client.writeContract({
302
+ address,
303
+ abi: RegistryABI,
304
+ functionName: 'setBLSValidator',
305
+ args: [validator],
306
+ account: account,
307
+ chain: client.chain
308
+ });
309
+ }
310
+ catch (error) {
311
+ throw AAStarError.fromViemError(error, 'setBLSValidator');
312
+ }
313
+ },
314
+ async setBLSAggregator({ aggregator, account }) {
315
+ try {
316
+ validateAddress(aggregator, 'aggregator');
317
+ return await client.writeContract({
318
+ address,
319
+ abi: RegistryABI,
320
+ functionName: 'setBLSAggregator',
321
+ args: [aggregator],
322
+ account: account,
323
+ chain: client.chain
324
+ });
325
+ }
326
+ catch (error) {
327
+ throw AAStarError.fromViemError(error, 'setBLSAggregator');
328
+ }
329
+ },
330
+ async setMySBT({ sbt, account }) {
331
+ try {
332
+ validateAddress(sbt, 'sbt');
333
+ return await client.writeContract({
334
+ address,
335
+ abi: RegistryABI,
336
+ functionName: 'setMySBT',
337
+ args: [sbt],
338
+ account: account,
339
+ chain: client.chain
340
+ });
341
+ }
342
+ catch (error) {
343
+ throw AAStarError.fromViemError(error, 'setMySBT');
344
+ }
345
+ },
346
+ async setSuperPaymaster({ paymaster, account }) {
347
+ try {
348
+ validateAddress(paymaster, 'paymaster');
349
+ return await client.writeContract({
350
+ address,
351
+ abi: RegistryABI,
352
+ functionName: 'setSuperPaymaster',
353
+ args: [paymaster],
354
+ account: account,
355
+ chain: client.chain
356
+ });
357
+ }
358
+ catch (error) {
359
+ throw AAStarError.fromViemError(error, 'setSuperPaymaster');
360
+ }
361
+ },
362
+ async setStaking({ staking, account }) {
363
+ try {
364
+ validateAddress(staking, 'staking');
365
+ return await client.writeContract({
366
+ address,
367
+ abi: RegistryABI,
368
+ functionName: 'setStaking',
369
+ args: [staking],
370
+ account: account,
371
+ chain: client.chain
372
+ });
373
+ }
374
+ catch (error) {
375
+ throw AAStarError.fromViemError(error, 'setStaking');
376
+ }
377
+ },
378
+ async setReputationSource({ source, account }) {
379
+ try {
380
+ validateAddress(source, 'source');
381
+ return await client.writeContract({
382
+ address,
383
+ abi: RegistryABI,
384
+ functionName: 'setReputationSource',
385
+ args: [source],
386
+ account: account,
387
+ chain: client.chain
388
+ });
389
+ }
390
+ catch (error) {
391
+ throw AAStarError.fromViemError(error, 'setReputationSource');
392
+ }
393
+ },
394
+ async blsValidator() {
395
+ try {
396
+ return await client.readContract({
397
+ address,
398
+ abi: RegistryABI,
399
+ functionName: 'blsValidator',
400
+ args: []
401
+ });
402
+ }
403
+ catch (error) {
404
+ throw AAStarError.fromViemError(error, 'blsValidator');
405
+ }
406
+ },
407
+ async blsAggregator() {
408
+ try {
409
+ return await client.readContract({
410
+ address,
411
+ abi: RegistryABI,
412
+ functionName: 'blsAggregator',
413
+ args: []
414
+ });
415
+ }
416
+ catch (error) {
417
+ throw AAStarError.fromViemError(error, 'blsAggregator');
418
+ }
419
+ },
420
+ async MYSBT() {
421
+ try {
422
+ return await client.readContract({
423
+ address,
424
+ abi: RegistryABI,
425
+ functionName: 'MYSBT',
426
+ args: []
427
+ });
428
+ }
429
+ catch (error) {
430
+ throw AAStarError.fromViemError(error, 'MYSBT');
431
+ }
432
+ },
433
+ async SUPER_PAYMASTER() {
434
+ try {
435
+ return await client.readContract({
436
+ address,
437
+ abi: RegistryABI,
438
+ functionName: 'SUPER_PAYMASTER',
439
+ args: []
440
+ });
441
+ }
442
+ catch (error) {
443
+ throw AAStarError.fromViemError(error, 'SUPER_PAYMASTER');
444
+ }
445
+ },
446
+ async GTOKEN_STAKING() {
447
+ try {
448
+ return await client.readContract({
449
+ address,
450
+ abi: RegistryABI,
451
+ functionName: 'GTOKEN_STAKING',
452
+ args: []
453
+ });
454
+ }
455
+ catch (error) {
456
+ throw AAStarError.fromViemError(error, 'GTOKEN_STAKING');
457
+ }
458
+ },
459
+ async reputationSource() {
460
+ try {
461
+ return await client.readContract({
462
+ address,
463
+ abi: RegistryABI,
464
+ functionName: 'reputationSource',
465
+ args: []
466
+ });
467
+ }
468
+ catch (error) {
469
+ throw AAStarError.fromViemError(error, 'reputationSource');
470
+ }
471
+ },
472
+ async isReputationSource({ source }) {
473
+ try {
474
+ validateAddress(source, 'source');
475
+ return await client.readContract({
476
+ address,
477
+ abi: RegistryABI,
478
+ functionName: 'isReputationSource',
479
+ args: [source]
480
+ });
481
+ }
482
+ catch (error) {
483
+ throw AAStarError.fromViemError(error, 'isReputationSource');
484
+ }
485
+ },
486
+ async lastReputationEpoch({ user }) {
487
+ try {
488
+ validateAddress(user, 'user');
489
+ return await client.readContract({
490
+ address,
491
+ abi: RegistryABI,
492
+ functionName: 'lastReputationEpoch',
493
+ args: [user]
494
+ });
495
+ }
496
+ catch (error) {
497
+ throw AAStarError.fromViemError(error, 'lastReputationEpoch');
498
+ }
259
499
  },
260
500
  // View Functions
261
- async registryRoleConfigs({ roleId }) {
262
- return client.readContract({
263
- address,
264
- abi: RegistryABI,
265
- functionName: 'roleConfigs',
266
- args: [roleId]
267
- });
268
- },
269
- async registryRoleCounts({ roleId }) {
270
- return client.readContract({
271
- address,
272
- abi: RegistryABI,
273
- functionName: 'roleCounts',
274
- args: [roleId]
275
- });
276
- },
277
- // Alias: getRoleMemberCount maps to contract's getRoleUserCount
278
- async registryGetRoleMemberCount({ roleId }) {
279
- return client.readContract({
280
- address,
281
- abi: RegistryABI,
282
- functionName: 'getRoleUserCount',
283
- args: [roleId]
284
- });
285
- },
286
- async registryRoleMembers({ roleId, index }) {
287
- return client.readContract({
288
- address,
289
- abi: RegistryABI,
290
- functionName: 'roleMembers',
291
- args: [roleId, index]
292
- });
293
- },
294
- async registryUserRoles({ user, index }) {
295
- return client.readContract({
296
- address,
297
- abi: RegistryABI,
298
- functionName: 'userRoles',
299
- args: [user, index]
300
- });
301
- },
302
- async registryUserRoleCount({ user }) {
303
- return client.readContract({
304
- address,
305
- abi: RegistryABI,
306
- functionName: 'userRoleCount',
307
- args: [user]
308
- });
309
- },
310
- async registryLevelThresholds({ level }) {
311
- return client.readContract({
312
- address,
313
- abi: RegistryABI,
314
- functionName: 'levelThresholds',
315
- args: [level]
316
- });
317
- },
318
- async registryExecutedProposals({ proposalId }) {
319
- return client.readContract({
320
- address,
321
- abi: RegistryABI,
322
- functionName: 'executedProposals',
323
- args: [proposalId]
324
- });
325
- },
326
- // Community lookup functions
327
- async registryCommunityByName({ name }) {
328
- return client.readContract({
329
- address,
330
- abi: RegistryABI,
331
- functionName: 'communityByName',
332
- args: [name]
333
- });
334
- },
335
- async registryCommunityByENS({ ensName }) {
336
- return client.readContract({
337
- address,
338
- abi: RegistryABI,
339
- functionName: 'communityByENS',
340
- args: [ensName]
341
- });
342
- },
343
- async registryCommunityByNameV3({ name }) {
344
- return this.registryCommunityByName({ name });
345
- },
346
- async registryCommunityByENSV3({ ensName }) {
347
- return this.registryCommunityByENS({ ensName });
348
- },
349
- async registryProposedRoleNames({ roleId }) {
350
- return client.readContract({
351
- address,
352
- abi: RegistryABI,
353
- functionName: 'proposedRoleNames',
354
- args: [roleId]
355
- });
356
- },
357
- // Role Metadata & Members
358
- async registryRoleLockDurations({ roleId }) {
359
- return client.readContract({
360
- address,
361
- abi: RegistryABI,
362
- functionName: 'roleLockDurations',
363
- args: [roleId]
364
- });
365
- },
366
- async registryRoleMetadata({ roleId, user }) {
367
- return client.readContract({
368
- address,
369
- abi: RegistryABI,
370
- functionName: 'roleMetadata',
371
- args: user ? [roleId, user] : [roleId]
372
- });
373
- },
374
- async registryRoleStakes({ roleId, user }) {
375
- return client.readContract({
376
- address,
377
- abi: RegistryABI,
378
- functionName: 'roleStakes',
379
- args: [roleId, user]
380
- });
381
- },
382
- async registryRoleSBTTokenIds({ roleId, user }) {
383
- return client.readContract({
384
- address,
385
- abi: RegistryABI,
386
- functionName: 'roleSBTTokenIds',
387
- args: [roleId, user]
388
- });
389
- },
390
- async registryRoleOwners({ roleId }) {
391
- return client.readContract({
392
- address,
393
- abi: RegistryABI,
394
- functionName: 'roleOwners',
395
- args: [roleId]
396
- });
397
- },
398
- async registryRoleMemberIndex({ roleId, user }) {
399
- return client.readContract({
400
- address,
401
- abi: RegistryABI,
402
- functionName: 'roleMemberIndex',
403
- args: [roleId, user]
404
- });
405
- },
406
- async registryGetRoleMembers({ roleId }) {
407
- return client.readContract({
408
- address,
409
- abi: RegistryABI,
410
- functionName: 'getRoleMembers',
411
- args: [roleId]
412
- });
413
- },
414
- async registryGetRoleUserCount({ roleId }) {
415
- return client.readContract({
416
- address,
417
- abi: RegistryABI,
418
- functionName: 'getRoleUserCount',
419
- args: [roleId]
420
- });
421
- },
422
- async registryGetUserRoles({ user }) {
423
- return client.readContract({
424
- address,
425
- abi: RegistryABI,
426
- functionName: 'getUserRoles',
427
- args: [user]
428
- });
429
- },
430
- async registryExitRole({ roleId, account }) {
431
- return client.writeContract({
432
- address,
433
- abi: RegistryABI,
434
- functionName: 'exitRole',
435
- args: [roleId],
436
- account: account,
437
- chain: client.chain
438
- });
439
- },
440
- async registryCalculateExitFee({ roleId, amount }) {
441
- return client.readContract({
442
- address,
443
- abi: RegistryABI,
444
- functionName: 'calculateExitFee',
445
- args: [roleId, amount]
446
- });
447
- },
448
- async registryAddLevelThreshold({ threshold, account }) {
449
- return client.writeContract({
450
- address,
451
- abi: RegistryABI,
452
- functionName: 'addLevelThreshold',
453
- args: [threshold],
454
- account: account,
455
- chain: client.chain
456
- });
457
- },
458
- async registrySetLevelThreshold({ index, threshold, account }) {
459
- return client.writeContract({
460
- address,
461
- abi: RegistryABI,
462
- functionName: 'setLevelThreshold',
463
- args: [index, threshold],
464
- account: account,
465
- chain: client.chain
466
- });
467
- },
468
- async registryAccountToUser({ account: userAccount }) {
469
- return client.readContract({
470
- address,
471
- abi: RegistryABI,
472
- functionName: 'accountToUser',
473
- args: [userAccount]
474
- });
475
- },
476
- // Credit & Tiers
477
- async registryGetCreditLimit({ user }) {
478
- return client.readContract({
479
- address,
480
- abi: RegistryABI,
481
- functionName: 'getCreditLimit',
482
- args: [user]
483
- });
484
- },
485
- async registrySetCreditTier({ level, limit, account }) {
486
- return client.writeContract({
487
- address,
488
- abi: RegistryABI,
489
- functionName: 'setCreditTier',
490
- args: [level, limit],
491
- account: account,
492
- chain: client.chain
493
- });
494
- },
495
- async registryCreditTierConfig({ level }) {
496
- return client.readContract({
497
- address,
498
- abi: RegistryABI,
499
- functionName: 'creditTierConfig',
500
- args: [level]
501
- });
502
- },
503
- // Role Admin
504
- async registryAdminConfigureRole({ roleId, minStake, entryBurn, exitFeePercent, minExitFee, account }) {
505
- return client.writeContract({
506
- address,
507
- abi: RegistryABI,
508
- functionName: 'adminConfigureRole',
509
- args: [roleId, minStake, entryBurn, exitFeePercent, minExitFee],
510
- account: account,
511
- chain: client.chain
512
- });
513
- },
514
- async registryCreateNewRole({ roleId, config, roleOwner, account }) {
515
- return client.writeContract({
516
- address,
517
- abi: RegistryABI,
518
- functionName: 'createNewRole',
519
- args: [roleId, config, roleOwner],
520
- account: account,
521
- chain: client.chain
522
- });
523
- },
524
- async registrySafeMintForRole({ roleId, user, data, account }) {
525
- return client.writeContract({
526
- address,
527
- abi: RegistryABI,
528
- functionName: 'safeMintForRole',
529
- args: [roleId, user, data],
530
- account: account,
531
- chain: client.chain
532
- });
533
- },
534
- async registryGetAccountCommunity({ account: userAccount }) {
535
- // Check if user has COMMUNITY role
536
- const COMMUNITY_ROLE_ID = '0x0000000000000000000000000000000000000000000000000000000000000002';
537
- const hasRole = await client.readContract({
538
- address,
539
- abi: RegistryABI,
540
- functionName: 'hasRole',
541
- args: [userAccount, COMMUNITY_ROLE_ID]
542
- });
543
- if (!hasRole) {
544
- return '0x0000000000000000000000000000000000000000';
545
- }
546
- // Get role data which contains the community token address
547
- const roleData = await client.readContract({
548
- address,
549
- abi: RegistryABI,
550
- functionName: 'getRoleData',
551
- args: [userAccount, COMMUNITY_ROLE_ID]
552
- });
553
- // Parse community token from role data (first 20 bytes after removing 0x)
554
- if (!roleData || roleData === '0x') {
555
- return '0x0000000000000000000000000000000000000000';
556
- }
557
- // Community token is at bytes 0-19 of roleData
558
- const tokenAddress = ('0x' + roleData.slice(2, 42));
559
- return tokenAddress;
501
+ async roleConfigs({ roleId }) {
502
+ try {
503
+ validateRequired(roleId, 'roleId');
504
+ const result = await client.readContract({
505
+ address,
506
+ abi: RegistryABI,
507
+ functionName: 'roleConfigs',
508
+ args: [roleId]
509
+ });
510
+ if (Array.isArray(result)) {
511
+ return {
512
+ minStake: result[0],
513
+ entryBurn: result[1],
514
+ slashThreshold: result[2],
515
+ slashBase: result[3],
516
+ slashInc: result[4],
517
+ slashMax: result[5],
518
+ exitFeePercent: result[6],
519
+ isActive: result[7],
520
+ minExitFee: result[8],
521
+ description: result[9],
522
+ owner: result[10],
523
+ roleLockDuration: result[11]
524
+ };
525
+ }
526
+ return result;
527
+ }
528
+ catch (error) {
529
+ throw AAStarError.fromViemError(error, 'roleConfigs');
530
+ }
531
+ },
532
+ async getRoleUserCount({ roleId }) {
533
+ try {
534
+ validateRequired(roleId, 'roleId');
535
+ return await client.readContract({
536
+ address,
537
+ abi: RegistryABI,
538
+ functionName: 'getRoleUserCount',
539
+ args: [roleId]
540
+ });
541
+ }
542
+ catch (error) {
543
+ throw AAStarError.fromViemError(error, 'getRoleUserCount');
544
+ }
545
+ },
546
+ async getRoleMembers({ roleId }) {
547
+ try {
548
+ validateRequired(roleId, 'roleId');
549
+ return await client.readContract({
550
+ address,
551
+ abi: RegistryABI,
552
+ functionName: 'getRoleMembers',
553
+ args: [roleId]
554
+ });
555
+ }
556
+ catch (error) {
557
+ throw AAStarError.fromViemError(error, 'getRoleMembers');
558
+ }
559
+ },
560
+ async getUserRoles({ user }) {
561
+ try {
562
+ validateAddress(user, 'user');
563
+ return await client.readContract({
564
+ address,
565
+ abi: RegistryABI,
566
+ functionName: 'getUserRoles',
567
+ args: [user]
568
+ });
569
+ }
570
+ catch (error) {
571
+ throw AAStarError.fromViemError(error, 'getUserRoles');
572
+ }
573
+ },
574
+ async roleMembers({ roleId, index }) {
575
+ try {
576
+ validateRequired(roleId, 'roleId');
577
+ validateRequired(index, 'index');
578
+ return await client.readContract({
579
+ address,
580
+ abi: RegistryABI,
581
+ functionName: 'roleMembers',
582
+ args: [roleId, index]
583
+ });
584
+ }
585
+ catch (error) {
586
+ throw AAStarError.fromViemError(error, 'roleMembers');
587
+ }
588
+ },
589
+ async userRoles({ user, index }) {
590
+ try {
591
+ validateAddress(user, 'user');
592
+ validateRequired(index, 'index');
593
+ return await client.readContract({
594
+ address,
595
+ abi: RegistryABI,
596
+ functionName: 'userRoles',
597
+ args: [user, index]
598
+ });
599
+ }
600
+ catch (error) {
601
+ throw AAStarError.fromViemError(error, 'userRoles');
602
+ }
603
+ },
604
+ async userRoleCount({ user }) {
605
+ try {
606
+ validateAddress(user, 'user');
607
+ return await client.readContract({
608
+ address,
609
+ abi: RegistryABI,
610
+ functionName: 'userRoleCount',
611
+ args: [user]
612
+ });
613
+ }
614
+ catch (error) {
615
+ throw AAStarError.fromViemError(error, 'userRoleCount');
616
+ }
617
+ },
618
+ async creditTierConfig({ tierIndex }) {
619
+ try {
620
+ validateAmount(tierIndex, 'tierIndex');
621
+ return await client.readContract({
622
+ address,
623
+ abi: RegistryABI,
624
+ functionName: 'creditTierConfig',
625
+ args: [tierIndex]
626
+ });
627
+ }
628
+ catch (error) {
629
+ throw AAStarError.fromViemError(error, 'creditTierConfig');
630
+ }
631
+ },
632
+ async levelThresholds({ levelIndex }) {
633
+ try {
634
+ validateAmount(levelIndex, 'levelIndex');
635
+ return await client.readContract({
636
+ address,
637
+ abi: RegistryABI,
638
+ functionName: 'levelThresholds',
639
+ args: [levelIndex]
640
+ });
641
+ }
642
+ catch (error) {
643
+ throw AAStarError.fromViemError(error, 'levelThresholds');
644
+ }
645
+ },
646
+ async calculateExitFee({ roleId, amount }) {
647
+ try {
648
+ validateRequired(roleId, 'roleId');
649
+ validateAmount(amount, 'amount');
650
+ return await client.readContract({
651
+ address,
652
+ abi: RegistryABI,
653
+ functionName: 'calculateExitFee',
654
+ args: [roleId, amount]
655
+ });
656
+ }
657
+ catch (error) {
658
+ throw AAStarError.fromViemError(error, 'calculateExitFee');
659
+ }
660
+ },
661
+ async accountToUser({ account }) {
662
+ try {
663
+ validateAddress(account, 'account');
664
+ return await client.readContract({
665
+ address,
666
+ abi: RegistryABI,
667
+ functionName: 'accountToUser',
668
+ args: [account]
669
+ });
670
+ }
671
+ catch (error) {
672
+ throw AAStarError.fromViemError(error, 'accountToUser');
673
+ }
674
+ },
675
+ async roleOwners({ roleId }) {
676
+ try {
677
+ validateRequired(roleId, 'roleId');
678
+ return await client.readContract({
679
+ address,
680
+ abi: RegistryABI,
681
+ functionName: 'roleOwners',
682
+ args: [roleId]
683
+ });
684
+ }
685
+ catch (error) {
686
+ throw AAStarError.fromViemError(error, 'roleOwners');
687
+ }
688
+ },
689
+ async roleStakes({ roleId, user }) {
690
+ try {
691
+ validateRequired(roleId, 'roleId');
692
+ validateAddress(user, 'user');
693
+ return await client.readContract({
694
+ address,
695
+ abi: RegistryABI,
696
+ functionName: 'roleStakes',
697
+ args: [roleId, user]
698
+ });
699
+ }
700
+ catch (error) {
701
+ throw AAStarError.fromViemError(error, 'roleStakes');
702
+ }
703
+ },
704
+ async roleLockDurations({ roleId }) {
705
+ try {
706
+ validateRequired(roleId, 'roleId');
707
+ return await client.readContract({
708
+ address,
709
+ abi: RegistryABI,
710
+ functionName: 'roleLockDurations',
711
+ args: [roleId]
712
+ });
713
+ }
714
+ catch (error) {
715
+ throw AAStarError.fromViemError(error, 'roleLockDurations');
716
+ }
560
717
  },
561
718
  // Constants (Role IDs)
562
- async registryROLE_COMMUNITY() {
563
- return client.readContract({
564
- address,
565
- abi: RegistryABI,
566
- functionName: 'ROLE_COMMUNITY',
567
- args: []
568
- });
569
- },
570
- async registryROLE_ENDUSER() {
571
- return client.readContract({
572
- address,
573
- abi: RegistryABI,
574
- functionName: 'ROLE_ENDUSER',
575
- args: []
576
- });
577
- },
578
- async registryROLE_PAYMASTER_SUPER() {
579
- return client.readContract({
580
- address,
581
- abi: RegistryABI,
582
- functionName: 'ROLE_PAYMASTER_SUPER',
583
- args: []
584
- });
585
- },
586
- async registryROLE_PAYMASTER_AOA() {
587
- return client.readContract({
588
- address,
589
- abi: RegistryABI,
590
- functionName: 'ROLE_PAYMASTER_AOA',
591
- args: []
592
- });
593
- },
594
- async registryROLE_DVT() {
595
- return client.readContract({
596
- address,
597
- abi: RegistryABI,
598
- functionName: 'ROLE_DVT',
599
- args: []
600
- });
601
- },
602
- async registryROLE_KMS() {
603
- return client.readContract({
604
- address,
605
- abi: RegistryABI,
606
- functionName: 'ROLE_KMS',
607
- args: []
608
- });
609
- },
610
- async registryROLE_ANODE() {
611
- return client.readContract({
612
- address,
613
- abi: RegistryABI,
614
- functionName: 'ROLE_ANODE',
615
- args: []
616
- });
617
- },
618
- async registryGTOKEN_STAKING() {
619
- return client.readContract({
620
- address,
621
- abi: RegistryABI,
622
- functionName: 'GTOKEN_STAKING',
623
- args: []
624
- });
625
- },
626
- async registryMYSBT() {
627
- return client.readContract({
628
- address,
629
- abi: RegistryABI,
630
- functionName: 'MYSBT',
631
- args: []
632
- });
633
- },
634
- async registrySUPER_PAYMASTER() {
635
- return client.readContract({
636
- address,
637
- abi: RegistryABI,
638
- functionName: 'SUPER_PAYMASTER',
639
- args: []
640
- });
641
- },
642
- async registryIsReputationSource({ source }) {
643
- return client.readContract({
644
- address,
645
- abi: RegistryABI,
646
- functionName: 'isReputationSource',
647
- args: [source]
648
- });
649
- },
650
- async registryLastReputationEpoch() {
651
- return client.readContract({
652
- address,
653
- abi: RegistryABI,
654
- functionName: 'lastReputationEpoch',
655
- args: []
656
- });
657
- },
658
- // Version
659
- async registryVersion() {
660
- return client.readContract({
661
- address,
662
- abi: RegistryABI,
663
- functionName: 'version',
664
- args: []
665
- });
719
+ async ROLE_COMMUNITY() {
720
+ try {
721
+ return await client.readContract({
722
+ address,
723
+ abi: RegistryABI,
724
+ functionName: 'ROLE_COMMUNITY',
725
+ args: []
726
+ });
727
+ }
728
+ catch (error) {
729
+ throw AAStarError.fromViemError(error, 'ROLE_COMMUNITY');
730
+ }
731
+ },
732
+ async ROLE_ENDUSER() {
733
+ try {
734
+ return await client.readContract({
735
+ address,
736
+ abi: RegistryABI,
737
+ functionName: 'ROLE_ENDUSER',
738
+ args: []
739
+ });
740
+ }
741
+ catch (error) {
742
+ throw AAStarError.fromViemError(error, 'ROLE_ENDUSER');
743
+ }
744
+ },
745
+ async ROLE_PAYMASTER_SUPER() {
746
+ try {
747
+ return await client.readContract({
748
+ address,
749
+ abi: RegistryABI,
750
+ functionName: 'ROLE_PAYMASTER_SUPER',
751
+ args: []
752
+ });
753
+ }
754
+ catch (error) {
755
+ throw AAStarError.fromViemError(error, 'ROLE_PAYMASTER_SUPER');
756
+ }
757
+ },
758
+ async ROLE_PAYMASTER_AOA() {
759
+ try {
760
+ return await client.readContract({
761
+ address,
762
+ abi: RegistryABI,
763
+ functionName: 'ROLE_PAYMASTER_AOA',
764
+ args: []
765
+ });
766
+ }
767
+ catch (error) {
768
+ throw AAStarError.fromViemError(error, 'ROLE_PAYMASTER_AOA');
769
+ }
770
+ },
771
+ async ROLE_DVT() {
772
+ try {
773
+ return await client.readContract({
774
+ address,
775
+ abi: RegistryABI,
776
+ functionName: 'ROLE_DVT',
777
+ args: []
778
+ });
779
+ }
780
+ catch (error) {
781
+ throw AAStarError.fromViemError(error, 'ROLE_DVT');
782
+ }
783
+ },
784
+ async ROLE_KMS() {
785
+ try {
786
+ return await client.readContract({
787
+ address,
788
+ abi: RegistryABI,
789
+ functionName: 'ROLE_KMS',
790
+ args: []
791
+ });
792
+ }
793
+ catch (error) {
794
+ throw AAStarError.fromViemError(error, 'ROLE_KMS');
795
+ }
796
+ },
797
+ async ROLE_ANODE() {
798
+ try {
799
+ return await client.readContract({
800
+ address,
801
+ abi: RegistryABI,
802
+ functionName: 'ROLE_ANODE',
803
+ args: []
804
+ });
805
+ }
806
+ catch (error) {
807
+ throw AAStarError.fromViemError(error, 'ROLE_ANODE');
808
+ }
809
+ },
810
+ // Ownership
811
+ async owner() {
812
+ try {
813
+ return await client.readContract({
814
+ address,
815
+ abi: RegistryABI,
816
+ functionName: 'owner',
817
+ args: []
818
+ });
819
+ }
820
+ catch (error) {
821
+ throw AAStarError.fromViemError(error, 'owner');
822
+ }
823
+ },
824
+ async transferOwnership({ newOwner, account }) {
825
+ try {
826
+ validateAddress(newOwner, 'newOwner');
827
+ return await client.writeContract({
828
+ address,
829
+ abi: RegistryABI,
830
+ functionName: 'transferOwnership',
831
+ args: [newOwner],
832
+ account: account,
833
+ chain: client.chain
834
+ });
835
+ }
836
+ catch (error) {
837
+ throw AAStarError.fromViemError(error, 'transferOwnership');
838
+ }
839
+ },
840
+ async renounceOwnership({ account }) {
841
+ try {
842
+ return await client.writeContract({
843
+ address,
844
+ abi: RegistryABI,
845
+ functionName: 'renounceOwnership',
846
+ args: [],
847
+ account: account,
848
+ chain: client.chain
849
+ });
850
+ }
851
+ catch (error) {
852
+ throw AAStarError.fromViemError(error, 'renounceOwnership');
853
+ }
854
+ },
855
+ async version() {
856
+ try {
857
+ return await client.readContract({
858
+ address,
859
+ abi: RegistryABI,
860
+ functionName: 'version',
861
+ args: []
862
+ });
863
+ }
864
+ catch (error) {
865
+ throw AAStarError.fromViemError(error, 'version');
866
+ }
666
867
  }
667
868
  });