lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.19
//*** Transfer From ***//
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
	    if(transfersEnabled){
	        // Check if the sender has enough
		    require(balanceOf[_from] >= _value);
		    // Check allowed
		    require(_value <= allowed[_from][msg.sender]);

		    // Subtract from the sender
		    balanceOf[_from] = (balanceOf[_from] - _value);
		    // Add the same to the recipient
		    balanceOf[_to] = (balanceOf[_to] + _value);

		    allowed[_from][msg.sender] = (allowed[_from][msg.sender] - _value);
		    Transfer(_from, _to, _value);
		    return true;
	    }
	    else{
	        return false;
	    }
	}
// Solidity 0.4.11
// @notice tokensale
// @param recipient The address of the recipient
// @return the transaction address and send the event as Transfer
function tokensale(address recipient) public payable {
        require(recipient != 0x0);

        uint256 weiAmount = msg.value;
        uint tokens = weiAmount.mul(getPrice());

        require(_leftSupply >= tokens);

        balances[owner] = balances[owner].sub(tokens);
        balances[recipient] = balances[recipient].add(tokens);

        _leftSupply = _leftSupply.sub(tokens);

        TokenPurchase(msg.sender, recipient, weiAmount, tokens);
    }
// Solidity 0.4.11
// Token distribution to founder, develoment team, partners, charity, and bounty
function sendBPESOToken(address to, uint256 value) public onlyOwner {
        require (
            to != 0x0 && value > 0 && _leftSupply >= value
        );

        balances[owner] = balances[owner].sub(value);
        balances[to] = balances[to].add(value);
        _leftSupply = _leftSupply.sub(value);
        Transfer(owner, to, value);
    }
// Solidity 0.4.11
// @notice send `value` token to `to` from `from`
// @param from The address of the sender
// @param to The address of the recipient
// @param value The amount of token to be transferred
// @return the transaction address and send the event as Transfer
function transferFrom(address from, address to, uint256 value) public {
        require (
            allowed[from][msg.sender] >= value && balances[from] >= value && value > 0
        );
        balances[from] = balances[from].sub(value);
        balances[to] = balances[to].add(value);
        allowed[from][msg.sender] = allowed[from][msg.sender].sub(value);
        Transfer(from, to, value);
    }
// Solidity 0.6.0
/**
 * @dev Joins and plays game.
 * @param _id Game id to join.
 * @param _referral Address for referral.
 * TESTED
 */
function joinAndPlayGame(uint256 _id, address _referral) external payable onlyNotCreator(_id) onlyAllowedToPlay {
    Game storage game = games[_id];
    require(game.creator != address(0), "No game with such id");
    require(game.winner == address(0), "Game has winner");
    require(game.bet == msg.value, "Wrong bet");
    require(_referral != msg.sender, "Wrong referral");

    addressBetTotal[msg.sender] = addressBetTotal[msg.sender].add(msg.value);

    game.opponent = msg.sender;
    if (_referral != address(0)) {
      game.opponentReferral = _referral;
    }

    //  play
    uint8 coinSide = uint8(uint256(keccak256(abi.encodePacked(now, msg.sender, gamesCreatedAmount, totalUsedInGame,devFeePending))) %2);
    game.winner = (coinSide == game.creatorGuessCoinSide) ? game.creator : game.opponent;

    gamesWithPendingPrizeWithdrawalForAddress[game.winner].push(_id);

    raffleParticipants.push(game.creator);
    raffleParticipants.push(game.opponent);
    lastPlayTimestamp[msg.sender] = now;
    gamesCompletedAmount = gamesCompletedAmount.add(1);
    totalUsedInGame = totalUsedInGame.add(msg.value);
    participatedGameIdxsForPlayer[msg.sender].push(_id);
    delete ongoingGameIdxForCreator[game.creator];

    if (isTopGame(_id)) {
      removeTopGame(game.id);
    }

    emit CF_GamePlayed(_id, game.creator, game.opponent, game.winner, game.bet);
  }
