/**
* .
* / \
* |.'.|
* |'.'|
* ,'| |'.
* |,-'-|-'-.|
* __|_| | _ _ _____ _
* | ___ \| | | | | | ___ \ | |
* | |_/ /|__ ___| | _____| |_ | |_/ /__ ___ | |
* | // _ \ / __| |/ / _ \ __| | __/ _ \ / _ \| |
* | |\ \ (_) | (__| < __/ |_ | | | (_) | (_) | |
* \_| \_\___/ \___|_|\_\___|\__| \_| \___/ \___/|_|
* +---------------------------------------------------+
* | DECENTRALISED STAKING PROTOCOL FOR ETHEREUM |
* +---------------------------------------------------+
*
* Rocket Pool is a first-of-its-kind Ethereum staking pool protocol, designed to
* be community-owned, decentralised, permissionless, & trustless.
*
* For more information about Rocket Pool, visit https://rocketpool.net
*
* Authored by the Rocket Pool Core Team
* Contributors: https://github.com/rocket-pool/rocketpool/graphs/contributors
* A special thanks to the Rocket Pool community for all their contributions.
*
*/pragmasolidity >0.5.0 <0.9.0;// SPDX-License-Identifier: GPL-3.0-onlyimport"../interface/RocketStorageInterface.sol";
/// @title Base settings / modifiers for each contract in Rocket Pool/// @author David RugendykeabstractcontractRocketBase{
// Calculate using this as the baseuint256constant calcBase =1ether;
// Version of the contractuint8public version;
// The main storage contract where primary persistant storage is maintained
RocketStorageInterface rocketStorage = RocketStorageInterface(address(0));
/*** Modifiers **********************************************************//**
* @dev Throws if called by any sender that doesn't match a Rocket Pool network contract
*/modifieronlyLatestNetworkContract() {
require(getBool(keccak256(abi.encodePacked("contract.exists", msg.sender))), "Invalid or outdated network contract");
_;
}
/**
* @dev Throws if called by any sender that doesn't match one of the supplied contract or is the latest version of that contract
*/modifieronlyLatestContract(stringmemory _contractName, address _contractAddress) {
require(_contractAddress == getAddress(keccak256(abi.encodePacked("contract.address", _contractName))), "Invalid or outdated contract");
_;
}
/**
* @dev Throws if called by any sender that isn't a registered node
*/modifieronlyRegisteredNode(address _nodeAddress) {
require(getBool(keccak256(abi.encodePacked("node.exists", _nodeAddress))), "Invalid node");
_;
}
/**
* @dev Throws if called by any sender that isn't a trusted node DAO member
*/modifieronlyTrustedNode(address _nodeAddress) {
require(getBool(keccak256(abi.encodePacked("dao.trustednodes.", "member", _nodeAddress))), "Invalid trusted node");
_;
}
/**
* @dev Throws if called by any sender that isn't a registered minipool
*/modifieronlyRegisteredMinipool(address _minipoolAddress) {
require(getBool(keccak256(abi.encodePacked("minipool.exists", _minipoolAddress))), "Invalid minipool");
_;
}
/**
* @dev Throws if called by any account other than a guardian account (temporary account allowed access to settings before DAO is fully enabled)
*/modifieronlyGuardian() {
require(msg.sender== rocketStorage.getGuardian(), "Account is not a temporary guardian");
_;
}
/*** Methods **********************************************************//// @dev Set the main Rocket Storage addressconstructor(RocketStorageInterface _rocketStorageAddress) {
// Update the contract address
rocketStorage = RocketStorageInterface(_rocketStorageAddress);
}
/// @dev Get the address of a network contract by namefunctiongetContractAddress(stringmemory _contractName) internalviewreturns (address) {
// Get the current contract addressaddress contractAddress = getAddress(keccak256(abi.encodePacked("contract.address", _contractName)));
// Check itrequire(contractAddress !=address(0x0), "Contract not found");
// Returnreturn contractAddress;
}
/// @dev Get the address of a network contract by name (returns address(0x0) instead of reverting if contract does not exist)functiongetContractAddressUnsafe(stringmemory _contractName) internalviewreturns (address) {
// Get the current contract addressaddress contractAddress = getAddress(keccak256(abi.encodePacked("contract.address", _contractName)));
// Returnreturn contractAddress;
}
/// @dev Get the name of a network contract by addressfunctiongetContractName(address _contractAddress) internalviewreturns (stringmemory) {
// Get the contract namestringmemory contractName = getString(keccak256(abi.encodePacked("contract.name", _contractAddress)));
// Check itrequire(bytes(contractName).length>0, "Contract not found");
// Returnreturn contractName;
}
/// @dev Get revert error message from a .call methodfunctiongetRevertMsg(bytesmemory _returnData) internalpurereturns (stringmemory) {
// If the _res length is less than 68, then the transaction failed silently (without a revert message)if (_returnData.length<68) return"Transaction reverted silently";
assembly {
// Slice the sighash.
_returnData :=add(_returnData, 0x04)
}
returnabi.decode(_returnData, (string)); // All that remains is the revert string
}
/*** Rocket Storage Methods ****************************************/// Note: Unused helpers have been removed to keep contract sizes down/// @dev Storage get methodsfunctiongetAddress(bytes32 _key) internalviewreturns (address) { return rocketStorage.getAddress(_key); }
functiongetUint(bytes32 _key) internalviewreturns (uint) { return rocketStorage.getUint(_key); }
functiongetString(bytes32 _key) internalviewreturns (stringmemory) { return rocketStorage.getString(_key); }
functiongetBytes(bytes32 _key) internalviewreturns (bytesmemory) { return rocketStorage.getBytes(_key); }
functiongetBool(bytes32 _key) internalviewreturns (bool) { return rocketStorage.getBool(_key); }
functiongetInt(bytes32 _key) internalviewreturns (int) { return rocketStorage.getInt(_key); }
functiongetBytes32(bytes32 _key) internalviewreturns (bytes32) { return rocketStorage.getBytes32(_key); }
/// @dev Storage set methodsfunctionsetAddress(bytes32 _key, address _value) internal{ rocketStorage.setAddress(_key, _value); }
functionsetUint(bytes32 _key, uint _value) internal{ rocketStorage.setUint(_key, _value); }
functionsetString(bytes32 _key, stringmemory _value) internal{ rocketStorage.setString(_key, _value); }
functionsetBytes(bytes32 _key, bytesmemory _value) internal{ rocketStorage.setBytes(_key, _value); }
functionsetBool(bytes32 _key, bool _value) internal{ rocketStorage.setBool(_key, _value); }
functionsetInt(bytes32 _key, int _value) internal{ rocketStorage.setInt(_key, _value); }
functionsetBytes32(bytes32 _key, bytes32 _value) internal{ rocketStorage.setBytes32(_key, _value); }
/// @dev Storage delete methodsfunctiondeleteAddress(bytes32 _key) internal{ rocketStorage.deleteAddress(_key); }
functiondeleteUint(bytes32 _key) internal{ rocketStorage.deleteUint(_key); }
functiondeleteString(bytes32 _key) internal{ rocketStorage.deleteString(_key); }
functiondeleteBytes(bytes32 _key) internal{ rocketStorage.deleteBytes(_key); }
functiondeleteBool(bytes32 _key) internal{ rocketStorage.deleteBool(_key); }
functiondeleteInt(bytes32 _key) internal{ rocketStorage.deleteInt(_key); }
functiondeleteBytes32(bytes32 _key) internal{ rocketStorage.deleteBytes32(_key); }
/// @dev Storage arithmetic methodsfunctionaddUint(bytes32 _key, uint256 _amount) internal{ rocketStorage.addUint(_key, _amount); }
functionsubUint(bytes32 _key, uint256 _amount) internal{ rocketStorage.subUint(_key, _amount); }
}