lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.7.5
/// @dev churn transfers contract ownership and set variables of the next TSS validator set.
/// @param _newOwner The address of new Owner.
/// @param _rewardAddressAndAmounts The reward addresses and amounts.
/// @param _isRemoved The flags to remove node.
/// @param _churnedInCount The number of next party size of TSS group.
/// @param _tssThreshold The number of next threshold.
/// @param _nodeRewardsRatio The number of rewards ratio for node owners
/// @param _withdrawalFeeBPS The amount of wthdrawal fees.
function churn(
        address _newOwner,
        bytes32[] memory _rewardAddressAndAmounts,
        bool[] memory _isRemoved,
        uint8 _churnedInCount,
        uint8 _tssThreshold,
        uint8 _nodeRewardsRatio,
        uint8 _withdrawalFeeBPS
    ) external override onlyOwner returns (bool) {
        require(
            _tssThreshold >= tssThreshold && _tssThreshold <= 2**8 - 1,
            "_tssThreshold should be >= tssThreshold"
        );
        require(
            _churnedInCount >= _tssThreshold + uint8(1),
            "n should be >= t+1"
        );
        require(
            _nodeRewardsRatio >= 0 && _nodeRewardsRatio <= 100,
            "_nodeRewardsRatio is not valid"
        );
        require(
            _withdrawalFeeBPS >= 0 && _withdrawalFeeBPS <= 100,
            "_withdrawalFeeBPS is invalid"
        );
        require(
            _rewardAddressAndAmounts.length == _isRemoved.length,
            "_rewardAddressAndAmounts and _isRemoved length is not match"
        );
        transferOwnership(_newOwner);
        // Update active node list
        for (uint256 i = 0; i < _rewardAddressAndAmounts.length; i++) {
            (address newNode, ) = _splitToValues(_rewardAddressAndAmounts[i]);
            _addNode(newNode, _rewardAddressAndAmounts[i], _isRemoved[i]);
        }
        bytes32[] memory nodeList = getActiveNodes();
        if (nodeList.length > 100) {
            revert("Stored node size should be <= 100");
        }
        churnedInCount = _churnedInCount;
        tssThreshold = _tssThreshold;
        nodeRewardsRatio = _nodeRewardsRatio;
        withdrawalFeeBPS = _withdrawalFeeBPS;
        return true;
    }
// Solidity 0.8.6
/**
 * @notice read the warning flag status of a contract address.
 * @param subjects An array of addresses being checked for a flag.
 * @return An array of bools where a true value for any flag indicates that
 * a flag was raised and a false value indicates that no flag was raised.
 */
function getFlags(
    address[] calldata subjects
  )
    external
    view
    override
    checkAccess()
    returns (bool[] memory)
  {
    bool[] memory responses = new bool[](subjects.length);
    for (uint256 i = 0; i < subjects.length; i++) {
      responses[i] = flags[subjects[i]];
    }
    return responses;
  }
// Solidity 0.8.6
/**
 * @notice allows owner to disable the warning flags for multiple addresses.
 * Access is controlled by loweringAccessController, except for owner
 * who always has access.
 * @param subjects List of the contract addresses whose flag is being lowered
 */
function lowerFlags(
    address[] calldata subjects
  )
    external
    override
  {
    require(_allowedToLowerFlags(), "Not allowed to lower flags");

    for (uint256 i = 0; i < subjects.length; i++) {
      address subject = subjects[i];

      _tryToLowerFlag(subject);
    }
  }
// Solidity 0.7.5
/// @dev getCurrentPriceLP returns the current exchange rate of LP token.
function getCurrentPriceLP()
        public
        override
        view
        returns (uint256 nowPrice)
    {
        (uint256 reserveA, uint256 reserveB) = getFloatReserve(
            address(0),
            WBTC_ADDR
        );
        uint256 totalLPs = IBurnableToken(lpToken).totalSupply();
        // decimals of totalReserved == 8, lpDecimals == 8, decimals of rate == 8
        nowPrice = totalLPs == 0
            ? initialExchangeRate
            : (reserveA.add(reserveB)).mul(lpDecimals).div(
                totalLPs.add(lockedLPTokensForNode)
            );
        return nowPrice;
    }
// Solidity 0.5.2
/**
 * @dev Owner can withdraw the remaining ETH balance as long as amount of minted tokens is
 * less than 1 token (due to possible rounding leftovers)
 *
 */