// Solidity 0.6.0
/**
 * @dev Withdraws prize for won game.
 * @param _maxLoop max loop.
 * TESTED
 */
function withdrawGamePrizes(uint256 _maxLoop) external {
    require(_maxLoop > 0, "_maxLoop == 0");
    
    uint256[] storage pendingGames = gamesWithPendingPrizeWithdrawalForAddress[msg.sender];
    require(pendingGames.length > 0, "no pending");
    require(_maxLoop <= pendingGames.length, "wrong _maxLoop");
    
    uint256 prizeTotal;
    for (uint256 i = 0; i < _maxLoop; i ++) {
      uint256 gameId = pendingGames[pendingGames.length.sub(1)];
      Game storage game = games[gameId];

      uint256 gamePrize = game.bet.mul(2);

      //  referral
      address winnerReferral = (msg.sender == game.creator) ? game.creatorReferral : game.opponentReferral;
      if (winnerReferral == address(0)) {
        winnerReferral = owner();
      }
      uint256 referralFee = gamePrize.mul(FEE_PERCENT).div(100);
      referralFeesPending[winnerReferral] = referralFeesPending[winnerReferral].add(referralFee);
      totalUsedReferralFees = totalUsedReferralFees.add(referralFee);
      
      prizeTotal += gamePrize;
      pendingGames.pop();
    }

    addressPrizeTotal[msg.sender] = addressPrizeTotal[msg.sender].add(prizeTotal);
    
    uint256 singleFee = prizeTotal.mul(FEE_PERCENT).div(100);
    partnerFeePending = partnerFeePending.add(singleFee);
    ongoinRafflePrize = ongoinRafflePrize.add(singleFee);
    devFeePending = devFeePending.add(singleFee.mul(2));

    prizeTotal = prizeTotal.sub(singleFee.mul(5));
    msg.sender.transfer(prizeTotal);

    //  partner transfer
    transferPartnerFee();

    emit CF_GamePrizesWithdrawn(msg.sender);
  }
// Solidity 0.6.0
/**
 * GameRaffle
 * TESTED
 */
function withdrawRafflePrizes() external override {
    require(rafflePrizePendingForAddress[msg.sender] > 0, "No raffle prize");

    uint256 prize = rafflePrizePendingForAddress[msg.sender];
    delete rafflePrizePendingForAddress[msg.sender];
    
    addressPrizeTotal[msg.sender] = addressPrizeTotal[msg.sender].add(prize);

    uint256 singleFee = prize.mul(FEE_PERCENT).div(100);
    partnerFeePending = partnerFeePending.add(singleFee);
    devFeePending = devFeePending.add(singleFee.mul(2));

    //  transfer prize
    prize = prize.sub(singleFee.mul(3));
    msg.sender.transfer(prize);

    //  partner transfer
    transferPartnerFee();

    emit CF_RafflePrizeWithdrawn(msg.sender, prize);
  }
// Solidity 0.6.0
/**
 * @dev Adds game idx to the beginning of topGames.
 * @param _id Game idx to be added.
 * TESTED
 */
function addTopGame(uint256 _id) external payable onlyCreator(_id) {
    require(msg.value == minBet, "Wrong fee");
    require(topGames[0] != _id, "Top in TopGames");
        
    uint256[5] memory topGamesTmp = [_id, 0, 0, 0, 0];
    bool isIdPresent;
    for (uint8 i = 0; i < 4; i ++) {
      if (topGames[i] == _id && !isIdPresent) {
        isIdPresent = true;
      }
      topGamesTmp[i+1] = (isIdPresent) ? topGames[i+1] : topGames[i];
    }
    topGames = topGamesTmp;
    devFeePending = devFeePending.add(msg.value);
    totalUsedInGame = totalUsedInGame.add(msg.value);

    emit CF_GameAddedToTop(_id, msg.sender);
  }
// Solidity 0.6.0
/**
 * @dev Removes game idx from topGames.
 * @param _id Game idx to be removed.
 * TESTED
 */
