lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * Set rewards portion for stakers in rewards amount. 
 * ex: 98 => 98% (2% for dev)
 */
function setRewardFee(uint256 rewardFee) external onlyOwner returns (bool) {
        require(rewardFee >= 96 && rewardFee <= 100, 'MOLStaker: reward fee should be in 96 ~ 100.' );

        _rewardFee = rewardFee;
        return true;
    }
// Solidity 0.5.1
// -------------------- Resonance api ----------------//
function getRecommendByIndex(uint256 index, address userAddress)
    public
    view
//    onlyResonance() TODO
    returns (
        uint256 straightTime,
        address refeAddress,
        uint256 ethAmount,
        bool supported
    )
    {
        straightTime = recommendRecord[userAddress].straightTime[index];
        refeAddress = recommendRecord[userAddress].refeAddress[index];
        ethAmount = recommendRecord[userAddress].ethAmount[index];
        supported = recommendRecord[userAddress].supported[index];
    }
// Solidity 0.5.1
// -------------------- user api ------------------------ //
// get current address's recommend record
function getRecommendRecord()
    public
    view
    returns (
        uint256[] memory straightTime,
        address[] memory refeAddress,
        uint256[] memory ethAmount,
        bool[]    memory supported
    )
    {
        RecommendRecord memory records = recommendRecord[msg.sender];
        straightTime = records.straightTime;
        refeAddress = records.refeAddress;
        ethAmount = records.ethAmount;
        supported = records.supported;
    }
// Solidity 0.8.9
/**
 * @dev See {IERC721-balanceOf}.
 */
function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");

        uint count = 0;
        uint length = _owners.length;
        for( uint i = 0; i < length; ++i ){
          if( owner == _owners[i] ){
            ++count;
          }
        }

        delete length;
        return count;
    }
// Solidity 0.5.11
/**
 * @dev Method that allows operators to remove allowed address
 * @param _address represents address that should be removed
 */
function removeGame(address _address) public onlyOperators {
        require(isGameAddress[_address]);

        uint len = gameContractAddresses.length;

        for (uint i=0; i<len; i++) {
            if (gameContractAddresses[i] == _address) {
                // move last game to i-th position
                gameContractAddresses[i] = gameContractAddresses[len-1];
                // delete last game in array (its already moved so its duplicate)
                delete gameContractAddresses[len-1];
                // resize gameContractAddresses array
                gameContractAddresses.length--;
                // remove allowed address
                isGameAddress[_address] = false;
                break;
            }
        }

    }
// Solidity 0.5.11
/**
 * @dev Checks for player winning history (up to 5 bets)
 * @param _user represents address of user
 * @return returns history of user in format of uint where each decimal 2 means that bet is won, and 1 means that bet is lost
 */
function getUsersBettingHistoryWithTypes(address _user) public view returns(uint history, uint types) {
        uint len = bets[_user].length;

        if (len > 0) {
            while (len >= 0) {
                len--;

                if (bets[_user][len].won) {
                    history = history * 10 + 2;
                } else {
                    history = history * 10 + 1;
                }

                types = types * 10 + uint(bets[_user][len].gameType);

                if (len == 0 || history > 10000) {
                    break;
                }
            }
        }
    }
// Solidity 0.5.11
/**
 * @dev Calculate possible winning with specific chance and amount
 * @param _chance represents chance of winning bet
 * @param _amount represents amount that is played for bet
 * @return returns uint of players profit with specific chance and amount
 */
function getPossibleWinnings(uint _chance, uint _amount) public view returns(uint) {
        // don chance
        if (_chance == 50) {
            return _amount;
        }

        GameType _type = getTypeFromChance(_chance);

        if (_type == GameType.White) {
            return _amount;
        }

        if (_type == GameType.Red) {
            return _amount * 3;
        }

        if (_type == GameType.Blue) {
            return _amount * 4;
        }

        if (_type == GameType.Orange) {
            return _amount * 19;
        }

        return 0;
    }
