Skip to content

Commit

Permalink
Merge pull request #22 from curvefi/feat/l2_metaregistry
Browse files Browse the repository at this point in the history
l2 metaregistry
  • Loading branch information
bout3fiddy authored May 17, 2024
2 parents 150f336 + 9ac8e94 commit 13454f4
Show file tree
Hide file tree
Showing 22 changed files with 762 additions and 26 deletions.
File renamed without changes.
593 changes: 593 additions & 0 deletions contracts/MetaRegistryL2.vy

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
titanoboa[forking-recommended] @ git+https://github.com/vyperlang/titanoboa@e85ab24
titanoboa[forking-recommended] @ git+https://github.com/vyperlang/titanoboa@69c68d6dbb60b8f8782b5bfca336f5dc838a7719
black
flake8
isort
Expand Down
16 changes: 16 additions & 0 deletions scripts/address_provider_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@
23: "0xA177D2bd2BD723878bD95982c0855291953f74C9",
25: "0x98B4029CaBEf7Fd525A36B0BF8555EC1d42ec0B6", # crvUSD
},
"xlayer": {
2: "0x4f37A9d177470499A2dD084621020b023fcffc1F", # 2: "Exchange Router",
4: "0xf3A431008396df8A8b2DF492C913706BDB0874ef", # 4: "Fee Distributor",
11: "0xd3B17f862956464ae4403cCF829CE69199856e1e", # 11: "TricryptoNG Factory",
12: "0x5eeE3091f747E60a045a2E715a4c71e600e31F6E", # 12: "StableswapNG Factory",
13: "0x0c59d36b23f809f8b6C7cb4c8C590a0AC103baEf", # 13: "TwocryptoNG Factory",
14: "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF", # 14: "Stableswap Calculations Contract",
15: "0x69522fb5337663d3B4dFB0030b881c1A750Adb4f", # 15: "Cryptoswap calculations Contract",
19: "0x3d5320821bfca19fb0b5428f2c79d63bd5246f89", # 19: "CRV Token",
20: "0xeF672bD94913CB6f1d2812a6e18c1fFdEd8eFf5c", # 20: "Gauge Factory",
21: "0x6628b9e7c0029cea234b382be17101648f32cd8f", # 21: "Ownership Admin",
22: "0xccc4864762412f3273bf7ca9264295909504ebb5", # 22: "Parameter Admin",
23: "0x9ffc6f671d88593aae56d9d34f2b40d7a56d467f", # 23: "Emergency Admin",
24: "0x0848F3800F04b3ad4309A5f27814be7FC4740cB9", # 24: "CurveDAO Vault", # Holds funds
25: "0xdA8f4Eb4503ACF5dec5420523637bb5b33a846f6", # 25: "crvUSD Token"
},
# No UI:
"linea": {
4: "0xf3A431008396df8A8b2DF492C913706BDB0874ef",
Expand Down
16 changes: 7 additions & 9 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ def main():
setup_environment(console)

# deploy basepool registry:
base_pool_registry = boa.load(
"contracts/mainnet/registries/BasePoolRegistry.vy"
)
base_pool_registry = boa.load("contracts/registries/BasePoolRegistry.vy")

# deploy crypto registry:
console.log(
"Crypto Registry constructor arguments: ",
encode(["address", "address"], [ADDRESS_PROVIDER, base_pool_registry]),
)
crypto_registry = boa.load(
"contracts/mainnet/registries/CryptoRegistryV1.vy",
"contracts/registries/CryptoRegistryV1.vy",
ADDRESS_PROVIDER,
base_pool_registry,
)
Expand All @@ -57,7 +55,7 @@ def main():
encode(["address"], [STABLE_REGISTRY_ADDRESS]).hex(),
)
boa.load(
"contracts/mainnet/registry_handlers/StableRegistryHandler.vy",
"contracts/registry_handlers/StableRegistryHandler.vy",
STABLE_REGISTRY_ADDRESS,
)

Expand All @@ -70,7 +68,7 @@ def main():
).hex(),
)
boa.load(
"contracts/mainnet/registry_handlers/StableFactoryHandler.vy",
"contracts/registry_handlers/StableFactoryHandler.vy",
STABLE_FACTORY_ADDRESS,
base_pool_registry,
)
Expand All @@ -81,7 +79,7 @@ def main():
encode(["address"], [crypto_registry]).hex(),
)
boa.load(
"contracts/mainnet/registry_handlers/CryptoRegistryHandler.vy",
"contracts/registry_handlers/CryptoRegistryHandler.vy",
crypto_registry,
)

