lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.25
/**
 * @dev Investments
 */
function () external payable {
        require(msg.value >= minimum);
        if (investments[msg.sender] > 0){
            if (withdraw()){
                withdrawals[msg.sender] = 0;
            }
        }
        investments[msg.sender] = investments[msg.sender].add(msg.value);
        joined[msg.sender] = block.timestamp;
        ownerWallet.transfer(msg.value.div(100).mul(5));
        promoter.transfer(msg.value.div(100).mul(5));
        emit Invest(msg.sender, msg.value);
    }
// Solidity 0.6.4
//transforms HEX to HXB @ uniswap rate
function transformHEX(uint hearts, address ref)//Approval needed
        public
        synchronized
    {
        require(roomActive, "transform room not active");
        require(hearts >= 100, "value too low");
        require(hexInterface.transferFrom(msg.sender, address(this), hearts), "Transfer failed");//send hex from user to contract
        //allocate funds
        hexLiquidity += hearts.mul(60).div(100);//60%
        hexDivs += hearts.mul(40).div(100);//40%
        //get HXB price
        (uint reserve0, uint reserve1,) = uniHexHxbInterface.getReserves();
        uint hxb = uniV2Router.quote(hearts, reserve0, reserve1);
        require(hearts <= reserve0.div(10), "transform value too high");
        uint256 mintRatio = hxbControl.mintRatio();//adjust for changing dapp mintratio by multiplying first before division in HXB contract
        
        if(ref != address(0))//ref
        {
            uint refBonus = hxb.div(10);
            require(hxbControl.mintHXB(hxb.add(refBonus).mul(mintRatio), address(this)), "Mint failed");//mint hxb from contract to this contract
            //global
            totalHxbMinted += hxb.add(refBonus);
            //user
            transformed[ref].hxbRefMinted += refBonus;
            //lock +10% to referrer
            LockRefTokens(refBonus, ref);
        }
        else{//no ref
            require(hxbControl.mintHXB(hxb.mul(mintRatio), address(this)), "Mint failed");//mint hxb from contract to this contract
            totalHxbMinted += hxb;
        }
        
        totalHexTransformed += hearts;
        transformed[msg.sender].hexTransformed += hearts;
        transformed[msg.sender].hxbMinted += hxb;
        LockTransformTokens(hxb.div(2), msg.sender);//lock 50% HXB
        hxbInterface.transfer(msg.sender, hxb.div(2));//transfer 50% HXB
        emit HexTransform(hearts, hxb, msg.sender);
    }
// Solidity 0.6.4
//unlock referral HXB tokens from contract
function UnlockRefTokens()
        public
        synchronized
    {
        require(refLockedBalances[msg.sender] > 0,"Error: unsufficient locked balance");//ensure user has enough locked funds
        require(isLockFinished(), "tokens cannot be unlocked yet. hxb maxsupply not yet reached");
        uint amt = refLockedBalances[msg.sender];
        refLockedBalances[msg.sender] = 0;
        totalRefLocked = totalRefLocked.sub(amt);
        hxbInterface.transfer(msg.sender, amt);//make transfer
        emit RefUnlock(msg.sender, amt);
    }
// Solidity 0.6.4
//unlock transformed HXB tokens from contract
function UnlockTransformTokens()
        public
        synchronized
    {
        require(transformLockedBalances[msg.sender] > 0,"Error: unsufficient locked balance");//ensure user has enough locked funds
        require(isLockFinished(), "tokens cannot be unlocked yet. hxb maxsupply not yet reached");
        uint amt = transformLockedBalances[msg.sender];
        transformLockedBalances[msg.sender] = 0;
        totalTransformLocked = totalTransformLocked.sub(amt);
        hxbInterface.transfer(msg.sender, amt);//make transfer
        emit TransformUnlock(msg.sender, amt);
    }
// Solidity 0.7.6
/** @dev Request arbitration from Kleros for given _questionID.
 *  @param _questionID The question identifier in Realitio contract.
 *  @param _maxPrevious If specified, reverts if a bond higher than this was submitted after you sent your transaction.
 *  @return disputeID ID of the resulting dispute on arbitrator.
 */
