From e5f167eb209fdfd63ef359e72fc40dd4b83f54ba Mon Sep 17 00:00:00 2001 From: Kieran Prasch Date: Sun, 24 May 2020 02:37:52 -0700 Subject: [PATCH] Introdice types module: reflect on-chain structs. --- nucypher/types.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 nucypher/types.py diff --git a/nucypher/types.py b/nucypher/types.py new file mode 100644 index 000000000..a3cccadb9 --- /dev/null +++ b/nucypher/types.py @@ -0,0 +1,97 @@ +""" + This file is part of nucypher. + + nucypher is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + nucypher is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with nucypher. If not, see . +""" + +from eth_typing.evm import ChecksumAddress +from typing import TypeVar, NewType, Tuple +from web3.types import Wei, Timestamp + +NuNits = NewType("NuNits", int) +Agent = TypeVar('Agent', bound='EthereumContractAgent') +Period = NewType('Period', int) +PeriodDelta = NewType('Period', int) + + +class ContractParams(Tuple): + pass + + +class ContractStruct(Tuple): + pass + + +class WorklockParameters(ContractParams): + token_supply: NuNits + start_bid_date: Timestamp + end_bid_date: Timestamp + end_cancellation_date: Timestamp + boosting_refund: int + staking_periods: int + min_allowed_bid: Wei + + +class StakingEscrowParameters(ContractParams): + seconds_per_period: int + minting_coefficient: int + lock_duration_coefficient_1: int + lock_duration_coefficient_2: int + maximum_rewarded_periods: int + first_phase_total_supply: NuNits + first_phase_max_issuance: NuNits + min_locked_periods: PeriodDelta + min_allowable_locked_tokens: NuNits + max_allowable_locked_tokens: NuNits + min_worker_periods: PeriodDelta + + +class SubStakeInfo(ContractStruct): + first_period: Period + last_period: Period + locked_value: NuNits + + +class RawSubStakeInfo(ContractStruct): + first_period: Period + last_period: Period + periods: int + locked_value: NuNits + + +class Downtime(ContractStruct): + start_period: Period + end_period: Period + + +class StakerFlags(ContractStruct): + wind_down_flag: bool + restake_flag: bool + measure_work_flag: bool + snapshot_flag: bool + + +class StakerInfo(ContractStruct): + value: NuNits + current_committed_period: Period + next_committed_period: Period + last_committed_period: Period + lock_restake_until_period: Period + completed_work: NuNits + worker_start_period: Period + worker: ChecksumAddress + flags: int + downtime: Tuple[Downtime] + substake_info: Tuple[RawSubStakeInfo] + history: Tuple[int]