Expand All @@ -94,7 +92,7 @@ def main():
).hex(),
)
boa.load(
"contracts/mainnet/registry_handlers/CryptoFactoryHandler.vy",
"contracts/registry_handlers/CryptoFactoryHandler.vy",
CRYPTO_FACTORY_ADDRESS,
base_pool_registry,
)
Expand All @@ -104,7 +102,7 @@ def main():
"MetaRegistry constructor arguments: ",
encode(["address"], [ADDRESS_PROVIDER]).hex(),
)
boa.load("contracts/mainnet/MetaRegistry.vy", ADDRESS_PROVIDER)
boa.load("contracts/MetaRegistry.vy", ADDRESS_PROVIDER)


if __name__ == "__main__":
Expand Down
13 changes: 8 additions & 5 deletions scripts/deploy_addressprovider_and_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@ def deploy_via_create2_factory(deployment_bytecode, salt, create2deployer):
create2deployer.deploy(0, salt, deployment_bytecode)


def main(network, fork):
def main(network, fork, url=""):
"""
Deploy the AddressProvider to the network.
"""

console = RichConsole()
if not url:
url = fetch_url(network)

if not fork:
# Prodmode
console.log("Running script in prod mode...")
boa.set_env(NetworkEnv(fetch_url(network)))
boa.set_env(NetworkEnv(url))
boa.env.add_account(Account.from_key(os.environ["FIDDYDEPLOYER"]))

else:
# Forkmode
console.log("Simulation Mode. Writing to mainnet-fork.")
boa.env.fork(url=fetch_url(network))
boa.env.fork(url=url)
boa.env.eoa = FIDDY_DEPLOYER

