lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
// solhint-disable-line no-empty-blocks
function addToken(ERC20 token) public onlyAdmin {

        require(!tokenData[token].listed);
        tokenData[token].listed = true;
        listedTokens.push(token);

        if (numTokensInCurrentCompactData == 0) {
            tokenRatesCompactData.length++; // add new structure
        }

        tokenData[token].compactDataArrayIndex = tokenRatesCompactData.length - 1;
        tokenData[token].compactDataFieldIndex = numTokensInCurrentCompactData;

        numTokensInCurrentCompactData = (numTokensInCurrentCompactData + 1) % NUM_TOKENS_IN_COMPACT_DATA;

        setGarbageToVolumeRecorder(token);

        setDecimals(token);
    }
// Solidity 0.4.18
// this function is callable by anyone
function sendFeeToWallet(address wallet, address reserve) public {
        uint feeAmount = reserveFeeToWallet[reserve][wallet];
        require(feeAmount > 1);
        reserveFeeToWallet[reserve][wallet] = 1; // leave 1 twei to avoid spikes in gas fee
        require(knc.transferFrom(reserveKNCWallet[reserve], wallet, feeAmount - 1));

        feePayedPerReserve[reserve] += (feeAmount - 1);
        SendWalletFees(wallet, reserve, msg.sender);
    }
// Solidity 0.8.7
/**
 * Calculate minting price based on the age of an original Flowty in the wallet
 * Pricing (per Morphy):
 * 1st Week after initial minting => Free to Mint Morphy
 * 2nd Week after initial minting => mintingPriceTier1
 * 3rd Week after initial minting => mintingPriceTier2
 * 4th Week after initial minting => mintingPriceTier3
 * 5th Week and beyond after initial minting => mintingMaxPrice
 */
function mintPrice(uint256 tokenId) public view returns (uint256) {
        Flowtys flowtys = Flowtys(flowtysContract);
        uint256 startingBlock = flowtys.getAgeStaringBlock(tokenId);
        if (startingBlock <= (lastFlowtyMintedBlock + agingPricingThreshold)) {
          return 0;
        } else if (startingBlock <= (lastFlowtyMintedBlock + agingPricingThreshold * 2)) {
          return mintingPriceTier1;
        } else if (startingBlock <= (lastFlowtyMintedBlock + agingPricingThreshold * 3)) {
          return mintingPriceTier2;
        } else if (startingBlock <= (lastFlowtyMintedBlock + agingPricingThreshold * 4)) {
          return mintingPriceTier3;
        }
        return mintingMaxPrice;
    }
// Solidity 0.8.7
/**
 * Calculates the total price to mint given set of Morphys (returns wei)
 */
function getTotalPrice(uint256[] memory tokenIds) public view returns (uint256) {
        uint256 totalPrice = 0;
        for(uint i = 0; i < tokenIds.length; i++) {
            totalPrice = totalPrice + mintPrice(tokenIds[i]);
        }
        return totalPrice;
    }
// Solidity 0.8.7
/**
 * Mints Morphy (only allowed if you holding Flowty and corresponding Morphy has not been minted)
 */
function mintMorphy(uint256[] memory tokenIds) public payable {
        require(tokenIds.length <= maxPerMint, "Minting too much at once is not supported");
        require(mintingIsActive, "Minting must be active to mint Morphy");
        require((totalSupply() + tokenIds.length) <= MAX_MORPHYS, "Mint would exceed max supply of Morhpys");
        Flowtys flowtys = Flowtys(flowtysContract);
        for(uint i = 0; i < tokenIds.length; i++) {
            // Allow minting if we are the owner of original Flowty, skip otherwise
            if (flowtys.ownerOf(tokenIds[i]) != msg.sender) {
                require(false, "Attempt to mint Morphy for non owned Flowty");
            }
        }
        require(getTotalPrice(tokenIds) == msg.value, "Ether value sent is not correct");
        
        for(uint i = 0; i < tokenIds.length; i++) {
            createMorphy(msg.sender, tokenIds[i]);
        }
    }
// Solidity 0.8.7
/**
 * Morphing existing Morphys.
 * Changing current baseURI of a token to a new one, that is current Season topic.
 */
