lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.8
/**
 * @notice Check whether an order exists or not
 * @dev Check the balance of the order
 * @param _module - Address of the module to use for the order execution
 * @param _inputToken - Address of the input token
 * @param _owner - Address of the order's owner
 * @param _witness - Address of the witness
 * @param _data - Bytes of the order's data
 * @return bool - whether the order exists or not
 */
function existOrder(
        IModule _module,
        IERC20 _inputToken,
        address payable _owner,
        address _witness,
        bytes calldata _data
    ) external view returns (bool) {
        bytes32 key = keyOf(
            _module,
            _inputToken,
            _owner,
            _witness,
           _data
        );

        if (address(_inputToken) == ETH_ADDRESS) {
            return ethDeposits[key] != 0;
        } else {
            return _inputToken.balanceOf(key.getVault()) != 0;
        }
    }
// Solidity 0.6.8
/**
 * @notice Check whether an order can be executed or not
 * @param _module - Address of the module to use for the order execution
 * @param _inputToken - Address of the input token
 * @param _owner - Address of the order's owner
 * @param _witness - Address of the witness
 * @param _data - Bytes of the order's data
 * @param _auxData - Bytes of the auxiliar data used for the handlers to execute the order
 * @return bool - whether the order can be executed or not
 */
function canExecuteOrder(
        IModule _module,
        IERC20 _inputToken,
        address payable _owner,
        address _witness,
        bytes calldata _data,
        bytes calldata _auxData
    ) external view returns (bool) {
        bytes32 key = keyOf(
            _module,
            _inputToken,
            _owner,
            _witness,
            _data
        );

        // Pull amount
        uint256 amount;
        if (address(_inputToken) == ETH_ADDRESS) {
            amount = ethDeposits[key];
        } else {
            amount = _inputToken.balanceOf(key.getVault());
        }

        return _module.canExecute(
            _inputToken,
            amount,
            _data,
            _auxData
        );
    }
// Solidity 0.6.8
/**
 * @notice Transfer the order amount to a recipient.
 * @dev For an ETH order, the ETH will be transferred from this contract
 * For a token order, its vault will be executed transferring the amount of tokens to
 * the recipient
 * @param _inputToken - Address of the input token
 * @param _key - Order's key
 * @param _to - Address of the recipient
 * @return amount - amount transferred
 */
function _pullOrder(
        IERC20 _inputToken,
        bytes32 _key,
        address payable _to
    ) private returns (uint256 amount) {
        if (address(_inputToken) == ETH_ADDRESS) {
            amount = ethDeposits[_key];
            ethDeposits[_key] = 0;
            (bool success,) = _to.call{value: amount}("");
            require(success, "HyperLimit#_pullOrder: PULL_ETHER_FAILED");
        } else {
            amount = _key.executeVault(_inputToken, _to);
        }
    }
// Solidity 0.6.12
/**
 	 * @notice Performs the minting of gToken shares upon the deposit of the
 	 *         reserve token. The actual number of shares being minted can
 	 *         be calculated using the calcDepositSharesFromCost function.
 	 *         In every deposit, 1% of the shares is retained in terms of
 	 *         deposit fee. Half of it is immediately burned and the other
 	 *         half is provided to the locked liquidity pool. The funds
 	 *         will be pulled in by this contract, therefore they must be
 	 *         previously approved.
 	 * @param _cost The amount of reserve token being deposited in the
 	 *              operation.
 	 */
function deposit(uint256 _cost) public override nonReentrant
	{
		address _from = msg.sender;
		require(_cost > 0, "cost must be greater than 0");
		(uint256 _netShares, uint256 _feeShares) = GFormulae._calcDepositSharesFromCost(_cost, totalReserve(), totalSupply(), depositFee());
		require(_netShares > 0, "shares must be greater than 0");
		G.pullFunds(reserveToken, _from, _cost);
		require(_prepareDeposit(_cost), "not available at the moment");
		_mint(_from, _netShares);
		_mint(address(this), _feeShares.div(2));
	}
// Solidity 0.6.12
/**
 	 * @notice Performs the burning of gToken shares upon the withdrawal of
 	 *         the reserve token. The actual amount of the reserve token to
 	 *         be received can be calculated using the
 	 *         calcWithdrawalCostFromShares function. In every withdrawal,
 	 *         1% of the shares is retained in terms of withdrawal fee.
 	 *         Half of it is immediately burned and the other half is
 	 *         provided to the locked liquidity pool.
 	 * @param _grossShares The gross amount of this gToken shares being
 	 *                     redeemed in the operation.
 	 */
