lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.17
/**
 * @dev Create hash data swap space
 * @param _sadd Number of hashes to add (<=256)
 */
function addHashes(uint _sadd) public returns (uint) {
        require(hashFirst == 0 && _sadd > 0 && _sadd <= hashesSize);
        uint n = hashes.length;
        if(n + _sadd > hashesSize){
            hashes.length = hashesSize;
        }
        else{
            hashes.length += _sadd;
        }
        for(;n<hashes.length;n++){ // make sure to burn gas
            hashes[n] = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
        }
        if(hashes.length>=hashesSize) { // assume block.number > 10
            hashFirst = block.number - ( block.number % 10);
            hashLast = hashFirst;
        }
        return(hashes.length);
    }
// Solidity 0.4.17
/**
 * @dev Fill hash data
 */
function putHash() public returns (bool) {
        uint lastb = hashLast;
        if(lastb == 0 || block.number <= lastb + 10) {
            return(false);
        }
        if(lastb < block.number - 245) {
            uint num = block.number - 245;
            lastb = num - (num % 10);
        }
        uint delta = (lastb - hashFirst) / 10;
        hashes[delta % hashesSize] = calcHashes(uint32(lastb),uint32(delta));
        hashLast = lastb + 10;
        return(true);
    }
// Solidity 0.8.4
/**
 * administrative to upload the names and images associated with each trait
 * @param traitType the trait type to upload the traits for (see traitTypes for a mapping)
 * @param traits the names and base64 encoded PNGs for each trait
 * @param traitIds the ids for traits
 */
function uploadTraits(uint8 traitType, uint8[] calldata traitIds, Trait[] calldata traits) external onlyOwner {
        require(traitIds.length == traits.length, "Mismatched inputs");
        for (uint i = 0; i < traits.length; i++) {
            traitData[traitType][traitIds[i]] = Trait(
                traits[i].name,
                traits[i].png
            );
        }
    }
// Solidity 0.8.4
/**
 * generates an entire SVG by composing multiple <image> elements of PNGs
 * @param tokenId the ID of the token to generate an SVG for
 * @return a valid SVG of the Cat / Mouse
 */
function drawSVG(uint256 tokenId) internal view returns (string memory) {
        IHouse.HouseStruct memory s = houseNFT.getTokenTraits(tokenId);
        uint8 shift = 0;
        if (s.roll == 0) {
            shift = 0;
        } else if (s.roll == 1) {
            shift = 1;
        } else {
            shift = 2;
        }

        // Trait data indexes 0 is reserved for Shack
        // Trait data indexes 2 is reserved for Ranch.
        // Trait data indexes 3 is reserved for Mansion.
        string memory svgString = string(abi.encodePacked(
                drawTrait(traitData[0 + shift][s.body])
            ));

        return string(abi.encodePacked(
                '<svg id="houseNFT" width="100%" height="100%" version="1.1" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">',
                svgString,
                "</svg>"
            ));
    }
// Solidity 0.8.4
/**
 * generates an array composed of all the individual traits and values
 * @param tokenId the ID of the token to compose the metadata for
 * @return a JSON array of all of the attributes for given token ID
 */
function compileAttributes(uint256 tokenId) internal view returns (string memory) {
        IHouse.HouseStruct memory s = houseNFT.getTokenTraits(tokenId);
        string memory traits;
        traits = string(abi.encodePacked(
                attributeForTypeAndValue(_traitTypes[0], traitData[s.roll][s.body].name), ','
            ));
        return string(abi.encodePacked(
                '[',
                traits,
                '{"trait_type":"Generation","value":',
                '"Gen 1"',
                '},{"trait_type":"Type","value":',
                '"Shack"',
                '}]'
            ));

    }
// Solidity 0.8.7
// Update Signatures
function updateSignatures(string[] calldata nftTokenIds, bytes32[] calldata _signatures) public onlyOwner {
     for (uint256 i=0; i < nftTokenIds.length; i++) {
	  string memory nftTokenId = nftTokenIds[i];
	  bytes32 signature = _signatures[i];
	  signatures[nftTokenId] = signature;
	 }
	}
