Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type hints #557

Merged
merged 102 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
cb15591
Pass RPCEndpoint properly
DimaStebaev Apr 5, 2024
9b923a7
Add types to rotation history
DimaStebaev Apr 5, 2024
8e6951e
Add black lines
DimaStebaev Apr 5, 2024
fd7a2c1
Don't pass multiple values for argument
DimaStebaev Apr 5, 2024
932d3fd
Fix type hint for contract class
DimaStebaev Apr 5, 2024
bf737c0
Fix get all plans return type
DimaStebaev Apr 5, 2024
eda2583
Fix return types
DimaStebaev Apr 5, 2024
eb3b58c
Add optional
DimaStebaev Apr 5, 2024
8c4f64f
Fix return type
DimaStebaev Apr 5, 2024
990728e
Fix return types
DimaStebaev Apr 5, 2024
0b686e2
Do not access an uninitialized variable
DimaStebaev Apr 5, 2024
a2823cb
Update redis
DimaStebaev Apr 5, 2024
41b5d0b
Fix types errors
DimaStebaev Apr 5, 2024
fc1d170
Fix exception arguments types
DimaStebaev Apr 16, 2024
9eee659
Fix wait method
DimaStebaev Apr 16, 2024
a4823fa
Fix types in web3_utils
DimaStebaev Apr 16, 2024
71057d1
Fix types in web3_wallet
DimaStebaev Apr 16, 2024
a6bd0e8
Fix types in sgx_wallet
DimaStebaev Apr 16, 2024
effdd35
Fix types in ledger_wallet
DimaStebaev Apr 16, 2024
d3bc27c
Fix types in redis_wallet
DimaStebaev Apr 16, 2024
a50a230
Add type hints to allocator.py
DimaStebaev Apr 16, 2024
9a3f3e2
Add type hints to contracts privision
DimaStebaev Apr 17, 2024
5500425
Add type hints to exceptions
DimaStebaev Apr 17, 2024
9baa8d2
Add type hints to generator
DimaStebaev Apr 17, 2024
4f01911
Merge with develop
DimaStebaev Apr 17, 2024
aedc909
Add type hints to schain_options
DimaStebaev Apr 17, 2024
88d7b31
Add type hints to ports_allocation
DimaStebaev Apr 17, 2024
df2bcb3
Add type hints to node_info
DimaStebaev Apr 17, 2024
5e9765f
Add type hints to helper
DimaStebaev Apr 17, 2024
981ad93
Add type hints to generator
DimaStebaev Apr 17, 2024
90ec4ec
Add type hints to utils
DimaStebaev Apr 17, 2024
625521a
Remove circular imports
DimaStebaev Apr 17, 2024
ed0da48
Add type hints to common
DimaStebaev Apr 17, 2024
2dbf9c1
Add type hints to results
DimaStebaev Apr 17, 2024
deca0b8
Add type hints to web3_utils
DimaStebaev Apr 17, 2024
8607380
Add type hints to web3_utils
DimaStebaev Apr 18, 2024
869bf4b
Add type hints to web3_wallet
DimaStebaev Apr 19, 2024
3e83500
Add type hints to tools
DimaStebaev Apr 19, 2024
e1e0e51
Add type hints to sgx_wallet
DimaStebaev Apr 19, 2024
07aa67d
Add type hints to sgx_wallet
DimaStebaev Apr 19, 2024
2d17b1f
Add type hints to ledger_wallet
DimaStebaev Apr 19, 2024
2d0343a
Add type hints to tools
DimaStebaev Apr 19, 2024
1ba8109
Add type hints to tools
DimaStebaev Apr 19, 2024
4db9f1e
Add type hints to ledger_wallet
DimaStebaev Apr 19, 2024
b00b116
Add type hints to base_contract
DimaStebaev Apr 23, 2024
e6333a6
Add type hints to redis_wallet
DimaStebaev Apr 23, 2024
3905d78
Add type hints to contract_manager
DimaStebaev Apr 23, 2024
caa047e
Add type hints to wallets
DimaStebaev Apr 23, 2024
6889822
Add type hints to token
DimaStebaev Apr 23, 2024
b5fca6e
Add type hints to sync_manager
DimaStebaev Apr 23, 2024
3fe15a0
Add type hints to schains_internal
DimaStebaev Apr 23, 2024
84d8059
Add type hints to punisher
DimaStebaev Apr 23, 2024
48eabb1
Add type hints to nodes
DimaStebaev Apr 24, 2024
15a528c
Add type hints to node_rotation
DimaStebaev Apr 24, 2024
f166c13
Add type hints to skale manager
DimaStebaev Apr 24, 2024
82b1f81
Add type hints to key_storage
DimaStebaev Apr 24, 2024
e89a96a
Add type hints to dkg
DimaStebaev Apr 24, 2024
de0a751
Add type hints to constants_holder
DimaStebaev Apr 24, 2024
e5f6a6d
Add type hints to bountry_v2
DimaStebaev Apr 24, 2024
0e4f8c4
Add type hints to time_helpers_with_debug
DimaStebaev Apr 24, 2024
e296c9c
Add type hints to validator_service
DimaStebaev Apr 24, 2024
46d45cb
Add type hints to token_state
DimaStebaev Apr 25, 2024
4b67c0b
Add type hints to slashing_table
DimaStebaev Apr 25, 2024
82972f4
Add type hints to distributor
DimaStebaev Apr 25, 2024
0f5c605
Add type hints to distributor
DimaStebaev Apr 25, 2024
581d672
Add type hints to delegation_period_manager
DimaStebaev Apr 25, 2024
2601e4b
Add type hints to linker
DimaStebaev Apr 25, 2024
b3fb7ac
Add type hints to escrow
DimaStebaev Apr 26, 2024
d3551ef
Add type hints to skale_base
DimaStebaev Apr 26, 2024
0271575
Add SkaleManagerContract
DimaStebaev Apr 26, 2024
877c08f
Add ImaContract
DimaStebaev Apr 26, 2024
d1e77d2
Add type hints to skale_manager
DimaStebaev Apr 26, 2024
b06ef21
Add type hints to skale_ima
DimaStebaev Apr 26, 2024
0ec835d
Add type hints to skale_allocator
DimaStebaev Apr 29, 2024
4da622d
Add type hints to allocator
DimaStebaev Apr 29, 2024
3f173e0
Add type hints to schains
DimaStebaev Apr 30, 2024
0d339b4
Add type hints to account tools
DimaStebaev Apr 30, 2024
49583c0
Add type hints to fake_multisig_contract
DimaStebaev Apr 30, 2024
4469203
Add type hints to rotation_history
DimaStebaev May 2, 2024
6791264
Add type hints to ports_allocation
DimaStebaev May 2, 2024
471ed0f
Add type hints to ports_allocation
DimaStebaev May 2, 2024
3c6570f
Add type hints to generator
DimaStebaev May 2, 2024
804d0d5
Add type hints to contracts_provision
DimaStebaev May 2, 2024
a602983
Fix imports
DimaStebaev May 2, 2024
0452f86
Fix main_test
DimaStebaev May 3, 2024
7c8f23b
Fix dkg_test
DimaStebaev May 3, 2024
d77c607
Fix node_rotation_test
DimaStebaev May 3, 2024
24fc092
Remove unused variable
DimaStebaev May 7, 2024
867f91b
Merge branch 'develop' into types
DimaStebaev May 20, 2024
2ff9ba1
Update skale manager tests
DimaStebaev May 20, 2024
d75f9f5
Fix rotation history tests
DimaStebaev May 20, 2024
10b1762
Fix redis adapter test
DimaStebaev May 20, 2024
a8efa3f
Update SGX test
DimaStebaev May 20, 2024
038b99c
Fix bug with beneficiary plan
DimaStebaev May 20, 2024
52c91ce
Fix codacy
DimaStebaev May 20, 2024
f340829
Fix default argument
DimaStebaev May 21, 2024
2d641cb
Fix delegation test
DimaStebaev May 21, 2024
4916eda
Fix runtime type checking
DimaStebaev May 21, 2024
d3c6fbc
Improve exception description
DimaStebaev May 24, 2024
9487667
Remove unneeded comments
DimaStebaev May 24, 2024
04a831c
Move declaration
DimaStebaev May 24, 2024
f408e01
Fix indention
DimaStebaev May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
install_requires=[
"asyncio==3.4.3",
"pyyaml==6.0",
"redis==4.4.4",
"redis==5.0.3",
"sgx.py==0.9dev2",
"skale-contracts==1.0.1a5",
"typing-extensions==4.9.0",
Expand Down
2 changes: 2 additions & 0 deletions skale/contracts/allocator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

from skale.contracts.allocator.escrow import Escrow
from skale.contracts.allocator.allocator import Allocator

__all__ = ['Allocator', 'Escrow']

Check warning on line 6 in skale/contracts/allocator/__init__.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/__init__.py#L6

Added line #L6 was not covered by tests
163 changes: 103 additions & 60 deletions skale/contracts/allocator/allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@
# along with SKALE.py. If not, see <https://www.gnu.org/licenses/>.
""" SKALE Allocator Core Escrow methods """

from enum import IntEnum

from skale.contracts.base_contract import BaseContract, transaction_method
from skale.transactions.exceptions import ContractLogicError
from skale.transactions.result import TxRes
from typing import Any, Dict, List

Check warning on line 21 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L21

Added line #L21 was not covered by tests

from eth_typing import ChecksumAddress
from web3 import Web3
from web3.contract.contract import ContractFunction
from web3.exceptions import ContractLogicError
from web3.types import Wei

Check warning on line 27 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L23-L27

Added lines #L23 - L27 were not covered by tests

from skale.contracts.allocator_contract import AllocatorContract
from skale.contracts.base_contract import transaction_method
from skale.types.allocation import (

Check warning on line 31 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L29-L31

Added lines #L29 - L31 were not covered by tests
BeneficiaryStatus,
BeneficiaryPlan,
Plan,
PlanId,
dmytrotkk marked this conversation as resolved.
Show resolved Hide resolved
PlanWithId,
TimeUnit
)
from skale.utils.helper import format_fields


Expand All @@ -47,36 +60,25 @@
MAX_NUM_OF_BENEFICIARIES = 9999


class TimeUnit(IntEnum):
DAY = 0
MONTH = 1
YEAR = 2


class BeneficiaryStatus(IntEnum):
UNKNOWN = 0
CONFIRMED = 1
ACTIVE = 2
TERMINATED = 3


class Allocator(BaseContract):
def is_beneficiary_registered(self, beneficiary_address: str) -> bool:
class Allocator(AllocatorContract):
def is_beneficiary_registered(self, beneficiary_address: ChecksumAddress) -> bool:

Check warning on line 64 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L63-L64

Added lines #L63 - L64 were not covered by tests
"""Confirms whether the beneficiary is registered in a Plan.

:returns: Boolean value
:rtype: bool
"""
return self.contract.functions.isBeneficiaryRegistered(beneficiary_address).call()
return bool(self.contract.functions.isBeneficiaryRegistered(beneficiary_address).call())

Check warning on line 70 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L70

Added line #L70 was not covered by tests

def is_delegation_allowed(self, beneficiary_address: str) -> bool:
return self.contract.functions.isDelegationAllowed(beneficiary_address).call()
def is_delegation_allowed(self, beneficiary_address: ChecksumAddress) -> bool:
return bool(self.contract.functions.isDelegationAllowed(beneficiary_address).call())

Check warning on line 73 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L72-L73

Added lines #L72 - L73 were not covered by tests

def is_vesting_active(self, beneficiary_address: str) -> bool:
return self.contract.functions.isVestingActive(beneficiary_address).call()
def is_vesting_active(self, beneficiary_address: ChecksumAddress) -> bool:
return bool(self.contract.functions.isVestingActive(beneficiary_address).call())

Check warning on line 76 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L75-L76

Added lines #L75 - L76 were not covered by tests

def get_escrow_address(self, beneficiary_address: str) -> str:
return self.contract.functions.getEscrowAddress(beneficiary_address).call()
def get_escrow_address(self, beneficiary_address: ChecksumAddress) -> ChecksumAddress:
return Web3.to_checksum_address(

Check warning on line 79 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L78-L79

Added lines #L78 - L79 were not covered by tests
self.contract.functions.getEscrowAddress(beneficiary_address).call()
)

@transaction_method
def add_plan(
Expand All @@ -87,7 +89,7 @@
vesting_interval: int,
can_delegate: bool,
is_terminatable: bool
) -> TxRes:
) -> ContractFunction:
return self.contract.functions.addPlan(
vestingCliff=vesting_cliff,
totalVestingDuration=total_vesting_duration,
Expand All @@ -100,12 +102,12 @@
@transaction_method
def connect_beneficiary_to_plan(
self,
beneficiary_address: str,
beneficiary_address: ChecksumAddress,
plan_id: int,
start_month: int,
full_amount: int,
lockup_amount: int,
) -> TxRes:
) -> ContractFunction:
return self.contract.functions.connectBeneficiaryToPlan(
beneficiary=beneficiary_address,
planId=plan_id,
Expand All @@ -115,61 +117,102 @@
)

