lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.6
//0: not revealed, 1: cat 2: tiger
function checkSpecies(uint256 _tokenId) public view returns (uint256){
        if(_secret == 0 || !_exists(_tokenId)){
            return 0;
        }
        if(evolved[_tokenId]){
            return 2;
        }
        uint256 rand = uint256(keccak256(abi.encodePacked(_tokenId, _secret)));
        if(rand % 3 == 0){
            return 2;
        }else{
            return 1;
        }
    }
// Solidity 0.8.4
/**
 * Sets series limit.
 *
 * @param series series name
 * @param limit limit of the tokens that can be under this series
 * @param mintPrice price to mint the token
 */
function setSeries(string memory series, uint256 limit, uint256 mintPrice) public onlyOwner {
        require(bytes(series).length > bytes("").length, "series cannot be empty string");
        _seriesLimits[series] = limit;
        _seriesMintPrices[series] = mintPrice;
        emit SeriesSet(msg.sender, series, limit, mintPrice);
    }
// Solidity 0.8.4
/**
 * Mints the token with predictions. This method will produce the logs so the user can find out the tokenId once transaction is written to the chain.
 *
 * @param series series name
 * @param nickname space for user to put the identifier
 * @param predict_1 prediction 1
 * @param predict_2 prediction 2
 * @param predict_3 prediction 3
 * @param predict_4 prediction 4
 * @param predict_5 prediction 5
 * @param predict_6 prediction 6
 *
 */
function mint(string memory series, string memory nickname, uint64 predict_1, uint64 predict_2, uint64 predict_3, uint64 predict_4, uint64 predict_5, uint64 predict_6)
        public payable
    {   
        require(_seriesMints[series] < _seriesLimits[series], "Series limit has been reached");
        require(msg.value == _seriesMintPrices[series], "ETH value does not match the series mint price");
        bytes memory b = new bytes(0);
        _mint(msg.sender, _numTokens, 1, b);
        uint64 luck = generateLuckyNum(_numTokens, _numDecimals);
        uint256 seriesNumber = _seriesMints[series] + 1;
        _predictions[_numTokens] = Prediction(block.timestamp, series, seriesNumber, nickname, luck, predict_1, predict_2, predict_3, predict_4, predict_5, predict_6);
        emit PredictionMinted(msg.sender, _numTokens, series, seriesNumber, nickname, luck, predict_1, predict_2, predict_3, predict_4, predict_5, predict_6);
        _numTokens = _numTokens + 1;
        _seriesMints[series] = seriesNumber;
    }
// Solidity 0.8.4
/**
 *
 * Sets the result for the given token.
 *
 * @param tokenId token id
 * @param result_0 the actual value at the time of when prediction had been written to the chain
 * @param result_1 the actual value to the prediction_1
 * @param result_2 the actual value to the prediction_2
 * @param result_3 the actual value to the prediction_3
 * @param result_4 the actual value to the prediction_4
 * @param result_5 the actual value to the prediction_5
 * @param result_6 the actual value to the prediction_6
 */
function setResult(uint256 tokenId, uint64 result_0, uint64 result_1, uint64 result_2, uint64 result_3, uint64 result_4, uint64 result_5, uint64 result_6)
        public onlyOwner
    {
        require(bytes(_predictions[tokenId].series).length > bytes("").length, "prediction must be minted before result can be set");
        _results[tokenId] = Result(result_0, result_1, result_2, result_3, result_4, result_5, result_6);
        emit ResultSet(msg.sender, tokenId, _predictions[tokenId].series, result_0, result_1, result_2, result_3, result_4, result_5, result_6);
    }
// Solidity 0.8.4
/**
 * Returns the result data under the specified token.
 *
 * @param tokenId token id
 * @return result data for the given token
 */
