lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
// Deposit  tokens to NerdVault for NERD allocation.
function deposit(uint256 _pid, uint256 _originAmount) public {
        claimLPTokensToFarmingPool(msg.sender);
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];

        massUpdatePools();

        // Transfer pending tokens
        // to user
        updateAndPayOutPending(_pid, msg.sender);

        uint256 lpAccumulationFee = _originAmount.mul(LP_ACCUMULATION_FEE).div(
            1000
        );
        uint256 _amount = _originAmount.sub(lpAccumulationFee);

        //Transfer in the amounts from user
        // save gas
        if (_amount > 0) {
            pool.token.safeTransferFrom(
                address(msg.sender),
                ADDRESS_LOCKED_LP_ACCUMULATION,
                lpAccumulationFee
            );
            pool.token.safeTransferFrom(
                address(msg.sender),
                address(this),
                _amount
            );
            updateDepositTime(_pid, msg.sender, _amount);
            user.amount = user.amount.add(_amount);
        }

        user.rewardDebt = user.amount.mul(pool.accNerdPerShare).div(1e18);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Test coverage
// [x] Does user get the deposited amounts?
// [x] Does user that its deposited for update correcty?
// [x] Does the depositor get their tokens decreased
function depositFor(
        address _depositFor,
        uint256 _pid,
        uint256 _originAmount
    ) public {
        claimLPTokensToFarmingPool(_depositFor);
        // requires no allowances
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][_depositFor];

        massUpdatePools();

        // Transfer pending tokens
        // to user
        updateAndPayOutPending(_pid, _depositFor); // Update the balances of person that amount is being deposited for
        uint256 lpAccumulationFee = _originAmount.mul(LP_ACCUMULATION_FEE).div(
            1000
        );
        uint256 _amount = _originAmount.sub(lpAccumulationFee);

        if (_amount > 0) {
            pool.token.safeTransferFrom(
                address(msg.sender),
                ADDRESS_LOCKED_LP_ACCUMULATION,
                lpAccumulationFee
            );
            pool.token.safeTransferFrom(
                address(msg.sender),
                address(this),
                _amount
            );
            updateDepositTime(_pid, _depositFor, _amount);
            user.amount = user.amount.add(_amount); // This is depositedFor address
        }

        user.rewardDebt = user.amount.mul(pool.accNerdPerShare).div(1e18); /// This is deposited for address
        emit Deposit(_depositFor, _pid, _amount);
    }
// Solidity 0.6.12
// Test coverage
// [x] Does allowance decrease?
// [x] Do oyu need allowance
// [x] Withdraws to correct address
function withdrawFrom(
        address owner,
        uint256 _pid,
        uint256 _amount
    ) public {
        claimLPTokensToFarmingPool(owner);
        PoolInfo storage pool = poolInfo[_pid];
        require(
            pool.allowance[owner][msg.sender] >= _amount,
            "withdraw: insufficient allowance"
        );
        pool.allowance[owner][msg.sender] = pool.allowance[owner][msg.sender]
            .sub(_amount);
        _withdraw(_pid, _amount, owner, msg.sender);
    }
// Solidity 0.6.12
// Low level withdraw function
function _withdraw(
        uint256 _pid,
        uint256 _amount,
        address from,
        address to
    ) internal {
        PoolInfo storage pool = poolInfo[_pid];
        //require(pool.withdrawable, "Withdrawing from this pool is disabled");
        UserInfo storage user = userInfo[_pid][from];
        (
            uint256 withdrawnableAmount,
            uint256 penaltyAmount
        ) = computeReleasableLPWithPenalty(_pid, from);
        require(withdrawnableAmount >= _amount, "withdraw: not good");

        massUpdatePools();
        updateAndPayOutPending(_pid, from); // Update balances of from this is not withdrawal but claiming NERD farmed

        if (_amount > 0) {
            uint256 _actualWithdrawn = _amount;
            uint256 _actualPenalty = _actualWithdrawn.mul(penaltyAmount).div(
                withdrawnableAmount
            );
            user.amount = user.amount.sub(_actualWithdrawn.add(_actualPenalty));

            pool.token.safeTransfer(address(to), _actualWithdrawn);

            if (_actualPenalty > 0) {
                //withdraw liquidtity for _actualPenalty
                uint256 otherTokenAmount = removeLiquidity(
                    address(pool.token),
                    _actualPenalty
                );
                swapTokenForNerd(address(pool.token), otherTokenAmount);

                updatePendingRewards();
            }
        }
        user.rewardDebt = user.amount.mul(pool.accNerdPerShare).div(1e18);

        emit Withdraw(to, _pid, _amount);
    }
