generated from Badger-Finance/badger-strategy-mix-v1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
5_production_proxy_check.py
165 lines (132 loc) · 5.59 KB
/
5_production_proxy_check.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
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
from brownie import network, BadgerRegistry, Controller, RemBadger, web3
from config import REGISTRY
from helpers.constants import AddressZero
from rich.console import Console
console = Console()
ADMIN_SLOT = int(0xB53127684A568B3173AE13B9F8A6016E243E63B6E8EE1178D6A717850B5D6103)
def main():
"""
Checks that the proxyAdmin of all conracts added to the BadgerRegistry match
the proxyAdminTimelock address on the same registry. How to run:
1. Add all keys for the network's registry to the 'keys' array below.
2. Add all authors' addresses with vaults added to the registry into the 'authors' array below.
3. Add all all keys for the proxyAdmins for the network's registry paired to their owners' keys.
4. Run the script and review the console output.
"""
console.print("You are using the", network.show_active(), "network")
# Get production registry
registry = BadgerRegistry.at(REGISTRY)
# Get proxyAdminTimelock
proxyAdmin = registry.get("proxyAdminTimelock")
assert proxyAdmin != AddressZero
console.print("[cyan]proxyAdminTimelock:[/cyan]", proxyAdmin)
# NOTE: Add all existing keys from your network's registry. For example:
keys = [
"governance",
"guardian",
"keeper",
"controller",
"badgerTree",
"devGovernance",
"paymentsGovernance",
"governanceTimelock",
"proxyAdminDev",
"rewardsLogger",
"keeperAccessControl",
"proxyAdminDfdBadger",
"dfdBadgerSharedGovernance",
]
# NOTE: Add all authors from your network's registry. For example:
authors = ["0x1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a"]
# NOTE: Add the keys to all proxyAdmins from your network's registry paired to their owner
proxyAdminOwners = [
["proxyAdminTimelock", "governanceTimelock"],
["proxyAdminDev", "devGovernance"],
["proxyAdminDfdBadger", "dfdBadgerSharedGovernance"],
]
check_by_keys(registry, proxyAdmin, keys)
check_vaults_and_strategies(registry, proxyAdmin, authors)
check_proxy_admin_owners(proxyAdminOwners, registry)
def check_by_keys(registry, proxyAdmin, keys):
console.print("[blue]Checking proxyAdmins by key...[/blue]")
# Check the proxyAdmin of the different proxy contracts
for key in keys:
proxy = registry.get(key)
if proxy == AddressZero:
console.print(key, ":[red] key doesn't exist on the registry![/red]")
continue
check_proxy_admin(proxy, proxyAdmin, key)
def check_vaults_and_strategies(registry, proxyAdmin, authors):
console.print("[blue]Checking proxyAdmins from vaults and strategies...[/blue]")
vaultStatus = [0, 1, 2]
vaults = []
strategies = []
stratNames = []
# get vaults by author
for author in authors:
vaults += registry.getVaults("v1", author)
vaults += registry.getVaults("v2", author)
# Get promoted vaults
for status in vaultStatus:
vaults += registry.getFilteredProductionVaults("v1", status)
vaults += registry.getFilteredProductionVaults("v2", status)
# Get strategies from vaults and check vaults' proxyAdmins
for vault in vaults:
try:
vaultContract = RemBadger.at(vault)
# get Controller
controller = Controller.at(vaultContract.controller())
strategies.append(controller.strategies(vaultContract.token()))
stratNames.append(vaultContract.name().replace("Badger Sett ", "Strategy "))
# Check vault proxyAdmin
check_proxy_admin(vault, proxyAdmin, vaultContract.name())
except Exception as error:
print("Something went wrong")
print(error)
for strat in strategies:
try:
# Check strategies' proxyAdmin
check_proxy_admin(strat, proxyAdmin, stratNames[strategies.index(strat)])
except Exception as error:
print("Something went wrong")
print(error)
def check_proxy_admin(proxy, proxyAdmin, key):
# Get proxyAdmin address form the proxy's ADMIN_SLOT
val = web3.eth.getStorageAt(proxy, ADMIN_SLOT).hex()
address = "0x" + val[26:66]
# Check differnt possible scenarios
if address == AddressZero:
console.print(key, ":[red] admin not found on slot (GnosisSafeProxy?)[/red]")
elif address != proxyAdmin:
console.print(
key, ":[red] admin is different to proxyAdminTimelock[/red] - ", address
)
else:
assert address == proxyAdmin
console.print(key, ":[green] admin matches proxyAdminTimelock![/green]")
def check_proxy_admin_owners(proxyAdminOwners, registry):
console.print("[blue]Checking proxyAdmins' owners...[/blue]")
for adminOwnerPair in proxyAdminOwners:
proxyAdmin = registry.get(adminOwnerPair[0])
owner = registry.get(adminOwnerPair[1])
# Get proxyAdmin's owner address from slot 0
val = web3.eth.getStorageAt(proxyAdmin, 0).hex()
address = "0x" + val[26:66]
# Check differnt possible scenarios
if address == AddressZero:
console.print(adminOwnerPair[0], ":[red] no address found at slot 0![/red]")
elif address != owner:
console.print(
adminOwnerPair[0],
":[red] owner is different to[/red]",
adminOwnerPair[1],
"-",
address,
)
else:
assert address == owner
console.print(
adminOwnerPair[0],
":[green] owner matches[/green]",
adminOwnerPair[1],
)