lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Sets Reward Distributor
 * @dev Admin function to set reward distributor
 * @param _newRewardDistributor new reward distributor
 */
function _setRewardDistributor(address _newRewardDistributor)
        external
        override
        onlyOwner
    {
        address _oldRewardDistributor = rewardDistributor;
        require(
            _newRewardDistributor != address(0) &&
                _newRewardDistributor != _oldRewardDistributor,
            "Reward Distributor address invalid"
        );

        rewardDistributor = _newRewardDistributor;
        emit NewRewardDistributor(_oldRewardDistributor, _newRewardDistributor);
    }
// Solidity 0.6.12
/**
 * @notice Hook function before iToken `mint()`
 * Checks if the account should be allowed to mint the given iToken
 * Will `revert()` if any check fails
 * @param _iToken The iToken to check the mint against
 * @param _minter The account which would get the minted tokens
 * @param _mintAmount The amount of underlying being minted to iToken
 */
function beforeMint(
        address _iToken,
        address _minter,
        uint256 _mintAmount
    ) external override {
        _checkiTokenListed(_iToken);

        Market storage _market = markets[_iToken];
        require(!_market.mintPaused, "Token mint has been paused");

        // Check the iToken's supply capacity, -1 means no limit
        uint256 _totalSupplyUnderlying =
            IERC20Upgradeable(_iToken).totalSupply().rmul(
                IiToken(_iToken).exchangeRateStored()
            );
        require(
            _totalSupplyUnderlying.add(_mintAmount) <= _market.supplyCapacity,
            "Token supply capacity reached"
        );

        // Update the Reward Distribution Supply state and distribute reward to suppplier
        IRewardDistributor(rewardDistributor).updateDistributionState(
            _iToken,
            false
        );
        IRewardDistributor(rewardDistributor).updateReward(
            _iToken,
            _minter,
            false
        );
    }
// Solidity 0.6.12
/**
 * @notice Hook function before iToken `redeem()`
 * Checks if the account should be allowed to redeem the given iToken
 * Will `revert()` if any check fails
 * @param _iToken The iToken to check the redeem against
 * @param _redeemer The account which would redeem iToken
 * @param _redeemAmount The amount of iToken to redeem
 */
function beforeRedeem(
        address _iToken,
        address _redeemer,
        uint256 _redeemAmount
    ) external override {
        // _redeemAllowed below will check whether _iToken is listed

        require(!markets[_iToken].redeemPaused, "Token redeem has been paused");

        _redeemAllowed(_iToken, _redeemer, _redeemAmount);

        // Update the Reward Distribution Supply state and distribute reward to suppplier
        IRewardDistributor(rewardDistributor).updateDistributionState(
            _iToken,
            false
        );
        IRewardDistributor(rewardDistributor).updateReward(
            _iToken,
            _redeemer,
            false
        );
    }
// Solidity 0.6.12
/**
 * @notice Hook function before iToken `borrow()`
 * Checks if the account should be allowed to borrow the given iToken
 * Will `revert()` if any check fails
 * @param _iToken The iToken to check the borrow against
 * @param _borrower The account which would borrow iToken
 * @param _borrowAmount The amount of underlying to borrow
 */