// Solidity 0.6.12
// function that lets owner/governance contract
// approve allowance for any token inside this contract
// This means all future UNI like airdrops are covered
// And at the same time allows us to give allowance to strategy contracts.
// Upcoming cYFI etc vaults strategy contracts will  se this function to manage and farm yield on value locked
function setStrategyContractOrDistributionContractAllowance(
        address tokenAddress,
        uint256 _amount,
        address contractAddress
    ) public onlySuperAdmin {
        require(
            isContract(contractAddress),
            "Recipent is not a smart contract, BAD"
        );
        require(
            block.number > contractStartBlock.add(95_000),
            "Governance setup grace period not over"
        );
        IERC20(tokenAddress).approve(contractAddress, _amount);
    }
// Solidity 0.4.15
/**
 * Accepts money deposit and makes record
 * minimum deposit is MINIMUM_DEPOSIT
 * @param beneficiar - the address to receive Tokens
 * @param countryCode - 3-digit country code
 * @dev if `msg.value < MINIMUM_DEPOSIT` throws
 */
function deposit (address beneficiar, uint16 countryCode)   payable  {  
        require(msg.value >= MINIMUM_DEPOSIT);
        require(state == State.Sale || state == State.Presale);

        /* this should end any finished period before starting any operations */
        tick();

        /* check if have enough tokens for the current period
         * if not, the call fails until tokens are deposited to the contract
         */
        require(isActive());

        uint256 tokensBought = msg.value / getTokenPrice();

        if(periods[currentPeriod].tokensSold + tokensBought >= tokensForPeriod(currentPeriod)) {
            tokensBought = tokensForPeriod(currentPeriod) - periods[currentPeriod].tokensSold;
        }

        uint256 moneySpent = getTokenPrice() * tokensBought;

        investmentsByCountries[countryCode] += moneySpent;

        if(tokensBought > 0) {
            assert(moneySpent <= msg.value);

            /* return the rest */
            if(msg.value > moneySpent) {
                msg.sender.transfer(msg.value - moneySpent);
            }

            periods[currentPeriod].tokensSold += tokensBought;
            unclaimedTokensForInvestor[beneficiar] += tokensBought;
            totalUnclaimedTokens += tokensBought;
            totalTokensSold += tokensBought;
            Deposited(msg.sender, moneySpent, tokensBought);
        }

        /* if all tokens are sold, get to the next period */
        tick();
    }
// Solidity 0.8.4
/**
 * Set verification of a users challenge
 * @param tokenId - the tokenId of the challenge
 * @param completed - true if the challenge has been verified
 * @return success - true if successful
 */
function setVerify(uint256 tokenId, bool completed)
        public
        returns (bool success)
    {
        require(!verificationPaused, "Verification is paused");
        require(
            tokenIdVerificationComplete[tokenId] == false,
            "Token has already been verified"
        );
        require(
            tokenIdToAccountabilityPartner[tokenId] == msg.sender,
            "Only the accountability partner can verify"
        );

        tokenIdVerificationComplete[tokenId] = true;
        tokenIdVerificationValue[tokenId] = completed;

        emit Verified(
            tokenId,
            completed,
            ownerOf(tokenId),
            accountabilityPartnerOf(tokenId)
        );

        return true;
    }
// Solidity 0.8.4
/**
 * Remove the verification status from the challenge
 * @param tokenId - the tokenId of the challenge
 * @return success - true if successful
 */
function unverify(uint256 tokenId) public returns (bool success) {
        require(!verificationPaused, "Verification is paused");
        require(
            tokenIdVerificationComplete[tokenId] == true,
            "Token has not been verified"
        );
        require(
            tokenIdToAccountabilityPartner[tokenId] == msg.sender,
            "Only the accountability partner can unverify"
        );

        tokenIdVerificationComplete[tokenId] = false;
        tokenIdVerificationValue[tokenId] = false;

        emit Unverified(
            tokenId,
            ownerOf(tokenId),
            accountabilityPartnerOf(tokenId)
        );

        return true;
    }
// Solidity 0.8.4
/**
 * Withdraw the balance of the contract
 * @dev owner only
 * @param _to - the address to send the balance to
 * @param _amount - the amount to send
 * @return sent - true if successful
 * @return data - data from the call
 */
function withdraw(address payable _to, uint256 _amount)
        external
        onlyOwner
        returns (bool sent, bytes memory data)
    {
        require(_amount < address(this).balance, "Not enough balance");
        require(_amount > 0, "Amount must be greater than 0");

        (sent, data) = _to.call{value: _amount}("");

        return (sent, data);
    }