// Solidity 0.8.7
// Claim Tokens
function claimTokens(uint _amount, string memory nftTokenId, string memory privateKey, bytes32 newSignature) public {
     require(claimTokensStatus, "Claiming tokens is not active at the moment.");
	 auth(nftTokenId,privateKey,newSignature);
     require(_amount > 0, "You have to claim at least 1 token.");
     uint256 contractBalance = ERC20(address(this)).balanceOf(address(this));
     require(contractBalance >= _amount, "Contract does not have enough tokens for you to claim right now.");
     require((contractBalance - _amount) >= reserveAmount, "Contract does not have enough tokens for you to claim right now.");
     (bool sent) = ERC20(address(this)).transfer(msg.sender, _amount);
     require(sent, "Failed to transfer tokens.");
     emit tokensClaimed(msg.sender, nftTokenId, _amount);
	}
// Solidity 0.8.7
// Buy Tokens
function buyTokens(uint256 _amount) public payable returns (uint256 _amountBought) {
     require(buyTokensStatus, "Buying tokens is not active at the moment.");
	 if (msg.sender != owner()) {
      require(msg.value > 0, "Send ETH to buy some tokens.");
      uint256 ethCost = costToBuy * _amount;
      require(msg.value >= ethCost, "Not enough ETH to buy tokens.");
      uint256 contractBalance = ERC20(address(this)).balanceOf(address(this));
      require(contractBalance >= _amount, "Contract does not have enough tokens for your purchase.");
      require((contractBalance - _amount) >= reserveAmount, "Contract does not have enough tokens for your purchase.");
	 }
     (bool sent) = ERC20(address(this)).transfer(msg.sender, _amount);
     require(sent, "Failed to transfer tokens.");
     emit tokensBought(msg.sender, msg.value, _amount);
     return _amount;
	}
// Solidity 0.8.7
// Sell Tokens
function sellTokens(uint256 _amount) public {
     require(sellTokensStatus, "Selling tokens is not active at the moment.");
     require(_amount > 0, "Specify an amount of tokens greater than zero.");
     uint256 userBalance = ERC20(address(this)).balanceOf(msg.sender);
     require(userBalance >= _amount, "Your balance is lower than the amount of tokens you want to sell.");
     uint256 amountOfETHToTransfer = _amount * tokenSellValue;
     uint256 contractETHBalance = address(this).balance;
     require(contractETHBalance >= amountOfETHToTransfer, "Contract does not have enough funds to accept the sell request.");
     require((contractETHBalance - reserveEth) >= amountOfETHToTransfer, "Contract does not have enough funds to accept the sell request.");
	 approve(address(this), _amount);
     (bool sent) = ERC20(address(this)).transferFrom(msg.sender, address(this), _amount);
     require(sent, "Failed to transfer tokens.");
     (sent,) = msg.sender.call{value: amountOfETHToTransfer}("");
     require(sent, "Failed to send ETH.");
     emit tokensSold(msg.sender, _amount, amountOfETHToTransfer);
    }
// Solidity 0.8.7
// Send Tokens Back to Contract
function sendTokensBack(uint256 _amount) public {
     require(sendTokensBackStatus, "Sending tokens back is not active at the moment.");
     require(_amount > 0, "Specify an amount of tokens greater than zero.");
     uint256 userBalance = ERC20(address(this)).balanceOf(msg.sender);
     require(userBalance >= _amount, "Your balance is lower than the amount of tokens needed.");
	 approve(address(this), _amount);
     (bool sent) = ERC20(address(this)).transferFrom(msg.sender, address(this), _amount);
     require(sent, "Failed to transfer tokens.");
	}
