lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.25
/**
 * @notice rebalance changes the total supply by the given amount (either deducts or adds)
 * by scaling all balance amounts proportionally (also those exempt from fees)
 * @dev this uses the current total supply (which is the sum of all token balances excluding
 * the inventory, i.e., the balances of owner and superowner) to compute the new scale factor
 * @param deducts indication if we deduct or add token from total supply
 * @param tokensAmount the number of tokens to add/deduct
 */
function rebalance(bool deducts, uint tokensAmount) external onlyOwner {
        uint oldTotalSupply = totalSupply();
        uint oldScaleFactor = scaleFactor;

        require(
            tokensAmount <= oldTotalSupply.mul(MAX_REBALANCE_PERCENT).div(100),
            "tokensAmount is within limits"
        );

        // new scale factor and total supply
        uint newScaleFactor;
        if (deducts) {
            newScaleFactor = oldScaleFactor.mul(
                oldTotalSupply.sub(tokensAmount)).div(oldTotalSupply
            );
        } else {
            newScaleFactor = oldScaleFactor.mul(
                oldTotalSupply.add(tokensAmount)).div(oldTotalSupply
            );
        }
        // update scaleFactor
        scaleFactor = newScaleFactor;

        // update total supply
        uint newTotalSupply = oldTotalSupply.mul(scaleFactor).div(oldScaleFactor);
        totalSupply_ = newTotalSupply;

        emit Rebalance(
            deducts,
            tokensAmount,
            oldScaleFactor,
            newScaleFactor,
            oldTotalSupply,
            newTotalSupply
        );

        if (deducts) {
            require(newTotalSupply < oldTotalSupply, "totalSupply shrinks");
            // avoid overly large rounding errors
            assert(oldTotalSupply.sub(tokensAmount.mul(9).div(10)) >= newTotalSupply);
            assert(oldTotalSupply.sub(tokensAmount.mul(11).div(10)) <= newTotalSupply);
        } else {
           require(newTotalSupply > oldTotalSupply, "totalSupply grows");
           // avoid overly large rounding errors
           assert(oldTotalSupply.add(tokensAmount.mul(9).div(10)) <= newTotalSupply);
           assert(oldTotalSupply.add(tokensAmount.mul(11).div(10)) >= newTotalSupply);
        }
    }
// Solidity 0.4.25
/**
 * @notice enable change of superowner
 * @param _newSuperowner the address of the new owner
 */
function transferSuperownership(
        address _newSuperowner
    )
    external nonZeroAddress(_newSuperowner)
    {
        require(msg.sender == superowner, "only superowner");
        require(!usedOwners[_newSuperowner], "owner was not used before");
        usedOwners[_newSuperowner] = true;
        uint value = balanceOf(superowner);
        if (value > 0) {
            super._burn(superowner, value);
            emit TransferExtd(
                superowner,
                AccountClassification.Superowner,
                address(0),
                AccountClassification.Zero,
                value
            );
        }
        emit SuperownershipTransferred(superowner, _newSuperowner);
        superowner = _newSuperowner;
    }
// Solidity 0.4.25
/**
 * @notice Compute the regular amount of tokens of an account.
 * @dev Gets the balance of the specified address.
 * @param account The address to query the the balance of.
 * @return An uint256 representing the amount owned by the passed address.
 */
function balanceOf(address account) public view returns (uint) {
        uint amount = balances[account];
        uint oldScaleFactor = lastScalingFactor[account];
        if (oldScaleFactor == 0) {
            return 0;
        } else if (oldScaleFactor == scaleFactor) {
            return amount;
        } else {
            return amount.mul(scaleFactor).div(oldScaleFactor);
        }
    }
// Solidity 0.4.25
/**
 * @notice enable change of owner
 * @param _newOwner the address of the new owner
 */
function transferOwnership(address _newOwner) public onlyOwner {
        require(!usedOwners[_newOwner], "owner was not used before");
        usedOwners[_newOwner] = true;
        uint value = balanceOf(owner);
        if (value > 0) {
            super._burn(owner, value);
            emit TransferExtd(
                owner,
                AccountClassification.Owner,
                address(0),
                AccountClassification.Zero,
                value
            );
        }
        super.transferOwnership(_newOwner);
    }
// Solidity 0.4.25
/**
 * @dev Transfer token for a specified address
 * @param _to The address to transfer to.
 * @param _value The amount to be transferred, from which the transfer fee will be deducted
 * @return true in case of success
 */
