From b24c1f5ef4d38ec0851b6327c5cb947b0dfe27de Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 14 Mar 2024 18:14:20 +0200 Subject: [PATCH] Register predeployed instance --- python/src/skale_contracts/constants.py | 1 + python/src/skale_contracts/project_factory.py | 3 +++ .../src/skale_contracts/projects/__init__.py | 6 ++++-- python/src/skale_contracts/projects/ima.py | 18 ++++++++++-------- .../skale_contracts/projects/skale_manager.py | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/python/src/skale_contracts/constants.py b/python/src/skale_contracts/constants.py index 8c5411e..ef189e3 100644 --- a/python/src/skale_contracts/constants.py +++ b/python/src/skale_contracts/constants.py @@ -3,3 +3,4 @@ REPOSITORY_URL = 'https://skalenetwork.github.io/skale-contracts/' METADATA_FILENAME = 'metadata.json' NETWORK_TIMEOUT = 60 +PREDEPLOYED_ALIAS = 'predeployed' diff --git a/python/src/skale_contracts/project_factory.py b/python/src/skale_contracts/project_factory.py index 9131384..de376d5 100644 --- a/python/src/skale_contracts/project_factory.py +++ b/python/src/skale_contracts/project_factory.py @@ -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: @@ -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') diff --git a/python/src/skale_contracts/projects/__init__.py b/python/src/skale_contracts/projects/__init__.py index a2aaf92..7eb124c 100644 --- a/python/src/skale_contracts/projects/__init__.py +++ b/python/src/skale_contracts/projects/__init__.py @@ -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'] diff --git a/python/src/skale_contracts/projects/ima.py b/python/src/skale_contracts/projects/ima.py index b663a36..8574662 100644 --- a/python/src/skale_contracts/projects/ima.py +++ b/python/src/skale_contracts/projects/ima.py @@ -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 @@ -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() ) @@ -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() ), @@ -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) diff --git a/python/src/skale_contracts/projects/skale_manager.py b/python/src/skale_contracts/projects/skale_manager.py index c79ae7e..9cf8840 100644 --- a/python/src/skale_contracts/projects/skale_manager.py +++ b/python/src/skale_contracts/projects/skale_manager.py @@ -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 @@ -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() )