Remove read-only mode related functions, storage variables, and contracts
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
|
||||
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;
|
||||
|
||||
import "./immutable/MixinStorage.sol";
|
||||
import "./libs/LibProxy.sol";
|
||||
|
||||
|
||||
contract ReadOnlyProxy is
|
||||
MixinStorage
|
||||
{
|
||||
using LibProxy for address;
|
||||
|
||||
// solhint-disable payable-fallback
|
||||
/// @dev Executes a read-only call to the staking contract, via `revertDelegateCall`.
|
||||
/// By routing through `revertDelegateCall` any state changes are reverted.
|
||||
// solhint-disable-next-line payable-fallback
|
||||
function ()
|
||||
external
|
||||
{
|
||||
address(this).proxyCall(
|
||||
LibProxy.RevertRule.NEVER_REVERT,
|
||||
this.revertDelegateCall.selector, // custom egress selector
|
||||
false // do not ignore ingress selector
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Executes a delegate call to the staking contract, if it is set.
|
||||
/// This function always reverts with the return data.
|
||||
function revertDelegateCall()
|
||||
external
|
||||
{
|
||||
readOnlyProxyCallee.proxyCall(
|
||||
LibProxy.RevertRule.ALWAYS_REVERT,
|
||||
bytes4(0), // no custom egress selector
|
||||
true // ignore ingress selector
|
||||
);
|
||||
}
|
||||
}
|
@@ -37,16 +37,10 @@ contract StakingProxy is
|
||||
|
||||
/// @dev Constructor.
|
||||
/// @param _stakingContract Staking contract to delegate calls to.
|
||||
/// @param _readOnlyProxy The address of the read only proxy.
|
||||
constructor(
|
||||
address _stakingContract,
|
||||
address _readOnlyProxy
|
||||
)
|
||||
constructor(address _stakingContract)
|
||||
public
|
||||
MixinStorage()
|
||||
{
|
||||
readOnlyProxy = _readOnlyProxy;
|
||||
|
||||
// Deployer address must be authorized in order to call `init`
|
||||
_addAuthorizedAddress(msg.sender);
|
||||
|
||||
@@ -89,29 +83,6 @@ contract StakingProxy is
|
||||
emit StakingContractDetachedFromProxy();
|
||||
}
|
||||
|
||||
/// @dev Set read-only mode (state cannot be changed).
|
||||
function setReadOnlyMode(bool shouldSetReadOnlyMode)
|
||||
external
|
||||
onlyAuthorized
|
||||
{
|
||||
// solhint-disable-next-line not-rely-on-time
|
||||
uint96 timestamp = block.timestamp.downcastToUint96();
|
||||
if (shouldSetReadOnlyMode) {
|
||||
stakingContract = readOnlyProxy;
|
||||
readOnlyState = IStructs.ReadOnlyState({
|
||||
isReadOnlyModeSet: true,
|
||||
lastSetTimestamp: timestamp
|
||||
});
|
||||
} else {
|
||||
stakingContract = readOnlyProxyCallee;
|
||||
readOnlyState.isReadOnlyModeSet = false;
|
||||
}
|
||||
emit ReadOnlyModeSet(
|
||||
shouldSetReadOnlyMode,
|
||||
timestamp
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Batch executes a series of calls to the staking contract.
|
||||
/// @param data An array of data that encodes a sequence of functions to
|
||||
/// call in the staking contracts.
|
||||
@@ -202,7 +173,7 @@ contract StakingProxy is
|
||||
internal
|
||||
{
|
||||
// Attach the staking contract
|
||||
stakingContract = readOnlyProxyCallee = _stakingContract;
|
||||
stakingContract = _stakingContract;
|
||||
emit StakingContractAttachedToProxy(_stakingContract);
|
||||
|
||||
// Call `init()` on the staking contract to initialize storage.
|
||||
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
|
||||
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";
|
||||
import "./interfaces/IZrxVaultBackstop.sol";
|
||||
|
||||
|
||||
contract ZrxVaultBackstop is
|
||||
IZrxVaultBackstop
|
||||
{
|
||||
|
||||
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 _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
|
||||
// TODO: Ensure correct value is set in production
|
||||
require(
|
||||
// solhint-disable-next-line not-rely-on-time
|
||||
block.timestamp.safeSub(readOnlyState.lastSetTimestamp) >= 40 days,
|
||||
"READ_ONLY_MODE_DURATION_TOO_SHORT"
|
||||
);
|
||||
|
||||
zrxVault.enterCatastrophicFailure();
|
||||
}
|
||||
}
|
@@ -34,15 +34,6 @@ contract MixinStorage is
|
||||
// address of staking contract
|
||||
address public stakingContract;
|
||||
|
||||
// address of read-only proxy
|
||||
address public readOnlyProxy;
|
||||
|
||||
// address for read-only proxy to call
|
||||
address public readOnlyProxyCallee;
|
||||
|
||||
// state of read-only mode in stakingProxy
|
||||
IStructs.ReadOnlyState public readOnlyState;
|
||||
|
||||
// mapping from StakeStatus to global stored balance
|
||||
// NOTE: only Status.DELEGATED is used to access this mapping, but this format
|
||||
// is used for extensibility
|
||||
|
@@ -33,12 +33,6 @@ contract IStakingProxy {
|
||||
/// @dev Emitted by StakingProxy when a staking contract is detached.
|
||||
event StakingContractDetachedFromProxy();
|
||||
|
||||
/// @dev Emitted by StakingProxy when read-only mode is set.
|
||||
event ReadOnlyModeSet(
|
||||
bool readOnlyMode,
|
||||
uint96 timestamp
|
||||
);
|
||||
|
||||
/// @dev Attach a staking contract; future calls will be delegated to the staking contract.
|
||||
/// Note that this is callable only by an authorized address.
|
||||
/// @param _stakingContract Address of staking contract.
|
||||
@@ -50,12 +44,6 @@ contract IStakingProxy {
|
||||
function detachStakingContract()
|
||||
external;
|
||||
|
||||
/// @dev Gets state of stakingProxy read-only mode.
|
||||
function readOnlyState()
|
||||
external
|
||||
view
|
||||
returns (IStructs.ReadOnlyState memory);
|
||||
|
||||
/// @dev Asserts that an epoch is between 5 and 30 days long.
|
||||
// Asserts that 0 < cobb douglas alpha value <= 1.
|
||||
// Asserts that a stake weight is <= 100%.
|
||||
|
@@ -30,16 +30,6 @@ interface IStorage {
|
||||
view
|
||||
returns (address);
|
||||
|
||||
function readOnlyProxy()
|
||||
external
|
||||
view
|
||||
returns (address);
|
||||
|
||||
function readOnlyProxyCallee()
|
||||
external
|
||||
view
|
||||
returns (address);
|
||||
|
||||
function lastPoolId()
|
||||
external
|
||||
view
|
||||
|
@@ -21,14 +21,6 @@ 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 Stats for a pool that earned rewards.
|
||||
/// @param feesCollected Fees collected in ETH by this pool.
|
||||
/// @param weightedStake Amount of weighted stake in the pool.
|
||||
|
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
|
||||
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;
|
||||
|
||||
|
||||
interface IZrxVaultBackstop {
|
||||
|
||||
/// @dev Triggers catastophic failure mode in the zrxzVault iff read-only mode
|
||||
/// has been continuously set for at least 40 days.
|
||||
function enterCatastrophicFailureIfProlongedReadOnlyMode()
|
||||
external;
|
||||
}
|
@@ -35,10 +35,7 @@ contract TestAssertStorageParams is
|
||||
|
||||
constructor()
|
||||
public
|
||||
StakingProxy(
|
||||
NIL_ADDRESS,
|
||||
NIL_ADDRESS
|
||||
)
|
||||
StakingProxy(NIL_ADDRESS)
|
||||
{}
|
||||
|
||||
function setAndAssertParams(StorageParams memory params)
|
||||
|
@@ -29,10 +29,7 @@ contract TestStakingProxy is
|
||||
// solhint-disable no-empty-blocks
|
||||
constructor(address _stakingContract)
|
||||
public
|
||||
StakingProxy(
|
||||
_stakingContract,
|
||||
NIL_ADDRESS
|
||||
)
|
||||
StakingProxy( _stakingContract)
|
||||
{}
|
||||
|
||||
function assertValidStorageParams()
|
||||
|
@@ -102,30 +102,6 @@ contract TestStorageLayoutAndConstants is
|
||||
)
|
||||
slot := add(slot, 0x1)
|
||||
|
||||
assertSlotAndOffset(
|
||||
readOnlyProxy_slot,
|
||||
readOnlyProxy_offset,
|
||||
slot,
|
||||
offset
|
||||
)
|
||||
slot := add(slot, 0x1)
|
||||
|
||||
assertSlotAndOffset(
|
||||
readOnlyProxyCallee_slot,
|
||||
readOnlyProxyCallee_offset,
|
||||
slot,
|
||||
offset
|
||||
)
|
||||
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