function transfer(
        address _to,
        uint _value
    )
    public whenNotPaused limitGasPrice returns (bool)
    {
        require(!transferBlacklisted[msg.sender], "sender is not blacklisted");
        require(!transferBlacklisted[_to], "to address is not blacklisted");
        require(!blockOtherAccounts ||
            (getAccountClassification(msg.sender) != AccountClassification.Other &&
            getAccountClassification(_to) != AccountClassification.Other),
            "addresses are not blocked");

        emit TransferExtd(
            msg.sender,
            getAccountClassification(msg.sender),
            _to,
            getAccountClassification(_to),
            _value
        );

        updateBalanceAndScaling(msg.sender);

        if (_to == address(0)) {
            // burn tokens
            super.burn(_value);
            return true;
        }

        updateBalanceAndScaling(_to);

        require(super.transfer(_to, _value), "transfer succeeds");

        if (!avoidsFees[msg.sender] && !avoidsFees[_to]) {
            computeAndBurnFee(_to, _value);
        }

        return true;
    }
// Solidity 0.4.25
/**
 * @dev Transfer tokens from one address to another
 * @param _from address The address which you want to send tokens from
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the amount of tokens to be transferred, from which the transfer fee
 * will be deducted
 * @return true in case of success
 */
function transferFrom(
        address _from,
        address _to,
        uint _value
    )
    public whenNotPaused limitGasPrice returns (bool)
    {
        require(!transferBlacklisted[msg.sender], "sender is not blacklisted");
        require(!transferBlacklisted[_from], "from address is not blacklisted");
        require(!transferBlacklisted[_to], "to address is not blacklisted");
        require(!blockOtherAccounts ||
            (getAccountClassification(_from) != AccountClassification.Other &&
            getAccountClassification(_to) != AccountClassification.Other),
            "addresses are not blocked");

        emit TransferExtd(
            _from,
            getAccountClassification(_from),
            _to,
            getAccountClassification(_to),
            _value
        );

        updateBalanceAndScaling(_from);

        if (_to == address(0)) {
            // burn tokens
            super.transferFrom(_from, msg.sender, _value);
            super.burn(_value);
            return true;
        }

        updateBalanceAndScaling(_to);

        require(super.transferFrom(_from, _to, _value), "transfer succeeds");

        if (!avoidsFees[msg.sender] && !avoidsFees[_from] && !avoidsFees[_to]) {
            computeAndBurnFee(_to, _value);
        }

        return true;
    }
// Solidity 0.4.25
/**
 * @dev Function for TAPs to mint tokens
 * @param _to The address that will receive the minted tokens.
 * @param _amount The amount of tokens to mint.
 * @return true in case of success
 */
function mint(address _to, uint _amount) public returns(bool) {
        require(!transferBlacklisted[_to], "to address is not blacklisted");
        require(!blockOtherAccounts || getAccountClassification(_to) != AccountClassification.Other,
            "to address is not blocked");
        updateBalanceAndScaling(_to);
        emit TransferExtd(
            address(0),
            AccountClassification.Zero,
            _to,
            getAccountClassification(_to),
            _amount
        );
        return super.mint(_to, _amount);
    }
// Solidity 0.4.25
// get AccountClassification of an account
function getAccountClassification(
        address account
    )
    internal view returns(AccountClassification)
    {
        if (account == address(0)) {
            return AccountClassification.Zero;
        } else if (account == owner) {
            return AccountClassification.Owner;
        } else if (account == superowner) {
            return AccountClassification.Superowner;
        } else if (TAPwhiteListed[account]) {
            return AccountClassification.TAP;
        } else {
            return AccountClassification.Other;
        }
    }
// Solidity 0.4.25
// update balance and scaleFactor
function updateBalanceAndScaling(address account) internal {
        uint oldBalance = balances[account];
        uint newBalance = balanceOf(account);
        if (lastScalingFactor[account] != scaleFactor) {
            lastScalingFactor[account] = scaleFactor;
        }
        if (oldBalance != newBalance) {
            balances[account] = newBalance;
        }
    }
// Solidity 0.5.17
/**
 * Imported from: https://github.com/alianse777/solidity-standard-library/blob/master/Math.sol
 * @dev Compute square root of x
 * @return sqrt(x)
 */
function sqrt(uint256 x) internal pure returns (uint256) {
       uint256 n = x / 2;
       uint256 lstX = 0;
       while (n != lstX){
           lstX = n;
           n = (n + x/n) / 2; 
       }
       return uint256(n);
   }
// Solidity 0.4.24
/**
 * Function for the frontend to dynamically retrieve the price scaling of buy orders.
 */
