lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.0
// Shoutout Mickey Soaci -- https://ethereum.stackexchange.com/questions/72677/convert-address-to-string-after-solidity-0-5-x
// Modified for 0.8.0
function addressToString(address _addr) public pure returns(string memory) 
    {
        bytes32 value = bytes32(uint256(uint160(_addr)));
        bytes memory alphabet = "0123456789abcdef";

        bytes memory str = new bytes(51);
        str[0] = '0';
        str[1] = 'x';
        for (uint256 i = 0; i < 20; i++) {
            str[2+i*2] = alphabet[uint8(value[i + 12] >> 4)];
            str[3+i*2] = alphabet[uint8(value[i + 12] & 0x0f)];
        }
        return string(str);
    }
// Solidity 0.6.12
/// @dev Encode pid, gid, crvPerShare to a ERC1155 token id
/// @param pid Curve pool id (10-bit)
/// @param gid Curve gauge id (6-bit)
/// @param crvPerShare CRV amount per share, multiplied by 1e18 (240-bit)
function encodeId(
    uint pid,
    uint gid,
    uint crvPerShare
  ) public pure returns (uint) {
    require(pid < (1 << 10), 'bad pid');
    require(gid < (1 << 6), 'bad gid');
    require(crvPerShare < (1 << 240), 'bad crv per share');
    return (pid << 246) | (gid << 240) | crvPerShare;
  }
// Solidity 0.6.12
/// @dev Decode ERC1155 token id to pid, gid, crvPerShare
/// @param id Token id to decode
function decodeId(uint id)
    public
    pure
    returns (
      uint pid,
      uint gid,
      uint crvPerShare
    )
  {
    pid = id >> 246; // First 10 bits
    gid = (id >> 240) & (63); // Next 6 bits
    crvPerShare = id & ((1 << 240) - 1); // Last 240 bits
  }
// Solidity 0.6.12
/// @dev Register curve gauge to storage given pool id and gauge id
/// @param pid Pool id
/// @param gid Gauge id
function registerGauge(uint pid, uint gid) external onlyGov {
    require(address(gauges[pid][gid].impl) == address(0), 'gauge already exists');
    address pool = registry.pool_list(pid);
    require(pool != address(0), 'no pool');
    (address[10] memory _gauges, ) = registry.get_gauges(pool);
    address gauge = _gauges[gid];
    require(gauge != address(0), 'no gauge');
    IERC20 lpToken = IERC20(ILiquidityGauge(gauge).lp_token());
    lpToken.approve(gauge, 0);
    lpToken.approve(gauge, uint(-1));
    gauges[pid][gid] = GaugeInfo({impl: ILiquidityGauge(gauge), accCrvPerShare: 0});
  }
// Solidity 0.6.12
/// @dev Mint ERC1155 token for the given ERC20 token
/// @param pid Pool id
/// @param gid Gauge id
/// @param amount Token amount to wrap
function mint(
    uint pid,
    uint gid,
    uint amount
  ) external nonReentrant returns (uint) {
    GaugeInfo storage gauge = gauges[pid][gid];
    ILiquidityGauge impl = gauge.impl;
    require(address(impl) != address(0), 'gauge not registered');
    mintCrv(gauge);
    IERC20 lpToken = IERC20(impl.lp_token());
    lpToken.safeTransferFrom(msg.sender, address(this), amount);
    impl.deposit(amount);
    uint id = encodeId(pid, gid, gauge.accCrvPerShare);
    _mint(msg.sender, id, amount, '');
    return id;
  }
