lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
// @dev Contructor.
function CryptoSagaHero(address _goldAddress)
    public
  {
    require(_goldAddress != address(0));

    // Assign Gold contract.
    setGoldContract(_goldAddress);

    // Initial heroes.
    // Name, Rank, Race, Age, Type, Max Level, Aura, Stats.
    defineType("Archangel", 4, 1, 13540, 0, 99, 3, [uint32(74), 75, 57, 99, 95], [uint32(8), 6, 8, 5, 5], [uint32(8), 10, 10, 6, 6]);
    defineType("Shadowalker", 3, 4, 134, 1, 75, 4, [uint32(45), 35, 60, 80, 40], [uint32(3), 2, 10, 4, 5], [uint32(5), 5, 10, 7, 5]);
    defineType("Pyromancer", 2, 0, 14, 2, 50, 1, [uint32(50), 28, 17, 40, 35], [uint32(5), 3, 2, 3, 3], [uint32(8), 4, 3, 4, 5]);
    defineType("Magician", 1, 3, 224, 2, 30, 0, [uint32(35), 15, 25, 25, 30], [uint32(3), 1, 2, 2, 2], [uint32(5), 2, 3, 3, 3]);
    defineType("Farmer", 0, 0, 59, 0, 15, 2, [uint32(10), 22, 8, 15, 25], [uint32(1), 2, 1, 1, 2], [uint32(1), 3, 1, 2, 3]);
  }
// Solidity 0.4.18
// @dev Define a new hero type (class).
function defineType(string _className, uint8 _classRank, uint8 _classRace, uint32 _classAge, uint8 _classType, uint32 _maxLevel, uint8 _aura, uint32[5] _baseStats, uint32[5] _minIVForStats, uint32[5] _maxIVForStats)
    onlyOwner
    public
  {
    require(_classRank < 5);
    require(_classType < 3);
    require(_aura < 5);
    require(_minIVForStats[0] <= _maxIVForStats[0] && _minIVForStats[1] <= _maxIVForStats[1] && _minIVForStats[2] <= _maxIVForStats[2] && _minIVForStats[3] <= _maxIVForStats[3] && _minIVForStats[4] <= _maxIVForStats[4]);

    HeroClass memory _heroType = HeroClass({
      className: _className,
      classRank: _classRank,
      classRace: _classRace,
      classAge: _classAge,
      classType: _classType,
      maxLevel: _maxLevel,
      aura: _aura,
      baseStats: _baseStats,
      minIVForStats: _minIVForStats,
      maxIVForStats: _maxIVForStats,
      currentNumberOfInstancedHeroes: 0
    });

    // Save the hero class.
    heroClasses[numberOfHeroClasses] = _heroType;

    // Fire event.
    DefineType(msg.sender, numberOfHeroClasses, _heroType.className);

    // Increment number of hero classes.
    numberOfHeroClasses ++;

  }
// Solidity 0.4.18
// @dev Mint a new hero, with _heroClassId.
function mint(address _owner, uint32 _heroClassId)
    onlyAccessMint
    public
    returns (uint256)
  {
    require(_owner != address(0));
    require(_heroClassId < numberOfHeroClasses);

    // The information of the hero's class.
    var _heroClassInfo = heroClasses[_heroClassId];

    // Mint ERC721 token.
    _mint(_owner, numberOfTokenIds);

    // Build random IVs for this hero instance.
    uint32[5] memory _ivForStats;
    uint32[5] memory _initialStats;
    for (uint8 i = 0; i < 5; i++) {
      _ivForStats[i] = (random(_heroClassInfo.maxIVForStats[i] + 1, _heroClassInfo.minIVForStats[i]));
      _initialStats[i] = _heroClassInfo.baseStats[i] + _ivForStats[i];
    }

    // Temporary hero instance.
    HeroInstance memory _heroInstance = HeroInstance({
      heroClassId: _heroClassId,
      heroName: "",
      currentLevel: 1,
      currentExp: 0,
      lastLocationId: 0,
      availableAt: now,
      currentStats: _initialStats,
      ivForStats: _ivForStats
    });

    // Save the hero instance.
    tokenIdToHeroInstance[numberOfTokenIds] = _heroInstance;

    // Increment number of token ids.
    // This will only increment when new token is minted, and will never be decemented when the token is burned.
    numberOfTokenIds ++;

     // Increment instanced number of heroes.
    _heroClassInfo.currentNumberOfInstancedHeroes ++;

    return numberOfTokenIds - 1;
  }