function result(uint256 tokenId) public view returns (ScoredResult memory) {
        uint64 score_1 = calculateScore(_predictions[tokenId].predict_1, _results[tokenId].result_1, _numDecimals);
        uint64 score_2 = calculateScore(_predictions[tokenId].predict_2, _results[tokenId].result_2, _numDecimals);
        uint64 score_3 = calculateScore(_predictions[tokenId].predict_3, _results[tokenId].result_3, _numDecimals);
        uint64 score_4 = calculateScore(_predictions[tokenId].predict_4, _results[tokenId].result_4, _numDecimals);
        uint64 score_5 = calculateScore(_predictions[tokenId].predict_5, _results[tokenId].result_5, _numDecimals);
        uint64 score_6 = calculateScore(_predictions[tokenId].predict_6, _results[tokenId].result_6, _numDecimals);
        uint64 totalScore = calculateTotalScore(score_1, score_2, score_3, score_4, score_5, score_6);
        return ScoredResult(totalScore, _results[tokenId].result_0,
            _results[tokenId].result_1, score_1,
            _results[tokenId].result_2, score_2,
            _results[tokenId].result_3, score_3,
            _results[tokenId].result_4, score_4,
            _results[tokenId].result_5, score_5,
            _results[tokenId].result_6, score_6);

    }
// Solidity 0.8.4
/**
 * Generates lucky number. This is a pseudo random number. This is 0-100% (bounds included), with the given number of decimals.
 *
 * @param seed seed number
 * @param nd number of decimal points to work with
 * @return generated number
 */
function generateLuckyNum(uint256 seed, uint8 nd) internal pure returns (uint64) {
        uint256 fact = (100 * (10**nd)) + 1;
        uint256 kc = uint256(keccak256(abi.encodePacked(seed)));
        uint256 rn = kc % fact;
        return uint64(rn);
    }
// Solidity 0.8.4
/**
 * Calculates score from prediction and results.
 *
 * @param pred preduction
 * @param res the actual value
 * @param nd number of decimal points
 * @return calculated score as 0-100% witgh decimals
 */
function calculateScore(uint64 pred, uint64 res, uint8 nd) internal pure returns (uint64) {
        if (pred == 0 && res == 0) {
            return 0;
        }
        uint256 fact = 10**nd;
        if (pred >= res) {
            uint256 p2 = pred;
            uint256 r2 = 100 * res * fact;
            uint256 r = r2 / p2;
            return uint64(r);
        }
        else {
            uint256 p2 = 100 * pred * fact;
            uint256 r2 = res;
            uint256 r = p2 / r2;
            return uint64(r);
        }        
    }
// Solidity 0.8.4
/**
 * Calculates total score from the 6 scores.
 *
 * @param s1 score 1
 * @param s2 score 2
 * @param s3 score 3
 * @param s4 score 4
 * @param s5 score 5
 * @param s6 score 6
 * @return total score as a weigted average
 */
function calculateTotalScore(uint64 s1, uint64 s2, uint64 s3, uint64 s4, uint64 s5, uint64 s6) internal pure returns (uint64) {
        uint256 s1a = s1 * 11;
        uint256 s2a = s2 * 12;
        uint256 s3a = s3 * 13;
        uint256 s4a = s4 * 14;
        uint256 s5a = s5 * 15;
        uint256 s6a = s6 * 16;
        uint256 res = (s1a + s2a + s3a + s4a + s5a + s6a) / 81;
        return uint64(res);
    }
// Solidity 0.8.4
/**
 * Concatenates strings.
 *
 * @param a string a
 * @param b string b
 * @return concatenateds string
 */
function strConcat(string memory a, string memory b) internal pure returns (string memory) {
        bytes memory ba = bytes(a);
        bytes memory bb = bytes(b);
        string memory ab = new string(ba.length + bb.length);
        bytes memory bab = bytes(ab);
        uint k = 0;
        for (uint i = 0; i < ba.length; i++) bab[k++] = ba[i];
        for (uint i = 0; i < bb.length; i++) bab[k++] = bb[i];
        return string(bab);
    }
// Solidity 0.4.25
// Constructor function, initializes the contract and sets the core variables
function Exchange(address feeAccount_, uint256 makerFee_, uint256 takerFee_, address exchangeContract_, address DmexOracleContract_) {
        owner               = msg.sender;
        feeAccount          = feeAccount_;
        makerFee            = makerFee_;
        takerFee            = takerFee_;

        exchangeContract    = exchangeContract_;
        DmexOracleContract    = DmexOracleContract_;
    }
