From dd166538d6e5d37fe728a2cf9bd3c1a86ef4c782 Mon Sep 17 00:00:00 2001 From: Oleksandr Salamatov Date: Tue, 20 Aug 2024 15:04:42 +0000 Subject: [PATCH] Add marionette support to python library --- .../src/skale_contracts/projects/__init__.py | 6 +- .../skale_contracts/projects/marionette.py | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 python/src/skale_contracts/projects/marionette.py diff --git a/python/src/skale_contracts/projects/__init__.py b/python/src/skale_contracts/projects/__init__.py index 4a75eec..d8df486 100644 --- a/python/src/skale_contracts/projects/__init__.py +++ b/python/src/skale_contracts/projects/__init__.py @@ -2,6 +2,7 @@ from .config_controller import ConfigControllerProject as ConfigController from .context import ContextProject as Context from .etherbase import EtherbaseProject as Etherbase +from .marionette import MarionetteProject as Marionette from .paymaster import PaymasterProject as Paymaster from .ima import \ MainnetImaProject as MainnetIma, \ @@ -9,5 +10,6 @@ from .skale_manager import SkaleManagerProject as SkaleManager from .skale_allocator import SkaleAllocatorProject as SkaleAllocator -__all__ = ['ConfigController', 'Context', 'Etherbase', 'MainnetIma', - 'Paymaster', 'SchainIma', 'SkaleAllocator', 'SkaleManager'] +__all__ = ['ConfigController', 'Context', 'Etherbase', 'Marionette', + 'MainnetIma', 'Paymaster', 'SchainIma', 'SkaleAllocator', + 'SkaleManager'] diff --git a/python/src/skale_contracts/projects/marionette.py b/python/src/skale_contracts/projects/marionette.py new file mode 100644 index 0000000..fa5fc97 --- /dev/null +++ b/python/src/skale_contracts/projects/marionette.py @@ -0,0 +1,56 @@ +"""Module connects marionette 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 MarionetteInstance(Instance): + """Represents instance of marionette""" + + PREDEPLOYED: dict[str, Address] = { + name: to_canonical_address(address) for name, address in { + 'Marionette': + '0xD2c0DeFACe000000000000000000000000000000' + }.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 MarionetteProject(Project): + """Represents marionette project""" + + @staticmethod + def name() -> str: + return 'marionette' + + def get_instance(self, alias_or_address: str) -> Instance: + if alias_or_address == PREDEPLOYED_ALIAS: + return self.create_instance( + MarionetteInstance.PREDEPLOYED['Marionette'] + ) + return super().get_instance(alias_or_address) + + @property + def github_repo(self) -> str: + return 'https://github.com/skalenetwork/marionette/' + + def create_instance(self, address: Address) -> Instance: + return MarionetteInstance(self, address) + + def get_abi_filename(self, version: str) -> str: + return f'marionette-{version}-abi.json'