lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.14
/**
 * @dev updates the state of the core as a result of a deposit action
 * @param _reserve the address of the reserve in which the deposit is happening
 * @param _user the address of the the user depositing
 * @param _amount the amount being deposited
 * @param _isFirstDeposit true if the user is depositing for the first time
 **/
function updateStateOnDeposit(
        address _reserve,
        address _user,
        uint256 _amount,
        bool _isFirstDeposit
    ) external onlyLendingPool {
        reserves[_reserve].updateCumulativeIndexes();
        updateReserveInterestRatesAndTimestampInternal(_reserve, _amount, 0);

        if (_isFirstDeposit) {
            //if this is the first deposit of the user, we configure the deposit as enabled to be used as collateral
            setUserUseReserveAsCollateral(_reserve, _user, true);
        }
    }
// Solidity 0.5.14
/**
 * @dev updates the state of the core as a result of a redeem action
 * @param _reserve the address of the reserve in which the redeem is happening
 * @param _user the address of the the user redeeming
 * @param _amountRedeemed the amount being redeemed
 * @param _userRedeemedEverything true if the user is redeeming everything
 **/
function updateStateOnRedeem(
        address _reserve,
        address _user,
        uint256 _amountRedeemed,
        bool _userRedeemedEverything
    ) external onlyLendingPool {
        //compound liquidity and variable borrow interests
        reserves[_reserve].updateCumulativeIndexes();
        updateReserveInterestRatesAndTimestampInternal(_reserve, 0, _amountRedeemed);

        //if user redeemed everything the useReserveAsCollateral flag is reset
        if (_userRedeemedEverything) {
            setUserUseReserveAsCollateral(_reserve, _user, false);
        }
    }
// Solidity 0.5.14
/**
 * @dev updates the state of the core as a consequence of a borrow action.
 * @param _reserve the address of the reserve on which the user is borrowing
 * @param _user the address of the borrower
 * @param _amountBorrowed the new amount borrowed
 * @param _borrowFee the fee on the amount borrowed
 * @param _rateMode the borrow rate mode (stable, variable)
 * @return the new borrow rate for the user
 **/
function updateStateOnBorrow(
        address _reserve,
        address _user,
        uint256 _amountBorrowed,
        uint256 _borrowFee,
        CoreLibrary.InterestRateMode _rateMode
    ) external onlyLendingPool returns (uint256, uint256) {
        // getting the previous borrow data of the user
        (uint256 principalBorrowBalance, , uint256 balanceIncrease) = getUserBorrowBalances(
            _reserve,
            _user
        );

        updateReserveStateOnBorrowInternal(
            _reserve,
            _user,
            principalBorrowBalance,
            balanceIncrease,
            _amountBorrowed,
            _rateMode
        );

        updateUserStateOnBorrowInternal(
            _reserve,
            _user,
            _amountBorrowed,
            balanceIncrease,
            _borrowFee,
            _rateMode
        );

        updateReserveInterestRatesAndTimestampInternal(_reserve, 0, _amountBorrowed);

        return (getUserCurrentBorrowRate(_reserve, _user), balanceIncrease);
    }
// Solidity 0.5.14
/**
 * @dev updates the state of the core as a consequence of a repay action.
 * @param _reserve the address of the reserve on which the user is repaying
 * @param _user the address of the borrower
 * @param _paybackAmountMinusFees the amount being paid back minus fees
 * @param _originationFeeRepaid the fee on the amount that is being repaid
 * @param _balanceIncrease the accrued interest on the borrowed amount
 * @param _repaidWholeLoan true if the user is repaying the whole loan
 **/
function updateStateOnRepay(
        address _reserve,
        address _user,
        uint256 _paybackAmountMinusFees,
        uint256 _originationFeeRepaid,
        uint256 _balanceIncrease,
        bool _repaidWholeLoan
    ) external onlyLendingPool {
        updateReserveStateOnRepayInternal(
            _reserve,
            _user,
            _paybackAmountMinusFees,
            _balanceIncrease
        );
        updateUserStateOnRepayInternal(
            _reserve,
            _user,
            _paybackAmountMinusFees,
            _originationFeeRepaid,
            _balanceIncrease,
            _repaidWholeLoan
        );

        updateReserveInterestRatesAndTimestampInternal(_reserve, _paybackAmountMinusFees, 0);
    }
