Skip to main content

Blockable

Blockable

Contract to manage time-related calculations based on block numbers, including eras and epochs.

Provides utility functions to determine current era, epoch, and eligibility for actions based on block progression. Eras and Epochs are 1-indexed.

BLOCKS_PRECISION

uint256 BLOCKS_PRECISION

Precision factor used in calculations.

halving

uint256 halving

Defines the number of eras that form one EPOCH cycle.

Used to determine epoch changes, linked to reward halving adjustments

constructor

constructor(uint256 _blocksPerEra, uint256 _halving) public

Initializes the Blockable contract.

Parameters

NameTypeDescription
_blocksPerErauint256The number of blocks in each era. Must be greater than 0.
_halvinguint256The number of eras that constitute one halving cycle/epoch.

canWithdraw

function canWithdraw(uint256 currentUserEra) public view returns (bool)

The user will be eligible for a withdrawal when their era is lower than the current contract era.

Checks if a user, based on their current era, is eligible for a withdraw.

Parameters

NameTypeDescription
currentUserErauint256The user's current era.

Return Values

NameTypeDescription
[0]boolbool True if currentUserEra is less than the contract's current era, false otherwise.

currentContractEra

function currentContractEra() public view returns (uint256)

Get the current contract era.

Calculates the current era of the contract based on block progression since deployment.

Return Values

NameTypeDescription
[0]uint256uint256 The current contract era.

currentEpoch

function currentEpoch() public view returns (uint256)

Epochs are 1-indexed. The calculation ensures that each epoch (including the first) comprises exactly halving eras, aligning with a conceptual 0-indexed era system for epoch grouping. For example, assuming halving = 12: Eras 1-12 (contract era numbers) -> Epoch 1 Eras 13-24 (contract era numbers) -> Epoch 2 And so on.

Calculates the current EPOCH of the contract.

Return Values

NameTypeDescription
[0]uint256uint256 Current contract EPOCH.

getEpochForEra

function getEpochForEra(uint256 era) public view returns (uint256)

Follows the same calculation logic as currentEpoch.

Calculates the epoch for a given era number.

Parameters

NameTypeDescription
erauint256The era number to determine the epoch for.

Return Values

NameTypeDescription
[0]uint256uint256 The epoch corresponding to the given era.

nextEraIn

function nextEraIn(uint256 targetEra) public view returns (int256)

Calculates the number of blocks remaining until the start of the next era.

Parameters

NameTypeDescription
targetErauint256The era for which to calculate the remaining blocks until its completion.

Return Values

NameTypeDescription
[0]int256int256 Number of blocks until the next era begins. Positive if targetEra is ongoing, negative if targetEra has passed, zero if the current block is the first block of the next era.

canWithdrawTimes

function canWithdrawTimes(uint256 currentUserEra) public view returns (uint256)

Returns 0 if currentUserEra has not yet ended. The result is scaled by 10**BLOCKS_PRECISION. For example, if 1.5 eras have passed, and BLOCKS_PRECISION is 5, it returns 150000.

Calculates a scaled value representing how many "blocksPerEra" periods have elapsed since a given currentUserEra ended.

Parameters

NameTypeDescription
currentUserErauint256The era that the user has completed.

Return Values

NameTypeDescription
[0]uint256uint256 Scaled representation of elapsed eras past currentUserEra.

_currentBlockNumber

function _currentBlockNumber() internal view returns (uint256)

Returns the current block number.

Return Values

NameTypeDescription
[0]uint256uint256 The current block.number.

canWithdrawModifier

modifier canWithdrawModifier(uint256 era)

Modifier to restrict a function's execution until the provided era has passed relative to the contract's current era.

Parameters

NameTypeDescription
erauint256The user's current recorded era.