lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.10
/**
 * @dev Creates a new voting proposal for the execution `_transaction` of `_targetContract`.
 * Only voter can create a new proposal.
 *
 * Emits a `ProposalStarted` event.
 *
 * Requirements:
 *
 * - `_targetContract` cannot be the zero address.
 * - `_transaction` length must not be less than 4 bytes.
 *
 * @notice Create a new voting proposal for the execution `_transaction` of `_targetContract`. You must be voter.
 * @param _targetContract Target contract address that can execute target `_transaction`
 * @param _transaction Target transaction to execute
 */
function newProposal( address _targetContract, bytes memory _transaction ) public onlyVoter {
        require(_targetContract != address(0), "Address must be non-zero");
        require(_transaction.length >= 4, "Tx must be 4+ bytes");
        // solhint-disable not-rely-on-time
        bytes32 _proposalHash = keccak256(abi.encodePacked(_targetContract, _transaction, now));
        require(proposals[_proposalHash].transaction.length == 0, "The poll has already been initiated");
        proposals[_proposalHash].targetContract = _targetContract;
        proposals[_proposalHash].transaction = _transaction;
        proposalsHashes.push(_proposalHash);
        proposalsCount = proposalsCount.add(1);
        emit ProposalStarted(_proposalHash);
    }
// Solidity 0.5.10
/**
 * @dev Adds sender's vote to the proposal and then follows the majority voting algoritm.
 *
 * Emits a `Vote` event.
 *
 * Requirements:
 *
 * - proposal with `_proposalHash` must not be finished.
 * - sender must not be already voted.
 *
 * @notice Vote "for" or "against" in proposal with `_proposalHash` hash.
 * @param _proposalHash Unique mapping key of proposal
 * @param _yes 1 is vote "for" and 0 is "against"
 */
function vote(bytes32 _proposalHash, bool _yes) public onlyVoter { // solhint-disable code-complexity
        require(!proposals[_proposalHash].finished, "Already finished");
        require(!proposals[_proposalHash].votedFor[msg.sender], "Already voted");
        require(!proposals[_proposalHash].votedAgainst[msg.sender], "Already voted");
        if (_yes) {
            proposals[_proposalHash].yesVotes = proposals[_proposalHash].yesVotes.add(1);
            proposals[_proposalHash].votedFor[msg.sender] = true;
        } else {
            proposals[_proposalHash].noVotes = proposals[_proposalHash].noVotes.add(1);
            proposals[_proposalHash].votedAgainst[msg.sender] = true;
        }
        emit Vote(
            _proposalHash,
            _yes,
            proposals[_proposalHash].yesVotes,
            proposals[_proposalHash].noVotes,
            votersCount
        );
        if (proposals[_proposalHash].yesVotes > votersCount.div(2)) {
            executeProposal(_proposalHash);
            finishProposal(_proposalHash);
        } else if (proposals[_proposalHash].noVotes >= (votersCount + 1).div(2)) {
            finishProposal(_proposalHash);
        }
    }
// Solidity 0.5.10
/**
 * @dev Removes `_address` from the voters list.
 * This method can be executed only via proposal of this Governance contract.
 *
 * Emits a `delVoter` event.
 *
 * Requirements:
 *
 * - `_address` must be in voters list.
 * - Num of voters must be more than one.
 *
 * @param _address Address of voter to delete
 */
function delVoter(address _address) public onlyMe {
        require(isVoter[_address], "Not in voters list");
        require(votersCount > 1, "Can not delete single voter");
        for (uint256 i = 0; i < voters.length; i++) {
            if (voters[i] == _address) {
                if (voters.length > 1) {
                    voters[i] = voters[voters.length - 1];
                }
                voters.length--; // Implicitly recovers gas from last element storage
                isVoter[_address] = false;
                votersCount = votersCount.sub(1);
                emit VoterDeleted(_address);
                break;
            }
        }
    }
// Solidity 0.6.12
// payout for claiming
function payouts(address payable _to, uint256 _amount, address token) external onlyOperator {
         require(_to != address(0),"_to is zero");
        if (token != ETHEREUM) {
            IERC20(token).safeTransfer(_to, _amount);
        } else {
            _to.transfer(_amount);
        }

        emit ePayouts(_to, _amount);
    }