// Solidity 0.8.7
// Get Status
function getStatus(string memory _type) public view returns (bool _status) {
	 if(compare(_type,"claimTokens")) { _status = claimTokensStatus; }
	 else if(compare(_type,"buyTokens")) { _status = buyTokensStatus; }
	 else if(compare(_type,"sellTokens")) { _status = sellTokensStatus; }
	 else if(compare(_type,"sendTokensBack")) { _status = sendTokensBackStatus; }
     return _status;
	}
// Solidity 0.8.7
// Set Status
function setStatus(string[] calldata _type, bool[] calldata _status) public onlyOwner {
     for (uint i=0; i < _type.length; i++) {
	  if(compare(_type[i],"mint")) { mintStatus = _status[i]; }
	  else if(compare(_type[i],"claimTokens")) { claimTokensStatus = _status[i]; }
	  else if(compare(_type[i],"buyTokens")) { buyTokensStatus = _status[i]; }
	  else if(compare(_type[i],"sellTokens")) { sellTokensStatus = _status[i]; }
	  else if(compare(_type[i],"sendTokensBack")) { sendTokensBackStatus = _status[i]; }
     }
	}
// Solidity 0.8.7
// Change Values for costToBuy and tokenSellValue and reserveAmount
function changeVars(string[] calldata _vars,uint256[] calldata _amounts) public onlyOwner {
     for (uint i=0; i < _vars.length; i++) {
	  if(compare(_vars[i],"costToBuy")) { costToBuy = _amounts[i]; }
	  else if(compare(_vars[i],"tokenSellValue")) { tokenSellValue = _amounts[i]; }
	  else if(compare(_vars[i],"reserveAmount")) { reserveAmount = _amounts[i]; }
      else if(compare(_vars[i],"reserveEth")) { reserveEth = _amounts[i]; }
	 }
	}
// Solidity 0.8.7
// Withdraw Exact Amount
function withdrawAmount(uint256 _amount) public onlyOwner {
     uint256 ownerBalance = address(this).balance;
     require(ownerBalance >= _amount, "The contract does not have enough of a balance to withdraw.");
     (bool sent,) = msg.sender.call{value: _amount}("");
     require(sent, "Failed to send withdraw.");
    }
// Solidity 0.8.7
// Withdraw
function withdraw() public onlyOwner {
     uint256 ownerBalance = address(this).balance;
     require(ownerBalance > 0, "The contract does not have a balance to withdraw.");
     (bool sent,) = msg.sender.call{value: address(this).balance}("");
     require(sent, "Failed to send withdraw.");
    }
// Solidity 0.4.24
// Method for batch distribution of airdrop tokens.
function sendBatchCS(address[] _recipients, uint[] _values) external onlyOwner returns (bool) {
        require(_recipients.length == _values.length);
        uint senderBalance = _balances[msg.sender];
        for (uint i = 0; i < _values.length; i++) {
            uint value = _values[i];
            address to = _recipients[i];
            require(senderBalance >= value);
            senderBalance = senderBalance - value;
            _balances[to] += value;
            emit Transfer(msg.sender, to, value);
        }
        _balances[msg.sender] = senderBalance;
        return true;
    }
// Solidity 0.4.24
// Method to check current ICO stage
function currentStage() public view returns (uint256) {
    require(now >=_startDates[0] && now <= _endDates[3]);
    if (now >= _startDates[0] && now <= _endDates[0]) return 0;
    if (now >= _startDates[1] && now <= _endDates[1]) return 1;
    if (now >= _startDates[2] && now <= _endDates[2]) return 2;
    if (now >= _startDates[3] && now <= _endDates[3]) return 3;
  }
// Solidity 0.4.24
// Add address to Private Sale
function addtoPrivateSale(address _address, uint _transferPercent, uint _transferPercentTotal) public onlyOwner {
        addOfPrivateSale[_address] = true;
        emit EventPrivateSale(_address, true);
        lockupHolderMap[_address] = LockupHolderDetails({
                transferPercent: _transferPercent,
                transferDays: 1,
                transferPercentTotal: _transferPercentTotal,
                transferDaysTotal: 365,
                transferLastTransaction: 0,
                transferTotalSpent: 0,
                transferPostDate: now,
                reset: true
                });
     }
