def divisible_stakes(mock_testerchain, token_economics): nu = (token_economics.minimum_allowed_locked * 2) + 1 seconds_per_period = token_economics.seconds_per_period current_period = epoch_to_period(mock_testerchain.get_blocktime(), seconds_per_period=seconds_per_period) final_period = current_period + (token_economics.minimum_locked_periods * 3) divisible_stakes = [(current_period, final_period, nu)] return divisible_stakes
def available_balance(self) -> int: token_agent = ContractAgency.get_agent(NucypherTokenAgent, self.registry) staking_agent = ContractAgency.get_agent(StakingEscrowAgent, self.registry) overall_balance = token_agent.get_balance( self.principal_contract.address) seconds_per_period = staking_agent.contract.functions.secondsPerPeriod( ).call() current_period = staking_agent.get_current_period() end_lock_period = epoch_to_period( self.end_timestamp, seconds_per_period=seconds_per_period) available_balance = overall_balance if current_period <= end_lock_period: staked_tokens = staking_agent.get_locked_tokens( staker_address=self.principal_contract.address, periods=end_lock_period - current_period) if self.unvested_tokens > staked_tokens: # The staked amount is deducted from the locked amount available_balance -= self.unvested_tokens - staked_tokens return available_balance
def test_epoch_to_period(): timestamp = maya.now().epoch current_period = epoch_to_period(epoch=timestamp, seconds_per_period=SECONDS_PER_PERIOD) assert current_period == (timestamp // SECONDS_PER_PERIOD)