function sweepVault(address payable _operator) public onlyPrimary {
        //1 initially minted + 1 possible rounding corrections
        require(communityToken.totalSupply() < 2 ether, 'Sweep available only if no minted tokens left');
        require(address(this).balance > 0, 'Vault is empty');
        _operator.transfer(address(this).balance);
        emit LogEthSent(address(this).balance, _operator);
    }
// Solidity 0.6.6
// A function used in case of strategy failure, possibly due to bug in the platform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
        depositsOpen = false;
        if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
            currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy 
        }
        currentStrategy = StabilizeStrategy(address(0));
        _timelockType = 0; // Prevent governance from changing to new strategy without timelock
    }
// Solidity 0.6.6
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
        _timelockStart = now;
        _timelockType = 2;
        _timelock_address = _address;
        _pendingStrategy = _address;
        if(totalSupply() == 0){
            // Can change strategy with one call in this case
            finishChangeStrategy();
        }
    }
// Solidity 0.7.5
/// @dev getDepositFeeRate returns deposit fees rate
/// @param _token The address of target token.
/// @param _amountOfFloat The amount of float.
function getDepositFeeRate(address _token, uint256 _amountOfFloat)
        public
        override
        view
        returns (uint256 depositFeeRate)
    {
        uint8 isFlip = _checkFlips(_token, _amountOfFloat);
        if (isFlip == 1) {
            depositFeeRate = _token == WBTC_ADDR ? depositFeesBPS : 0;
        } else if (isFlip == 2) {
            depositFeeRate = _token == address(0) ? depositFeesBPS : 0;
        }
    }
// Solidity 0.7.5
/// @dev getActiveNodes returns active nodes list (stakes and amount)
function getActiveNodes() public override view returns (bytes32[] memory) {
        uint256 nodeCount = 0;
        uint256 count = 0;
        // Seek all nodes
        for (uint256 i = 0; i < nodeAddrs.length; i++) {
            if (nodes[nodeAddrs[i]] != 0x0) {
                nodeCount = nodeCount.add(1);
            }
        }
        bytes32[] memory _nodes = new bytes32[](nodeCount);
        for (uint256 i = 0; i < nodeAddrs.length; i++) {
            if (nodes[nodeAddrs[i]] != 0x0) {
                _nodes[count] = nodes[nodeAddrs[i]];
                count = count.add(1);
            }
        }
        return _nodes;
    }
// Solidity 0.8.4
/**
 * @dev Searches a sorted `array` and returns the first index that contains
 * a value greater or equal to `element`. If no such index exists (i.e. all
 * values in the array are strictly less than `element`), the array length is
 * returned. Time complexity O(log n).
 *
 * `array` is expected to be sorted in ascending order, and to contain no
 * repeated elements.
 */
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        if (array.length == 0) {
            return 0;
        }

        uint256 low = 0;
        uint256 high = array.length;

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds down (it does integer division with truncation).
            if (array[mid] > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && array[low - 1] == element) {
            return low - 1;
        } else {
            return low;
        }
    }
// Solidity 0.5.16
// DEPERECATED:
function getAllRatesForDEX(
        IERC20 fromToken,
        IERC20 toToken,
        uint256 amount,
        uint256 parts,
        uint256 disableFlags
    ) public view returns(uint256[] memory results) {
        results = new uint256[](parts);
        for (uint i = 0; i < parts; i++) {
            (results[i],) = getExpectedReturn(
                fromToken,
                toToken,
                amount.mul(i + 1).div(parts),
                1,
                disableFlags
            );
        }
    }
// Solidity 0.8.11
/**
 * @dev The main function of the contract. Should be called in the constructor function of the coin
 *
 * @param _guidelineSummary A summary of the guideline. The summary can be used as a title for
 * the guideline when it is retrieved and displayed on a front-end.
 *
 * @param _guideline The guideline itself.
 */
function setGuideline(string memory _guidelineSummary, string memory _guideline) internal {

        /**
        * @dev creating a new struct instance of the type Guideline and storing it in memory.
        */
        Guideline memory guideline = Guideline(_guidelineSummary, _guideline);

        /**
        * @dev pushing the struct created above in the guideline_struct array.
        */
        guidelines.push(guideline);


        /**
        * @dev Emit the GuidelineCreated event.
        */
        emit GuidelineCreated(_guidelineSummary, _guideline);

        /**
        * @dev Increment numberOfGuidelines by one.
        */
        numberOfGuidelines++;
    }