// Solidity 0.6.12
// burn 1/2 for claiming 
function burnOuts(address[] calldata _burnUsers, uint256[] calldata _amounts) 
        external onlyOperator 
    {
        require(_burnUsers.length == _amounts.length, "not equal");

        for(uint256 i = 0; i<_burnUsers.length; i++) {
            require(_balances[_burnUsers[i]] >= _amounts[i], "insufficient");

            _balances[_burnUsers[i]] = _balances[_burnUsers[i]].sub(_amounts[i]);
            Nsure.burn(_amounts[i]);

            emit Burn(_burnUsers[i],_amounts[i]);
        }
    }
// Solidity 0.5.0
/*
 *       FEE: 
 *              1 = 0.001%
 *           1000 = 1%
 *         100000 = 100%
 */
function setFeeDistributions(address _token, address _feeWallet, string memory _name, uint256 _percent) public  onlyOwner {
        require(_token != address(0), "address not valid");
        require(_feeWallet != address(0), "address not valid");

        _Fee[] storage fees = feeDistributions[_token];
        // uint256 feesCount = fees.length;
        uint256 feesCount = getFeeDistributionsCount(_token);

        bool feeExiste = false;

        uint totalFeePercent = getTotalFeePercent (_token);
        totalFeePercent = totalFeePercent.add(_percent);
        require(totalFeePercent <= 100000, "total fee cannot exceed 100");

        for (uint i = 0; i < feesCount; i++){
            if (fees[i].wallet == _feeWallet){
                fees[i].name    = _name;
                fees[i].percent = _percent;
                fees[i].active  = true;

                feeExiste = true;
                break;
            }
        }

        // fee not found => add as new fee
        if (!feeExiste){
            _Fee memory fee;

            fee.id = (feesCount + 1);
            fee.name = _name;
            fee.wallet = _feeWallet;
            fee.percent = _percent;
            fee.active = true;

            fees.push(fee);
        }
    }
// Solidity 0.6.12
/**
 * @dev users can invoke this function to open a new pool.
 * @param _token the ERC20 token of the reward.
 * @param _reward the amount of reward.
 * @param _weight determines how the pool ranks in frontend.
 * @param _expiry the timestamp the pool expires. when a pool expires
 * the owner will have to pay to renew it or it won't accept new entries.
 **/
function openNewPool (IERC20 _token, address _currencyToken, uint112 _exchangeRate,
    uint _reward, uint _weight, uint64 _expiry, bytes32 name) external returns (uint pid){

    // require (_weight >= minPoolCost, "Need more YouBetToken");

    address poolOwner = msg.sender;

    _reward = _safeTokenTransfer(poolOwner, address(_token), _reward, address(0));

    if(_weight>0) {
      YouBetToken.safeTransferFrom(poolOwner, address(this), _weight);
      YouBetToken.safeTransfer(feeTo, _weight);
    }    
    
    pid = _openNewPool(poolOwner, _token, _currencyToken, _exchangeRate,
      _reward, _weight, _expiry);
    if(name != ''){
      _renamePool(pid, name);
    }
  }
// Solidity 0.6.12
/**
 * @dev users can invoke this function to purchase tokens.
 * @param _pid the pool id where the user is purchasing
 * @param _purchaseAmount amount in token to purchase
 **/
function buyTokenWithETH (uint _pid, uint _purchaseAmount, 
    address referrer) external payable {
    address _customer = msg.sender;
    require (pools[_pid].status == PoolStatus.OPEN, "lottery pool not open");
    require (now < pools[_pid].expiry, "lottery pool expired");

    IERC20 _pooltoken = IERC20(pools[_pid].token);
    address _poolCurrencyToken = pools[_pid].currencyToken;

    require (_poolCurrencyToken==WETH);    

    uint cost = _purchaseAmount.mul(pools[_pid].exchangeRate)/1e18;

    IWETH(WETH).deposit{value: cost}();

    if(referrer != address(0)){
      uint commission = cost.mul(perOrderCommissionRate)/1e5;
      IERC20(WETH).safeTransfer(referrer, commission);
      // will not undeflow
      cost -= commission;
      emit Commission(referrer, _customer, WETH, commission);
    }

    uint _balance = cost.add(pools[_pid].balance);
    uint _rewardBalance = _pooltoken.balanceOf(address(this));
    require(_balance <= uint112(-1) && _rewardBalance <= uint112(-1), 'OVERFLOW');
    pools[_pid].balance = uint112(_balance);

    _pooltoken.safeTransfer(_customer, _purchaseAmount);

    // will not overflow
    uint112 _newReward = uint112(uint(pools[_pid].reward).sub(_purchaseAmount));
    uint112 _rewardRealBalance = uint112(_rewardBalance);
    pools[_pid].reward = _newReward<_rewardRealBalance?_newReward:_rewardRealBalance;

    if(referrer != address(0)) {
      uint newReferrarSales = _purchaseAmount.add(poolReferrerSales[_pid][referrer]);
      require(newReferrarSales <= uint112(-1), 'OVERFLOW');
      poolReferrerSales[_pid][referrer] = newReferrarSales;
      if(newReferrarSales > pools[_pid].winnerCandidateSales){
        pools[_pid].winnerCandidateSales = uint112(newReferrarSales);
        pools[_pid].winnerCandidate = referrer;
      }

    }

    emit Purchase(_pid, _customer, _purchaseAmount, 
      address(_pooltoken), _poolCurrencyToken, cost);
  }