@transaction_method
def start_vesting(self, beneficiary_address: str) -> TxRes:
def start_vesting(self, beneficiary_address: ChecksumAddress) -> ContractFunction:

Check warning on line 120 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L120

Added line #L120 was not covered by tests
return self.contract.functions.startVesting(beneficiary_address)

@transaction_method
def stop_vesting(self, beneficiary_address: str) -> TxRes:
def stop_vesting(self, beneficiary_address: ChecksumAddress) -> ContractFunction:

Check warning on line 124 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L124

Added line #L124 was not covered by tests
return self.contract.functions.stopVesting(beneficiary_address)

@transaction_method
def grant_role(self, role: bytes, address: str) -> TxRes:
def grant_role(self, role: bytes, address: ChecksumAddress) -> ContractFunction:

Check warning on line 128 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L128

Added line #L128 was not covered by tests
return self.contract.functions.grantRole(role, address)

def vesting_manager_role(self) -> bytes:
return self.contract.functions.VESTING_MANAGER_ROLE().call()
return bytes(self.contract.functions.VESTING_MANAGER_ROLE().call())

Check warning on line 132 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L132

Added line #L132 was not covered by tests

def has_role(self, role: bytes, address: str) -> bool:
return self.contract.functions.hasRole(role, address).call()
def has_role(self, role: bytes, address: ChecksumAddress) -> bool:
return bool(self.contract.functions.hasRole(role, address).call())

