Skip to content

Commit

Permalink
remove addessprovider dependency from metaregistry:
Browse files Browse the repository at this point in the history
  • Loading branch information
bout3fiddy committed Feb 21, 2024
1 parent 1a8ad55 commit 3309fb3
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 15 deletions.
36 changes: 29 additions & 7 deletions contracts/mainnet/MetaRegistry.vy
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ ADMIN_ACTIONS_DELAY: constant(uint256) = 3 * 86400


# ---- storage variables ---- #
address_provider: public(AddressProvider)
owner: public(address)
admin: public(address)
future_admin: public(address)

# get registry/registry_handler by index, index starts at 0:
get_registry: public(HashMap[uint256, address])
Expand All @@ -67,9 +67,8 @@ registry_length: public(uint256)

# ---- constructor ---- #
@external
def __init__(_address_provider: address):
self.address_provider = AddressProvider(_address_provider)
self.owner = AddressProvider(_address_provider).admin()
def __init__():
self.admin = msg.sender


# ---- internal methods ---- #
Expand Down Expand Up @@ -133,7 +132,7 @@ def add_registry_handler(_registry_handler: address):
@notice Adds a registry from the address provider entry
@param _registry_handler Address of the handler contract
"""
assert msg.sender == self.owner # dev: only owner
assert msg.sender == self.admin # dev: only admin

self._update_single_registry(self.registry_length, _registry_handler)

Expand All @@ -145,7 +144,7 @@ def update_registry_handler(_index: uint256, _registry_handler: address):
@param _index The index of the registry in get_registry
@param _registry_handler Address of the new handler contract
"""
assert msg.sender == self.owner # dev: only owner
assert msg.sender == self.admin # dev: only admin
assert _index < self.registry_length

self._update_single_registry(_index, _registry_handler)
Expand Down Expand Up @@ -559,3 +558,26 @@ def pool_list(_index: uint256) -> address:
return RegistryHandler(handler).pool_list(_index - pools_skip)
pools_skip += count
return empty(address)


@external
def commit_transfer_ownership(_addr: address):
"""
@notice Transfer ownership of this contract to `addr`
@param _addr Address of the new owner
"""
assert msg.sender == self.admin # dev: admin only
self.future_admin = _addr


@external
def accept_transfer_ownership():
"""
@notice Accept a pending ownership transfer
@dev Only callable by the new owner
"""
_admin: address = self.future_admin
assert msg.sender == _admin # dev: future admin only

self.admin = _admin
self.future_admin = empty(address)
36 changes: 33 additions & 3 deletions contracts/mainnet/registries/BasePoolRegistry.vy
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ event BasePoolRemoved:
basepool: indexed(address)


ADDRESS_PROVIDER: constant(address) = 0x0000000022D53366457F9d5E68Ec105046FC4383
admin: public(address)
future_admin: public(address)

base_pool: HashMap[address, BasePool]
base_pool_list: public(address[100])
get_base_pool_for_lp_token: public(HashMap[address, address])
base_pool_count: public(uint256)
last_updated: public(uint256)


@external
def __init__():
self.admin = msg.sender