// Solidity 0.8.11
/**
 * @dev function that converts an address into a string
 * NOTE: this function returns all lowercase letters. Ethereum addresses are not case sensitive.
 * However, because of this the address won't pass the optional checksum validation.
 */
function addressToString(address _address) internal pure returns(string memory) {
        bytes32 _bytes = bytes32(uint256(uint160(_address)));
        bytes memory HEX = "0123456789abcdef";
        bytes memory _string = new bytes(42);
        _string[0] = '0';
        _string[1] = 'x';
        for(uint i = 0; i < 20; i++) {
            _string[2+i*2] = HEX[uint8(_bytes[i + 12] >> 4)];
            _string[3+i*2] = HEX[uint8(_bytes[i + 12] & 0x0f)];
        }
        return string(_string);
    }
// Solidity 0.7.5
/// @dev _rewardsCollection collects tx rewards.
/// @param _feesToken The token address for collection fees.
/// @param _rewardsAmount The amount of rewards.
function _rewardsCollection(address _feesToken, uint256 _rewardsAmount)
        internal
    {
        if (_rewardsAmount == 0) return;
        if (_feesToken == lpToken) {
            feesLPTokensForNode = feesLPTokensForNode.add(_rewardsAmount);
            emit RewardsCollection(_feesToken, _rewardsAmount, 0, 0);
            return;
        }
        // Get current LP token price.
        uint256 nowPrice = getCurrentPriceLP();
        // Add all fees into pool
        floatAmountOf[_feesToken] = floatAmountOf[_feesToken].add(
            _rewardsAmount
        );
        uint256 amountForNodes = _rewardsAmount.mul(nodeRewardsRatio).div(100);
        // Alloc LP tokens for nodes as fees
        uint256 amountLPTokensForNode = amountForNodes.mul(priceDecimals).div(
            nowPrice
        );
        // Add minted LP tokens for Nodes
        lockedLPTokensForNode = lockedLPTokensForNode.add(
            amountLPTokensForNode
        );
        emit RewardsCollection(
            _feesToken,
            _rewardsAmount,
            amountLPTokensForNode,
            nowPrice
        );
    }
// Solidity 0.8.4
// Update balance and/or total supply snapshots before the values are modified. This is implemented
// in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        if (from == address(0)) {
            // mint
            _updateAccountSnapshot(to);
            _updateTotalSupplySnapshot();
        } else if (to == address(0)) {
            // burn
            _updateAccountSnapshot(from);
            _updateTotalSupplySnapshot();
        } else {
            // transfer
            _updateAccountSnapshot(from);
            _updateAccountSnapshot(to);
        }
    }
// Solidity 0.4.16
/* function to send tokens to a given address */
function transfer(address _to, uint256 _value) returns (bool success){
        require (now < startTime); //check if the crowdsale is already over
        require(msg.sender == owner && now < startTime + 1 years && safeSub(balanceOf[msg.sender],_value) < 1000000000); //prevent the owner of spending his share of tokens within the first year 
        balanceOf[msg.sender] = safeSub(balanceOf[msg.sender],_value);                     // Subtract from the sender
        balanceOf[_to] = safeAdd(balanceOf[_to],_value);                            // Add the same to the recipient
        Transfer(msg.sender, _to, _value);                   // Notify anyone listening that this transfer took place
        return true;
    }
// Solidity 0.4.16
/* Transferfrom function*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
        require (now < startTime && _from!=owner); //check if the crowdsale is already over 
        require(_from == owner && now < startTime + 1 years && safeSub(balanceOf[_from],_value) < 1000000000);
        var _allowance = allowance[_from][msg.sender];
        balanceOf[_from] = safeSub(balanceOf[_from],_value); // Subtract from the sender
        balanceOf[_to] = safeAdd(balanceOf[_to],_value);     // Add the same to the recipient
        allowance[_from][msg.sender] = safeSub(_allowance,_value);
        Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.4.16
/* To be called when ICO is closed, burns the remaining tokens but the D-WALLET FREEZE VAULT (1000000000) and the ones reserved
 *  for the bounty program (24000000).
 *  anybody may burn the tokens after ICO ended, but only once (in case the owner holds more tokens in the future).
 *  this ensures that the owner will not posses a majority of the tokens. */