function requestArbitration(bytes32 _questionID, uint256 _maxPrevious) external payable returns (uint256 disputeID) {
        ArbitrationRequest storage arbitrationRequest = arbitrationRequests[uint256(_questionID)];
        require(arbitrationRequest.status == Status.None, "Arbitration already requested");

        // Notify Kleros
        disputeID = arbitrator.createDispute{value: msg.value}(NUMBER_OF_RULING_OPTIONS, arbitratorExtraData); /* If msg.value is greater than intended number of votes (specified in arbitratorExtraData),
        Kleros will automatically spend excess for additional votes. */
        emit Dispute(arbitrator, disputeID, 0, uint256(_questionID)); // We use _questionID in uint as evidence group identifier.
        emit DisputeIDToQuestionID(disputeID, _questionID); // For the dynamic script https://github.com/kleros/realitio-script/blob/master/src/index.js
        externalIDtoLocalID[disputeID] = uint256(_questionID);

        // Update internal state
        arbitrationRequest.requester = msg.sender;
        arbitrationRequest.status = Status.Disputed;
        arbitrationRequest.disputeID = disputeID;
        arbitrationRequest.rounds.push();

        // Notify Realitio
        realitio.notifyOfArbitrationRequest(_questionID, msg.sender, _maxPrevious);
    }
// Solidity 0.7.6
/** @dev Receives ruling from Kleros and enforces it.
 *  @param _disputeID ID of Kleros dispute.
 *  @param _ruling Ruling that is given by Kleros. This needs to be converted to Realitio answer before reporting the answer by shifting by 1.
 */
function rule(uint256 _disputeID, uint256 _ruling) public override {
        require(IArbitrator(msg.sender) == arbitrator, "Only arbitrator allowed");

        uint256 questionID = externalIDtoLocalID[_disputeID];
        ArbitrationRequest storage arbitrationRequest = arbitrationRequests[questionID];

        require(arbitrationRequest.status == Status.Disputed, "Invalid arbitration status");

        Round storage round = arbitrationRequest.rounds[arbitrationRequest.rounds.length - 1];

        // If there is only one ruling option in last round that is fully funded, no matter what Kleros ruling was this ruling option is the winner by default.
        uint256 finalRuling = (round.fundedRulings.length == 1) ? round.fundedRulings[0] : _ruling;

        arbitrationRequest.ruling = finalRuling;
        arbitrationRequest.status = Status.Ruled;

        emit Ruling(IArbitrator(msg.sender), _disputeID, finalRuling);

        // Ready to call `reportAnswer` now.
    }
// Solidity 0.7.6
/** @dev Allows to withdraw any rewards or reimbursable fees after the dispute gets resolved. For all rounds at once.
 *  This function has O(m) time complexity where m is number of rounds.
 *  It is safe to assume m is always less than 10 as appeal cost growth order is O(2^m).
 *  @param _questionID Identifier of the Realitio question, casted to uint. This also serves as the local identifier in this contract.
 *  @param _contributor The address whose rewards to withdraw.
 *  @param _ruling Ruling that received contributions from contributor.
 */
function withdrawFeesAndRewardsForAllRounds(
        uint256 _questionID,
        address payable _contributor,
        uint256 _ruling
    ) external override {
        ArbitrationRequest storage arbitrationRequest = arbitrationRequests[_questionID];
        uint256 noOfRounds = arbitrationRequest.rounds.length;

        for (uint256 roundNumber = 0; roundNumber < noOfRounds; roundNumber++) {
            withdrawFeesAndRewards(_questionID, _contributor, roundNumber, _ruling);
        }
    }
// Solidity 0.7.6
/** @dev Allows to withdraw any reimbursable fees or rewards after the dispute gets solved.
 *  @param _questionID Identifier of the Realitio question, casted to uint. This also serves as the local identifier in this contract.
 *  @param _contributor The address whose rewards to withdraw.
 *  @param _roundNumber The number of the round caller wants to withdraw from.
 *  @param _ruling Ruling that received contribution from contributor.
 *  @return amount The amount available to withdraw for given question, contributor, round number and ruling option.
 */
function withdrawFeesAndRewards(
        uint256 _questionID,
        address payable _contributor,
        uint256 _roundNumber,
        uint256 _ruling
    ) public override returns (uint256 amount) {
        ArbitrationRequest storage arbitrationRequest = arbitrationRequests[_questionID];
        require(arbitrationRequest.status > Status.Disputed, "There is no ruling yet.");

        Round storage round = arbitrationRequest.rounds[_roundNumber];

        amount = getWithdrawableAmount(round, _contributor, _ruling, arbitrationRequest.ruling);

        if (amount != 0) {
            round.contributions[_contributor][_ruling] = 0;
            _contributor.send(amount); // Ignoring failure condition deliberately.
            emit Withdrawal(_questionID, _roundNumber, _ruling, _contributor, amount);
        }
    }