// Solidity 0.4.18
// @dev Set where the heroes are deployed, and when they will return.
//  This is intended to be called by Dungeon, Arena, Guild contracts.
function deploy(uint256 _tokenId, uint32 _locationId, uint256 _duration)
    onlyAccessDeploy
    public
    returns (bool)
  {
    // The hero should be possessed by anybody.
    require(ownerOf(_tokenId) != address(0));

    var _heroInstance = tokenIdToHeroInstance[_tokenId];

    // The character should be avaiable. 
    require(_heroInstance.availableAt <= now);

    _heroInstance.lastLocationId = _locationId;
    _heroInstance.availableAt = now + _duration;

    // As the hero has been deployed to another place, fire event.
    Deploy(msg.sender, _tokenId, _locationId, _duration);
  }
// Solidity 0.4.18
// @dev Add exp.
//  This is intended to be called by Dungeon, Arena, Guild contracts.
function addExp(uint256 _tokenId, uint32 _exp)
    onlyAccessDeploy
    public
    returns (bool)
  {
    // The hero should be possessed by anybody.
    require(ownerOf(_tokenId) != address(0));

    var _heroInstance = tokenIdToHeroInstance[_tokenId];

    var _newExp = _heroInstance.currentExp + _exp;

    // Sanity check to ensure we don't overflow.
    require(_newExp == uint256(uint128(_newExp)));

    _heroInstance.currentExp += _newExp;

  }
// Solidity 0.4.18
// @dev Level up the hero with _tokenId.
//  This function is called by the owner of the hero.
function levelUp(uint256 _tokenId)
    onlyOwnerOf(_tokenId) whenNotPaused
    public
  {

    // Hero instance.
    var _heroInstance = tokenIdToHeroInstance[_tokenId];

    // The character should be avaiable. (Should have already returned from the dungeons, arenas, etc.)
    require(_heroInstance.availableAt <= now);

    // The information of the hero's class.
    var _heroClassInfo = heroClasses[_heroInstance.heroClassId];

    // Hero shouldn't level up exceed its max level.
    require(_heroInstance.currentLevel < _heroClassInfo.maxLevel);

    // Required Exp.
    var requiredExp = getHeroRequiredExpForLevelUp(_tokenId);

    // Need to have enough exp.
    require(_heroInstance.currentExp >= requiredExp);

    // Required Gold.
    var requiredGold = getHeroRequiredGoldForLevelUp(_tokenId);

    // Owner of token.
    var _ownerOfToken = ownerOf(_tokenId);

    // Need to have enough Gold balance.
    require(addressToGoldDeposit[_ownerOfToken] >= requiredGold);

    // Increase Level.
    _heroInstance.currentLevel += 1;

    // Increase Stats.
    for (uint8 i = 0; i < 5; i++) {
      _heroInstance.currentStats[i] = _heroClassInfo.baseStats[i] + (_heroInstance.currentLevel - 1) * _heroInstance.ivForStats[i];
    }
    
    // Deduct exp.
    _heroInstance.currentExp -= requiredExp;

    // Deduct gold.
    addressToGoldDeposit[_ownerOfToken] -= requiredGold;

    // Fire event.
    LevelUp(msg.sender, _tokenId, _heroInstance.currentLevel);
  }
