lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
//Salviamo l'indirizzo del creatore del contratto per inviare gli ether ricevuti
function ChrisCoin(){
		owner = msg.sender;
		balances[msg.sender] = CREATOR_TOKEN;
		start = now;
		end = now.add(LENGHT_BONUS);	//fine periodo bonus
		end2 = end.add(LENGHT_BONUS2);	//fine periodo bonus
		end3 = end2.add(LENGHT_BONUS3);	//fine periodo bonus
		end4 = end3.add(LENGHT_BONUS4);	//fine periodo bonus
	}
// Solidity 0.4.18
//Creazione dei token
function createTokens() payable{
		require(msg.value >= 0);
		uint256 tokens = msg.value.mul(10 ** decimals);
		tokens = tokens.mul(RATE);
		tokens = tokens.div(10 ** 18);
		if (bonusAllowed)
		{
			if (now >= start && now < end)
			{
			tokens += tokens.mul(PERC_BONUS).div(100);
			}
			if (now >= end && now < end2)
			{
			tokens += tokens.mul(PERC_BONUS2).div(100);
			}
			if (now >= end2 && now < end3)
			{
			tokens += tokens.mul(PERC_BONUS3).div(100);
			}
			if (now >= end3 && now < end4)
			{
			tokens += tokens.mul(PERC_BONUS4).div(100);
			}
		}
		uint256 sum2 = balances[owner].sub(tokens);		
		require(sum2 >= CREATOR_TOKEN_END);
		uint256 sum = _totalSupply.add(tokens);		
		balances[msg.sender] = balances[msg.sender].add(tokens);
		balances[owner] = balances[owner].sub(tokens);
		_totalSupply = sum;
		owner.transfer(msg.value);
		Transfer(owner, msg.sender, tokens);
	}
// Solidity 0.8.0
// ######## MINTING
function rarityIndexForNumber(uint256 number, uint8 traitType) internal view returns (bytes1) {
        uint16 lowerBound = 0;
        for (uint8 i = 0; i < rarities[traitType].length; i++) {
            uint16 upperBound = lowerBound + rarities[traitType][i];
            if (number >= lowerBound && number < upperBound)
                return bytes1(i);
            lowerBound = upperBound;
        }

        revert();
    }
// Solidity 0.4.18
//Invio dei token con delega
function transferFrom(address _from, address _to, uint256 _value) returns (bool success){
		require(allowed[_from][msg.sender] >= _value && balances[msg.sender] >= _value	&& _value > 0);
		balances[_from] = balances[_from].sub(_value);
		balances[_to] = balances[_to].add(_value);
		allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
		Transfer(_from, _to, _value);
		return true;
	}
// Solidity 0.4.18
//brucia tutti i token rimanenti
function burnAll() public {		
		require(msg.sender == owner);
		address burner = msg.sender;
		uint256 total = balances[burner];
		if (total > CREATOR_TOKEN_END) {
			total = total.sub(CREATOR_TOKEN_END);
			balances[burner] = balances[burner].sub(total);
			if (_totalSupply >= total){
				_totalSupply = _totalSupply.sub(total);
			}
			Burn(burner, total);
		}
	}
// Solidity 0.4.18
//brucia la quantita' _value di token
function burn(uint256 _value) public {
		require(msg.sender == owner);
        require(_value > 0);
        require(_value <= balances[msg.sender]);
		_value = _value.mul(10 ** decimals);
        address burner = msg.sender;
		uint t = balances[burner].sub(_value);
		require(t >= CREATOR_TOKEN_END);
        balances[burner] = balances[burner].sub(_value);
        if (_totalSupply >= _value){
			_totalSupply = _totalSupply.sub(_value);
		}
        Burn(burner, _value);
	}
// Solidity 0.5.16
// Initializer
function init(
    address _summoner,
    address _DAI_ADDR,
    uint256 _withdrawLimit,
    uint256 _consensusThresholdPercentage
  ) public {
    require(! initialized, "Initialized");
    require(_consensusThresholdPercentage <= PRECISION, "Consensus threshold > 1");
    initialized = true;
    memberCount = 1;
    DAI = IERC20(_DAI_ADDR);
    issuersOrFulfillers = new address payable[](1);
    issuersOrFulfillers[0] = address(this);
    approvers = new address[](1);
    approvers[0] = address(this);
    withdrawLimit = _withdrawLimit;
    consensusThresholdPercentage = _consensusThresholdPercentage;

    // Add `_summoner` as the first member
    isMember[_summoner] = true;
  }