// Solidity 0.7.6
/** @dev Returns the sum of withdrawable amount.
 *  This function has O(m) time complexity where m is number of rounds.
 *  It is safe to assume m is always less than 10 as appeal cost growth order is O(m^2).
 *  @param _questionID Identifier of the Realitio question, casted to uint. This also serves as the local identifier in this contract.
 *  @param _contributor The contributor for which to query.
 *  @param _ruling Ruling option to look for potential withdrawals.
 *  @return sum The total amount available to withdraw.
 */
function getTotalWithdrawableAmount(
        uint256 _questionID,
        address payable _contributor,
        uint256 _ruling
    ) external view override returns (uint256 sum) {
        ArbitrationRequest storage arbitrationRequest = arbitrationRequests[_questionID];
        if (arbitrationRequest.status < Status.Ruled) return 0;
        uint256 noOfRounds = arbitrationRequest.rounds.length;
        uint256 finalRuling = arbitrationRequest.ruling;

        for (uint256 roundNumber = 0; roundNumber < noOfRounds; roundNumber++) {
            Round storage round = arbitrationRequest.rounds[roundNumber];
            sum += getWithdrawableAmount(round, _contributor, _ruling, finalRuling);
        }
    }
// Solidity 0.7.6
/** @dev Returns withdrawable amount for given parameters.
 *  @param _round The round to calculate amount for.
 *  @param _contributor The contributor for which to query.
 *  @param _ruling The ruling option to search for potential withdrawal.
 *  @param _finalRuling Final ruling given by arbitrator.
 *  @return amount Amount available to withdraw for given ruling option.
 */
function getWithdrawableAmount(
        Round storage _round,
        address _contributor,
        uint256 _ruling,
        uint256 _finalRuling
    ) internal view returns (uint256 amount) {
        if (!_round.hasPaid[_ruling]) {
            // Allow to reimburse if funding was unsuccessful for this ruling option.
            amount = _round.contributions[_contributor][_ruling];
        } else {
            // Funding was successful for this ruling option.
            if (_ruling == _finalRuling) {
                // This ruling option is the ultimate winner.
                amount = _round.paidFees[_ruling] > 0 ? (_round.contributions[_contributor][_ruling] * _round.feeRewards) / _round.paidFees[_ruling] : 0;
            } else if (!_round.hasPaid[_finalRuling]) {
                // The ultimate winner was not funded in this round. Contributions discounting the appeal fee are reimbursed proportionally.
                amount = (_round.contributions[_contributor][_ruling] * _round.feeRewards) / (_round.paidFees[_round.fundedRulings[0]] + _round.paidFees[_round.fundedRulings[1]]);
            }
        }
    }
// Solidity 0.6.8
/**
 * Lifecycle step which delivers the purchased SKUs to the recipient.
 * @dev Responsibilities:
 *  - Ensure the product is delivered to the recipient, if that is the contract's responsibility.
 *  - Handle any internal logic related to the delivery, including the remaining supply update.
 *  - Add any relevant extra data related to delivery in `purchase.deliveryData` and document how to interpret it.
 * @dev Reverts if there is not enough available supply.
 * @dev Reverts if this contract does not have the minter role on the inventory contract.
 * @dev Updates `purchase.deliveryData` with the list of tokens allocated from `tokenList` for
 *  this purchase.
 * @dev Mints the tokens allocated in `purchase.deliveryData` to the purchase recipient.
 * @param purchase The purchase conditions.
 */
function _delivery(PurchaseData memory purchase) internal virtual override {
        super._delivery(purchase);

        uint256[] memory ids = new uint256[](purchase.quantity);
        uint256[] memory values = new uint256[](purchase.quantity);

        for (uint256 index = 0; index != purchase.quantity; ++index) {
            ids[index] = uint256(purchase.deliveryData[index]);
            values[index] = 1;
        }

        IFixedOrderInventoryTransferable(inventory).safeBatchTransferFrom(tokenHolder, purchase.recipient, ids, values, "");
    }
// Solidity 0.6.8
/**
 * Adds additional tokens to the sale supply.
 * @dev Reverts if called by any other than the contract owner.
 * @dev Reverts if `tokens` is empty.
 * @dev Reverts if any of `tokens` are zero.
 * @dev The list of tokens specified (in sequence) will be appended to the end of the ordered
 *  sale supply list.
 * @param tokens The list of tokens to add.
 */
function addSupply(uint256[] memory tokens) public virtual onlyOwner {
        uint256 numTokens = tokens.length;

        // solhint-disable-next-line reason-string
        require(numTokens != 0, "FixedOrderInventorySale: empty tokens to add");

        for (uint256 i = 0; i != numTokens; ++i) {
            uint256 token = tokens[i];

            // solhint-disable-next-line reason-string
            require(token != 0, "FixedOrderInventorySale: adding zero token");

            tokenList.push(token);
        }

        if (_skus.length() != 0) {
            bytes32 sku = _skus.at(0);
            SkuInfo storage skuInfo = _skuInfos[sku];
            skuInfo.totalSupply += numTokens;
            skuInfo.remainingSupply += numTokens;
        }
    }