function beforeBorrow(
        address _iToken,
        address _borrower,
        uint256 _borrowAmount
    ) external override {
        _checkiTokenListed(_iToken);

        Market storage _market = markets[_iToken];
        require(!_market.borrowPaused, "Token borrow has been paused");

        if (!hasBorrowed(_borrower, _iToken)) {
            // Unlike collaterals, borrowed asset can only be added by iToken,
            // rather than enabled by user directly.
            require(msg.sender == _iToken, "sender must be iToken");

            // Have checked _iToken is listed, just add it
            _addToBorrowed(_borrower, _iToken);
        }

        // Check borrower's equity
        (, uint256 _shortfall, , ) =
            calcAccountEquityWithEffect(_borrower, _iToken, 0, _borrowAmount);

        require(_shortfall == 0, "Account has some shortfall");

        // Check the iToken's borrow capacity, -1 means no limit
        uint256 _totalBorrows = IiToken(_iToken).totalBorrows();
        require(
            _totalBorrows.add(_borrowAmount) <= _market.borrowCapacity,
            "Token borrow capacity reached"
        );

        // Update the Reward Distribution Borrow state and distribute reward to borrower
        IRewardDistributor(rewardDistributor).updateDistributionState(
            _iToken,
            true
        );
        IRewardDistributor(rewardDistributor).updateReward(
            _iToken,
            _borrower,
            true
        );
    }
// Solidity 0.8.9
/// @notice A quantity of integers that were committed by anybody and are now mature are revealed
/// @param  revealsLeft up to how many reveals will occur
function _reveal(uint32 revealsLeft) internal {
        for (; revealsLeft > 0 && _commitQueue.isMature(); revealsLeft--) {
            // Get one from queue
            address recipient;
            uint64 maturityBlock;
            (recipient, maturityBlock) = _commitQueue.dequeue();

            // Allocate randomly
            uint256 randomNumber = _random(maturityBlock);
            uint256 randomIndex = randomNumber % _dropInventoryIntegers.count();
            uint allocatedNumber = _dropInventoryIntegers.popByIndex(randomIndex);
            _revealCallback(recipient, allocatedNumber);
        }
    }
// Solidity 0.6.12
/**
 * @notice Hook function after iToken `repayBorrow()`
 * Will `revert()` if any operation fails
 * @param _iToken The iToken being repaid
 * @param _payer The account which would repay
 * @param _borrower The account which has borrowed
 * @param _repayAmount  The amount of underlying being repaied
 */
function afterRepayBorrow(
        address _iToken,
        address _payer,
        address _borrower,
        uint256 _repayAmount
    ) external override {
        _checkiTokenListed(_iToken);

        // Remove _iToken from borrowed list if new borrow balance is 0
        if (IiToken(_iToken).borrowBalanceStored(_borrower) == 0) {
            // Only allow called by iToken as we are going to remove this token from borrower's borrowed list
            require(msg.sender == _iToken, "sender must be iToken");

            // Have checked _iToken is listed, just remove it
            _removeFromBorrowed(_borrower, _iToken);
        }

        _payer;
        _repayAmount;
    }
// Solidity 0.6.12
/**
 * @notice Hook function before iToken `liquidateBorrow()`
 * Checks if the account should be allowed to liquidate the given iToken
 * for the borrower. Will `revert()` if any check fails
 * @param _iTokenBorrowed The iToken was borrowed
 * @param _iTokenCollateral The collateral iToken to be liqudate with
 * @param _liquidator The account which would repay the borrowed iToken
 * @param _borrower The account which has borrowed
 * @param _repayAmount The amount of underlying to repay
 */
function beforeLiquidateBorrow(
        address _iTokenBorrowed,
        address _iTokenCollateral,
        address _liquidator,
        address _borrower,
        uint256 _repayAmount
    ) external override {
        // Tokens must have been listed
        require(
            iTokens.contains(_iTokenBorrowed) &&
                iTokens.contains(_iTokenCollateral),
            "Tokens have not been listed"
        );

        (, uint256 _shortfall, , ) = calcAccountEquity(_borrower);

        require(_shortfall > 0, "Account does not have shortfall");

        // Only allowed to repay the borrow balance's close factor
        uint256 _borrowBalance =
            IiToken(_iTokenBorrowed).borrowBalanceStored(_borrower);
        uint256 _maxRepay = _borrowBalance.rmul(closeFactorMantissa);

        require(_repayAmount <= _maxRepay, "Repay exceeds max repay allowed");

        _liquidator;
    }
