lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.11
/// Get current reward for stake
/// @dev calculates returnable stake amount
/// @param _user the user to query
/// @param _index the stake index to query
/// @return total stake reward
function currentReward(address _user, uint256 _index) public view returns (uint256) {
    if(stakeList[msg.sender][_index].amount == 0){
      return 0;
    }
    uint256 amount = stakeList[_user][_index].amount;
    uint256 daysPercent = (block.timestamp - stakeList[msg.sender][_index].stakeTime).div(86400).mul(7);
    uint256 minutePercent = (block.timestamp - stakeList[msg.sender][_index].stakeTime).mul(8101851);

    //
    uint moondayReserves;
    uint cropReserves;
    uint wethMReserves;
    uint wethCReserves;

    if(moonday < weth){
      (wethMReserves, moondayReserves,) = lpToken.getReserves();
    }
    else{
      (moondayReserves, wethMReserves,) = lpToken.getReserves();
    }

    if(crops < weth){
      (wethCReserves, cropReserves,) = cropsETHToken.getReserves();
    }
    else{
      (cropReserves, wethCReserves,) = cropsETHToken.getReserves();
    }

    uint256 cropsPrice = wethCReserves.mul(100000000).div(cropReserves).mul(10000000000).div(wethMReserves.mul(100000000).div(moondayReserves)).mul(100000000);
    /*
    if(daysPercent > 185){
      return cropsPrice.mul(amount).div(1 ether).mul(185).div(50);
    }
    else{
      return cropsPrice.mul(amount).div(1 ether).mul(daysPercent).div(50);
    }*/
    if(minutePercent > 18500000000000){
      return cropsPrice.mul(amount).div(1 ether).mul(18500000000000).div(5000000000000);
    }
    else{
      return cropsPrice.mul(amount).div(1 ether).mul(minutePercent).div(5000000000000);
    }
  }
// Solidity 0.6.11
/// Stake LP token
/// @dev stakes users LP tokens
/// @param _amount the amount to stake
/// @param _refCode optional referral code
function stake(uint256 _amount, uint _refCode) public {
      require(_amount > 0, "Cannot stake 0");

      uint256 deposit = _amount.mul(7).div(10);
      stakeList[msg.sender][stakeCount[msg.sender]].amount = deposit;
      stakeList[msg.sender][stakeCount[msg.sender]].stakeTime = block.timestamp;
      lpToken.safeTransferFrom(msg.sender, address(this), deposit);
      stakeCount[msg.sender]++;

      if(refCodeIndex[_refCode] != address(0)){
        lpToken.safeTransferFrom(msg.sender, owner, _amount.mul(22).div(100));
        lpToken.safeTransferFrom(msg.sender, dev1, _amount.div(100));
        lpToken.safeTransferFrom(msg.sender, dev2, _amount.div(100));
        lpToken.safeTransferFrom(msg.sender, dev3, _amount.div(100));
        lpToken.safeTransferFrom(msg.sender, refCodeIndex[_refCode], _amount.div(20));
      }
      else{
        lpToken.safeTransferFrom(msg.sender, owner, _amount.mul(27).div(100));
        lpToken.safeTransferFrom(msg.sender, dev1, _amount.div(100));
        lpToken.safeTransferFrom(msg.sender, dev2, _amount.div(100));
        lpToken.safeTransferFrom(msg.sender, dev3, _amount.div(100));
      }

      emit Staked(msg.sender, deposit, stakeCount[msg.sender] - 1);
  }
// Solidity 0.8.3
/**
 * @dev Removes a value from the oracle.
 * Note: this function is only callable by the Governance contract.
 * @param _queryId is ID of the specific data feed
 * @param _timestamp is the timestamp of the data value to remove
 */