// Solidity 0.5.14
/**
 * @dev updates the state of the core as a consequence of a swap rate action.
 * @param _reserve the address of the reserve on which the user is repaying
 * @param _user the address of the borrower
 * @param _principalBorrowBalance the amount borrowed by the user
 * @param _compoundedBorrowBalance the amount borrowed plus accrued interest
 * @param _balanceIncrease the accrued interest on the borrowed amount
 * @param _currentRateMode the current interest rate mode for the user
 **/
function updateStateOnSwapRate(
        address _reserve,
        address _user,
        uint256 _principalBorrowBalance,
        uint256 _compoundedBorrowBalance,
        uint256 _balanceIncrease,
        CoreLibrary.InterestRateMode _currentRateMode
    ) external onlyLendingPool returns (CoreLibrary.InterestRateMode, uint256) {
        updateReserveStateOnSwapRateInternal(
            _reserve,
            _user,
            _principalBorrowBalance,
            _compoundedBorrowBalance,
            _currentRateMode
        );

        CoreLibrary.InterestRateMode newRateMode = updateUserStateOnSwapRateInternal(
            _reserve,
            _user,
            _balanceIncrease,
            _currentRateMode
        );

        updateReserveInterestRatesAndTimestampInternal(_reserve, 0, 0);

        return (newRateMode, getUserCurrentBorrowRate(_reserve, _user));
    }
// Solidity 0.5.14
/**
 * @dev updates the state of the core as a consequence of a liquidation action.
 * @param _principalReserve the address of the principal reserve that is being repaid
 * @param _collateralReserve the address of the collateral reserve that is being liquidated
 * @param _user the address of the borrower
 * @param _amountToLiquidate the amount being repaid by the liquidator
 * @param _collateralToLiquidate the amount of collateral being liquidated
 * @param _feeLiquidated the amount of origination fee being liquidated
 * @param _liquidatedCollateralForFee the amount of collateral equivalent to the origination fee + bonus
 * @param _balanceIncrease the accrued interest on the borrowed amount
 * @param _liquidatorReceivesAToken true if the liquidator will receive aTokens, false otherwise
 **/
function updateStateOnLiquidation(
        address _principalReserve,
        address _collateralReserve,
        address _user,
        uint256 _amountToLiquidate,
        uint256 _collateralToLiquidate,
        uint256 _feeLiquidated,
        uint256 _liquidatedCollateralForFee,
        uint256 _balanceIncrease,
        bool _liquidatorReceivesAToken
    ) external onlyLendingPool {
        updatePrincipalReserveStateOnLiquidationInternal(
            _principalReserve,
            _user,
            _amountToLiquidate,
            _balanceIncrease
        );

        updateCollateralReserveStateOnLiquidationInternal(
            _collateralReserve
        );

        updateUserStateOnLiquidationInternal(
            _principalReserve,
            _user,
            _amountToLiquidate,
            _feeLiquidated,
            _balanceIncrease
        );

        updateReserveInterestRatesAndTimestampInternal(_principalReserve, _amountToLiquidate, 0);

        if (!_liquidatorReceivesAToken) {
            updateReserveInterestRatesAndTimestampInternal(
                _collateralReserve,
                0,
                _collateralToLiquidate.add(_liquidatedCollateralForFee)
            );
        }

    }
// Solidity 0.5.14
/**
 * @dev updates the state of the core as a consequence of a stable rate rebalance
 * @param _reserve the address of the principal reserve where the user borrowed
 * @param _user the address of the borrower
 * @param _balanceIncrease the accrued interest on the borrowed amount
 * @return the new stable rate for the user
 **/
function updateStateOnRebalance(address _reserve, address _user, uint256 _balanceIncrease)
        external
        onlyLendingPool
        returns (uint256)
    {
        updateReserveStateOnRebalanceInternal(_reserve, _user, _balanceIncrease);

        //update user data and rebalance the rate
        updateUserStateOnRebalanceInternal(_reserve, _user, _balanceIncrease);
        updateReserveInterestRatesAndTimestampInternal(_reserve, 0, 0);
        return usersReserveData[_user][_reserve].stableBorrowRate;
    }