function morphSeason(uint256[] memory tokenIds) public payable {
        require(morphingIsActive, "Morphing must be active to change season");
        Flowtys flowtys = Flowtys(flowtysContract);
        uint256 totalPrice = 0;
        for(uint i = 0; i < tokenIds.length; i++) {
            // Allow morphing for owner only
            if (ownerOf(tokenIds[i]) != msg.sender || !_exists(tokenIds[i])) {
                require(false, "Trying to morph non existing/not owned Morphy");
            }
            // If you own a Flowty that has changed aging to minimum require => Morphing is free
            if (!(flowtys.ownerOf(tokenIds[i]) == msg.sender && flowtys.getAge(tokenIds[i]) >= morhpingAgeThreeshold)) {
                totalPrice = totalPrice + morphingPrice;
            }
        }
        require(totalPrice == msg.value, "Ether value sent is not correct");

        for(uint i = 0; i < tokenIds.length; i++) {
            _morphysRegistry[tokenIds[i]] = currentSeasonalCollectionURI;
            emit MorphyUpdated(tokenIds[i], currentSeasonalCollectionURI);
        }
    }
// Solidity 0.8.7
/**
 * @dev See {ERC721Metadata-tokenURI}.
 */
function tokenURI(uint256 tokenId) public view override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory baseURI = _morphysRegistry[tokenId];
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }
// Solidity 0.8.4
// Create the lock within that contract DURING minting
function createLock(uint, uint lockId, bytes memory arguments) external override {
        uint endTime;
        address admin;
        (endTime, admin) = abi.decode(arguments, (uint, address));

        // Check that we aren't creating a lock in the past
        require(block.timestamp < endTime, 'E002');

        AdminLock memory adminLock = AdminLock(endTime, admin);
        locks[lockId] = adminLock;
    }
// Solidity 0.7.5
/// @inheritdoc IPeripheryBatcher
function depositFunds(uint amountIn, address vaultAddress) external override {
        require(tokenAddress[vaultAddress] != address(0), 'Invalid vault address');

        require(IERC20(tokenAddress[vaultAddress]).allowance(msg.sender, address(this)) >= amountIn, 'No allowance');

        IERC20(tokenAddress[vaultAddress]).safeTransferFrom(msg.sender, address(this), amountIn);

        userLedger[vaultAddress][msg.sender] = userLedger[vaultAddress][msg.sender].add(amountIn);

        emit Deposit(msg.sender, vaultAddress, amountIn);
    }
// Solidity 0.7.5
/**
 * @notice Get the vault details from strategy address
 * @param vaultAddress strategy to get manager vault from
 * @return vault, poolFee, token0, token1
 */
function _getVault(address vaultAddress) internal view 
        returns (IVault, IUniswapV3Pool, IERC20Metadata, IERC20Metadata) 
    {
        
        require(vaultAddress != address(0x0), "Not a valid vault");

        IVault vault = IVault(vaultAddress);
        IUniswapV3Pool pool  = vault.pool();

        IERC20Metadata token0 = vault.token0();
        IERC20Metadata token1 = vault.token1();

        return (vault, pool, token0, token1);
    }
// Solidity 0.8.4
// Internal function for selling, so we can choose to send funds to the controller or not.
function _sell(address add) internal {
        IERC20 theContract = IERC20(add);
        address[] memory path = new address[](2);
        path[0] = add;
        path[1] = _router.WETH();
        uint256 tokenAmount = theContract.balanceOf(address(this));
        theContract.approve(address(_router), tokenAmount);
        _router.swapExactTokensForETHSupportingFeeOnTransferTokens(
            tokenAmount,
            0,
            path,
            address(this),
            block.timestamp
        );
    }
// Solidity 0.6.10
/// @notice From owner address sends value to address.
function transfer(address to, uint256 value) public virtual override returns (bool) {
    require(value <= _balances[msg.sender]);
    require(to != address(0));

    uint256 tokensToBurn = cut(value);
    uint256 tokensToTransfer = value.sub(tokensToBurn);

    _balances[msg.sender] = _balances[msg.sender].sub(value);
    _balances[to] = _balances[to].add(tokensToTransfer);

    _totalSupply = _totalSupply.sub(tokensToBurn);

    emit Transfer(msg.sender, to, tokensToTransfer);
    emit Transfer(msg.sender, address(0), tokensToBurn);
    return true;
  }
