mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Updated require message errors with constant string numbers to reduce gas
This commit is contained in:
parent
cd09d04d30
commit
abe967c707
|
@ -44,6 +44,14 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
uint256 public constant MAX_STABLE_RATE_BORROW_SIZE_PERCENT = 25;
|
||||
uint256 public constant FLASHLOAN_FEE_TOTAL = 9;
|
||||
|
||||
//require error messages
|
||||
string private constant NOT_ENOUGH_STABLE_BORROW_BALANCE = '1'; // 'User does not have any stable rate loan for this reserve'
|
||||
string private constant INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET = '2'; // 'Interest rate rebalance conditions were not met'
|
||||
string private constant LIQUIDATION_CALL_FAILED = '3'; // 'Liquidation call failed'
|
||||
string private constant NOT_ENOUGH_LIQUIDITY_TO_BORROW = '4'; // 'There is not enough liquidity available to borrow'
|
||||
string private constant REQUESTED_AMOUNT_TO_SMALL = '5'; // 'The requested amount is too small for a FlashLoan.'
|
||||
string private constant INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '6'; // 'The actual balance of the protocol is inconsistent'
|
||||
|
||||
ILendingPoolAddressesProvider internal _addressesProvider;
|
||||
|
||||
mapping(address => ReserveLogic.ReserveData) internal _reserves;
|
||||
|
@ -195,8 +203,14 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
|
||||
reserve.updateCumulativeIndexesAndTimestamp();
|
||||
|
||||
if (ReserveLogic.InterestRateMode(interestRateMode) == ReserveLogic.InterestRateMode.STABLE) {
|
||||
IStableDebtToken(reserve.stableDebtTokenAddress).mint(msg.sender, amount, userStableRate);
|
||||
if (
|
||||
ReserveLogic.InterestRateMode(interestRateMode) == ReserveLogic.InterestRateMode.STABLE
|
||||
) {
|
||||
IStableDebtToken(reserve.stableDebtTokenAddress).mint(
|
||||
msg.sender,
|
||||
amount,
|
||||
userStableRate
|
||||
);
|
||||
} else {
|
||||
IVariableDebtToken(reserve.variableDebtTokenAddress).mint(msg.sender, amount);
|
||||
}
|
||||
|
@ -240,7 +254,10 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
) external override nonReentrant {
|
||||
ReserveLogic.ReserveData storage reserve = _reserves[asset];
|
||||
|
||||
(uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(onBehalfOf, reserve);
|
||||
(uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(
|
||||
onBehalfOf,
|
||||
reserve
|
||||
);
|
||||
|
||||
ReserveLogic.InterestRateMode interestRateMode = ReserveLogic.InterestRateMode(rateMode);
|
||||
|
||||
|
@ -291,7 +308,10 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
function swapBorrowRateMode(address asset, uint256 rateMode) external override nonReentrant {
|
||||
ReserveLogic.ReserveData storage reserve = _reserves[asset];
|
||||
|
||||
(uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(msg.sender, reserve);
|
||||
(uint256 stableDebt, uint256 variableDebt) = Helpers.getUserCurrentDebt(
|
||||
msg.sender,
|
||||
reserve
|
||||
);
|
||||
|
||||
ReserveLogic.InterestRateMode interestRateMode = ReserveLogic.InterestRateMode(rateMode);
|
||||
|
||||
|
@ -344,7 +364,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
uint256 stableBorrowBalance = IERC20(address(stableDebtToken)).balanceOf(user);
|
||||
|
||||
// user must be borrowing on asset at a stable rate
|
||||
require(stableBorrowBalance > 0, 'User does not have any stable rate loan for this reserve');
|
||||
require(stableBorrowBalance > 0, NOT_ENOUGH_STABLE_BORROW_BALANCE);
|
||||
|
||||
uint256 rebalanceDownRateThreshold = reserve.currentStableBorrowRate.rayMul(
|
||||
WadRayMath.ray().add(REBALANCE_DOWN_RATE_DELTA)
|
||||
|
@ -358,8 +378,9 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
uint256 userStableRate = stableDebtToken.getUserStableRate(user);
|
||||
|
||||
require(
|
||||
userStableRate < reserve.currentLiquidityRate || userStableRate > rebalanceDownRateThreshold,
|
||||
'Interest rate rebalance conditions were not met'
|
||||
userStableRate < reserve.currentLiquidityRate ||
|
||||
userStableRate > rebalanceDownRateThreshold,
|
||||
INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET
|
||||
);
|
||||
|
||||
//burn old debt tokens, mint new ones
|
||||
|
@ -435,7 +456,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
receiveAToken
|
||||
)
|
||||
);
|
||||
require(success, 'Liquidation call failed');
|
||||
require(success, LIQUIDATION_CALL_FAILED);
|
||||
|
||||
(uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string));
|
||||
|
||||
|
@ -469,11 +490,8 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
//calculate amount fee
|
||||
uint256 amountFee = amount.mul(FLASHLOAN_FEE_TOTAL).div(10000);
|
||||
|
||||
require(
|
||||
availableLiquidityBefore >= amount,
|
||||
'There is not enough liquidity available to borrow'
|
||||
);
|
||||
require(amountFee > 0, 'The requested amount is too small for a FlashLoan.');
|
||||
require(availableLiquidityBefore >= amount, NOT_ENOUGH_LIQUIDITY_TO_BORROW);
|
||||
require(amountFee > 0, REQUESTED_AMOUNT_TO_SMALL);
|
||||
|
||||
//get the FlashLoanReceiver instance
|
||||
IFlashLoanReceiver receiver = IFlashLoanReceiver(receiverAddress);
|
||||
|
@ -489,7 +507,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
|
||||
require(
|
||||
availableLiquidityAfter == availableLiquidityBefore.add(amountFee),
|
||||
'The actual balance of the protocol is inconsistent'
|
||||
INCONSISTENT_PROTOCOL_ACTUAL_BALANCE
|
||||
);
|
||||
|
||||
//compounding the cumulated interest
|
||||
|
@ -659,7 +677,9 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
user
|
||||
);
|
||||
usageAsCollateralEnabled = _usersConfig[user].isUsingAsCollateral(reserve.index);
|
||||
variableBorrowIndex = IVariableDebtToken(reserve.variableDebtTokenAddress).getUserIndex(user);
|
||||
variableBorrowIndex = IVariableDebtToken(reserve.variableDebtTokenAddress).getUserIndex(
|
||||
user
|
||||
);
|
||||
}
|
||||
|
||||
function getReserves() external override view returns (address[] memory) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user