function withdraw(uint256 _grossShares) public override nonReentrant
	{
		address _from = msg.sender;
		require(_grossShares > 0, "shares must be greater than 0");
		(uint256 _cost, uint256 _feeShares) = GFormulae._calcWithdrawalCostFromShares(_grossShares, totalReserve(), totalSupply(), withdrawalFee());
		require(_cost > 0, "cost must be greater than 0");
		require(_prepareWithdrawal(_cost), "not available at the moment");
		_cost = G.min(_cost, G.getBalance(reserveToken));
		G.pushFunds(reserveToken, _from, _cost);
		_burn(_from, _grossShares);
		_mint(address(this), _feeShares.div(2));
	}
// Solidity 0.4.24
/**
 * @dev gives square root of given x.
 */
function sqrt(uint256 x)
    internal
    pure
    returns (uint256 y)
    {
        uint256 z = ((add(x,1)) / 2);
        y = x;
        while (z < y)
        {
            y = z;
            z = ((add((x / z),z)) / 2);
        }
    }
// Solidity 0.4.24
/**
 * @dev x to the power of y
 */
function pwr(uint256 x, uint256 y)
    internal
    pure
    returns (uint256)
    {
        if (x==0)
            return (0);
        else if (y==0)
            return (1);
        else
        {
            uint256 z = x;
            for (uint256 i=1; i < y; i++)
                z = mul(z,x);
            return (z);
        }
    }
// Solidity 0.4.24
/**
 * @dev emergency buy uses last stored affiliate ID and team snek
 */
function()
    isActivated()
    isHuman()
    isWithinLimits(msg.value)
    public
    payable
    {
        // set up our tx event data and determine if player is new or not
        F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_);

        // fetch player id
        uint256 _pID = pIDxAddr_[msg.sender];

        // buy core
        buyCore(_pID, plyr_[_pID].laff, 2, _eventData_);
    }
// Solidity 0.4.24
/**
 * @dev converts all incoming ethereum to keys.
 * -functionhash- 0x8f38f309 (using ID for affiliate)
 * -functionhash- 0x98a0871d (using address for affiliate)
 * -functionhash- 0xa65b37a1 (using name for affiliate)
 * @param _affCode the ID/address/name of the player who gets the affiliate fee
 * @param _team what team is the player playing for?
 */
function buyXid(uint256 _affCode, uint256 _team)
    isActivated()
    isHuman()
    isWithinLimits(msg.value)
    public
    payable
    {
        // set up our tx event data and determine if player is new or not
        F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_);

        // fetch player id
        uint256 _pID = pIDxAddr_[msg.sender];

        // manage affiliate residuals
        // if no affiliate code was given or player tried to use their own, lolz
        if (_affCode == 0 || _affCode == _pID)
        {
            // use last stored affiliate code
            _affCode = plyr_[_pID].laff;

            // if affiliate code was given & its not the same as previously stored
        } else if (_affCode != plyr_[_pID].laff) {
            // update last affiliate
            plyr_[_pID].laff = _affCode;
        }

        // verify a valid team was selected
        _team = verifyTeam(_team);

        // buy core
        buyCore(_pID, _affCode, _team, _eventData_);
    }
// Solidity 0.4.24
/**
 * @dev essentially the same as buy, but instead of you sending ether
 * from your wallet, it uses your unwithdrawn earnings.
 * -functionhash- 0x349cdcac (using ID for affiliate)
 * -functionhash- 0x82bfc739 (using address for affiliate)
 * -functionhash- 0x079ce327 (using name for affiliate)
 * @param _affCode the ID/address/name of the player who gets the affiliate fee
 * @param _team what team is the player playing for?
 * @param _eth amount of earnings to use (remainder returned to gen vault)
 */
function reLoadXid(uint256 _affCode, uint256 _team, uint256 _eth)
    isActivated()
    isHuman()
    isWithinLimits(_eth)
    public
    {
        // set up our tx event data
        F3Ddatasets.EventReturns memory _eventData_;

        // fetch player ID
        uint256 _pID = pIDxAddr_[msg.sender];

        // manage affiliate residuals
        // if no affiliate code was given or player tried to use their own, lolz
        if (_affCode == 0 || _affCode == _pID)
        {
            // use last stored affiliate code
            _affCode = plyr_[_pID].laff;

            // if affiliate code was given & its not the same as previously stored
        } else if (_affCode != plyr_[_pID].laff) {
            // update last affiliate
            plyr_[_pID].laff = _affCode;
        }

        // verify a valid team was selected
        _team = verifyTeam(_team);

        // reload core
        reLoadCore(_pID, _affCode, _team, _eth, _eventData_);
    }