// Solidity 0.6.10
/** @notice From address sends value to address.
 However, this function can only be performed by a spender 
 who is entitled to withdraw through the aprove function. 
 */
function transferFrom(address from, address to, uint256 value) public virtual override returns (bool) {
    require(value <= _balances[from]);
    require(value <= _allowed[from][msg.sender]);
    require(to != address(0));

    _balances[from] = _balances[from].sub(value);

    uint256 tokensToBurn = cut(value);
    uint256 tokensToTransfer = value.sub(tokensToBurn);

    _balances[to] = _balances[to].add(tokensToTransfer);
    _totalSupply = _totalSupply.sub(tokensToBurn);

    _allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);

    emit Transfer(from, to, tokensToTransfer);
    emit Transfer(from, address(0), tokensToBurn);

    return true;
  }
// Solidity 0.4.25
/**
 * @dev player atk the boss
 * @param _value number virus for this attack boss
 */
function atkBoss(uint256 _value) public disableContract
    {
        require(bossData[bossRoundNumber].ended == false);
        require(bossData[bossRoundNumber].totalDame < bossData[bossRoundNumber].bossHp);
        require(players[msg.sender].nextTimeAtk <= now);

        Engineer.subVirus(msg.sender, _value);
        
        uint256 rate = 50 + randomNumber(msg.sender, now, 60); // 50 - 110%
        
        uint256 atk = SafeMath.div(SafeMath.mul(_value, rate), 100);
        
        updateShareETH(msg.sender);

        // update dame
        BossData storage b = bossData[bossRoundNumber];
        
        uint256 currentTotalDame = b.totalDame;
        uint256 dame = 0;
        if (atk > b.def) {
            dame = SafeMath.sub(atk, b.def);
        }

        b.totalDame = SafeMath.min(SafeMath.add(currentTotalDame, dame), b.bossHp);
        b.playerLastAtk = msg.sender;

        dame = SafeMath.sub(b.totalDame, currentTotalDame);

        // bonus crystals
        uint256 crystalsBonus = SafeMath.div(SafeMath.mul(dame, 5), 100);
        MiningWar.addCrystal(msg.sender, crystalsBonus);
        // update player
        PlayerData storage p = players[msg.sender];

        p.nextTimeAtk = now + HALF_TIME_ATK_BOSS;

        if (p.currentBossRoundNumber == bossRoundNumber) {
            p.dame = SafeMath.add(p.dame, dame);
        } else {
            p.currentBossRoundNumber = bossRoundNumber;
            p.dame = dame;
        }

        bool isLastHit;
        if (b.totalDame >= b.bossHp) {
            isLastHit = true;
            endAtkBoss();
        }
        
        // emit event attack boss
        emit eventAttackBoss(b.bossRoundNumber, msg.sender, _value, dame, p.dame, now, isLastHit, crystalsBonus);
    }
// Solidity 0.4.25
/**
 * @dev calculate share Eth of player
 */
function calculateShareETH(address _addr, uint256 _bossRoundNumber) public view returns(uint256 _share)
    {
        PlayerData memory p = players[_addr];
        BossData memory b = bossData[_bossRoundNumber];
        if ( 
            p.lastBossRoundNumber >= p.currentBossRoundNumber && 
            p.currentBossRoundNumber != 0 
            ) {
            _share = 0;
        } else {
            if (b.totalDame == 0) return 0;
            _share = SafeMath.div(SafeMath.mul(SafeMath.mul(b.prizePool, 95), p.dame), SafeMath.mul(b.totalDame, 100)); // prizePool * 95% * playerDame / totalDame 
        } 
        if (b.ended == false)  _share = 0;
    }
// Solidity 0.7.5
/**
 @notice stake ASG to enter warmup
 @param _amount uint
 @return bool
 */
