From 288d8f288973c25da696f83f0c5296fb5541e953 Mon Sep 17 00:00:00 2001
From: pol <>
Date: Wed, 2 Sep 2020 18:53:39 +0200
Subject: [PATCH] Added LendingPoolLiquidationManager error messages to error
 lib, and updated tests.

---
 .../lendingpool/LendingPoolLiquidationManager.sol    | 11 ++++++-----
 contracts/libraries/helpers/Errors.sol               |  7 +++++++
 helpers/types.ts                                     | 10 +++++++---
 test/liquidation-atoken.spec.ts                      | 12 ++++++------
 test/liquidation-underlying.spec.ts                  | 11 +++--------
 5 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/contracts/lendingpool/LendingPoolLiquidationManager.sol b/contracts/lendingpool/LendingPoolLiquidationManager.sol
index a36ed3f3..27a29277 100644
--- a/contracts/lendingpool/LendingPoolLiquidationManager.sol
+++ b/contracts/lendingpool/LendingPoolLiquidationManager.sol
@@ -21,6 +21,7 @@ import {Helpers} from '../libraries/helpers/Helpers.sol';
 import {WadRayMath} from '../libraries/math/WadRayMath.sol';
 import {PercentageMath} from '../libraries/math/PercentageMath.sol';
 import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