// Solidity 0.6.12
/**
 * @notice Hook function after iToken `liquidateBorrow()`
 * Will `revert()` if any operation fails
 * @param _iTokenBorrowed The iToken was borrowed
 * @param _iTokenCollateral The collateral iToken to be seized
 * @param _liquidator The account which would repay and seize
 * @param _borrower The account which has borrowed
 * @param _repaidAmount  The amount of underlying being repaied
 * @param _seizedAmount  The amount of collateral being seized
 */
function afterLiquidateBorrow(
        address _iTokenBorrowed,
        address _iTokenCollateral,
        address _liquidator,
        address _borrower,
        uint256 _repaidAmount,
        uint256 _seizedAmount
    ) external override {
        _iTokenBorrowed;
        _iTokenCollateral;
        _liquidator;
        _borrower;
        _repaidAmount;
        _seizedAmount;

        // Unlike repayBorrow, liquidateBorrow does not allow to repay all borrow balance
        // No need to check whether should remove from borrowed asset list
    }
// Solidity 0.6.12
/**
 * @notice Hook function before iToken `seize()`
 * Checks if the liquidator should be allowed to seize the collateral iToken
 * Will `revert()` if any check fails
 * @param _iTokenCollateral The collateral iToken to be seize
 * @param _iTokenBorrowed The iToken was borrowed
 * @param _liquidator The account which has repaid the borrowed iToken
 * @param _borrower The account which has borrowed
 * @param _seizeAmount The amount of collateral iToken to seize
 */
function beforeSeize(
        address _iTokenCollateral,
        address _iTokenBorrowed,
        address _liquidator,
        address _borrower,
        uint256 _seizeAmount
    ) external override {
        require(!seizePaused, "Seize has been paused");

        // Markets must have been listed
        require(
            iTokens.contains(_iTokenBorrowed) &&
                iTokens.contains(_iTokenCollateral),
            "Tokens have not been listed"
        );

        // Sanity Check the controllers
        require(
            IiToken(_iTokenBorrowed).controller() ==
                IiToken(_iTokenCollateral).controller(),
            "Controller mismatch between Borrowed and Collateral"
        );

        // Update the Reward Distribution Supply state on collateral
        IRewardDistributor(rewardDistributor).updateDistributionState(
            _iTokenCollateral,
            false
        );

        // Update reward of liquidator and borrower on collateral
        IRewardDistributor(rewardDistributor).updateReward(
            _iTokenCollateral,
            _liquidator,
            false
        );
        IRewardDistributor(rewardDistributor).updateReward(
            _iTokenCollateral,
            _borrower,
            false
        );

        _seizeAmount;
    }
// Solidity 0.6.12
/**
 * @notice Hook function before iToken `transfer()`
 * Checks if the transfer should be allowed
 * Will `revert()` if any check fails
 * @param _iToken The iToken to be transfered
 * @param _from The account to be transfered from
 * @param _to The account to be transfered to
 * @param _amount The amount to be transfered
 */
function beforeTransfer(
        address _iToken,
        address _from,
        address _to,
        uint256 _amount
    ) external override {
        // _redeemAllowed below will check whether _iToken is listed

        require(!transferPaused, "Transfer has been paused");

        // Check account equity with this amount to decide whether the transfer is allowed
        _redeemAllowed(_iToken, _from, _amount);

        // Update the Reward Distribution supply state
        IRewardDistributor(rewardDistributor).updateDistributionState(
            _iToken,
            false
        );

        // Update reward of from and to
        IRewardDistributor(rewardDistributor).updateReward(
            _iToken,
            _from,
            false
        );
        IRewardDistributor(rewardDistributor).updateReward(_iToken, _to, false);
    }
// Solidity 0.6.12
/**
 * @notice Hook function before iToken `flashloan()`
 * Checks if the flashloan should be allowed
 * Will `revert()` if any check fails
 * @param _iToken The iToken to be flashloaned
 * @param _to The account flashloaned transfer to
 * @param _amount The amount to be flashloaned
 */