// Solidity 0.6.12
/**
 * @dev allows anyone to draw the winning ticket for an eligible pool.
 * @param _pid the pool id where user is drawing.
 **/
function closePool (uint _pid) external {
    address _poolOwner = pools[_pid].owner;

    require (pools[_pid].status==PoolStatus.OPEN, "Pool must be open");

    require (_poolOwner==msg.sender||msg.sender==owner(), "unauthorized");

    IERC20 _pooltoken = IERC20(pools[_pid].token);
    IERC20 _poolCurrencyToken = IERC20(pools[_pid].currencyToken);
    uint _poolReward = pools[_pid].reward;
    uint _poolExchangeRate = pools[_pid].exchangeRate;
    uint _poolBalance = pools[_pid].balance;

    uint _fees = _poolBalance/100;
    uint _contestReward = _poolBalance.mul(contestRewardRate)/1e5;
    uint _poolOwnerRevenue = _poolBalance - _fees - _contestReward;

    _poolCurrencyToken.safeTransfer(_poolOwner, _poolOwnerRevenue);
    _pooltoken.safeTransfer(_poolOwner, _poolReward);

    _poolCurrencyToken.safeTransfer(feeTo, _fees);

    processContestWinner(_pid, _contestReward);

  }
// Solidity 0.5.2
// function transferFrom(address _from, address _to, uint256 _id, uint256 _value) external {
//     _transferFrom(_from, _to, _id, _value);
// }
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external {
        _transferFrom(_from, _to, _id, _value);
        require(_checkERC1155AndCallSafeTransfer(msg.sender == address(_sandContract) ? _from : msg.sender, _from, _to, _id, _value, _data, false, false));
    }
// Solidity 0.5.2
// function batchTransferFrom(address _from, address _to, uint256[]calldata  _ids, uint256[] calldata _values) external {
//     _batchTransferFrom(_from, _to, _ids, _values);
// }
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external {
        _batchTransferFrom(_from, _to, _ids, _values);
        require(_checkERC1155AndCallSafeBatchTransfer(msg.sender == address(_sandContract) ? _from : msg.sender, _from, _to, _ids, _values, _data));
    }
// Solidity 0.5.2
// TODO enable ?
function extractERC721(address _sender, uint256 _id, string calldata _uri) external {
        require(msg.sender == _sender || msg.sender == address(_sandContract) || mSuperOperators[msg.sender], "require meta approval");
        require(erc1155_metadataURIHashes[_id] != 0, "Not an ERC1155 Token");
        require(erc1155_metadataURIHashes[_id] == keccak256(abi.encodePacked(_uri)), "URI hash does not match");
        _burnERC1155(_sender, _id, 1);
        address creator = creatorOf(_id);
        uint256 newTokenId = uint256(creator) * 2**(256-160) + 0 * 2**(256-160-8) + nextSubId;
        nextSubId++;
        _mint(_uri, 1, creator, _sender, newTokenId, "");
        emit Extraction(_id, newTokenId, _uri);
    }
// Solidity 0.4.19
/**
 * @dev transfer token for a specified address with froze status checking
 * @param _toMulti The addresses to transfer to.
 * @param _values The array of the amount to be transferred.
 */
function transferMultiAddress(address[] _toMulti, uint256[] _values) public whenNotPaused returns (bool) {
    require(!frozenAccount[msg.sender]);
    assert(_toMulti.length == _values.length);

    uint256 i = 0;
    while ( i < _toMulti.length) {
        require(_toMulti[i] != address(0));
        require(_values[i] <= balances[msg.sender]);

        // SafeMath.sub will throw if there is not enough balance.
        balances[msg.sender] = balances[msg.sender].sub(_values[i]);
        balances[_toMulti[i]] = balances[_toMulti[i]].add(_values[i]);
        Transfer(msg.sender, _toMulti[i], _values[i]);

        i = i.add(1);
    }

    return true;
  }