// Solidity 0.8.4
/**
 * Get the URI of a token
 * @param tokenId - the tokenId of the token
 * @return tokenURI - the uri of the token
 */
function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        string memory _tokenURI = tokenIdToIpfsHash[tokenId];
        string memory base = _baseURI();

        // If there is no base URI, return the token URI.
        if (bytes(base).length == 0) {
            return _tokenURI;
        }
        // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
        if (bytes(_tokenURI).length > 0) {
            return string(abi.encodePacked(base, _tokenURI));
        }
        // If there is a baseURI but no tokenURI, return the base because this shouldn't happen
        return string(abi.encodePacked(base));
    }
// Solidity 0.5.12
/**
 * Holder can withdraw the ETH when price >= box.openPrice or now >= box.openTime.
 * After breaking the box, the box will be burned.
 */
function breakBox(uint _boxId) public {
    require(_isApprovedOrOwner(_msgSender(), _boxId), "ERC721: transfer caller is not owner nor approved");
    uint ether_price_now = getEthPrice();
    MoonBox storage box = moonBoxs[_boxId];
    require(box.etherNumber > 0, "This box has been opened");
    if(box.openPrice <= ether_price_now || box.openTime <= now) {
      super._burn(_boxId);
      msg.sender.transfer(box.etherNumber);
      emit BreakBox(_boxId, now);
    } else {
      revert("The break condition is not yet satisfied.");
    }
  }
// Solidity 0.5.12
/**
 * Holder can withdraw the ETH when price >= box.openPrice or now >= box.openTime.
 * After open the box, you still have the box.
 * Developers will receive a fee of.1%.
 */
function openBox(uint _boxId) public {
    require(_isApprovedOrOwner(_msgSender(), _boxId), "ERC721: transfer caller is not owner nor approved");
    uint ether_price_now = getEthPrice();
    MoonBox storage box = moonBoxs[_boxId];
    require(box.etherNumber > 0, "This box has been opened");
    if(box.openPrice <= ether_price_now || box.openTime <= now) {
      uint fee = box.etherNumber / tipRatio;
      uint payout = box.etherNumber.sub(fee);
      box.etherNumber = 0;
      msg.sender.transfer(payout);
      owner.transfer(fee);
      emit OpenBox(_boxId, now);
    } else {
      revert("The open condition is not yet satisfied.");
    }
  }
// Solidity 0.5.12
/**
 * @dev Gets the list of token IDs of the requested owner.
 * @param _owner address owning the tokens
 * @return uint256[] List of token IDs owned by the requested address
 */
function getMoonBoxsByOwner(address _owner) external view returns(uint[] memory) {
    uint boxNum = super.balanceOf(_owner);
    uint[] memory result = new uint[](boxNum);
    uint counter = 0;
    for (uint i = 0; i < moonBoxs.length; i++) {
      if (super._exists(i) && super._isApprovedOrOwner(_owner, i)) {
        result[counter] = i;
        counter++;
      }
    }
    return result;
  }
// Solidity 0.5.12
/**
 * when developer changed the address of the oracle.
 * Users have one week to opt out safely.
 */
function quit(uint _boxId) external {
    require(_isApprovedOrOwner(_msgSender(), _boxId), "ERC721: transfer caller is not owner nor approved");
    MoonBox storage box = moonBoxs[_boxId];
    require(box.etherNumber > 0, "This box has been opened");
    if(now < new_uniswap_address_effective_time) {
      super._burn(_boxId);
      msg.sender.transfer(box.etherNumber);
      emit Quit(_boxId, now);
    } else {
      revert("The quit condition is not yet satisfied.");
    }
  }
// Solidity 0.6.12
///@dev Deposits alTokens into the transmuter 
///
///@param amount the amount of alTokens to stake
function stake(uint256 amount)
        public
        noContractAllowed()
        ensureUserActionDelay()
        runPhasedDistribution()
        updateAccount(msg.sender)
        checkIfNewUser()
    {
        require(!pause, "emergency pause enabled");

        // requires approval of AlToken first
        address sender = msg.sender;
        //require tokens transferred in;
        IERC20Burnable(alToken).safeTransferFrom(sender, address(this), amount);
        totalSupplyAltokens = totalSupplyAltokens.add(amount);
        depositedAlTokens[sender] = depositedAlTokens[sender].add(amount);
        emit AlUsdStaked(sender, amount);
    }
