mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Refactored as per the PR comments
This commit is contained in:
parent
288d8f2889
commit
714c2ff3fd
|
@ -56,7 +56,10 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
* @dev only lending pools configurator can use functions affected by this modifier
|
||||
**/
|
||||
modifier onlyLendingPoolConfigurator {
|
||||
require(_addressesProvider.getLendingPoolConfigurator() == msg.sender, '30');
|
||||
require(
|
||||
_addressesProvider.getLendingPoolConfigurator() == msg.sender,
|
||||
Errors.CALLER_NOT_LENDING_POOL_CONFIGURATOR
|
||||
);
|
||||
_;
|
||||
}
|
||||
|
||||
|
@ -360,7 +363,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
|
||||
require(
|
||||
userStableRate < reserve.currentLiquidityRate || userStableRate > rebalanceDownRateThreshold,
|
||||
Errors.INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET
|
||||
Errors.INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET
|
||||
);
|
||||
|
||||
//burn old debt tokens, mint new ones
|
||||
|
@ -471,7 +474,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool {
|
|||
uint256 amountFee = amount.mul(FLASHLOAN_FEE_TOTAL).div(10000);
|
||||
|
||||
require(availableLiquidityBefore >= amount, Errors.NOT_ENOUGH_LIQUIDITY_TO_BORROW);
|
||||
require(amountFee > 0, Errors.REQUESTED_AMOUNT_TO_SMALL);
|
||||
require(amountFee > 0, Errors.REQUESTED_AMOUNT_TOO_SMALL);
|
||||
|
||||
//get the FlashLoanReceiver instance
|
||||
IFlashLoanReceiver receiver = IFlashLoanReceiver(receiverAddress);
|
||||
|
|
|
@ -15,7 +15,7 @@ library Errors {
|
|||
string public constant NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance'
|
||||
string public constant TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.'
|
||||
string public constant BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled'
|
||||
string public constant INVALID_INTERESTRATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected'
|
||||
string public constant INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected'
|
||||
string public constant COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0'
|
||||
string public constant HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold'
|
||||
string public constant COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow'
|
||||
|
@ -23,7 +23,7 @@ library Errors {
|
|||
string public constant CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed
|
||||
string public constant AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // 'The requested amount is greater than the max loan size in stable rate mode
|
||||
string public constant NO_DEBT_OF_SELECTED_TYPE = '15'; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
|
||||
string public constant NO_EPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed'
|
||||
string public constant NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed'
|
||||
string public constant NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve'
|
||||
string public constant NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve'
|
||||
string public constant UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0'
|
||||
|
@ -31,34 +31,35 @@ library Errors {
|
|||
|
||||
// require error messages - LendingPool
|
||||
string public constant NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve'
|
||||
string public constant INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met'
|
||||
string public constant INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met'
|
||||
string public constant LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed'
|
||||
string public constant NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow'
|
||||
string public constant REQUESTED_AMOUNT_TO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.'
|
||||
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'
|
||||
|
||||
// require error messages - aToken
|
||||
string public constant CALLER_MUST_BE_LENDING_POOL = '27'; // 'The caller of this function must be a lending pool'
|
||||
string public constant NOT_ALLOWED_TO_REDIRECT_INTEREST = '28'; // 'Caller is not allowed to redirect the interest of the user'
|
||||
string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '29'; // 'User cannot give allowance to himself'
|
||||
string public constant TRANSFER_AMOUNT_NOT_GT_0 = '30'; // 'Transferred amount needs to be greater than zero'
|
||||
string public constant INTEREST_ALREADY_REDIRECTED = '31'; // 'Interest is already redirected to the user'
|
||||
string public constant NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '32'; // 'Interest stream can only be redirected if there is a valid balance'
|
||||
string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool'
|
||||
string public constant INTEREST_REDIRECTION_NOT_ALLOWED = '29'; // 'Caller is not allowed to redirect the interest of the user'
|
||||
string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
|
||||
string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
|
||||
string public constant INTEREST_ALREADY_REDIRECTED = '32'; // 'Interest is already redirected to the user'
|
||||
string public constant NO_VALID_BALANCE_FOR_REDIRECTION = '33'; // 'Interest stream can only be redirected if there is a valid balance'
|
||||
|
||||
// require error messages - ReserveLogic
|
||||
string public constant RESERVE_ALREADY_INITIALIZED = '33'; // 'Reserve has already been initialized'
|
||||
string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized'
|
||||
|
||||
//require error messages - LendingPoolConfiguration
|
||||
string public constant CALLER_NOT_LENDING_POOL_MANAGER = '34'; // 'The caller must be a lending pool manager'
|
||||
string public constant RESERVE_LIQUIDITY_NOT_0 = '35'; // 'The liquidity of the reserve needs to be 0'
|
||||
string public constant CALLER_NOT_LENDING_POOL_MANAGER = '35'; // 'The caller must be a lending pool manager'
|
||||
string public constant RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0'
|
||||
|
||||
//require error messages - LendingPoolAddressesProviderRegistry
|
||||
string public constant PROVIDER_NOT_REGISTERED = '36'; // 'Provider is not registered'
|
||||
string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered'
|
||||
|
||||
//return error messages - LendingPoolLiquidationManager
|
||||
string public constant HEALTH_FACTOR_NOT_BELLOW_THRESHOLD = '37'; // 'Health factor is not below the threshold'
|
||||
string public constant COLLATERAL_CANNOT_BE_LIQUIDATED = '38'; // 'The collateral chosen cannot be liquidated'
|
||||
string public constant SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '39'; // 'User did not borrow the specified currency'
|
||||
string public constant NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '40'; // "There isn't enough liquidity available to liquidate"
|
||||
string public constant NO_ERRORS = '41'; // 'No errors'
|
||||
string public constant HEALTH_FACTOR_NOT_BELLOW_THRESHOLD = '38'; // 'Health factor is not below the threshold'
|
||||
string public constant COLLATERAL_CANNOT_BE_LIQUIDATED = '39'; // 'The collateral chosen cannot be liquidated'
|
||||
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'
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ library ValidationLogic {
|
|||
require(
|
||||
uint256(ReserveLogic.InterestRateMode.VARIABLE) == interestRateMode ||
|
||||
uint256(ReserveLogic.InterestRateMode.STABLE) == interestRateMode,
|
||||
Errors.INVALID_INTERESTRATE_MODE_SELECTED
|
||||
Errors.INVALID_INTEREST_RATE_MODE_SELECTED
|
||||
);
|
||||
|
||||
//check that the amount is available in the reserve
|
||||
|
@ -245,7 +245,7 @@ library ValidationLogic {
|
|||
|
||||
require(
|
||||
amountSent != uint256(-1) || msg.sender == onBehalfOf,
|
||||
Errors.NO_EPLICIT_AMOUNT_TO_REPAY_ON_BEHALF
|
||||
Errors.NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ library ValidationLogic {
|
|||
Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY
|
||||
);
|
||||
} else {
|
||||
revert(Errors.INVALID_INTERESTRATE_MODE_SELECTED);
|
||||
revert(Errors.INVALID_INTEREST_RATE_MODE_SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
|
|||
function redirectInterestStreamOf(address from, address to) external override {
|
||||
require(
|
||||
msg.sender == _interestRedirectionAllowances[from],
|
||||
Errors.NOT_ALLOWED_TO_REDIRECT_INTEREST
|
||||
Errors.INTEREST_REDIRECTION_NOT_ALLOWED
|
||||
);
|
||||
_redirectInterestStream(from, to);
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ contract AToken is VersionedInitializable, ERC20, IAToken {
|
|||
uint256 fromIndex
|
||||
) = _cumulateBalance(from);
|
||||
|
||||
require(fromBalance > 0, Errors.NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM);
|
||||
require(fromBalance > 0, Errors.NO_VALID_BALANCE_FOR_REDIRECTION);
|
||||
|
||||
//if the user is already redirecting the interest to someone, before changing
|
||||
//the redirection address we substract the redirected balance of the previous
|
||||
|
|
|
@ -52,7 +52,7 @@ export enum ProtocolErrors {
|
|||
NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5', // 'User cannot withdraw more than the available balance'
|
||||
TRANSFER_NOT_ALLOWED = '6', // 'Transfer cannot be allowed.'
|
||||
BORROWING_NOT_ENABLED = '7', // 'Borrowing is not enabled'
|
||||
INVALID_INTERESTRATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected'
|
||||
INVALID_INTEREST_RATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected'
|
||||
COLLATERAL_BALANCE_IS_0 = '9', // 'The collateral balance is 0'
|
||||
HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10', // 'Health factor is lesser than the liquidation threshold'
|
||||
COLLATERAL_CANNOT_COVER_NEW_BORROW = '11', // 'There is not enough collateral to cover a new borrow'
|
||||
|
@ -60,7 +60,7 @@ export enum ProtocolErrors {
|
|||
CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13', // collateral is (mostly) the same currency that is being borrowed
|
||||
AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14', // 'The requested amount is greater than the max loan size in stable rate mode
|
||||
NO_DEBT_OF_SELECTED_TYPE = '15', // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
|
||||
NO_EPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16', // 'To repay on behalf of an user an explicit amount to repay is needed'
|
||||
NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16', // 'To repay on behalf of an user an explicit amount to repay is needed'
|
||||
NO_STABLE_RATE_LOAN_IN_RESERVE = '17', // 'User does not have a stable rate loan in progress on this reserve'
|
||||
NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18', // 'User does not have a variable rate loan in progress on this reserve'
|
||||
UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19', // 'The underlying balance needs to be greater than 0'
|
||||
|
@ -68,36 +68,37 @@ export enum ProtocolErrors {
|
|||
|
||||
// require error messages - LendingPool
|
||||
NOT_ENOUGH_STABLE_BORROW_BALANCE = '21', // 'User does not have any stable rate loan for this reserve'
|
||||
INTERESTRATE_REBALANCE_CONDITIONS_NOT_MET = '22', // 'Interest rate rebalance conditions were not met'
|
||||
INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22', // 'Interest rate rebalance conditions were not met'
|
||||
LIQUIDATION_CALL_FAILED = '23', // 'Liquidation call failed'
|
||||
NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24', // 'There is not enough liquidity available to borrow'
|
||||
REQUESTED_AMOUNT_TO_SMALL = '25', // 'The requested amount is too small for a FlashLoan.'
|
||||
REQUESTED_AMOUNT_TOO_SMALL = '25', // 'The requested amount is too small for a FlashLoan.'
|
||||
INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26', // 'The actual balance of the protocol is inconsistent'
|
||||
CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27', // 'The actual balance of the protocol is inconsistent'
|
||||
|
||||
// require error messages - aToken
|
||||
CALLER_MUST_BE_LENDING_POOL = '27', // 'The caller of this function must be a lending pool'
|
||||
NOT_ALLOWED_TO_REDIRECT_INTEREST = '28', // 'Caller is not allowed to redirect the interest of the user'
|
||||
CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '29', // 'User cannot give allowance to himself'
|
||||
TRANSFER_AMOUNT_NOT_GT_0 = '30', // 'Transferred amount needs to be greater than zero'
|
||||
INTEREST_ALREADY_REDIRECTED = '31', // 'Interest is already redirected to the user'
|
||||
NO_VALID_BALANCE_FOR_REDIRECT_INT_STREAM = '32', // 'Interest stream can only be redirected if there is a valid balance'
|
||||
CALLER_MUST_BE_LENDING_POOL = '28', // 'The caller of this function must be a lending pool'
|
||||
INTEREST_REDIRECTION_NOT_ALLOWED = '29', // 'Caller is not allowed to redirect the interest of the user'
|
||||
CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
|
||||
TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
|
||||
INTEREST_ALREADY_REDIRECTED = '32', // 'Interest is already redirected to the user'
|
||||
NO_VALID_BALANCE_FOR_REDIRECTION = '33', // 'Interest stream can only be redirected if there is a valid balance'
|
||||
|
||||
// require error messages - ReserveLogic
|
||||
RESERVE_ALREADY_INITIALIZED = '33', // 'Reserve has already been initialized'
|
||||
RESERVE_ALREADY_INITIALIZED = '34', // 'Reserve has already been initialized'
|
||||
|
||||
//require error messages - LendingPoolConfiguration
|
||||
CALLER_NOT_LENDING_POOL_MANAGER = '34', // 'The caller must be a lending pool manager'
|
||||
RESERVE_LIQUIDITY_NOT_0 = '35', // 'The liquidity of the reserve needs to be 0'
|
||||
CALLER_NOT_LENDING_POOL_MANAGER = '35', // 'The caller must be a lending pool manager'
|
||||
RESERVE_LIQUIDITY_NOT_0 = '36', // 'The liquidity of the reserve needs to be 0'
|
||||
|
||||
//require error messages - LendingPoolAddressesProviderRegistry
|
||||
PROVIDER_NOT_REGISTERED = '36', // 'Provider is not registered'
|
||||
PROVIDER_NOT_REGISTERED = '37', // 'Provider is not registered'
|
||||
|
||||
//return error messages - LendingPoolLiquidationManager
|
||||
HEALTH_FACTOR_NOT_BELLOW_THRESHOLD = '37', // 'Health factor is not below the threshold'
|
||||
COLLATERAL_CANNOT_BE_LIQUIDATED = '38', // 'The collateral chosen cannot be liquidated'
|
||||
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '39', // 'User did not borrow the specified currency'
|
||||
NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '40', // "There isn't enough liquidity available to liquidate"
|
||||
NO_ERRORS = '41', // 'No errors'
|
||||
HEALTH_FACTOR_NOT_BELLOW_THRESHOLD = '38', // 'Health factor is not below the threshold'
|
||||
COLLATERAL_CANNOT_BE_LIQUIDATED = '39', // 'The collateral chosen cannot be liquidated'
|
||||
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40', // 'User did not borrow the specified currency'
|
||||
NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41', // "There isn't enough liquidity available to liquidate"
|
||||
NO_ERRORS = '42', // 'No errors'
|
||||
|
||||
// old
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
|||
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
|
||||
const {
|
||||
INCONSISTENT_PROTOCOL_ACTUAL_BALANCE,
|
||||
REQUESTED_AMOUNT_TO_SMALL,
|
||||
REQUESTED_AMOUNT_TOO_SMALL,
|
||||
NOT_ENOUGH_LIQUIDITY_TO_BORROW,
|
||||
} = ProtocolErrors;
|
||||
|
||||
|
@ -112,7 +112,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
|||
'1', //1 wei loan
|
||||
'0x10'
|
||||
)
|
||||
).to.be.revertedWith(REQUESTED_AMOUNT_TO_SMALL);
|
||||
).to.be.revertedWith(REQUESTED_AMOUNT_TOO_SMALL);
|
||||
});
|
||||
|
||||
it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user