function stake(uint256 _amount, address _recipient)
        external
        returns (bool)
    {
        rebase();

        IERC20(ASG).safeTransferFrom(msg.sender, address(this), _amount);

        Claim memory info = warmupInfo[_recipient];
        require(!info.lock, "Deposits for account are locked");

        warmupInfo[_recipient] = Claim({
            deposit: info.deposit.add(_amount),
            gons: info.gons.add(IsASG(sASG).gonsForBalance(_amount)),
            expiry: epoch.number.add(warmupPeriod),
            lock: false
        });

        IERC20(sASG).safeTransfer(warmupContract, _amount);
        return true;
    }
// Solidity 0.8.6
// Get user infos
function getUserInfos() public view returns (UserInfo[] memory returnData) {
        returnData = new UserInfo[](userAddrs.length);
        for (uint i=0; i<userAddrs.length; i++) {
            UserInfo memory _userInfo = userInfo[userAddrs[i]];
            returnData[i] = _userInfo;
        }
        return returnData;
    }
// Solidity 0.8.6
// set User Info
function setUserInfo(address addr, uint256 depositedAmount, uint256 purchasedAmount, uint256 withdrawnAmount) public onlyAuthorized {
       UserInfo storage _userInfo = userInfo[addr];
       if (_userInfo.depositedAmount == 0) {
           userAddrs.push(addr);
       } else {
           totalCoinAmount = totalCoinAmount.sub(Math.min(totalCoinAmount, _userInfo.depositedAmount));
           totalSoldAmount = totalSoldAmount.sub(Math.min(totalSoldAmount, _userInfo.purchasedAmount));
       }
        totalCoinAmount = totalCoinAmount.add(depositedAmount);
        totalSoldAmount = totalSoldAmount.add(purchasedAmount);

       _userInfo.depositedAmount = depositedAmount;
       _userInfo.purchasedAmount = purchasedAmount;
       _userInfo.withdrawnAmount = withdrawnAmount;
    }
// Solidity 0.8.6
// deposit
// coinAmount (decimals: COIN_DECIMALS) 
function deposit(uint256 _coinAmount, uint8 coinIndex) external whenSale {
        require( totalSaleAmount >= totalSoldAmount, "totalSaleAmount >= totalSoldAmount");

        CoinInfo memory _coinInfo = coinInfo[coinIndex];
        IERC20 coin = IERC20(_coinInfo.addr);

        // calculate token amount to be transferred
        (uint256 tokenAmount, uint256 coinAmount) = calcTokenAmount(_coinAmount, coinIndex);
        uint256 availableTokenAmount = totalSaleAmount.sub(totalSoldAmount);

        // if the token amount is less than remaining
        if (availableTokenAmount < tokenAmount) {
            tokenAmount = availableTokenAmount;
            (_coinAmount, coinAmount) = calcCoinAmount(availableTokenAmount, coinIndex);
        }

        // validate purchasing
        _preValidatePurchase(_msgSender(), tokenAmount, coinAmount, coinIndex);

        // transfer coin and token
        coin.transferFrom(_msgSender(), address(this), coinAmount);
        xGovToken.transfer(_msgSender(), tokenAmount);

        // transfer coin to treasury
        if (treasuryAddress != 0x0000000000000000000000000000000000000000) {
            coin.transfer(treasuryAddress, coinAmount);
        }

        // update global state
        totalCoinAmount = totalCoinAmount.add(_coinAmount);
        totalSoldAmount = totalSoldAmount.add(tokenAmount);
        
       // update purchased token list
       UserInfo storage _userInfo = userInfo[_msgSender()];
       if (_userInfo.depositedAmount == 0) {
           userAddrs.push(_msgSender());
       }
       _userInfo.depositedAmount = _userInfo.depositedAmount.add(_coinAmount);
       _userInfo.purchasedAmount = _userInfo.purchasedAmount.add(tokenAmount);
       
       emit TokensPurchased(_msgSender(), _coinAmount, tokenAmount);

       xJoyToken _xJoyToken = xJoyToken(address(xGovToken));
       _xJoyToken.addPurchaser(_msgSender(), tokenAmount);
    }