function removeValue(bytes32 _queryId, uint256 _timestamp) external {
        require(
            msg.sender ==
                IController(TELLOR_ADDRESS).addresses(_GOVERNANCE_CONTRACT) ||
                msg.sender ==
                IController(TELLOR_ADDRESS).addresses(_ORACLE_CONTRACT),
            "caller must be the governance contract or the oracle contract"
        );
        Report storage rep = reports[_queryId];
        uint256 _index = rep.timestampIndex[_timestamp];
        // Shift all timestamps back to reflect deletion of value
        for (uint256 i = _index; i < rep.timestamps.length - 1; i++) {
            rep.timestamps[i] = rep.timestamps[i + 1];
            rep.timestampIndex[rep.timestamps[i]] -= 1;
        }
        // Delete and reset timestamp and value
        delete rep.timestamps[rep.timestamps.length - 1];
        rep.timestamps.pop();
        rep.valueByTimestamp[_timestamp] = "";
        rep.timestampIndex[_timestamp] = 0;
    }
// Solidity 0.8.3
/**
 * @dev Adds tips to incentivize reporters to submit values for specific data IDs.
 * @param _queryId is ID of the specific data feed
 * @param _tip is the amount to tip the given data ID
 * @param _queryData is required for IDs greater than 100, informs reporters how to fulfill request. See github.com/tellor-io/dataSpecs
 */
function tipQuery(
        bytes32 _queryId,
        uint256 _tip,
        bytes memory _queryData
    ) external {
        // Require tip to be greater than 1 and be paid
        require(_tip > 1, "Tip should be greater than 1");
        require(
            IController(TELLOR_ADDRESS).approveAndTransferFrom(
                msg.sender,
                address(this),
                _tip
            ),
            "tip must be paid"
        );
        require(
            _queryId == keccak256(_queryData) ||
                uint256(_queryId) <= 100 ||
                msg.sender ==
                IController(TELLOR_ADDRESS).addresses(_GOVERNANCE_CONTRACT),
            "id must be hash of bytes data"
        );
        // Burn half the tip
        _tip = _tip / 2;
        IController(TELLOR_ADDRESS).burn(_tip);
        // Update total tip amount for user, data ID, and in total contract
        tips[_queryId] += _tip;
        tipsByUser[msg.sender] += _tip;
        tipsInContract += _tip;
        emit TipAdded(msg.sender, _queryId, _tip, tips[_queryId], _queryData);
    }
// Solidity 0.8.3
/**
 * @dev Calculates the current reward for a reporter given tips
 * and time based reward
 * @param _queryId is ID of the specific data feed
 * @return uint256 tips on given queryId
 * @return uint256 time based reward
 */
function getCurrentReward(bytes32 _queryId)
        public
        view
        returns (uint256, uint256)
    {
        IController _tellor = IController(TELLOR_ADDRESS);
        uint256 _timeDiff = block.timestamp - timeOfLastNewValue;
        uint256 _reward = (_timeDiff * timeBasedReward) / 300; //.5 TRB per 5 minutes (should we make this upgradeable)
        if (_tellor.balanceOf(address(this)) < _reward + tipsInContract) {
            _reward = _tellor.balanceOf(address(this)) - tipsInContract;
        }
        return (tips[_queryId], _reward);
    }
// Solidity 0.8.9
// extract 0-6 substring at spot within mega palette string
function getColor(uint256 spot) private pure returns (string memory) {
    if (spot == 0) return '';
    bytes memory strBytes = bytes(COLORS);
    bytes memory result = new bytes(6);
    for (uint256 i = (spot * 6); i < ((spot + 1) * 6); i++) result[i - (spot * 6)] = strBytes[i];
    return string(result);
  }
// Solidity 0.8.0
// Manage GameObjects
function addGameObject(
        uint256 _maxSupply,
        uint256 _mintPrice,
        bool _paidWithToken
    ) public onlyOwner {
        GameObject storage go = gameObjects[counter.current()];
        go.gameObjectId = counter.current();
        go.maxSupply = _maxSupply;
        go.mintPrice = _mintPrice;
        go.paidWithToken = _paidWithToken;
        go.isSaleClosed = true;
        go.totalSupply = 0;

        counter.increment();
    }