// Solidity 0.6.12
/// @dev Sets the keeper list
///
/// This function reverts if the caller is not governance
///
/// @param _keepers the accounts to set states for.
/// @param _states the accounts states.
function setKeepers(address[] calldata _keepers, bool[] calldata _states) external onlyGov() {
        uint256 n = _keepers.length;
        for(uint256 i = 0; i < n; i++) {
            keepers[_keepers[i]] = _states[i];
        }
        emit KeepersSet(_keepers, _states);
    }
// Solidity 0.6.12
/// @dev Updates the active vault.
///
/// This function reverts if the vault adapter is the zero address, if the token that the vault adapter accepts
/// is not the token that this contract defines as the parent asset, or if the contract has not yet been initialized.
///
/// @param _adapter the adapter for the new active vault.
function _updateActiveVault(YearnVaultAdapterWithIndirection _adapter) internal {
        require(_adapter != YearnVaultAdapterWithIndirection(ZERO_ADDRESS), "Transmuter: active vault address cannot be 0x0.");
        require(address(_adapter.token()) == token, "Transmuter.vault: token mismatch.");
        require(!adapters[_adapter], "Adapter already in use");
        adapters[_adapter] = true;
        _vaults.push(VaultWithIndirection.Data({
            adapter: _adapter,
            totalDeposited: 0
        }));

        emit ActiveVaultUpdated(_adapter);
    }
// Solidity 0.6.12
/// @dev Recalls funds from active vault if less than amt exist locally
///
/// @param amt amount of funds that need to exist locally to fulfill pending request
function ensureSufficientFundsExistLocally(uint256 amt) internal {
        uint256 currentBal = IERC20Burnable(token).balanceOf(address(this));
        if (currentBal < amt) {
            uint256 diff = amt - currentBal;
            // get enough funds from active vault to replenish local holdings & fulfill claim request
            _recallExcessFundsFromActiveVault(plantableThreshold.add(diff));
        }
    }
// Solidity 0.6.12
/// @dev Plants or recalls funds from the active vault
///
/// This function plants excess funds in an external vault, or recalls them from the external vault
/// Should only be called as part of distribute()
function _plantOrRecallExcessFunds() internal {
        // check if the transmuter holds more funds than plantableThreshold
        uint256 bal = IERC20Burnable(token).balanceOf(address(this));
        uint256 marginVal = plantableThreshold.mul(plantableMargin).div(100);
        if (bal > plantableThreshold.add(marginVal)) {
            uint256 plantAmt = bal - plantableThreshold;
            // if total funds above threshold, send funds to vault
            VaultWithIndirection.Data storage _activeVault = _vaults.last();
            _activeVault.deposit(plantAmt);
        } else if (bal < plantableThreshold.sub(marginVal)) {
            // if total funds below threshold, recall funds from vault
            // first check that there are enough funds in vault
            uint256 harvestAmt = plantableThreshold - bal;
            _recallExcessFundsFromActiveVault(harvestAmt);
        }
    }
// Solidity 0.6.12
/// @dev Recalls up to the harvestAmt from the active vault
///
/// This function will recall less than harvestAmt if only less is available
///
/// @param _recallAmt the amount to harvest from the active vault
function _recallExcessFundsFromActiveVault(uint256 _recallAmt) internal {
        VaultWithIndirection.Data storage _activeVault = _vaults.last();
        uint256 activeVaultVal = _activeVault.totalValue();
        if (activeVaultVal < _recallAmt) {
            _recallAmt = activeVaultVal;
        }
        if (_recallAmt > 0) {
            _recallFundsFromActiveVault(_recallAmt);
        }
    }
// Solidity 0.6.12
/// @dev Sets the rewards contract.
///
/// This function reverts if the new rewards contract is the zero address or the caller is not the current governance.
///
/// @param _rewards the new rewards contract.
function setRewards(address _rewards) external onlyGov() {
        // Check that the rewards address is not the zero address. Setting the rewards to the zero address would break
        // transfers to the address because of `safeTransfer` checks.
        require(_rewards != ZERO_ADDRESS, "Transmuter: rewards address cannot be 0x0.");

        rewards = _rewards;

        emit RewardsUpdated(_rewards);
    }
// Solidity 0.6.12
/// @dev Migrates transmuter funds to a new transmuter
///
/// @param migrateTo address of the new transmuter
function migrateFunds(address migrateTo) external onlyGov() {
        require(migrateTo != address(0), "cannot migrate to 0x0");
        require(pause, "migrate: set emergency exit first");

        // leave enough funds to service any pending transmutations
        uint256 totalFunds = IERC20Burnable(token).balanceOf(address(this));
        uint256 migratableFunds = totalFunds.sub(totalSupplyAltokens, "not enough funds to service stakes");
        IERC20Burnable(token).approve(migrateTo, migratableFunds);
        ITransmuter(migrateTo).distribute(address(this), migratableFunds);
        emit MigrationComplete(migrateTo, migratableFunds);
    }