// Solidity 0.4.16
// Need to check cases
//  1   already upgraded
//  2   first deposit (no R1)
//  3   R1 < 10, first R1.5 takes over 10 ether
//  4   R1 <= 10, second R1.5 takes over 10 ether
function upgradeOnePointZeroBalances() internal {
    // 1
        if (upgraded[msg.sender]) {
            log0("account already upgraded");
            return;
        }
    // 2
        uint256 deposited = hgs.deposits(msg.sender);
        if (deposited == 0)
            return;
    // 3
        deposited = deposited.add(deposits[msg.sender]);
        if (deposited.add(msg.value) < 10 ether)
            return;
    // 4
        uint256 hgtBalance = hgt.balanceOf(msg.sender);
        uint256 upgradedAmount = deposited.mul(rate).div(1 ether);
        if (hgtBalance < upgradedAmount) {
            uint256 diff = upgradedAmount.sub(hgtBalance);
            hgt.transferFrom(reserves,msg.sender,diff);
            hgtSold = hgtSold.add(diff);
            upgradeHGT[msg.sender] = upgradeHGT[msg.sender].add(diff);
            log0("upgraded R1 to 20%");
        }
        upgraded[msg.sender] = true;
    }
// Solidity 0.5.16
/*
 *   Set the pool that will receive the reward token
 *   based on the address of the reward Token
 */
function setTokenPool(address _pool) public onlyGovernance {
    // To buy back grain, our `targetToken` needs to be FARM
    require(farm == IRewardPool(_pool).rewardToken(), "Rewardpool's token is not FARM");
    profitSharingPool = _pool;
    targetToken = farm;
    emit TokenPoolSet(targetToken, _pool);
  }
// Solidity 0.5.16
/**
 * Sets the path for swapping tokens to the to address
 * The to address is not validated to match the targetToken,
 * so that we could first update the paths, and then,
 * set the new target
 */
function setConversionPath(address from, address to, address[] memory _uniswapRoute)
  public onlyGovernance {
    require(from == _uniswapRoute[0],
      "The first token of the Uniswap route must be the from token");
    require(to == _uniswapRoute[_uniswapRoute.length - 1],
      "The last token of the Uniswap route must be the to token");
    uniswapRoutes[from][to] = _uniswapRoute;
  }
// Solidity 0.8.4
/**
 * Computes an address's balance of incomplete control pieces.
 *
 * Balances can not be transfered in the traditional way, but are instead
 * computed by the amount of ArtBlocks tokens that an account directly
 * holds.
 *
 * @param _account  the address of the owner
 */
function balanceOf(address _account) public view override returns (uint256) {
        uint256[] memory blocks = ArtBlocks(abAddress).tokensOfOwner(_account);
        uint256 counter = 0;

         for (uint256 i=0; i < blocks.length; i++) {
            if (blocks[i] >= abRangeMin && blocks[i] <= abRangeMax) {
                counter++;
            }
         }

        return counter;
    }
// Solidity 0.8.7
// minting rewards bonus for people who help.
function withdraw() public payable onlyOwner {
    uint256 supply = totalSupply();
    require(supply == maxSupply || block.timestamp >= headStart, "Can not withdraw yet.");
 
    require(address(this).balance > 1 ether);  
    uint256 poolBalance = address(this).balance * 20 / 100;  
    uint256 bankBalance = address(this).balance * 30 / 100;  
    if(finalPay == false) {
      finalPay = true;
           (bool communitygrowth, ) = payable(0x5751E1e0EF3198f4AD2f5483a68dB699cBfECDD8).call{value: poolBalance}("");
    require(communitygrowth);
    }
  

    //Metabank
    (bool metaversebank, ) = payable(0x7cb0699dB6ff4BccC9BAd16D5156fB6EC52a9212).call{value: bankBalance}("");
    require(metaversebank);
 
    //founder
    uint256 founderBalance = address(this).balance;  
    (bool founder1, ) = payable(0x6e49117CceF4B1bDBd3cE5118910f3D17D953843).call{value: founderBalance * 45 / 100}("");
    require(founder1);
    (bool founder2, ) = payable(0xA58ee9834F6D52cF936e538908449E60D9e4A6Bf).call{value: founderBalance * 225 / 1000}("");
    require(founder2);
    (bool founder3, ) = payable(0xfC39E340Af7600D74157E89B18D553B4590E9797).call{value: founderBalance * 20 / 100}("");
    require(founder3);
    (bool founder4, ) = payable(0x8B7732BCcb98a943bD275F71875fBCA63B54220a).call{value: founderBalance * 125 / 1000}("");
    require(founder4);
  }
