From cbf068fd73089ce6d78dd72b323b064ac9234faf Mon Sep 17 00:00:00 2001 From: Oleksandr Salamatov Date: Thu, 11 Apr 2024 14:49:17 +0000 Subject: [PATCH] Add context-contract project --- .../src/skale_contracts/projects/__init__.py | 4 +- .../projects/context_contract.py | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 python/src/skale_contracts/projects/context_contract.py diff --git a/python/src/skale_contracts/projects/__init__.py b/python/src/skale_contracts/projects/__init__.py index cc88ec4..62f5ca1 100644 --- a/python/src/skale_contracts/projects/__init__.py +++ b/python/src/skale_contracts/projects/__init__.py @@ -1,8 +1,10 @@ """Supported projects""" +from .context_contract import ContextProject as Context from .ima import \ MainnetImaProject as MainnetIma, \ SchainImaProject as SchainIma from .skale_manager import SkaleManagerProject as SkaleManager from .skale_allocator import SkaleAllocatorProject as SkaleAllocator -__all__ = ['MainnetIma', 'SchainIma', 'SkaleAllocator', 'SkaleManager'] +__all__ = ['Context', 'MainnetIma', 'SchainIma', 'SkaleAllocator', + 'SkaleManager'] diff --git a/python/src/skale_contracts/projects/context_contract.py b/python/src/skale_contracts/projects/context_contract.py new file mode 100644 index 0000000..dc92818 --- /dev/null +++ b/python/src/skale_contracts/projects/context_contract.py @@ -0,0 +1,63 @@ +"""Module connects context-contract project to the SKALE contracts library""" +from __future__ import annotations +from typing import TYPE_CHECKING +from eth_utils.address import to_canonical_address + +from skale_contracts.constants import PREDEPLOYED_ALIAS +from skale_contracts.instance import Instance +from skale_contracts.project import Project + +if TYPE_CHECKING: + from eth_typing import Address, ChecksumAddress + + +class ContextInstance(Instance): + """Represents instance of context-contract""" + + INITIAL_VERSION = '1.0.0-develop.5' + + PREDEPLOYED: dict[str, Address] = { + name: to_canonical_address(address) for name, address in { + 'ContextContract': + '0xD2001000000000000000000000000000000000D2' + }.items()} + + 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") + + def _get_version(self) -> str: + try: + return super()._get_version() + except ValueError: + return self.INITIAL_VERSION + + +class ContextProject(Project): + """Represents context-contract project""" + + @staticmethod + def name() -> str: + return 'ContextContract' + + @property + def github_repo(self) -> str: + return 'https://github.com/skalenetwork/context-contract/' + + def create_instance(self, address: Address) -> Instance: + return ContextInstance(self, address) + + def get_instance(self, alias_or_address: str) -> Instance: + if alias_or_address == PREDEPLOYED_ALIAS: + return self.create_instance( + ContextInstance.PREDEPLOYED['ContextContract'] + ) + return super().get_instance(alias_or_address) + + def get_abi_filename(self, version: str) -> str: + return f'context-{version}-abi.json'