function burn(){
    	//if tokens have not been burned already and the ICO ended
    	if(!burned && now>endTime){
    		uint difference = safeSub(balanceOf[owner], 1024000000);//checked for overflow above
    		balanceOf[owner] = 1024000000;
    		totalSupply = safeSub(totalSupply, difference);
    		burned = true;
    		Burned(difference);
    	}
    }
// Solidity 0.4.25
// Getting egg price by id and quality
function getEggPrice(uint64 _petId, uint16 _quality) pure public returns(uint256 price) {
        		
        uint64[6] memory egg_prices = [0, 150 finney, 600 finney, 3 ether, 12 ether, 600 finney];
        
		uint8 egg = 2;
	
		if(_quality > 55000)
		    egg = 1;
			
		if(_quality > 26000 && _quality < 26500)
			egg = 3;
			
		if(_quality > 39100 && _quality < 39550)
			egg = 3;
			
		if(_quality > 31000 && _quality < 31250)
			egg = 4;
			
		if(_quality > 34500 && _quality < 35500)
			egg = 5;
			
		price = egg_prices[egg];
		
		uint8 discount = 10;
		
		if(_petId<= 600)
			discount = 20;
		if(_petId<= 400)
			discount = 30;
		if(_petId<= 200)
			discount = 50;
		if(_petId<= 120)
			discount = 80;
		
		price = price - (price*discount / 100);
    }
// Solidity 0.4.25
// Save rewards for all referral levels
function applyReward(uint64 _petId, uint16 _quality) internal {
        
        uint8[6] memory rewardByLevel = [0,250,120,60,30,15];
        
        uint256 eggPrice = getEggPrice(_petId, _quality);
        
        uint64 _currentPetId = _petId;
        
        // make rewards for 5 levels
        for(uint8 level=1; level<=5; level++) {
            uint64 _parentId = petsInfo[_currentPetId].parentId;
            // if no parent referral - break
            if(_parentId == 0)
                break;
            
            // increase pet balance
            petsInfo[_parentId].amount+= eggPrice * rewardByLevel[level] / 1000;
            
            // get parent id from parent id to move to the next level
            _currentPetId = _parentId;
        }
        
    }
// Solidity 0.7.5
/// @dev _addNode updates a staker's info.
/// @param _addr The address of staker.
/// @param _data The data of staker.
/// @param _remove The flag to remove node.
function _addNode(
        address _addr,
        bytes32 _data,
        bool _remove
    ) internal returns (bool) {
        if (_remove) {
            delete nodes[_addr];
            return true;
        }
        if (!isInList[_addr]) {
            nodeAddrs.push(_addr);
            isInList[_addr] = true;
        }
        if (nodes[_addr] == 0x0) {
            nodes[_addr] = _data;
        }
        return true;
    }
// Solidity 0.4.25
// Make synchronization, available for any sender
function sync() external whenNotPaused {
        
        // Checking synchronization status
        require(petSyncEnabled);
        
        // Get supply of pets from parent contract
        uint64 petSupply = uint64(parentInterface.totalSupply());
        require(petSupply > lastPetId);

        // Synchronize pets        
        for(uint8 i=0; i < syncLimit; i++)
        {
            lastPetId++;
            
            if(lastPetId > petSupply)
            {
                lastPetId = petSupply;
                break;
            }
            
            addPet(lastPetId);
        }
    }
// Solidity 0.4.25
// Function of manual add pet    
function addPet(uint64 _id) internal {
        (uint64 birthTime, uint256 genes, uint64 breedTimeout, uint16 quality, address owner) = parentInterface.getPet(_id);
        
        uint16 gradeQuality = quality;

        // For first pets - bonus quality in grade calculating
        if(_id < 244)
			gradeQuality = quality - 13777;
			
		// Calculating seats in circle
        uint8 petGrade = getGradeByQuailty(gradeQuality);
        uint8 petSeats = seatsByGrade(petGrade);
        
        // Adding pet into circle
        addPetIntoCircle(_id, petSeats);
        
        // Save reward for each referral level
        applyReward(_id, quality);
    }
