Documentation for MixinVaultCore
This commit is contained in:
parent
2a5742c12d
commit
ee969261b4
60
contracts/staking/contracts/src/interfaces/IVaultCore.sol
Normal file
60
contracts/staking/contracts/src/interfaces/IVaultCore.sol
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
interface IVaultCore
|
||||||
|
{
|
||||||
|
|
||||||
|
/// @dev This mixin contains core logic for vaults.
|
||||||
|
/// This includes management of the staking contract
|
||||||
|
/// and setting the vault to "Catastrophic Failure Mode".
|
||||||
|
/// It's up to the vault how they handle this failure mode; however,
|
||||||
|
/// all vaults should disable all functionality aside from withdrawals.
|
||||||
|
/// Vaults should only be set to Catastrophic Failure Mode iff there is
|
||||||
|
/// non-recoverable corruption of the staking contracts. If there is a
|
||||||
|
/// recoverable flaw/bug/vulnerability, simply detach the staking contract
|
||||||
|
/// by setting its address to `address(0)`. Once in Catostrophic Failure Mode,
|
||||||
|
/// a vault cannot be reset to normal mode; this prevents corruption of related
|
||||||
|
/// state in the staking contract.
|
||||||
|
|
||||||
|
/// @dev Emitted when the Staking contract is changed.
|
||||||
|
/// @param stakingContractAddress Address of the new Staking contract.
|
||||||
|
event StakingContractChanged(
|
||||||
|
address stakingContractAddress
|
||||||
|
);
|
||||||
|
|
||||||
|
/// @dev Emitted when the Staking contract is put into Catostrophic Failure Mode
|
||||||
|
/// @param sender Address of sender (`msg.sender`)
|
||||||
|
event InCatostrophicFailureMode(
|
||||||
|
address sender
|
||||||
|
);
|
||||||
|
|
||||||
|
/// @dev Sets the address of the Staking Contract.
|
||||||
|
/// Note that only the contract owner can call this function.
|
||||||
|
/// @param _stakingContractAddress Address of Staking contract.
|
||||||
|
function setStakingContract(address payable _stakingContractAddress)
|
||||||
|
external;
|
||||||
|
|
||||||
|
/// @dev Vault enters into Catostrophic Failure Mode.
|
||||||
|
/// *** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! ***
|
||||||
|
/// Note that only the contract owner can call this function.
|
||||||
|
function enterCatostrophicFailure()
|
||||||
|
external;
|
||||||
|
}
|
@ -19,21 +19,39 @@
|
|||||||
pragma solidity ^0.5.5;
|
pragma solidity ^0.5.5;
|
||||||
|
|
||||||
import "@0x/contracts-utils/contracts/src/Authorizable.sol";
|
import "@0x/contracts-utils/contracts/src/Authorizable.sol";
|
||||||
|
import "../interfaces/IVaultCore.sol";
|
||||||
|
|
||||||
|
|
||||||
contract MixinVaultCore is
|
contract MixinVaultCore is
|
||||||
Authorizable
|
Authorizable,
|
||||||
|
IVaultCore
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// @dev This mixin contains core logic for vaults.
|
||||||
|
/// This includes management of the staking contract
|
||||||
|
/// and setting the vault to "Catastrophic Failure Mode".
|
||||||
|
/// It's up to the vault how they handle this failure mode; however,
|
||||||
|
/// all vaults should disable all functionality aside from withdrawals.
|
||||||
|
/// Vaults should only be set to Catastrophic Failure Mode iff there is
|
||||||
|
/// non-recoverable corruption of the staking contracts. If there is a
|
||||||
|
/// recoverable flaw/bug/vulnerability, simply detach the staking contract
|
||||||
|
/// by setting its address to `address(0)`. Once in Catostrophic Failure Mode,
|
||||||
|
/// a vault cannot be reset to normal mode; this prevents corruption of related
|
||||||
|
/// state in the staking contract.
|
||||||
|
|
||||||
|
// Address of staking contract
|
||||||
address payable internal stakingContractAddress;
|
address payable internal stakingContractAddress;
|
||||||
|
|
||||||
|
// True iff vault has been set to Catostrophic Failure Mode
|
||||||
bool internal isInCatostrophicFailure;
|
bool internal isInCatostrophicFailure;
|
||||||
|
|
||||||
|
/// @dev Constructor.
|
||||||
constructor() public {
|
constructor() public {
|
||||||
stakingContractAddress = 0x0000000000000000000000000000000000000000;
|
stakingContractAddress = 0x0000000000000000000000000000000000000000;
|
||||||
isInCatostrophicFailure = false;
|
isInCatostrophicFailure = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @dev Asserts that the sender (`msg.sender`) is the staking contract.
|
||||||
modifier onlyStakingContract {
|
modifier onlyStakingContract {
|
||||||
require(
|
require(
|
||||||
msg.sender == stakingContractAddress,
|
msg.sender == stakingContractAddress,
|
||||||
@ -42,6 +60,7 @@ contract MixinVaultCore is
|
|||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @dev Asserts that this contract *is in* Catostrophic Failure Mode.
|
||||||
modifier onlyInCatostrophicFailure {
|
modifier onlyInCatostrophicFailure {
|
||||||
require(
|
require(
|
||||||
isInCatostrophicFailure,
|
isInCatostrophicFailure,
|
||||||
@ -50,6 +69,7 @@ contract MixinVaultCore is
|
|||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @dev Asserts that this contract *is not in* Catostrophic Failure Mode.
|
||||||
modifier onlyNotInCatostrophicFailure {
|
modifier onlyNotInCatostrophicFailure {
|
||||||
require(
|
require(
|
||||||
!isInCatostrophicFailure,
|
!isInCatostrophicFailure,
|
||||||
@ -58,17 +78,25 @@ contract MixinVaultCore is
|
|||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setStakingContractAddrsess(address payable _stakingContractAddress)
|
/// @dev Sets the address of the Staking Contract.
|
||||||
|
/// Note that only the contract owner can call this function.
|
||||||
|
/// @param _stakingContractAddress Address of Staking contract.
|
||||||
|
function setStakingContract(address payable _stakingContractAddress)
|
||||||
external
|
external
|
||||||
onlyOwner
|
onlyOwner
|
||||||
{
|
{
|
||||||
stakingContractAddress = _stakingContractAddress;
|
stakingContractAddress = _stakingContractAddress;
|
||||||
|
emit StakingContractChanged(stakingContractAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @dev Vault enters into Catostrophic Failure Mode.
|
||||||
|
/// *** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! ***
|
||||||
|
/// Note that only the contract owner can call this function.
|
||||||
function enterCatostrophicFailure()
|
function enterCatostrophicFailure()
|
||||||
external
|
external
|
||||||
onlyOwner
|
onlyOwner
|
||||||
{
|
{
|
||||||
isInCatostrophicFailure = true;
|
isInCatostrophicFailure = true;
|
||||||
|
emit InCatostrophicFailureMode(msg.sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -42,6 +42,9 @@ contract StakingPoolRewardVault is
|
|||||||
/// allows withdrawals to be made. Once this vault is in catostrophic
|
/// allows withdrawals to be made. Once this vault is in catostrophic
|
||||||
/// failure mode, it cannot be returned to normal mode; this prevents
|
/// failure mode, it cannot be returned to normal mode; this prevents
|
||||||
/// corruption of related state in the staking contract.
|
/// corruption of related state in the staking contract.
|
||||||
|
///
|
||||||
|
/// When in Catastrophic Failure Mode, the Staking contract can still
|
||||||
|
/// perform withdrawals on behalf of its users.
|
||||||
|
|
||||||
// mapping from Pool to Reward Balance in ETH
|
// mapping from Pool to Reward Balance in ETH
|
||||||
mapping (bytes32 => Balance) internal balanceByPoolId;
|
mapping (bytes32 => Balance) internal balanceByPoolId;
|
||||||
|
@ -134,7 +134,7 @@ export class StakingWrapper {
|
|||||||
);
|
);
|
||||||
// set staking proxy contract in zrx vault
|
// set staking proxy contract in zrx vault
|
||||||
await (this
|
await (this
|
||||||
._zrxVaultContractIfExists).setStakingContractAddrsess.awaitTransactionSuccessAsync(
|
._zrxVaultContractIfExists).setStakingContract.awaitTransactionSuccessAsync(
|
||||||
(this._stakingProxyContractIfExists).address,
|
(this._stakingProxyContractIfExists).address,
|
||||||
);
|
);
|
||||||
// set zrx vault in staking contract
|
// set zrx vault in staking contract
|
||||||
@ -152,7 +152,7 @@ export class StakingWrapper {
|
|||||||
);
|
);
|
||||||
// set staking proxy contract in reward vault
|
// set staking proxy contract in reward vault
|
||||||
await (this
|
await (this
|
||||||
._rewardVaultContractIfExists).setStakingContractAddrsess.awaitTransactionSuccessAsync(
|
._rewardVaultContractIfExists).setStakingContract.awaitTransactionSuccessAsync(
|
||||||
(this._stakingProxyContractIfExists).address,
|
(this._stakingProxyContractIfExists).address,
|
||||||
);
|
);
|
||||||
// set reward vault in staking contract
|
// set reward vault in staking contract
|
||||||
|
Loading…
x
Reference in New Issue
Block a user