Check warning on line 135 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L134-L135

Added lines #L134 - L135 were not covered by tests

def __get_beneficiary_plan_params_raw(self, beneficiary_address: str):
return self.contract.functions.getBeneficiaryPlanParams(beneficiary_address).call()
def __get_beneficiary_plan_params_raw(self, beneficiary_address: ChecksumAddress) -> List[Any]:
return list(self.contract.functions.getBeneficiaryPlanParams(beneficiary_address).call())

Check warning on line 138 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L137-L138

Added lines #L137 - L138 were not covered by tests

@format_fields(BENEFICIARY_FIELDS)
def get_beneficiary_plan_params_dict(self, beneficiary_address: str) -> dict:
def get_beneficiary_plan_params_dict(self, beneficiary_address: ChecksumAddress) -> List[Any]:

Check warning on line 141 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L141

Added line #L141 was not covered by tests
return self.__get_beneficiary_plan_params_raw(beneficiary_address)

def get_beneficiary_plan_params(self, beneficiary_address: str) -> dict:
def get_beneficiary_plan_params(self, beneficiary_address: ChecksumAddress) -> BeneficiaryPlan:

Check warning on line 144 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L144

Added line #L144 was not covered by tests
plan_params = self.get_beneficiary_plan_params_dict(beneficiary_address)
plan_params['statusName'] = BeneficiaryStatus(plan_params['status']).name
return plan_params