// Solidity 0.4.24
/**
 * @dev use these to register names.  they are just wrappers that will send the
 * registration requests to the PlayerBook contract.  So registering here is the
 * same as registering there.  UI will always display the last name you registered.
 * but you will still own all previously registered names to use as affiliate
 * links.
 * - must pay a registration fee.
 * - name must be unique
 * - names will be converted to lowercase
 * - name cannot start or end with a space
 * - cannot have more than 1 space in a row
 * - cannot be only numbers
 * - cannot start with 0x
 * - name must be at least 1 char
 * - max length of 32 characters long
 * - allowed characters: a-z, 0-9, and space
 * -functionhash- 0x921dec21 (using ID for affiliate)
 * -functionhash- 0x3ddd4698 (using address for affiliate)
 * -functionhash- 0x685ffd83 (using name for affiliate)
 * @param _nameString players desired name
 * @param _affCode affiliate ID, address, or name of who referred you
 * @param _all set to true if you want this to push your info to all games
 * (this might cost a lot of gas)
 */
function registerNameXID(string _nameString, uint256 _affCode, bool _all)
    isHuman()
    public
    payable
    {
        bytes32 _name = _nameString.nameFilter();
        address _addr = msg.sender;
        uint256 _paid = msg.value;
        (bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXIDFromDapp.value(_paid)(_addr, _name, _affCode, _all);

        uint256 _pID = pIDxAddr_[_addr];

        // fire event
        emit F3Devents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now);
    }
// Solidity 0.4.24
/**
 * @dev return the price buyer will pay for next 1 individual key.
 * -functionhash- 0x018a25e8
 * @return price for next key bought (in wei format)
 */
function getBuyPrice()
    public
    view
    returns(uint256)
    {
        // setup local rID
        uint256 _rID = rID_;

        // grab time
        uint256 _now = now;

        // are we in a round?
        if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
            return ( (round_[_rID].keys.add(1000000000000000000)).ethRec(1000000000000000000) );
        else // rounds over.  need price for new round
            return ( 75000000000000 ); // init
    }
// Solidity 0.4.24
/**
 * @dev returns time left.  dont spam this, you'll ddos yourself from your node
 * provider
 * -functionhash- 0xc7e284b8
 * @return time left in seconds
 */
function getTimeLeft()
    public
    view
    returns(uint256)
    {
        // setup local rID
        uint256 _rID = rID_;

        // grab time
        uint256 _now = now;

        if (_now < round_[_rID].end)
            if (_now > round_[_rID].strt + rndGap_)
                return( (round_[_rID].end).sub(_now) );
            else
                return( (round_[_rID].strt + rndGap_).sub(_now) );
        else
            return(0);
    }
// Solidity 0.4.24
/**
 * @dev returns player earnings per vaults
 * -functionhash- 0x63066434
 * @return winnings vault
 * @return general vault
 * @return affiliate vault
 */
function getPlayerVaults(uint256 _pID)
    public
    view
    returns(uint256 ,uint256, uint256)
    {
        // setup local rID
        uint256 _rID = rID_;

        // if round has ended.  but round end has not been run (so contract has not distributed winnings)
        if (now > round_[_rID].end && round_[_rID].ended == false && round_[_rID].plyr != 0)
        {
            // if player is winner
            if (round_[_rID].plyr == _pID)
            {
                return
                (
                (plyr_[_pID].win).add( ((round_[_rID].pot).mul(48)) / 100 ),
                (plyr_[_pID].gen).add(  getPlayerVaultsHelper(_pID, _rID).sub(plyrRnds_[_pID][_rID].mask)   ),
                plyr_[_pID].aff
                );
                // if player is not the winner
            } else {
                return
                (
                plyr_[_pID].win,
                (plyr_[_pID].gen).add(  getPlayerVaultsHelper(_pID, _rID).sub(plyrRnds_[_pID][_rID].mask)  ),
                plyr_[_pID].aff
                );
            }

            // if round is still going on, or round has ended and round end has been ran
        } else {
            return
            (
            plyr_[_pID].win,
            (plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)),
            plyr_[_pID].aff
            );
        }
    }