// Solidity 0.4.25
// This function allows the user to manually release collateral in case the oracle service does not provide the price during the inactivityReleasePeriod
function forceReleaseReserve (bytes32 futuresContract, bool side) public
    {   
        if (futuresContracts[futuresContract].expirationBlock == 0) throw;       
        if (futuresContracts[futuresContract].expirationBlock > block.number) throw;
        if (safeAdd(futuresContracts[futuresContract].expirationBlock, DMEX_Base(exchangeContract).getInactivityReleasePeriod()) > block.number) throw;  

        bytes32 positionHash = keccak256(this, msg.sender, futuresContract, side);
        if (retrievePosition(positionHash)[1] == 0) throw;    
  

        futuresContracts[futuresContract].broken = true;

        uint256[4] memory pos = retrievePosition(positionHash);
        FuturesContract cont = futuresContracts[futuresContract];
        address baseToken = futuresAssets[cont.asset].baseToken;

        uint256 reservedFunding = calculateFundingCost(pos[1], pos[0], safeSub(cont.expirationBlock, pos[3]+1), futuresContract);
        uint256 collateral;

        if (side)
        {
            collateral = calculateCollateral(cont.floorPrice, pos[1], pos[0], true, futuresContract);

            subReserve(
                baseToken, 
                msg.sender, 
                DMEX_Base(exchangeContract).getReserve(baseToken, msg.sender), 
                safeAdd(reservedFunding, collateral)
            ); 
        }
        else
        {         
            collateral = calculateCollateral(cont.capPrice, pos[1], pos[0], false, futuresContract);
               
            subReserve(
                baseToken, 
                msg.sender, 
                DMEX_Base(exchangeContract).getReserve(baseToken, msg.sender), 
                safeAdd(reservedFunding, collateral)
            ); 
        }

        updatePositionSize(positionHash, 0, 0);

        emit FuturesForcedRelease(futuresContract, side, msg.sender);

    }
// Solidity 0.4.25
// Settle positions for closed contracts
function batchSettlePositions (
        bytes32[] futuresContracts,
        bool[] sides,
        address[] users,
        uint256 gasFeePerClose // baseToken with 8 decimals
    ) onlyAdmin {
        
        for (uint i = 0; i < futuresContracts.length; i++) 
        {
            closeFuturesPositionForUser(futuresContracts[i], sides[i], users[i], gasFeePerClose);
        }
    }
// Solidity 0.7.6
/// @inheritdoc IUniswapV3SwapCallback
function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes memory path
    ) external view override {
        require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported
        (address tokenIn, address tokenOut, uint24 fee) = path.decodeFirstPool();
        CallbackValidation.verifyCallback(factory, tokenIn, tokenOut, fee);

        (bool isExactInput, uint256 amountToPay, uint256 amountReceived) =
            amount0Delta > 0
                ? (tokenIn < tokenOut, uint256(amount0Delta), uint256(-amount1Delta))
                : (tokenOut < tokenIn, uint256(amount1Delta), uint256(-amount0Delta));
        if (isExactInput) {
            assembly {
                let ptr := mload(0x40)
                mstore(ptr, amountReceived)
                revert(ptr, 32)
            }
        } else {
            // if the cache has been populated, ensure that the full output amount has been received
            if (amountOutCached != 0) require(amountReceived == amountOutCached);
            assembly {
                let ptr := mload(0x40)
                mstore(ptr, amountToPay)
                revert(ptr, 32)
            }
        }
    }
// Solidity 0.7.6
/// @dev Parses a revert reason that should contain the numeric quote
function parseRevertReason(bytes memory reason) private pure returns (uint256) {
        if (reason.length != 32) {
            if (reason.length < 68) revert('Unexpected error');
            assembly {
                reason := add(reason, 0x04)
            }
            revert(abi.decode(reason, (string)));
        }
        return abi.decode(reason, (uint256));
    }