function calculateTokensReceived(uint256 _ethereumToSpend) 
        public 
        view 
        returns(uint256)
    {
        uint256 _dividends = SafeMath.div(SafeMath.mul(_ethereumToSpend, dividendFee_), 100);
        uint256 _jackpotPay = SafeMath.div(SafeMath.mul(_ethereumToSpend, jackpotFee_), 100);
        uint256 _devPay = SafeMath.div(SafeMath.mul(_ethereumToSpend, greedFee_), 100);
        uint256 _taxedEthereum = SafeMath.sub(SafeMath.sub(SafeMath.sub(_ethereumToSpend, _dividends), _jackpotPay), _devPay);
        uint256 _amountOfTokens = ethereumToTokens_(_taxedEthereum);
        
        return _amountOfTokens;
    }
// Solidity 0.6.10
// functions (UI)
function createDsellerOffer(uint256 _maxAmountStock, uint256 _minAmountStock,
                             string memory _ticker, bytes32 _tickerBytes,
                             uint256 _fundsSeller, uint256 _dsellerPercentage,
                             uint8[17] memory _afkHours, uint256 _durationCap) public
  {
    trades.push(Trade(_ticker, 0, address(0x0), msg.sender, 0, 0, false, 0));
    tradesMeta.push(TradeMeta(0,0, _durationCap, 0));
    afkHours.push(_afkHours);
    trades_ticker.push(_tickerBytes);
    trades_maxAmountStock.push(_maxAmountStock);
    trades_minAmountStock.push(_minAmountStock);
    trades_dsellerPercentage.push(_dsellerPercentage);
    //
    trades_isActive.push(false);
    trades_isCancelled.push(false);
    //
    addressTrades[msg.sender].push(trades.length-1);
    //excess should be withdrawable
    ERC20Token DAI = ERC20Token(DAI_token);
    DAI.transferFrom(msg.sender, address(this), _fundsSeller);
    trades_fundsSeller.push(_fundsSeller);
    emit OfferCreated(_ticker, _maxAmountStock, _minAmountStock, _dsellerPercentage, msg.sender);
  }
// Solidity 0.4.24
//This is where all your gas goes, sorry
//Not sorry, you probably only paid 1 gwei
function sqrt(uint x) internal pure returns (uint y) {
        uint z = (x + 1) / 2;
        y = x;
        while (z < y) {
            y = z;
            z = (x / z + z) / 2;
        }
    }
// Solidity 0.5.10
/// @notice This method can be used by the controller to extract mistakenly
///  sent tokens to this contract.
/// @param _token The address of the token contract that you want to recover
///  set to 0 in case you want to extract ether.
function _claimStdTokens(address _token, address payable to) internal {
        if (_token == address(0x0)) {
            to.transfer(address(this).balance);
            return;
        }
        TransferableToken token = TransferableToken(_token);
        uint balance = token.balanceOf(address(this));

        (bool status,) = _token.call(abi.encodeWithSignature("transfer(address,uint256)", to, balance));
        require(status, "call failed");
        emit ClaimedTokens(_token, to, balance);
  }
// Solidity 0.8.1
// Mint special ones
function mintSpecial(address to, uint id) external {
    require(msg.sender == owner);
    require(  id == 11 || id == 14 || id == 30 || id == 2021 || id == 69 || id == 1907 || id == 1947 || id == 1966 || id == 1976 || id == 4283 || id == 8146 || id == 8219);  
    _mint(to, id);
    totalSupply++;
  }
// Solidity 0.8.1
//User/Customer Mint
function mintHotCactusClub(uint numberOfTokens) public payable {
    
        require(numberOfTokens > 0 && numberOfTokens <= maxHotCactusClubPurchase, "Can only mint 20 tokens at a time");
        require(totalSupply + numberOfTokens <= MAX_HCC, "Purchase would exceed max supply of Cactus");
        require(msg.value >= HotCactusClubPrice * numberOfTokens, "Ether value sent is not correct");
        
        for(uint i = 0; i < numberOfTokens; i++) {
            if (totalSupply < MAX_HCC) {
                //if to avoid the special numbers
                if (  mintIndex == 11 || mintIndex == 14 || mintIndex == 30 || mintIndex == 2021 || mintIndex == 69 || mintIndex == 1907 || mintIndex == 1947 || mintIndex == 1966 || mintIndex == 1976 || mintIndex == 4283 || mintIndex == 8146 || mintIndex == 8219) {
                    mintIndex++;
                }
                _mint(msg.sender, mintIndex);
                mintIndex++;
                totalSupply++;
            }
        }

    }