// Solidity 0.5.14
/**
 * @dev transfers to the user a specific amount from the reserve.
 * @param _reserve the address of the reserve where the transfer is happening
 * @param _user the address of the user receiving the transfer
 * @param _amount the amount being transferred
 **/
function transferToUser(address _reserve, address payable _user, uint256 _amount)
        external
        onlyLendingPool
    {
        if (_reserve != EthAddressLib.ethAddress()) {
            ERC20(_reserve).safeTransfer(_user, _amount);
        } else {
            //solium-disable-next-line
            (bool result, ) = _user.call.value(_amount).gas(50000)("");
            require(result, "Transfer of ETH failed");
        }
    }
// Solidity 0.5.14
/**
 * @dev transfers the protocol fees to the fees collection address
 * @param _token the address of the token being transferred
 * @param _user the address of the user from where the transfer is happening
 * @param _amount the amount being transferred
 * @param _destination the fee receiver address
 **/
function transferToFeeCollectionAddress(
        address _token,
        address _user,
        uint256 _amount,
        address _destination
    ) external payable onlyLendingPool {
        address payable feeAddress = address(uint160(_destination)); //cast the address to payable

        if (_token != EthAddressLib.ethAddress()) {
            require(
                msg.value == 0,
                "User is sending ETH along with the ERC20 transfer. Check the value attribute of the transaction"
            );
            ERC20(_token).safeTransferFrom(_user, feeAddress, _amount);
        } else {
            require(msg.value >= _amount, "The amount and the value sent to deposit do not match");
            //solium-disable-next-line
            (bool result, ) = feeAddress.call.value(_amount).gas(50000)("");
            require(result, "Transfer of ETH failed");
        }
    }
// Solidity 0.5.14
/**
 * @dev transfers the fees to the fees collection address in the case of liquidation
 * @param _token the address of the token being transferred
 * @param _amount the amount being transferred
 * @param _destination the fee receiver address
 **/
function liquidateFee(
        address _token,
        uint256 _amount,
        address _destination
    ) external payable onlyLendingPool {
        address payable feeAddress = address(uint160(_destination)); //cast the address to payable
        require(
            msg.value == 0,
            "Fee liquidation does not require any transfer of value"
        );

        if (_token != EthAddressLib.ethAddress()) {
            ERC20(_token).safeTransfer(feeAddress, _amount);
        } else {
            //solium-disable-next-line
            (bool result, ) = feeAddress.call.value(_amount).gas(50000)("");
            require(result, "Transfer of ETH failed");
        }
    }
// Solidity 0.5.14
/**
 * @dev transfers an amount from a user to the destination reserve
 * @param _reserve the address of the reserve where the amount is being transferred
 * @param _user the address of the user from where the transfer is happening
 * @param _amount the amount being transferred
 **/
function transferToReserve(address _reserve, address payable _user, uint256 _amount)
        external
        payable
        onlyLendingPool
    {
        if (_reserve != EthAddressLib.ethAddress()) {
            require(msg.value == 0, "User is sending ETH along with the ERC20 transfer.");
            ERC20(_reserve).safeTransferFrom(_user, address(this), _amount);

        } else {
            require(msg.value >= _amount, "The amount and the value sent to deposit do not match");

            if (msg.value > _amount) {
                //send back excess ETH
                uint256 excessAmount = msg.value.sub(_amount);
                //solium-disable-next-line
                (bool result, ) = _user.call.value(excessAmount).gas(50000)("");
                require(result, "Transfer of ETH failed");
            }
        }
    }
// Solidity 0.5.14
/**
 * @dev returns the basic data (balances, fee accrued, reserve enabled/disabled as collateral)
 * needed to calculate the global account data in the LendingPoolDataProvider
 * @param _reserve the address of the reserve
 * @param _user the address of the user
 * @return the user deposited balance, the principal borrow balance, the fee, and if the reserve is enabled as collateral or not
 **/
function getUserBasicReserveData(address _reserve, address _user)
        external
        view
        returns (uint256, uint256, uint256, bool)
    {
        CoreLibrary.ReserveData storage reserve = reserves[_reserve];
        CoreLibrary.UserReserveData storage user = usersReserveData[_user][_reserve];

        uint256 underlyingBalance = getUserUnderlyingAssetBalance(_reserve, _user);

        if (user.principalBorrowBalance == 0) {
            return (underlyingBalance, 0, 0, user.useAsCollateral);
        }

        return (
            underlyingBalance,
            user.getCompoundedBorrowBalance(reserve),
            user.originationFee,
            user.useAsCollateral
        );
    }
