Cleanup rich reverts

This commit is contained in:
Amir Bandeali
2019-09-24 18:13:30 -07:00
parent e5aaf68277
commit 57f5b12e24
9 changed files with 59 additions and 198 deletions

View File

@@ -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
));
}
}

View File

@@ -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
));
}

View File

@@ -34,12 +34,12 @@ library LibStakingRichErrors {
MismatchedFeeAndPayment
}
enum InitializationErrorCode {
enum InitializationErrorCodes {
MixinSchedulerAlreadyInitialized,
MixinParamsAlreadyInitialized
}
enum InvalidParamValueErrorCode {
enum InvalidParamValueErrorCodes {
InvalidCobbDouglasAlpha,
InvalidRewardDelegatedStakeWeight,
InvalidMaximumMakersInPool,
@@ -54,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 =
@@ -82,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;
@@ -102,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;
@@ -139,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
)
@@ -167,7 +141,8 @@ library LibStakingRichErrors {
);
}
function ExchangeAddressAlreadyRegisteredError(
function ExchangeManagerError(
ExchangeManagerErrorCodes errorCodes,
address exchangeAddress
)
internal
@@ -175,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
);
}
@@ -224,7 +187,7 @@ library LibStakingRichErrors {
}
function MakerPoolAssignmentError(
MakerPoolAssignmentErrorCodes errorCode,
MakerPoolAssignmentErrorCodes errorCodes,
address makerAddress,
bytes32 poolId
)
@@ -234,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
@@ -299,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
)
@@ -325,7 +258,7 @@ library LibStakingRichErrors {
{
return abi.encodeWithSelector(
OPERATOR_SHARE_ERROR_SELECTOR,
errorCode,
errorCodes,
poolId,
operatorShare
);
@@ -347,7 +280,7 @@ library LibStakingRichErrors {
}
function InvalidProtocolFeePaymentError(
ProtocolFeePaymentErrorCodes errorCode,
ProtocolFeePaymentErrorCodes errorCodes,
uint256 expectedProtocolFeePaid,
uint256 actualProtocolFeePaid
)
@@ -357,7 +290,7 @@ library LibStakingRichErrors {
{
return abi.encodeWithSelector(
INVALID_PROTOCOL_FEE_PAYMENT_ERROR_SELECTOR,
errorCode,
errorCodes,
expectedProtocolFeePaid,
actualProtocolFeePaid
);
@@ -374,7 +307,7 @@ library LibStakingRichErrors {
);
}
function InitializationError(InitializationErrorCode code)
function InitializationError(InitializationErrorCodes code)
internal
pure
returns (bytes memory)
@@ -385,7 +318,7 @@ library LibStakingRichErrors {
);
}
function InvalidParamValueError(InvalidParamValueErrorCode code)
function InvalidParamValueError(InvalidParamValueErrorCodes code)
internal
pure
returns (bytes memory)

View File

@@ -118,7 +118,7 @@ contract MixinParams is
) {
LibRichErrors.rrevert(
LibStakingRichErrors.InitializationError(
LibStakingRichErrors.InitializationErrorCode.MixinParamsAlreadyInitialized
LibStakingRichErrors.InitializationErrorCodes.MixinParamsAlreadyInitialized
)
);
}

View File

@@ -97,7 +97,7 @@ contract MixinScheduler is
if (currentEpochStartTimeInSeconds != 0) {
LibRichErrors.rrevert(
LibStakingRichErrors.InitializationError(
LibStakingRichErrors.InitializationErrorCode.MixinSchedulerAlreadyInitialized
LibStakingRichErrors.InitializationErrorCodes.MixinSchedulerAlreadyInitialized
)
);
}

View File

@@ -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.

View File

@@ -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);
});