creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts/utils/math/SafeMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)\n\npragma solidity ^0.8.0;\n\n// CAUTION\n// This version of SafeMath should only be used with Solidity 0.8 or later,\n// because it relies on the compiler's built in overflow checks.\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations.\n *\n * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler\n * now has built in overflow checking.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            uint256 c = a + b;\n            if (c < a) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b > a) return (false, 0);\n            return (true, a - b);\n        }\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n            // benefit is lost if 'b' is also tested.\n            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n            if (a == 0) return (true, 0);\n            uint256 c = a * b;\n            if (c / a != b) return (false, 0);\n            return (true, c);\n        }\n    }\n\n    /**\n     * @dev Returns the division of two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a / b);\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n     *\n     * _Available since v3.4._\n     */\n    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n        unchecked {\n            if (b == 0) return (false, 0);\n            return (true, a % b);\n        }\n    }\n\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a + b;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a - b;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a * b;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator.\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a / b;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a % b;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {trySub}.\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        unchecked {\n            require(b <= a, errorMessage);\n            return a - b;\n        }\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        unchecked {\n            require(b > 0, errorMessage);\n            return a / b;\n        }\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * reverting with custom message when dividing by zero.\n     *\n     * CAUTION: This function is deprecated because it requires allocating memory for the error\n     * message unnecessarily. For custom revert reasons use {tryMod}.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        unchecked {\n            require(b > 0, errorMessage);\n            return a % b;\n        }\n    }\n}\n"
      },
      "contracts/mainnet/interfaces/ILendingPoolAddressesProvider.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.8.12;\n\n/**\n * @title LendingPoolAddressesProvider contract\n * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles\n * - Acting also as factory of proxies and admin of those, so with right to change its implementations\n * - Owned by the Aave Governance\n * @author Aave\n **/\ninterface ILendingPoolAddressesProvider {\n\tevent MarketIdSet(string newMarketId);\n\tevent LendingPoolUpdated(address indexed newAddress);\n\tevent ConfigurationAdminUpdated(address indexed newAddress);\n\tevent EmergencyAdminUpdated(address indexed newAddress);\n\tevent LendingPoolConfiguratorUpdated(address indexed newAddress);\n\tevent LendingPoolCollateralManagerUpdated(address indexed newAddress);\n\tevent PriceOracleUpdated(address indexed newAddress);\n\tevent LendingRateOracleUpdated(address indexed newAddress);\n\tevent ProxyCreated(bytes32 id, address indexed newAddress);\n\tevent AddressSet(bytes32 id, address indexed newAddress, bool hasProxy);\n\n\tfunction getMarketId() external view returns (string memory);\n\n\tfunction setMarketId(string calldata marketId) external;\n\n\tfunction setAddress(bytes32 id, address newAddress) external;\n\n\tfunction setAddressAsProxy(bytes32 id, address impl) external;\n\n\tfunction getAddress(bytes32 id) external view returns (address);\n\n\tfunction getLendingPool() external view returns (address);\n\n\tfunction setLendingPoolImpl(address pool) external;\n\n\tfunction getLendingPoolConfigurator() external view returns (address);\n\n\tfunction setLendingPoolConfiguratorImpl(address configurator) external;\n\n\tfunction getLendingPoolCollateralManager() external view returns (address);\n\n\tfunction setLendingPoolCollateralManager(address manager) external;\n\n\tfunction getPoolAdmin() external view returns (address);\n\n\tfunction setPoolAdmin(address admin) external;\n\n\tfunction getEmergencyAdmin() external view returns (address);\n\n\tfunction setEmergencyAdmin(address admin) external;\n\n\tfunction getPriceOracle() external view returns (address);\n\n\tfunction setPriceOracle(address priceOracle) external;\n\n\tfunction getLendingRateOracle() external view returns (address);\n\n\tfunction setLendingRateOracle(address lendingRateOracle) external;\n\n\tfunction getLiquidationFeeTo() external view returns (address);\n\n\tfunction setLiquidationFeeTo(address liquidationFeeTo) external;\n}\n"
      },
      "contracts/mainnet/interfaces/ILendingRateOracle.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.8.12;\n\n/**\n * @title ILendingRateOracle interface\n * @notice Interface for the Aave borrow rate oracle. Provides the average market borrow rate to be used as a base for the stable borrow rate calculations\n **/\n\ninterface ILendingRateOracle {\n\t/**\n    @dev returns the market borrow rate in ray\n    **/\n\tfunction getMarketBorrowRate(address asset) external view returns (uint256);\n\n\t/**\n    @dev sets the market borrow rate. Rate value must be in ray\n    **/\n\tfunction setMarketBorrowRate(address asset, uint256 rate) external;\n}\n"
      },
      "contracts/mainnet/interfaces/IReserveInterestRateStrategy.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.8.12;\n\n/**\n * @title IReserveInterestRateStrategyInterface interface\n * @dev Interface for the calculation of the interest rates\n * @author Aave\n */\ninterface IReserveInterestRateStrategy {\n\tfunction baseVariableBorrowRate() external view returns (uint256);\n\n\tfunction getMaxVariableBorrowRate() external view returns (uint256);\n\n\tfunction calculateInterestRates(\n\t\taddress reserve,\n\t\tuint256 availableLiquidity,\n\t\tuint256 totalStableDebt,\n\t\tuint256 totalVariableDebt,\n\t\tuint256 averageStableBorrowRate,\n\t\tuint256 reserveFactor\n\t) external view returns (uint256, uint256, uint256);\n\n\tfunction calculateInterestRates(\n\t\taddress reserve,\n\t\taddress aToken,\n\t\tuint256 liquidityAdded,\n\t\tuint256 liquidityTaken,\n\t\tuint256 totalStableDebt,\n\t\tuint256 totalVariableDebt,\n\t\tuint256 averageStableBorrowRate,\n\t\tuint256 reserveFactor\n\t) external view returns (uint256 liquidityRate, uint256 stableBorrowRate, uint256 variableBorrowRate);\n}\n"
      },
      "contracts/mainnet/lending/lendingpool/DefaultReserveInterestRateStrategy.sol": {
        "content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity 0.8.12;\n\nimport \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport {IReserveInterestRateStrategy} from \"../../interfaces/IReserveInterestRateStrategy.sol\";\nimport {WadRayMath} from \"../libraries/math/WadRayMath.sol\";\nimport {PercentageMath} from \"../libraries/math/PercentageMath.sol\";\nimport {ILendingPoolAddressesProvider} from \"../../interfaces/ILendingPoolAddressesProvider.sol\";\nimport {ILendingRateOracle} from \"../../interfaces/ILendingRateOracle.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n/**\n * @title DefaultReserveInterestRateStrategy contract\n * @notice Implements the calculation of the interest rates depending on the reserve state\n * @dev The model of interest rate is based on 2 slopes, one before the `OPTIMAL_UTILIZATION_RATE`\n * point of utilization and another from that one to 100%\n * - An instance of this same contract, can't be used across different Aave markets, due to the caching\n *   of the LendingPoolAddressesProvider\n * @author Aave\n **/\ncontract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {\n\tusing WadRayMath for uint256;\n\tusing SafeMath for uint256;\n\tusing PercentageMath for uint256;\n\n\t/**\n\t * @dev this constant represents the utilization rate at which the pool aims to obtain most competitive borrow rates.\n\t * Expressed in ray\n\t **/\n\tuint256 public immutable OPTIMAL_UTILIZATION_RATE;\n\n\t/**\n\t * @dev This constant represents the excess utilization rate above the optimal. It's always equal to\n\t * 1-optimal utilization rate. Added as a constant here for gas optimizations.\n\t * Expressed in ray\n\t **/\n\n\tuint256 public immutable EXCESS_UTILIZATION_RATE;\n\n\tILendingPoolAddressesProvider public immutable addressesProvider;\n\n\t// Base variable borrow rate when Utilization rate = 0. Expressed in ray\n\tuint256 internal immutable _baseVariableBorrowRate;\n\n\t// Slope of the variable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray\n\tuint256 internal immutable _variableRateSlope1;\n\n\t// Slope of the variable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray\n\tuint256 internal immutable _variableRateSlope2;\n\n\t// Slope of the stable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray\n\tuint256 internal immutable _stableRateSlope1;\n\n\t// Slope of the stable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray\n\tuint256 internal immutable _stableRateSlope2;\n\n\tconstructor(\n\t\tILendingPoolAddressesProvider provider,\n\t\tuint256 optimalUtilizationRate_,\n\t\tuint256 baseVariableBorrowRate_,\n\t\tuint256 variableRateSlope1_,\n\t\tuint256 variableRateSlope2_,\n\t\tuint256 stableRateSlope1_,\n\t\tuint256 stableRateSlope2_\n\t) {\n\t\tOPTIMAL_UTILIZATION_RATE = optimalUtilizationRate_;\n\t\tEXCESS_UTILIZATION_RATE = WadRayMath.ray().sub(optimalUtilizationRate_);\n\t\taddressesProvider = provider;\n\t\t_baseVariableBorrowRate = baseVariableBorrowRate_;\n\t\t_variableRateSlope1 = variableRateSlope1_;\n\t\t_variableRateSlope2 = variableRateSlope2_;\n\t\t_stableRateSlope1 = stableRateSlope1_;\n\t\t_stableRateSlope2 = stableRateSlope2_;\n\t}\n\n\tfunction variableRateSlope1() external view returns (uint256) {\n\t\treturn _variableRateSlope1;\n\t}\n\n\tfunction variableRateSlope2() external view returns (uint256) {\n\t\treturn _variableRateSlope2;\n\t}\n\n\tfunction stableRateSlope1() external view returns (uint256) {\n\t\treturn _stableRateSlope1;\n\t}\n\n\tfunction stableRateSlope2() external view returns (uint256) {\n\t\treturn _stableRateSlope2;\n\t}\n\n\tfunction baseVariableBorrowRate() external view returns (uint256) {\n\t\treturn _baseVariableBorrowRate;\n\t}\n\n\tfunction getMaxVariableBorrowRate() external view returns (uint256) {\n\t\treturn _baseVariableBorrowRate.add(_variableRateSlope1).add(_variableRateSlope2);\n\t}\n\n\t/**\n\t * @dev Calculates the interest rates depending on the reserve's state and configurations\n\t * @param reserve The address of the reserve\n\t * @param liquidityAdded The liquidity added during the operation\n\t * @param liquidityTaken The liquidity taken during the operation\n\t * @param totalStableDebt The total borrowed from the reserve a stable rate\n\t * @param totalVariableDebt The total borrowed from the reserve at a variable rate\n\t * @param averageStableBorrowRate The weighted average of all the stable rate loans\n\t * @param reserveFactor The reserve portion of the interest that goes to the treasury of the market\n\t * @return The liquidity rate, the stable borrow rate and the variable borrow rate\n\t **/\n\tfunction calculateInterestRates(\n\t\taddress reserve,\n\t\taddress aToken,\n\t\tuint256 liquidityAdded,\n\t\tuint256 liquidityTaken,\n\t\tuint256 totalStableDebt,\n\t\tuint256 totalVariableDebt,\n\t\tuint256 averageStableBorrowRate,\n\t\tuint256 reserveFactor\n\t) external view returns (uint256, uint256, uint256) {\n\t\tuint256 availableLiquidity = IERC20(reserve).balanceOf(aToken);\n\t\t//avoid stack too deep\n\t\tavailableLiquidity = availableLiquidity.add(liquidityAdded).sub(liquidityTaken);\n\n\t\treturn\n\t\t\tcalculateInterestRates(\n\t\t\t\treserve,\n\t\t\t\tavailableLiquidity,\n\t\t\t\ttotalStableDebt,\n\t\t\t\ttotalVariableDebt,\n\t\t\t\taverageStableBorrowRate,\n\t\t\t\treserveFactor\n\t\t\t);\n\t}\n\n\tstruct CalcInterestRatesLocalVars {\n\t\tuint256 totalDebt;\n\t\tuint256 currentVariableBorrowRate;\n\t\tuint256 currentStableBorrowRate;\n\t\tuint256 currentLiquidityRate;\n\t\tuint256 utilizationRate;\n\t}\n\n\t/**\n\t * @dev Calculates the interest rates depending on the reserve's state and configurations.\n\t * NOTE This function is kept for compatibility with the previous DefaultInterestRateStrategy interface.\n\t * New protocol implementation uses the new calculateInterestRates() interface\n\t * @param reserve The address of the reserve\n\t * @param availableLiquidity The liquidity available in the corresponding aToken\n\t * @param totalStableDebt The total borrowed from the reserve a stable rate\n\t * @param totalVariableDebt The total borrowed from the reserve at a variable rate\n\t * @param averageStableBorrowRate The weighted average of all the stable rate loans\n\t * @param reserveFactor The reserve portion of the interest that goes to the treasury of the market\n\t * @return The liquidity rate, the stable borrow rate and the variable borrow rate\n\t **/\n\tfunction calculateInterestRates(\n\t\taddress reserve,\n\t\tuint256 availableLiquidity,\n\t\tuint256 totalStableDebt,\n\t\tuint256 totalVariableDebt,\n\t\tuint256 averageStableBorrowRate,\n\t\tuint256 reserveFactor\n\t) public view returns (uint256, uint256, uint256) {\n\t\tCalcInterestRatesLocalVars memory vars;\n\n\t\tvars.totalDebt = totalStableDebt.add(totalVariableDebt);\n\t\tvars.currentVariableBorrowRate = 0;\n\t\tvars.currentStableBorrowRate = 0;\n\t\tvars.currentLiquidityRate = 0;\n\n\t\tvars.utilizationRate = vars.totalDebt == 0 ? 0 : vars.totalDebt.rayDiv(availableLiquidity.add(vars.totalDebt));\n\n\t\tvars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle()).getMarketBorrowRate(\n\t\t\treserve\n\t\t);\n\n\t\tif (vars.utilizationRate > OPTIMAL_UTILIZATION_RATE) {\n\t\t\tuint256 excessUtilizationRateRatio = vars.utilizationRate.sub(OPTIMAL_UTILIZATION_RATE).rayDiv(\n\t\t\t\tEXCESS_UTILIZATION_RATE\n\t\t\t);\n\n\t\t\tvars.currentStableBorrowRate = vars.currentStableBorrowRate.add(_stableRateSlope1).add(\n\t\t\t\t_stableRateSlope2.rayMul(excessUtilizationRateRatio)\n\t\t\t);\n\n\t\t\tvars.currentVariableBorrowRate = _baseVariableBorrowRate.add(_variableRateSlope1).add(\n\t\t\t\t_variableRateSlope2.rayMul(excessUtilizationRateRatio)\n\t\t\t);\n\t\t} else {\n\t\t\tvars.currentStableBorrowRate = vars.currentStableBorrowRate.add(\n\t\t\t\t_stableRateSlope1.rayMul(vars.utilizationRate.rayDiv(OPTIMAL_UTILIZATION_RATE))\n\t\t\t);\n\t\t\tvars.currentVariableBorrowRate = _baseVariableBorrowRate.add(\n\t\t\t\tvars.utilizationRate.rayMul(_variableRateSlope1).rayDiv(OPTIMAL_UTILIZATION_RATE)\n\t\t\t);\n\t\t}\n\n\t\tvars.currentLiquidityRate = _getOverallBorrowRate(\n\t\t\ttotalStableDebt,\n\t\t\ttotalVariableDebt,\n\t\t\tvars.currentVariableBorrowRate,\n\t\t\taverageStableBorrowRate\n\t\t).rayMul(vars.utilizationRate).percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(reserveFactor));\n\n\t\treturn (vars.currentLiquidityRate, vars.currentStableBorrowRate, vars.currentVariableBorrowRate);\n\t}\n\n\t/**\n\t * @dev Calculates the overall borrow rate as the weighted average between the total variable debt and total stable debt\n\t * @param totalStableDebt The total borrowed from the reserve a stable rate\n\t * @param totalVariableDebt The total borrowed from the reserve at a variable rate\n\t * @param currentVariableBorrowRate The current variable borrow rate of the reserve\n\t * @param currentAverageStableBorrowRate The current weighted average of all the stable rate loans\n\t * @return The weighted averaged borrow rate\n\t **/\n\tfunction _getOverallBorrowRate(\n\t\tuint256 totalStableDebt,\n\t\tuint256 totalVariableDebt,\n\t\tuint256 currentVariableBorrowRate,\n\t\tuint256 currentAverageStableBorrowRate\n\t) internal pure returns (uint256) {\n\t\tuint256 totalDebt = totalStableDebt.add(totalVariableDebt);\n\n\t\tif (totalDebt == 0) return 0;\n\n\t\tuint256 weightedVariableRate = totalVariableDebt.wadToRay().rayMul(currentVariableBorrowRate);\n\n\t\tuint256 weightedStableRate = totalStableDebt.wadToRay().rayMul(currentAverageStableBorrowRate);\n\n\t\tuint256 overallBorrowRate = weightedVariableRate.add(weightedStableRate).rayDiv(totalDebt.wadToRay());\n\n\t\treturn overallBorrowRate;\n\t}\n}\n"
      },
      "contracts/mainnet/lending/libraries/helpers/Errors.sol": {
        "content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity 0.8.12;\n\n/**\n * @title Errors library\n * @author Aave\n * @notice Defines the error messages emitted by the different contracts of the Aave protocol\n * @dev Error messages prefix glossary:\n *  - VL = ValidationLogic\n *  - MATH = Math libraries\n *  - CT = Common errors between tokens (AToken, VariableDebtToken and StableDebtToken)\n *  - AT = AToken\n *  - SDT = StableDebtToken\n *  - VDT = VariableDebtToken\n *  - LP = LendingPool\n *  - LPAPR = LendingPoolAddressesProviderRegistry\n *  - LPC = LendingPoolConfiguration\n *  - RL = ReserveLogic\n *  - LPCM = LendingPoolCollateralManager\n *  - P = Pausable\n */\nlibrary Errors {\n\t//common errors\n\tstring public constant CALLER_NOT_POOL_ADMIN = \"33\"; // 'The caller must be the pool admin'\n\tstring public constant BORROW_ALLOWANCE_NOT_ENOUGH = \"59\"; // User borrows on behalf, but allowance are too small\n\n\t//contract specific errors\n\tstring public constant VL_INVALID_AMOUNT = \"1\"; // 'Amount must be greater than 0'\n\tstring public constant VL_NO_ACTIVE_RESERVE = \"2\"; // 'Action requires an active reserve'\n\tstring public constant VL_RESERVE_FROZEN = \"3\"; // 'Action cannot be performed because the reserve is frozen'\n\tstring public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = \"4\"; // 'The current liquidity is not enough'\n\tstring public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = \"5\"; // 'User cannot withdraw more than the available balance'\n\tstring public constant VL_TRANSFER_NOT_ALLOWED = \"6\"; // 'Transfer cannot be allowed.'\n\tstring public constant VL_BORROWING_NOT_ENABLED = \"7\"; // 'Borrowing is not enabled'\n\tstring public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = \"8\"; // 'Invalid interest rate mode selected'\n\tstring public constant VL_COLLATERAL_BALANCE_IS_0 = \"9\"; // 'The collateral balance is 0'\n\tstring public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = \"10\"; // 'Health factor is lesser than the liquidation threshold'\n\tstring public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = \"11\"; // 'There is not enough collateral to cover a new borrow'\n\tstring public constant VL_STABLE_BORROWING_NOT_ENABLED = \"12\"; // stable borrowing not enabled\n\tstring public constant VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY = \"13\"; // collateral is (mostly) the same currency that is being borrowed\n\tstring public constant VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = \"14\"; // 'The requested amount is greater than the max loan size in stable rate mode\n\tstring public constant VL_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'\n\tstring public constant VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = \"16\"; // 'To repay on behalf of an user an explicit amount to repay is needed'\n\tstring public constant VL_NO_STABLE_RATE_LOAN_IN_RESERVE = \"17\"; // 'User does not have a stable rate loan in progress on this reserve'\n\tstring public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = \"18\"; // 'User does not have a variable rate loan in progress on this reserve'\n\tstring public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = \"19\"; // 'The underlying balance needs to be greater than 0'\n\tstring public constant VL_DEPOSIT_ALREADY_IN_USE = \"20\"; // 'User deposit is already being used as collateral'\n\tstring public constant LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = \"21\"; // 'User does not have any stable rate loan for this reserve'\n\tstring public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = \"22\"; // 'Interest rate rebalance conditions were not met'\n\tstring public constant LP_LIQUIDATION_CALL_FAILED = \"23\"; // 'Liquidation call failed'\n\tstring public constant LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = \"24\"; // 'There is not enough liquidity available to borrow'\n\tstring public constant LP_REQUESTED_AMOUNT_TOO_SMALL = \"25\"; // 'The requested amount is too small for a FlashLoan.'\n\tstring public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = \"26\"; // 'The actual balance of the protocol is inconsistent'\n\tstring public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = \"27\"; // 'The caller of the function is not the lending pool configurator'\n\tstring public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = \"28\";\n\tstring public constant CT_CALLER_MUST_BE_LENDING_POOL = \"29\"; // 'The caller of this function must be a lending pool'\n\tstring public constant CT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = \"30\"; // 'User cannot give allowance to himself'\n\tstring public constant CT_TRANSFER_AMOUNT_NOT_GT_0 = \"31\"; // 'Transferred amount needs to be greater than zero'\n\tstring public constant RL_RESERVE_ALREADY_INITIALIZED = \"32\"; // 'Reserve has already been initialized'\n\tstring public constant LPC_RESERVE_LIQUIDITY_NOT_0 = \"34\"; // 'The liquidity of the reserve needs to be 0'\n\tstring public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = \"35\"; // 'The liquidity of the reserve needs to be 0'\n\tstring public constant LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = \"36\"; // 'The liquidity of the reserve needs to be 0'\n\tstring public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = \"37\"; // 'The liquidity of the reserve needs to be 0'\n\tstring public constant LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = \"38\"; // 'The liquidity of the reserve needs to be 0'\n\tstring public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = \"39\"; // 'The liquidity of the reserve needs to be 0'\n\tstring public constant LPC_INVALID_ADDRESSES_PROVIDER_ID = \"40\"; // 'The liquidity of the reserve needs to be 0'\n\tstring public constant LPC_INVALID_CONFIGURATION = \"75\"; // 'Invalid risk parameters for the reserve'\n\tstring public constant LPC_CALLER_NOT_EMERGENCY_ADMIN = \"76\"; // 'The caller must be the emergency admin'\n\tstring public constant LPAPR_PROVIDER_NOT_REGISTERED = \"41\"; // 'Provider is not registered'\n\tstring public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = \"42\"; // 'Health factor is not below the threshold'\n\tstring public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = \"43\"; // 'The collateral chosen cannot be liquidated'\n\tstring public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = \"44\"; // 'User did not borrow the specified currency'\n\tstring public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = \"45\"; // \"There isn't enough liquidity available to liquidate\"\n\tstring public constant LPCM_NO_ERRORS = \"46\"; // 'No errors'\n\tstring public constant LP_INVALID_FLASHLOAN_MODE = \"47\"; //Invalid flashloan mode selected\n\tstring public constant MATH_MULTIPLICATION_OVERFLOW = \"48\";\n\tstring public constant MATH_ADDITION_OVERFLOW = \"49\";\n\tstring public constant MATH_DIVISION_BY_ZERO = \"50\";\n\tstring public constant RL_LIQUIDITY_INDEX_OVERFLOW = \"51\"; //  Liquidity index overflows uint128\n\tstring public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = \"52\"; //  Variable borrow index overflows uint128\n\tstring public constant RL_LIQUIDITY_RATE_OVERFLOW = \"53\"; //  Liquidity rate overflows uint128\n\tstring public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = \"54\"; //  Variable borrow rate overflows uint128\n\tstring public constant RL_STABLE_BORROW_RATE_OVERFLOW = \"55\"; //  Stable borrow rate overflows uint128\n\tstring public constant CT_INVALID_MINT_AMOUNT = \"56\"; //invalid amount to mint\n\tstring public constant LP_FAILED_REPAY_WITH_COLLATERAL = \"57\";\n\tstring public constant CT_INVALID_BURN_AMOUNT = \"58\"; //invalid amount to burn\n\tstring public constant LP_FAILED_COLLATERAL_SWAP = \"60\";\n\tstring public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = \"61\";\n\tstring public constant LP_REENTRANCY_NOT_ALLOWED = \"62\";\n\tstring public constant LP_CALLER_MUST_BE_AN_ATOKEN = \"63\";\n\tstring public constant LP_IS_PAUSED = \"64\"; // 'Pool is paused'\n\tstring public constant LP_NO_MORE_RESERVES_ALLOWED = \"65\";\n\tstring public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = \"66\";\n\tstring public constant RC_INVALID_LTV = \"67\";\n\tstring public constant RC_INVALID_LIQ_THRESHOLD = \"68\";\n\tstring public constant RC_INVALID_LIQ_BONUS = \"69\";\n\tstring public constant RC_INVALID_DECIMALS = \"70\";\n\tstring public constant RC_INVALID_RESERVE_FACTOR = \"71\";\n\tstring public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = \"72\";\n\tstring public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = \"73\";\n\tstring public constant LP_INCONSISTENT_PARAMS_LENGTH = \"74\";\n\tstring public constant UL_INVALID_INDEX = \"77\";\n\tstring public constant LP_NOT_CONTRACT = \"78\";\n\tstring public constant SDT_STABLE_DEBT_OVERFLOW = \"79\";\n\tstring public constant SDT_BURN_EXCEEDS_BALANCE = \"80\";\n\n\t/**\n\t * @dev Custom Radiant codes added +200 to avoid conflicts with the AaveV2/V3 ones\n\t * @custom:borrow-and-supply-caps\n\t */\n\tstring public constant INVALID_BORROW_CAP = \"201\"; // Invalid borrow cap value\n\tstring public constant INVALID_SUPPLY_CAP = \"202\"; // Invalid supply cap value\n\tstring public constant BORROW_CAP_EXCEEDED = \"203\"; // Borrow cap is exceeded\n\tstring public constant SUPPLY_CAP_EXCEEDED = \"204\"; // Supply cap is exceeded\n\n\tenum CollateralManagerErrors {\n\t\tNO_ERROR,\n\t\tNO_COLLATERAL_AVAILABLE,\n\t\tCOLLATERAL_CANNOT_BE_LIQUIDATED,\n\t\tCURRRENCY_NOT_BORROWED,\n\t\tHEALTH_FACTOR_ABOVE_THRESHOLD,\n\t\tNOT_ENOUGH_LIQUIDITY,\n\t\tNO_ACTIVE_RESERVE,\n\t\tHEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,\n\t\tINVALID_EQUAL_ASSETS_TO_SWAP,\n\t\tFROZEN_RESERVE\n\t}\n}\n"
      },
      "contracts/mainnet/lending/libraries/math/PercentageMath.sol": {
        "content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity 0.8.12;\n\nimport {Errors} from \"../helpers/Errors.sol\";\n\n/**\n * @title PercentageMath library\n * @author Aave\n * @notice Provides functions to perform percentage calculations\n * @dev Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR\n * @dev Operations are rounded half up\n **/\n\nlibrary PercentageMath {\n\tuint256 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals\n\tuint256 constant HALF_PERCENT = PERCENTAGE_FACTOR / 2;\n\n\t/**\n\t * @dev Executes a percentage multiplication\n\t * @param value The value of which the percentage needs to be calculated\n\t * @param percentage The percentage of the value to be calculated\n\t * @return The percentage of value\n\t **/\n\tfunction percentMul(uint256 value, uint256 percentage) internal pure returns (uint256) {\n\t\tif (value == 0 || percentage == 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\trequire(value <= (type(uint256).max - HALF_PERCENT) / percentage, Errors.MATH_MULTIPLICATION_OVERFLOW);\n\n\t\treturn (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR;\n\t}\n\n\t/**\n\t * @dev Executes a percentage division\n\t * @param value The value of which the percentage needs to be calculated\n\t * @param percentage The percentage of the value to be calculated\n\t * @return The value divided the percentage\n\t **/\n\tfunction percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {\n\t\trequire(percentage != 0, Errors.MATH_DIVISION_BY_ZERO);\n\t\tuint256 halfPercentage = percentage / 2;\n\n\t\trequire(value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR, Errors.MATH_MULTIPLICATION_OVERFLOW);\n\n\t\treturn (value * PERCENTAGE_FACTOR + halfPercentage) / percentage;\n\t}\n}\n"
      },
      "contracts/mainnet/lending/libraries/math/WadRayMath.sol": {
        "content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity 0.8.12;\n\nimport {Errors} from \"../helpers/Errors.sol\";\n\n/**\n * @title WadRayMath library\n * @author Aave\n * @dev Provides mul and div function for wads (decimal numbers with 18 digits precision) and rays (decimals with 27 digits)\n **/\n\nlibrary WadRayMath {\n\tuint256 internal constant WAD = 1e18;\n\tuint256 internal constant halfWAD = WAD / 2;\n\n\tuint256 internal constant RAY = 1e27;\n\tuint256 internal constant halfRAY = RAY / 2;\n\n\tuint256 internal constant WAD_RAY_RATIO = 1e9;\n\n\t/**\n\t * @return One ray, 1e27\n\t **/\n\tfunction ray() internal pure returns (uint256) {\n\t\treturn RAY;\n\t}\n\n\t/**\n\t * @return One wad, 1e18\n\t **/\n\n\tfunction wad() internal pure returns (uint256) {\n\t\treturn WAD;\n\t}\n\n\t/**\n\t * @return Half ray, 1e27/2\n\t **/\n\tfunction halfRay() internal pure returns (uint256) {\n\t\treturn halfRAY;\n\t}\n\n\t/**\n\t * @return Half ray, 1e18/2\n\t **/\n\tfunction halfWad() internal pure returns (uint256) {\n\t\treturn halfWAD;\n\t}\n\n\t/**\n\t * @dev Multiplies two wad, rounding half up to the nearest wad\n\t * @param a Wad\n\t * @param b Wad\n\t * @return The result of a*b, in wad\n\t **/\n\tfunction wadMul(uint256 a, uint256 b) internal pure returns (uint256) {\n\t\tif (a == 0 || b == 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\trequire(a <= (type(uint256).max - halfWAD) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);\n\n\t\treturn (a * b + halfWAD) / WAD;\n\t}\n\n\t/**\n\t * @dev Divides two wad, rounding half up to the nearest wad\n\t * @param a Wad\n\t * @param b Wad\n\t * @return The result of a/b, in wad\n\t **/\n\tfunction wadDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n\t\trequire(b != 0, Errors.MATH_DIVISION_BY_ZERO);\n\t\tuint256 halfB = b / 2;\n\n\t\trequire(a <= (type(uint256).max - halfB) / WAD, Errors.MATH_MULTIPLICATION_OVERFLOW);\n\n\t\treturn (a * WAD + halfB) / b;\n\t}\n\n\t/**\n\t * @dev Multiplies two ray, rounding half up to the nearest ray\n\t * @param a Ray\n\t * @param b Ray\n\t * @return The result of a*b, in ray\n\t **/\n\tfunction rayMul(uint256 a, uint256 b) internal pure returns (uint256) {\n\t\tif (a == 0 || b == 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\trequire(a <= (type(uint256).max - halfRAY) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);\n\n\t\treturn (a * b + halfRAY) / RAY;\n\t}\n\n\t/**\n\t * @dev Divides two ray, rounding half up to the nearest ray\n\t * @param a Ray\n\t * @param b Ray\n\t * @return The result of a/b, in ray\n\t **/\n\tfunction rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n\t\trequire(b != 0, Errors.MATH_DIVISION_BY_ZERO);\n\t\tuint256 halfB = b / 2;\n\n\t\trequire(a <= (type(uint256).max - halfB) / RAY, Errors.MATH_MULTIPLICATION_OVERFLOW);\n\n\t\treturn (a * RAY + halfB) / b;\n\t}\n\n\t/**\n\t * @dev Casts ray down to wad\n\t * @param a Ray\n\t * @return a casted to wad, rounded half up to the nearest wad\n\t **/\n\tfunction rayToWad(uint256 a) internal pure returns (uint256) {\n\t\tuint256 halfRatio = WAD_RAY_RATIO / 2;\n\t\tuint256 result = halfRatio + a;\n\t\trequire(result >= halfRatio, Errors.MATH_ADDITION_OVERFLOW);\n\n\t\treturn result / WAD_RAY_RATIO;\n\t}\n\n\t/**\n\t * @dev Converts wad up to ray\n\t * @param a Wad\n\t * @return a converted in ray\n\t **/\n\tfunction wadToRay(uint256 a) internal pure returns (uint256) {\n\t\tuint256 result = a * WAD_RAY_RATIO;\n\t\trequire(result / WAD_RAY_RATIO == a, Errors.MATH_MULTIPLICATION_OVERFLOW);\n\t\treturn result;\n\t}\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 999999,
        "details": {
          "yul": true
        }
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "metadata": {
        "useLiteralContent": true
      },
      "libraries": {}
    }
  }}