Skip to content

Commit

Permalink
Merge pull request #78 from skalenetwork/77-add-etherbase-support-to-…
Browse files Browse the repository at this point in the history
…python-library

Add etherbase support to python library
  • Loading branch information
OleksanderSalamatov authored Aug 20, 2024
2 parents 19365b7 + 7448efc commit 0737bf4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/src/skale_contracts/projects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Supported projects"""
from .config_controller import ConfigControllerProject as ConfigController
from .context import ContextProject as Context
from .etherbase import EtherbaseProject as Etherbase
from .paymaster import PaymasterProject as Paymaster
from .ima import \
MainnetImaProject as MainnetIma, \
SchainImaProject as SchainIma
from .skale_manager import SkaleManagerProject as SkaleManager
from .skale_allocator import SkaleAllocatorProject as SkaleAllocator

__all__ = ['ConfigController', 'Context', 'MainnetIma', 'Paymaster',
'SchainIma', 'SkaleAllocator', 'SkaleManager']
__all__ = ['ConfigController', 'Context', 'Etherbase', 'MainnetIma',
'Paymaster', 'SchainIma', 'SkaleAllocator', 'SkaleManager']
56 changes: 56 additions & 0 deletions python/src/skale_contracts/projects/etherbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Module connects etherbase 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 EtherbaseInstance(Instance):
"""Represents instance of etherbase"""

PREDEPLOYED: dict[str, Address] = {
name: to_canonical_address(address) for name, address in {
'Etherbase':
'0xd2bA3e0000000000000000000000000000000000'
}.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 EtherbaseProject(Project):
"""Represents etherbase project"""

@staticmethod
def name() -> str:
return 'etherbase'

def get_instance(self, alias_or_address: str) -> Instance:
if alias_or_address == PREDEPLOYED_ALIAS:
return self.create_instance(
EtherbaseInstance.PREDEPLOYED['Etherbase']
)
return super().get_instance(alias_or_address)

@property
def github_repo(self) -> str:
return 'https://github.com/skalenetwork/etherbase/'

def create_instance(self, address: Address) -> Instance:
return EtherbaseInstance(self, address)

def get_abi_filename(self, version: str) -> str:
return f'etherbase-{version}-abi.json'

0 comments on commit 0737bf4

Please sign in to comment.