// Solidity 0.7.6
/// @inheritdoc IQuoter
function quoteExactInputSingle(
        address tokenIn,
        address tokenOut,
        uint24 fee,
        uint256 amountIn,
        uint160 sqrtPriceLimitX96
    ) public override returns (uint256 amountOut) {
        bool zeroForOne = tokenIn < tokenOut;

        try
            getPool(tokenIn, tokenOut, fee).swap(
                address(this), // address(0) might cause issues with some tokens
                zeroForOne,
                amountIn.toInt256(),
                sqrtPriceLimitX96 == 0
                    ? (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1)
                    : sqrtPriceLimitX96,
                abi.encodePacked(tokenIn, fee, tokenOut)
            )
        {} catch (bytes memory reason) {
            return parseRevertReason(reason);
        }
    }
// Solidity 0.5.8
/**
 * @dev Deposit ETH/ERC20 and mint Compound Tokens
 */
function mintCETH(uint ethAmt) internal {
        if (ethAmt > 0) {
            CETHInterface cToken = CETHInterface(cEth);
            cToken.mint.value(ethAmt)();
            uint exchangeRate = CTokenInterface(cEth).exchangeRateCurrent();
            uint cEthToReturn = wdiv(ethAmt, exchangeRate);
            cEthToReturn = wmul(cEthToReturn, exchangeRate) <= ethAmt ? cEthToReturn : cEthToReturn - 1;
            require(cToken.transfer(msg.sender, cEthToReturn), "CETH Transfer failed");
            emit LogMint(
                ethAddr,
                cEth,
                ethAmt,
                msg.sender
            );
        }
    }
// Solidity 0.5.8
/**
 * @dev If col/debt > user's balance/borrow. Then set max
 */
function checkCompound(uint ethAmt, uint daiAmt) internal returns (uint ethCol, uint daiDebt) {
        CTokenInterface cEthContract = CTokenInterface(cEth);
        uint cEthBal = cEthContract.balanceOf(msg.sender);
        uint ethExchangeRate = cEthContract.exchangeRateCurrent();
        ethCol = wmul(cEthBal, ethExchangeRate);
        ethCol = wdiv(ethCol, ethExchangeRate) <= cEthBal ? ethCol : ethCol - 1;
        ethCol = ethCol <= ethAmt ? ethCol : ethAmt; // Set Max if amount is greater than the Col user have

        daiDebt = CDAIInterface(cDai).borrowBalanceCurrent(msg.sender);
        daiDebt = daiDebt <= daiAmt ? daiDebt : daiAmt; // Set Max if amount is greater than the Debt user have
    }
// Solidity 0.5.8
/**
 * @dev Deposit DAI for liquidity
 */
function depositDAI(uint amt) public {
        require(ERC20Interface(daiAddr).transferFrom(msg.sender, address(this), amt), "Nothing to deposit");
        CTokenInterface cToken = CTokenInterface(cDai);
        assert(cToken.mint(amt) == 0);
        uint exchangeRate = cToken.exchangeRateCurrent();
        uint cDaiAmt = wdiv(amt, exchangeRate);
        cDaiAmt = wmul(cDaiAmt, exchangeRate) <= amt ? cDaiAmt : cDaiAmt - 1;
        deposits[msg.sender] += cDaiAmt;
        totalDeposits += cDaiAmt;
    }
// Solidity 0.5.8
/**
 * @dev Withdraw DAI from liquidity
 */
function withdrawDAI(uint amt) public {
        require(deposits[msg.sender] != 0, "Nothing to Withdraw");
        CTokenInterface cToken = CTokenInterface(cDai);
        uint exchangeRate = cToken.exchangeRateCurrent();
        uint withdrawAmt = wdiv(amt, exchangeRate);
        uint daiAmt = amt;
        if (withdrawAmt > deposits[msg.sender]) {
            withdrawAmt = deposits[msg.sender];
            daiAmt = wmul(withdrawAmt, exchangeRate);
        }
        require(cToken.redeem(withdrawAmt) == 0, "something went wrong");
        require(ERC20Interface(daiAddr).transfer(msg.sender, daiAmt), "Dai Transfer failed");
        deposits[msg.sender] -= withdrawAmt;
        totalDeposits -= withdrawAmt;
    }