def __get_plan_raw(self, plan_id: int):
return self.contract.functions.getPlan(plan_id).call()
if plan_params is None:
raise ValueError('Plan for ', beneficiary_address, ' is missing')
if isinstance(plan_params, list):
return self._to_beneficiary_plan({

Check warning on line 149 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L146-L149

Added lines #L146 - L149 were not covered by tests
**plan_params[0],
'statusName': BeneficiaryStatus(plan_params[0]['status']).name
})
if isinstance(plan_params, dict):
return self._to_beneficiary_plan({

Check warning on line 154 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L153-L154

Added lines #L153 - L154 were not covered by tests
**plan_params,
'statusName': BeneficiaryStatus(plan_params.get('status', 0)).name
})
raise TypeError(f'Internal error on getting plan params for ${beneficiary_address}')

Check warning on line 158 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L158

Added line #L158 was not covered by tests

def __get_plan_raw(self, plan_id: PlanId) -> List[Any]:
return list(self.contract.functions.getPlan(plan_id).call())

Check warning on line 161 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L160-L161

Added lines #L160 - L161 were not covered by tests

@format_fields(PLAN_FIELDS)
def get_plan(self, plan_id: int) -> dict:
def get_untyped_plan(self, plan_id: PlanId) -> List[Any]:

Check warning on line 164 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L164