// Solidity 0.4.24
/**
 * @dev returns all current round info needed for front end
 * -functionhash- 0x747dff42
 * @return eth invested during ICO phase
 * @return round id
 * @return total keys for round
 * @return time round ends
 * @return time round started
 * @return current pot
 * @return current team ID & player ID in lead
 * @return current player in leads address
 * @return current player in leads name
 * @return whales eth in for round
 * @return bears eth in for round
 * @return sneks eth in for round
 * @return bulls eth in for round
 * @return airdrop tracker # & airdrop pot
 */
function getCurrentRoundInfo()
    public
    view
    returns(uint256, uint256, uint256, uint256, uint256, uint256, uint256, address, bytes32, uint256, uint256, uint256, uint256, uint256)
    {
        // setup local rID
        uint256 _rID = rID_;

        return
        (
        round_[_rID].ico,               //0
        _rID,                           //1
        round_[_rID].keys,              //2
        round_[_rID].end,               //3
        round_[_rID].strt,              //4
        round_[_rID].pot,               //5
        (round_[_rID].team + (round_[_rID].plyr * 10)),     //6
        plyr_[round_[_rID].plyr].addr,  //7
        plyr_[round_[_rID].plyr].name,  //8
        rndTmEth_[_rID][0],             //9
        rndTmEth_[_rID][1],             //10
        rndTmEth_[_rID][2],             //11
        rndTmEth_[_rID][3],             //12
        airDropTracker_ + (airDropPot_ * 1000)              //13
        );
    }
// Solidity 0.4.24
/**
 * @dev returns player info based on address.  if no address is given, it will
 * use msg.sender
 * -functionhash- 0xee0b5d8b
 * @param _addr address of the player you want to lookup
 * @return player ID
 * @return player name
 * @return keys owned (current round)
 * @return winnings vault
 * @return general vault
 * @return affiliate vault
 	 * @return player round eth
 */
function getPlayerInfoByAddress(address _addr)
    public
    view
    returns(uint256, bytes32, uint256, uint256, uint256, uint256, uint256)
    {
        // setup local rID
        uint256 _rID = rID_;

        if (_addr == address(0))
        {
            _addr == msg.sender;
        }
        uint256 _pID = pIDxAddr_[_addr];

        return
        (
        _pID,                               //0
        plyr_[_pID].name,                   //1
        plyrRnds_[_pID][_rID].keys,         //2
        plyr_[_pID].win,                    //3
        (plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)),       //4
        plyr_[_pID].aff,                    //5
        plyrRnds_[_pID][_rID].eth           //6
        );
    }
// Solidity 0.4.24
/**
 * @dev returns the amount of keys you would get given an amount of eth.
 * -functionhash- 0xce89c80c
 * @param _rID round ID you want price for
 * @param _eth amount of eth sent in
 * @return keys received
 */
function calcKeysReceived(uint256 _rID, uint256 _eth)
    public
    view
    returns(uint256)
    {
        // grab time
        uint256 _now = now;

        // are we in a round?
        if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
            return ( (round_[_rID].eth).keysRec(_eth) );
        else // rounds over.  need keys for new round
            return ( (_eth).keys() );
    }
// Solidity 0.4.24
/**
 * @dev returns current eth price for X keys.
 * -functionhash- 0xcf808000
 * @param _keys number of keys desired (in 18 decimal format)
 * @return amount of eth needed to send
 */
function iWantXKeys(uint256 _keys)
    public
    view
    returns(uint256)
    {
        // setup local rID
        uint256 _rID = rID_;

        // grab time
        uint256 _now = now;

        // are we in a round?
        if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0)))
            return ( (round_[_rID].keys.add(_keys)).ethRec(_keys) );
        else // rounds over.  need price for new round
            return ( (_keys).eth() );
    }
// Solidity 0.4.24
/**
 	 * @dev receives name/player info from names contract
 */
function receivePlayerInfo(uint256 _pID, address _addr, bytes32 _name, uint256 _laff)
    external
    {
        require (msg.sender == address(PlayerBook), "your not playerNames contract... hmmm..");
        if (pIDxAddr_[_addr] != _pID)
            pIDxAddr_[_addr] = _pID;
        if (pIDxName_[_name] != _pID)
            pIDxName_[_name] = _pID;
        if (plyr_[_pID].addr != _addr)
            plyr_[_pID].addr = _addr;
        if (plyr_[_pID].name != _name)
            plyr_[_pID].name = _name;
        if (plyr_[_pID].laff != _laff)
            plyr_[_pID].laff = _laff;
        if (plyrNames_[_pID][_name] == false)
            plyrNames_[_pID][_name] = true;
    }