// Solidity 0.5.14
/**
 * @dev checks if a user is allowed to borrow at a stable rate
 * @param _reserve the reserve address
 * @param _user the user
 * @param _amount the amount the the user wants to borrow
 * @return true if the user is allowed to borrow at a stable rate, false otherwise
 **/
function isUserAllowedToBorrowAtStable(address _reserve, address _user, uint256 _amount)
        external
        view
        returns (bool)
    {
        CoreLibrary.ReserveData storage reserve = reserves[_reserve];
        CoreLibrary.UserReserveData storage user = usersReserveData[_user][_reserve];

        if (!reserve.isStableBorrowRateEnabled) return false;

        return
            !user.useAsCollateral ||
            !reserve.usageAsCollateralEnabled ||
            _amount > getUserUnderlyingAssetBalance(_reserve, _user);
    }
// Solidity 0.5.14
/**
 * @dev gets the reserve current stable borrow rate. Is the market rate if the reserve is empty
 * @param _reserve the reserve address
 * @return the reserve current stable borrow rate
 **/
function getReserveCurrentStableBorrowRate(address _reserve) public view returns (uint256) {
        CoreLibrary.ReserveData storage reserve = reserves[_reserve];
        ILendingRateOracle oracle = ILendingRateOracle(addressesProvider.getLendingRateOracle());

        if (reserve.currentStableBorrowRate == 0) {
            //no stable rate borrows yet
            return oracle.getMarketBorrowRate(_reserve);
        }

        return reserve.currentStableBorrowRate;
    }
// Solidity 0.5.14
/**
 * @dev this function aggregates the configuration parameters of the reserve.
 * It's used in the LendingPoolDataProvider specifically to save gas, and avoid
 * multiple external contract calls to fetch the same data.
 * @param _reserve the reserve address
 * @return the reserve decimals
 * @return the base ltv as collateral
 * @return the liquidation threshold
 * @return if the reserve is used as collateral or not
 **/
function getReserveConfiguration(address _reserve)
        external
        view
        returns (uint256, uint256, uint256, bool)
    {
        uint256 decimals;
        uint256 baseLTVasCollateral;
        uint256 liquidationThreshold;
        bool usageAsCollateralEnabled;

        CoreLibrary.ReserveData storage reserve = reserves[_reserve];
        decimals = reserve.decimals;
        baseLTVasCollateral = reserve.baseLTVasCollateral;
        liquidationThreshold = reserve.liquidationThreshold;
        usageAsCollateralEnabled = reserve.usageAsCollateralEnabled;

        return (decimals, baseLTVasCollateral, liquidationThreshold, usageAsCollateralEnabled);
    }
// Solidity 0.5.14
/**
 * @dev returns the utilization rate U of a specific reserve
 * @param _reserve the reserve for which the information is needed
 * @return the utilization rate in ray
 **/
function getReserveUtilizationRate(address _reserve) public view returns (uint256) {
        CoreLibrary.ReserveData storage reserve = reserves[_reserve];

        uint256 totalBorrows = reserve.getTotalBorrows();

        if (totalBorrows == 0) {
            return 0;
        }

        uint256 availableLiquidity = getReserveAvailableLiquidity(_reserve);

        return totalBorrows.rayDiv(availableLiquidity.add(totalBorrows));
    }
// Solidity 0.5.14
/**
 * @dev users with no loans in progress have NONE as borrow rate mode
 * @param _reserve the address of the reserve for which the information is needed
 * @param _user the address of the user for which the information is needed
 * @return the borrow rate mode for the user,
 **/
function getUserCurrentBorrowRateMode(address _reserve, address _user)
        public
        view
        returns (CoreLibrary.InterestRateMode)
    {
        CoreLibrary.UserReserveData storage user = usersReserveData[_user][_reserve];

        if (user.principalBorrowBalance == 0) {
            return CoreLibrary.InterestRateMode.NONE;
        }

        return
            user.stableBorrowRate > 0
            ? CoreLibrary.InterestRateMode.STABLE
            : CoreLibrary.InterestRateMode.VARIABLE;
    }