Added line #L164 was not covered by tests
return self.__get_plan_raw(plan_id)

def get_all_plans(self) -> dict:
def get_plan(self, plan_id: PlanId) -> Plan:
untyped_plan = self.get_untyped_plan(plan_id)
if untyped_plan is None:
raise ValueError('Plan ', plan_id, ' is missing')
if isinstance(untyped_plan, list):
return self._to_plan(untyped_plan[0])
if isinstance(untyped_plan, dict):
return self._to_plan(untyped_plan)
raise TypeError(plan_id)

Check warning on line 175 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L167-L175

Added lines #L167 - L175 were not covered by tests

def get_all_plans(self) -> List[PlanWithId]:

Check warning on line 177 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L177

Added line #L177 was not covered by tests
plans = []
for i in range(1, MAX_NUM_OF_PLANS):
try:
plan = self.get_plan(i)
plan['planId'] = i
plan_id = PlanId(i)
plan = PlanWithId({**self.get_plan(plan_id), 'planId': plan_id})

Check warning on line 182 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L181-L182

Added lines #L181 - L182 were not covered by tests
plans.append(plan)
except (ContractLogicError, ValueError):
break
return plans

def calculate_vested_amount(self, address: str) -> int:
return self.contract.functions.calculateVestedAmount(address).call()

def get_finish_vesting_time(self, address: str) -> int:
return self.contract.functions.getFinishVestingTime(address).call()

def get_lockup_period_end_timestamp(self, address: str) -> int:
return self.contract.functions.getLockupPeriodEndTimestamp(address).call()

def get_time_of_next_vest(self, address: str) -> int:
return self.contract.functions.getTimeOfNextVest(address).call()
def calculate_vested_amount(self, address: ChecksumAddress) -> Wei:
return Wei(self.contract.functions.calculateVestedAmount(address).call())

Check warning on line 189 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L188-L189

Added lines #L188 - L189 were not covered by tests

def get_finish_vesting_time(self, address: ChecksumAddress) -> int:
return int(self.contract.functions.getFinishVestingTime(address).call())

Check warning on line 192 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L191-L192

Added lines #L191 - L192 were not covered by tests

def get_lockup_period_end_timestamp(self, address: ChecksumAddress) -> int:
return int(self.contract.functions.getLockupPeriodEndTimestamp(address).call())

