// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./BaseMath.sol"; import "./LiquityMath.sol"; import "../Interfaces/IActivePool.sol"; import "../Interfaces/IDefaultPool.sol"; import "../Interfaces/IPriceFeed.sol"; import "../Interfaces/ILiquityBase.sol"; import "../Interfaces/ILiquityBaseParams.sol"; /** * Base contract for TroveManager, BorrowerOperations and StabilityPool. Contains global system constants and * common functions. */ contract LiquityBase is BaseMath, ILiquityBase { using SafeMath for uint256; uint256 public constant _100pct = 1000000000000000000; // 1e18 == 100% /// Amount of ZUSD to be locked in gas pool on opening troves uint256 public constant ZUSD_GAS_COMPENSATION = 20e18; /// Minimum amount of net ZUSD debt a trove must have uint256 public constant MIN_NET_DEBT = 180e18; IActivePool public activePool; IDefaultPool public defaultPool; IPriceFeed public override priceFeed; ILiquityBaseParams public override liquityBaseParams; // --- Gas compensation functions --- // Returns the composite debt (drawn debt + gas compensation) of a trove, for the purpose of ICR calculation function _getCompositeDebt(uint256 _debt) internal pure returns (uint256) { return _debt.add(ZUSD_GAS_COMPENSATION); } function _getNetDebt(uint256 _debt) internal pure returns (uint256) { return _debt.sub(ZUSD_GAS_COMPENSATION); } /// Return the amount of ETH to be drawn from a trove's collateral and sent as gas compensation. function _getCollGasCompensation(uint256 _entireColl) internal view returns (uint256) { return _entireColl / liquityBaseParams.PERCENT_DIVISOR(); } function getEntireSystemColl() public view returns (uint256 entireSystemColl) { uint256 activeColl = activePool.getETH(); uint256 liquidatedColl = defaultPool.getETH(); return activeColl.add(liquidatedColl); } function getEntireSystemDebt() public view returns (uint256 entireSystemDebt) { uint256 activeDebt = activePool.getZUSDDebt(); uint256 closedDebt = defaultPool.getZUSDDebt(); return activeDebt.add(closedDebt); } function _getTCR(uint256 _price) internal view returns (uint256 TCR) { uint256 entireSystemColl = getEntireSystemColl(); uint256 entireSystemDebt = getEntireSystemDebt(); TCR = LiquityMath._computeCR(entireSystemColl, entireSystemDebt, _price); return TCR; } function _checkRecoveryMode(uint256 _price) internal view returns (bool) { uint256 TCR = _getTCR(_price); return TCR < liquityBaseParams.CCR(); } function _requireUserAcceptsFee( uint256 _fee, uint256 _amount, uint256 _maxFeePercentage ) internal pure { uint256 feePercentage = _fee.mul(DECIMAL_PRECISION).div(_amount); require(feePercentage <= _maxFeePercentage, "Fee exceeded provided maximum"); } }