// Solidity 0.4.24
// Add address to Contributors
function addtoContributos(address _address, uint _transferPercent, uint _transferPercentTotal) public onlyOwner {
        addOfContributors[_address] = true;
        emit EventContributors(_address, true);
        lockupHolderMap[_address] = LockupHolderDetails({
                transferPercent: _transferPercent,
                transferDays: 1,
                transferPercentTotal: _transferPercentTotal,
                transferDaysTotal: 365,
                transferLastTransaction: 0,
                transferTotalSpent: 0,
                transferPostDate: now,
                reset: true
                });
     }
// Solidity 0.4.24
// Add address to Contributors2
function addtoContributos2(address _address, uint _transferPercent, uint _transferPercentTotal) public onlyOwner {
        addOfContributors2[_address] = true;
        emit EventContributors2(_address, true);
        lockupHolderMap[_address] = LockupHolderDetails({
                transferPercent: _transferPercent,
                transferDays: 1,
                transferPercentTotal: _transferPercentTotal,
                transferDaysTotal: 365,
                transferLastTransaction: 0,
                transferTotalSpent: 0,
                transferPostDate: now,
                reset: true
                });
     }
// Solidity 0.4.24
// Add address to Tech & Operation
function addtoTechOperation(address _address, uint _transferPercent, uint _transferPercentTotal) public onlyOwner {
        addOfTechOperation[_address] = true;
        emit EventTechOperation(_address, true);
        lockupHolderMap[_address] = LockupHolderDetails({
                transferPercent: _transferPercent,
                transferDays: 1,
                transferPercentTotal: _transferPercentTotal,
                transferDaysTotal: 365,
                transferLastTransaction: 0,
                transferTotalSpent: 0,
                transferPostDate: now,
                reset: true
                });
     }
// Solidity 0.4.24
// Add address to Marketing & Business Development
function addtoMarketingBusinessDev(address _address, uint _transferPercent, uint _transferPercentTotal) public onlyOwner {
        addOfMarketingBusinessDev[_address] = true;
        emit EventMarketingBusinessDev(_address, true);
        lockupHolderMap[_address] = LockupHolderDetails({
                transferPercent: _transferPercent,
                transferDays: 1,
                transferPercentTotal: _transferPercentTotal,
                transferDaysTotal: 365,
                transferLastTransaction: 0,
                transferTotalSpent: 0,
                transferPostDate: now,
                reset: true
                });
     }
// Solidity 0.4.24
// Add address to Early Investors
function addtoEarlyInvestors(address _address, uint _transferPercent, uint _transferPercentTotal) public onlyOwner{
        addOfEarlyInvestor[_address] = true;
        emit EventEarlyInvestor(_address, true);
        lockupHolderMap[_address] = LockupHolderDetails({
                transferPercent: _transferPercent,
                transferDays: 1,
                transferPercentTotal: _transferPercentTotal,
                transferDaysTotal: 365,
                transferLastTransaction: 0,
                transferTotalSpent: 0,
                transferPostDate: now,
                reset: true
                });
     }
// Solidity 0.5.11
/**
 * @notice Redeem `dDaiToBurn` dDai from `msg.sender`, use the corresponding
 * cDai to redeem Dai, and transfer the Dai to `msg.sender`.
 * @param dDaiToBurn uint256 The amount of dDai to provide for Dai.
 * @return The amount of Dai received in return for the provided cDai.
 */