// Solidity 0.4.24
/**
 * @dev gets existing or registers new pID.  use this when a player may be new
 * @return pID
 */
function determinePID(F3Ddatasets.EventReturns memory _eventData_)
    private
    returns (F3Ddatasets.EventReturns)
    {
        uint256 _pID = pIDxAddr_[msg.sender];
        // if player is new to this version of fomo3d
        if (_pID == 0)
        {
            // grab their player ID, name and last aff ID, from player names contract
            _pID = PlayerBook.getPlayerID(msg.sender);
            bytes32 _name = PlayerBook.getPlayerName(_pID);
            uint256 _laff = PlayerBook.getPlayerLAff(_pID);

            // set up player account
            pIDxAddr_[msg.sender] = _pID;
            plyr_[_pID].addr = msg.sender;

            if (_name != "")
            {
                pIDxName_[_name] = _pID;
                plyr_[_pID].name = _name;
                plyrNames_[_pID][_name] = true;
            }

            if (_laff != 0 && _laff != _pID)
                plyr_[_pID].laff = _laff;

            // set the new player bool to true
            _eventData_.compressedData = _eventData_.compressedData + 1;
        }
        return (_eventData_);
    }
// Solidity 0.4.24
/**
 * @dev decides if round end needs to be run & new round started.  and if
 * player unmasked earnings from previously played rounds need to be moved.
 */
function managePlayer(uint256 _pID, F3Ddatasets.EventReturns memory _eventData_)
    private
    returns (F3Ddatasets.EventReturns)
    {
        // if player has played a previous round, move their unmasked earnings
        // from that round to gen vault.
        if (plyr_[_pID].lrnd != 0)
            updateGenVault(_pID, plyr_[_pID].lrnd);

        // update player's last round played
        plyr_[_pID].lrnd = rID_;

        // set the joined round bool to true
        _eventData_.compressedData = _eventData_.compressedData + 10;

        return(_eventData_);
    }
// Solidity 0.4.24
/**
 * @dev moves any unmasked earnings to gen vault.  updates earnings mask
 */
function updateGenVault(uint256 _pID, uint256 _rIDlast)
    private
    {
        uint256 _earnings = calcUnMaskedEarnings(_pID, _rIDlast);
        if (_earnings > 0)
        {
            // put in gen vault
            plyr_[_pID].gen = _earnings.add(plyr_[_pID].gen);
            // zero out their earnings by updating mask
            plyrRnds_[_pID][_rIDlast].mask = _earnings.add(plyrRnds_[_pID][_rIDlast].mask);
        }
    }
// Solidity 0.4.24
/**
 * @dev updates round timer based on number of whole keys bought.
 */
function updateTimer(uint256 _keys, uint256 _rID)
    private
    {
        // grab time
        uint256 _now = now;

        // calculate time based on number of keys bought
        uint256 _newTime;
        if (_now > round_[_rID].end && round_[_rID].plyr == 0)
            _newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(_now);
        else
            _newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(round_[_rID].end);

        // compare to max and set new end time
        if (_newTime < (rndMax_).add(_now))
            round_[_rID].end = _newTime;
        else
            round_[_rID].end = rndMax_.add(_now);
    }
// Solidity 0.4.24
/**
 * @dev distributes eth based on fees to com, aff, and p3d
 */
function distributeExternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_)
    private
    returns(F3Ddatasets.EventReturns)
    {
        // pay 2% out to community rewards
        uint256 _com = _eth / 50;

        // distribute share to affiliate
        uint256 _aff = _eth / 10;

        // decide what to do with affiliate share of fees
        // affiliate must not be self, and must have a name registered
        if (_affID != _pID && plyr_[_affID].name != '') {
            plyr_[_affID].aff = _aff.add(plyr_[_affID].aff);
            emit F3Devents.onAffiliatePayout(_affID, plyr_[_affID].addr, plyr_[_affID].name, _rID, _pID, _aff, now);
        } else {
            _com = _com.add(_aff);
        }

        uint256 _mkt = _eth.mul(fees_[_team].marketing) / 100;
        _com = _com.add(_mkt);
        owner.transfer(_com);

        _eventData_.mktAmount = _mkt;
//        _eventData_.comAmount = _com;
        return(_eventData_);
    }