// Solidity 0.5.11
/**
 * @dev check chances for specific game type and number
 * @param _gameType represents type of game
 * @return return value that represents chance of winning with specific number and gameType
 */
function getChance(GameType _gameType) public pure returns(uint) {
        if (_gameType == GameType.White) {
            return 4760;
        }

        if (_gameType == GameType.Red) {
            return 2380;
        }

        if (_gameType == GameType.Blue) {
            return 1904;
        }

        if (_gameType == GameType.Orange) {
            return 476;
        }
    }
// Solidity 0.5.11
/**
 * @dev check winning for specific bet for user
 * @param _user represents address of user
 * @param _betId represents id of bet for specific user
 * @return return value that represents users profit, in case round is not finished or bet is lost, returns 0
 */
function getUserProfitForFinishedBet(address _user, uint _betId) public view returns(uint) {
        Bet memory betObject = bets[_user][_betId];
        GameType selectedColor = rounds[betObject.round].selectedColor;
        uint chance = getChance(betObject.gameType);

        if (rounds[betObject.round].state == RoundState.Finished) {
            if (betObject.gameType == selectedColor) {
                return getPossibleWinnings(chance, betObject.amount);
            }
        }

        return 0;
    }
// Solidity 0.8.9
/**
 * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
 */
function tokenOfOwnerByIndex(address owner, uint256 index)
        public
        view
        virtual
        override
        returns (uint256 tokenId)
    {
        require(
            index < this.balanceOf(owner),
            "ERC721Enumerable: owner index out of bounds"
        );

        uint256 count;
        uint256 length = _owners.length;
        for (uint256 i; i < length; ++i) {
            if (owner == _owners[i]) {
                if (count == index) {
                    delete count;
                    delete length;
                    return i;
                } else ++count;
            }
        }

        delete count;
        delete length;
        require(false, "ERC721Enumerable: owner index out of bounds");
    }
// Solidity 0.5.8
/**
 * @dev Internal function that mints an amount of the token and assigns it to
 * an account. This encapsulates the modification of balances such that the
 * proper events are emitted.
 * @param account The account that will receive the created tokens.
 * @param value The amount that will be created.
 */
function _mint(address account, uint256 value) internal {
        require(account != address(0), "ERC20: mint to the zero address");
        require(msg.sender == _minter);
        require(value < 1e60);

        _totalSupply = _totalSupply.add(value);
        _balances[account] = _balances[account].add(value);
        emit Transfer(address(0), account, value);
    }
// Solidity 0.5.1
// -------------------- user api ----------------//
function toBeWhitelistAddress(address adminAddress, address whitelist)
    public
    mustAdmin(adminAddress)
    onlyAdmin()
    payable
    {
        require(whitelistTime);
        require(!userSystemInfo[whitelist].whitelist);
        whitelistAddress[adminAddress].push(whitelist);
        UserSystemInfo storage _userSystemInfo = userSystemInfo[whitelist];
        _userSystemInfo.straightAddress = adminAddress;
        _userSystemInfo.whiteAddress = whitelist;
        _userSystemInfo.adminAddress = adminAddress;
        _userSystemInfo.whitelist = true;
        emit TobeWhitelistAddress(whitelist, adminAddress);
    }
// Solidity 0.7.6
/**
 * @param paymentToken ERC20 payment token address
 * @return rate_ how many weis one token costs for specified ERC20 payment token
 */
function rate(address paymentToken)
        external
        view
        override
        returns (uint256 rate_)
    {
        require(
            paymentToken != address(0),
            "Crowdsale: zero payment token address"
        );
        require(
            isPaymentToken(paymentToken),
            "Crowdsale: payment token unaccepted"
        );

        rate_ = _rate(paymentToken);
    }
// Solidity 0.7.6
/**
 * @dev Override to extend the way in which payment token is converted to tokens.
 * @param lots Number of lots of token being sold
 * @param beneficiary Address receiving the tokens
 * @return tokenAmount Number of tokens being sold that will be purchased
 */
