-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_current_permissions.py
67 lines (55 loc) · 2.17 KB
/
gen_current_permissions.py
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
import requests
import json
import os
from bal_addresses import AddrBook, GITHUB_DEPLOYMENTS_RAW, NoResultError
from web3 import Web3
from bal_tools import Web3Rpc
DRPC_KEY = os.getenv("DRPC_KEY")
def build_chain_permissions_list(chain_name):
a = AddrBook(chain_name)
results = {}
action_ids_list = (
f"{GITHUB_DEPLOYMENTS_RAW}/action-ids/{chain_name}/action-ids.json"
)
w3 = Web3Rpc(chain_name, DRPC_KEY)
try:
authorizer_address = a.search_unique("20210418-authorizer/Authorizer").address
except NoResultError as e:
print(f"WARNING: Authorizer not found: {e}")
return results
authorizer = w3.eth.contract(
address=authorizer_address,
abi=json.load(open("bal_addresses/abis/Authorizer.json")),
)
try:
result = requests.get(action_ids_list)
except requests.exceptions.HTTPError as err:
print(f"URL: {requests.request.url} returned error {err}")
input = result.json()
for deployment, contracts in input.items():
print(f"Processing {deployment}")
for data in contracts.values():
for action_id in data["actionIds"].values():
if action_id in results:
continue # already have data
numMembers = authorizer.functions.getRoleMemberCount(action_id).call()
if numMembers > 0:
memberAddressList = []
for i in range(0, numMembers, 1):
caller = str(
authorizer.functions.getRoleMember(action_id, i).call()
)
memberAddressList.append(caller)
results[action_id] = memberAddressList
return results
def generate_chain_files(chain):
permissions = build_chain_permissions_list(chain)
with open(f"outputs/permissions/active/{chain}.json", "w") as f:
json.dump(permissions, f, indent=2)
f.write("\n")
def main():
for chain in AddrBook.chains.BALANCER_PRODUCTION_CHAINS:
print(f"\n\n\nGenerating Permissions Data for {chain.capitalize()}\n\n\n")
generate_chain_files(chain)
if __name__ == "__main__":
main()