// Solidity 0.8.6
// Calc token amount by coin amount
function calcWithdrawalAmount(address addr) public view returns (uint256) {
        require(checkVestingPeriod(), "This is not vesting period.");

        uint256 VESTING_START = SALE_START.add(LOCKING_DURATION);

        UserInfo memory _userInfo = userInfo[addr];
        uint256 totalAmount = 0;
        if (block.timestamp >= VESTING_START.add(VESTING_DURATION)) {
            totalAmount = _userInfo.purchasedAmount;
        } else {
            totalAmount = _userInfo.purchasedAmount.mul(block.timestamp.sub(VESTING_START)).div(VESTING_DURATION);
        }

        uint256 withdrawalAmount = totalAmount.sub(_userInfo.withdrawnAmount);
        return withdrawalAmount;
    }
// Solidity 0.8.6
// Validate purchase
function _preValidatePurchase(address purchaser, uint256 tokenAmount, uint256 coinAmount, uint8 coinIndex) internal view {
        require( coinInfoCount >= coinIndex, "coinInfoCount >= coinIndex");
        CoinInfo memory _coinInfo = coinInfo[coinIndex];
        IERC20 coin = IERC20(_coinInfo.addr);

        require(purchaser != address(0), "Purchaser is the zero address");
        require(coinAmount != 0, "Coin amount is 0");
        require(tokenAmount != 0, "Token amount is 0");

        require(xGovToken.balanceOf(address(this)) >= tokenAmount, "$xJoyToken amount is lack!");
        require(coin.balanceOf(msg.sender) >= coinAmount, "Purchaser's coin amount is lack!");
        require(coin.allowance(msg.sender, address(this)) >= coinAmount, "Purchaser's allowance is low!");

        this;
    }
// Solidity 0.8.5
/**
 * @dev Get token details for a specific address from an index of owner's token lsit
 * @param owner_ for which to get the token details
 * @param index from which to start retrieving the token details
 */
function getTokenDetailsForFromIndex(address owner_, uint256 index)
        public
        view
        returns (NFTDetails[] memory)
    {
        uint256[] memory ownerList = ownerTokenList[owner_];
        NFTDetails[] memory details = new NFTDetails[](
            ownerList.length - index
        );
        uint256 counter = 0;
        for (uint256 i = index; i < ownerList.length; i++) {
            details[counter] = ownedTokensDetails[owner_][ownerList[i]];
            counter++;
        }
        return details;
    }
// Solidity 0.8.5
/**
 * @dev Get the list of tokens for a specific owner
 * @param _owner address to retrieve token ids for
 */
function tokensByOwner(address _owner)
        external
        view
        returns (uint256[] memory)
    {
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount == 0) {
            return new uint256[](0);
        } else {
            uint256[] memory result = new uint256[](tokenCount);
            for (uint256 index; index < tokenCount; index++) {
                result[index] = tokenOfOwnerByIndex(_owner, index);
            }
            return result;
        }
    }
// Solidity 0.8.5
/**
 * @dev Get the remaining contract balance
 */
function getRemainingContractBalance() public view returns (uint256) {
        uint256 balance = address(this).balance;
        uint256 teamBalance;
        for (uint8 i; i < currentTeamBalance.length; i++) {
            teamBalance += currentTeamBalance[i];
        }
        if (balance > teamBalance) {
            return balance - teamBalance;
        }
        return 0;
    }
// Solidity 0.8.5
/**
 * Get random index and save it
 */
function randomId() internal returns (uint256) {
        uint256 totalSize = MAX_TOKENS - totalSupply();
        uint256 index = uint256(
            keccak256(
                abi.encodePacked(
                    indexStorage.nonce,
                    block.coinbase,
                    block.difficulty,
                    block.timestamp
                )
            )
        ) % totalSize;

        totalSize--;
        uint256 value;

        uint256 currentValue = indexStorage.indices[index];
        if (currentValue != 0) {
            value = currentValue;
        } else {
            value = index;
        }
        uint16 currentLastValue = indexStorage.indices[totalSize];
        // Move last value to selected position
        if (currentLastValue == 0) {
            // Array position not initialized, so use position
            indexStorage.indices[index] = uint16(totalSize);
        } else {
            // Array position holds a value so use that
            indexStorage.indices[index] = currentLastValue;
        }
        indexStorage.nonce++;
        // Don't allow a zero index, start counting at 1
        return value + 1;
    }