Check warning on line 195 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L194-L195

Added lines #L194 - L195 were not covered by tests

def get_time_of_next_vest(self, address: ChecksumAddress) -> int:
return int(self.contract.functions.getTimeOfNextVest(address).call())

Check warning on line 198 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L197-L198

Added lines #L197 - L198 were not covered by tests

def _to_plan(self, untyped_plan: Dict[str, Any]) -> Plan:
return Plan({

Check warning on line 201 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L200-L201

Added lines #L200 - L201 were not covered by tests
'totalVestingDuration': int(untyped_plan['totalVestingDuration']),
'vestingCliff': int(untyped_plan['vestingCliff']),
'vestingIntervalTimeUnit': TimeUnit(untyped_plan['vestingIntervalTimeUnit']),
'vestingInterval': int(untyped_plan['vestingInterval']),
'isDelegationAllowed': bool(untyped_plan['isDelegationAllowed']),
'isTerminatable': bool(untyped_plan['isTerminatable'])
})

def _to_beneficiary_plan(self, untyped_beneficiary_plan: Dict[str, Any]) -> BeneficiaryPlan:
return BeneficiaryPlan({

Check warning on line 211 in skale/contracts/allocator/allocator.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/allocator.py#L210-L211

Added lines #L210 - L211 were not covered by tests
'status': BeneficiaryStatus(untyped_beneficiary_plan['status']),
'statusName': str(untyped_beneficiary_plan['statusName']),
'planId': PlanId(untyped_beneficiary_plan['planId']),
'startMonth': int(untyped_beneficiary_plan['startMonth']),
'fullAmount': Wei(untyped_beneficiary_plan['fullAmount']),
'amountAfterLockup': Wei(untyped_beneficiary_plan['amountAfterLockup'])
})
49 changes: 36 additions & 13 deletions skale/contracts/allocator/escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,49 @@
# along with SKALE.py. If not, see <https://www.gnu.org/licenses/>.
""" SKALE Allocator Core Escrow methods """

from __future__ import annotations

Check warning on line 21 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L21

Added line #L21 was not covered by tests
import functools
from typing import Any, Callable, TYPE_CHECKING

Check warning on line 23 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L23

Added line #L23 was not covered by tests

from skale.contracts.base_contract import BaseContract, transaction_method
from eth_typing import ChecksumAddress
from web3.contract.contract import ContractFunction
from web3.types import Wei

Check warning on line 27 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L25-L27

Added lines #L25 - L27 were not covered by tests

from skale.contracts.allocator_contract import AllocatorContract
from skale.contracts.base_contract import transaction_method

Check warning on line 30 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L29-L30

Added lines #L29 - L30 were not covered by tests
from skale.transactions.result import TxRes
from skale.types.delegation import DelegationId
from skale.types.validator import ValidatorId

Check warning on line 33 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L32-L33

Added lines #L32 - L33 were not covered by tests

if TYPE_CHECKING:
from skale.contracts.allocator.allocator import Allocator

Check warning on line 36 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L35-L36

Added lines #L35 - L36 were not covered by tests


def beneficiary_escrow(transaction):
def beneficiary_escrow(transaction: Callable[..., TxRes]) -> Callable[..., TxRes]:

Check warning on line 39 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L39

Added line #L39 was not covered by tests
@functools.wraps(transaction)
def wrapper(self, *args, beneficiary_address, **kwargs):
def wrapper(

Check warning on line 41 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L41

Added line #L41 was not covered by tests
self: AllocatorContract,
*args: Any,
beneficiary_address: ChecksumAddress,
**kwargs: Any
) -> TxRes:
self.contract = self.skale.instance.get_contract('Escrow', beneficiary_address)
return transaction(self, *args, **kwargs)
return wrapper


class Escrow(BaseContract):
class Escrow(AllocatorContract):

Check warning on line 52 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L52