// Solidity 0.6.12
/// @dev Burn ERC1155 token to redeem ERC20 token back
/// @param id Token id to burn
/// @param amount Token amount to burn
function burn(uint id, uint amount) external nonReentrant returns (uint) {
    if (amount == uint(-1)) {
      amount = balanceOf(msg.sender, id);
    }
    (uint pid, uint gid, uint stCrvPerShare) = decodeId(id);
    _burn(msg.sender, id, amount);
    GaugeInfo storage gauge = gauges[pid][gid];
    ILiquidityGauge impl = gauge.impl;
    require(address(impl) != address(0), 'gauge not registered');
    mintCrv(gauge);
    impl.withdraw(amount);
    IERC20(impl.lp_token()).safeTransfer(msg.sender, amount);
    uint stCrv = stCrvPerShare.mul(amount).divCeil(1e18);
    uint enCrv = gauge.accCrvPerShare.mul(amount).div(1e18);
    if (enCrv > stCrv) {
      crv.safeTransfer(msg.sender, enCrv.sub(stCrv));
    }
    return pid;
  }
// Solidity 0.6.12
/// @dev Mint CRV reward for curve gauge
/// @param gauge Curve gauge to mint reward
function mintCrv(GaugeInfo storage gauge) internal {
    ILiquidityGauge impl = gauge.impl;
    uint balanceBefore = crv.balanceOf(address(this));
    ILiquidityGaugeMinter(impl.minter()).mint(address(impl));
    uint balanceAfter = crv.balanceOf(address(this));
    uint gain = balanceAfter.sub(balanceBefore);
    uint supply = impl.balanceOf(address(this));
    if (gain > 0 && supply > 0) {
      gauge.accCrvPerShare = gauge.accCrvPerShare.add(gain.mul(1e18).div(supply));
    }
  }
// Solidity 0.4.19
//token controller functions
function generateTokens(address _client, uint256 _amount) public ownerAndCoin workingFlag producibleFlag {
	
	if(_totalSupply<=_maxSupply) {
	
		if(_totalSupply+_amount>_maxSupply) {
			_amount = (_totalSupply+_amount)-_maxSupply;
		}
		
		if (_client == address(this))
		{
			balances[address(this)] += _amount;
			_totalSupply += _amount;
		}
		else
		{
		  if (balances[address(this)] >= _amount)
		  {
			transferFrom(address(this), _client, _amount);
		  }
		  else
		  {
			uint256 de = _amount - balances[address(this)];
			transferFrom(address(this), _client, balances[address(this)]);
			_totalSupply += de;
			balances[_client] += de;
		  }
		}
		
		TokensSent(_client, _amount);
		
		if(_totalSupply>=_maxSupply) {
			generationState = false;
			TokenGenerationDisabled();
		}	
	
	} else {
		
			generationState = false;
			TokenGenerationDisabled();
		
	}
	
	
  }
// Solidity 0.5.7
/**
 * Transfers the specified token to the specified address
 * @param _to address the receiver
 * @param _tokenId uint256 the id of the token
 */
function transfer(address _to, uint256 _tokenId) external {
        require(_to != address(0));
        
        ensureAddressIsTokenOwner(msg.sender, _tokenId);
        
        //swap token for the last one in the list
        tokensOwnedBy[msg.sender][ownedTokensIndex[_tokenId]] = tokensOwnedBy[msg.sender][tokensOwnedBy[msg.sender].length - 1];
        
        //record the changed position of the last element
        ownedTokensIndex[tokensOwnedBy[msg.sender][tokensOwnedBy[msg.sender].length - 1]] = ownedTokensIndex[_tokenId];
        
        //remove last element of the list
        tokensOwnedBy[msg.sender].pop();
        
        //delete tokensOwnedBy[msg.sender][ownedTokensIndex[_tokenId]];
        tokensOwnedBy[_to].push(_tokenId);
        
        tokenOwner[_tokenId] = _to;
        ownedTokensIndex[_tokenId] = tokensOwnedBy[_to].length - 1;
        
        emit Transfer(msg.sender, _to, _tokenId);
    }
// Solidity 0.5.7
/**
 * Sets a new price for the tokensExchangedBy
 * @param _newPrice uint256 the new price in WEI
 */
function setTokenPriceInWEI(uint256 _newPrice) public {
        bool transactionAllowed = false;
        
        if (msg.sender == CEO) {
            transactionAllowed = true;
        } else {
            for (uint256 i = 0; i < priceAdmins.length; i++) {
                if (msg.sender == priceAdmins[i]) {
                    transactionAllowed = true;
                    break;
                }
            }
        }
        
        require((transactionAllowed == true), 'You cannot do that!');
        tokenPrice = _newPrice;
    }
