Skip to content

Commit

Permalink
FactoryRegistry: refactor init hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Nov 15, 2024
1 parent a5b9795 commit fb9d03e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
20 changes: 20 additions & 0 deletions contracts/helpers/FactoryRegistry.vy
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,45 @@ MAX_FACTORIES: public(constant(uint256)) = 10
pool_factories: DynArray[address, MAX_FACTORIES]
rewards_factories: DynArray[address, MAX_FACTORIES]
gauge_factories: DynArray[address, MAX_FACTORIES]
init_hashes: DynArray[bytes32, MAX_FACTORIES]

@deploy
def __init__(
_pool_factories: DynArray[address, MAX_FACTORIES],
_rewards_factories: DynArray[address, MAX_FACTORIES],
_gauge_factories: DynArray[address, MAX_FACTORIES],
_ihashes: DynArray[bytes32, MAX_FACTORIES],
):
assert len(_pool_factories) == len(_rewards_factories)
assert len(_pool_factories) == len(_gauge_factories)
assert len(_pool_factories) == len(_ihashes)

self.pool_factories = _pool_factories
self.rewards_factories = _rewards_factories
self.gauge_factories = _gauge_factories
self.init_hashes = _ihashes

@external
@view
def poolFactories() -> DynArray[address, MAX_FACTORIES]:
return self.pool_factories


@external
@view
def initHashToPoolFactory(_factory: address) -> bytes32:
counted: uint256 = len(self.pool_factories)

for findex: uint256 in range(0, MAX_FACTORIES):
if findex >= counted:
break

if self.pool_factories[findex] == _factory:
return self.init_hashes[findex]

return empty(bytes32)


@external
@view
def factoriesToPoolFactory(_factory: address) -> (address, address):
Expand Down
11 changes: 5 additions & 6 deletions contracts/modules/lp_shared.vy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ MAX_POOLS: constant(uint256) = 2000
MAX_ITERATIONS: constant(uint256) = 8000

ROOT_CHAIN_IDS: constant(uint256[2]) = [10, 8453]
FACTORY_TO_INIT_HASH: HashMap[address, bytes32]

# Interfaces

Expand All @@ -18,6 +17,7 @@ interface IFactoryRegistry:
def poolFactories() -> DynArray[address, MAX_FACTORIES]: view
def poolFactoriesLength() -> uint256: view
def factoriesToPoolFactory(_factory: address) -> address[2]: view
def initHashToPoolFactory(_factory: address) -> bytes32: view

interface IVoter:
def gauges(_pool_addr: address) -> address: view
Expand Down Expand Up @@ -50,10 +50,6 @@ def __init__(_voter: address, _registry: address, _convertor: address):
self.registry = IFactoryRegistry(_registry)
self.convertor = _convertor

# Root (placeholder) pool factory
self.FACTORY_TO_INIT_HASH[0xd02D36A5e826731c0cF6Be97922DAfa516B9E4B4] = \
0xb6ce19baf736d6d711871f9c2a3b71e32332f2230ba65b57060620d5d33997c9

@internal
@view
def _pools(_limit: uint256, _offset: uint256)\
Expand Down Expand Up @@ -177,7 +173,10 @@ def _root_lp_address(
@param _type The pool type
@return address
"""
init_hash: bytes32 = self.FACTORY_TO_INIT_HASH[_factory]
if chain.id in ROOT_CHAIN_IDS:
return empty(address)

init_hash: bytes32 = staticcall self.registry.initHashToPoolFactory(_factory)

if init_hash == empty(bytes32):
return empty(address)
Expand Down
1 change: 1 addition & 0 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def main():
str(os.getenv(f'FACTORIES_{chain_id}')).split(','),
str(os.getenv(f'REWARDS_FACTORIES_{chain_id}')).split(','),
str(os.getenv(f'GAUGE_FACTORIES_{chain_id}')).split(','),
str(os.getenv(f'INIT_HASHES_{chain_id}')).split(','),
{'from': account}
)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_factory_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ def test_factoriesToPoolFactory(factory_registry):

result = factory_registry.factoriesToPoolFactory(ADDRESS_ZERO)
assert ADDRESS_ZERO in result


@pytest.mark.skipif(int(CHAIN_ID) in [10, 8453], reason="Only leaf chains")
def test_initHashToPoolFactory(factory_registry):
factories = factory_registry.poolFactories()
result = factory_registry.initHashToPoolFactory(factories[0])

assert str(result) in os.getenv(f'INIT_HASHES_{CHAIN_ID}')

0 comments on commit fb9d03e

Please sign in to comment.