// Solidity 0.4.25
// Function for automatic add pet
function automaticPetAdd(uint256 _price, uint16 _quality, uint64 _id) external {
        require(!petSyncEnabled);
        require(msg.sender == address(parentInterface));
        
        lastPetId = _id;
        
        // Calculating seats in circle
        uint8 petGrade = getGradeByQuailty(_quality);
        uint8 petSeats = seatsByGrade(petGrade);
        
        // Adding pet into circle
        addPetIntoCircle(_id, petSeats);
        
        // Save reward for each referral level
        applyRewardByAmount(_id, _price);
    }
// Solidity 0.4.25
// Function for withdraw reward by pet owner
function withdrawReward(uint64 _petId) external whenNotPaused {
        
        // Get pet information
        PetInfo memory petInfo = petsInfo[_petId];
        
        // Get owner of pet from pet contract and check it
         (uint64 birthTime, uint256 genes, uint64 breedTimeout, uint16 quality, address petOwner) = parentInterface.getPet(_petId);
        require(petOwner == msg.sender);

        // Transfer reward
        msg.sender.transfer(petInfo.amount);
        
        // Change reward amount in pet information
        petInfo.amount = 0;
        petsInfo[_petId] = petInfo;
    }
// Solidity 0.4.25
// Emergency reward sending by admin
function sendRewardByAdmin(uint64 _petId) external onlyOwner whenNotPaused {
        
        // Get pet information
        PetInfo memory petInfo = petsInfo[_petId];
        
        // Get owner of pet from pet contract and check it
        (uint64 birthTime, uint256 genes, uint64 breedTimeout, uint16 quality, address petOwner) = parentInterface.getPet(_petId);

        // Transfer reward
        petOwner.transfer(petInfo.amount);
        
        // Change reward amount in pet information
        petInfo.amount = 0;
        petsInfo[_petId] = petInfo;
    }
// Solidity 0.5.6
// call update BEFORE all transfers
function update(address whom) private {
        // safety checks
        if (lastUpdated[whom] >= allocations.length) return;
        uint myBalance = balanceOf(whom);
        if (myBalance == 0) return;
        uint supply = totalSupply();
        // get data struct handy
        mapping(address=>uint) storage myRevenue = allocations[lastUpdated[whom]];
        mapping(address=>uint) storage myRevenueBooked = bookedRevenueDue[whom];
        for (uint i = 0; i < tokenList.length; i++) {
            uint value = myRevenue[tokenList[i]].mul(myBalance).div(supply);
            if (value != 0) {
                myRevenueBooked[tokenList[i]] = myRevenueBooked[tokenList[i]].add(value);
            }
        }
        lastUpdated[whom] = allocations.length;
    }
// Solidity 0.5.6
// this function expects an allowance to have been made to allow tokens to be claimed to contract
function addRevenueInTokens(ERC20 token, uint value) public onlyOwner {
        allocations.length += 1;
        require(token.transferFrom(msg.sender, address(this),value),"cannot slurp the tokens");
        if (!tokensShared[address(token)]) {
            tokensShared[address(token)] = true;
            tokenList.push(address(token));
        }
        for (uint period = 0;period < allocations.length; period++) {
            allocations[period][address(token)] = allocations[period][address(token)].add(value);
        }
    }
// Solidity 0.8.7
//int to string function.
function uint2str(uint256 _i)
        internal
        pure
        returns (string memory _uintAsString)
    {
        if (_i == 0) {
            return "0";
        }
        uint256 j = _i;
        uint256 len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bstr = new bytes(len);
        uint256 k = len;
        while (_i != 0) {
            k = k - 1;
            uint8 temp = (48 + uint8(_i - (_i / 10) * 10));
            bytes1 b1 = bytes1(temp);
            bstr[k] = b1;
            _i /= 10;
        }
        return string(bstr);
    }
// Solidity 0.8.7
//OwnerMinting Function. The team is reserving 100 Mechs from the 10,000 collection for promotional purposes and internal rewards.
function ownerMint(uint256 tokenQuant) public payable virtual onlyOwner {
        
        require(
            tokenCounter + tokenQuant < maxSupply,
            "Would exceed max supply!"
        );

        for (uint256 i; i < tokenQuant; i++) {
            _mint(msg.sender, tokenCounter);
            tokenCounter = tokenCounter + 1;
        }

    }