adding epoch management
This commit is contained in:
@@ -18,15 +18,19 @@
|
||||
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
import "./core/MixinConstants.sol";
|
||||
import "./core/MixinStorage.sol";
|
||||
import "./core/MixinStake.sol";
|
||||
import "./core/MixinPools.sol";
|
||||
import "./core/MixinEpoch.sol";
|
||||
|
||||
|
||||
contract Staking is
|
||||
//IStaking,
|
||||
//IStakingEvents,
|
||||
MixinConstants,
|
||||
MixinStorage,
|
||||
MixinEpoch,
|
||||
MixinStake,
|
||||
MixinPools
|
||||
{
|
||||
@@ -218,6 +222,79 @@ contract Staking is
|
||||
return makerAddresses;
|
||||
}
|
||||
|
||||
///// EPOCHS /////
|
||||
|
||||
// @TODO - MixinAuthorizable
|
||||
function goToNextEpoch()
|
||||
external
|
||||
{
|
||||
_goToNextEpoch();
|
||||
}
|
||||
|
||||
function getEpochPeriodInSeconds()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getEpochPeriodInSeconds();
|
||||
}
|
||||
|
||||
function getTimelockPeriodInEpochs()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getTimelockPeriodInEpochs();
|
||||
}
|
||||
|
||||
function getCurrentEpochStartTimeInSeconds()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentEpochStartTimeInSeconds();
|
||||
}
|
||||
|
||||
function getCurrentTimelockPeriodStartEpoch()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentTimelockPeriodStartEpoch();
|
||||
}
|
||||
|
||||
function getCurrentEpochEndTimeInSeconds()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentEpochEndTimeInSeconds();
|
||||
}
|
||||
|
||||
function getCurrentTimelockPeriodEndEpoch()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentTimelockPeriodEndEpoch();
|
||||
}
|
||||
|
||||
function getCurrentEpoch()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentEpoch();
|
||||
}
|
||||
|
||||
function getCurrentTimelockPeriod()
|
||||
external
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentTimelockPeriod();
|
||||
}
|
||||
|
||||
///// SETTERS /////
|
||||
|
||||
function setZrxVault(address _zrxVault)
|
||||
|
||||
@@ -21,6 +21,8 @@ pragma solidity ^0.5.5;
|
||||
|
||||
contract MixinConstants {
|
||||
|
||||
uint64 constant MAX_UINT_64 = 2**64 - 1;
|
||||
|
||||
uint256 constant TOKEN_MULTIPLIER = 10**18;
|
||||
|
||||
bytes32 constant INITIAL_POOL_ID = 0x0000000000000000000000000000000100000000000000000000000000000000;
|
||||
@@ -29,5 +31,11 @@ contract MixinConstants {
|
||||
|
||||
address constant public NIL_ADDRESS = 0x0000000000000000000000000000000000000000;
|
||||
|
||||
|
||||
uint64 constant public INITIAL_EPOCH = 1;
|
||||
|
||||
uint64 constant public INITIAL_TIMELOCK_PERIOD = INITIAL_EPOCH;
|
||||
|
||||
uint64 constant public EPOCH_PERIOD_IN_SECONDS = 1; // @TODO SET FOR DEPLOYMENT
|
||||
|
||||
uint64 constant public TIMELOCK_PERIOD_IN_EPOCHS = 2; // @TODO SET FOR DEPLOYMENT
|
||||
}
|
||||
|
||||
@@ -20,14 +20,104 @@ pragma solidity ^0.5.5;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
|
||||
import "./MixinStorage.sol";
|
||||
import "../interfaces/IStructs.sol";
|
||||
|
||||
contract MixinEpoch {
|
||||
contract MixinEpoch is
|
||||
IStructs,
|
||||
MixinConstants,
|
||||
MixinStorage
|
||||
{
|
||||
|
||||
function _goToNextEpoch()
|
||||
internal
|
||||
{
|
||||
// get current timestamp
|
||||
require(
|
||||
block.timestamp <= MAX_UINT_64,
|
||||
"INVALID_BLOCK_TIMESTAMP"
|
||||
);
|
||||
uint64 currentBlockTimestamp = uint64(block.timestamp);
|
||||
|
||||
// get current epoch
|
||||
uint64 _currentEpoch = currentEpoch;
|
||||
require(
|
||||
_currentEpoch + _getEpochPeriodInSeconds() >= currentBlockTimestamp,
|
||||
"INVALID_BLOCK_TIMESTAMP"
|
||||
);
|
||||
|
||||
// incremment epoch
|
||||
currentEpoch = _currentEpoch + 1;
|
||||
currentEpochStartTimeInSeconds = currentBlockTimestamp;
|
||||
|
||||
// increment timelock period, if needed
|
||||
uint64 _currentTimelockPeriod = currentTimelockPeriod;
|
||||
if (_currentEpoch >= _currentTimelockPeriod + _getTimelockPeriodInEpochs()) {
|
||||
currentTimelockPeriod = _currentTimelockPeriod + 1;
|
||||
currentTimelockPeriodStartEpoch = currentEpoch;
|
||||
}
|
||||
}
|
||||
|
||||
function _getEpochPeriodInSeconds()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return EPOCH_PERIOD_IN_SECONDS;
|
||||
}
|
||||
|
||||
function _getTimelockPeriodInEpochs()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return TIMELOCK_PERIOD_IN_EPOCHS;
|
||||
}
|
||||
|
||||
function _getCurrentEpochStartTimeInSeconds()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return currentEpochStartTimeInSeconds;
|
||||
}
|
||||
|
||||
function _getCurrentTimelockPeriodStartEpoch()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return currentTimelockPeriodStartEpoch;
|
||||
}
|
||||
|
||||
function _getCurrentEpochEndTimeInSeconds()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentEpochStartTimeInSeconds() + _getEpochPeriodInSeconds();
|
||||
}
|
||||
|
||||
function _getCurrentTimelockPeriodEndEpoch()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return _getCurrentTimelockPeriodStartEpoch() + _getTimelockPeriodInEpochs();
|
||||
}
|
||||
|
||||
function _getCurrentEpoch()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
return currentEpoch;
|
||||
}
|
||||
|
||||
function _getCurrentTimelockPeriod()
|
||||
internal
|
||||
view
|
||||
returns (uint64)
|
||||
{
|
||||
// @TODO - IMPLEMENT
|
||||
return 7;
|
||||
return currentTimelockPeriod;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,18 @@ contract MixinStorage is
|
||||
// mapping from Pool Id to Addresses
|
||||
mapping (bytes32 => address[]) makerAddressesByPoolId;
|
||||
|
||||
// current epoch
|
||||
uint64 currentEpoch = INITIAL_EPOCH;
|
||||
|
||||
// current epoch start time
|
||||
uint64 currentEpochStartTimeInSeconds;
|
||||
|
||||
// current withdrawal period
|
||||
uint64 currentTimelockPeriod = INITIAL_TIMELOCK_PERIOD;
|
||||
|
||||
// current epoch start time
|
||||
uint64 currentTimelockPeriodStartEpoch = INITIAL_EPOCH;
|
||||
|
||||
// ZRX vault
|
||||
IVault zrxVault;
|
||||
|
||||
|
||||
@@ -231,6 +231,10 @@ export class StakingWrapper {
|
||||
const makerAddresses = this.getStakingContract().getMakerAddressesForPool.getABIDecodedReturnData(returndata);
|
||||
return makerAddresses;
|
||||
}
|
||||
///// EPOCHS /////
|
||||
//public async goToNextEpoch()
|
||||
|
||||
///// ZRX VAULT /////
|
||||
public async getZrxVaultBalance(holder: string): Promise<BigNumber> {
|
||||
const balance = await this.getZrxVaultContract().balanceOf.callAsync(holder);
|
||||
return balance;
|
||||
|
||||
Reference in New Issue
Block a user