// Solidity 0.4.19
/**
 * @dev Transfer tokens from one address to another with checking the frozen status
 * @param _from address The address which you want to send tokens from
 * @param _toMulti address[] The addresses which you want to transfer to in boundle
 * @param _values uint256[] the array of amount of tokens to be transferred
 */
function transferMultiAddressFrom(address _from, address[] _toMulti, uint256[] _values) public whenNotPaused returns (bool) {
    require(!frozenAccount[_from]);
    assert(_toMulti.length == _values.length);
    
    uint256 i = 0;
    while ( i < _toMulti.length) {
        require(_toMulti[i] != address(0));
        require(_values[i] <= balances[_from]);
        require(_values[i] <= allowed[_from][msg.sender]);

        // SafeMath.sub will throw if there is not enough balance.
        balances[_from] = balances[_from].sub(_values[i]);
        balances[_toMulti[i]] = balances[_toMulti[i]].add(_values[i]);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_values[i]);
        Transfer(_from, _toMulti[i], _values[i]);

        i = i.add(1);
    }

    return true;
  }
// Solidity 0.7.4
// Tokens sold by crowdsale contract will be frozen ultil crowdsale ends
function txAllowed(address sender, uint256 amount) private returns (bool isAllowed) {
        if (timelock[sender] > block.timestamp) {
            return isBalanceFree(sender, amount);
        } else {
            if (frozenBalances[sender] > 0) frozenBalances[sender] = 0;
            return true;
        }
        
    }
// Solidity 0.6.11
/*
 Current code intentionally prevents governance re-initialization.
 This may be a problem in an upgrade situation, in a case that the upgrade-to implementation
 performs an initialization (for real) and within that calls initGovernance().
 
 Possible workarounds:
 1. Clearing the governance info altogether by changing the MAIN_GOVERNANCE_INFO_TAG.
 This will remove existing main governance information.
 2. Modify the require part in this function, so that it will exit quietly
 when trying to re-initialize (uncomment the lines below).
 */
function initGovernance()
        internal
    {
        string memory tag = getGovernanceTag();
        GovernanceInfoStruct storage gub = governanceInfo[tag];
        // TODO(Remo,01/09/2021): Consider un-commenting lines below.
        // if (gub.initialized) {
        //     return;
        // }
        require(!gub.initialized, "ALREADY_INITIALIZED");
        gub.initialized = true;  // to ensure addGovernor() won't fail.
        // Add the initial governer.
        addGovernor(msg.sender);
    }
// Solidity 0.4.26
/* Send tokens */
function transfer(address _to, uint256 _value) public returns(bool){
    if (_to == 0x0) return false;                               // Prevent transfer to 0x0 address. Use burn() instead
    if (_value <= 0) return false;
    if (balanceOf[msg.sender] < _value) revert();           // Check if the sender has enough
    if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
    balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value);              // Subtract from the sender
    balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value);                            // Add the same to the recipient
    emit Transfer(msg.sender, _to, _value);                      // Notify anyone listening that this transfer took place
	return true;
  }
// Solidity 0.4.26
/* Transfer tokens */
function transferFrom(address _from, address _to, uint256 _value) public returns(bool success) {
    if (_to == 0x0) revert();                                // Prevent transfer to 0x0 address. Use burn() instead
    if (_value <= 0) revert();
    if (balanceOf[_from] < _value) revert();                 // Check if the sender has enough
    if (balanceOf[_to] + _value < balanceOf[_to]) revert();  // Check for overflows
    if (_value > allowance[_from][msg.sender]) revert();     // Check allowance
    balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value);                         // Subtract from the sender
    balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value);                             // Add the same to the recipient
    allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
    emit Transfer(_from, _to, _value);
    return true;
  }
// Solidity 0.4.26
/* Destruction of the token */
function burn(uint256 _value) public returns(bool success) {
    if (balanceOf[msg.sender] < _value) revert();            // Check if the sender has enough
    if (_value <= 0) revert();
    balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value);           // Subtract from the sender
    totalSupply = SafeMath.safeSub(totalSupply, _value);                                // Updates totalSupply
    emit Burn(msg.sender, _value);
    return true;
  }