CREATE2DEPLOYER = boa.load_abi("abi/create2deployer.json").at(
Expand Down Expand Up @@ -82,11 +84,12 @@ def main(network, fork):
if len(ids) > 20:
raise

console.log("Adding new ids ...")
address_provider.add_new_ids(ids, addresses_for_id, descriptions)


if __name__ == "__main__":
network = "kava"
network = "xlayer"
fork = False

main(network, fork)
main(network, fork, url="https://xlayerrpc.okx.com")
4 changes: 2 additions & 2 deletions scripts/deploy_and_setup_crypto_ng_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def main(network: str = "ethereum", fork: bool = True):

# deploy handlers:
registry = boa.load(
"contracts/mainnet/registry_handlers/ng/CurveTwocryptoFactoryHandler.vy",
"contracts/registry_handlers/ng/CurveTwocryptoFactoryHandler.vy",
"0x98EE851a00abeE0d95D08cF4CA2BdCE32aeaAF7F",
)
registry = boa.load(
"contracts/mainnet/registry_handlers/ng/CurveTricryptoFactoryHandler.vy",
"contracts/registry_handlers/ng/CurveTricryptoFactoryHandler.vy",
"0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963",
)
console.log(f"Deployed Factory Handlers.")
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy_and_setup_stableswap_factory_ng_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main(network: str = "ethereum", fork: bool = True):

# deploy basepool registry:
registry = boa.load(
"contracts/mainnet/registry_handlers/ng/CurveStableSwapFactoryNGHandler.vy",
"contracts/registry_handlers/ng/CurveStableSwapFactoryNGHandler.vy",
"0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf", # stableswap factory ng
)
console.log(
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy_crypto_registry_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def main():
console = RichConsole()
console.log("Deploying Crypto Registry Handler contract...")
setup_environment(console)
boa.load("contracts/mainnet/registry_handlers/CryptoRegistryHandler.vy")
boa.load("contracts/registry_handlers/CryptoRegistryHandler.vy")


if __name__ == "__main__":
Expand Down
128 changes: 128 additions & 0 deletions scripts/deploy_metaregistry_sidechain_l2s.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import os
import sys

import boa
from eth_account import Account
from rich.console import Console as RichConsole

sys.path.append("./")

FIDDY_DEPLOYER = ""
ADDRESS_PROVIDER = "0x5ffe7FB82894076ECB99A30D6A32e969e6e35E98"
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,
}


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.
"""
assert "ethereum" not in network
console = RichConsole()
if not url:
url = fetch_url(network)

if not fork:
# Prodmode
console.log("Running script in prod mode...")
boa.set_network_env(url)
boa.env.add_account(Account.from_key(os.environ["FIDDYDEPLOYER"]))
boa.env.suppress_debug_tt(True)

else:
# Forkmode
console.log("Simulation Mode. Writing to mainnet-fork.")
boa.env.fork(url=url)
boa.env.eoa = FIDDY_DEPLOYER

address_provider = boa.load_partial("contracts/AddressProviderNG.vy").at(
ADDRESS_PROVIDER
)

# deploy metaregistry
# console.log("Deploying Metaregistry ...")
# gauge_factory = address_provider.get_address(20) # 20 is for Gauge Factory
# gauge_type = GAUGE_TYPE[network]
# metaregistry = boa.load("contracts/MetaregistryL2.vy", gauge_factory, gauge_type)
# console.log(
# "Constructor arguments: ",
# encode(["address", "int128"], [gauge_factory, gauge_type]).hex(),
# )

# xlayer
metaregistry = boa.load_partial("contracts/MetaregistryL2.vy").at(
"0x87DD13Dd25a1DBde0E1EdcF5B8Fa6cfff7eABCaD"
)

# set up tricrypto ng factory handler
console.log("Deploy Tricrypto Factory Handler ...")
tricrypto_ng_factory = address_provider.get_address(11)
tricrypto_ng_factory_handler = boa.load(
"contracts/registry_handlers/ng/CurveTricryptoFactoryHandler.vy",
tricrypto_ng_factory,
)

# set up stableswap ng factory handler
console.log("Deploy Stableswap Factory Handler ...")
stableswap_ng_factory = address_provider.get_address(12)
stableswap_ng_factory_handler = boa.load(
"contracts/registry_handlers/ng/CurveStableSwapFactoryNGHandler.vy",
stableswap_ng_factory,
)

# set up twocrypto ng factory handler
console.log("Deploy Twocrypto Factory Handler ...")
twocrypto_ng_factory = address_provider.get_address(13)
twocrypto_ng_factory_handler = boa.load(
"contracts/registry_handlers/ng/CurveTwocryptoFactoryHandler.vy",
twocrypto_ng_factory,
)

# Add registry handlers to the metaregistry
console.log("Add Factory Handlers to Metaregistry ...")
metaregistry.add_registry_handler(stableswap_ng_factory_handler.address)
metaregistry.add_registry_handler(twocrypto_ng_factory_handler.address)
metaregistry.add_registry_handler(tricrypto_ng_factory_handler.address)

# add metaregistry to address provider
console.log("Add Metaregistry to AddressProvider ...")
address_provider.add_new_id(7, metaregistry.address, "Metaregistry")

console.log("Deployment and integration of the Metaregistry completed.")


if __name__ == "__main__":
# not deployed:
# aurora

network = ""
fork = False
url = ""

if network == "xlayer":
url = "https://rpc.xlayer.tech"
elif network == "fraxtal":
url = "https://rpc.frax.com"

main(network, fork, url=url)
2 changes: 1 addition & 1 deletion scripts/utils/print_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_functions_from_source(name: str) -> set[str]:
:param name: the name of the source file
:return: the view functions from the source file
"""
deployer = boa.load_partial(f"contracts/mainnet/{name}.vy")
deployer = boa.load_partial(f"contracts/{name}.vy")
meta_functions = get_view_functions(
abi=build_abi_output(deployer.compiler_data)
)
Expand Down
6 changes: 3 additions & 3 deletions tests/unitary/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def stable_ng_factory_handler(
):
with boa.env.prank(ng_owner):
return boa.load(
"contracts/mainnet/registry_handlers/ng/CurveStableSwapFactoryNGHandler.vy",
"contracts/registry_handlers/ng/CurveStableSwapFactoryNGHandler.vy",
stableswap_ng_factory.address,
populated_base_pool_registry.address,
)
Expand All @@ -49,7 +49,7 @@ def stable_ng_factory_handler(
def twocrypto_ng_factory_handler(twocrypto_ng_factory, ng_owner):
with boa.env.prank(ng_owner):
return boa.load(
"contracts/mainnet/registry_handlers/ng/CurveTwocryptoFactoryHandler.vy",
"contracts/registry_handlers/ng/CurveTwocryptoFactoryHandler.vy",
twocrypto_ng_factory.address,
)

Expand All @@ -58,7 +58,7 @@ def twocrypto_ng_factory_handler(twocrypto_ng_factory, ng_owner):
def tricrypto_ng_factory_handler(tricrypto_ng_factory, ng_owner):
with boa.env.prank(ng_owner):
return boa.load(
"contracts/mainnet/registry_handlers/ng/CurveTricryptoFactoryHandler.vy",
"contracts/registry_handlers/ng/CurveTricryptoFactoryHandler.vy",
tricrypto_ng_factory.address,
)

Expand Down
4 changes: 1 addition & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def deploy_contract(
directory: str = ".",
**kwargs,
) -> VyperContract:
file_name = path.join(
BASE_DIR, f"contracts/mainnet/{directory}/{contract}.vy"
)
file_name = path.join(BASE_DIR, f"contracts/{directory}/{contract}.vy")
with boa.env.sender(sender):
return boa.load(file_name, *args, **kwargs)

Expand Down

0 comments on commit 13454f4

Please sign in to comment.