function removeTopGame(uint256 _id) private {
    uint256[5] memory tmpArr;
    bool found;
    
    for(uint256 i = 0; i < 5; i ++) {
      if(topGames[i] == _id) {
        found = true;
      } else {
        if (found) {
          tmpArr[i-1] = topGames[i];
        } else {
          tmpArr[i] = topGames[i];
        }
      }
    }

    require(found, "Not TopGame");
    topGames = tmpArr;
  }
// Solidity 0.8.9
/// @notice give the list of owners for the list of ids given.
/// @param ids The list if token ids to check.
/// @return addresses The list of addresses, corresponding to the list of ids.
function owners(uint256[] calldata ids) external view returns (address[] memory addresses) {
        addresses = new address[](ids.length);
        for (uint256 i = 0; i < ids.length; i++) {
            uint256 id = ids[i];
            addresses[i] = address(uint160(_owners[id]));
        }
    }
// Solidity 0.8.9
/// @notice mint one of bleep if not already minted. Can only be called by `minter`.
/// @param id bleep id which represent a pair of (note, instrument).
/// @param to address that will receive the Bleep.
function mint(uint16 id, address to) external {
        require(msg.sender == minter, "ONLY_MINTER_ALLOWED");
        require(id < 1024, "INVALID_BLEEP");

        require(to != address(0), "NOT_TO_ZEROADDRESS");
        require(to != address(this), "NOT_TO_THIS");
        address owner = _ownerOf(id);
        require(owner == address(0), "ALREADY_CREATED");
        _safeTransferFrom(address(0), to, id, "");
    }
// Solidity 0.8.9
/// @notice mint multiple bleeps if not already minted. Can only be called by `minter`.
/// @param ids list of bleep id which represent each a pair of (note, instrument).
/// @param to address that will receive the Bleeps.
function multiMint(uint16[] calldata ids, address to) external {
        require(msg.sender == minter, "ONLY_MINTER_ALLOWED");
        require(to != address(0), "NOT_TO_ZEROADDRESS");
        require(to != address(this), "NOT_TO_THIS");

        for (uint256 i = 0; i < ids.length; i++) {
            uint256 id = ids[i];
            require(id < 1024, "INVALID_BLEEP");
            address owner = _ownerOf(id);
            require(owner == address(0), "ALREADY_CREATED");
            _safeTransferFrom(address(0), to, id, "");
        }
    }
// Solidity 0.6.12
//management functions
//add lenders for the strategy to choose between
// only governance to stop strategist adding dodgy lender
function addLender(address a) public onlyGovernance {
        IGenericLender n = IGenericLender(a);
        require(n.strategy() == address(this), "Undocked Lender");

        for (uint256 i = 0; i < lenders.length; i++) {
            require(a != address(lenders[i]), "Already Added");
        }
        lenders.push(n);
    }
// Solidity 0.6.12
//force removes the lender even if it still has a balance
function _removeLender(address a, bool force) internal {
        for (uint256 i = 0; i < lenders.length; i++) {
            if (a == address(lenders[i])) {
                bool allWithdrawn = lenders[i].withdrawAll();

                if (!force) {
                    require(allWithdrawn, "WITHDRAW FAILED");
                }

                //put the last index here
                //remove last index
                if (i != lenders.length - 1) {
                    lenders[i] = lenders[lenders.length - 1];
                }

                //pop shortens array by 1 thereby deleting the last index
                lenders.pop();

                //if balance to spend we might as well put it into the best lender
                if (want.balanceOf(address(this)) > 0) {
                    adjustPosition(0);
                }
                return;
            }
        }
        require(false, "NOT LENDER");
    }
// Solidity 0.6.12
//Returns the status of all lenders attached the strategy
function lendStatuses() public view returns (lendStatus[] memory) {
        lendStatus[] memory statuses = new lendStatus[](lenders.length);
        for (uint256 i = 0; i < lenders.length; i++) {
            lendStatus memory s;
            s.name = lenders[i].lenderName();
            s.add = address(lenders[i]);
            s.assets = lenders[i].nav();
            s.rate = lenders[i].apr();
            statuses[i] = s;
        }

        return statuses;
    }
