Refactored error messages

This commit is contained in:
The3D 2020-09-04 12:48:29 +02:00
parent 7456656b28
commit 58488158cd
4 changed files with 36 additions and 21 deletions

View File

@ -37,6 +37,7 @@ library Errors {
string public constant REQUESTED_AMOUNT_TOO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.'
string public constant INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent'
string public constant CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The actual balance of the protocol is inconsistent'
string public constant INVALID_FLASHLOAN_MODE = '43'; //Invalid flashloan mode selected
// require error messages - aToken
string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool'
@ -48,6 +49,11 @@ library Errors {
// require error messages - ReserveLogic
string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized'
string public constant LIQUIDITY_INDEX_OVERFLOW = '47'; // Liquidity index overflows uint128
string public constant VARIABLE_BORROW_INDEX_OVERFLOW = '48'; // Variable borrow index overflows uint128
string public constant LIQUIDITY_RATE_OVERFLOW = '49'; // Liquidity rate overflows uint128
string public constant VARIABLE_BORROW_RATE_OVERFLOW = '50'; // Variable borrow rate overflows uint128
string public constant STABLE_BORROW_RATE_OVERFLOW = '51'; // Stable borrow rate overflows uint128
//require error messages - LendingPoolConfiguration
string public constant CALLER_NOT_LENDING_POOL_MANAGER = '35'; // 'The caller must be a lending pool manager'
@ -62,5 +68,9 @@ library Errors {
string public constant SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40'; // 'User did not borrow the specified currency'
string public constant NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41'; // "There isn't enough liquidity available to liquidate"
string public constant NO_ERRORS = '42'; // 'No errors'
string public constant INVALID_FLASHLOAN_MODE = '43'; //Invalid flashloan mode selected
//require error messages - Math libraries
string public constant MULTIPLICATION_OVERFLOW = '44';
string public constant ADDITION_OVERFLOW = '45';
string public constant DIVISION_BY_ZERO = '46';
}

View File

@ -133,7 +133,7 @@ library ReserveLogic {
lastUpdateTimestamp
);
uint256 index = cumulatedLiquidityInterest.rayMul(reserve.lastLiquidityIndex);
require(index < (1 << 128), "ReserveLogic: Liquidity index overflow");
require(index < (1 << 128), Errors.LIQUIDITY_INDEX_OVERFLOW);
reserve.lastLiquidityIndex = uint128(index);
@ -147,7 +147,7 @@ library ReserveLogic {
index = cumulatedVariableBorrowInterest.rayMul(
reserve.lastVariableBorrowIndex
);
require(index < (1 << 128), "ReserveLogic: Variable borrow index overflow");
require(index < (1 << 128), Errors.VARIABLE_BORROW_INDEX_OVERFLOW);
reserve.lastVariableBorrowIndex = uint128(index);
}
}
@ -175,7 +175,7 @@ library ReserveLogic {
result = result.rayMul(
reserve.lastLiquidityIndex
);
require(result < (1 << 128), "ReserveLogic: Liquidity index overflow");
require(result < (1 << 128), Errors.LIQUIDITY_INDEX_OVERFLOW);
reserve.lastLiquidityIndex = uint128(result);
}

View File

@ -1,6 +1,9 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;
import {Errors} from '../helpers/Errors.sol';
/**
* @title PercentageMath library
* @author Aave
@ -27,11 +30,11 @@ library PercentageMath {
uint256 result = value*percentage;
require(result/value == percentage, "PercentageMath: Multiplication overflow");
require(result/value == percentage, Errors.MULTIPLICATION_OVERFLOW);
result+=HALF_PERCENT;
require(result >= HALF_PERCENT, "PercentageMath: Addition overflow");
require(result >= HALF_PERCENT, Errors.ADDITION_OVERFLOW);
return result/PERCENTAGE_FACTOR;
}
@ -43,16 +46,16 @@ library PercentageMath {
* @return the value divided the percentage
**/
function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {
require(percentage != 0, "PercentageMath: Division by 0");
require(percentage != 0, Errors.DIVISION_BY_ZERO);
uint256 halfPercentage = percentage / 2;
uint256 result = value*PERCENTAGE_FACTOR;
require(result/PERCENTAGE_FACTOR == value, "PercentageMath: Multiplication overflow");
require(result/PERCENTAGE_FACTOR == value, Errors.MULTIPLICATION_OVERFLOW);
result += halfPercentage;
require(result >= halfPercentage, "PercentageMath: Addition overflow");
require(result >= halfPercentage, Errors.ADDITION_OVERFLOW);
return result/percentage;
}

View File

@ -1,6 +1,8 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;
import {Errors} from '../helpers/Errors.sol';
/**
* @title WadRayMath library
* @author Aave
@ -60,11 +62,11 @@ library WadRayMath {
uint256 result = a*b;
require(result/a == b, "WadRayMath: Multiplication overflow");
require(result/a == b, Errors.MULTIPLICATION_OVERFLOW);
result+=halfWAD;
require(result >= halfWAD, "WadRayMath: Addition overflow");
require(result >= halfWAD, Errors.ADDITION_OVERFLOW);
return result/WAD;
}
@ -76,17 +78,17 @@ library WadRayMath {
* @return the result of a/b, in wad
**/
function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "WadRayMath: Division by 0");
require(b != 0, Errors.DIVISION_BY_ZERO);
uint256 halfB = b / 2;
uint256 result = a*WAD;
require(result/WAD == a, "WadRayMath: Multiplication overflow");
require(result/WAD == a, Errors.MULTIPLICATION_OVERFLOW);
result += halfB;
require(result >= halfB, "WadRayMath: Addition overflow");
require(result >= halfB, Errors.ADDITION_OVERFLOW);
return result/b;
}
@ -104,11 +106,11 @@ library WadRayMath {
uint256 result = a*b;
require(result/a == b, "WadRayMath: Multiplication overflow");
require(result/a == b, Errors.MULTIPLICATION_OVERFLOW);
result+=halfRAY;
require(result >= halfRAY, "WadRayMath: Addition overflow");
require(result >= halfRAY, Errors.ADDITION_OVERFLOW);
return result/RAY;
}
@ -120,17 +122,17 @@ library WadRayMath {
* @return the result of a/b, in ray
**/
function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "WadRayMath: Division by 0");
require(b != 0, Errors.DIVISION_BY_ZERO);
uint256 halfB = b / 2;
uint256 result = a*RAY;
require(result/RAY == a, "WadRayMath: Multiplication overflow");
require(result/RAY == a, Errors.MULTIPLICATION_OVERFLOW);
result += halfB;
require(result >= halfB, "WadRayMath: Addition overflow");
require(result >= halfB, Errors.ADDITION_OVERFLOW);
return result/b;
@ -144,7 +146,7 @@ library WadRayMath {
function rayToWad(uint256 a) internal pure returns (uint256) {
uint256 halfRatio = WAD_RAY_RATIO / 2;
uint256 result = halfRatio+a;
require(result >= halfRatio, "WadRayMath: Addition overflow");
require(result >= halfRatio, Errors.ADDITION_OVERFLOW);
return result/WAD_RAY_RATIO;
}
@ -156,7 +158,7 @@ library WadRayMath {
**/
function wadToRay(uint256 a) internal pure returns (uint256) {
uint256 result = a*WAD_RAY_RATIO;
require(result/WAD_RAY_RATIO == a, "WadRayMath: Multiplication overflow");
require(result/WAD_RAY_RATIO == a, Errors.MULTIPLICATION_OVERFLOW);
return result;
}
}