// Solidity 0.6.12
/**
 * @dev Multiplies two way, rounding half up to the nearest way
 * @param a Way
 * @param b Way
 * @return The result of a*b, in way
 **/
function wayMul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0 || b == 0) {
      return 0;
    }

    require(a <= (type(uint256).max - halfWAY) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);

    return (a * b + halfWAY) / WAY;
  }
// Solidity 0.8.1
//------------------------//
//Reserve some for marketing purpose
function reserveSome(address _to, uint _reserveAmount) external {
        require(msg.sender == owner);
        require(_reserveAmount > 0 && _reserveAmount <= HotCactusClubReserve, "Not enough reserve left for team");
        for (uint i = 0; i < _reserveAmount; i++) {
            
             //if to avoid the special numbers
                if (  mintIndex == 11 || mintIndex == 14 || mintIndex == 30 || mintIndex == 2021 || mintIndex == 69 || mintIndex == 1907 || mintIndex == 1947 || mintIndex == 1966 || mintIndex == 1976 || mintIndex == 4283 || mintIndex == 8146 || mintIndex == 8219) {
                    mintIndex++;
                }
                _mint(_to, mintIndex);
                mintIndex++;
                totalSupply++;
        }
        HotCactusClubReserve = HotCactusClubReserve - _reserveAmount;
    }
// Solidity 0.7.6
// Counts votes and sets the outcome allocation for each pool,
// can be called by anyone through DAO after an epoch ends.
// The new allocation value is the average of the vote outcome and the current value
function updateBasketBalance() public onlyDAO {
        uint128 _epochId = getCurrentEpoch();
        require(lastEpochUpdate < _epochId, "Epoch is not over");

        for (uint256 i = 0; i < allTokens.length; i++) {
            uint256 _currentValue = continuousVote[allTokens[i]]; // new vote outcome
            uint256 _previousValue = tokenAllocation[allTokens[i]]; // before this vote

            // the new current value is the average between the 2 values
            tokenAllocation[allTokens[i]] = (_currentValue.add(_previousValue))
                .div(2);

            // update the previous value
            tokenAllocationBefore[allTokens[i]] = _previousValue;

            emit UpdateAllocation(
                _epochId,
                allTokens[i],
                tokenAllocation[allTokens[i]]
            );
        }

        lastEpochUpdate = _epochId;
        lastEpochEnd = block.timestamp;
    }
// Solidity 0.7.6
// adds a token to the baskte balancer
// this mirrors the tokens in the pool both in allocation and order added
// every time a token is added to the pool it needs to be added here as well
function addToken(address token, uint256 allocation)
        external
        onlyDAO
        returns (uint256)
    {
        // add token and store allocation
        allTokens.push(token);
        tokenAllocationBefore[token] = allocation;
        tokenAllocation[token] = allocation;
        continuousVote[token] = allocation;

        //update total allocation
        fullAllocation = fullAllocation.add(allocation);

        emit NewToken(token, allocation);

        return allTokens.length;
    }
// Solidity 0.7.6
// removes a token from the baskte balancer
// every time a token is removed to the pool it needs to be removed here as well
function removeToken(address token) external onlyDAO returns (uint256) {
        require(tokenAllocation[token] != 0, "Token is not part of Basket");

        fullAllocation = fullAllocation.sub(continuousVote[token]);

        //remove token from array, moving all others 1 down if necessary
        uint256 index;
        for (uint256 i = 0; i < allTokens.length; i++) {
            if (allTokens[i] == token) {
                index = i;
                break;
            }
        }

        for (uint256 i = index; i < allTokens.length - 1; i++) {
            allTokens[i] = allTokens[i + 1];
        }
        allTokens.pop();

        // reset allocations
        tokenAllocationBefore[token] = 0;
        tokenAllocation[token] = 0;
        continuousVote[token] = 0;

        emit RemoveToken(token);

        return allTokens.length;
    }
// Solidity 0.4.24
/*
 * To create SYN Token and assign to transaction initiator
 */
function createTokens(address _beneficiary) internal {
       _preValidatePurchase(_beneficiary);
      //Calculate SYN Token to send
      uint256 totalNumberOfTokenTransferred = _getTokenAmount(msg.value);
      //check token to supply is not reaching the token hard cap
      assert (tokenSupplied.add(totalNumberOfTokenTransferred) <= TOKEN_CROWDFUNDING);
      
      //transfer tokens to investor
      transferTokens(_beneficiary, totalNumberOfTokenTransferred);

      //initializing structure for the address of the beneficiary
      Investor storage _investor = investors[_beneficiary];
      //Update investor's balance
      _investor.tokenSent = _investor.tokenSent.add(totalNumberOfTokenTransferred);
      _investor.weiReceived = _investor.weiReceived.add(msg.value);
      weiRaised = weiRaised.add(msg.value);
      tokenSupplied = tokenSupplied.add(totalNumberOfTokenTransferred);
      wallet.transfer(msg.value);
    }