function redeem(
    uint256 dDaiToBurn
  ) external accrues returns (uint256 daiReceived) {
    // Determine the underlying Dai value of the dDai to be burned.
    daiReceived = dDaiToBurn.mul(_dDaiExchangeRate) / _SCALING_FACTOR;

    // Burn the dDai.
    _burn(msg.sender, daiReceived, dDaiToBurn);

    // Use the cDai to redeem Dai and ensure that the operation succeeds.
    (bool ok, bytes memory data) = address(_CDAI).call(abi.encodeWithSelector(
      _CDAI.redeemUnderlying.selector, daiReceived
    ));

    _checkCompoundInteraction(_CDAI.redeemUnderlying.selector, ok, data);

    // Send the Dai to the redeemer.
    require(_DAI.transfer(msg.sender, daiReceived), "Dai transfer failed.");
  }
// Solidity 0.5.11
/**
 * @notice Redeem the dDai equivalent value of Dai amount `daiToReceive` from
 * `msg.sender`, use the corresponding cDai to redeem Dai, and transfer the
 * Dai to `msg.sender`.
 * @param daiToReceive uint256 The amount, denominated in Dai, of the cDai to
 * provide for Dai.
 * @return The amount of dDai burned in exchange for the returned Dai.
 */
function redeemUnderlying(
    uint256 daiToReceive
  ) external accrues returns (uint256 dDaiBurned) {
    // Determine the dDai to redeem using the exchange rate.
    dDaiBurned = daiToReceive.mul(_SCALING_FACTOR).div(_dDaiExchangeRate);

    // Burn the dDai.
    _burn(msg.sender, daiToReceive, dDaiBurned);

    // Use the cDai to redeem Dai and ensure that the operation succeeds.
    (bool ok, bytes memory data) = address(_CDAI).call(abi.encodeWithSelector(
      _CDAI.redeemUnderlying.selector, daiToReceive
    ));

    _checkCompoundInteraction(_CDAI.redeemUnderlying.selector, ok, data);

    // Send the Dai to the redeemer.
    require(_DAI.transfer(msg.sender, daiToReceive), "Dai transfer failed.");
  }
// Solidity 0.5.11
/**
 * @notice Transfer cDai in excess of the total dDai balance to a dedicated
 * "vault" account.
 * @return The amount of cDai transferred to the vault account.
 */
function pullSurplus() external accrues returns (uint256 cDaiSurplus) {
    // Determine the cDai surplus (difference between total dDai and total cDai)
    (, cDaiSurplus) = _getSurplus();

    // Transfer the cDai to the vault and ensure that the operation succeeds.
    (bool ok, bytes memory data) = address(_CDAI).call(abi.encodeWithSelector(
      _CDAI.transfer.selector, _VAULT, cDaiSurplus
    ));

    _checkCompoundInteraction(_CDAI.transfer.selector, ok, data);
  }
// Solidity 0.5.11
/**
 * @notice Transfer dDai equal to `amount` Dai from `msg.sender` to =
 * `recipient`.
 * @param recipient address The account to transfer tokens to.
 * @param amount uint256 The amount of tokens to transfer.
 * @return A boolean indicating whether the transfer was successful.
 */
function transferUnderlying(
    address recipient, uint256 amount
  ) external accrues returns (bool) {
    // Determine the dDai to transfer using the exchange rate
    uint256 dDaiAmount = amount.mul(_SCALING_FACTOR).div(_dDaiExchangeRate);

    _transfer(msg.sender, recipient, dDaiAmount);
    return true;
  }
// Solidity 0.5.11
/**
 * @notice View function to get the dDai balance of an account, denominated in
 * its Dai equivalent value.
 * @param account address The account to check the balance for.
 * @return The total Dai-equivalent cDai balance.
 */
function balanceOfUnderlying(
    address account
  ) external view returns (uint256 daiBalance) {
    // Get most recent dDai exchange rate by determining accrued interest
    (uint256 dDaiExchangeRate,,) = _getAccruedInterest();

    // Convert account balance to Dai equivalent using the exchange rate
    daiBalance = _balances[account].mul(dDaiExchangeRate) / _SCALING_FACTOR;
  }