// Solidity 0.6.12
/**
 * Mints NFTEA
 */
function mintTEA(uint numberOfTokens) public payable {
        require(saleIsActive, "Sale must be active to mint TEA");
        require(numberOfTokens <= maxTeaPurchase, "Can only mint 50 tokens at a time");
        require(totalSupply().add(numberOfTokens) <= MAX_Tea, "Purchase would exceed max supply of Tea");
        require(TeaPrice.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        
        for(uint i = 0; i < numberOfTokens; i++) {
            uint mintIndex = totalSupply();
            if (totalSupply() < MAX_Tea) {
                _safeMint(msg.sender, mintIndex);
            }
            if (totalSupply() % 145 == 143){
                _safeMint(msg.sender, mintIndex+1);
            }
        }

        // If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after
        // the end of pre-sale, set the starting index block
        if (startingIndexBlock == 0 && (totalSupply() == MAX_Tea || block.timestamp >= REVEAL_TIMESTAMP)) {
            startingIndexBlock = block.number;
        } 
    }
// Solidity 0.6.2
/**
 * @notice Adds new adapter to adapters list.
 * The function is callable only by the owner.
 * @param newAdapter Address of new adapter.
 * @param _assets Addresses of adapter's assets.
 */
function addAdapter(
        address newAdapter,
        address[] memory _assets
    )
        public
        onlyOwner
    {
        require(newAdapter != address(0), "AAM: zero adapter!");
        require(newAdapter != INITIAL_ADAPTER, "AAM: initial adapter!");
        require(adapters[newAdapter] == address(0), "AAM: adapter exists!");

        adapters[newAdapter] = adapters[INITIAL_ADAPTER];
        adapters[INITIAL_ADAPTER] = newAdapter;

        assets[newAdapter] = _assets;
    }
// Solidity 0.6.2
/**
 * @notice Removes one of adapters from adapters list.
 * The function is callable only by the owner.
 * @param adapter Address of adapter to be removed.
 */
function removeAdapter(
        address adapter
    )
        public
        onlyOwner
    {
        require(isValidAdapter(adapter), "AAM: invalid adapter!");

        address prevAdapter;
        address currentAdapter = adapters[adapter];
        while (currentAdapter != adapter) {
            prevAdapter = currentAdapter;
            currentAdapter = adapters[currentAdapter];
        }

        delete assets[adapter];

        adapters[prevAdapter] = adapters[adapter];
        adapters[adapter] = address(0);
    }
// Solidity 0.6.2
/**
 * @notice Removes one of adapter's assets by its index.
 * The function is callable only by the owner.
 * @param adapter Address of adapter.
 * @param assetIndex Index of adapter's asset to be removed.
 */
function removeAdapterAsset(
        address adapter,
        uint256 assetIndex
    )
        public
        onlyOwner
    {
        require(isValidAdapter(adapter), "AAM: adapter is not valid!");

        address[] storage adapterAssets = assets[adapter];
        uint256 length = adapterAssets.length;
        require(assetIndex < length, "AAM: asset index is too large!");

        if (assetIndex != length - 1) {
            adapterAssets[assetIndex] = adapterAssets[length - 1];
        }

        adapterAssets.pop();
    }
// Solidity 0.6.2
/**
 * @return Array of adapters.
 */
function getAdapters()
        public
        view
        returns (address[] memory)
    {
        uint256 counter = 0;
        address currentAdapter = adapters[INITIAL_ADAPTER];

        while (currentAdapter != INITIAL_ADAPTER) {
            currentAdapter = adapters[currentAdapter];
            counter++;
        }

        address[] memory adaptersList = new address[](counter);
        counter = 0;
        currentAdapter = adapters[INITIAL_ADAPTER];

        while (currentAdapter != INITIAL_ADAPTER) {
            adaptersList[counter] = currentAdapter;
            currentAdapter = adapters[currentAdapter];
            counter++;
        }

        return adaptersList;
    }
// Solidity 0.6.2
/**
 * @return All the amounts and rates of supported assets
 * via supported adapters by the given user.
 */
function getBalancesAndRates(
        address user
    )
        external
        view
        returns(ProtocolDetail[] memory)
    {
        address[] memory adapters = getAdapters();
        ProtocolDetail[] memory protocolDetails = new ProtocolDetail[](adapters.length);

        for (uint256 i = 0; i < adapters.length; i++) {
            protocolDetails[i] = ProtocolDetail({
                name: Adapter(adapters[i]).getProtocolName(),
                balances: getBalances(user, adapters[i]),
                rates: getRates(adapters[i])
            });
        }

        return protocolDetails;
    }
// Solidity 0.6.2
/**
 * @return All the exchange rates for supported assets
 * via the supported adapters.
 */
function getRates()
        external
        view
        returns (ProtocolRate[] memory)
    {
        address[] memory adapters = getAdapters();
        ProtocolRate[] memory protocolRates = new ProtocolRate[](adapters.length);

        for (uint256 i = 0; i < adapters.length; i++) {
            protocolRates[i] = ProtocolRate({
                name: Adapter(adapters[i]).getProtocolName(),
                rates: getRates(adapters[i])
            });
        }

        return protocolRates;
    }
// Solidity 0.6.2
/**
 * @return All the amounts of the given assets
 * via the given adapter by the given user.
 */
function getBalances(
        address user,
        address adapter,
        address[] memory assets
    )
        public
        view
        returns (AssetBalance[] memory)
    {
        uint256 length = assets.length;
        AssetBalance[] memory assetBalances = new AssetBalance[](length);

        for (uint256 i = 0; i < length; i++) {
            address asset = assets[i];
            assetBalances[i] = AssetBalance({
                asset: asset,
                amount: Adapter(adapter).getAssetAmount(asset, user),
                decimals: getAssetDecimals(asset)
            });
        }

        return assetBalances;
    }
// Solidity 0.6.2
/**
 * @return All the exchange rates for the given assets
 * via the given adapter.
 */
function getRates(
        address adapter,
        address[] memory assets
    )
        public
        view
        returns (AssetRate[] memory)
    {
        uint256 length = assets.length;
        AssetRate[] memory rates = new AssetRate[](length);

        for (uint256 i = 0; i < length; i++) {
            address asset = assets[i];
            rates[i] = AssetRate({
                asset: asset,
                components: Adapter(adapter).getUnderlyingRates(asset)
            });
        }

        return rates;
    }
// Solidity 0.8.9
/// @notice Mints multiple new martians
/// @dev The method includes a signature that was provided by the MarsGenesis backend, to ensure data integrity
/// @param signatures The signatures provided by the backend to ensure data integrity
/// @param martianIds The IDs of the martians to be minted
/// @param landTokenIds The IDs of the MarsGenesis parcels to be redeemed
/// @param promoOwner Any promo martian address
/// @return true
function mintMartians(bytes[] memory signatures, uint[] memory martianIds, uint[] memory landTokenIds, address promoOwner) external payable returns (bool) {                
        uint total = martianIds.length;
        require(landTokenIds.length <= total, "D0");

        if (landTokenIds.length > 0) {
            require(_reservedMartians >= uint16(landTokenIds.length));
            
            for(uint i = 0; i < total; i++) {
                require(_marsGenesisCoreContract.ownerOf(landTokenIds[i]) == msg.sender, "E1");
                require(landTokenIdRedeemed[landTokenIds[i]] == false, "E2");
                landTokenIdRedeemed[landTokenIds[i]] = true;
            }
            _reservedMartians -= uint16(landTokenIds.length);
        }

        require(_tokenIdTracker.current() + total + _reservedMartians <= MAX_MARTIANS, "MAX");

        address martianOwner;
        if (hasRole(DEFAULT_ADMIN_ROLE, _msgSender())) {
            martianOwner = promoOwner;
        } else {
            require(msg.value >= 0.08 ether * (total - landTokenIds.length), "$");
            martianOwner = _msgSender();
        }

        for(uint i = 0; i < total; i++) {
            require(_mintedIds[martianIds[i]] == false, "ID");

            bytes32 hash = keccak256(abi.encodePacked(address(this), martianIds[i], msg.sender));
            address signer = _recoverSigner(hash, signatures[i]);
            require(signer == _deployerAddress, "SIGN");

            uint newTokenId = _mintMartian(martianOwner, martianIds[i]);

            if (i < landTokenIds.length) {
                emit Discovery(martianOwner, newTokenId, martianIds[i], landTokenIds[i]);
            } else {
                emit Discovery(martianOwner, newTokenId, martianIds[i], 10001);
            }
        }
        
        return true;
    }
// Solidity 0.8.0
/**
 * A Scribe is a contract that is allowed to write Lore *if* the transaction
 * originated from the token owner. For example, The Great Burning may write
 * the death of a Wizard and the inception of their Soul
 */
function addLoreWithScribe(
        address tokenContract,
        uint256 tokenId,
        uint256 parentLoreId,
        bool nsfw,
        string memory loreMetadataURI
    ) public onlyAllowedTokenContract(tokenContract) {
        require(scribeAllowlist[_msgSender()], 'sender is not a Scribe');

        address tokenOwner = IERC721(tokenContract).ownerOf(tokenId);
        require(
            tokenOwner == tx.origin, // ! - note that msg.sender must be a Scribe for this to work
            'Owner: tx.origin is not the token owner'
        );

        tokenLore[tokenContract][tokenId].push(
            // we credit this lore to the Scribe, not the token owner
            Lore(_msgSender(), parentLoreId, nsfw, false, loreMetadataURI)
        );

        emit LoreAdded(
            tokenContract,
            tokenId,
            tokenLore[tokenContract][tokenId].length - 1
        );
    }
// Solidity 0.4.24
/**
 * @dev Function to stop minting new tokens.
 * @return True if the operation was successful.
 */
function finishMinting() onlyOwner canMint public returns (bool) {

    require(foundationAddress != address(0) && teamAddress != address(0) && bountyAddress != address(0));
    require(SHARE_PURCHASERS + SHARE_FOUNDATION + SHARE_TEAM + SHARE_BOUNTY == 1000);
    require(totalSupply_ != 0);
    
    // before calling this method totalSupply includes only purchased tokens
    uint256 onePerThousand = totalSupply_ / SHARE_PURCHASERS; //ignore (totalSupply mod 617) ~= 616e-8,
    
    uint256 foundationTokens = onePerThousand * SHARE_FOUNDATION;             
    uint256 teamTokens = onePerThousand * SHARE_TEAM;   
    uint256 bountyTokens = onePerThousand * SHARE_BOUNTY;
      
    mint(foundationAddress, foundationTokens);
    mint(teamAddress, teamTokens);
    mint(bountyAddress, bountyTokens);
  
    mintingFinished = true;
    emit MintFinished();
    return true;
  }
// Solidity 0.4.25
/**
 * @dev Returns the data about a token.
 */
function getDataForTokenId(uint256 _tokenId) public view returns
    (
        uint,
        string,
        uint,
        uint,
        address,
        address,
        uint
    )
    {
         metaData storage meta = tokenToMetaData[_tokenId];
        return (
            _tokenId,
            meta.seed,
            meta.parent1,
            meta.parent2,
            ownerOf(_tokenId),
            getApproved(_tokenId),
            meta.remixCount
        );
    }
// Solidity 0.4.25
// Converts uint to a string
function uint2str(uint i) internal pure returns (string){
        if (i == 0) return "0";
        uint j = i;
        uint length;
        while (j != 0){
            length++;
            j /= 10;
        }
        bytes memory bstr = new bytes(length);
        uint k = length - 1;
        while (i != 0){
            bstr[k--] = byte(48 + i % 10);
            i /= 10;
        }
        return string(bstr);
    }
// Solidity 0.5.0
// Vesting Issue Function -----
function issue_Vesting_RND(address _to, uint _time) onlyOwner_creator public
    {
        require(saleTime == false);
        require(vestingReleaseRound_RND >= _time);
        
        uint time = now;
        require( ( ( endSaleTime + (_time * vestingReleaseTime_RND) ) < time ) && ( vestingRelease_RND[_time] > 0 ) );
        
        uint tokens = vestingRelease_RND[_time];

        require(maxSupply_RND >= issueToken_RND.add(tokens));
        
        balances[_to] = balances[_to].add(tokens);
        vestingRelease_RND[_time] = 0;
        
        issueToken_Total = issueToken_Total.add(tokens);
        issueToken_RND = issueToken_RND.add(tokens);
        
        emit Issue_RND(_to, tokens);
    }
// Solidity 0.5.17
// accept ether subscription payments
// only one time per address
// msg.value = ticketPriceWei + expected future price format in wei
// Example 
// 1. ticketPrice is 0.01 Ether 
// 2. Your future price prediction is 9588.25
// 3. You send 0.1 + 0.0000000000958825
// 4. The contract registers your prediction of 958825
// 5. The contract pays you back  get back 0.0000000000958825 Ether 
function() payable external {
        require(status == 0, 'closed');
        require(msg.value > ticketPriceWei && msg.value < ticketPriceWei + 10000000, 'invalid ticket price');
        require(futures[msg.sender] == 0, 'already in');
        uint future = msg.value - ticketPriceWei;
        futures[msg.sender] = future;
        subscribers.push(msg.sender);
        msg.sender.transfer(future);
        emit PriceBet(msg.sender, future, now);
    }
// Solidity 0.5.17
// close subscription doors
function closeSubscriptions() public {
        require(msg.sender == factory, 'only factory');
        require(status == 0, 'wrong transition');
        status = 1;
        // in case of one+ subscribers
        // lunch the next solution timer
        if(subscribers.length == 0) {
            status = 2;
            distributeRewards();
        }
        emit RoundClose();
    }
// Solidity 0.5.17
// if the execution did not happen after 24 hours
// the beneficiary can withdraw total amount same share
// equally with the subscribers
function rollback() public {
        
        // should be not distributed
        require(status < 3, 'already distributed');
        
        // only the beneficiary can do it
        require(msg.sender == beneficiary, 'only beneficiary');
        
        // at least 24H passed without execution
        uint unlockTime = created.add(executionDelay).add(24*3600);
        require(now >= unlockTime, 'still early');
        
        // the balance is normally distributed
        uint perShareWei = address(this).balance.div(subscribers.length);
        for(uint i = 0; i < subscribers.length; i++) {
            subscribers[i].transfer(perShareWei);
        }
    }
// Solidity 0.5.17
// set the solution and alarm the distribution
// pay the factory and tell about the gas Limit
function executeResult(uint solution) public returns (uint gasLimit) {
        require(msg.sender == factory, 'only factory');
        require(status == 1, 'wrong transition');
        status = 2;
        winSolution = solution;
        emit RoundExecuted(winSolution);

        // default provable 20 GWei per Gas and 200 000 GAS      
        uint PROVABLE_GAS_PRICE = 20e9 wei;

        // estimation for the factory
        uint estGas = subscribers.length*7000 + 300000;
        uint estWei = estGas.mul(PROVABLE_GAS_PRICE);

        // check up the available cost
        if(address(this).balance >= estWei) {
            // defaulting extras back to factory
            factory.transfer((estGas.sub(200000)).mul(PROVABLE_GAS_PRICE));
            return estGas;
        } else {
            // The factory covers DEFAULT PROVABLE GAS COST: 20GWEI * 200 000 GAS
            return 200000;
        }
    }