// Solidity 0.5.16
/**
 Member management
 */
function addMembers(
    address[] memory _newMembers,
    uint256[] memory _tributes,
    address[] memory _members,
    bytes[]   memory _signatures,
    uint256[] memory _salts
  )
    public
    withConsensus(
      this.addMembers.selector,
      abi.encode(_newMembers, _tributes),
      _members,
      _signatures,
      _salts
    )
  {
    require(_newMembers.length == _tributes.length, "_newMembers not same length as _tributes");
    for (uint256 i = 0; i < _newMembers.length; i = i.add(1)) {
      _addMember(_newMembers[i], _tributes[i]);
    }
  }
// Solidity 0.5.16
/**
 Fund management
 */
function transferDAI(
    address[] memory _dests,
    uint256[] memory _amounts,
    address[] memory _members,
    bytes[]   memory _signatures,
    uint256[] memory _salts
  )
    public
    withConsensus(
      this.transferDAI.selector,
      abi.encode(_dests, _amounts),
      _members,
      _signatures,
      _salts
    )
  {
    require(_dests.length == _amounts.length, "_dests not same length as _amounts");
    for (uint256 i = 0; i < _dests.length; i = i.add(1)) {
      _transferDAI(_dests[i], _amounts[i]);
    }
  }
// Solidity 0.5.16
/**
 Posting bounties
 */
function postBounty(
    string memory _dataIPFSHash,
    uint256 _deadline,
    uint256 _reward,
    address _standardBounties,
    uint256 _standardBountiesVersion,
    address[] memory _members,
    bytes[]   memory _signatures,
    uint256[] memory _salts
  )
    public
    withConsensus(
      this.postBounty.selector,
      abi.encode(_dataIPFSHash, _deadline, _reward, _standardBounties, _standardBountiesVersion),
      _members,
      _signatures,
      _salts
    )
    returns (uint256 _bountyID)
  {
    return _postBounty(_dataIPFSHash, _deadline, _reward, _standardBounties, _standardBountiesVersion);
  }
// Solidity 0.5.16
/**
 Working on bounties
 */
function performBountyAction(
    uint256 _bountyID,
    string memory _dataIPFSHash,
    address _standardBounties,
    uint256 _standardBountiesVersion,
    address[] memory _members,
    bytes[]   memory _signatures,
    uint256[] memory _salts
  )
    public
    withConsensus(
      this.performBountyAction.selector,
      abi.encode(_bountyID, _dataIPFSHash, _standardBounties, _standardBountiesVersion),
      _members,
      _signatures,
      _salts
    )
  {
    _standardBounties.performAction(
      _standardBountiesVersion,
      address(this),
      _bountyID,
      _dataIPFSHash
    );
    emit PerformBountyAction(_bountyID);
  }
// Solidity 0.5.16
/**
 Consensus
 */
function naiveMessageHash(
    bytes4       _funcSelector,
    bytes memory _funcParams,
    uint256      _salt
  ) public view returns (bytes32) {
    // "|END|" is used to separate _funcParams from the rest, to prevent maliciously ambiguous signatures
    return keccak256(abi.encodeWithSelector(_funcSelector, _funcParams, "|END|", _salt, address(this)));
  }
// Solidity 0.5.16
// limits how much could be withdrawn each day, should be called before transfer() or approve()
function _applyWithdrawLimit(uint256 _amount) internal {
    // check if the limit will be exceeded
    if (_timestampToDayID(now).sub(_timestampToDayID(lastWithdrawTimestamp)) >= 1) {
      // new day, don't care about existing limit
      withdrawnToday = 0;
    }
    uint256 newWithdrawnToday = withdrawnToday.add(_amount);
    require(newWithdrawnToday <= withdrawLimit, "Withdraw limit exceeded");
    withdrawnToday = newWithdrawnToday;
    lastWithdrawTimestamp = now;
  }
