diff --git a/python/src/skale_contracts/instance.py b/python/src/skale_contracts/instance.py index 3c2a2f1..a3da474 100644 --- a/python/src/skale_contracts/instance.py +++ b/python/src/skale_contracts/instance.py @@ -3,8 +3,9 @@ from __future__ import annotations from abc import ABC, abstractmethod import json -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, cast from attr import dataclass +from eth_typing import ChecksumAddress from parver import Version as PyVersion from semver.version import Version as SemVersion @@ -83,16 +84,19 @@ def abi(self) -> SkaleAbi: return self._abi @abstractmethod - def get_contract_address(self, name: str) -> Address: + def get_contract_address(self, name: str, *args: str|Address|ChecksumAddress) -> Address: """Get address of the contract by it's name""" - def get_contract(self, name: str) -> Contract: + def get_contract(self, name: str, *args: str|Address|ChecksumAddress) -> Contract: """Get Contract object of the contract by it's name""" - address = self.get_contract_address(name) + address = self.get_contract_address(name, *args) return self.web3.eth.contract(address=address, abi=self.abi[name]) # protected - @abstractmethod def _get_version(self) -> str: - pass + contract = self.web3.eth.contract( + address=self.address, + abi=[DEFAULT_GET_VERSION_FUNCTION] + ) + return cast(str, contract.functions.version().call()) diff --git a/python/src/skale_contracts/project_factory.py b/python/src/skale_contracts/project_factory.py index de376d5..8626b0b 100644 --- a/python/src/skale_contracts/project_factory.py +++ b/python/src/skale_contracts/project_factory.py @@ -18,6 +18,7 @@ class 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') + skale_allocator = ProjectMetadata(name='skale-allocator', path='skale-allocator') def create_project(network: Network, name: str) -> Project: @@ -28,4 +29,6 @@ def create_project(network: Network, name: str) -> Project: return projects.MainnetIma(network, Projects.mainnet_ima) if name == Projects.schain_ima.name: return projects.SchainIma(network, Projects.schain_ima) + if name == Projects.skale_allocator.name: + return projects.SkaleAllocator(network, Projects.skale_allocator) 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 7eb124c..cc88ec4 100644 --- a/python/src/skale_contracts/projects/__init__.py +++ b/python/src/skale_contracts/projects/__init__.py @@ -3,5 +3,6 @@ MainnetImaProject as MainnetIma, \ SchainImaProject as SchainIma from .skale_manager import SkaleManagerProject as SkaleManager +from .skale_allocator import SkaleAllocatorProject as SkaleAllocator -__all__ = ['MainnetIma', 'SchainIma', 'SkaleManager'] +__all__ = ['MainnetIma', 'SchainIma', 'SkaleAllocator', 'SkaleManager'] diff --git a/python/src/skale_contracts/projects/ima.py b/python/src/skale_contracts/projects/ima.py index 8574662..cab97be 100644 --- a/python/src/skale_contracts/projects/ima.py +++ b/python/src/skale_contracts/projects/ima.py @@ -1,8 +1,7 @@ """Module connects IMA to the SKALE contracts library""" from __future__ import annotations -from typing import cast, TYPE_CHECKING -from eth_typing import Address +from typing import TYPE_CHECKING from eth_utils.address import to_canonical_address from skale_contracts.constants import PREDEPLOYED_ALIAS @@ -13,6 +12,7 @@ if TYPE_CHECKING: + from eth_typing import Address, ChecksumAddress from web3.contract.contract import Contract MESSAGE_PROXY_ABI = [ @@ -26,9 +26,6 @@ def __init__(self, project: Project, address: Address) -> None: super().__init__(project, address) self.message_proxy = self.web3.eth.contract(address=address, abi=MESSAGE_PROXY_ABI) - def _get_version(self) -> str: - return cast(str, self.message_proxy.functions.version().call()) - class ImaProject(Project): """Represents IMA project""" @@ -45,7 +42,7 @@ def __init__(self, project: Project, address: Address) -> None: super().__init__(project, address) self._contract_manager: Contract | None = None - def get_contract_address(self, name: str) -> Address: + def get_contract_address(self, name: str, *args: str|Address|ChecksumAddress) -> Address: if name == 'MessageProxyForMainnet': return self.address if name == 'CommunityPool': @@ -101,7 +98,7 @@ class SchainImaInstance(ImaInstance): 'TokenManagerERC721WithMetadata': '0xd2AaA00a00000000000000000000000000000000' }.items()} - def get_contract_address(self, name: str) -> Address: + def get_contract_address(self, name: str, *args: str|Address|ChecksumAddress) -> Address: if name in self.PREDEPLOYED: return self.PREDEPLOYED[name] raise RuntimeError(f"Can't get address of {name} contract") diff --git a/python/src/skale_contracts/projects/skale_manager.py b/python/src/skale_contracts/projects/skale_manager.py index 9cf8840..0733df8 100644 --- a/python/src/skale_contracts/projects/skale_manager.py +++ b/python/src/skale_contracts/projects/skale_manager.py @@ -1,7 +1,7 @@ """Module connects skale-manager project to the SKALE contracts library""" from __future__ import annotations -from typing import cast, TYPE_CHECKING +from typing import TYPE_CHECKING from eth_utils.address import to_canonical_address from skale_contracts.instance import Instance, DEFAULT_GET_VERSION_FUNCTION @@ -9,7 +9,7 @@ if TYPE_CHECKING: - from eth_typing import Address + from eth_typing import Address, ChecksumAddress from web3.contract.contract import Contract SKALE_MANAGER_ABI = [ @@ -48,14 +48,11 @@ def __init__(self, project: Project, address: Address) -> None: 'TimeHelpersWithDebug': 'TimeHelpers' } - def get_contract_address(self, name: str) -> Address: + def get_contract_address(self, name: str, *args: str|Address|ChecksumAddress) -> Address: return to_canonical_address( self.contract_manager.functions.getContract(self._actual_name(name)).call() ) - def _get_version(self) -> str: - return cast(str, self.skale_manager.functions.version().call()) - def _actual_name(self, name: str) -> str: if name in self.custom_names: return self.custom_names[name]