// Solidity 0.5.10
/**
 * @dev PUBLIC FACING: Optionally update daily data for a smaller
 * range to reduce gas cost for a subsequent operation
 * @param beforeDay Only update days before this day number (optional; 0 for current day)
 */
function dailyDataUpdate(uint256 beforeDay)
        external
    {
        GlobalsCache memory g;
        GlobalsCache memory gSnapshot;
        _globalsLoad(g, gSnapshot);

        /* Skip pre-claim period */
        require(g._currentDay > CLAIM_PHASE_START_DAY, "NUG: Too early");

        if (beforeDay != 0) {
            require(beforeDay <= g._currentDay, "NUG: beforeDay cannot be in the future");

            _dailyDataUpdate(g, beforeDay, false);
        } else {
            /* Default to updating before current day */
            _dailyDataUpdate(g, g._currentDay, false);
        }

        _globalsSync(g, gSnapshot);
    }
// Solidity 0.5.10
/**
 * @dev PUBLIC FACING: External helper to return multiple values of daily data with
 * a single call.
 * @param beginDay First day of data range
 * @param endDay Last day (non-inclusive) of data range
 * @return array of day stake shares total
 * @return array of day payout total
 */
function dailyDataRange(uint256 beginDay, uint256 endDay)
        external
        view
        returns (uint256[] memory _dayStakeSharesTotal, uint256[] memory _dayPayoutTotal, uint256[] memory _dayDividends)
    {
        require(beginDay < endDay && endDay <= globals.dailyDataCount, "NUG: range invalid");

        _dayStakeSharesTotal = new uint256[](endDay - beginDay);
        _dayPayoutTotal = new uint256[](endDay - beginDay);
        _dayDividends = new uint256[](endDay - beginDay);

        uint256 src = beginDay;
        uint256 dst = 0;
        do {
            _dayStakeSharesTotal[dst] = uint256(dailyData[src].dayStakeSharesTotal);
            _dayPayoutTotal[dst++] = uint256(dailyData[src].dayPayoutTotal);
            _dayDividends[dst++] = dailyData[src].dayDividends;
        } while (++src < endDay);

        return (_dayStakeSharesTotal, _dayPayoutTotal, _dayDividends);
    }
// Solidity 0.5.10
/**
 * @dev Efficiently delete from an unordered array by moving the last element
 * to the "hole" and reducing the array length. Can change the order of the list
 * and invalidate previously held indexes.
 * @notice stakeListRef length and stakeIndex are already ensured valid in stakeEnd()
 * @param stakeListRef Reference to stakeLists[stakerAddr] array in storage
 * @param stakeIndex Index of the element to delete
 */
function _stakeRemove(StakeStore[] storage stakeListRef, uint256 stakeIndex)
        internal
    {
        uint256 lastIndex = stakeListRef.length - 1;

        /* Skip the copy if element to be removed is already the last element */
        if (stakeIndex != lastIndex) {
            /* Copy last element to the requested element's "hole" */
            stakeListRef[stakeIndex] = stakeListRef[lastIndex];
        }

        /*
            Reduce the array length now that the array is contiguous.
            Surprisingly, 'pop()' uses less gas than 'stakeListRef.length = lastIndex'
        */
        stakeListRef.pop();
    }
// Solidity 0.5.10
/**
 * @dev Estimate the stake payout for an incomplete day
 * @param g Cache of stored globals
 * @param stakeSharesParam Param from stake to calculate bonuses for
 * @param day Day to calculate bonuses for
 * @return Payout in Guns
 */
function _estimatePayoutRewardsDay(GlobalsCache memory g, uint256 stakeSharesParam, uint256 day)
        internal
        view
        returns (uint256 payout)
    {
        /* Prevent updating state for this estimation */
        GlobalsCache memory gTmp;
        _globalsCacheSnapshot(g, gTmp);

        DailyRoundState memory rs;
        rs._allocSupplyCached = totalSupply() + g._lockedGunsTotal;

        _dailyRoundCalc(gTmp, rs, day);

        /* Stake is no longer locked so it must be added to total as if it were */
        gTmp._stakeSharesTotal += stakeSharesParam;

        payout = rs._payoutTotal * stakeSharesParam / gTmp._stakeSharesTotal;

        return payout;
    }