// Solidity 0.6.12
//the weighted apr of all lenders. sum(nav * apr)/totalNav
function estimatedAPR() public view returns (uint256) {
        uint256 bal = estimatedTotalAssets();
        if (bal == 0) {
            return 0;
        }

        uint256 weightedAPR = 0;

        for (uint256 i = 0; i < lenders.length; i++) {
            weightedAPR = weightedAPR.add(lenders[i].weightedApr());
        }

        return weightedAPR.div(bal);
    }
// Solidity 0.6.12
//Estimates the impact on APR if we add more money. It does not take into account adjusting position
function _estimateDebtLimitIncrease(uint256 change) internal view returns (uint256) {
        uint256 highestAPR = 0;
        uint256 aprChoice = 0;
        uint256 assets = 0;

        for (uint256 i = 0; i < lenders.length; i++) {
            uint256 apr = lenders[i].aprAfterDeposit(change);
            if (apr > highestAPR) {
                aprChoice = i;
                highestAPR = apr;
                assets = lenders[i].nav();
            }
        }

        uint256 weightedAPR = highestAPR.mul(assets.add(change));

        for (uint256 i = 0; i < lenders.length; i++) {
            if (i != aprChoice) {
                weightedAPR = weightedAPR.add(lenders[i].weightedApr());
            }
        }

        uint256 bal = estimatedTotalAssets().add(change);

        return weightedAPR.div(bal);
    }
// Solidity 0.6.12
//Estimates debt limit decrease. It is not accurate and should only be used for very broad decision making
function _estimateDebtLimitDecrease(uint256 change) internal view returns (uint256) {
        uint256 lowestApr = uint256(-1);
        uint256 aprChoice = 0;

        for (uint256 i = 0; i < lenders.length; i++) {
            uint256 apr = lenders[i].aprAfterDeposit(change);
            if (apr < lowestApr) {
                aprChoice = i;
                lowestApr = apr;
            }
        }

        uint256 weightedAPR = 0;

        for (uint256 i = 0; i < lenders.length; i++) {
            if (i != aprChoice) {
                weightedAPR = weightedAPR.add(lenders[i].weightedApr());
            } else {
                uint256 asset = lenders[i].nav();
                if (asset < change) {
                    //simplistic. not accurate
                    change = asset;
                }
                weightedAPR = weightedAPR.add(lowestApr.mul(change));
            }
        }
        uint256 bal = estimatedTotalAssets().add(change);
        return weightedAPR.div(bal);
    }
// Solidity 0.6.12
//gives estiomate of future APR with a change of debt limit. Useful for governance to decide debt limits
function estimatedFutureAPR(uint256 newDebtLimit) public view returns (uint256) {
        uint256 oldDebtLimit = vault.strategies(address(this)).totalDebt;
        uint256 change;
        if (oldDebtLimit < newDebtLimit) {
            change = newDebtLimit - oldDebtLimit;
            return _estimateDebtLimitIncrease(change);
        } else {
            change = oldDebtLimit - newDebtLimit;
            return _estimateDebtLimitDecrease(change);
        }
    }
// Solidity 0.6.12
/*
 * Key logic.
 *   The algorithm moves assets from lowest return to highest
 *   like a very slow idiots bubble sort
 *   we ignore debt outstanding for an easy life
 */
function adjustPosition(uint256 _debtOutstanding) internal override {
        _debtOutstanding; //ignored. we handle it in prepare return
        //emergency exit is dealt with at beginning of harvest
        if (emergencyExit) {
            return;
        }

        //we just keep all money in want if we dont have any lenders
        if (lenders.length == 0) {
            return;
        }

        (uint256 lowest, uint256 lowestApr, uint256 highest, uint256 potential) = estimateAdjustPosition();

        if (potential > lowestApr) {
            //apr should go down after deposit so wont be withdrawing from self
            lenders[lowest].withdrawAll();
        }

        uint256 bal = want.balanceOf(address(this));
        if (bal > 0) {
            want.safeTransfer(address(lenders[highest]), bal);
            lenders[highest].deposit();
        }
    }