// Solidity 0.8.5
/**
 * @dev Create a new royalty stage
 */
function _nextRoyaltyStage() internal {
        uint256 lastIndex = getLastRoyaltyStageIndex();
        uint256 valueAdded = address(depositor).balance -
            (totalRoyaltyAdded - totalRoyaltyWithdrawed);

        totalRoyaltyAdded += valueAdded;

        uint256 totalTeamRoyalty;
        for (uint8 i; i < royaltyReceiverAddresses.length; i++) {
            uint256 teamMemberRoyalty = (valueAdded *
                royaltyReceiverPercentages[i]) / 100;

            currentTeamRoyalty[i] += teamMemberRoyalty;

            totalTeamRoyalty += teamMemberRoyalty;
        }

        royaltyStages[lastIndex].endDate = block.timestamp;
        royaltyStages[lastIndex].amount = valueAdded;

        royaltyStages.push(RoyaltyStage(block.timestamp, 0, 0));
    }
// Solidity 0.8.5
/**
 * @dev Check if a new royalty stage can be created
 */
function canChangeRoyaltyStage() public view returns (bool) {
        RoyaltyStage memory lastStage = royaltyStages[
            getLastRoyaltyStageIndex()
        ];
        uint256 valueAdded = address(depositor).balance -
            (totalRoyaltyAdded - totalRoyaltyWithdrawed);
        return
            valueAdded > 0 &&
            (block.timestamp - lastStage.startDate) >= royaltyInterval;
    }
// Solidity 0.4.21
/**
 * @dev Mint token to own address.
 * @param _mintedAmount amount to mint.
 */
function mintToken(uint256 _mintedAmount) onlyAdmin supplyLock public {
        require(totalSupply.add(_mintedAmount) < 250000000 * (10**18)); //Max supply ever
        balances[msg.sender] = SafeMath.add(balances[msg.sender], _mintedAmount);
        totalSupply = SafeMath.add(totalSupply, _mintedAmount);
        emit Transfer(0, this, _mintedAmount);
        emit Transfer(this, msg.sender, _mintedAmount);
    }
// Solidity 0.8.9
/**
 * @notice Mint SpaceConvicts.
 * @param amount Number of SpaceConvicts to mint.
 * @dev Utilize unchecked {} and calldata for gas savings.
 */
function mint(uint16 amount) external payable {
        require(conf.mintEnabled, "Minting is disabled.");
        require(
            conf.supply + amount <= conf.maxNFTs,
            "Amount exceeds maximum supply."
        );
        require(
            conf.price * amount <= msg.value,
            "Ether value sent is not correct."
        );

        amount = amount + uint16(amount) / uint16(10) * 4 + uint16(amount % 10) / uint16(3);

        _safeMint(msg.sender, amount);
        conf.supply = conf.supply + amount;
    }
// Solidity 0.6.2
// Withdraw LP tokens from MasterStar.
function withdraw(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(_amount > 0, "user amount is zero");
        require(user.amount >= _amount, "withdraw: not good");
        updatePool(_pid);
        uint256 pending = user.amount.mul(pool.accTokenPerShare).div(1e12).sub(user.rewardDebt);
        safeTokenTransfer(msg.sender, pending);
        user.amount = user.amount.sub(_amount);
        user.rewardDebt = user.amount.mul(pool.accTokenPerShare).div(1e12);
        pool.lpToken.safeTransfer(address(msg.sender), _amount);
        emit Withdraw(msg.sender, _pid, _amount);
        if(pool.finishMigrate) { // finish migrate record user withdraw lpToken
            pool.lockCrosschainAmount = pool.lockCrosschainAmount.add(_amount);
            _depositMigratePoolAddr(_pid, pool.accTokenPerShare, _amount);

            emit MigrateWithdraw(msg.sender, _pid, _amount);
        }
    }