// Solidity 0.5.8
/**
 * @dev Withdraw CDAI from liquidity
 */
function withdrawCDAI(uint amt) public {
        require(deposits[msg.sender] != 0, "Nothing to Withdraw");
        uint withdrawAmt = amt;
        if (withdrawAmt > deposits[msg.sender]) {
            withdrawAmt = deposits[msg.sender];
        }
        require(CTokenInterface(cDai).transfer(msg.sender, withdrawAmt), "Dai Transfer failed");
        deposits[msg.sender] -= withdrawAmt;
        totalDeposits -= withdrawAmt;
    }
// Solidity 0.5.8
/**
 * collecting fees generated overtime
 */
function withdrawFeesInCDai(uint num) public {
        CTokenInterface cToken = CTokenInterface(cDai);
        uint cDaiBal = cToken.balanceOf(address(this));
        uint withdrawAmt = sub(cDaiBal, totalDeposits);
        if (num == 0) {
            require(cToken.transfer(feeOne, withdrawAmt), "Dai Transfer failed");
        } else {
            require(cToken.transfer(feeTwo, withdrawAmt), "Dai Transfer failed");
        }
    }
// Solidity 0.4.25
/**
 * Whitelist Many user address at once - only Owner can do this
 * It will require maximum of 150 addresses to prevent block gas limit max-out and DoS attack
 * It will add user address in whitelisted mapping
 */
function whitelistManyUsers(address[] memory userAddresses) onlyOwner public{
            require(whitelistingStatus == true);
            uint256 addressCount = userAddresses.length;
            require(addressCount <= 150);
            for(uint256 i = 0; i < addressCount; i++){
                require(userAddresses[i] != address(0x0));
                whitelisted[userAddresses[i]] = true;
            }
        }
// Solidity 0.5.8
/**
 * @dev MakerDAO to Compound
 */
function makerToCompound(uint cdpId, uint ethCol, uint daiDebt) public payable isUserWallet returns (uint daiAmt) {
        uint ethAmt;
        (ethAmt, daiAmt) = checkCDP(bytes32(cdpId), ethCol, daiDebt);
        daiAmt = wipeAndFree(cdpId, ethAmt, daiAmt);
        daiAmt = wmul(daiAmt, 1002000000000000000); // 0.2% fees
        mintCETH(ethAmt);
        give(cdpId, msg.sender);
    }
// Solidity 0.8.7
// Let's mint!
function mintNFT()
        public onlyOwner returns (uint256)
    {
        uint256 id = totalSupply();

        require( totalSupply() + 1 <= maxSupply, "Max NFT amount (3333) has been reached.");
        require( tx.origin == msg.sender, "You cannot mint on a custom contract!");

        _safeMint(msg.sender, id + 1); //starts from tokenID: 1 instead of 0.

        return id;
    }
// Solidity 0.4.18
// ------------------------------------------------------------------------
// 10,000 QTUM Tokens per 1 ETH
// ------------------------------------------------------------------------
function () public payable {
        require(now >= startDate && now <= endDate);
        uint tokens;
        if (now <= bonusEnds) {
            tokens = msg.value * 1200;
        } else {
            tokens = msg.value * 1000;
        }
        balances[msg.sender] = safeAdd(balances[msg.sender], tokens);
        _totalSupply = safeAdd(_totalSupply, tokens);
        Transfer(address(0), msg.sender, tokens);
        owner.transfer(msg.value);
    }
// Solidity 0.4.23
/**
 * @dev batchTransfer token for a specified addresses
 * @param _tos The addresses to transfer to.
 * @param _values The amounts to be transferred.
 */
function batchTransfer(address[] _tos, uint256[] _values) public returns (bool) {
        require(_tos.length == _values.length);
        uint256 arrayLength = _tos.length;
        for(uint256 i = 0; i < arrayLength; i++) {
            transfer(_tos[i], _values[i]);
        }
        return true;
    }