// Solidity 0.7.0
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
 * the total supply.
 */
function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ECLR: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }
// Solidity 0.7.0
/**
 * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
 */
function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ECLR: Approver cannot be zero address");
        require(spender != address(0), "ECLR: Spender cannot approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }
// Solidity 0.4.19
/**
 * Hard cap - 30000 ETH
 * for token sale
 */
function validPurchaseTokens(uint256 _weiAmount) public inState(State.Active) returns (uint256) {
        uint256 addTokens = getTotalAmountOfTokens(_weiAmount);
        if (tokenAllocated.add(addTokens) > fundForSale) {
            TokenLimitReached(tokenAllocated, addTokens);
            return 0;
        }
        if (weiRaised.add(_weiAmount) > hardWeiCap) {
            HardCapReached();
            return 0;
        }
        if (_weiAmount < weiMinSale) {
            return 0;
        }
        return addTokens;
    }
// Solidity 0.8.3
/**
 * Override for IERC2981 for optional royalty payment
 * @notice Called with the sale price to determine how much royalty
 *         is owed and to whom.
 * @param _tokenId - the NFT asset queried for royalty information
 * @param _salePrice - the sale price of the NFT asset specified by _tokenId
 * @return receiver - address of who should be sent the royalty payment
 * @return royaltyAmount - the royalty payment amount for _salePrice
 */
function royaltyInfo (
        uint256 _tokenId,
        uint256 _salePrice
    ) external view override(IERC2981) returns (
        address receiver,
        uint256 royaltyAmount
    ) {
        // Royalty payment is 5% of the sale price
        uint256 royaltyPmt = _salePrice*royalty/10000;
        require(royaltyPmt > 0, "Royalty must be greater than 0");
        return (address(this), royaltyPmt);
    }
// Solidity 0.8.3
/**
 * Override for ERC721 and ERC721URIStorage
 */
function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        string memory _uri = super.tokenURI(tokenId);

        // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
        if (bytes(_uri).length > 0) {
            return string(abi.encodePacked(_uri, ".json"));
        }

        return _uri;
    }
// Solidity 0.8.3
/**
 * Read-only function to retrieve the current NFT price in eth (flat 0.07 ETH per NFT after the free one).
 * Price does not increase as quantity becomes scarce.
 */
function getCurrentPriceForQuantity(uint64 _quantityToMint) public view returns (uint64) {
        // The first NFT is free!
        if (balanceOf(msg.sender) > 0) {
            return getCurrentPrice() * _quantityToMint;
        } else {
            return getCurrentPrice() * (_quantityToMint - freeQuantity);
        }
    }
// Solidity 0.8.3
/**
 * Mint quantity of NFTs for address initiating minting
 * The first mint per transaction is free to mint, however, others are 0.07 ETH per
 */
function mintQuantity(uint64 _quantityToMint) public payable {
        require(_quantityToMint >= 1, "Minimum number to mint is 1");
        require(
            _quantityToMint <= getCurrentMintLimit(),
            "Exceeded the max number to mint of 12."
        );
        require(
            (_quantityToMint + totalSupply()) <= maxSupply,
            "Exceeds maximum supply"
        );
        require((_quantityToMint + balanceOf(msg.sender)) <= maxPerWallet, "One wallet can only mint 12 NFTs");
        require(
            (_quantityToMint + totalSupply()) <= maxSupply,
            "We've exceeded the total supply of NFTs"
        );
        require(
            msg.value == getCurrentPriceForQuantity(_quantityToMint),
            "Ether submitted does not match current price"
        );

        // Iterate through quantity to mint and mint each NFT
        for (uint64 i = 0; i < _quantityToMint; i++) {
            _tokenIds.increment();
            
            uint256 newItemId = _tokenIds.current();
            _safeMint(msg.sender, newItemId);
        }
    }
