Move storage assertions into StakingProxy
This commit is contained in:
parent
e2ee7e6837
commit
cc67f732e1
@ -198,5 +198,81 @@ contract StakingProxy is
|
||||
revert(add(initReturnData, 0x20), mload(initReturnData))
|
||||
}
|
||||
}
|
||||
|
||||
// Assert initialized storage values are valid
|
||||
_assertValidStorageParams();
|
||||
}
|
||||
|
||||
/// @dev Asserts that an epoch is between 5 and 30 days long.
|
||||
// Asserts that cobb douglas alpha value is between 0 and 1.
|
||||
// Asserts that a stake weight is <= 100%.
|
||||
// Asserts that pools allow >= 1 maker.
|
||||
// Asserts that all addresses are initialized.
|
||||
function _assertValidStorageParams()
|
||||
private
|
||||
view
|
||||
{
|
||||
// Epoch length must be between 5 and 30 days long
|
||||
uint256 _epochDurationInSeconds = epochDurationInSeconds;
|
||||
if (_epochDurationInSeconds < 5 days || _epochDurationInSeconds > 30 days) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidEpochDuration
|
||||
));
|
||||
}
|
||||
|
||||
// Alpha must be 0 < x < 1
|
||||
uint32 _cobbDouglasAlphaDenominator = cobbDouglasAlphaDenominator;
|
||||
if (cobbDouglasAlphaNumerator > _cobbDouglasAlphaDenominator || _cobbDouglasAlphaDenominator == 0) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidCobbDouglasAlpha
|
||||
));
|
||||
}
|
||||
|
||||
// Weight of delegated stake must be <= 100%
|
||||
if (rewardDelegatedStakeWeight > PPM_DENOMINATOR) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidRewardDelegatedStakeWeight
|
||||
));
|
||||
}
|
||||
|
||||
// Pools must allow at least one maker
|
||||
if (maximumMakersInPool == 0) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidMaximumMakersInPool
|
||||
));
|
||||
}
|
||||
|
||||
// ERC20Proxy and Vault contract addresses must always be initialized
|
||||
if (address(wethAssetProxy) == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidWethProxyAddress
|
||||
));
|
||||
}
|
||||
|
||||
if (address(ethVault) == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidEthVaultAddress
|
||||
));
|
||||
}
|
||||
|
||||
if (address(rewardVault) == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidRewardVaultAddress
|
||||
));
|
||||
}
|
||||
|
||||
if (address(zrxVault) == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidZrxVaultAddress
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ library LibStakingRichErrors {
|
||||
InvalidWethProxyAddress,
|
||||
InvalidEthVaultAddress,
|
||||
InvalidRewardVaultAddress,
|
||||
InvalidZrxVaultAddress
|
||||
InvalidZrxVaultAddress,
|
||||
InvalidEpochDuration
|
||||
}
|
||||
|
||||
enum MakerPoolAssignmentErrorCodes {
|
||||
|
@ -192,20 +192,6 @@ contract MixinParams is
|
||||
)
|
||||
private
|
||||
{
|
||||
_assertValidRewardDelegatedStakeWeight(_rewardDelegatedStakeWeight);
|
||||
_assertValidMaximumMakersInPool(_maximumMakersInPool);
|
||||
_assertValidCobbDouglasAlpha(
|
||||
_cobbDouglasAlphaNumerator,
|
||||
_cobbDouglasAlphaDenominator
|
||||
);
|
||||
_assertValidAddresses(
|
||||
_wethProxyAddress,
|
||||
_ethVaultAddress,
|
||||
_rewardVaultAddress,
|
||||
_zrxVaultAddress
|
||||
);
|
||||
// TODO: set boundaries on some of these params
|
||||
|
||||
epochDurationInSeconds = _epochDurationInSeconds;
|
||||
rewardDelegatedStakeWeight = _rewardDelegatedStakeWeight;
|
||||
minimumPoolStake = _minimumPoolStake;
|
||||
@ -230,98 +216,4 @@ contract MixinParams is
|
||||
_zrxVaultAddress
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Asserts that cobb douglas alpha values are valid.
|
||||
/// @param numerator Numerator for cobb douglas alpha factor.
|
||||
/// @param denominator Denominator for cobb douglas alpha factor.
|
||||
function _assertValidCobbDouglasAlpha(
|
||||
uint32 numerator,
|
||||
uint32 denominator
|
||||
)
|
||||
private
|
||||
pure
|
||||
{
|
||||
// Alpha must be 0 < x < 1
|
||||
if (numerator > denominator || denominator == 0) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidCobbDouglasAlpha
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Asserts that a stake weight is valid.
|
||||
/// @param weight How much delegated stake is weighted vs operator stake, in ppm.
|
||||
function _assertValidRewardDelegatedStakeWeight(
|
||||
uint32 weight
|
||||
)
|
||||
private
|
||||
pure
|
||||
{
|
||||
if (weight > PPM_DENOMINATOR) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidRewardDelegatedStakeWeight
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Asserts that a maximum makers value is valid.
|
||||
/// @param amount Maximum number of maker addresses allowed to be registered to a pool.
|
||||
function _assertValidMaximumMakersInPool(
|
||||
uint256 amount
|
||||
)
|
||||
private
|
||||
pure
|
||||
{
|
||||
if (amount == 0) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidMaximumMakersInPool
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Asserts that passed in addresses are non-zero.
|
||||
/// @param _wethProxyAddress The address that can transfer WETH for fees.
|
||||
/// @param _ethVaultAddress Address of the EthVault contract.
|
||||
/// @param _rewardVaultAddress Address of the StakingPoolRewardVault contract.
|
||||
/// @param _zrxVaultAddress Address of the ZrxVault contract.
|
||||
function _assertValidAddresses(
|
||||
address _wethProxyAddress,
|
||||
address _ethVaultAddress,
|
||||
address _rewardVaultAddress,
|
||||
address _zrxVaultAddress
|
||||
)
|
||||
private
|
||||
pure
|
||||
{
|
||||
if (_wethProxyAddress == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidWethProxyAddress
|
||||
));
|
||||
}
|
||||
|
||||
if (_ethVaultAddress == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidEthVaultAddress
|
||||
));
|
||||
}
|
||||
|
||||
if (_rewardVaultAddress == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidRewardVaultAddress
|
||||
));
|
||||
}
|
||||
|
||||
if (_zrxVaultAddress == NIL_ADDRESS) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidZrxVaultAddress
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user