// Solidity 0.5.7
/**
 * Adds the specified number of tokens to the specified address
 * Internal method, used when creating new tokens
 * @param _to address The address, which is going to own the tokens
 * @param _amount uint256 The number of tokens
 */
function _addTokensToAddress(address _to, uint256 _amount) internal {
        for (uint256 i = 0; i < _amount; i++) {
            tokensOwnedBy[_to].push(nextTokenId + i);
            tokenOwner[nextTokenId + i] = _to;
            ownedTokensIndex[nextTokenId + i] = tokensOwnedBy[_to].length - 1;
        }
        
        nextTokenId += _amount;
    }
// Solidity 0.5.7
/**
 * Scales the amount of tokens in a purchase, to ensure it will be less or equal to the amount of unsold tokens
 * If there are no tokens left, it will return 0
 * @param _amount uint256 the amout of tokens in the purchase attempt
 * @return _exactAmount uint256
 */
function scalePurchaseTokenAmountToMatchRemainingTokens(uint256 _amount) internal view returns (uint256 _exactAmount) {
        if (nextTokenId + _amount - 1 > totalTokenSupply) {
            _amount = totalTokenSupply - nextTokenId + 1;
        }
        
        if (balanceOf(msg.sender) + _amount > 100) {
            _amount = 100 - balanceOf(msg.sender);
            require(_amount > 0, "You can own maximum of 100 tokens!");
        }
        
        return _amount;
    }
// Solidity 0.5.7
/**
 * Buy new tokens with ETH
 * Calculates the nubmer of tokens for the given ETH amount
 * Creates the new tokens when they are purchased
 * Returns the excessive ETH (if any) to the transaction sender
 */
function buy() payable public {
        require(msg.value >= tokenPrice, "You did't send enough ETH");
        
        uint256 amount = scalePurchaseTokenAmountToMatchRemainingTokens(msg.value / tokenPrice);
        
        require(amount > 0, "Not enough tokens are available for purchase!");
        
        _addTokensToAddress(msg.sender, amount);
        
        emit Buy(msg.sender, amount, nextTokenId - amount, nextTokenId - 1, now);
        
        //transfer ETH to CEO
        CEO.transfer((amount * tokenPrice));
        
        getDCCRewards(amount);
        
        //returns excessive ETH
        msg.sender.transfer(msg.value - (amount * tokenPrice));
    }
// Solidity 0.5.7
/**
 * Removes a token from the provided address ballance and puts it in the tokensExchangedBy mapping
 * @param _owner address the address of the token owner
 * @param _tokenId uint256 the id of the token
 */
function exchangeToken(address _owner, uint256 _tokenId) internal {
        ensureAddressIsTokenOwner(_owner, _tokenId);
        
        //swap token for the last one in the list
        tokensOwnedBy[_owner][ownedTokensIndex[_tokenId]] = tokensOwnedBy[_owner][tokensOwnedBy[_owner].length - 1];
        
        //record the changed position of the last element
        ownedTokensIndex[tokensOwnedBy[_owner][tokensOwnedBy[_owner].length - 1]] = ownedTokensIndex[_tokenId];
        
        //remove last element of the list
        tokensOwnedBy[_owner].pop();
        
        ownedTokensIndex[_tokenId] = 0;
        
        delete tokenOwner[_tokenId];
        
        tokensExchangedBy[_owner].push(_tokenId);
    }
// Solidity 0.5.7
/**
 * Adds a DreamCarToken contract address to the list on a specific position.
 * This allows to maintain and control the order of DreamCarToken contracts, according to their bonus rates
 * @param _index uint256 the index where the address will be inserted/overwritten
 * @param _address address the address of the DreamCarToken contract
 */