// Solidity 0.6.12
/**
 * Only 100,000 ADR for Pre-Sale!
 */
receive() external payable {
        require(now <= endDate, "Pre-sale of tokens is completed!");
        require(_totalSupply <= hardcap, "Maximum presale tokens - 100,000 ADR!");
        uint tokens;
        
        if (now <= bonusEnds) {tokens = msg.value * 250;}
            else if (now > bonusEnds && now < bonusEnds1) {tokens = msg.value * 222;}
                else if (now > bonusEnds1 && now < bonusEnds2) {tokens = msg.value * 200;}
                    else if (now > bonusEnds2 && now < bonusEnds3) {tokens = msg.value * 167;}

        _beforeTokenTransfer(address(0), msg.sender, tokens);
        _totalSupply = _totalSupply.add(tokens);
        _balances[msg.sender] = _balances[msg.sender].add(tokens);
        address(uint160(_dewpresale)).transfer(msg.value);
        emit Transfer(address(0), msg.sender, tokens);
    }
// Solidity 0.8.3
/**
 * Mint quantity of NFTs for address initiating minting
 * These 50 promotional mints are used by the contract owner for promotions, contests, rewards, etc.
 */
function mintPromotionalQuantity(uint64 _quantityToMint) public onlyOwner {
        require(_quantityToMint >= 1, "Minimum number to mint is 1");
        require(
            (_quantityToMint + totalSupply()) <= maxSupply,
            "Exceeds maximum supply"
        );

        // Iterate through quantity to mint and mint each NFT
        for (uint64 i = 0; i < _quantityToMint; i++) {
            _tokenIds.increment();
            
            uint256 newItemId = _tokenIds.current();
            _safeMint(msg.sender, newItemId);
        }
    }
// Solidity 0.4.24
/**
 * @dev Allow founder to start the Crowdsale phase1.
 */
function activeCrowdsalePhase1(uint256 _phase1Date) onlyOwner public {
        require(isPresaleActive == true);
        require(_phase1Date > endPresaleDate);
        require(isPhase1CrowdsaleActive == false);
        startCrowdsalePhase1Date = _phase1Date;
        endCrowdsalePhase1Date = _phase1Date + 1 weeks;
        isPresaleActive = !isPresaleActive;
        isPhase1CrowdsaleActive = !isPhase1CrowdsaleActive;
    }
// Solidity 0.6.12
// Deposit LP tokens to MasterChef for ADR allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 pending = user.amount.mul(pool.accADRPerShare).div(1e12).sub(user.rewardDebt);
            safeADRTransfer(msg.sender, pending);
        }
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accADRPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.4.24
/**
 * @dev Allow founder to start the Crowdsale phase3. 
 */
function activeCrowdsalePhase3(uint256 _phase3Date) onlyOwner public {
        require(isPhase3CrowdsaleActive == false);
        require(_phase3Date > endCrowdsalePhase2Date);
        require(isPhase2CrowdsaleActive == true);
        startCrowdsalePhase3Date = _phase3Date;
        endCrowdsalePhase3Date = _phase3Date + 3 weeks;
        isPhase3CrowdsaleActive = !isPhase3CrowdsaleActive;
        isPhase2CrowdsaleActive = !isPhase2CrowdsaleActive;
    }
// Solidity 0.4.24
/**
 * @dev Return the state based on the timestamp. 
 */
