-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdeploy_metaregistryl2.py
318 lines (266 loc) · 10.4 KB
/
deploy_metaregistryl2.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
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
# flake8: noqa
import os
import sys
import boa
import yaml
from boa.network import NetworkEnv
from eth.constants import ZERO_ADDRESS
from eth_account import Account
from rich import console as rich_console
sys.path.append("./")
from scripts.deploy_addressprovider_and_setup import fetch_url
from scripts.legacy_base_pools import base_pools as BASE_POOLS
from scripts.utils.constants import FIDDY_DEPLOYER
console = rich_console.Console()
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
ADDRESS_PROVIDER = (
"0x5ffe7FB82894076ECB99A30D6A32e969e6e35E98" # gets replaced for zksync
)
# if -1: no gauge type known just yet
GAUGE_TYPE = {
"arbitrum": 7,
"optimism": 11,
"polygon": 2,
"base": 0,
"fraxtal": 11,
"bsc": 12,
"gnosis": 4,
"fantom": 1,
"avalanche": 8,
"aurora": -1,
"celo": -1,
"kava": 9,
"mantle": -1,
"linea": -1,
"scroll": -1,
"polygon-zkevm": -1,
"xlayer": -1,
"zksync": -1,
}
def check_contract_deployed(network, designation):
with open("./deployments.yaml", "r") as file:
deployments = yaml.safe_load(file)
if deployments is None:
deployments = {}
if (
network in deployments.keys()
and designation in deployments[network].keys()
):
contract_address = deployments[network][designation]
console.log(
f"{designation} deployed already at {network}: {contract_address}"
)
return contract_address
return ZERO_ADDRESS
def store_deployed_contract(network, designation, deployment_address):
with open("./deployments.yaml", "r") as file:
deployments = yaml.safe_load(file)
if deployments is None:
deployments = {}
if not network in deployments.keys():
deployments[network] = {}
deployments[network][designation] = str(deployment_address)
with open("./deployments.yaml", "w") as file:
yaml.dump(deployments, file)
def deploy_and_cache_contracts(
network, designation, contract_file, args, fork=False
):
contract_address = check_contract_deployed(network, designation)
if contract_address != ZERO_ADDRESS:
return boa.load_partial(contract_file).at(contract_address)
deployed_contract = boa.load(contract_file, *args)
if not fork:
store_deployed_contract(
network, designation, deployed_contract.address
)
return deployed_contract
def deploy_base_pool_registry(network, fork):
# deploy base pool registry (even if there are no legacy base pools):
console.log("Deploying base pool registry ...")
base_pools = []
if network in BASE_POOLS.keys():
base_pools = BASE_POOLS[network]
base_pools_registry = deploy_and_cache_contracts(
network,
"BasePoolRegistry",
"contracts/registries/BasePoolRegistry.vy",
[],
fork,
)
# will add new base pools if registry does not have it:
if not len(base_pools) == base_pools_registry.base_pool_count():
console.log("Adding base pools to the base pool registry ...")
added_base_pools = [
base_pools_registry.base_pool_list(i)
for i in range(len(base_pools))
]
for base_pool in base_pools:
if not base_pool[0] in added_base_pools:
base_pools_registry.add_base_pool(*base_pool)
return base_pools_registry
def legacy_deployment(address_provider, metaregistry, registry_list):
# deploy stableswap registry and factory handlers
stableswap_custom_pool_registry = address_provider.get_address(0)
if stableswap_custom_pool_registry != ZERO_ADDRESS:
console.log(
"Adding stableswap custom pool registry to the Metaregistry ..."
)
registry_handler = deploy_and_cache_contracts(
network,
"StableRegistryHandler",
"contracts/registry_handlers/StableRegistryHandler.vy",
[stableswap_custom_pool_registry],
fork,
)
if registry_handler.address not in registry_list:
metaregistry.add_registry_handler(registry_handler.address)
stableswap_factory = address_provider.get_address(3)
if stableswap_factory != ZERO_ADDRESS:
# we need the base pools registry for legacy deployments
base_pools_registry = deploy_base_pool_registry(network, fork)
console.log("Adding stableswap factory to the Metaregistry ...")
registry_handler = deploy_and_cache_contracts(
network,
"StableFactoryHandler",
"contracts/registry_handlers/StableFactoryHandler.vy",
[stableswap_factory, base_pools_registry.address],
fork,
)
if registry_handler.address not in registry_list:
metaregistry.add_registry_handler(registry_handler.address)
# deploy cryptoswap registry and factory handlers
cryptoswap_custom_pool_registry = address_provider.get_address(5)
if cryptoswap_custom_pool_registry != ZERO_ADDRESS:
console.log(
"Adding cryptoswap custom pool registry to the Metaregistry ..."
)
registry_handler = deploy_and_cache_contracts(
network,
"CryptoRegistryHandler",
"contracts/registry_handlers/CryptoRegistryHandler.vy",
[cryptoswap_custom_pool_registry],
fork,
)
if registry_handler.address not in registry_list:
metaregistry.add_registry_handler(registry_handler.address)
cryptoswap_factory = address_provider.get_address(6)
if cryptoswap_factory != ZERO_ADDRESS:
console.log("Adding cryptoswap factory to the Metaregistry ...")
registry_handler = deploy_and_cache_contracts(
network,
"CryptoFactoryHandler",
"contracts/registry_handlers/CryptoFactoryHandler.vy",
[cryptoswap_factory, base_pools_registry.address],
fork,
)
if registry_handler.address not in registry_list:
metaregistry.add_registry_handler(registry_handler.address)
def ng_deployment(address_provider, metaregistry, registry_list):
# set up tricrypto ng factory handler
tricrypto_ng_factory = address_provider.get_address(11)
if tricrypto_ng_factory != ZERO_ADDRESS:
console.log("Adding Tricrypto Factory NG Handler ...")
registry_handler = deploy_and_cache_contracts(
network,
"TricryptoFactoryNGHandler",
"contracts/registry_handlers/ng/CurveTricryptoFactoryHandler.vy",
[tricrypto_ng_factory],
fork,
)
if registry_handler.address not in registry_list:
metaregistry.add_registry_handler(registry_handler.address)
# set up stableswap ng factory handler
stableswap_ng_factory = address_provider.get_address(12)
if stableswap_ng_factory != ZERO_ADDRESS:
console.log("Adding Stableswap Factory NG Handler ...")
registry_handler = deploy_and_cache_contracts(
network,
"StableswapFactoryNGHandler",
"contracts/registry_handlers/ng/CurveStableSwapFactoryNGHandler.vy",
[stableswap_ng_factory],
fork,
)
if registry_handler.address not in registry_list:
metaregistry.add_registry_handler(registry_handler.address)
# set up twocrypto ng factory handler
twocrypto_ng_factory = address_provider.get_address(13)
if twocrypto_ng_factory != ZERO_ADDRESS:
console.log("Adding Twocrypto Factory NG Handler ...")
registry_handler = deploy_and_cache_contracts(
network,
"TwocryptoFactoryNGHandler",
"contracts/registry_handlers/ng/CurveTwocryptoFactoryHandler.vy",
[twocrypto_ng_factory],
fork,
)
if registry_handler.address not in registry_list:
metaregistry.add_registry_handler(registry_handler.address)
def main(network, fork, url):
if network == "zksync":
if not fork:
boa_zksync.set_zksync_env(url)
console.log("Prodmode on zksync Era ...")
else:
boa_zksync.set_zksync_fork(url)
console.log("Forkmode on zksync Era ...")
boa.env.set_eoa(Account.from_key(os.environ["FIDDYDEPLOYER"]))
else:
if fork:
boa.env.fork(url)
console.log("Forkmode ...")
boa.env.eoa = FIDDY_DEPLOYER # set eoa address here
else:
console.log("Prodmode ...")
boa.set_env(NetworkEnv(url))
boa.env.add_account(Account.from_key(os.environ["FIDDYDEPLOYER"]))
address_provider = boa.load_partial("contracts/AddressProviderNG.vy").at(
ADDRESS_PROVIDER
)
metaregistry_address = address_provider.get_address(7)
# deploy metaregistry or fetch if it doesnt exist:
console.log("Deploying Metaregistry ...")
gauge_factory = address_provider.get_address(20) # 20 is for Gauge Factory
gauge_type = GAUGE_TYPE[network]
deploy_mregistry = metaregistry_address == ZERO_ADDRESS
deploy_mregistry = False
if deploy_mregistry:
metaregistry = deploy_and_cache_contracts(
network,
"Metaregistry",
"contracts/MetaregistryL2.vy",
[gauge_factory, gauge_type],
fork,
)
# Add Metaregistry to AddressProvider
console.log("Add Metaregistry to AddressProvider ...")
address_provider.add_new_id(7, metaregistry.address, "Metaregistry")
else:
metaregistry = boa.load_partial("contracts/MetaRegistryL2.vy").at(
metaregistry_address
)
registry_list = [
metaregistry.get_registry(i)
for i in range(metaregistry.registry_length())
]
# legacy registry handlers deployment:
legacy_deployment(address_provider, metaregistry, registry_list)
# ng registry handlers deployment:
ng_deployment(address_provider, metaregistry, registry_list)
console.log(
f"Deployment and integration of the Metaregistry on {network} completed."
)
if __name__ == "__main__":
network = "zksync"
url = ""
fork = False
if network == "zksync":
import boa_zksync
url = "https://mainnet.era.zksync.io"
ADDRESS_PROVIDER = "0x3934a3bB913E4a44316a89f5a83876B9C63e4F31"
elif network == "fraxtal":
network_url = "https://rpc.frax.com"
elif network == "kava":
network_url = "https://rpc.ankr.com/kava_evm"
else:
network_url = fetch_url(network)
main(network, fork, url)