function beforeFlashloan(
        address _iToken,
        address _to,
        uint256 _amount
    ) external override {
        // Flashloan share the same pause state with borrow
        require(!markets[_iToken].borrowPaused, "Token borrow has been paused");

        _checkiTokenListed(_iToken);

        _to;
        _amount;

        // Update the Reward Distribution Borrow state
        IRewardDistributor(rewardDistributor).updateDistributionState(
            _iToken,
            true
        );
    }
// Solidity 0.8.9
/// @notice Find the Plus Code representing `childCode` plus some more area if input is a valid Plus Code; otherwise
///         revert
/// @param  childCode  a Plus Code
/// @return parentCode the Plus Code representing the smallest area which contains the `childCode` area plus some
///                    additional area
function getParent(uint256 childCode) internal pure returns (uint256 parentCode) {
        uint8 childCodeLength = getCodeLength(childCode);
        if (childCodeLength == 2) {
            revert("Code length 2 Plus Codes do not have parents");
        }
        if (childCodeLength == 4) {
            return childCode & 0xFFFF00000000000000 | 0x3030303030302B;
        }
        if (childCodeLength == 6) {
            return childCode & 0xFFFFFFFF0000000000 | 0x303030302B;
        }
        if (childCodeLength == 8) {
            return childCode & 0xFFFFFFFFFFFF000000 | 0x30302B;
        }
        if (childCodeLength == 10) {
            return childCode >> 8*2;
        }
        // childCodeLength ∈ {11, 12}
        return childCode >> 8*1;
    }
// Solidity 0.6.12
/**
 * @notice Calculate amount of collateral iToken to seize after repaying an underlying amount
 * @dev Used in liquidation
 * @param _iTokenBorrowed The iToken was borrowed
 * @param _iTokenCollateral The collateral iToken to be seized
 * @param _actualRepayAmount The amount of underlying token liquidator has repaied
 * @return _seizedTokenCollateral amount of iTokenCollateral tokens to be seized
 */
function liquidateCalculateSeizeTokens(
        address _iTokenBorrowed,
        address _iTokenCollateral,
        uint256 _actualRepayAmount
    ) external view virtual override returns (uint256 _seizedTokenCollateral) {
        /* Read oracle prices for borrowed and collateral assets */
        uint256 _priceBorrowed =
            IPriceOracle(priceOracle).getUnderlyingPrice(_iTokenBorrowed);
        uint256 _priceCollateral =
            IPriceOracle(priceOracle).getUnderlyingPrice(_iTokenCollateral);
        require(
            _priceBorrowed != 0 && _priceCollateral != 0,
            "Borrowed or Collateral asset price is invalid"
        );

        uint256 _valueRepayPlusIncentive =
            _actualRepayAmount.mul(_priceBorrowed).rmul(
                liquidationIncentiveMantissa
            );

        // Use stored value here as it is view function
        uint256 _exchangeRateMantissa =
            IiToken(_iTokenCollateral).exchangeRateStored();

        // seizedTokenCollateral = valueRepayPlusIncentive / valuePerTokenCollateral
        // valuePerTokenCollateral = exchangeRateMantissa * priceCollateral
        _seizedTokenCollateral = _valueRepayPlusIncentive
            .rdiv(_exchangeRateMantissa)
            .div(_priceCollateral);
    }
// Solidity 0.6.12
/**
 * @notice Returns the markets list the account has entered
 * @param _account The address of the account to query
 * @return _accountCollaterals The markets list the account has entered
 */
function getEnteredMarkets(address _account)
        external
        view
        override
        returns (address[] memory _accountCollaterals)
    {
        AccountData storage _accountData = accountsData[_account];

        uint256 _len = _accountData.collaterals.length();
        _accountCollaterals = new address[](_len);
        for (uint256 i = 0; i < _len; i++) {
            _accountCollaterals[i] = _accountData.collaterals.at(i);
        }
    }
