Skip to content

Commit

Permalink
Add skale-allocator project
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Apr 2, 2024
1 parent a2b0ae3 commit 29a4844
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
16 changes: 10 additions & 6 deletions python/src/skale_contracts/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())
3 changes: 3 additions & 0 deletions python/src/skale_contracts/project_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
3 changes: 2 additions & 1 deletion python/src/skale_contracts/projects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
11 changes: 4 additions & 7 deletions python/src/skale_contracts/projects/ima.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +12,7 @@


if TYPE_CHECKING:
from eth_typing import Address, ChecksumAddress
from web3.contract.contract import Contract

MESSAGE_PROXY_ABI = [
Expand All @@ -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"""
Expand All @@ -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':
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 3 additions & 6 deletions python/src/skale_contracts/projects/skale_manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""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
from skale_contracts.project import Project


if TYPE_CHECKING:
from eth_typing import Address
from eth_typing import Address, ChecksumAddress
from web3.contract.contract import Contract

SKALE_MANAGER_ABI = [
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 29a4844

Please sign in to comment.