From 902abc2bf72bbeb2ca4b7a3c497c853454a222df Mon Sep 17 00:00:00 2001 From: bout3fiddy <11488427+bout3fiddy@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:54:06 +0200 Subject: [PATCH] add script to deploy all registries at once --- deployments.yaml | 10 +- scripts/add_new_id_addressprovider.py | 5 +- scripts/address_provider_constants.py | 6 +- ...deploy_addressprovider_and_setup_zksync.py | 2 +- scripts/deploy_metaregistryl2.py | 8 +- scripts/deploy_rate_provider.py | 2 +- scripts/deploy_registries_zksync.py | 375 ++++++++++++++++++ scripts/update_address_provider.py | 144 +++++++ 8 files changed, 539 insertions(+), 13 deletions(-) create mode 100644 scripts/deploy_registries_zksync.py create mode 100644 scripts/update_address_provider.py diff --git a/deployments.yaml b/deployments.yaml index d78fe13..4c8ab8c 100644 --- a/deployments.yaml +++ b/deployments.yaml @@ -72,7 +72,9 @@ polygon: TricryptoFactoryNGHandler: '0xf46D25696677898454dfDd644830C821243A1188' TwocryptoFactoryNGHandler: '0xb00e89eabd59cd3254c88e390103cf17e914f678' zksync: - Metaregistry: '0x48e4b27553e7643E10229ea3cba91c188dc524B1' - StableswapFactoryNGHandler: '0x4Cabf81fbf1F42531d55507F38Be77367481a8dF' - TricryptoFactoryNGHandler: '0xf3f38b1677553789A048FFf4A2CeedCDf063309e' - TwocryptoFactoryNGHandler: '0x0F3d82D719582BcaB662F434D77B089C86D05FAb' + AddressProvider: '0xBF664Ac8e934230FC6A381702678cc29661d38D5' + Metaregistry: '' + RateProvider: '0x9eB20D123F877f06c93CE82De4507B0911dFA783' + StableswapFactoryNGHandler: '' + TricryptoFactoryNGHandler: '' + TwocryptoFactoryNGHandler: '' diff --git a/scripts/add_new_id_addressprovider.py b/scripts/add_new_id_addressprovider.py index db716ab..cdfcfd4 100644 --- a/scripts/add_new_id_addressprovider.py +++ b/scripts/add_new_id_addressprovider.py @@ -11,6 +11,9 @@ from eth_account import Account from rich.console import Console as RichConsole +import sys +sys.path.append("./") + from scripts.address_provider_constants import ( ADDRESS_PROVIDER_MAPPING, addresses, @@ -100,7 +103,7 @@ def main(network, fork, url): import boa_zksync url = "https://mainnet.era.zksync.io" - ADDRESS_PROVIDER = "0x54A5a69e17Aa6eB89d77aa3828E38C9Eb4fF263D" + ADDRESS_PROVIDER = "0x3934a3bB913E4a44316a89f5a83876B9C63e4F31" elif network == "fraxtal": network_url = "https://rpc.frax.com" elif network == "kava": diff --git a/scripts/address_provider_constants.py b/scripts/address_provider_constants.py index f7c25ea..f5ddd97 100644 --- a/scripts/address_provider_constants.py +++ b/scripts/address_provider_constants.py @@ -309,9 +309,9 @@ "zksync": { 2: "0x7C915390e109CA66934f1eB285854375D1B127FA", # 2: "Exchange Router", 4: "0xCb8799BFF48bb549F7B69Bb9BE60DbA7cd4F1BB7", # 4: "Fee Distributor", - 11: "0x5044112fDf6c8DCc788a669c17345cfDB06549fa", # 11: "TricryptoNG Factory", - 12: "0x375444aeDEb6C3db897f293E1DBa85D7422A6859", # 12: "StableswapNG Factory", - 13: "0x24992A09E2257AF325102Cefa1F09E80E9062d49", # 13: "TwocryptoNG Factory", + 11: "0x5d4174C40f1246dABe49693845442927d5929f0D", # 11: "TricryptoNG Factory", + 12: "0xFcAb5d04e8e031334D5e8D2C166B08daB0BE6CaE", # 12: "StableswapNG Factory", + 13: "0xf3a546AF64aFd6BB8292746BA66DB33aFAE72114", # 13: "TwocryptoNG Factory", 19: "0x5945932099f124194452a4c62d34bB37f16183B2", # 19: "CRV Token", 20: "", # 20: "Gauge Factory", 21: "", # 21: "Ownership Admin", diff --git a/scripts/deploy_addressprovider_and_setup_zksync.py b/scripts/deploy_addressprovider_and_setup_zksync.py index b3841d0..b13a51e 100644 --- a/scripts/deploy_addressprovider_and_setup_zksync.py +++ b/scripts/deploy_addressprovider_and_setup_zksync.py @@ -1,4 +1,4 @@ -# AddressProvider deployed on zksync at: 0x54A5a69e17Aa6eB89d77aa3828E38C9Eb4fF263D +# AddressProvider deployed on zksync at: 0x3934a3bB913E4a44316a89f5a83876B9C63e4F31 import os diff --git a/scripts/deploy_metaregistryl2.py b/scripts/deploy_metaregistryl2.py index 0c87d8b..4493b5d 100644 --- a/scripts/deploy_metaregistryl2.py +++ b/scripts/deploy_metaregistryl2.py @@ -262,8 +262,11 @@ def main(network, fork, url): 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 metaregistry_address == ZERO_ADDRESS: + if deploy_mregistry: metaregistry = deploy_and_cache_contracts( network, "Metaregistry", @@ -303,9 +306,8 @@ def main(network, fork, url): if network == "zksync": import boa_zksync - url = "https://mainnet.era.zksync.io" - ADDRESS_PROVIDER = "0x54A5a69e17Aa6eB89d77aa3828E38C9Eb4fF263D" + ADDRESS_PROVIDER = "0x3934a3bB913E4a44316a89f5a83876B9C63e4F31" elif network == "fraxtal": network_url = "https://rpc.frax.com" elif network == "kava": diff --git a/scripts/deploy_rate_provider.py b/scripts/deploy_rate_provider.py index 4758560..e79c053 100644 --- a/scripts/deploy_rate_provider.py +++ b/scripts/deploy_rate_provider.py @@ -69,7 +69,7 @@ def main(network, fork, url): import boa_zksync network_url = "https://mainnet.era.zksync.io" - ADDRESS_PROVIDER = "0x54A5a69e17Aa6eB89d77aa3828E38C9Eb4fF263D" + ADDRESS_PROVIDER = "0x3934a3bB913E4a44316a89f5a83876B9C63e4F31" elif network == "fraxtal": network_url = "https://rpc.frax.com" elif network == "kava": diff --git a/scripts/deploy_registries_zksync.py b/scripts/deploy_registries_zksync.py new file mode 100644 index 0000000..106cc01 --- /dev/null +++ b/scripts/deploy_registries_zksync.py @@ -0,0 +1,375 @@ +# 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.address_provider_constants import ( + ADDRESS_PROVIDER_MAPPING, + addresses, +) +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" + +# 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"])) + + # deploy address provider: + address_provider = deploy_and_cache_contracts( + network, + "AddressProvider", + "contracts/AddressProviderNG.vy", + [], + fork, + ) + + # deploy rate provider: + rate_provider = deploy_and_cache_contracts( + network, + "RateProvider", + "contracts/RateProvider.vy", + [address_provider.address], + fork, + ) + + console.log("Adding rate provider to address provider") + if address_provider.get_address(18) == ZERO_ADDRESS: + address_provider.add_new_id( + 18, rate_provider.address, "Spot Rate Provider" + ) + elif address_provider.get_address(18) != rate_provider.address: + address_provider.update_address(18, rate_provider.address) + + # set up address provider: + ids = [] + addresses_for_id = [] + descriptions = [] + for id in addresses[network].keys(): + address = addresses[network][id] + description = ADDRESS_PROVIDER_MAPPING[id] + existing_id = address_provider.get_id_info(id) + + if not address: + continue + + if ( + existing_id[0].lower() + == "0x0000000000000000000000000000000000000000" + ): + console.log(f"New id {id} at {address} for {description}.") + ids.append(id) + addresses_for_id.append(address) + descriptions.append(description) + + elif existing_id[0].lower() != address.lower(): + console.log(f"Updating id {id} for {description} with {address}.") + address_provider.update_id(id, address, description) + + if len(ids) > 20: + raise + + if len(ids) > 0: + console.log("Adding new IDs to the Address Provider.") + address_provider.add_new_ids(ids, addresses_for_id, descriptions) + + # metaregistry deployment: + 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) diff --git a/scripts/update_address_provider.py b/scripts/update_address_provider.py new file mode 100644 index 0000000..797d3af --- /dev/null +++ b/scripts/update_address_provider.py @@ -0,0 +1,144 @@ +# flake8 no-qa E402 +# Contract deployed at: 0x5ffe7FB82894076ECB99A30D6A32e969e6e35E98 +# Deployed at: Ethereum, Arbitrum, Optimism, Base, Bsc, Polygon, +# Fantom, Gnosis, Aurora, Celo, Mantle, +# Linea, Polygon zkEVM, Scroll, Fraxtal, Avalanche, Kava + +import os + +import boa +from boa.network import NetworkEnv +from eth_account import Account +from rich.console import Console as RichConsole + + +FIDDY_DEPLOYER = "0x2d12D0907A388811e3AA855A550F959501d303EE" +ADDRESS_PROVIDER = ( + "0x5ffe7FB82894076ECB99A30D6A32e969e6e35E98" # gets replaced for zksync +) +to_update = { + "ethereum": { + 2: '0x16C6521Dff6baB339122a0FE25a9116693265353', + 4: '0xD16d5eC345Dd86Fb63C6a9C43c517210F1027914', + }, + "optimism": { + 2: '0x0DCDED3545D565bA3B19E683431381007245d983', + }, + "gnosis": { + 2: '0x0DCDED3545D565bA3B19E683431381007245d983', + }, + "polygon": { + 2: '0x0DCDED3545D565bA3B19E683431381007245d983', + }, + "fantom": { + 2: '0x0DCDED3545D565bA3B19E683431381007245d983', + }, + "kava": { + 2: '0x0DCDED3545D565bA3B19E683431381007245d983', + }, + "arbitrum": { + 2: '0x2191718CD32d02B8E60BAdFFeA33E4B5DD9A0A0D', + }, + "avalanche": { + 2: '0x0DCDED3545D565bA3B19E683431381007245d983', + }, + "base": { + 2: '0x4f37A9d177470499A2dD084621020b023fcffc1F', + }, + "bsc": { + 2: '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', + }, + "fraxtal": { + 2: '0x9f2Fa7709B30c75047980a0d70A106728f0Ef2db', + }, + "xlayer": { + 2: '0xBFab8ebc836E1c4D81837798FC076D219C9a1855', + }, + "mantle": { + 2: '0x4f37A9d177470499A2dD084621020b023fcffc1F', + }, + "zksync": { + 2: '0x7C915390e109CA66934f1eB285854375D1B127FA', + }, +} + + +def fetch_url(network): + return os.getenv("DRPC_URL") % (network, os.getenv("DRPC_KEY")) + + +def main(network, fork, url): + """ + Deploy the AddressProvider to the network. + """ + + console = RichConsole() + + 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_obj = boa.load_partial("contracts/AddressProviderNG.vy") + address_provider = address_provider_obj.at(ADDRESS_PROVIDER) + + console.log(f"For network: {network}") + + # set up address provider + network_update = to_update[network] + if not network_update: + return + + updating = False + for key, value in network_update.items(): + current_value = address_provider.get_address(key) + if not current_value == value: + updating = True + console.log(f"Updating id {key} from {current_value} to {value}.") + address_provider.update_address(key, value) + + if updating: + console.log("Done!") + else: + console.log("Already updated!") + + +if __name__ == "__main__": + + fork = False + + for network in to_update.keys(): + + url = "" + + if network == "zksync": + import boa_zksync + network_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" + elif network == "xlayer": + network_url = "https://xlayerrpc.okx.com" + elif network == "mantle": + network_url = "https://rpc.mantle.xyz" + else: + network_url = fetch_url(network) + + main(network, fork, network_url)