-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathACL.ts
378 lines (343 loc) · 9.81 KB
/
ACL.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// Import event types from the registrar contract ABI
import {SetPermission, SetPermissionParams, ChangePermissionManager} from '../types/ACL/ACL'
// Import entity types from the schema
import {
FinancePermission,
TokenManagerPermission,
VotingPermission,
EVMScriptRegistryPermission,
ACLPermission,
KernelPermission,
VaultPermission,
TokenManagerManagers,
FinanceManagers,
VotingManagers,
EVMScriptRegistryManagers,
VaultManagers,
ACLManagers,
KernelManagers,
Vault,
TokenManager,
Finance,
Voting,
EVMScriptRegistry,
ACL,
Kernel
} from '../types/schema'
import {
FINANCE_CHANGE_BUDGETS_ROLE_HASH,
FINANCE_CHANGE_PERIOD_ROLE_HASH,
FINANCE_CREATE_PAYMENTS_ROLE_HASH,
FINANCE_MANAGE_PAYMENTS_ROLE_HASH,
FINANCE_EXECUTE_PAYMENTS_ROLE_HASH,
TOKEN_MANAGER_ASSIGN_ROLE_HASH,
TOKEN_MANAGER_BURN_ROLE_HASH,
TOKEN_MANAGER_ISSUE_ROLE_HASH,
TOKEN_MANAGER_MINT_ROLE_HASH,
TOKEN_MANAGER_REVOKE_VESTINGS_ROLE_HASH,
VOTING_CREATE_VOTES_ROLE_HASH,
VOTING_MODIFY_QUORUM_ROLE_HASH,
VOTING_MODIFY_SUPPORT_ROLE_HASH,
EVM_SCRIPT_REGISTRY_ADD_EXECUTOR_ROLE_HASH,
EVM_SCRIPT_REGISTRY_MANAGER_ROLE_HASH, // alias for enable and disable executors
roleLookupTable
} from './constants'
export function handleSetPermission(event: SetPermission): void {
let id = event.params.app.toHex()
let role = event.params.role.toHex()
let entity = event.params.entity.toHex()
// Vault
if (Vault.load(id) != null) {
let vp = VaultPermission.load(role)
if (vp == null) {
vp = new VaultPermission(role)
vp.entities = new Array<string>()
vp.appAddress = id
}
if (event.params.allowed == true) {
let roleName = roleLookupTable.get(role) as string
vp.role = roleName
let entities = vp.entities
let i = entities.indexOf(entity)
if (i == -1) {
entities.push(entity)
vp.entities = entities
vp.save()
}
} else if (event.params.allowed == false) {
let entities = vp.entities
let i = entities.indexOf(entity)
entities.splice(i, 1)
vp.entities = entities
vp.save()
}
}
// Token Manager
else if (TokenManager.load(id) != null) {
let tmp = TokenManagerPermission.load(role)
if (tmp == null) {
tmp = new TokenManagerPermission(role)
tmp.entities = new Array<string>()
tmp.appAddress = id
}
if (event.params.allowed == true) {
let roleName = roleLookupTable.get(role) as string
tmp.role = roleName
let entities = tmp.entities
let i = entities.indexOf(entity)
if (i == -1) {
entities.push(entity)
tmp.entities = entities
tmp.save()
}
} else if (event.params.allowed == false) {
let entities = tmp.entities
let i = entities.indexOf(entity)
entities.splice(i, 1)
tmp.entities = entities
tmp.save()
}
}
// Finance
else if (Finance.load(id) != null) {
let fp = FinancePermission.load(role)
if (fp == null) {
fp = new FinancePermission(role)
fp.entities = new Array<string>()
fp.appAddress = id
}
if (event.params.allowed == true) {
let roleName = roleLookupTable.get(role) as string
fp.role = roleName
let entities = fp.entities
let i = entities.indexOf(entity)
if (i == -1) {
entities.push(entity)
fp.entities = entities
fp.save()
}
} else if (event.params.allowed == false) {
let entities = fp.entities
let i = entities.indexOf(entity)
entities.splice(i, 1)
fp.entities = entities
fp.save()
}
}
// Voting
else if (Voting.load(id) != null) {
let vp = VotingPermission.load(role)
if (vp == null) {
vp = new VotingPermission(role)
vp.entities = new Array<string>()
vp.appAddress = id
}
if (event.params.allowed == true) {
let roleName = roleLookupTable.get(role) as string
vp.role = roleName
let entities = vp.entities
let i = entities.indexOf(entity)
if (i == -1) {
entities.push(entity)
vp.entities = entities
vp.save()
}
} else if (event.params.allowed == false) {
let entities = vp.entities
let i = entities.indexOf(entity)
entities.splice(i, 1)
vp.entities = entities
vp.save()
}
}
// EVMScriptRegistry
else if (EVMScriptRegistry.load(id) != null) {
let evmsr = EVMScriptRegistryPermission.load(role)
if (evmsr == null) {
evmsr = new EVMScriptRegistryPermission(role)
evmsr.entities = new Array<string>()
evmsr.appAddress = id
}
if (event.params.allowed == true) {
let roleName = roleLookupTable.get(role) as string
evmsr.role = roleName
let entities = evmsr.entities
let i = entities.indexOf(entity)
if (i == -1) {
entities.push(entity)
evmsr.entities = entities
evmsr.save()
}
} else if (event.params.allowed == false) {
let entities = evmsr.entities
let i = entities.indexOf(entity)
entities.splice(i, 1)
evmsr.entities = entities
evmsr.save()
}
}
// ACL
else if (ACL.load(id) != null) {
let aclp = ACLPermission.load(role)
if (aclp == null) {
aclp = new ACLPermission(role)
aclp.entities = new Array<string>()
aclp.appAddress = id
}
if (event.params.allowed == true) {
let roleName = roleLookupTable.get(role) as string
aclp.role = roleName
let entities = aclp.entities
let i = entities.indexOf(entity)
if (i == -1) {
entities.push(entity)
aclp.entities = entities
aclp.save()
}
} else if (event.params.allowed == false) {
let entities = aclp.entities
let i = entities.indexOf(entity)
entities.splice(i, 1)
aclp.entities = entities
aclp.save()
}
}
// Kernel
else if (Kernel.load(id) != null) {
let kp = KernelPermission.load(role)
if (kp == null) {
kp = new KernelPermission(role)
kp.entities = new Array<string>()
kp.appAddress = id
}
if (event.params.allowed == true) {
let roleName = roleLookupTable.get(role) as string
kp.role = roleName
let entities = kp.entities
let i = entities.indexOf(entity)
if (i == -1) {
entities.push(entity)
kp.entities = entities
kp.save()
}
} else if (event.params.allowed == false) {
let entities = kp.entities
let i = entities.indexOf(entity)
entities.splice(i, 1)
kp.entities = entities
kp.save()
}
}
}
export function handleChangePermissionManager(event: ChangePermissionManager): void {
let id = event.params.app.toHex()
let role = event.params.role.toHex()
let manager = event.params.manager
// VAULT
if (Vault.load(id) != null) {
let vm = VaultManagers.load(id)
if (vm == null) {
vm = new VaultManagers(id)
}
vm.managesTransfers = manager
vm.save()
}
// TOKEN MANAGER
else if (TokenManager.load(id) != null) {
let tmm = TokenManagerManagers.load(id)
if (tmm == null) {
tmm = new TokenManagerManagers(id)
}
if (role == TOKEN_MANAGER_REVOKE_VESTINGS_ROLE_HASH) {
tmm.managesRevokeVestings = manager
tmm.save()
} else if (role == TOKEN_MANAGER_MINT_ROLE_HASH) {
tmm.managesMint = manager
tmm.save()
} else if (role == TOKEN_MANAGER_ISSUE_ROLE_HASH) {
tmm.managesIssue = manager
tmm.save()
} else if (role == TOKEN_MANAGER_BURN_ROLE_HASH) {
tmm.managesBurn = manager
tmm.save()
} else if (role == TOKEN_MANAGER_ASSIGN_ROLE_HASH) {
tmm.managesAssign = manager
tmm.save()
}
}
// FINANCE
else if (Finance.load(id) != null) {
let fm = FinanceManagers.load(id)
if (fm == null) {
fm = new FinanceManagers(id)
}
if (role == FINANCE_EXECUTE_PAYMENTS_ROLE_HASH) {
fm.managesExecutePayments = manager
fm.save()
} else if (role == FINANCE_MANAGE_PAYMENTS_ROLE_HASH) {
fm.managesManagePayments = manager
fm.save()
} else if (role == FINANCE_CREATE_PAYMENTS_ROLE_HASH) {
fm.managesCreatePayments = manager
fm.save()
} else if (role == FINANCE_CHANGE_BUDGETS_ROLE_HASH) {
fm.managesChangeBudget = manager
fm.save()
} else if (role == FINANCE_CHANGE_PERIOD_ROLE_HASH) {
fm.managesChangePeriod = manager
fm.save()
}
}
// VOTING
else if (Voting.load(id) != null) {
let vm = VotingManagers.load(id)
if (vm == null) {
vm = new VotingManagers(id)
}
if (role == VOTING_MODIFY_SUPPORT_ROLE_HASH) {
vm.managesModifySupport = manager
vm.save()
} else if (role == VOTING_MODIFY_QUORUM_ROLE_HASH) {
vm.managesModifyQuorum = manager
vm.save()
} else if (role == VOTING_CREATE_VOTES_ROLE_HASH) {
vm.managesCreateVotes = manager
vm.save()
}
}
// EVMScriptRegistry
else if (EVMScriptRegistry.load(id) != null) {
let evmsr = EVMScriptRegistryManagers.load(id)
if (evmsr == null) {
evmsr = new EVMScriptRegistryManagers(id)
}
if (role == EVM_SCRIPT_REGISTRY_ADD_EXECUTOR_ROLE_HASH) {
evmsr.managesAddExecutor = manager
evmsr.save()
} else if (role == EVM_SCRIPT_REGISTRY_MANAGER_ROLE_HASH) {
evmsr.managesEnableAndDisableExecutors = manager
evmsr.save()
}
}
// ACL
else if (ACL.load(id) != null) {
let am = ACLManagers.load(id)
if (am == null) {
am = new ACLManagers(id)
}
am.managesCreatePermissions = manager
am.save()
}
//Kernel
else if (Kernel.load(id) != null) {
let km = KernelManagers.load(id)
if (km == null) {
km = new KernelManagers(id)
}
km.managesManageApps = manager
km.save()
}
}
// hasnt been called on my app, doesnt appear to be used anywhere in the DApp, leaving out
export function handleSetPermissionParams(event: SetPermissionParams): void {
}