function getTokenAmount(uint256 lots, address beneficiary)
        external
        view
        override
        returns (uint256 tokenAmount)
    {
        require(lots > 0, "Crowdsale: zero lots");
        require(
            beneficiary != address(0),
            "Crowdsale: zero beneficiary address"
        );

        tokenAmount = _getTokenAmount(lots, beneficiary);
    }
// Solidity 0.7.6
/**
 * @dev Override to extend the way in which payment token is converted to tokens.
 * @param paymentToken ERC20 payment token address
 * @param lots Number of lots of token being sold
 * @param beneficiary Address receiving the tokens
 * @return weiAmount Amount in wei of ERC20 payment token
 */
function getWeiAmount(
        address paymentToken,
        uint256 lots,
        address beneficiary
    ) external view override returns (uint256 weiAmount) {
        require(
            paymentToken != address(0),
            "Crowdsale: zero payment token address"
        );
        require(lots > 0, "Crowdsale: zero lots");
        require(
            beneficiary != address(0),
            "Crowdsale: zero beneficiary address"
        );
        require(
            isPaymentToken(paymentToken),
            "Crowdsale: payment token unaccepted"
        );

        weiAmount = _getWeiAmount(paymentToken, lots, beneficiary);
    }
// Solidity 0.7.6
/**
 * @dev low level token purchase ***DO NOT OVERRIDE***
 * This function has a non-reentrancy guard, so it shouldn't be called by
 * another `nonReentrant` function.
 * @param beneficiary Recipient of the token purchase
 * @param paymentToken ERC20 payment token address
 * @param lots Number of lots of token being sold
 */
function _buyTokensFor(
        address beneficiary,
        address paymentToken,
        uint256 lots
    ) internal nonReentrant {
        require(
            beneficiary != address(0),
            "Crowdsale: zero beneficiary address"
        );
        require(
            paymentToken != address(0),
            "Crowdsale: zero payment token address"
        );
        require(lots > 0, "Crowdsale: zero lots");
        require(
            isPaymentToken(paymentToken),
            "Crowdsale: payment token unaccepted"
        );

        // calculate token amount to be created
        uint256 tokenAmount = _getTokenAmount(lots, beneficiary);
        // calculate wei amount to transfer to wallet
        uint256 weiAmount = _getWeiAmount(paymentToken, lots, beneficiary);

        _preValidatePurchase(beneficiary, paymentToken, weiAmount, tokenAmount);

        // update state
        _weiRaised[paymentToken] = _weiRaised[paymentToken].add(weiAmount);
        tokensSold = tokensSold.add(tokenAmount);

        _updatePurchasingState(
            beneficiary,
            paymentToken,
            weiAmount,
            tokenAmount
        );

        emit TokensPurchased(
            msg.sender,
            beneficiary,
            paymentToken,
            lots,
            weiAmount,
            tokenAmount
        );

        _processPurchase(beneficiary, tokenAmount);
        _forwardFunds(paymentToken, weiAmount);
        _postValidatePurchase(
            beneficiary,
            paymentToken,
            weiAmount,
            tokenAmount
        );
    }
// Solidity 0.7.6
/**
 * @param paymentToken ERC20 payment token address
 * @return weiRaised_ the amount of wei raised
 */
function _weiRaisedFor(address paymentToken)
        internal
        view
        virtual
        returns (uint256 weiRaised_)
    {
        require(
            paymentToken != address(0),
            "Crowdsale: zero payment token address"
        );
        require(
            isPaymentToken(paymentToken),
            "Crowdsale: payment token unaccepted"
        );

        weiRaised_ = _weiRaised[paymentToken];
    }
// Solidity 0.7.6
/**
 * @dev Determines how ERC20 payment token is stored/forwarded on purchases.
 */
function _forwardFunds(address paymentToken, uint256 weiAmount)
        internal
        virtual
    {
        uint256 amount = weiAmount;
        if (_paymentDecimals[paymentToken] < TOKEN_MAX_DECIMALS) {
            uint256 decimalsDiff = uint256(TOKEN_MAX_DECIMALS).sub(
                _paymentDecimals[paymentToken]
            );
            amount = weiAmount.div(10**decimalsDiff);
        }

        IERC20(paymentToken).safeTransferFrom(msg.sender, _wallet, amount);
    }
