Skip to content

Commit

Permalink
Register predeployed instance
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Mar 14, 2024
1 parent 4faf20f commit b24c1f5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions python/src/skale_contracts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
REPOSITORY_URL = 'https://skalenetwork.github.io/skale-contracts/'
METADATA_FILENAME = 'metadata.json'
NETWORK_TIMEOUT = 60
PREDEPLOYED_ALIAS = 'predeployed'
3 changes: 3 additions & 0 deletions python/src/skale_contracts/project_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Projects:
"""Contains all known projects"""
skale_manager = ProjectMetadata(name='skale-manager', path='skale-manager')
mainnet_ima = ProjectMetadata(name='mainnet-ima', path='mainnet-ima')
schain_ima = ProjectMetadata(name='schain-ima', path='schain-ima')


def create_project(network: Network, name: str) -> Project:
Expand All @@ -25,4 +26,6 @@ def create_project(network: Network, name: str) -> Project:
return projects.SkaleManager(network, Projects.skale_manager)
if name == Projects.mainnet_ima.name:
return projects.MainnetIma(network, Projects.mainnet_ima)
if name == Projects.schain_ima.name:
return projects.SchainIma(network, Projects.schain_ima)
raise ValueError(f'Project with name {name} is unknown')
6 changes: 4 additions & 2 deletions python/src/skale_contracts/projects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Supported projects"""
from .ima import MainnetImaProject as MainnetIma
from .ima import \
MainnetImaProject as MainnetIma, \
SchainImaProject as SchainIma
from .skale_manager import SkaleManagerProject as SkaleManager

__all__ = ["MainnetIma", "SkaleManager"]
__all__ = ['MainnetIma', 'SchainIma', 'SkaleManager']
18 changes: 10 additions & 8 deletions python/src/skale_contracts/projects/ima.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from eth_typing import Address
from eth_utils.address import to_canonical_address

from skale_contracts.constants import PREDEPLOYED_ALIAS
from skale_contracts.instance import Instance, DEFAULT_GET_VERSION_FUNCTION
from skale_contracts.project import Project

Expand Down Expand Up @@ -48,17 +49,14 @@ def get_contract_address(self, name: str) -> Address:
if name == 'MessageProxyForMainnet':
return self.address
if name == 'CommunityPool':
return cast(
Address,
return to_canonical_address(
self.get_contract("MessageProxyForMainnet").functions.communityPool().call()
)
if name == 'Linker':
return cast(
Address,
return to_canonical_address(
self.get_contract("MessageProxyForMainnet").functions.linker().call()
)
return cast(
Address,
return to_canonical_address(
self.contract_manager.functions.getContract(name).call()
)

Expand All @@ -67,8 +65,7 @@ def contract_manager(self) -> Contract:
"""ContractManager contract of a skale-manager instance associated with the IMA"""
if self._contract_manager is None:
self._contract_manager = self.web3.eth.contract(
address=cast(
Address,
address=to_canonical_address(
self.get_contract("MessageProxyForMainnet")
.functions.contractManagerOfSkaleManager().call()
),
Expand Down Expand Up @@ -113,6 +110,11 @@ def get_contract_address(self, name: str) -> Address:
class SchainImaProject(ImaProject):
"""Represents schain part of IMA project"""

def get_instance(self, alias_or_address: str) -> Instance:
if alias_or_address == PREDEPLOYED_ALIAS:
return self.create_instance(SchainImaInstance.PREDEPLOYED['MessageProxyForSchain'])
return super().get_instance(alias_or_address)

def create_instance(self, address: Address) -> Instance:
return SchainImaInstance(self, address)

Expand Down
4 changes: 2 additions & 2 deletions python/src/skale_contracts/projects/skale_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations
from typing import cast, TYPE_CHECKING
from eth_utils.address import to_canonical_address

from skale_contracts.instance import Instance, DEFAULT_GET_VERSION_FUNCTION
from skale_contracts.project import Project
Expand Down Expand Up @@ -48,8 +49,7 @@ def __init__(self, project: Project, address: Address) -> None:
}

def get_contract_address(self, name: str) -> Address:
return cast(
Address,
return to_canonical_address(
self.contract_manager.functions.getContract(self._actual_name(name)).call()
)

Expand Down

0 comments on commit b24c1f5

Please sign in to comment.