// Solidity 0.6.12
//share must add up to 1000. 500 means 50% etc
function manualAllocation(lenderRatio[] memory _newPositions) public onlyAuthorized {
        uint256 share = 0;

        for (uint256 i = 0; i < lenders.length; i++) {
            lenders[i].withdrawAll();
        }

        uint256 assets = want.balanceOf(address(this));

        for (uint256 i = 0; i < _newPositions.length; i++) {
            bool found = false;

            //might be annoying and expensive to do this second loop but worth it for safety
            for (uint256 j = 0; j < lenders.length; j++) {
                if (address(lenders[j]) == _newPositions[i].lender) {
                    found = true;
                }
            }
            require(found, "NOT LENDER");

            share = share.add(_newPositions[i].share);
            uint256 toSend = assets.mul(_newPositions[i].share).div(1000);
            want.safeTransfer(_newPositions[i].lender, toSend);
            IGenericLender(_newPositions[i].lender).deposit();
        }

        require(share == 1000, "SHARE!=1000");
    }
// Solidity 0.6.12
//cycle through withdrawing from worst rate first
function _withdrawSome(uint256 _amount) internal returns (uint256 amountWithdrawn) {
        if (lenders.length == 0) {
            return 0;
        }

        //dont withdraw dust
        if (_amount < withdrawalThreshold) {
            return 0;
        }

        amountWithdrawn = 0;
        //most situations this will only run once. Only big withdrawals will be a gas guzzler
        uint256 j = 0;
        while (amountWithdrawn < _amount) {
            uint256 lowestApr = uint256(-1);
            uint256 lowest = 0;
            for (uint256 i = 0; i < lenders.length; i++) {
                if (lenders[i].hasAssets()) {
                    uint256 apr = lenders[i].apr();
                    if (apr < lowestApr) {
                        lowestApr = apr;
                        lowest = i;
                    }
                }
            }
            if (!lenders[lowest].hasAssets()) {
                return amountWithdrawn;
            }
            amountWithdrawn = amountWithdrawn.add(lenders[lowest].withdraw(_amount - amountWithdrawn));
            j++;
            //dont want infinite loop
            if (j >= 6) {
                return amountWithdrawn;
            }
        }
    }
// Solidity 0.6.12
/*
 * Liquidate as many assets as possible to `want`, irregardless of slippage,
 * up to `_amountNeeded`. Any excess should be re-invested here as well.
 */
function liquidatePosition(uint256 _amountNeeded) internal override returns (uint256 _amountFreed, uint256 _loss) {
        uint256 _balance = want.balanceOf(address(this));

        if (_balance >= _amountNeeded) {
            //if we don't set reserve here withdrawer will be sent our full balance
            return (_amountNeeded, 0);
        } else {
            uint256 received = _withdrawSome(_amountNeeded - _balance).add(_balance);
            if (received >= _amountNeeded) {
                return (_amountNeeded, 0);
            } else {
                return (received, 0);
            }
        }
    }
// Solidity 0.6.12
//Locks the contract for owner for the amount of time provided
function lock(uint256 time) public virtual onlyOwner {
        require(
            time <= (block.timestamp + 31536000),
            "Only lockable for up to 1 year"
        );

        _previousOwner = _owner;
        _owner = address(0);
        _lockTime = now + time;
        emit OwnershipTransferred(_owner, address(0));
    }
// Solidity 0.6.12
// Removes an address from the circulating supply
function removeAddressFromSupply(address removedAddress) external onlyOwner() {
        uint256 id = removedFromCirculation.length;
        require(removedAddress != address(uniswapV2Router), "Cannot add router (already accounted for)");
        require(removedAddress != 0x000000000000000000000000000000000000dEaD || removedAddress != 0x0000000000000000000000000000000000000000, "Cannot add burn address (already accounted for)");
        
        removedAddressIndex[removedAddress] = id;
        removedFromCirculation.push(removedAddress);
        emit AddressRemovedFromSupply(removedAddress);
    }