// Solidity 0.4.18
/// @dev Cancels the input order.
/// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient.
/// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt.
/// @param cancelTakerTokenAmount Desired amount of takerToken to cancel in order.
/// @return Amount of takerToken cancelled.
function cancelOrder(
        address[5] orderAddresses,
        uint[6] orderValues,
        uint cancelTakerTokenAmount)
        public
        onlyWhitelisted
        returns (uint)
    {
        Order memory order = Order({
            maker: orderAddresses[0],
            taker: orderAddresses[1],
            makerToken: orderAddresses[2],
            takerToken: orderAddresses[3],
            feeRecipient: orderAddresses[4],
            makerTokenAmount: orderValues[0],
            takerTokenAmount: orderValues[1],
            makerFee: orderValues[2],
            takerFee: orderValues[3],
            expirationTimestampInSec: orderValues[4],
            orderHash: getOrderHash(orderAddresses, orderValues)
        });

        require(order.maker == msg.sender);
        require(order.makerTokenAmount > 0 && order.takerTokenAmount > 0 && cancelTakerTokenAmount > 0);

        if (block.timestamp >= order.expirationTimestampInSec) {
            LogError(uint8(Errors.ORDER_EXPIRED), order.orderHash);
            return 0;
        }

        uint remainingTakerTokenAmount = safeSub(order.takerTokenAmount, getUnavailableTakerTokenAmount(order.orderHash));
        uint cancelledTakerTokenAmount = min256(cancelTakerTokenAmount, remainingTakerTokenAmount);
        if (cancelledTakerTokenAmount == 0) {
            LogError(uint8(Errors.ORDER_FULLY_FILLED_OR_CANCELLED), order.orderHash);
            return 0;
        }

        cancelled[order.orderHash] = safeAdd(cancelled[order.orderHash], cancelledTakerTokenAmount);

        LogCancel(
            order.maker,
            order.feeRecipient,
            order.makerToken,
            order.takerToken,
            getPartialAmount(cancelledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount),
            cancelledTakerTokenAmount,
            keccak256(order.makerToken, order.takerToken),
            order.orderHash
        );
        return cancelledTakerTokenAmount;
    }
// Solidity 0.4.18
/// @dev Synchronously executes multiple fill orders in a single transaction.
/// @param orderAddresses Array of address arrays containing individual order addresses.
/// @param orderValues Array of uint arrays containing individual order values.
/// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders.
/// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting.
/// @param v Array ECDSA signature v parameters.
/// @param r Array of ECDSA signature r parameters.
/// @param s Array of ECDSA signature s parameters.
function batchFillOrders(
        address[5][] orderAddresses,
        uint[6][] orderValues,
        uint[] fillTakerTokenAmounts,
        bool shouldThrowOnInsufficientBalanceOrAllowance,
        uint8[] v,
        bytes32[] r,
        bytes32[] s)
        public
    {
        for (uint i = 0; i < orderAddresses.length; i++) {
            fillOrder(
                orderAddresses[i],
                orderValues[i],
                fillTakerTokenAmounts[i],
                shouldThrowOnInsufficientBalanceOrAllowance,
                v[i],
                r[i],
                s[i]
            );
        }
    }
// Solidity 0.4.18
/// @dev Synchronously executes multiple fillOrKill orders in a single transaction.
/// @param orderAddresses Array of address arrays containing individual order addresses.
/// @param orderValues Array of uint arrays containing individual order values.
/// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders.
/// @param v Array ECDSA signature v parameters.
/// @param r Array of ECDSA signature r parameters.
/// @param s Array of ECDSA signature s parameters.
function batchFillOrKillOrders(
        address[5][] orderAddresses,
        uint[6][] orderValues,
        uint[] fillTakerTokenAmounts,
        uint8[] v,
        bytes32[] r,
        bytes32[] s)
        public
    {
        for (uint i = 0; i < orderAddresses.length; i++) {
            fillOrKillOrder(
                orderAddresses[i],
                orderValues[i],
                fillTakerTokenAmounts[i],
                v[i],
                r[i],
                s[i]
            );
        }
    }
// Solidity 0.4.18
/// @dev Calculates Keccak-256 hash of order with specified parameters.
/// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient.
/// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt.
/// @return Keccak-256 hash of order.
function getOrderHash(address[5] orderAddresses, uint[6] orderValues)
        public
        constant
        returns (bytes32)
    {
        return keccak256(
            address(this),
            orderAddresses[0], // maker
            orderAddresses[1], // taker
            orderAddresses[2], // makerToken
            orderAddresses[3], // takerToken
            orderAddresses[4], // feeRecipient
            orderValues[0],    // makerTokenAmount
            orderValues[1],    // takerTokenAmount
            orderValues[2],    // makerFee
            orderValues[3],    // takerFee
            orderValues[4],    // expirationTimestampInSec
            orderValues[5]     // salt
        );
    }