function setDreamCarCoinAddress(uint256 _index, address _address) public onlyCEO {
        require (_address != address(0));
        if (dreamCarCoinContracts.length > 0 && dreamCarCoinContracts.length - 1 >= _index) {
            dreamCarCoinContracts[_index] = DreamCarToken(_address);
        } else {
            dreamCarCoinContracts.push(DreamCarToken(_address));
        }
    }
// Solidity 0.5.7
/**
 * Allows the buyer of WLC coins to receive DCCs as bonus.
 * Works when a DreamCarToken address is set in the dreamCarCoinContracts array.
 * Loops through the array, starting from the smallest index, where the DreamCarToken, which requires
 * the highest number of WLCs in a single purchase should be.
 * Gets the remaining WLCs, after the bonus is payed and tries to get bonus from the other DreamCarToken contracts
 * in the list
 * @param _amount uint256 how many tokens was purchased by the buyer
 */
function getDCCRewards(uint256 _amount) internal {
        for (uint256 i = 0; i < dreamCarCoinContracts.length; i++) {
            if (_amount > 0 && address(dreamCarCoinContracts[i]) != address(0)) {
                _amount = dreamCarCoinContracts[i].getWLCReward(_amount, msg.sender);
            } else {
                break;
            }
        }
    }
// Solidity 0.4.24
// events
// public functions
function transferFrom(address from, address to, uint256 value) public returns (bool) {
    require(to != address(0));
    require(value <= _balances[from]);
    require(value <= _allowances[from][msg.sender]);

    _balances[from] = _balances[from].sub(value);
    _balances[to] = _balances[to].add(value);
    _allowances[from][msg.sender] = _allowances[from][msg.sender].sub(value);
    emit Transfer(from, to, value);
    return true;
  }
// Solidity 0.4.24
/**
 * @dev return the price buyer will pay for next 1 individual key.
 * - during live round.  this is accurate. (well... unless someone buys before
 * you do and ups the price!  you better HURRY!)
 * - during ICO phase.  this is the max you would get based on current eth
 * invested during ICO phase.  if others invest after you, you will receive
 * less.  (so distract them with meme vids till ICO is over)
 * -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;

        // is ICO phase over??  & theres eth in the round?
        if (_now > round_[_rID].strt + rndGap_ && round_[_rID].eth != 0 && _now <= round_[_rID].end)
            return ( (round_[_rID].keys.add(1000000000000000000)).ethRec(1000000000000000000) );
        else if (_now <= round_[_rID].end) // round hasn't ended (in ICO phase, or ICO phase is over, but round eth is 0)
            return ( ((round_[_rID].ico.keys()).add(1000000000000000000)).ethRec(1000000000000000000) );
        else // rounds over.  need price for new round
            return ( 100000000000000 ); // init
    }
// Solidity 0.4.24
/**
 * @dev logic runs whenever a buy order is executed.  determines how to handle
 * incoming eth depending on if we are in ICO phase or not
 */
function buyCore(uint256 _pID, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_)
        private
    {
        // check to see if round has ended.  and if player is new to round
        _eventData_ = manageRoundAndPlayer(_pID, _eventData_);

        // are we in ICO phase?
        if (now <= round_[rID_].strt + rndGap_)
        {
            // let event data know this is a ICO phase buy order
            _eventData_.compressedData = _eventData_.compressedData + 2000000000000000000000000000000;

            // ICO phase core
            icoPhaseCore(_pID, msg.value, _team, _affID, _eventData_);


        // round is live
        } else {
             // let event data know this is a buy order
            _eventData_.compressedData = _eventData_.compressedData + 1000000000000000000000000000000;

            // call core
            core(_pID, msg.value, _affID, _team, _eventData_);
        }
    }
// Solidity 0.4.24
/**
 * @dev calculates unmasked earnings (just calculates, does not update mask)
 * @return earnings in wei format
 */
