From 1ecced7e6f28150828e1d16c71ae5e0aead56252 Mon Sep 17 00:00:00 2001 From: Oleksandr Salamatov Date: Mon, 19 Aug 2024 16:06:45 +0000 Subject: [PATCH] Added config controller support to python library --- .../src/skale_contracts/projects/__init__.py | 5 +- .../projects/config_controller.py | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 python/src/skale_contracts/projects/config_controller.py diff --git a/python/src/skale_contracts/projects/__init__.py b/python/src/skale_contracts/projects/__init__.py index eb769e3..14b2b0f 100644 --- a/python/src/skale_contracts/projects/__init__.py +++ b/python/src/skale_contracts/projects/__init__.py @@ -1,4 +1,5 @@ """Supported projects""" +from .config_controller import ConfigControllerProject as ConfigController from .context import ContextProject as Context from .paymaster import PaymasterProject as Paymaster from .ima import \ @@ -7,5 +8,5 @@ from .skale_manager import SkaleManagerProject as SkaleManager from .skale_allocator import SkaleAllocatorProject as SkaleAllocator -__all__ = ['Context', 'MainnetIma', 'Paymaster', 'SchainIma', - 'SkaleAllocator', 'SkaleManager'] +__all__ = ['ConfigController', 'Context', 'MainnetIma', 'Paymaster', + 'SchainIma', 'SkaleAllocator', 'SkaleManager'] diff --git a/python/src/skale_contracts/projects/config_controller.py b/python/src/skale_contracts/projects/config_controller.py new file mode 100644 index 0000000..c041d9d --- /dev/null +++ b/python/src/skale_contracts/projects/config_controller.py @@ -0,0 +1,56 @@ +"""Module connects config-controller 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 ConfigControllerInstance(Instance): + """Represents instance of config-controller""" + + PREDEPLOYED: dict[str, Address] = { + name: to_canonical_address(address) for name, address in { + 'ConfigController': + '0xD2002000000000000000000000000000000000d2' + }.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") + + +class ConfigControllerProject(Project): + """Represents config-controller project""" + + @staticmethod + def name() -> str: + return 'config-controller' + + def get_instance(self, alias_or_address: str) -> Instance: + if alias_or_address == PREDEPLOYED_ALIAS: + return self.create_instance( + ConfigControllerInstance.PREDEPLOYED['ConfigController'] + ) + return super().get_instance(alias_or_address) + + @property + def github_repo(self) -> str: + return 'https://github.com/skalenetwork/config-controller/' + + def create_instance(self, address: Address) -> Instance: + return ConfigControllerInstance(self, address) + + def get_abi_filename(self, version: str) -> str: + return f'config-controller-{version}-abi.json'