Added line #L52 was not covered by tests
@property
@functools.lru_cache()
def allocator(self):
def allocator(self) -> Allocator:

Check warning on line 55 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L55

Added line #L55 was not covered by tests
return self.skale.allocator

def init_contract(self, skale, address, abi) -> None:
self.contract = None
def init_contract(self, *args: Any) -> None:
self.contract = self.allocator.contract

Check warning on line 59 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L58-L59

Added lines #L58 - L59 were not covered by tests

@beneficiary_escrow
@transaction_method
def retrieve(self) -> TxRes:
def retrieve(self) -> ContractFunction:

Check warning on line 63 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L63

Added line #L63 was not covered by tests
"""Allows Holder to retrieve vested tokens from the Escrow contract

:returns: Transaction results
Expand All @@ -53,7 +70,7 @@

@beneficiary_escrow
@transaction_method
def retrieve_after_termination(self, address: str) -> TxRes:
def retrieve_after_termination(self, address: ChecksumAddress) -> ContractFunction:

Check warning on line 73 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L73

Added line #L73 was not covered by tests
"""Allows Core Owner to retrieve remaining transferrable escrow balance
after Core holder termination. Slashed tokens are non-transferable

Expand All @@ -64,7 +81,13 @@

@beneficiary_escrow
@transaction_method
def delegate(self, validator_id: int, amount: int, delegation_period: int, info: str) -> TxRes:
def delegate(

Check warning on line 84 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L84

Added line #L84 was not covered by tests
self,
validator_id: ValidatorId,
amount: Wei,
delegation_period: int,
info: str
) -> ContractFunction:
"""Allows Core holder to propose a delegation to a validator

:param validator_id: ID of the validator to delegate tokens
Expand All @@ -82,7 +105,7 @@

@beneficiary_escrow
@transaction_method
def request_undelegation(self, delegation_id: int) -> TxRes:
def request_undelegation(self, delegation_id: DelegationId) -> ContractFunction:

Check warning on line 108 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L108

Added line #L108 was not covered by tests
"""Allows Holder and Owner to request undelegation. Only Owner can
request undelegation after Core holder is deactivated (upon holder termination)

Expand All @@ -95,7 +118,7 @@

@beneficiary_escrow
@transaction_method
def withdraw_bounty(self, validator_id: int, to: str) -> TxRes:
def withdraw_bounty(self, validator_id: ValidatorId, to: ChecksumAddress) -> ContractFunction:

Check warning on line 121 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L121

Added line #L121 was not covered by tests
"""Allows Beneficiary and Vesting Owner to withdraw earned bounty.

:param validator_id: ID of the validator
Expand All @@ -109,7 +132,7 @@

@beneficiary_escrow
@transaction_method
def cancel_pending_delegation(self, delegation_id: int) -> TxRes:
def cancel_pending_delegation(self, delegation_id: DelegationId) -> ContractFunction:

Check warning on line 135 in skale/contracts/allocator/escrow.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator/escrow.py#L135

Added line #L135 was not covered by tests
"""Cancel pending delegation request.

:param delegation_id: ID of the delegation to cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with SKALE.py. If not, see <https://www.gnu.org/licenses/>.
from skale.contracts.base_contract import BaseContract
from skale.skale_allocator import SkaleAllocator

Check warning on line 20 in skale/contracts/allocator_contract.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator_contract.py#L19-L20

Added lines #L19 - L20 were not covered by tests

from enum import Enum


class DelegationStatus(Enum):
PROPOSED = 0
ACCEPTED = 1
CANCELED = 2
REJECTED = 3
DELEGATED = 4
UNDELEGATION_REQUESTED = 5
COMPLETED = 6
class AllocatorContract(BaseContract[SkaleAllocator]):
pass

Check warning on line 24 in skale/contracts/allocator_contract.py

View check run for this annotation

Codecov / codecov/patch

skale/contracts/allocator_contract.py#L23-L24

Added lines #L23 - L24 were not covered by tests
Loading
Loading