Track state of read-only mode in stakingProxy
This commit is contained in:
		@@ -20,6 +20,7 @@ pragma solidity ^0.5.9;
 | 
			
		||||
pragma experimental ABIEncoderV2;
 | 
			
		||||
 | 
			
		||||
import "./libs/LibProxy.sol";
 | 
			
		||||
import "./libs/LibSafeDowncast.sol";
 | 
			
		||||
import "./immutable/MixinStorage.sol";
 | 
			
		||||
import "./interfaces/IStorageInit.sol";
 | 
			
		||||
import "./interfaces/IStakingProxy.sol";
 | 
			
		||||
@@ -30,6 +31,7 @@ contract StakingProxy is
 | 
			
		||||
    MixinStorage
 | 
			
		||||
{
 | 
			
		||||
    using LibProxy for address;
 | 
			
		||||
    using LibSafeDowncast for uint256;
 | 
			
		||||
 | 
			
		||||
    /// @dev Constructor.
 | 
			
		||||
    /// @param _stakingContract Staking contract to delegate calls to.
 | 
			
		||||
@@ -86,16 +88,25 @@ contract StakingProxy is
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @dev Set read-only mode (state cannot be changed).
 | 
			
		||||
    function setReadOnlyMode(bool readOnlyMode)
 | 
			
		||||
    function setReadOnlyMode(bool shouldSetReadOnlyMode)
 | 
			
		||||
        external
 | 
			
		||||
        onlyAuthorized
 | 
			
		||||
    {
 | 
			
		||||
        if (readOnlyMode) {
 | 
			
		||||
        uint96 timestamp = block.timestamp.downcastToUint96();
 | 
			
		||||
        if (shouldSetReadOnlyMode) {
 | 
			
		||||
            stakingContract = readOnlyProxy;
 | 
			
		||||
            readOnlyState = IStructs.ReadOnlyState({
 | 
			
		||||
                isReadOnlyModeSet: true,
 | 
			
		||||
                lastSetTimestamp: timestamp
 | 
			
		||||
            });
 | 
			
		||||
        } else {
 | 
			
		||||
            stakingContract = readOnlyProxyCallee;
 | 
			
		||||
            readOnlyState.isReadOnlyModeSet = false;
 | 
			
		||||
        }
 | 
			
		||||
        emit ReadOnlyModeSet(readOnlyMode);
 | 
			
		||||
        emit ReadOnlyModeSet(
 | 
			
		||||
            shouldSetReadOnlyMode,
 | 
			
		||||
            timestamp
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @dev Batch executes a series of calls to the staking contract.
 | 
			
		||||
@@ -108,9 +119,9 @@ contract StakingProxy is
 | 
			
		||||
        // Initialize commonly used variables.
 | 
			
		||||
        bool success;
 | 
			
		||||
        bytes memory returnData;
 | 
			
		||||
        batchReturnData = new bytes[](data.length);
 | 
			
		||||
        address staking = stakingContract;
 | 
			
		||||
        uint256 dataLength = data.length;
 | 
			
		||||
        batchReturnData = new bytes[](dataLength);
 | 
			
		||||
        address staking = stakingContract;
 | 
			
		||||
 | 
			
		||||
        // Ensure that a staking contract has been attached to the proxy.
 | 
			
		||||
        if (staking == address(0)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -105,6 +105,7 @@ contract ZrxVault is
 | 
			
		||||
    function enterCatastrophicFailure()
 | 
			
		||||
        external
 | 
			
		||||
        onlyAuthorized
 | 
			
		||||
        onlyNotInCatastrophicFailure
 | 
			
		||||
    {
 | 
			
		||||
        isInCatastrophicFailure = true;
 | 
			
		||||
        emit InCatastrophicFailureMode(msg.sender);
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,10 @@ contract MixinStorage is
 | 
			
		||||
    // address for read-only proxy to call
 | 
			
		||||
    address public readOnlyProxyCallee;
 | 
			
		||||
 | 
			
		||||
    // mapping from StakeStatus to gloabl stored balance
 | 
			
		||||
    // state of read-only mode in stakingProxy
 | 
			
		||||
    IStructs.ReadOnlyState public readOnlyState;
 | 
			
		||||
 | 
			
		||||
    // mapping from StakeStatus to global stored balance
 | 
			
		||||
    // (access using _loadSyncedBalance or _loadUnsyncedBalance)
 | 
			
		||||
    // NOTE: only Status.DELEGATED is used to access this mapping, but this format
 | 
			
		||||
    // is used for extensibility
 | 
			
		||||
 
 | 
			
		||||
@@ -17,9 +17,12 @@
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
pragma experimental ABIEncoderV2;
 | 
			
		||||
 | 
			
		||||
import "./IStructs.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
interface IStakingProxy /* is IStaking */
 | 
			
		||||
contract IStakingProxy /* is IStaking */
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /// @dev Emitted by StakingProxy when a staking contract is attached.
 | 
			
		||||
@@ -33,7 +36,8 @@ interface IStakingProxy /* is IStaking */
 | 
			
		||||
 | 
			
		||||
    /// @dev Emitted by StakingProxy when read-only mode is set.
 | 
			
		||||
    event ReadOnlyModeSet(
 | 
			
		||||
        bool readOnlyMode
 | 
			
		||||
        bool readOnlyMode,
 | 
			
		||||
        uint96 timestamp
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    /// @dev Delegates calls to the staking contract, if it is set.
 | 
			
		||||
@@ -52,4 +56,10 @@ interface IStakingProxy /* is IStaking */
 | 
			
		||||
    /// Note that this is callable only by an authorized address.
 | 
			
		||||
    function detachStakingContract()
 | 
			
		||||
        external;
 | 
			
		||||
 | 
			
		||||
    /// @dev Gets state of stakingProxy read-only mode.
 | 
			
		||||
    function readOnlyState()
 | 
			
		||||
        external
 | 
			
		||||
        view
 | 
			
		||||
        returns (IStructs.ReadOnlyState memory);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,14 @@ pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
interface IStructs {
 | 
			
		||||
 | 
			
		||||
    /// @dev State of stakingProxy read-only mode.
 | 
			
		||||
    /// @param isReadOnlyModeSet True if in read-only mode.
 | 
			
		||||
    /// @param lastSetTimestamp Timestamp at which read-only mode was last set.
 | 
			
		||||
    struct ReadOnlyState {
 | 
			
		||||
        bool isReadOnlyModeSet;
 | 
			
		||||
        uint96 lastSetTimestamp;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// @dev Status for a pool that actively traded during the current epoch.
 | 
			
		||||
    /// (see MixinExchangeFees).
 | 
			
		||||
    /// @param feesCollected Fees collected in ETH by this pool.
 | 
			
		||||
 
 | 
			
		||||
@@ -118,6 +118,14 @@ contract TestStorageLayoutAndConstants is
 | 
			
		||||
            )
 | 
			
		||||
            slot := add(slot, 0x1)
 | 
			
		||||
 | 
			
		||||
            assertSlotAndOffset(
 | 
			
		||||
                readOnlyState_slot,
 | 
			
		||||
                readOnlyState_offset,
 | 
			
		||||
                slot,
 | 
			
		||||
                offset
 | 
			
		||||
            )
 | 
			
		||||
            slot := add(slot, 0x1)
 | 
			
		||||
 | 
			
		||||
            assertSlotAndOffset(
 | 
			
		||||
                _globalStakeByStatus_slot,
 | 
			
		||||
                _globalStakeByStatus_offset,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user