// Solidity 0.4.21
/// @dev In later version, require authorities consensus
/// @notice Add an approved version of Melon
/// @param ofVersion Address of the version to add
/// @return id integer ID of the version (list index)
function addVersion(
        address ofVersion
    )
        pre_cond(msg.sender == address(this))
        returns (uint id)
    {
        require(msg.sender == address(this));
        Version memory info;
        info.version = ofVersion;
        info.active = true;
        info.timestamp = now;
        versions.push(info);
        emit VersionUpdated(versions.length - 1);
    }
// Solidity 0.4.11
/**
 * Based on http://www.codecodex.com/wiki/Calculate_an_integer_square_root
 */
function sqrt(uint num) internal returns (uint) {
    if (0 == num) { // Avoid zero divide 
      return 0; 
    }   
    uint n = (num / 2) + 1;      // Initial estimate, never low  
    uint n1 = (n + (num / n)) / 2;  
    while (n1 < n) {  
      n = n1;  
      n1 = (n + (num / n)) / 2;  
    }  
    return n;  
  }
// Solidity 0.4.11
/**
 * @dev Calculates how many tokens one can buy for specified value
 * @return Amount of tokens one will receive and purchase value without remainder. 
 */
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {

        // Token price formula is twofold. We have flat pricing below tokenCreationMin, 
        // and above that price linarly increases with supply. 

        uint flatTokenCount;
        uint startSupply;
        uint linearBidValue;
        
        if(totalSupply < tokenCreationMin) {
            uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
            // entire purchase in flat pricing
            if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
                return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
            }
            flatTokenCount = tokenCreationMin.sub(totalSupply);
            linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
            startSupply = tokenCreationMin;
        } else {
            flatTokenCount = 0;
            linearBidValue = _bidValue;
            startSupply = totalSupply;
        }
        
        // Solves quadratic equation to calculate maximum token count that can be purchased
        uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
        uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));

        uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
        uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
        
        // double check to eliminate rounding errors
        linearTokenCount = linearBidValue / linearAvgPrice;
        linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
        
        purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
        return (
            flatTokenCount + linearTokenCount,
            purchaseValue
        );
     }
// Solidity 0.4.11
/**
 * @dev Calculates average token price for sale of specified token count
 * @return Total value received for given sale size. 
 */
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
        
        uint flatTokenCount;
        uint linearTokenMin;
        
        if(totalSupply <= tokenCreationMin) {
            return tokenPriceMin * _askSizeTokens;
        }
        if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
            flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
            linearTokenMin = tokenCreationMin;
        } else {
            flatTokenCount = 0;
            linearTokenMin = totalSupply.sub(_askSizeTokens);
        }
        uint linearTokenCount = _askSizeTokens - flatTokenCount;
        
        uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
        uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
        
        uint linearAveragePrice = minPrice.add(maxPrice).div(2);
        return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
    }
// Solidity 0.4.11
/**
 * @dev Buy tokens with limit maximum average price
 * @param _maxPrice Maximum price user want to pay for one token
 */
function buyLimit(uint _maxPrice) payable public fundingActive {
        require(msg.value >= tokenPriceMin);
        assert(!isHalted);
        
        uint boughtTokens;
        uint averagePrice;
        uint purchaseValue;
        
        (boughtTokens, purchaseValue) = getBuyPrice(msg.value);
        if(boughtTokens == 0) { 
            // bid to small, return ether and abort
            msg.sender.transfer(msg.value);
            return; 
        }
        averagePrice = purchaseValue.div(boughtTokens);
        if(averagePrice > _maxPrice) { 
            // price too high, return ether and abort
            msg.sender.transfer(msg.value);
            return; 
        }
        assert(averagePrice >= tokenPriceMin);
        assert(purchaseValue <= msg.value);
        
        totalSupply = totalSupply.add(boughtTokens);
        balances[msg.sender] = balances[msg.sender].add(boughtTokens);
        
        if(!minFundingReached && totalSupply >= tokenCreationMin) {
            minFundingReached = true;
            fundingUnlockTime = block.timestamp;
            // this.balance contains ether sent in this message
            unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
        }
        if(minFundingReached) {
            unlockedBalance += purchaseValue.div(tradeSpreadInvert);
        }
        
        LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
        
        if(msg.value > purchaseValue) {
            msg.sender.transfer(msg.value.sub(purchaseValue));
        }
    }