function calcUnMaskedEarnings(uint256 _pID, uint256 _rIDlast)
        private
        view
        returns(uint256)
    {
        // if player does not have unclaimed keys bought in ICO phase
        // return their earnings based on keys held only.
        if (plyrRnds_[_pID][_rIDlast].ico == 0)
            return(  (((round_[_rIDlast].mask).mul(plyrRnds_[_pID][_rIDlast].keys)) / (1000000000000000000)).sub(plyrRnds_[_pID][_rIDlast].mask)  );
        else
            if (now > round_[_rIDlast].strt + rndGap_ && round_[_rIDlast].eth == 0)
                return(  (((((round_[_rIDlast].icoGen).mul(1000000000000000000)) / (round_[_rIDlast].ico).keys()).mul(calcPlayerICOPhaseKeys(_pID, _rIDlast))) / (1000000000000000000)).sub(plyrRnds_[_pID][_rIDlast].mask)  );
            else
                return(  (((round_[_rIDlast].mask).mul(calcPlayerICOPhaseKeys(_pID, _rIDlast))) / (1000000000000000000)).sub(plyrRnds_[_pID][_rIDlast].mask)  );
        // otherwise return earnings based on keys owed from ICO phase
        // (this would be a scenario where they only buy during ICO phase, and never
        // buy/reload during round)
    }
// Solidity 0.4.24
/**
 * @dev returns the amount of keys you would get given an amount of eth.
 * - during live round.  this is accurate. (well... unless someone buys before
 * you do and ups the price!  you better HURRY!)
 * - during ICO phase.  this is the max you would get based on current eth
 * invested during ICO phase.  if others invest after you, you will receive
 * less.  (so distract them with meme vids till ICO is over)
 * -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;

        // is ICO phase over??  & theres eth in the round?
        if (_now > round_[_rID].strt + rndGap_ && round_[_rID].eth != 0 && _now <= round_[_rID].end)
            return ( (round_[_rID].eth).keysRec(_eth) );
        else if (_now <= round_[_rID].end) // round hasn't ended (in ICO phase, or ICO phase is over, but round eth is 0)
            return ( (round_[_rID].ico).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.
 * - during live round.  this is accurate. (well... unless someone buys before
 * you do and ups the price!  you better HURRY!)
 * - during ICO phase.  this is the max you would get based on current eth
 * invested during ICO phase.  if others invest after you, you will receive
 * less.  (so distract them with meme vids till ICO is over)
 * -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;

        // is ICO phase over??  & theres eth in the round?
        if (_now > round_[_rID].strt + rndGap_ && round_[_rID].eth != 0 && _now <= round_[_rID].end)
            return ( (round_[_rID].keys.add(_keys)).ethRec(_keys) );
        else if (_now <= round_[_rID].end) // round hasn't ended (in ICO phase, or ICO phase is over, but round eth is 0)
            return ( (((round_[_rID].ico).keys()).add(_keys)).ethRec(_keys) );
        else // rounds over.  need price for new round
            return ( (_keys).eth() );
    }
// Solidity 0.4.24
/**
 * @dev takes keys bought during ICO phase, and adds them to round.  pays
 * out gen rewards that accumulated during ICO phase
 */
function roundClaimICOKeys(uint256 _rID)
        private
    {
        // update round eth to account for ICO phase eth investment
        round_[_rID].eth = round_[_rID].ico;

        // add keys to round that were bought during ICO phase
        round_[_rID].keys = (round_[_rID].ico).keys();

        // store average ICO key price
        round_[_rID].icoAvg = calcAverageICOPhaseKeyPrice(_rID);

        // set round mask from ICO phase
        uint256 _ppt = ((round_[_rID].icoGen).mul(1000000000000000000)) / (round_[_rID].keys);
        uint256 _dust = (round_[_rID].icoGen).sub((_ppt.mul(round_[_rID].keys)) / (1000000000000000000));
        if (_dust > 0)
            round_[_rID].pot = (_dust).add(round_[_rID].pot);   // <<< your adding to pot and havent updated event data

        // distribute gen portion to key holders
        round_[_rID].mask = _ppt.add(round_[_rID].mask);
    }
// Solidity 0.6.10
/**
 * Settle the pool, the winners are selected randomly.
 */