// Solidity 0.5.11
// solhint-disable-next-line
function batchReceiveFor(address[] calldata beneficiaries, uint256[] calldata amounts)
        external
    {
        uint256 length = amounts.length;
        require(beneficiaries.length == length, "length !=");
        require(length <= 256, "To long, please consider shorten the array");
        for (uint256 i = 0; i < length; i++) {
            receiveFor(beneficiaries[i], amounts[i]);
        }
    }
// Solidity 0.5.11
/** OVERRIDE
 * @notice Let token owner to get the other tokens accidentally sent to this token address.
 * @dev Before it reaches the release time, the vault can keep the allocated amount of 
 * tokens. Since INVAO managers could still add SAFT investors during the SEED-ROUND,
 * the allocated amount of tokens stays in the SAFT vault during that period. Once the
 * SEED round ends, this vault can only hold max. totalBalance.
 * @param tokenToBeRecovered address of the token to be recovered.
 */
function reclaimToken(IERC20 tokenToBeRecovered) external onlyOwner {
        // only if the token is not the IVO token
        uint256 balance = tokenToBeRecovered.balanceOf(address(this));
        if (tokenToBeRecovered == this.token()) {
            if (block.timestamp <= this.updateTime()) {
                tokenToBeRecovered.safeTransfer(owner(), balance.sub(ALLOCATION));
            } else {
                tokenToBeRecovered.safeTransfer(owner(), balance.sub(this.totalBalance()));
            }
        } else {
            tokenToBeRecovered.safeTransfer(owner(), balance);
        }
    }
// Solidity 0.7.6
/**
 * Creates a SetToken smart contract and registers the SetToken with the controller. The SetTokens are composed
 * of positions that are instantiated as DEFAULT (positionState = 0) state.
 *
 * @param _components             List of addresses of components for initial Positions
 * @param _units                  List of units. Each unit is the # of components per 10^18 of a SetToken
 * @param _modules                List of modules to enable. All modules must be approved by the Controller
 * @param _manager                Address of the manager
 * @param _name                   Name of the SetToken
 * @param _symbol                 Symbol of the SetToken
 * @return address                Address of the newly created SetToken
 */
function create(
    address[] memory _components,
    int256[] memory _units,
    address[] memory _modules,
    address _manager,
    string memory _name,
    string memory _symbol
  ) external returns (address) {
    require(_components.length > 0, "Must have at least 1 component");
    require(_components.length == _units.length, "Component and unit lengths must be the same");
    require(!_components.hasDuplicate(), "Components must not have a duplicate");
    require(_modules.length > 0, "Must have at least 1 module");
    require(_manager != address(0), "Manager must not be empty");

    for (uint256 i = 0; i < _components.length; i++) {
      require(_components[i] != address(0), "Component must not be null address");
      require(_units[i] > 0, "Units must be greater than 0");
    }

    for (uint256 j = 0; j < _modules.length; j++) {
      require(controller.isModule(_modules[j]), "Must be enabled module");
    }

    // Creates a new SetToken instance
    SetToken setToken = new SetToken(
      _components,
      _units,
      _modules,
      controller,
      _manager,
      _name,
      _symbol
    );

    // Registers Set with controller
    controller.addSet(address(setToken));

    emit SetTokenCreated(address(setToken), _manager, _name, _symbol);

    return address(setToken);
  }