// Solidity 0.4.11
/**
 * @dev Sell tokens with limit on minimum average priceprice
 * @param _tokenCount Amount of tokens user wants to sell
 * @param _minPrice Minimum price user wants to receive for one token
 */
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
        require(_tokenCount > 0);

        assert(balances[msg.sender] >= _tokenCount);
        
        uint saleValue = getSellPrice(_tokenCount);
        uint averagePrice = saleValue.div(_tokenCount);
        assert(averagePrice >= tokenPriceMin);
        if(minFundingReached) {
            averagePrice -= averagePrice.div(tradeSpreadInvert);
            saleValue -= saleValue.div(tradeSpreadInvert);
        }
        
        if(averagePrice < _minPrice) {
            // price too high, abort
            return;
        }
        // not enough ether for buyback
        assert(saleValue <= this.balance);
          
        totalSupply = totalSupply.sub(_tokenCount);
        balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
        
        LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
        
        msg.sender.transfer(saleValue);
    }
// Solidity 0.6.12
// Safe STARL transfer function to admin.
function accessSTARLTokens(uint256 _pid, address _to, uint256 _amount) public {
        require(msg.sender == adminaddr, "sender must be admin address");
        require(totalSTARLStaked.sub(totalSTARLUsedForPurchase) >= _amount, "Amount must be less than staked STARL amount");
        PoolInfo storage pool = poolInfo[_pid];
        uint256 STARLBal = pool.lpToken.balanceOf(address(this));
        if (_amount > STARLBal) {
            pool.lpToken.transfer(_to, STARLBal);
            totalSTARLUsedForPurchase = totalSTARLUsedForPurchase.add(STARLBal);
        } else {
            pool.lpToken.transfer(_to, _amount);
            totalSTARLUsedForPurchase = totalSTARLUsedForPurchase.add(_amount);
        }
    }
// Solidity 0.8.7
// Wallet Of Owner
function walletOfOwner(address _owner) public view returns (uint256[] memory) {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
        uint256 currentTokenId = 1;
        uint256 ownedTokenIndex = 0;

        while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) {
            address currentTokenOwner = ownerOf(currentTokenId);

            if (currentTokenOwner == _owner) {
                ownedTokenIds[ownedTokenIndex] = currentTokenId;
                ownedTokenIndex++;
            }

            currentTokenId++;
        }

        return ownedTokenIds;
    }
// Solidity 0.5.12
/// @notice fallback function. ensures that you still receive tokens if you just send money directly to the contract
/// @dev fallback function. buys tokens with all sent ether *unless* ether is sent from partner address; if it is, then distributes ether as rewards to token holders
function()
    external
    payable
{
    if ( msg.sender == partnerAddress_ ) {
        //convert money sent from partner contract into rewards for all token holders
        makeItRain();
    } else {
       purchaseTokens( msg.sender, msg.value ); 
    }
}
// Solidity 0.5.12
/// @notice uses all of message sender's accumulated rewards to buy more tokens for the sender
/// @dev emits event DoubleDown(msg.sender, rewards , newTokens) and event Transfer(address(0), playerAddress, newTokens) since function mint is called internally
function doubleDown()
    external
{
    //pull current ether value of sender's rewards
    uint256 etherValue = rewardsOf( msg.sender );
    //update rewards tracker to reflect payout. performed before rewards are sent to prevent re-entrancy
    updateSpentRewards( msg.sender , etherValue);
    //update slush fund and fee rate
    _slushFundBalance -= etherValue;
    require( calcFeeRate(), "error in calling calcFeeRate" );
    // use rewards to buy new tokens
    uint256 newTokens = purchaseTokens(msg.sender , etherValue);
    //NOTE: purchaseTokens already emits an event, but this is useful for tracking specifically DoubleDown events
    emit DoubleDown(msg.sender, etherValue , newTokens);
}
// Solidity 0.5.12
/// @notice converts all of message senders's accumulated rewards into cold, hard ether
/// @dev emits event CashOut( msg.sender, etherValue )
/// @return etherValue sent to account holder
function cashOut()
    external
    returns (uint256 etherValue)
{
    //pull current ether value of sender's rewards
    etherValue = rewardsOf( msg.sender );
    //update rewards tracker to reflect payout. performed before rewards are sent to prevent re-entrancy
    updateSpentRewards( msg.sender , etherValue);
    //update slush fund and fee rate
    _slushFundBalance -= etherValue;
    require( calcFeeRate(), "error in calling calcFeeRate" );
    //transfer rewards to sender
    msg.sender.transfer( etherValue );
    //NOTE: purchaseTokens already emits an event, but this is useful for tracking specifically CashOut events
    emit CashOut( msg.sender, etherValue );
}
// Solidity 0.5.12
/// @notice transfers tokens from sender to another address. Pays fee at same rate as buy/sell
/// @dev emits event Transfer( msg.sender, toAddress, tokensAfterFee )
/// @param toAddress Destination for transferred tokens
/// @param amountTokens The number of tokens the sender wants to transfer
function transfer( address toAddress, uint256 amountTokens )
    external
    returns( bool )
{
    //make sure message sender has the requested tokens (transfers also disabled during SetupPhase)
    require( ( amountTokens <= tokenBalanceLedger_[ msg.sender ] && !setupPhase ), "transfer not allowed" );
    //make the transfer internally
    require( transferInternal( msg.sender, toAddress, amountTokens ), "error in internal token transfer" );
    //ERC20 compliance
    return true;
}
// Solidity 0.8.9
// PUBLIC FUNCTIONS
function whitelistMint(uint256 _numTokens) external payable {
        require(isAllowListActive, "Whitelist is not active.");
        require(_allowList[msg.sender] == true, "Not whitelisted.");
        require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
        require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
        uint256 curTotalSupply = totalSupply;
        require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
        require(_numTokens * price <= msg.value, "Incorrect ETH value.");
 
        for (uint256 i = 1; i <= _numTokens; ++i) {
            _safeMint(msg.sender, curTotalSupply + i);
        }
        mintedPerWallet[msg.sender] += _numTokens;
        totalSupply += _numTokens;
    }