// Solidity 0.6.12
/**
 * @notice Add markets to `msg.sender`'s markets list for liquidity calculations
 * @param _iTokens The list of addresses of the iToken markets to be entered
 * @return _results Success indicator for whether each corresponding market was entered
 */
function enterMarkets(address[] calldata _iTokens)
        external
        override
        returns (bool[] memory _results)
    {
        uint256 _len = _iTokens.length;

        _results = new bool[](_len);
        for (uint256 i = 0; i < _len; i++) {
            _results[i] = _enterMarket(_iTokens[i], msg.sender);
        }
    }
// Solidity 0.6.12
/**
 * @notice Add the market to the account's markets list for liquidity calculations
 * @param _iToken The market to enter
 * @param _account The address of the account to modify
 * @return True if entered successfully, false for non-listed market or other errors
 */
function _enterMarket(address _iToken, address _account)
        internal
        returns (bool)
    {
        // Market not listed, skip it
        if (!iTokens.contains(_iToken)) {
            return false;
        }

        // add() will return false if iToken is in account's market list
        if (accountsData[_account].collaterals.add(_iToken)) {
            emit MarketEntered(_iToken, _account);
        }

        return true;
    }
// Solidity 0.6.12
/**
 * @notice Remove markets from `msg.sender`'s collaterals for liquidity calculations
 * @param _iTokens The list of addresses of the iToken to exit
 * @return _results Success indicators for whether each corresponding market was exited
 */
function exitMarkets(address[] calldata _iTokens)
        external
        override
        returns (bool[] memory _results)
    {
        uint256 _len = _iTokens.length;
        _results = new bool[](_len);
        for (uint256 i = 0; i < _len; i++) {
            _results[i] = _exitMarket(_iTokens[i], msg.sender);
        }
    }
// Solidity 0.8.9
/// @dev Convert a Plus Code to an ASCII (and UTF-8) string
/// @param  plusCode the Plus Code to format
/// @return the ASCII (and UTF-8) string showing the Plus Code
function toString(uint256 plusCode) internal pure returns(string memory) {
        getCodeLength(plusCode);
        bytes memory retval = new bytes(0);
        while (plusCode > 0) {
            retval = abi.encodePacked(uint8(plusCode % 2**8), retval);
            plusCode >>= 8;
        }
        return string(retval);
    }
// Solidity 0.6.12
/**
 * @notice Returns the asset list the account has borrowed
 * @param _account The address of the account to query
 * @return _borrowedAssets The asset list the account has borrowed
 */
function getBorrowedAssets(address _account)
        external
        view
        override
        returns (address[] memory _borrowedAssets)
    {
        AccountData storage _accountData = accountsData[_account];

        uint256 _len = _accountData.borrowed.length();
        _borrowedAssets = new address[](_len);
        for (uint256 i = 0; i < _len; i++) {
            _borrowedAssets[i] = _accountData.borrowed.at(i);
        }
    }
// Solidity 0.6.12
/**
 * @notice Return all of the iTokens
 * @return _alliTokens The list of iToken addresses
 */
function getAlliTokens()
        public
        view
        override
        returns (address[] memory _alliTokens)
    {
        EnumerableSetUpgradeable.AddressSet storage _iTokens = iTokens;

        uint256 _len = _iTokens.length();
        _alliTokens = new address[](_len);
        for (uint256 i = 0; i < _len; i++) {
            _alliTokens[i] = _iTokens.at(i);
        }
    }
// Solidity 0.7.3
// Pick one ETH Winner when 5,000 cats are minted.
function _ethRaffle() private {
        uint256 swag = 4959;
        uint256 rd = randomizer() % 1000;
        bytes32 txHash = keccak256(
            abi.encode(
                ownerOf(swag - 1000 + rd),
                ownerOf(swag - 2000 + rd),
                ownerOf(swag - 3000 + rd),
                ownerOf(swag - 4000 + rd),
                msg.sender
            )
        );
        ethWinner = ownerOf((uint256(txHash) % 4959) + 1);
    }
