Merge pull request #2203 from 0xProject/feat/3.0/consolidate-rich-reverts
Cleanup rich reverts
This commit is contained in:
@@ -146,7 +146,7 @@ contract StakingProxy is
|
||||
if (_epochDurationInSeconds < 5 days || _epochDurationInSeconds > 30 days) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidEpochDuration
|
||||
LibStakingRichErrors.InvalidParamValueErrorCodes.InvalidEpochDuration
|
||||
));
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ contract StakingProxy is
|
||||
if (cobbDouglasAlphaNumerator > _cobbDouglasAlphaDenominator || _cobbDouglasAlphaDenominator == 0) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidCobbDouglasAlpha
|
||||
LibStakingRichErrors.InvalidParamValueErrorCodes.InvalidCobbDouglasAlpha
|
||||
));
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ contract StakingProxy is
|
||||
if (rewardDelegatedStakeWeight > PPM_DENOMINATOR) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidRewardDelegatedStakeWeight
|
||||
LibStakingRichErrors.InvalidParamValueErrorCodes.InvalidRewardDelegatedStakeWeight
|
||||
));
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ contract StakingProxy is
|
||||
if (maximumMakersInPool == 0) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidMaximumMakersInPool
|
||||
LibStakingRichErrors.InvalidParamValueErrorCodes.InvalidMaximumMakersInPool
|
||||
));
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ contract StakingProxy is
|
||||
if (minimumPoolStake < 2) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidParamValueError(
|
||||
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidMinimumPoolStake
|
||||
LibStakingRichErrors.InvalidParamValueErrorCodes.InvalidMinimumPoolStake
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@@ -51,7 +51,8 @@ contract MixinExchangeManager is
|
||||
onlyAuthorized
|
||||
{
|
||||
if (validExchanges[addr]) {
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.ExchangeAddressAlreadyRegisteredError(
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.ExchangeManagerError(
|
||||
LibStakingRichErrors.ExchangeManagerErrorCodes.ExchangeAlreadyRegistered,
|
||||
addr
|
||||
));
|
||||
}
|
||||
@@ -66,7 +67,8 @@ contract MixinExchangeManager is
|
||||
onlyAuthorized
|
||||
{
|
||||
if (!validExchanges[addr]) {
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.ExchangeAddressNotRegisteredError(
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.ExchangeManagerError(
|
||||
LibStakingRichErrors.ExchangeManagerErrorCodes.ExchangeNotRegistered,
|
||||
addr
|
||||
));
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
|
||||
import "../interfaces/IStructs.sol";
|
||||
|
||||
|
||||
library LibStakingRichErrors {
|
||||
@@ -33,12 +34,12 @@ library LibStakingRichErrors {
|
||||
MismatchedFeeAndPayment
|
||||
}
|
||||
|
||||
enum InitializationErrorCode {
|
||||
enum InitializationErrorCodes {
|
||||
MixinSchedulerAlreadyInitialized,
|
||||
MixinParamsAlreadyInitialized
|
||||
}
|
||||
|
||||
enum InvalidParamValueErrorCode {
|
||||
enum InvalidParamValueErrorCodes {
|
||||
InvalidCobbDouglasAlpha,
|
||||
InvalidRewardDelegatedStakeWeight,
|
||||
InvalidMaximumMakersInPool,
|
||||
@@ -53,21 +54,18 @@ library LibStakingRichErrors {
|
||||
PoolIsFull
|
||||
}
|
||||
|
||||
// bytes4(keccak256("MiscalculatedRewardsError(uint256,uint256)"))
|
||||
bytes4 internal constant MISCALCULATED_REWARDS_ERROR_SELECTOR =
|
||||
0xf7806c4e;
|
||||
enum ExchangeManagerErrorCodes {
|
||||
ExchangeAlreadyRegistered,
|
||||
ExchangeNotRegistered
|
||||
}
|
||||
|
||||
// bytes4(keccak256("OnlyCallableByExchangeError(address)"))
|
||||
bytes4 internal constant ONLY_CALLABLE_BY_EXCHANGE_ERROR_SELECTOR =
|
||||
0xb56d2df0;
|
||||
|
||||
// bytes4(keccak256("ExchangeAddressAlreadyRegisteredError(address)"))
|
||||
bytes4 internal constant EXCHANGE_ADDRESS_ALREADY_REGISTERED_ERROR_SELECTOR =
|
||||
0xc87a78b7;
|
||||
|
||||
// bytes4(keccak256("ExchangeAddressNotRegisteredError(address)"))
|
||||
bytes4 internal constant EXCHANGE_ADDRESS_NOT_REGISTERED_ERROR_SELECTOR =
|
||||
0x7dc025b0;
|
||||
// bytes4(keccak256("ExchangeManagerError(uint8,address)"))
|
||||
bytes4 internal constant EXCHANGE_MANAGER_ERROR_SELECTOR =
|
||||
0xb9588e43;
|
||||
|
||||
// bytes4(keccak256("InsufficientBalanceError(uint256,uint256)"))
|
||||
bytes4 internal constant INSUFFICIENT_BALANCE_ERROR_SELECTOR =
|
||||
@@ -81,10 +79,6 @@ library LibStakingRichErrors {
|
||||
bytes4 internal constant MAKER_POOL_ASSIGNMENT_ERROR_SELECTOR =
|
||||
0x69945e3f;
|
||||
|
||||
// bytes4(keccak256("WithdrawAmountExceedsMemberBalanceError(uint256,uint256)"))
|
||||
bytes4 internal constant WITHDRAW_AMOUNT_EXCEEDS_MEMBER_BALANCE_ERROR_SELECTOR =
|
||||
0xfc9c065f;
|
||||
|
||||
// bytes4(keccak256("BlockTimestampTooLowError(uint256,uint256)"))
|
||||
bytes4 internal constant BLOCK_TIMESTAMP_TOO_LOW_ERROR_SELECTOR =
|
||||
0xa6bcde47;
|
||||
@@ -101,10 +95,6 @@ library LibStakingRichErrors {
|
||||
bytes internal constant ONLY_CALLABLE_IF_NOT_IN_CATASTROPHIC_FAILURE_ERROR =
|
||||
hex"7dd020ce";
|
||||
|
||||
// bytes4(keccak256("AmountExceedsBalanceOfPoolError(uint256,uint96)"))
|
||||
bytes4 internal constant AMOUNT_EXCEEDS_BALANCE_OF_POOL_ERROR_SELECTOR =
|
||||
0x4c5c09dd;
|
||||
|
||||
// bytes4(keccak256("OperatorShareError(uint8,bytes32,uint32)"))
|
||||
bytes4 internal constant OPERATOR_SHARE_ERROR_SELECTOR =
|
||||
0x22df9597;
|
||||
@@ -113,9 +103,9 @@ library LibStakingRichErrors {
|
||||
bytes4 internal constant POOL_EXISTENCE_ERROR_SELECTOR =
|
||||
0x9ae94f01;
|
||||
|
||||
// bytes4(keccak256("InvalidStakeStatusError(uint256)"))
|
||||
// bytes4(keccak256("InvalidStakeStatusError(uint8)"))
|
||||
bytes4 internal constant INVALID_STAKE_STATUS_ERROR_SELECTOR =
|
||||
0xb7161acd;
|
||||
0x7cf20260;
|
||||
|
||||
// bytes4(keccak256("ProxyDestinationCannotBeNilError()"))
|
||||
bytes internal constant PROXY_DESTINATION_CANNOT_BE_NIL_ERROR =
|
||||
@@ -138,21 +128,6 @@ library LibStakingRichErrors {
|
||||
0x614b800a;
|
||||
|
||||
// solhint-disable func-name-mixedcase
|
||||
function MiscalculatedRewardsError(
|
||||
uint256 totalRewardsPaid,
|
||||
uint256 initialContractBalance
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
MISCALCULATED_REWARDS_ERROR_SELECTOR,
|
||||
totalRewardsPaid,
|
||||
initialContractBalance
|
||||
);
|
||||
}
|
||||
|
||||
function OnlyCallableByExchangeError(
|
||||
address senderAddress
|
||||
)
|
||||
@@ -166,7 +141,8 @@ library LibStakingRichErrors {
|
||||
);
|
||||
}
|
||||
|
||||
function ExchangeAddressAlreadyRegisteredError(
|
||||
function ExchangeManagerError(
|
||||
ExchangeManagerErrorCodes errorCodes,
|
||||
address exchangeAddress
|
||||
)
|
||||
internal
|
||||
@@ -174,20 +150,8 @@ library LibStakingRichErrors {
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
EXCHANGE_ADDRESS_ALREADY_REGISTERED_ERROR_SELECTOR,
|
||||
exchangeAddress
|
||||
);
|
||||
}
|
||||
|
||||
function ExchangeAddressNotRegisteredError(
|
||||
address exchangeAddress
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
EXCHANGE_ADDRESS_NOT_REGISTERED_ERROR_SELECTOR,
|
||||
EXCHANGE_MANAGER_ERROR_SELECTOR,
|
||||
errorCodes,
|
||||
exchangeAddress
|
||||
);
|
||||
}
|
||||
@@ -223,7 +187,7 @@ library LibStakingRichErrors {
|
||||
}
|
||||
|
||||
function MakerPoolAssignmentError(
|
||||
MakerPoolAssignmentErrorCodes errorCode,
|
||||
MakerPoolAssignmentErrorCodes errorCodes,
|
||||
address makerAddress,
|
||||
bytes32 poolId
|
||||
)
|
||||
@@ -233,27 +197,12 @@ library LibStakingRichErrors {
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
MAKER_POOL_ASSIGNMENT_ERROR_SELECTOR,
|
||||
errorCode,
|
||||
errorCodes,
|
||||
makerAddress,
|
||||
poolId
|
||||
);
|
||||
}
|
||||
|
||||
function WithdrawAmountExceedsMemberBalanceError(
|
||||
uint256 withdrawAmount,
|
||||
uint256 balance
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
WITHDRAW_AMOUNT_EXCEEDS_MEMBER_BALANCE_ERROR_SELECTOR,
|
||||
withdrawAmount,
|
||||
balance
|
||||
);
|
||||
}
|
||||
|
||||
function BlockTimestampTooLowError(
|
||||
uint256 epochEndTime,
|
||||
uint256 currentBlockTimestamp
|
||||
@@ -298,23 +247,8 @@ library LibStakingRichErrors {
|
||||
return ONLY_CALLABLE_IF_NOT_IN_CATASTROPHIC_FAILURE_ERROR;
|
||||
}
|
||||
|
||||
function AmountExceedsBalanceOfPoolError(
|
||||
uint256 amount,
|
||||
uint96 poolBalance
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
AMOUNT_EXCEEDS_BALANCE_OF_POOL_ERROR_SELECTOR,
|
||||
amount,
|
||||
poolBalance
|
||||
);
|
||||
}
|
||||
|
||||
function OperatorShareError(
|
||||
OperatorShareErrorCodes errorCode,
|
||||
OperatorShareErrorCodes errorCodes,
|
||||
bytes32 poolId,
|
||||
uint32 operatorShare
|
||||
)
|
||||
@@ -324,7 +258,7 @@ library LibStakingRichErrors {
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
OPERATOR_SHARE_ERROR_SELECTOR,
|
||||
errorCode,
|
||||
errorCodes,
|
||||
poolId,
|
||||
operatorShare
|
||||
);
|
||||
@@ -346,7 +280,7 @@ library LibStakingRichErrors {
|
||||
}
|
||||
|
||||
function InvalidProtocolFeePaymentError(
|
||||
ProtocolFeePaymentErrorCodes errorCode,
|
||||
ProtocolFeePaymentErrorCodes errorCodes,
|
||||
uint256 expectedProtocolFeePaid,
|
||||
uint256 actualProtocolFeePaid
|
||||
)
|
||||
@@ -356,13 +290,13 @@ library LibStakingRichErrors {
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
INVALID_PROTOCOL_FEE_PAYMENT_ERROR_SELECTOR,
|
||||
errorCode,
|
||||
errorCodes,
|
||||
expectedProtocolFeePaid,
|
||||
actualProtocolFeePaid
|
||||
);
|
||||
}
|
||||
|
||||
function InvalidStakeStatusError(uint256 status)
|
||||
function InvalidStakeStatusError(IStructs.StakeStatus status)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
@@ -373,7 +307,7 @@ library LibStakingRichErrors {
|
||||
);
|
||||
}
|
||||
|
||||
function InitializationError(InitializationErrorCode code)
|
||||
function InitializationError(InitializationErrorCodes code)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
@@ -384,7 +318,7 @@ library LibStakingRichErrors {
|
||||
);
|
||||
}
|
||||
|
||||
function InvalidParamValueError(InvalidParamValueErrorCode code)
|
||||
function InvalidParamValueError(InvalidParamValueErrorCodes code)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
|
@@ -287,7 +287,7 @@ contract MixinStake is
|
||||
|
||||
// invalid status
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InvalidStakeStatusError(uint256(status))
|
||||
LibStakingRichErrors.InvalidStakeStatusError(status)
|
||||
);
|
||||
|
||||
// required to compile ~ we should never hit this.
|
||||
|
@@ -118,7 +118,7 @@ contract MixinParams is
|
||||
) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InitializationError(
|
||||
LibStakingRichErrors.InitializationErrorCode.MixinParamsAlreadyInitialized
|
||||
LibStakingRichErrors.InitializationErrorCodes.MixinParamsAlreadyInitialized
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -97,7 +97,7 @@ contract MixinScheduler is
|
||||
if (currentEpochStartTimeInSeconds != 0) {
|
||||
LibRichErrors.rrevert(
|
||||
LibStakingRichErrors.InitializationError(
|
||||
LibStakingRichErrors.InitializationErrorCode.MixinSchedulerAlreadyInitialized
|
||||
LibStakingRichErrors.InitializationErrorCodes.MixinSchedulerAlreadyInitialized
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -37,7 +37,10 @@ blockchainTests('Exchange Integrations', env => {
|
||||
const isValidAddressValid = await validExchanges.callAsync(exchange);
|
||||
expect(isValidAddressValid).to.be.true();
|
||||
// 3 try adding valid address again
|
||||
let revertError = new StakingRevertErrors.ExchangeAddressAlreadyRegisteredError(exchange);
|
||||
let revertError = new StakingRevertErrors.ExchangeManagerError(
|
||||
StakingRevertErrors.ExchangeManagerErrorCodes.ExchangeAlreadyRegistered,
|
||||
exchange,
|
||||
);
|
||||
let tx = addExchangeAddress.awaitTransactionSuccessAsync(exchange);
|
||||
await expect(tx).to.revertWith(revertError);
|
||||
// 4 remove valid address
|
||||
@@ -45,7 +48,10 @@ blockchainTests('Exchange Integrations', env => {
|
||||
const isValidAddressStillValid = await validExchanges.callAsync(exchange);
|
||||
expect(isValidAddressStillValid).to.be.false();
|
||||
// 5 try removing valid address again
|
||||
revertError = new StakingRevertErrors.ExchangeAddressNotRegisteredError(exchange);
|
||||
revertError = new StakingRevertErrors.ExchangeManagerError(
|
||||
StakingRevertErrors.ExchangeManagerErrorCodes.ExchangeNotRegistered,
|
||||
exchange,
|
||||
);
|
||||
tx = removeExchangeAddress.awaitTransactionSuccessAsync(exchange);
|
||||
await expect(tx).to.revertWith(revertError);
|
||||
// @todo should not be able to add / remove an exchange if not contract owner.
|
||||
|
@@ -224,7 +224,7 @@ blockchainTests('Migration tests', env => {
|
||||
epochDurationInSeconds: fiveDays.minus(1),
|
||||
});
|
||||
const expectedError = new StakingRevertErrors.InvalidParamValueError(
|
||||
StakingRevertErrors.InvalidParamValueErrorCode.InvalidEpochDuration,
|
||||
StakingRevertErrors.InvalidParamValueErrorCodes.InvalidEpochDuration,
|
||||
);
|
||||
expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
@@ -234,7 +234,7 @@ blockchainTests('Migration tests', env => {
|
||||
epochDurationInSeconds: thirtyDays.plus(1),
|
||||
});
|
||||
const expectedError = new StakingRevertErrors.InvalidParamValueError(
|
||||
StakingRevertErrors.InvalidParamValueErrorCode.InvalidEpochDuration,
|
||||
StakingRevertErrors.InvalidParamValueErrorCodes.InvalidEpochDuration,
|
||||
);
|
||||
expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
@@ -258,7 +258,7 @@ blockchainTests('Migration tests', env => {
|
||||
cobbDouglasAlphaDenominator: constants.ZERO_AMOUNT,
|
||||
});
|
||||
const expectedError = new StakingRevertErrors.InvalidParamValueError(
|
||||
StakingRevertErrors.InvalidParamValueErrorCode.InvalidCobbDouglasAlpha,
|
||||
StakingRevertErrors.InvalidParamValueErrorCodes.InvalidCobbDouglasAlpha,
|
||||
);
|
||||
expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
@@ -269,7 +269,7 @@ blockchainTests('Migration tests', env => {
|
||||
cobbDouglasAlphaDenominator: new BigNumber(100),
|
||||
});
|
||||
const expectedError = new StakingRevertErrors.InvalidParamValueError(
|
||||
StakingRevertErrors.InvalidParamValueErrorCode.InvalidCobbDouglasAlpha,
|
||||
StakingRevertErrors.InvalidParamValueErrorCodes.InvalidCobbDouglasAlpha,
|
||||
);
|
||||
expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
@@ -295,7 +295,7 @@ blockchainTests('Migration tests', env => {
|
||||
rewardDelegatedStakeWeight: new BigNumber(stakingConstants.PPM).plus(1),
|
||||
});
|
||||
const expectedError = new StakingRevertErrors.InvalidParamValueError(
|
||||
StakingRevertErrors.InvalidParamValueErrorCode.InvalidRewardDelegatedStakeWeight,
|
||||
StakingRevertErrors.InvalidParamValueErrorCodes.InvalidRewardDelegatedStakeWeight,
|
||||
);
|
||||
expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
@@ -312,7 +312,7 @@ blockchainTests('Migration tests', env => {
|
||||
maximumMakersInPool: constants.ZERO_AMOUNT,
|
||||
});
|
||||
const expectedError = new StakingRevertErrors.InvalidParamValueError(
|
||||
StakingRevertErrors.InvalidParamValueErrorCode.InvalidMaximumMakersInPool,
|
||||
StakingRevertErrors.InvalidParamValueErrorCodes.InvalidMaximumMakersInPool,
|
||||
);
|
||||
expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
Reference in New Issue
Block a user