mirror of
				https://github.com/Instadapp/aave-protocol-v2.git
				synced 2024-07-29 21:47:30 +00:00 
			
		
		
		
	Added LendingPoolLiquidationManager error messages to error lib, and updated tests.
This commit is contained in:
		
							parent
							
								
									5b5f8ae74a
								
							
						
					
					
						commit
						288d8f2889
					
				| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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'
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 () => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user