LCOV - code coverage report
Current view: top level - protocol/libraries/logic - EModeLogic.sol (source / functions) Coverage Total Hit
Test: lcov.info.p Lines: 100.0 % 5 5
Test Date: 2024-09-24 09:34:24 Functions: 100.0 % 1 1
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: BUSL-1.1
       2                 :             : pragma solidity ^0.8.10;
       3                 :             : 
       4                 :             : import {GPv2SafeERC20} from '../../../dependencies/gnosis/contracts/GPv2SafeERC20.sol';
       5                 :             : import {IERC20} from '../../../dependencies/openzeppelin/contracts/IERC20.sol';
       6                 :             : import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol';
       7                 :             : import {UserConfiguration} from '../configuration/UserConfiguration.sol';
       8                 :             : import {WadRayMath} from '../math/WadRayMath.sol';
       9                 :             : import {PercentageMath} from '../math/PercentageMath.sol';
      10                 :             : import {DataTypes} from '../types/DataTypes.sol';
      11                 :             : import {ValidationLogic} from './ValidationLogic.sol';
      12                 :             : import {ReserveLogic} from './ReserveLogic.sol';
      13                 :             : 
      14                 :             : /**
      15                 :             :  * @title EModeLogic library
      16                 :             :  * @author Aave
      17                 :             :  * @notice Implements the base logic for all the actions related to the eMode
      18                 :             :  */
      19                 :             : library EModeLogic {
      20                 :             :   using ReserveLogic for DataTypes.ReserveCache;
      21                 :             :   using ReserveLogic for DataTypes.ReserveData;
      22                 :             :   using GPv2SafeERC20 for IERC20;
      23                 :             :   using UserConfiguration for DataTypes.UserConfigurationMap;
      24                 :             :   using WadRayMath for uint256;
      25                 :             :   using PercentageMath for uint256;
      26                 :             : 
      27                 :             :   // See `IPool` for descriptions
      28                 :             :   event UserEModeSet(address indexed user, uint8 categoryId);
      29                 :             : 
      30                 :             :   /**
      31                 :             :    * @notice Updates the user efficiency mode category
      32                 :             :    * @dev Will revert if user is borrowing non-compatible asset or change will drop HF < HEALTH_FACTOR_LIQUIDATION_THRESHOLD
      33                 :             :    * @dev Emits the `UserEModeSet` event
      34                 :             :    * @param reservesData The state of all the reserves
      35                 :             :    * @param reservesList The addresses of all the active reserves
      36                 :             :    * @param eModeCategories The configuration of all the efficiency mode categories
      37                 :             :    * @param usersEModeCategory The state of all users efficiency mode category
      38                 :             :    * @param userConfig The user configuration mapping that tracks the supplied/borrowed assets
      39                 :             :    * @param params The additional parameters needed to execute the setUserEMode function
      40                 :             :    */
      41                 :             :   function executeSetUserEMode(
      42                 :             :     mapping(address => DataTypes.ReserveData) storage reservesData,
      43                 :             :     mapping(uint256 => address) storage reservesList,
      44                 :             :     mapping(uint8 => DataTypes.EModeCategory) storage eModeCategories,
      45                 :             :     mapping(address => uint8) storage usersEModeCategory,
      46                 :             :     DataTypes.UserConfigurationMap storage userConfig,
      47                 :             :     DataTypes.ExecuteSetUserEModeParams memory params
      48                 :             :   ) external {
      49                 :       10023 :     if (usersEModeCategory[msg.sender] == params.categoryId) return;
      50                 :             : 
      51                 :        9617 :     ValidationLogic.validateSetUserEMode(
      52                 :             :       eModeCategories,
      53                 :             :       userConfig,
      54                 :             :       params.reservesCount,
      55                 :             :       params.categoryId
      56                 :             :     );
      57                 :             : 
      58                 :        8614 :     usersEModeCategory[msg.sender] = params.categoryId;
      59                 :             : 
      60                 :        8614 :     ValidationLogic.validateHealthFactor(
      61                 :             :       reservesData,
      62                 :             :       reservesList,
      63                 :             :       eModeCategories,
      64                 :             :       userConfig,
      65                 :             :       msg.sender,
      66                 :             :       params.categoryId,
      67                 :             :       params.reservesCount,
      68                 :             :       params.oracle
      69                 :             :     );
      70                 :        7612 :     emit UserEModeSet(msg.sender, params.categoryId);
      71                 :             :   }
      72                 :             : }
        

Generated by: LCOV version 2.1-1