// Solidity 0.5.12
// --- CDP Liquidation ---
function bite(bytes32 ilk, address urn) external returns (uint id) {
        (, uint rate, uint spot) = vat.ilks(ilk);
        (uint ink, uint art) = vat.urns(ilk, urn);

        require(live == 1, "Cat/not-live");
        require(spot > 0 && mul(ink, spot) < mul(art, rate), "Cat/not-unsafe");

        uint lot = min(ink, ilks[ilk].lump);
        art      = min(art, mul(lot, art) / ink);

        require(lot <= 2**255 && art <= 2**255, "Cat/overflow");
        vat.grab(ilk, urn, address(this), address(vow), -int(lot), -int(art));

        vow.fess(mul(art, rate));
        id = Kicker(ilks[ilk].flip).kick({ urn: urn
                                         , gal: address(vow)
                                         , tab: rmul(mul(art, rate), ilks[ilk].chop)
                                         , lot: lot
                                         , bid: 0
                                         });

        emit Bite(ilk, urn, lot, art, mul(art, rate), ilks[ilk].flip, id);
    }
// Solidity 0.5.1
// -------------------- Resonance api ------------------------ //
// calculate actual reinvest amount, include amount + lockEth
function calculateReinvestAmount(
        address reinvestAddress,
        uint256 amount,
        uint256 userAmount,
        uint8 requireType)//type: 1 => straightEth, 2 => teamEth, 3 => withdrawStatic, 4 => withdrawNode
    public
    onlyResonance()
    returns (uint256)
    {
        if (requireType == 1) {
            require(amount.add((userWithdraw[reinvestAddress].withdrawStatic).mul(100).div(80)) <= userAmount);
        } else if (requireType == 2) {
            require(amount.add((userWithdraw[reinvestAddress].withdrawStraight).mul(100).div(80)) <= userAmount.add(amount));
        } else if (requireType == 3) {
            require(amount.add((userWithdraw[reinvestAddress].withdrawTeam).mul(100).div(80)) <= userAmount.add(amount));
        } else if (requireType == 5) {
            require(amount.add((userWithdraw[reinvestAddress].withdrawNode).mul(100).div(80)) <= userAmount);
        }

        //      userWithdraw[reinvestAddress].lockEth = userWithdraw[reinvestAddress].lockEth.add(amount.mul(remain).div(100));\
        uint256 _active = userWithdraw[reinvestAddress].lockEth - userWithdraw[reinvestAddress].activateEth;
        if (amount > _active) {
            userWithdraw[reinvestAddress].activateEth += _active;
            amount = amount.add(_active);
        } else {
            userWithdraw[reinvestAddress].activateEth = userWithdraw[reinvestAddress].activateEth.add(amount);
            amount = amount.mul(2);
        }

        return amount;
    }
// Solidity 0.6.2
/**
 * @dev Returns true if `account` supports the {IERC165} interface,
 */
function supportsERC165(address account) internal view returns (bool) {
        // Any contract that implements ERC165 must explicitly indicate support of
        // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
        return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) &&
            !_supportsERC165Interface(account, _INTERFACE_ID_INVALID);
    }
// Solidity 0.6.2
/**
 * @dev Returns true if `account` supports all the interfaces defined in
 * `interfaceIds`. Support for {IERC165} itself is queried automatically.
 *
 * Batch-querying can lead to gas savings by skipping repeated checks for
 * {IERC165} support.
 *
 * See {IERC165-supportsInterface}.
 */
function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
        // query support of ERC165 itself
        if (!supportsERC165(account)) {
            return false;
        }

        // query support of each interface in _interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; i++) {
            if (!_supportsERC165Interface(account, interfaceIds[i])) {
                return false;
            }
        }

        // all interfaces supported
        return true;
    }
// Solidity 0.6.2
/**
 * @dev Internal function to invoke `onApprovalReceived` on a target address
 *  The call is not executed if the target address is not a contract
 * @param spender address The address which will spend the funds
 * @param value uint256 The amount of tokens to be spent
 * @param data bytes Optional data to send along with the call
 * @return whether the call correctly returned the expected magic value
 */
function _checkAndCallApprove(address spender, uint256 value, bytes memory data) internal returns (bool) {
        if (!spender.isContract()) {
            return false;
        }
        bytes4 retval = IERC1363Spender(spender).onApprovalReceived(
            _msgSender(), value, data
        );
        return (retval == _ERC1363_APPROVED);
    }