// Solidity 0.6.12
// Re-Adds an address to the circulating supply
function addAddressToSupply(address addedAddress) external onlyOwner() {
        uint256 id = removedAddressIndex[addedAddress];
        require(addedAddress != address(uniswapV2Router), "Cannot add router (already accounted for)");
        require(addedAddress != 0x000000000000000000000000000000000000dEaD || addedAddress != 0x0000000000000000000000000000000000000000, "Cannot add burn address (already accounted for)");

        delete removedFromCirculation[id];
        emit AddressAddedToSupply(addedAddress);
    }
// Solidity 0.8.0
/**
 * Mint Waffles
 */
function mintWaffles(uint256 numberOfTokens) public payable {
        require(saleIsActive, "Mint is not available right now");
        require(
            numberOfTokens <= MAX_PURCHASE,
            "Can only mint 20 tokens at a time"
        );
        require(
            totalSupply().add(numberOfTokens) <= MAX_TOKENS,
            "Purchase would exceed max supply of Waffles"
        );
        require(
            CURRENT_PRICE.mul(numberOfTokens) <= msg.value,
            "Value sent is not correct"
        );
        uint256 first_encounter = block.timestamp;
        uint256 tokenId;

        for (uint256 i = 1; i <= numberOfTokens; i++) {
            tokenId = totalSupply().add(1);
            if (tokenId <= MAX_TOKENS) {
                _safeMint(msg.sender, tokenId);
                _WafflesDetail[tokenId] = WafflesDetail(first_encounter);
                emit TokenMinted(tokenId, msg.sender, first_encounter);
            }
        }
    }
// Solidity 0.8.10
// once enabled, can never be turned off
function enableTrading() external onlyOwner {
        tradingActive = true;
        swapEnabled = true;
        lastLpBurnTime = block.timestamp;
        sellMarketingFee = 9;
        sellLiquidityFee = 1;
        sellDevFee = 5;
        sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee;
    }
// Solidity 0.4.21
//below function can be used when you want to send every recipeint with different number of tokens
function sendTokens(address[] dests, uint256[] values) whenDropIsActive onlyOwner external {
    uint256 i = 0;
    while (i < dests.length) {
        uint256 toSend = values[i] * 10**8;
        sendInternally(dests[i] , toSend, values[i]);
        i++;
    }
  }
// Solidity 0.4.21
// this function can be used when you want to send same number of tokens to all the recipients
function sendTokensSingleValue(address[] dests, uint256 value) whenDropIsActive onlyOwner external {
    uint256 i = 0;
    uint256 toSend = value * 10**8;
    while (i < dests.length) {
        sendInternally(dests[i] , toSend, value);
        i++;
    }
  }
// Solidity 0.6.12
/**
 * @dev calculates x^n, in ray. The code uses the ModExp precompile
 * @param x base
 * @param n exponent
 * @return z = x^n, in ray
 */
function rayPow(uint256 x, uint256 n) internal pure returns (uint256 z) {
    z = n % 2 != 0 ? x : RAY;

    for (n /= 2; n != 0; n /= 2) {
      x = rayMul(x, x);

      if (n % 2 != 0) {
        z = rayMul(z, x);
      }
    }
  }
// Solidity 0.6.12
/**
 Public function to release the accumulated fee income to the payees.
 @dev anyone can call this.
 */
function release() public override nonReentrant {
    uint256 income = a.core().availableIncome();
    require(income > 0, "income is 0");
    require(payees.length > 0, "Payees not configured yet");
    lastReleasedAt = now;

    // Mint USDX to all receivers
    for (uint256 i = 0; i < payees.length; i++) {
      address payee = payees[i];
      _release(income, payee);
    }
    emit FeeReleased(income, lastReleasedAt);
  }