generated from Badger-Finance/badger-strategy-mix-v1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
1_production_deploy.py
209 lines (157 loc) · 5.4 KB
/
1_production_deploy.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
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
import time
from brownie import (
accounts,
network,
BrikedStrategy,
RemBadger,
AdminUpgradeabilityProxy,
Controller,
BadgerRegistry,
)
from config import WANT, PROTECTED_TOKENS, FEES, REGISTRY
from helpers.constants import AddressZero
import click
from rich.console import Console
console = Console()
sleep_between_tx = 1
def main():
"""
FOR STRATEGISTS AND GOVERNANCE
Deploys a Controller, a RemBadger and your strategy under upgradable proxies and wires them up.
Note that it sets your deployer account as the governance for the three contracts so that
the setup and production tests are simpler and more efficient. The rest of the permissioned actors
are set based on the latest entries from the Badger Registry.
"""
# Get deployer account from local keystore
dev = connect_account()
# Get actors from registry
registry = BadgerRegistry.at(REGISTRY)
strategist = registry.get("governance")
guardian = registry.get("guardian")
keeper = registry.get("keeper")
proxyAdmin = registry.get("proxyAdminTimelock")
assert strategist != AddressZero
assert guardian != AddressZero
assert keeper != AddressZero
assert proxyAdmin != AddressZero
# Deploy controller
controller = deploy_controller(dev, proxyAdmin)
# Deploy Vault
vault = deploy_vault(
controller.address,
dev.address, # Deployer will be set as governance for testing stage
keeper,
guardian,
dev,
proxyAdmin,
)
# Deploy Strategy
strategy = deploy_strategy(
controller.address,
dev.address, # Deployer will be set as governance for testing stage
strategist,
keeper,
guardian,
dev,
proxyAdmin,
)
# Wire up vault and strategy to test controller
wire_up_test_controller(controller, vault, strategy, dev)
def deploy_controller(dev, proxyAdmin):
controller_logic = Controller.at(
"0x01d10fdc6b484BE380144dF12EB6C75387EfC49B"
) # Controller Logic
# Deployer address will be used for all actors as controller will only be used for testing
args = [
dev.address,
dev.address,
dev.address,
dev.address,
]
controller_proxy = AdminUpgradeabilityProxy.deploy(
controller_logic,
proxyAdmin,
controller_logic.initialize.encode_input(*args),
{"from": dev},
)
time.sleep(sleep_between_tx)
## We delete from deploy and then fetch again so we can interact
AdminUpgradeabilityProxy.remove(controller_proxy)
controller_proxy = Controller.at(controller_proxy.address)
console.print(
"[green]Controller was deployed at: [/green]", controller_proxy.address
)
return controller_proxy
def deploy_vault(controller, governance, keeper, guardian, dev, proxyAdmin):
args = [
WANT,
controller,
governance,
keeper,
guardian,
False,
"",
"",
]
print("Vault Arguments: ", args)
vault_logic = RemBadger.at(
"0xAF0B504BD20626d1fd57F8903898168FCE7ecbc8"
) # RemBadger Logic
vault_proxy = AdminUpgradeabilityProxy.deploy(
vault_logic,
proxyAdmin,
vault_logic.initialize.encode_input(*args),
{"from": dev},
)
time.sleep(sleep_between_tx)
## We delete from deploy and then fetch again so we can interact
AdminUpgradeabilityProxy.remove(vault_proxy)
vault_proxy = RemBadger.at(vault_proxy.address)
console.print("[green]Vault was deployed at: [/green]", vault_proxy.address)
assert vault_proxy.paused()
vault_proxy.unpause({"from": dev})
assert vault_proxy.paused() == False
return vault_proxy
def deploy_strategy(
controller, governance, strategist, keeper, guardian, dev, proxyAdmin
):
args = [
governance,
strategist,
controller,
keeper,
guardian,
PROTECTED_TOKENS,
FEES,
]
print("Strategy Arguments: ", args)
strat_logic = BrikedStrategy.deploy({"from": dev})
time.sleep(sleep_between_tx)
strat_proxy = AdminUpgradeabilityProxy.deploy(
strat_logic,
proxyAdmin,
strat_logic.initialize.encode_input(*args),
{"from": dev},
)
time.sleep(sleep_between_tx)
## We delete from deploy and then fetch again so we can interact
AdminUpgradeabilityProxy.remove(strat_proxy)
strat_proxy = BrikedStrategy.at(strat_proxy.address)
console.print("[green]Strategy was deployed at: [/green]", strat_proxy.address)
return strat_proxy
def wire_up_test_controller(controller, vault, strategy, dev):
controller.approveStrategy(WANT, strategy.address, {"from": dev})
time.sleep(sleep_between_tx)
assert controller.approvedStrategies(WANT, strategy.address) == True
controller.setStrategy(WANT, strategy.address, {"from": dev})
time.sleep(sleep_between_tx)
assert controller.strategies(WANT) == strategy.address
controller.setVault(WANT, vault.address, {"from": dev})
time.sleep(sleep_between_tx)
assert controller.vaults(WANT) == vault.address
console.print("[blue]Controller wired up![/blue]")
def connect_account():
click.echo(f"You are using the '{network.show_active()}' network")
dev = accounts.load(click.prompt("Account", type=click.Choice(accounts.load())))
click.echo(f"You are using: 'dev' [{dev.address}]")
return dev