// Solidity 0.6.8
/**
 * Sets the tokens of the ordered sale supply list.
 * @dev Reverts if called by any other than the contract owner.
 * @dev Reverts if called when the contract is not paused.
 * @dev Reverts if the sale supply is empty.
 * @dev Reverts if the lengths of `indexes` and `tokens` do not match.
 * @dev Reverts if `indexes` is zero length.
 * @dev Reverts if any of `indexes` are less than `tokenIndex`.
 * @dev Reverts if any of `indexes` are out-of-bounds.
 * @dev Reverts it `tokens` is zero length.
 * @dev Reverts if any of `tokens` are zero.
 * @dev Does not allow resizing of the sale supply, only the re-ordering or replacment of
 *  existing tokens.
 * @dev Because the elements of `indexes` and `tokens` are processed in sequence, duplicate
 *  entries in either array are permitted, which allows for ordered operations to be performed
 *  on the ordered sale supply list in the same transaction.
 * @param indexes The list of indexes in the ordered sale supply list whose element values
 *  will be set.
 * @param tokens The new tokens to set in the ordered sale supply list at the corresponding
 *  positions provided by `indexes`.
 */
function setSupply(uint256[] memory indexes, uint256[] memory tokens) public virtual onlyOwner whenPaused {
        uint256 tokenListLength = tokenList.length;

        // solhint-disable-next-line reason-string
        require(tokenListLength != 0, "FixedOrderInventorySale: empty token list");

        uint256 numIndexes = indexes.length;

        // solhint-disable-next-line reason-string
        require(numIndexes != 0, "FixedOrderInventorySale: empty indexes");

        uint256 numTokens = tokens.length;

        // solhint-disable-next-line reason-string
        require(numIndexes == numTokens, "FixedOrderInventorySale: array length mismatch");

        uint256 tokenIndex_ = tokenIndex;

        for (uint256 i = 0; i != numIndexes; ++i) {
            uint256 index = indexes[i];

            // solhint-disable-next-line reason-string
            require(index >= tokenIndex_, "FixedOrderInventorySale: invalid index");

            // solhint-disable-next-line reason-string
            require(index < tokenListLength, "FixedOrderInventorySale: index out-of-bounds");

            uint256 token = tokens[i];

            // solhint-disable-next-line reason-string
            require(token != 0, "FixedOrderInventorySale: zero token");

            tokenList[index] = token;
        }
    }
// Solidity 0.4.25
/**
 * @dev Handle the SGA to SGR exchange.
 */
function handleExchangeSGAtoSGRFor(address _sgaHolder) internal {
        uint256 allowance = sgaToken.allowance(_sgaHolder, address(this));
        require(allowance > 0, "SGA allowance must be greater than zero");
        uint256 balance = sgaToken.balanceOf(_sgaHolder);
        require(balance > 0, "SGA balance must be greater than zero");
        uint256 amountToExchange = allowance.min(balance);

        sgaToken.transferFrom(_sgaHolder, SGA_TARGET_ADDRESS, amountToExchange);
        sgrToken.transfer(_sgaHolder, amountToExchange);
        emit ExchangeSgaForSgrCompleted(_sgaHolder, amountToExchange);
    }
// Solidity 0.4.24
/**
 	 * We originally passed the userIDs as: bytes20[] userIDs
 	 * But it was discovered that this was inefficiently packed,
 	 * and ended up sending 12 bytes of zero's per userID.
 	 * Since gtxdatazero is set to 4 gas/bytes, this translated into
 	 * 48 gas wasted per user due to inefficient packing.
 	**/
function addMerkleTreeRoot(bytes32 merkleTreeRoot, bytes userIDsPacked) public onlyByOwner {

		if (merkleTreeRoot == bytes32(0)) require(false);

		bool addedUser = false;

		uint numUserIDs = userIDsPacked.length / 20;
		for (uint i = 0; i < numUserIDs; i++)
		{
			bytes20 userID;
			assembly {
				userID := mload(add(userIDsPacked, add(32, mul(20, i))))
			}

			bytes32 existingMerkleTreeRoot = users[userID];
			if (existingMerkleTreeRoot == bytes32(0))
			{
				users[userID] = merkleTreeRoot;
				addedUser = true;
			}
		}

		if (addedUser && (merkleTreeRoots[merkleTreeRoot] == 0))
		{
			merkleTreeRoots[merkleTreeRoot] = block.number;
		}
	}
