Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
@0x/contracts-staking: Remove redundant "FixedMath" prefix from `…
Browse files Browse the repository at this point in the history
…FixedMath` revert errors.
  • Loading branch information
merklejerk committed Sep 4, 2019
1 parent 07398c8 commit 8ee2a07
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 41 deletions.
2 changes: 2 additions & 0 deletions contracts/staking/contracts/src/fees/MixinExchangeFees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ contract MixinExchangeFees is
/// @param makerAddress The address of the order's maker.
function payProtocolFee(
address makerAddress,
// solhint-disable-next-line
address payerAddress,
// solhint-disable-next-line
uint256 protocolFeePaid
)
external
Expand Down
22 changes: 11 additions & 11 deletions contracts/staking/contracts/src/libs/LibFixedMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ library LibFixedMath {
/// Negative results are clamped to zero.
function _uintMul(int256 f, uint256 u) internal pure returns (uint256) {
if (int256(u) < int256(0)) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathUnsignedValueError(
LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
u
));
Expand Down Expand Up @@ -112,7 +112,7 @@ library LibFixedMath {
/// Reverts if `n` is too large to fit in a fixed-point number.
function _toFixed(uint256 n) internal pure returns (int256 f) {
if (int256(n) < int256(0)) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathUnsignedValueError(
LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
n
));
Expand All @@ -124,13 +124,13 @@ library LibFixedMath {
/// Reverts if `n` / `d` is too large to fit in a fixed-point number.
function _toFixed(uint256 n, uint256 d) internal pure returns (int256 f) {
if (int256(n) < int256(0)) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathUnsignedValueError(
LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
n
));
}
if (int256(d) < int256(0)) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathUnsignedValueError(
LibRichErrors.rrevert(LibFixedMathRichErrors.UnsignedValueError(
LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
d
));
Expand All @@ -146,13 +146,13 @@ library LibFixedMath {
/// @dev Get the natural logarithm of a fixed-point number 0 < `x` <= LN_MAX_VAL
function _ln(int256 x) internal pure returns (int256 r) {
if (x > LN_MAX_VAL) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathSignedValueError(
LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
x
));
}
if (x <= 0) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathSignedValueError(
LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
LibFixedMathRichErrors.ValueErrorCodes.TOO_SMALL,
x
));
Expand Down Expand Up @@ -241,7 +241,7 @@ library LibFixedMath {
return FIXED_1;
}
if (x > EXP_MAX_VAL) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathSignedValueError(
LibRichErrors.rrevert(LibFixedMathRichErrors.SignedValueError(
LibFixedMathRichErrors.ValueErrorCodes.TOO_LARGE,
x
));
Expand Down Expand Up @@ -335,7 +335,7 @@ library LibFixedMath {
}
c = a * b;
if (c / a != b) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathBinOpError(
LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
LibFixedMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
a,
b
Expand All @@ -346,7 +346,7 @@ library LibFixedMath {
/// @dev Returns the division of two numbers, reverting on division by zero.
function __div(int256 a, int256 b) private pure returns (int256 c) {
if (b == 0) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathBinOpError(
LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
LibFixedMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
a,
b
Expand All @@ -359,14 +359,14 @@ library LibFixedMath {
function __add(int256 a, int256 b) private pure returns (int256 c) {
c = a + b;
if (c > 0 && a < 0 && b < 0) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathBinOpError(
LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
LibFixedMathRichErrors.BinOpErrorCodes.SUBTRACTION_OVERFLOW,
a,
b
));
}
if (c < 0 && a > 0 && b > 0) {
LibRichErrors.rrevert(LibFixedMathRichErrors.FixedMathBinOpError(
LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
LibFixedMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
a,
b
Expand Down
18 changes: 9 additions & 9 deletions contracts/staking/contracts/src/libs/LibFixedMathRichErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ library LibFixedMathRichErrors {
DIVISION_BY_ZERO
}

// bytes4(keccak256("FixedMathSignedValueError(uint8,int256)"))
// bytes4(keccak256("SignedValueError(uint8,int256)"))
bytes4 internal constant SIGNED_VALUE_ERROR_SELECTOR =
0x0edd9c46;
0xed2f26a1;

// bytes4(keccak256("FixedMathUnsignedValueError(uint8,uint256)"))
// bytes4(keccak256("UnsignedValueError(uint8,uint256)"))
bytes4 internal constant UNSIGNED_VALUE_ERROR_SELECTOR =
0x38e93856;
0xbd79545f;

// bytes4(keccak256("FixedMathBinOpError(uint8,int256,int256)"))
// bytes4(keccak256("BinOpError(uint8,int256,int256)"))
bytes4 internal constant BIN_OP_ERROR_SELECTOR =
0x2bd3386e;
0x8c12dfe7;

// solhint-disable func-name-mixedcase
function FixedMathSignedValueError(
function SignedValueError(
ValueErrorCodes error,
int256 n
)
Expand All @@ -63,7 +63,7 @@ library LibFixedMathRichErrors {
);
}

function FixedMathUnsignedValueError(
function UnsignedValueError(
ValueErrorCodes error,
uint256 n
)
Expand All @@ -78,7 +78,7 @@ library LibFixedMathRichErrors {
);
}

function FixedMathBinOpError(
function BinOpError(
BinOpErrorCodes error,
int256 a,
int256 b
Expand Down
42 changes: 21 additions & 21 deletions contracts/staking/test/lib_fixed_math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ blockchainTests('LibFixedMath', env => {
});

it('invert(0) throws', async () => {
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.DivisionByZero,
);
const tx = testContract.invert.callAsync(toFixed(0));
Expand Down Expand Up @@ -125,7 +125,7 @@ blockchainTests('LibFixedMath', env => {

it('mulDiv(x, y, 0) throws', async () => {
const [a, n, d] = [1.2345, 149, 0];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.DivisionByZero,
);
const tx = testContract.mulDiv.callAsync(toFixed(a), new BigNumber(n), new BigNumber(d));
Expand Down Expand Up @@ -158,7 +158,7 @@ blockchainTests('LibFixedMath', env => {

it('throws on overflow', async () => {
const [a, b] = [MAX_FIXED_VALUE, new BigNumber(1)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.AdditionOverflow,
a,
b,
Expand All @@ -169,7 +169,7 @@ blockchainTests('LibFixedMath', env => {

it('throws on underflow', async () => {
const [a, b] = [MIN_FIXED_VALUE, new BigNumber(-1)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.SubtractionUnderflow,
a,
b,
Expand Down Expand Up @@ -204,7 +204,7 @@ blockchainTests('LibFixedMath', env => {

it('throws on underflow', async () => {
const [a, b] = [MIN_FIXED_VALUE, new BigNumber(1)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.SubtractionUnderflow,
a,
b.negated(),
Expand All @@ -215,7 +215,7 @@ blockchainTests('LibFixedMath', env => {

it('throws on overflow', async () => {
const [a, b] = [MAX_FIXED_VALUE, new BigNumber(-1)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.AdditionOverflow,
a,
b.negated(),
Expand Down Expand Up @@ -266,7 +266,7 @@ blockchainTests('LibFixedMath', env => {

it('throws on underflow', async () => {
const [a, b] = [MIN_FIXED_VALUE, new BigNumber(2)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
a,
b,
Expand All @@ -277,7 +277,7 @@ blockchainTests('LibFixedMath', env => {

it('throws on overflow', async () => {
const [a, b] = [MAX_FIXED_VALUE, new BigNumber(2)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
a,
b,
Expand All @@ -298,7 +298,7 @@ blockchainTests('LibFixedMath', env => {

it('x / 0 throws', async () => {
const [a, b] = [1, 0];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.DivisionByZero,
toFixed(a).times(FIXED_POINT_DIVISOR),
toFixed(b),
Expand Down Expand Up @@ -365,7 +365,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if rhs is too large', async () => {
const [a, b] = [toFixed(1), MAX_FIXED_VALUE.plus(1)];
const expectedError = new FixedMathRevertErrors.FixedMathUnsignedValueError(
const expectedError = new FixedMathRevertErrors.UnsignedValueError(
FixedMathRevertErrors.ValueErrorCodes.TooLarge,
b,
);
Expand All @@ -375,7 +375,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if lhs is too large', async () => {
const [a, b] = [MAX_FIXED_VALUE, new BigNumber(2)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
a,
b,
Expand Down Expand Up @@ -457,7 +457,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if the numerator is too large to convert', async () => {
const [n, d] = [MAX_FIXED_VALUE.dividedToIntegerBy(FIXED_POINT_DIVISOR).plus(1), new BigNumber(1000)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
n,
FIXED_POINT_DIVISOR,
Expand All @@ -468,7 +468,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if the denominator is zero', async () => {
const [n, d] = [new BigNumber(1), new BigNumber(0)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.DivisionByZero,
n.times(FIXED_POINT_DIVISOR),
d,
Expand All @@ -493,7 +493,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if the numerator is too large', async () => {
const [n, d] = [MAX_FIXED_VALUE.plus(1), new BigNumber(1000)];
const expectedError = new FixedMathRevertErrors.FixedMathUnsignedValueError(
const expectedError = new FixedMathRevertErrors.UnsignedValueError(
FixedMathRevertErrors.ValueErrorCodes.TooLarge,
n,
);
Expand All @@ -503,7 +503,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if the denominator is too large', async () => {
const [n, d] = [new BigNumber(1000), MAX_FIXED_VALUE.plus(1)];
const expectedError = new FixedMathRevertErrors.FixedMathUnsignedValueError(
const expectedError = new FixedMathRevertErrors.UnsignedValueError(
FixedMathRevertErrors.ValueErrorCodes.TooLarge,
d,
);
Expand All @@ -513,7 +513,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if the numerator is too large to convert', async () => {
const [n, d] = [MAX_FIXED_VALUE.dividedToIntegerBy(FIXED_POINT_DIVISOR).plus(1), new BigNumber(1000)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
n,
FIXED_POINT_DIVISOR,
Expand All @@ -524,7 +524,7 @@ blockchainTests('LibFixedMath', env => {

it('throws if the denominator is zero', async () => {
const [n, d] = [new BigNumber(1), new BigNumber(0)];
const expectedError = new FixedMathRevertErrors.FixedMathBinOpError(
const expectedError = new FixedMathRevertErrors.BinOpError(
FixedMathRevertErrors.BinOpErrorCodes.DivisionByZero,
n.times(FIXED_POINT_DIVISOR),
d,
Expand Down Expand Up @@ -554,7 +554,7 @@ blockchainTests('LibFixedMath', env => {

it('ln(x = 0) throws', async () => {
const x = toFixed(0);
const expectedError = new FixedMathRevertErrors.FixedMathSignedValueError(
const expectedError = new FixedMathRevertErrors.SignedValueError(
FixedMathRevertErrors.ValueErrorCodes.TooSmall,
x,
);
Expand All @@ -564,7 +564,7 @@ blockchainTests('LibFixedMath', env => {

it('ln(x > 1) throws', async () => {
const x = toFixed(1.000001);
const expectedError = new FixedMathRevertErrors.FixedMathSignedValueError(
const expectedError = new FixedMathRevertErrors.SignedValueError(
FixedMathRevertErrors.ValueErrorCodes.TooLarge,
x,
);
Expand All @@ -574,7 +574,7 @@ blockchainTests('LibFixedMath', env => {

it('ln(x < 0) throws', async () => {
const x = toFixed(-0.000001);
const expectedError = new FixedMathRevertErrors.FixedMathSignedValueError(
const expectedError = new FixedMathRevertErrors.SignedValueError(
FixedMathRevertErrors.ValueErrorCodes.TooSmall,
x,
);
Expand Down Expand Up @@ -642,7 +642,7 @@ blockchainTests('LibFixedMath', env => {

it('exp(x > EXP_MAX_VAL) throws', async () => {
const x = toFixed(MAX_EXP_NUMBER).plus(1);
const expectedError = new FixedMathRevertErrors.FixedMathSignedValueError(
const expectedError = new FixedMathRevertErrors.SignedValueError(
FixedMathRevertErrors.ValueErrorCodes.TooLarge,
x,
);
Expand Down

0 comments on commit 8ee2a07

Please sign in to comment.