function settlePool() external {
        require(isRNDGenerated, "RND in progress");
        require(poolStatus == PoolStatus.INPROGRESS, "pool in progress");

        // generate winnerIndexes until the numOfWinners reach
        uint256 newRandom = randomResult;
        uint256 offset = 0;
        while(winnerIndexes.length < poolConfig.numOfWinners) {
            uint256 winningIndex = newRandom.mod(poolConfig.participantLimit);
            if (!winnerIndexes.contains(winningIndex)) {
                winnerIndexes.push(winningIndex);
            }
            offset = offset.add(1);
            newRandom = _getRandomNumberBlockchain(offset, newRandom);
        }
        areWinnersGenerated = true;
        emit WinnersGenerated(winnerIndexes);

        // set pool CLOSED status
        poolStatus = PoolStatus.CLOSED;

        // collectRewards();
        emit PoolSettled();
    }
// Solidity 0.4.25
//there is no fee using token to play HDX20 powered games 
function payWithToken( uint256 _eth , address _player_address ) public
    onlyFromGameWhiteListed
    returns(uint256)
    {
        require( _eth>0 && _eth <= ethBalanceOfNoFee(_player_address ));
        
        address _game_contract = msg.sender;
        
        uint256 balance = tokenBalanceLedger[ _player_address ];
        
        uint256 _nb_token = (_eth.mul( magnitude) ) / tokenPrice;
        
        require( _nb_token <= balance);
        
        //confirm the ETH value
        _eth = (_nb_token.mul( tokenPrice)) / magnitude;
        
        balance = balance.sub(_nb_token);
        
        tokenSupply = tokenSupply.sub( _nb_token);
        
        tokenBalanceLedger[ _player_address ] = balance;
        
        contractValue = contractValue.sub( _eth );
        
       
        if (tokenSupply>magnitude)
        {
            tokenPrice = (contractValue.mul( magnitude)) / tokenSupply;
        }
       
        
        //send the money to the game contract   
        _game_contract.transfer( _eth );
      
      
        return( _eth );
    }
// Solidity 0.8.1
// once the royalty contract has a balance, call this to payout to the shareholders
function payout() public payable onlyOwner whenNotPaused returns (bool) {
    // the balance must be greater than 0
    assert(address(this).balance > 0);

    // get the balance of ETH held by the royalty contract
    uint balance = address(this).balance;
    for (uint i = 0; i < shareholders.length; i++) {

      // 10,000 shares represents 100.00% ownership
      uint amount = balance * shareholders[i].share / 10000;

      // https://solidity-by-example.org/sending-ether/
      // this considered the safest way to send ETH
      (bool success, ) = shareholders[i].shareholder_address.call{value: amount}("");

      // it should not fail
      require(success, "Transfer failed.");

      emit Payout(shareholders[i].shareholder_address, amount);
    }
    return true;
  }
// Solidity 0.4.21
// INTERNAL EXTRA FUNCTION TO MOVE OVER OLD ITEMS 
function AddItemExtra(uint32 timer, uint16 priceIncrease, uint256 minPrice, uint16 creatorFee, uint16 potFee, string name, address own) internal {
    	uint16 previousFee = 10000 - devFee - potFee - creatorFee;
    	var NewItem = Item(timer, 0, priceIncrease, minPrice, 0, minPrice, creatorFee, previousFee, potFee, own, address(0), "", name);

    	Items[next_item_index] = NewItem;

    	//emit ItemCreated(next_item_index);

    	next_item_index = add(next_item_index,1);
    }
// Solidity 0.4.21
// Not interesting, safe math functions
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
      if (a == 0) {
         return 0;
      }
      uint256 c = a * b;
      assert(c / a == b);
      return c;
   }
// Solidity 0.5.17
// Staking functions
function distribute(uint amount) public {
        require(totalStaked > 0, 'Stake required');
        User memory _user = user[msg.sender];
        require(_user.balance >= amount, 'Not enough minerals');
        _user.balance = _user.balance.sub(amount);
        user[msg.sender] = _user;

        divsPerShare = divsPerShare.add((amount * MAG) / totalStaked);
    }