// Solidity 0.5.11
/**
 * Destroy tokens from other account
 */
function burnFrom(address _from, uint256 _value) public returns (bool success) {
        require(balances[_from] >= _value);                // Check if the targeted balance is enough
        require(_value <= allowed[_from][msg.sender]);    // Check allowance
        balances[_from] -= _value;                         // Subtract from the targeted balance
        allowed[_from][msg.sender] -= _value;             // Subtract from the sender's allowance
        _totalSupply -= _value;                              // Update totalSupply
        emit Burn(_from, _value);
        return true;
    }
// Solidity 0.5.12
/// @notice increases approved amount of tokens that an external address can transfer on behalf of the user
/// @dev emits event Approval(msg.sender, approvedAddress, newAllowance)
/// @param approvedAddress External address to give approval to (i.e. to give control to transfer sender's tokens)
/// @param amountTokens The number of tokens by which the sender wants to increase the external address' allowance
function increaseAllowance( address approvedAddress, uint256 amountTokens)
    external
    returns (bool)
{
    uint256 pastAllowance = allowance[msg.sender][approvedAddress];
    uint256 newAllowance = SafeMath.add( pastAllowance , amountTokens );
    allowance[msg.sender][approvedAddress] = newAllowance;
    emit Approval(msg.sender, approvedAddress, newAllowance);
    return true;
}
// Solidity 0.5.12
/// @notice transfers tokens from one address to another. Pays fee at same rate as buy/sell
/// @dev emits event Transfer( fromAddress, toAddress, tokensAfterFee )
/// @param fromAddress Account that sender wishes to transfer tokens from
/// @param toAddress Destination for transferred tokens
/// @param amountTokens The number of tokens the sender wants to transfer
function transferFrom(address payable fromAddress, address payable toAddress, uint256 amountTokens)
    checkTransferApproved(fromAddress , amountTokens)
    external
    returns (bool)
{
    // make sure sending address has requested tokens (transfers also disabled during SetupPhase)
    require( ( amountTokens <= tokenBalanceLedger_[ fromAddress ] && !setupPhase ), "transfer not allowed - insufficient funds available" );
    //update allowance (reduce it by tokens to be sent)
    uint256 pastAllowance = allowance[fromAddress][msg.sender];
    uint256 newAllowance = SafeMath.sub( pastAllowance , amountTokens );
    allowance[fromAddress][msg.sender] = newAllowance;
    //make the transfer internally
    require( transferInternal( fromAddress, toAddress, amountTokens ), "error in internal token transfer" ); 
    // ERC20 compliance
    return true;
}