diff --git a/contracts/staking/contracts/src/Staking.sol b/contracts/staking/contracts/src/Staking.sol index 4a3e4863df..4def709daa 100644 --- a/contracts/staking/contracts/src/Staking.sol +++ b/contracts/staking/contracts/src/Staking.sol @@ -18,6 +18,7 @@ pragma solidity ^0.5.9; +import "./interfaces/IStaking.sol"; import "./core/MixinExchange.sol"; import "./core/MixinZrxVault.sol"; import "./core/MixinRewardVault.sol"; @@ -30,7 +31,7 @@ import "./core/MixinRewards.sol"; contract Staking is - IStakingEvents, + IStaking, MixinDeploymentConstants, MixinConstants, MixinStorage, diff --git a/contracts/staking/contracts/src/core/MixinExchange.sol b/contracts/staking/contracts/src/core/MixinExchange.sol index a63c7001c3..842e3dbb71 100644 --- a/contracts/staking/contracts/src/core/MixinExchange.sol +++ b/contracts/staking/contracts/src/core/MixinExchange.sol @@ -19,7 +19,6 @@ pragma solidity ^0.5.5; import "../interfaces/IStakingEvents.sol"; - import "../immutable/MixinConstants.sol"; import "../immutable/MixinStorage.sol"; @@ -30,6 +29,9 @@ contract MixinExchange is MixinStorage { + /// @dev This mixin contains logic for managing exchanges + /// + modifier onlyExchange() { require( isValidExchangeAddress(msg.sender), diff --git a/contracts/staking/contracts/src/core/MixinScheduler.sol b/contracts/staking/contracts/src/core/MixinScheduler.sol index 55aa88fff0..4e592d1308 100644 --- a/contracts/staking/contracts/src/core/MixinScheduler.sol +++ b/contracts/staking/contracts/src/core/MixinScheduler.sol @@ -18,6 +18,7 @@ pragma solidity ^0.5.5; +import "../core_interfaces/IMixinScheduler.sol"; import "../libs/LibSafeMath.sol"; import "../libs/LibSafeMath64.sol"; import "../immutable/MixinConstants.sol"; @@ -27,7 +28,8 @@ import "../interfaces/IStructs.sol"; contract MixinScheduler is MixinConstants, - MixinStorage + MixinStorage, + IMixinScheduler { using LibSafeMath for uint256; @@ -132,7 +134,7 @@ contract MixinScheduler is // validate that we can increment the current epoch require( - getCurrentEpochEndTimeInSeconds() <= currentBlockTimestamp, + getCurrentEpochEarliestEndTimeInSeconds() <= currentBlockTimestamp, "BLOCK_TIMESTAMP_TOO_LOW" ); diff --git a/contracts/staking/contracts/src/core_interfaces/IMixinScheduler.sol b/contracts/staking/contracts/src/core_interfaces/IMixinScheduler.sol new file mode 100644 index 0000000000..189aac423a --- /dev/null +++ b/contracts/staking/contracts/src/core_interfaces/IMixinScheduler.sol @@ -0,0 +1,85 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.5.5; + + +contract IMixinScheduler { + + /// @dev This mixin contains logic for time-based scheduling. + /// All processes in the system are segmented into time intervals, called epochs. + /// Epochs have a fixed minimum time period that is configured when this contract is deployed. + /// The current epoch only changes by calling this contract, which can be invoked by anyone. + /// Epochs serve as the basis for all other time intervals, which provides a more stable + /// and consistent scheduling metric than time. Timelocks, for example, are measured in epochs. + + /// @dev Returns the current epoch. + function getCurrentEpoch() + public + view + returns (uint64); + + /// @dev Returns the current epoch period, measured in seconds. + /// Epoch period = [startTimeInSeconds..endTimeInSeconds) + function getEpochPeriodInSeconds() + public + pure + returns (uint64); + + /// @dev Returns the start time in seconds of the current epoch. + /// Epoch period = [startTimeInSeconds..endTimeInSeconds) + function getCurrentEpochStartTimeInSeconds() + public + view + returns (uint64); + + /// @dev Returns the earliest end time in seconds of this epoch. + /// The next epoch can begin once this time is reached. + /// Epoch period = [startTimeInSeconds..endTimeInSeconds) + function getCurrentEpochEarliestEndTimeInSeconds() + public + view + returns (uint64); + + /// @dev Returns the current timelock period + function getCurrentTimelockPeriod() + public + view + returns (uint64); + + /// @dev Returns the length of a timelock period, measured in epochs. + /// Timelock period = [startEpoch..endEpoch) + function getTimelockPeriodInEpochs() + public + pure + returns (uint64); + + /// @dev Returns the epoch that the current timelock period started at. + /// Timelock period = [startEpoch..endEpoch) + function getCurrentTimelockPeriodStartEpoch() + public + view + returns (uint64); + + /// @dev Returns the epoch that the current timelock period will end. + /// Timelock period = [startEpoch..endEpoch) + function getCurrentTimelockPeriodEndEpoch() + public + view + returns (uint64); +} diff --git a/contracts/staking/contracts/src/interfaces/IStaking.sol b/contracts/staking/contracts/src/interfaces/IStaking.sol index 8cb1d4e26e..1162defda4 100644 --- a/contracts/staking/contracts/src/interfaces/IStaking.sol +++ b/contracts/staking/contracts/src/interfaces/IStaking.sol @@ -19,9 +19,62 @@ pragma solidity ^0.5.5; -interface IStaking -{ - function stake(uint256 amount) external returns (uint256); - function unstake(uint256 amount) external returns (uint256); - function getStakeBalance(address owner) external view returns (uint256); +/// THIS CONTRACT IS AUTO-GENERATED FROM INTERFACES IN `./core_interfaces` /// +contract IStaking { + + /// @dev Returns the current epoch. + function getCurrentEpoch() + public + view + returns (uint64); + + /// @dev Returns the current epoch period, measured in seconds. + /// Epoch period = [startTimeInSeconds..endTimeInSeconds) + function getEpochPeriodInSeconds() + public + pure + returns (uint64); + + /// @dev Returns the start time in seconds of the current epoch. + /// Epoch period = [startTimeInSeconds..endTimeInSeconds) + function getCurrentEpochStartTimeInSeconds() + public + view + returns (uint64); + + /// @dev Returns the earliest end time in seconds of this epoch. + /// The next epoch can begin once this time is reached. + /// Epoch period = [startTimeInSeconds..endTimeInSeconds) + function getCurrentEpochEarliestEndTimeInSeconds() + public + view + returns (uint64); + + /// @dev Returns the current timelock period + function getCurrentTimelockPeriod() + public + view + returns (uint64); + + /// @dev Returns the length of a timelock period, measured in epochs. + /// Timelock period = [startEpoch..endEpoch) + function getTimelockPeriodInEpochs() + public + pure + returns (uint64); + + /// @dev Returns the epoch that the current timelock period started at. + /// Timelock period = [startEpoch..endEpoch) + function getCurrentTimelockPeriodStartEpoch() + public + view + returns (uint64); + + /// @dev Returns the epoch that the current timelock period will end. + /// Timelock period = [startEpoch..endEpoch) + function getCurrentTimelockPeriodEndEpoch() + public + view + returns (uint64); + } diff --git a/contracts/staking/package.json b/contracts/staking/package.json index a11d73d90c..d5f2ef9ed3 100644 --- a/contracts/staking/package.json +++ b/contracts/staking/package.json @@ -73,11 +73,10 @@ }, "dependencies": { "@0x/base-contract": "^5.1.0", - "@0x/contracts-test-utils": "^3.1.6", - "@0x/contracts-utils": "3.1.1", + "@0x/contracts-utils": "3.1.6", "@0x/contracts-asset-proxy": "^2.1.1", "@0x/contracts-erc20": "^2.2.0", - "@0x/order-utils": "^7.2.0", + "@0x/order-utils": "^8.1.0", "@0x/types": "^2.2.2", "@0x/typescript-typings": "^4.2.2", "@0x/utils": "^4.3.1", diff --git a/contracts/staking/test/utils/staking_wrapper.ts b/contracts/staking/test/utils/staking_wrapper.ts index 3dae3c18f1..aafeb61b4a 100644 --- a/contracts/staking/test/utils/staking_wrapper.ts +++ b/contracts/staking/test/utils/staking_wrapper.ts @@ -458,10 +458,10 @@ export class StakingWrapper { const value = this.getStakingContract().getCurrentTimelockPeriodStartEpoch.getABIDecodedReturnData(returnData); return value; } - public async getCurrentEpochEndTimeInSecondsAsync(): Promise { - const calldata = this.getStakingContract().getCurrentEpochEndTimeInSeconds.getABIEncodedTransactionData(); + public async getCurrentEpochEarliestEndTimeInSecondsAsync(): Promise { + const calldata = this.getStakingContract().getCurrentEpochEarliestEndTimeInSeconds.getABIEncodedTransactionData(); const returnData = await this._callAsync(calldata); - const value = this.getStakingContract().getCurrentEpochEndTimeInSeconds.getABIDecodedReturnData(returnData); + const value = this.getStakingContract().getCurrentEpochEarliestEndTimeInSeconds.getABIDecodedReturnData(returnData); return value; } public async getCurrentTimelockPeriodEndEpochAsync(): Promise {