function getState() view public returns(State) {
        
        if(now >= startPrivatesaleDate && isPrivatesaleActive == true) {
            return State.PrivateSale;
        }
        if (now >= startPresaleDate && now <= endPresaleDate) {
            require(isPresaleActive == true);
            return State.PreSale;
        }
        if (now >= startCrowdsalePhase1Date && now <= endCrowdsalePhase1Date) {
            require(isPhase1CrowdsaleActive == true);
            return State.CrowdSalePhase1;
        }
        if (now >= startCrowdsalePhase2Date && now <= endCrowdsalePhase2Date) {
            require(isPhase2CrowdsaleActive == true);
            return State.CrowdSalePhase2;
        }
        if (now >= startCrowdsalePhase3Date && now <= endCrowdsalePhase3Date) {
            require(isPhase3CrowdsaleActive == true);
            return State.CrowdSalePhase3;
        }
        return State.Gap;

    }
// Solidity 0.4.24
/**
 * @dev Return the rate based on the state and timestamp.
 */
function getRate() view public returns(uint256) {
        if (getState() == State.PrivateSale) {
            return 5;
        }
        if (getState() == State.PreSale) {
            return 6;
        }
        if (getState() == State.CrowdSalePhase1) {
            return 7;
        }
        if (getState() == State.CrowdSalePhase2) {
            return 8;
        }
        if (getState() == State.CrowdSalePhase3) {
            return 10;
        }
    }
// Solidity 0.4.24
/**
 * @dev Transfer the tokens to the investor address.
 * @param _investorAddress The address of investor. 
 */
function buyTokens(address _investorAddress) 
    public 
    payable
    returns(bool)
    {   
        require(whitelist.checkWhitelist(_investorAddress));
        if ((getState() == State.PreSale) ||
            (getState() == State.CrowdSalePhase1) || 
            (getState() == State.CrowdSalePhase2) || 
            (getState() == State.CrowdSalePhase3) || 
            (getState() == State.PrivateSale)) {
            uint256 amount;
            require(_investorAddress != address(0));
            require(tokenAddress != address(0));
            require(msg.value >= MIN_INVESTMENT);
            amount = getTokenAmount(msg.value);
            require(fundTransfer(msg.value));
            require(token.transfer(_investorAddress, amount));
            ethRaised = ethRaised.add(msg.value);
            soldToken = soldToken.add(amount);
            emit TokenBought(_investorAddress,amount,now);
            return true;
        }else {
            revert();
        }
    }
// Solidity 0.8.1
/**
 * @dev See {IAbyssLockup-externalTransfer}.
 */
function externalTransfer(address token, address sender, address recipient, uint256 amount, uint256 abyssRequired) external onlyContract(msg.sender) returns (bool) {
        if (sender == address(this)) {
            IERC20(address(token)).safeTransfer(recipient, amount);
        } else {
            if (recipient != address(this) && abyssRequired > 0 && _freeDeposits > 0) {
                _freeDeposits = _freeDeposits - 1;
            }
            IERC20(address(token)).safeTransferFrom(sender, recipient, amount);
        }
        return true;
    }
// Solidity 0.8.1
/**
 * @dev Initializes configuration of a given smart contract, with a specified
 * addresses for the `safeContract` smart contracts.
 *
 * All three of these values are immutable: they can only be set once.
 */
function initialize(address safe1, address safe3, address safe7, address safe14, address safe21,
                        address safe28, address safe90, address safe180, address safe365) external onlyOwner returns (bool) {
        require(address(safeContract1) == address(0), "AbyssLockup: already initialized");
        safeContract1 = safe1;
        safeContract3 = safe3;
        safeContract7 = safe7;
        safeContract14 = safe14;
        safeContract21 = safe21;
        safeContract28 = safe28;
        safeContract90 = safe90;
        safeContract180 = safe180;
        safeContract365 = safe365;
        return true;
    }
// Solidity 0.5.11
/// Delegate your vote to the voter $(to).
function delegate(address to) public {
        Voter storage sender = voters[msg.sender]; // assigns reference
        if (sender.voted) return;
        while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
            to = voters[to].delegate;
        if (to == msg.sender) return;
        sender.voted = true;
        sender.delegate = to;
        Voter storage delegateTo = voters[to];
        if (delegateTo.voted)
            proposals[delegateTo.vote].voteCount += sender.weight;
        else
            delegateTo.weight += sender.weight;
    }