+import {Errors} from '../libraries/helpers/Errors.sol';
 
 /**
  * @title LendingPoolLiquidationManager contract
@@ -132,7 +133,7 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
     if (vars.healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
       return (
         uint256(LiquidationErrors.HEALTH_FACTOR_ABOVE_THRESHOLD),
-        'Health factor is not below the threshold'
+        Errors.HEALTH_FACTOR_NOT_BELLOW_THRESHOLD
       );
     }
 
@@ -148,7 +149,7 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
     if (!vars.isCollateralEnabled) {
       return (
         uint256(LiquidationErrors.COLLATERAL_CANNOT_BE_LIQUIDATED),
-        'The collateral chosen cannot be liquidated'
+        Errors.COLLATERAL_CANNOT_BE_LIQUIDATED
       );
     }
 
@@ -161,7 +162,7 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
     if (vars.userStableDebt == 0 && vars.userVariableDebt == 0) {
       return (
         uint256(LiquidationErrors.CURRRENCY_NOT_BORROWED),
-        'User did not borrow the specified currency'
+        Errors.SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER
       );
     }
 
@@ -202,7 +203,7 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
       if (currentAvailableCollateral < vars.maxCollateralToLiquidate) {
         return (
           uint256(LiquidationErrors.NOT_ENOUGH_LIQUIDITY),
-          "There isn't enough liquidity available to liquidate"
+          Errors.NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE
         );
       }
     }
@@ -268,7 +269,7 @@ contract LendingPoolLiquidationManager is ReentrancyGuard, VersionedInitializabl
       receiveAToken
     );
 
-    return (uint256(LiquidationErrors.NO_ERROR), 'No errors');
+    return (uint256(LiquidationErrors.NO_ERROR), Errors.NO_ERRORS);
   }
 
   struct AvailableCollateralToLiquidateLocalVars {
diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol
index 388ea88f..1b3f6980 100644
--- a/contracts/libraries/helpers/Errors.sol
+++ b/contracts/libraries/helpers/Errors.sol
@@ -54,4 +54,11 @@ library Errors {
 
   //require error messages - LendingPoolAddressesProviderRegistry
   string public constant PROVIDER_NOT_REGISTERED = '36'; // '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'
 }
diff --git a/helpers/types.ts b/helpers/types.ts
index 713b9510..e98e5a3c 100644
--- a/helpers/types.ts
+++ b/helpers/types.ts
@@ -92,6 +92,13 @@ export enum ProtocolErrors {
   //require error messages - LendingPoolAddressesProviderRegistry
   PROVIDER_NOT_REGISTERED = '36', // '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'
+
   // old
 
   INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
@@ -100,10 +107,7 @@ export enum ProtocolErrors {
   INVALID_REDIRECTED_BALANCE_BEFORE_TRANSFER = 'Invalid redirected balance before transfer',
   INVALID_REDIRECTED_BALANCE_AFTER_TRANSFER = 'Invalid redirected balance after transfer',
   INVALID_REDIRECTION_ADDRESS = 'Invalid redirection address',
-  HF_IS_NOT_BELLOW_THRESHOLD = 'Health factor is not below the threshold',
   INVALID_HF = 'Invalid health factor',
-  USER_DID_NOT_BORROW_SPECIFIED = 'User did not borrow the specified currency',
-  THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED = 'The collateral chosen cannot be liquidated',
 }
 
 export type tEthereumAddress = string;
diff --git a/test/liquidation-atoken.spec.ts b/test/liquidation-atoken.spec.ts
index 6e4af1e1..155b7c25 100644
--- a/test/liquidation-atoken.spec.ts
+++ b/test/liquidation-atoken.spec.ts
@@ -13,10 +13,10 @@ const {expect} = chai;
 
 makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => {
   const {
-    HF_IS_NOT_BELLOW_THRESHOLD,
+    HEALTH_FACTOR_NOT_BELLOW_THRESHOLD,
     INVALID_HF,
-    USER_DID_NOT_BORROW_SPECIFIED,
-    THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED,
+    SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER,
+    COLLATERAL_CANNOT_BE_LIQUIDATED,
   } = ProtocolErrors;
 
   it('LIQUIDATION - Deposits WETH, borrows DAI/Check liquidation fails because health factor is above 1', async () => {
@@ -71,7 +71,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
     //someone tries to liquidate user 2
     await expect(
       pool.liquidationCall(weth.address, dai.address, borrower.address, 1, true)
-    ).to.be.revertedWith(HF_IS_NOT_BELLOW_THRESHOLD);
+    ).to.be.revertedWith(HEALTH_FACTOR_NOT_BELLOW_THRESHOLD);
   });
 
   it('LIQUIDATION - Drop the health factor below 1', async () => {
@@ -96,7 +96,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
     //user 2 tries to borrow
     await expect(
       pool.liquidationCall(weth.address, weth.address, borrower.address, oneEther.toString(), true)
-    ).revertedWith(USER_DID_NOT_BORROW_SPECIFIED);
+    ).revertedWith(SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER);
   });
 
   it('LIQUIDATION - Tries to liquidate a different collateral than the borrower collateral', async () => {
@@ -105,7 +105,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
 
     await expect(
       pool.liquidationCall(dai.address, dai.address, borrower.address, oneEther.toString(), true)
-    ).revertedWith(THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED);
+    ).revertedWith(COLLATERAL_CANNOT_BE_LIQUIDATED);
   });
 
   it('LIQUIDATION - Liquidates the borrow', async () => {
diff --git a/test/liquidation-underlying.spec.ts b/test/liquidation-underlying.spec.ts
index 676c9c26..064e3856 100644
--- a/test/liquidation-underlying.spec.ts
+++ b/test/liquidation-underlying.spec.ts
@@ -13,12 +13,7 @@ const chai = require('chai');
 const {expect} = chai;
 
 makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', (testEnv) => {
-  const {
-    HF_IS_NOT_BELLOW_THRESHOLD,
-    INVALID_HF,
-    USER_DID_NOT_BORROW_SPECIFIED,
-    THE_COLLATERAL_CHOSEN_CANNOT_BE_LIQUIDATED,
-  } = ProtocolErrors;
+  const {INVALID_HF} = ProtocolErrors;
 
   it('LIQUIDATION - Deposits WETH, borrows DAI', async () => {
     const {dai, weth, users, pool, oracle} = testEnv;
@@ -67,7 +62,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
 
     expect(userGlobalDataAfter.currentLiquidationThreshold.toString()).to.be.bignumber.equal(
       '8000',
-      'Invalid liquidation threshold'
+      INVALID_HF
     );
   });
 
@@ -86,7 +81,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
 
     expect(userGlobalData.healthFactor.toString()).to.be.bignumber.lt(
       oneEther.toFixed(0),
-      'Invalid health factor'
+      INVALID_HF
     );
   });