// Solidity 0.8.7
/* acceptor mint one baby, left another baby for proposer to claim */
function breed(
        MatingRequest calldata matingRequest,
        uint16 acceptorTokenId,
        bytes calldata sig
    ) external callerIsUser isAtSalePhase(SalePhase.Breed) {
        validateMatingRequest(matingRequest, sig);

        uint16 punkId;
        uint16 baycId;
        address punkOwnerAddress;
        address baycOwnerAddress;

        if (matingRequest.isProposerPunk) {
            punkId = matingRequest.proposerTokenId;
            punkOwnerAddress = matingRequest.proposerAddress;
            baycId = acceptorTokenId;
            baycOwnerAddress = msg.sender;
        } else {
            punkId = acceptorTokenId;
            punkOwnerAddress = msg.sender;
            baycId = matingRequest.proposerTokenId;
            baycOwnerAddress = matingRequest.proposerAddress;
        }

        require(!punkBred(punkId), 'Punk already bred a baby.');
        require(!baycBred(baycId), 'Bayc already bred a baby.');

        bred.set(punkId2Index(punkId));
        bred.set(baycId2Index(baycId));

        // check ownership
        verifyPunkOwnership(punkId, punkOwnerAddress);
        verifyBaycOwnership(baycId, baycOwnerAddress);

        uint16 babyTokenId = uint16(_currentIndex);

        babyParents[babyTokenId] = Parents(
            punkId,
            baycId,
            matingRequest.isProposerPunk,
            false,
            true
        );

        emit Breed(
            matingRequest.proposerTokenId,
            matingRequest.isProposerPunk,
            acceptorTokenId,
            msg.sender,
            babyTokenId
        );

        // mint baby token for acceptor, proposer should claim the twin baby later.
        _mint(msg.sender, 1, '', false);
    }
// Solidity 0.8.7
/* For proposer to claim the baby. */
function claimBaby(uint16 siblingId)
        external
        callerIsUser
        isAtSalePhase(SalePhase.Breed)
    {
        Parents storage parentsInfo = babyParents[siblingId];
        require(parentsInfo.hasParents, 'No baby to be claimed.');
        if (parentsInfo.isProposerPunk) {
            verifyPunkOwnership(parentsInfo.punkTokenId, msg.sender);
        } else {
            verifyBaycOwnership(parentsInfo.baycTokenId, msg.sender);
        }
        require(!parentsInfo.proposerClaimed, 'Baby already claimed.');

        parentsInfo.proposerClaimed = true;

        uint16 babyTokenId = uint16(_currentIndex);
        babyParents[babyTokenId] = parentsInfo;

        emit Claim(babyTokenId, siblingId, msg.sender);
        _mint(msg.sender, 1, '', false);
    }
// Solidity 0.5.10
/**
 * @notice Buy a license
 * @dev Requires value to be equal to the price of the license.
 *      The _owner must not already own a license.
 */
function _buyFrom(address _licenseOwner) internal returns(uint) {
        require(licenseDetails[_licenseOwner].creationTime == 0, "License already bought");

        licenseDetails[_licenseOwner] = LicenseDetails({
            price: price,
            creationTime: block.timestamp
        });

        uint idx = licenseOwners.push(_licenseOwner);
        idxLicenseOwners[_licenseOwner] = idx;

        emit Bought(_licenseOwner, price);

        require(_safeTransferFrom(token, _licenseOwner, burnAddress, price), "Unsuccessful token transfer");

        return idx;
    }
// Solidity 0.5.10
/**
 * @notice Support for "approveAndCall". Callable only by `token()`.
 * @param _from Who approved.
 * @param _amount Amount being approved, need to be equal `price()`.
 * @param _token Token being approved, need to be equal `token()`.
 * @param _data Abi encoded data with selector of `buy(and)`.
 */
function receiveApproval(address _from, uint256 _amount, address _token, bytes memory _data) public {
        require(_amount == price, "Wrong value");
        require(_token == address(token), "Wrong token");
        require(_token == address(msg.sender), "Wrong call");
        require(_data.length == 4, "Wrong data length");

        require(_abiDecodeBuy(_data) == bytes4(0xa6f2ae3a), "Wrong method selector"); //bytes4(keccak256("buy()"))

        _buyFrom(_from);
    }