@internal
@view
def _get_basepool_coins(_pool: address) -> address[MAX_COINS]:
Expand Down Expand Up @@ -225,7 +232,7 @@ def add_base_pool(_pool: address, _lp_token: address, _n_coins: uint256, _is_leg
@param _is_lending True if the base pool is a Curve Lending pool
@param _is_v2 True if the base pool is a Curve CryptoSwap pool
"""
assert msg.sender == AddressProvider(ADDRESS_PROVIDER).admin() # dev: admin-only function
assert msg.sender == self.admin # dev: admin-only function
assert self.base_pool[_pool].lp_token == empty(address) # dev: pool exists

# add pool to base_pool_list
Expand All @@ -252,7 +259,7 @@ def remove_base_pool(_pool: address):
@notice Remove a base pool from the registry
@param _pool Address of the base pool
"""
assert msg.sender == AddressProvider(ADDRESS_PROVIDER).admin() # dev: admin-only function
assert msg.sender == self.admin # dev: admin-only function
assert _pool != empty(address)
assert self.base_pool[_pool].lp_token != empty(address) # dev: pool doesn't exist

Expand Down Expand Up @@ -284,3 +291,26 @@ def remove_base_pool(_pool: address):

self.last_updated = block.timestamp
log BasePoolRemoved(_pool)


@external
def commit_transfer_ownership(_addr: address):
"""
@notice Transfer ownership of this contract to `addr`
@param _addr Address of the new owner
"""
assert msg.sender == self.admin # dev: admin only
self.future_admin = _addr


@external
def accept_transfer_ownership():
"""
@notice Accept a pending ownership transfer
@dev Only callable by the new owner
"""
_admin: address = self.future_admin
assert msg.sender == _admin # dev: future admin only

self.admin = _admin
self.future_admin = empty(address)
3 changes: 3 additions & 0 deletions scripts/setup_metaregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

RICH_CONSOLE = RichConsole(file=sys.stdout)

# TODO: Metaregistry and Base Pool Registry no longer have a dependency AddressProvider's admin.
# Adjust the code accordingly:


def main():
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def crypto_factory() -> VyperContract:


@pytest.fixture(scope="module")
def base_pool_registry(alice_address):
def base_pool_registry(owner):
return deploy_contract(
"BasePoolRegistry", sender=alice_address, directory="registries"
"BasePoolRegistry", sender=owner, directory="registries"
)


Expand Down Expand Up @@ -94,8 +94,8 @@ def address_provider(crypto_registry, owner):


@pytest.fixture(scope="module")
def metaregistry(address_provider, owner):
return deploy_contract("MetaRegistry", address_provider, sender=owner)
def metaregistry(owner):
return deploy_contract("MetaRegistry", sender=owner)


@pytest.fixture(scope="module")
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def twocrypto_ng_pool(
2000000000000,
146000000000000,
866,
1777655918836068423,
1500 * 10**18,
)

return twocrypto_ng_amm_deployer.at(swap)
108 changes: 108 additions & 0 deletions tests/unitary/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import boa
import pytest

from tests.utils import deploy_contract

pytest_plugins = [
"tests.fixtures.accounts",
"tests.fixtures.constants",
"tests.fixtures.deployments",
"tests.fixtures.functions",
]


@pytest.fixture(scope="module")
def metaregistry(ng_owner):
return deploy_contract("MetaRegistry", sender=ng_owner)


@pytest.fixture(scope="module")
def base_pool_registry(ng_owner):
return deploy_contract(
"BasePoolRegistry", sender=ng_owner, directory="registries"
)


@pytest.fixture(scope="module")
def populated_base_pool_registry(base_pool_registry, ng_owner, base_pools):
with boa.env.sender(ng_owner):
for data in base_pools.values():
base_pool_registry.add_base_pool(
data["pool"],
data["lp_token"],
data["num_coins"],
data["is_legacy"],
data["is_lending"],
data["is_v2"],
)
return base_pool_registry


@pytest.fixture(scope="module")
def stable_factory_handler(
populated_base_pool_registry, stableswap_ng_factory, owner
):
return deploy_contract(
"StableFactoryHandler",
stableswap_ng_factory.address,
populated_base_pool_registry.address,
sender=owner,
directory="registry_handlers",
)


@pytest.fixture(scope="module")
def crypto_registry_handler(owner, crypto_registry):
return deploy_contract(
"CryptoRegistryHandler",
crypto_registry.address,
sender=owner,
directory="registry_handlers",
)


@pytest.fixture(scope="module")
def crypto_factory_handler(
populated_base_pool_registry, crypto_factory, owner
):
return deploy_contract(
"CryptoFactoryHandler",
crypto_factory.address,
populated_base_pool_registry.address,
sender=owner,
directory="registry_handlers",
)


@pytest.fixture(scope="module")
def registries(
stable_registry, stable_factory, crypto_registry, crypto_factory
):
return [stable_registry, stable_factory, crypto_registry, crypto_factory]


@pytest.fixture(scope="module")
def handlers(
stable_registry_handler,
stable_factory_handler,
crypto_registry_handler,
crypto_factory_handler,
):
return [
stable_registry_handler,
stable_factory_handler,
crypto_registry_handler,
crypto_factory_handler,
]


@pytest.fixture(scope="module")
def populated_metaregistry(metaregistry, handlers, owner):
for handler in handlers:
metaregistry.add_registry_handler(handler.address, sender=owner)
return metaregistry


@pytest.fixture(scope="module")
def stable_registry_handler_index():
return 0

0 comments on commit 3309fb3

Please sign in to comment.