From a7ef54dbff7c1109c2ac517b85190db299cb3e9c Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Sun, 6 Oct 2019 12:02:40 -0700 Subject: [PATCH] Implement ZrxVaultBackstop --- .../contracts/src/ZrxVaultBackstop.sol | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 contracts/staking/contracts/src/ZrxVaultBackstop.sol diff --git a/contracts/staking/contracts/src/ZrxVaultBackstop.sol b/contracts/staking/contracts/src/ZrxVaultBackstop.sol new file mode 100644 index 0000000000..874291f131 --- /dev/null +++ b/contracts/staking/contracts/src/ZrxVaultBackstop.sol @@ -0,0 +1,69 @@ +/* + + Copyright 2019 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.9; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; +import "./interfaces/IStructs.sol"; +import "./interfaces/IZrxVault.sol"; +import "./interfaces/IStakingProxy.sol"; + + +contract ZrxVaultBackstop { + + using LibSafeMath for uint256; + + IStakingProxy public stakingProxy; + IZrxVault public zrxVault; + + /// @dev Constructor. Sets stakingProxy and zrxVault. + /// @param _stakingProxyAddress Address of stakingProxy. + /// @param _zrxVaultAddress Address of zrxVault. + constructor( + address payable _stakingProxyAddress, + address _zrxVaultAddress + ) + public + { + stakingProxy = IStakingProxy(_stakingProxyAddress); + zrxVault = IZrxVault(_zrxVaultAddress); + } + + /// @dev Triggers catastophic failure mode in the zrxzVault iff read-only mode + /// has been continuously set for at least 40 days. + function enterCatastrophicFailureIfProlongedReadOnlyMode() + external + { + IStructs.ReadOnlyState memory readOnlyState = stakingProxy.readOnlyState(); + + // Ensure read-only mode is set + require( + readOnlyState.isReadOnlyModeSet, + "READ_ONLY_MODE_NOT_SET" + ); + + // Ensure that the stakingProxy has been in read-only mode for a long enough time + require( + block.timestamp.safeSub(readOnlyState.lastSetTimestamp) >= 40 days, + "READ_ONLY_MODE_LENGTH_TOO_SHORT" + ); + + zrxVault.enterCatastrophicFailure(); + } +}