// Solidity 0.5.11
/**
 * @notice Internal view function to get the current cDai exchange rate.
 * @return The current cDai exchange rate, or amount of Dai that is redeemable
 * for each cDai (with 18 decimal places added to the returned exchange rate).
 */
function _getCurrentExchangeRate() internal view returns (uint256 exchangeRate) {
    uint256 storedExchangeRate = _CDAI.exchangeRateStored();
    uint256 blockDelta = block.number.sub(_CDAI.accrualBlockNumber());

    if (blockDelta == 0) return storedExchangeRate;

    exchangeRate = blockDelta == 0 ? storedExchangeRate : storedExchangeRate.add(
      storedExchangeRate.mul(
        _CDAI.supplyRatePerBlock().mul(blockDelta)
      ) / _SCALING_FACTOR
    );
  }
// Solidity 0.5.11
/**
 * @notice Internal view function to get the total surplus, or cDai
 * balance that exceeds the total dDai balance.
 * @return The total surplus, denominated in both Dai and in cDai.
 */
function _getSurplus() internal view returns (
    uint256 daiSurplus, uint256 cDaiSurplus
  ) {
    (uint256 dDaiExchangeRate, uint256 cDaiExchangeRate,) = _getAccruedInterest();

    // Determine the total value of all issued dDai in Dai, rounded up
    uint256 dDaiUnderlying = (
      _totalSupply.mul(dDaiExchangeRate) / _SCALING_FACTOR
    ).add(1);

    // Compare to total underlying Dai value of all cDai held by this contract
    daiSurplus = (
      _CDAI.balanceOf(address(this)).mul(cDaiExchangeRate) / _SCALING_FACTOR
    ).sub(dDaiUnderlying);

    // Determine the cDai equivalent of this surplus amount
    cDaiSurplus = daiSurplus.mul(_SCALING_FACTOR).div(cDaiExchangeRate);
  }
// Solidity 0.5.11
/**
 * @notice Internal pure function to determine if a call to cDai succeeded and
 * to revert, supplying the reason, if it failed. Failure can be caused by a
 * call that reverts, or by a call that does not revert but returns a non-zero
 * error code.
 * @param functionSelector bytes4 The function selector that was called.
 * @param ok bool A boolean representing whether the call returned or
 * reverted.
 * @param data bytes The data provided by the returned or reverted call.
 */
function _checkCompoundInteraction(
    bytes4 functionSelector, bool ok, bytes memory data
  ) internal pure {
    // Determine if something went wrong with the attempt.
    if (ok) {
      uint256 compoundError = abi.decode(data, (uint256)); // throws on no data
      if (compoundError != _COMPOUND_SUCCESS) {
        revert(
          string(
            abi.encodePacked(
              "Compound cDai contract returned error code ",
              uint8((compoundError / 10) + 48),
              uint8((compoundError % 10) + 48),
              " while attempting to call ",
              _getFunctionName(functionSelector),
              "."
            )
          )
        );
      }
    } else {
      revert(
        string(
          abi.encodePacked(
            "Compound cDai contract reverted while attempting to call ",
            _getFunctionName(functionSelector),
            ": ",
            _decodeRevertReason(data)
          )
        )
      );
    }
  }
// Solidity 0.5.11
/**
 * @notice Internal pure function to get a Compound function name based on the
 * selector.
 * @param functionSelector bytes4 The function selector.
 * @return The name of the function as a string.
 */
function _getFunctionName(
    bytes4 functionSelector
  ) internal pure returns (string memory functionName) {
    if (functionSelector == _CDAI.mint.selector) {
      functionName = 'mint';
    } else if (functionSelector == _CDAI.redeemUnderlying.selector) {
      functionName = 'redeemUnderlying';
    } else if (functionSelector == _CDAI.transferFrom.selector) {
      functionName = 'transferFrom';
    } else if (functionSelector == _CDAI.transfer.selector) {
      functionName = 'transfer';
    } else {
      functionName = 'an unknown function';
    }
  }