// Solidity 0.7.3
// Pick one Tesla Winner when 9,999 cats are minted.
function _tesla() private {
        require(totalSupply() == MAX_CATS);

        uint256 swag = 9918;
        uint256 rd = randomizer() % 1000;

        bytes32 txHash = keccak256(
            abi.encode(
                ownerOf(swag - 1000 + rd),
                ownerOf(swag - 2000 + rd),
                ownerOf(swag - 3000 + rd),
                ownerOf(swag - 4000 + rd),
                ownerOf(swag - 5000 + rd),
                ownerOf(swag - 6000 + rd),
                msg.sender
            )
        );
        teslaWinner = ownerOf((uint256(txHash) % 9918) + 1);
    }
// Solidity 0.8.7
// Only callable by the erc721 contract on mint/transferFrom/safeTransferFrom.
// Updates reward amount and last claimed timestamp
function updateReward(
        address from,
        address to,
        uint256 qty
    ) external {
        require(msg.sender == address(CoreToken));
        if (from != address(0)) {
            rewards[from] += getPendingReward(from);
            lastClaimed[from] = block.timestamp;
            balances[from] -= qty;
        }
        if (to != address(0)) {
            balances[to] += qty;
            rewards[to] += getPendingReward(to);
            lastClaimed[to] = block.timestamp;
        }
    }
// Solidity 0.5.12
// --- Math ---
function add(uint x, int y) internal pure returns (uint z) {
        z = x + uint(y);
        require(y >= 0 || z <= x);
        require(y <= 0 || z >= x);
    }
// Solidity 0.5.12
// --- CDP Fungibility ---
function fork(bytes32 ilk, address src, address dst, int dink, int dart) external note {
        Urn storage u = urns[ilk][src];
        Urn storage v = urns[ilk][dst];
        Ilk storage i = ilks[ilk];

        u.ink = sub(u.ink, dink);
        u.art = sub(u.art, dart);
        v.ink = add(v.ink, dink);
        v.art = add(v.art, dart);

        uint utab = mul(u.art, i.rate);
        uint vtab = mul(v.art, i.rate);

        // both sides consent
        require(both(wish(src, msg.sender), wish(dst, msg.sender)), "Vat/not-allowed");

        // both sides safe
        require(utab <= mul(u.ink, i.spot), "Vat/not-safe-src");
        require(vtab <= mul(v.ink, i.spot), "Vat/not-safe-dst");

        // both sides non-dusty
        require(either(utab >= i.dust, u.art == 0), "Vat/dust-src");
        require(either(vtab >= i.dust, v.art == 0), "Vat/dust-dst");
    }
// Solidity 0.5.12
// --- CDP Confiscation ---
function grab(bytes32 i, address u, address v, address w, int dink, int dart) external note auth {
        Urn storage urn = urns[i][u];
        Ilk storage ilk = ilks[i];

        urn.ink = add(urn.ink, dink);
        urn.art = add(urn.art, dart);
        ilk.Art = add(ilk.Art, dart);

        int dtab = mul(ilk.rate, dart);

        gem[i][v] = sub(gem[i][v], dink);
        sin[w]    = sub(sin[w],    dtab);
        vice      = sub(vice,      dtab);
    }
// Solidity 0.5.12
// --- Rates ---
function fold(bytes32 i, address u, int rate) external note auth {
        require(live == 1, "Vat/not-live");
        Ilk storage ilk = ilks[i];
        ilk.rate = add(ilk.rate, rate);
        int rad  = mul(ilk.Art, rate);
        dai[u]   = add(dai[u], rad);
        debt     = add(debt,   rad);
    }