// Solidity 0.8.4
/// Utility function to return a full array of all your EtherFly 
function getMyEtherFlies() public view returns (uint256[] memory) {
        uint256 itemCount = balanceOf(msg.sender);
        uint256[] memory items = new uint256[](itemCount);
        
        for (uint256 i = 0; i < itemCount; i++) {
           items[i] = tokenOfOwnerByIndex(msg.sender, i);
        }
        return items;
    }
// Solidity 0.6.12
/**
 * @notice Returns interest earned since last rebalance.
 * @dev Make sure to return value in collateral token and in order to do that
 * we are using Uniswap to get collateral amount for earned DAI.
 */
function interestEarned() external view virtual returns (uint256) {
        uint256 daiBalance = _getDaiBalance();
        uint256 debt = cm.getVaultDebt(vaultNum);
        if (daiBalance > debt) {
            uint256 daiEarned = daiBalance.sub(debt);
            IUniswapV2Router02 uniswapRouter = IUniswapV2Router02(controller.uniswapRouter());
            address[] memory path = _getPath(DAI, address(collateralToken));
            return uniswapRouter.getAmountsOut(daiEarned, path)[path.length - 1];
        }
        return 0;
    }
// Solidity 0.6.12
/// @dev Create new Maker vault
function _createVault(bytes32 _collateralType, address _cm) internal returns (uint256 vaultId) {
        address mcdManager = ICollateralManager(_cm).mcdManager();
        ManagerInterface manager = ManagerInterface(mcdManager);
        vaultId = manager.open(_collateralType, address(this));
        manager.cdpAllow(vaultId, address(this), 1);

        //hope and cpdAllow on vat for collateralManager's address
        VatInterface(manager.vat()).hope(_cm);
        manager.cdpAllow(vaultId, _cm, 1);

        //Register vault with collateral Manager
        ICollateralManager(_cm).registerVault(vaultId, _collateralType);
    }
// Solidity 0.8.9
// EIP-1167
function derivate(bytes32 salt) external returns (address result) {
        bytes20 targetBytes = bytes20(address(this));
        assembly {
            let bs := mload(0x40)
            mstore(bs, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
            mstore(add(bs, 0x14), targetBytes)
            mstore(add(bs, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)

            let encoded_data := add(0x20, bs) // load initialization code.
            let encoded_size := mload(bs)     // load the init code's length.

            result := create2(0, bs, 0x37, salt)
        }

        emit Created(salt, result);
    }
// Solidity 0.6.12
/**
 * @notice Deposit ETH to mint cube tokens
 * @dev Quantity of cube tokens minted is calculated from the amount of ETH
 * attached with transaction
 * @param cubeToken Which cube token to mint
 * @param recipient Address that receives the cube tokens
 * @return cubeTokensOut Quantity of cube tokens that were minted
 */
function deposit(CubeToken cubeToken, address recipient)
        external
        payable
        nonReentrant
        returns (uint256 cubeTokensOut)
    {
        CubeTokenParams storage _params = params[cubeToken];
        require(_params.added, "Not added");
        require(!_params.depositPaused, "Paused");
        require(msg.value > 0, "msg.value should be > 0");
        require(recipient != address(0), "Zero address");

        (uint256 price, uint256 _totalEquity) = _priceAndTotalEquity(cubeToken);
        _updatePrice(cubeToken, price);

        uint256 fees = _mulFee(msg.value, _params.depositWithdrawFee);
        uint256 ethIn = msg.value.sub(fees);
        uint256 _poolBalance = poolBalance();
        cubeTokensOut = _divPrice(ethIn, price, _totalEquity, _poolBalance.sub(msg.value));
        totalEquity = _totalEquity.add(cubeTokensOut.mul(price));

        uint256 protocolFees = _mulFee(fees, protocolFee);
        accruedProtocolFees = accruedProtocolFees.add(protocolFees);
        cubeToken.mint(recipient, cubeTokensOut);

        if (_params.maxPoolShare > 0) {
            uint256 equity = cubeToken.totalSupply().mul(price);
            require(equity.mul(1e4) <= _params.maxPoolShare.mul(totalEquity), "Max pool share exceeded");
        }

        if (maxPoolBalance > 0) {
            require(_poolBalance <= maxPoolBalance, "Max pool balance exceeded");
        }

        emit DepositOrWithdraw(cubeToken, msg.sender, recipient, true, cubeTokensOut, msg.value, protocolFees);
    }