// Solidity 0.5.14
/**
 * @dev gets the current borrow rate of the user
 * @param _reserve the address of the reserve for which the information is needed
 * @param _user the address of the user for which the information is needed
 * @return the borrow rate for the user,
 **/
function getUserCurrentBorrowRate(address _reserve, address _user)
        internal
        view
        returns (uint256)
    {
        CoreLibrary.InterestRateMode rateMode = getUserCurrentBorrowRateMode(_reserve, _user);

        if (rateMode == CoreLibrary.InterestRateMode.NONE) {
            return 0;
        }

        return
            rateMode == CoreLibrary.InterestRateMode.STABLE
            ? usersReserveData[_user][_reserve].stableBorrowRate
            : reserves[_reserve].currentVariableBorrowRate;
    }
// Solidity 0.5.14
/**
 * @dev calculates and returns the borrow balances of the user
 * @param _reserve the address of the reserve
 * @param _user the address of the user
 * @return the principal borrow balance, the compounded balance and the balance increase since the last borrow/repay/swap/rebalance
 **/
function getUserBorrowBalances(address _reserve, address _user)
        public
        view
        returns (uint256, uint256, uint256)
    {
        CoreLibrary.UserReserveData storage user = usersReserveData[_user][_reserve];
        if (user.principalBorrowBalance == 0) {
            return (0, 0, 0);
        }

        uint256 principal = user.principalBorrowBalance;
        uint256 compoundedBalance = CoreLibrary.getCompoundedBorrowBalance(
            user,
            reserves[_reserve]
        );
        return (principal, compoundedBalance, compoundedBalance.sub(principal));
    }
// Solidity 0.5.14
/**
 * @dev removes the last added reserve in the reservesList array
 * @param _reserveToRemove the address of the reserve
 **/
function removeLastAddedReserve(address _reserveToRemove)
     external onlyLendingPoolConfigurator {

        address lastReserve = reservesList[reservesList.length-1];

        require(lastReserve == _reserveToRemove, "Reserve being removed is different than the reserve requested");

        //as we can't check if totalLiquidity is 0 (since the reserve added might not be an ERC20) we at least check that there is nothing borrowed
        require(getReserveTotalBorrows(lastReserve) == 0, "Cannot remove a reserve with liquidity deposited");

        reserves[lastReserve].isActive = false;
        reserves[lastReserve].aTokenAddress = address(0);
        reserves[lastReserve].decimals = 0;
        reserves[lastReserve].lastLiquidityCumulativeIndex = 0;
        reserves[lastReserve].lastVariableBorrowCumulativeIndex = 0;
        reserves[lastReserve].borrowingEnabled = false;
        reserves[lastReserve].usageAsCollateralEnabled = false;
        reserves[lastReserve].baseLTVasCollateral = 0;
        reserves[lastReserve].liquidationThreshold = 0;
        reserves[lastReserve].liquidationBonus = 0;
        reserves[lastReserve].interestRateStrategyAddress = address(0);

        reservesList.pop();
    }
// Solidity 0.5.14
/**
 * @dev updates the state of a reserve as a consequence of a borrow action.
 * @param _reserve the address of the reserve on which the user is borrowing
 * @param _user the address of the borrower
 * @param _principalBorrowBalance the previous borrow balance of the borrower before the action
 * @param _balanceIncrease the accrued interest of the user on the previous borrowed amount
 * @param _amountBorrowed the new amount borrowed
 * @param _rateMode the borrow rate mode (stable, variable)
 **/
function updateReserveStateOnBorrowInternal(
        address _reserve,
        address _user,
        uint256 _principalBorrowBalance,
        uint256 _balanceIncrease,
        uint256 _amountBorrowed,
        CoreLibrary.InterestRateMode _rateMode
    ) internal {
        reserves[_reserve].updateCumulativeIndexes();

        //increasing reserve total borrows to account for the new borrow balance of the user
        //NOTE: Depending on the previous borrow mode, the borrows might need to be switched from variable to stable or vice versa

        updateReserveTotalBorrowsByRateModeInternal(
            _reserve,
            _user,
            _principalBorrowBalance,
            _balanceIncrease,
            _amountBorrowed,
            _rateMode
        );
    }