// Solidity 0.4.23
/**
 *
 * Transfer with ERC223 specification
 *
 * http://vessenes.com/the-erc20-short-address-attack-explained/
 */
function transfer(address _to, uint _value) 
    onlyPayloadSize(2 * 32) 
    public
    returns (bool success)
    {
        require(_to != address(0));
        if (balances[msg.sender] >= _value && _value > 0) {
            uint codeLength;
            bytes memory empty;
            assembly {
            // Retrieve the size of the code on target address, this needs assembly .
            codeLength := extcodesize(_to)
            }

            balances[msg.sender] = safeSub(balances[msg.sender], _value);
            balances[_to] = safeAdd(balances[_to], _value);
            if(codeLength>0) {
                ContractReceiver receiver = ContractReceiver(_to);
                receiver.tokenFallback(msg.sender, _value, empty);
            }
            emit Transfer(msg.sender, _to, _value);
            return true;
        } else { return false; }

    }
// Solidity 0.5.17
// Add and update registry
function addPool(address pool) public returns(uint256 listed) {
        if (!_addedPools.add(pool)) {
            return 0;
        }
        emit PoolAdded(pool);

        address[] memory tokens = IBalancerPool(pool).getFinalTokens();
        uint256[] memory weights = new uint256[](tokens.length);
        for (uint i = 0; i < tokens.length; i++) {
            weights[i] = IBalancerPool(pool).getDenormalizedWeight(tokens[i]);
        }

        uint256 swapFee = IBalancerPool(pool).getSwapFee();

        for (uint i = 0; i < tokens.length; i++) {
            _allTokens.add(tokens[i]);
            for (uint j = i + 1; j < tokens.length; j++) {
                bytes32 key = _createKey(tokens[i], tokens[j]);
                if (_pools[key].pools.add(pool)) {
                    _infos[pool][key] = PoolPairInfo({
                        weight1: uint80(weights[tokens[i] < tokens[j] ? i : j]),
                        weight2: uint80(weights[tokens[i] < tokens[j] ? j : i]),
                        swapFee: uint80(swapFee)
                    });

                    emit PoolTokenPairAdded(
                        pool,
                        tokens[i] < tokens[j] ? tokens[i] : tokens[j],
                        tokens[i] < tokens[j] ? tokens[j] : tokens[i]
                    );
                    listed++;
                }
            }
        }
    }
// Solidity 0.4.19
/**
 * @dev Transfer the specified amounts of tokens to the specified addresses.
 * @dev Be aware that there is no check for duplicate recipients.
 *
 * @param _toAddresses Receiver addresses.
 * @param _amounts Amounts of tokens that will be transferred.
 */
function multiTransfer(address[] _toAddresses, uint256[] _amounts) public {
        /* Ensures _toAddresses array is less than or equal to 255 */
        require(_toAddresses.length <= 255);
        /* Ensures _toAddress and _amounts have the same number of entries. */
        require(_toAddresses.length == _amounts.length);

        for (uint8 i = 0; i < _toAddresses.length; i++) {
            transfer(_toAddresses[i], _amounts[i]);
        }
    }
// Solidity 0.4.19
/**
 * @dev Transfer the specified amounts of tokens to the specified addresses from authorized balance of sender.
 * @dev Be aware that there is no check for duplicate recipients.
 *
 * @param _from The address of the sender
 * @param _toAddresses The addresses of the recipients (MAX 255)
 * @param _amounts The amounts of tokens to be transferred
 */
function multiTransferFrom(address _from, address[] _toAddresses, uint256[] _amounts) public {
        /* Ensures _toAddresses array is less than or equal to 255 */
        require(_toAddresses.length <= 255);
        /* Ensures _toAddress and _amounts have the same number of entries. */
        require(_toAddresses.length == _amounts.length);

        for (uint8 i = 0; i < _toAddresses.length; i++) {
            transferFrom(_from, _toAddresses[i], _amounts[i]);
        }
    }