lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @dev Just exchange your SHAKE for MILK2.
 * Caller must have SHAKE on his/her balance.
 * `_amount` is amount of user's SHAKE that he/she want burn for get MILK2 
 * Note that one need use `_amount` without decimals.
 * 
 * Note that MILK2 amount will calculate from the reduced by one step `currShakePrice`
 *
 * Function can be called after `START_FROM_BLOCK`
 */
function getMilkForShake(uint16 _amount) external {
        require(block.number >= START_FROM_BLOCK, "Please wait for start block");

        IERC20 shakeToken = IERC20(SHAKE_ADDRESS);
        
        require(shakeToken.balanceOf(msg.sender) >= uint256(_amount)*10**18, "There is no enough SHAKE");
        require(shakeToken.burn(msg.sender, uint256(_amount)*10**18), "Can't burn your SHAKE");
        
        IERC20 milk2Token = IERC20(MILK_ADDRESS);
        milk2Token.mint(msg.sender, uint256(_amount).mul(currShakePrice.sub(SHAKE_PRICE_STEP)));
        
    }
// Solidity 0.8.9
/**
 * @dev Returns the key-value pair stored at position `index` in the map. O(1).
 *
 * Note that there are no guarantees on the ordering of entries inside the
 * array, and it may change when more entries are added or removed.
 *
 * Requirements:
 *
 * - `index` must be strictly less than {length}.
 */
function _at(Map storage map, uint256 index)
        private
        view
        returns (bytes32, bytes32)
    {
        require(
            map._entries.length > index,
            "EnumerableMap: index out of bounds"
        );

        MapEntry storage entry = map._entries[index];
        return (entry._key, entry._value);
    }
// Solidity 0.6.2
// Enter the bar. Pay some SUSHIs. Earn some shares.
function enter(uint256 _amount) public {
        uint256 totalSushi = sushi.balanceOf(address(this));
        uint256 totalShares = totalSupply();
        if (totalShares == 0 || totalSushi == 0) {
            _mint(msg.sender, _amount);
        } else {
            uint256 what = _amount.mul(totalShares).div(totalSushi);
            _mint(msg.sender, what);
        }
        sushi.transferFrom(msg.sender, address(this), _amount);
    }
// Solidity 0.8.2
//wraping all buy or mint function in one function:
function mint(uint256 _countNfts) public payable whenNotPaused {
        uint NFTsPrice = NFTPrice * _countNfts;
        address to = msg.sender; 
        require(totalSupply() + _countNfts <= NFTMaxSupply, "NFT: Max Supply reached");
        require(_countNfts > 0, "NFT: No of NFTs must be greater then zero");
        

        if (msg.sender != owner()) {
            require(startSale == true, "NFT sale not started");
            require(msg.value == NFTsPrice, "Please enter exact price");
            require(_countNfts <= maxCapPerMint, "Max limit is 50 NFT in one transaction");
            require(mintBlanceOf[to] + _countNfts <= maxCapPerMint, "Max per wallet minting limit reached");
        }
        
        for (uint i = 0; i < _countNfts; i++ ) {
            uint256 tokenId = _tokenIdCounter.current();
            _tokenIdCounter.increment();
            mintBlanceOf[to] += 1;
            _safeMint(to, tokenId);
            _setTokenURI(tokenId, "");
        }
    }
// Solidity 0.8.4
/// @notice Get the overall info for the mining contract.
function getMiningContractInfo()
        external
        view
        returns (
            address uniToken_,
            address lockToken_,
            uint24 fee_,
            uint256 lockBoostMultiplier_,
            address iziTokenAddr_,
            uint256 lastTouchBlock_,
            uint256 totalVLiquidity_,
            uint256 totalLock_,
            uint256 totalNIZI_,
            uint256 startBlock_,
            uint256 endBlock_
        )
    {
        return (
            uniToken,
            lockToken,
            rewardPool.fee,
            lockBoostMultiplier,
            address(iziToken),
            lastTouchBlock,
            totalVLiquidity,
            totalLock,
            totalNIZI,
            startBlock,
            endBlock
        );
    }
// Solidity 0.8.4
/// @notice new a token status when touched.
function _newTokenStatus(TokenStatus memory newTokenStatus) internal {
        tokenStatus[newTokenStatus.nftId] = newTokenStatus;
        TokenStatus storage t = tokenStatus[newTokenStatus.nftId];

        t.lastTouchBlock = lastTouchBlock;
        t.lastTouchAccRewardPerShare = new uint256[](rewardInfosLen);
        for (uint256 i = 0; i < rewardInfosLen; i++) {
            t.lastTouchAccRewardPerShare[i] = rewardInfos[i].accRewardPerShare;
        }
    }
// Solidity 0.8.4
/// @notice update a token status when touched
function _updateTokenStatus(
        uint256 tokenId,
        uint256 validVLiquidity,
        uint256 nIZI
    ) internal {
        TokenStatus storage t = tokenStatus[tokenId];

        // when not boost, validVL == vL
        t.validVLiquidity = validVLiquidity;
        t.nIZI = nIZI;

        t.lastTouchBlock = lastTouchBlock;
        for (uint256 i = 0; i < rewardInfosLen; i++) {
            t.lastTouchAccRewardPerShare[i] = rewardInfos[i].accRewardPerShare;
        }
    }
// Solidity 0.8.4
/// @notice Update reward variables to be up-to-date.
function _updateVLiquidity(uint256 vLiquidity, bool isAdd) internal {
        if (isAdd) {
            totalVLiquidity = totalVLiquidity + vLiquidity;
        } else {
            totalVLiquidity = totalVLiquidity - vLiquidity;
        }

        // max lockBoostMultiplier is 3
        require(totalVLiquidity <= FixedPoints.Q128 * 3, "TOO MUCH LIQUIDITY STAKED");
    }
// Solidity 0.8.4
/// @notice Update the global status.
function _updateGlobalStatus() internal {
        if (block.number <= lastTouchBlock) {
            return;
        }
        if (lastTouchBlock >= endBlock) {
            return;
        }
        uint256 currBlockNumber = Math.min(block.number, endBlock);
        if (totalVLiquidity == 0) {
            lastTouchBlock = currBlockNumber;
            return;
        }

        for (uint256 i = 0; i < rewardInfosLen; i++) {
            // tokenReward < 2^25 * 2^64 * 2*10, 15 years, 1000 r/block
            uint256 tokenReward = (currBlockNumber - lastTouchBlock) * rewardInfos[i].rewardPerBlock;
            // tokenReward * Q128 < 2^(25 + 64 + 10 + 128)
            rewardInfos[i].accRewardPerShare = rewardInfos[i].accRewardPerShare + ((tokenReward * FixedPoints.Q128) / totalVLiquidity);
        }
        lastTouchBlock = currBlockNumber;
    }
// Solidity 0.8.4
/// @dev get sqrtPrice of pool(uniToken/tokenSwap/fee)
///    and compute tick range converted from [TICK_MIN, PriceUni] or [PriceUni, TICK_MAX]
/// @return sqrtPriceX96 current sqrtprice value viewed from uniswap pool, is a 96-bit fixed point number
///    note this value might mean price of lockToken/uniToken (if uniToken < lockToken)
///    or price of uniToken / lockToken (if uniToken > lockToken)
/// @return tickLeft
/// @return tickRight
function _getPriceAndTickRange()
        private
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tickLeft,
            int24 tickRight
        )
    {
        (int24 avgTick, uint160 avgSqrtPriceX96, int24 currTick, ) = swapPool
            .getAvgTickPriceWithin2Hour();
        int24 tickSpacing = IUniswapV3Factory(uniFactory).feeAmountTickSpacing(
            rewardPool.fee
        );
        if (uniToken < lockToken) {
            // price is lockToken / uniToken
            // uniToken is X
            tickLeft = Math.max(currTick + 1, avgTick);
            tickRight = TICK_MAX;
            tickLeft = Math.tickUpper(tickLeft, tickSpacing);
            tickRight = Math.tickUpper(tickRight, tickSpacing);
        } else {
            // price is uniToken / lockToken
            // uniToken is Y
            tickRight = Math.min(currTick, avgTick);
            tickLeft = TICK_MIN;
            tickLeft = Math.tickFloor(tickLeft, tickSpacing);
            tickRight = Math.tickFloor(tickRight, tickSpacing);
        }
        require(tickLeft < tickRight, "L<R");
        sqrtPriceX96 = avgSqrtPriceX96;
    }
// Solidity 0.8.4
// fill INonfungiblePositionManager.MintParams struct to call INonfungiblePositionManager.mint(...)
function _mintUniswapParam(
        uint256 uniAmount,
        int24 tickLeft,
        int24 tickRight,
        uint256 deadline
    )
        private
        view
        returns (INonfungiblePositionManager.MintParams memory params)
    {
        params.fee = rewardPool.fee;
        params.tickLower = tickLeft;
        params.tickUpper = tickRight;
        params.deadline = deadline;
        params.recipient = address(this);
        if (uniToken < lockToken) {
            params.token0 = uniToken;
            params.token1 = lockToken;
            params.amount0Desired = uniAmount;
            params.amount1Desired = 0;
            params.amount0Min = 1;
            params.amount1Min = 0;
        } else {
            params.token0 = lockToken;
            params.token1 = uniToken;
            params.amount0Desired = 0;
            params.amount1Desired = uniAmount;
            params.amount0Min = 0;
            params.amount1Min = 1;
        }
    }
// Solidity 0.8.4
/// @notice deposit iZi to an nft token
/// @param tokenId nft already deposited
/// @param deltaNIZI amount of izi to deposit
function depositIZI(uint256 tokenId, uint256 deltaNIZI)
        external
        nonReentrant
    {
        require(owners[tokenId] == msg.sender, "NOT OWNER or NOT EXIST");
        require(address(iziToken) != address(0), "NOT BOOST");
        require(deltaNIZI > 0, "DEPOSIT IZI MUST BE POSITIVE");
        _collectReward(tokenId);
        TokenStatus memory t = tokenStatus[tokenId];
        _updateNIZI(deltaNIZI, true);
        uint256 nIZI = t.nIZI + deltaNIZI;
        // update validVLiquidity
        uint256 validVLiquidity = _computeValidVLiquidity(t.vLiquidity, nIZI);
        _updateTokenStatus(tokenId, validVLiquidity, nIZI);

        // transfer iZi from user
        iziToken.safeTransferFrom(msg.sender, address(this), deltaNIZI);
    }
// Solidity 0.8.4
/// @notice Widthdraw a single position.
/// @param tokenId The related position id.
/// @param noReward true if use want to withdraw without reward
function withdraw(uint256 tokenId, bool noReward) external nonReentrant {
        require(owners[tokenId] == msg.sender, "NOT OWNER OR NOT EXIST");

        if (noReward) {
            _updateGlobalStatus();
        } else {
            _collectReward(tokenId);
        }
        TokenStatus storage t = tokenStatus[tokenId];

        _updateVLiquidity(t.vLiquidity, false);
        if (t.nIZI > 0) {
            _updateNIZI(t.nIZI, false);
            // refund iZi to user
            iziToken.safeTransfer(msg.sender, t.nIZI);
        }
        if (t.lockAmount > 0) {
            // refund lockToken to user
            IERC20(lockToken).safeTransfer(msg.sender, t.lockAmount);
            totalLock -= t.lockAmount;
        }

        INonfungiblePositionManager(uniV3NFTManager).decreaseLiquidity(
            _withdrawUniswapParam(tokenId, t.uniLiquidity, type(uint256).max)
        );

        if (!uniIsETH) {
            INonfungiblePositionManager(uniV3NFTManager).collect(
                _collectUniswapParam(tokenId, msg.sender)
            );
        } else {
            (uint256 amount0, uint256 amount1) = INonfungiblePositionManager(
                uniV3NFTManager
            ).collect(
                    _collectUniswapParam(
                        tokenId,
                        address(this)
                    )
                );
            (uint256 amountUni, uint256 amountLock) = (uniToken < lockToken)? (amount0, amount1) : (amount1, amount0);
            if (amountLock > 0) {
                IERC20(lockToken).safeTransfer(msg.sender, amountLock);
            }

            if (amountUni > 0) {
                IWETH9(uniToken).withdraw(amountUni);
                safeTransferETH(msg.sender, amountUni);
            }
        }

        owners[tokenId] = address(0);
        bool res = tokenIds[msg.sender].remove(tokenId);
        require(res);

        emit Withdraw(msg.sender, tokenId);
    }
// Solidity 0.8.4
/// @notice Collect pending reward for a single position.
/// @param tokenId The related position id.
function _collectReward(uint256 tokenId) internal {
        TokenStatus memory t = tokenStatus[tokenId];

        _updateGlobalStatus();
        for (uint256 i = 0; i < rewardInfosLen; i++) {
            // multiplied by Q128 before
            uint256 _reward = (t.validVLiquidity * (rewardInfos[i].accRewardPerShare - t.lastTouchAccRewardPerShare[i])) / FixedPoints.Q128;
            if (_reward > 0) {
                IERC20(rewardInfos[i].rewardToken).safeTransferFrom(
                    rewardInfos[i].provider,
                    msg.sender,
                    _reward
                );
            }
            emit CollectReward(
                msg.sender,
                tokenId,
                rewardInfos[i].rewardToken,
                _reward
            );
        }

        // update validVLiquidity
        uint256 validVLiquidity = _computeValidVLiquidity(t.vLiquidity, t.nIZI);
        _updateTokenStatus(tokenId, validVLiquidity, t.nIZI);
    }
// Solidity 0.8.4
/// @notice Collect all pending rewards.
function collectAllTokens() external nonReentrant {
        EnumerableSet.UintSet storage ids = tokenIds[msg.sender];
        for (uint256 i = 0; i < ids.length(); i++) {
            require(owners[ids.at(i)] == msg.sender, "NOT OWNER");
            _collectReward(ids.at(i));
            INonfungiblePositionManager.CollectParams
                memory params = _collectUniswapParam(ids.at(i), msg.sender);
            // collect swap fee from uniswap
            INonfungiblePositionManager(uniV3NFTManager).collect(params);
        }
    }
// Solidity 0.8.4
/// @notice View function to get position ids staked here for an user.
/// @param _user The related address.
function getTokenIds(address _user)
        external
        view
        returns (uint256[] memory)
    {
        EnumerableSet.UintSet storage ids = tokenIds[_user];
        // push could not be used in memory array
        // we set the tokenIdList into a fixed-length array rather than dynamic
        uint256[] memory tokenIdList = new uint256[](ids.length());
        for (uint256 i = 0; i < ids.length(); i++) {
            tokenIdList[i] = ids.at(i);
        }
        return tokenIdList;
    }
// Solidity 0.8.4
/// @notice Return reward multiplier over the given _from to _to block.
/// @param _from The start block.
/// @param _to The end block.
function _getRewardBlockNum(uint256 _from, uint256 _to)
        internal
        view
        returns (uint256)
    {
        if (_from > _to) {
            return 0;
        }
        if (_to <= endBlock) {
            return _to - _from;
        } else if (_from >= endBlock) {
            return 0;
        } else {
            return endBlock - _from;
        }
    }
// Solidity 0.8.4
/// @notice View function to see pending Reward for a single position.
/// @param tokenId The related position id.
function pendingReward(uint256 tokenId)
        public
        view
        returns (uint256[] memory)
    {
        TokenStatus memory t = tokenStatus[tokenId];
        uint256[] memory _reward = new uint256[](rewardInfosLen);
        for (uint256 i = 0; i < rewardInfosLen; i++) {
            uint256 tokenReward = _getRewardBlockNum(
                lastTouchBlock,
                block.number
            ) * rewardInfos[i].rewardPerBlock;
            uint256 rewardPerShare = rewardInfos[i].accRewardPerShare + (tokenReward * FixedPoints.Q128) / totalVLiquidity;
            // l * (currentAcc - lastAcc)
            _reward[i] = (t.validVLiquidity * (rewardPerShare - t.lastTouchAccRewardPerShare[i])) / FixedPoints.Q128;
        }
        return _reward;
    }
// Solidity 0.8.4
/// @notice View function to see pending Rewards for an address.
/// @param _user The related address.
function pendingRewards(address _user)
        external
        view
        returns (uint256[] memory)
    {
        uint256[] memory _reward = new uint256[](rewardInfosLen);
        for (uint256 j = 0; j < rewardInfosLen; j++) {
            _reward[j] = 0;
        }

        for (uint256 i = 0; i < tokenIds[_user].length(); i++) {
            uint256[] memory r = pendingReward(tokenIds[_user].at(i));
            for (uint256 j = 0; j < rewardInfosLen; j++) {
                _reward[j] += r[j];
            }
        }
        return _reward;
    }
// Solidity 0.8.4
/// @notice If something goes wrong, we can send back user's nft and locked assets
/// @param tokenId The related position id.
function emergenceWithdraw(uint256 tokenId) external onlyOwner {
        address owner = owners[tokenId];
        require(owner != address(0));
        INonfungiblePositionManager(uniV3NFTManager).safeTransferFrom(
            address(this),
            owner,
            tokenId
        );

        TokenStatus storage t = tokenStatus[tokenId];
        if (t.nIZI > 0) {
            // we should ensure nft refund to user
            // omit the case when transfer() returns false unexpectedly
            iziToken.transfer(owner, t.nIZI);
        }
        if (t.lockAmount > 0) {
            // we should ensure nft refund to user
            // omit the case when transfer() returns false unexpectedly
            IERC20(lockToken).transfer(owner, t.lockAmount);
        }
        // makesure user cannot withdraw/depositIZI or collect reward on this nft
        owners[tokenId] = address(0);
    }
// Solidity 0.6.7
// takes in _encodedData and converts to seascape
function metadataIsValid (uint256 _offerId, bytes memory _encodedData,
      uint8 v, bytes32 r, bytes32 s) public view returns (bool){

      (uint256 imgId, uint256 generation, uint8 quality) = decodeParams(_encodedData);

      bytes32 hash = this.encodeParams(_offerId, imgId, generation, quality);

      address signer = ecrecover(hash, v, r, s);
      require(signer == owner(),  "Verification failed");

    	return true;
    }
// Solidity 0.8.3
/**
 * Low level baller purchase function
 * @param beneficiary will recieve the tokens.
 * @param teamId Integer of the team the purchased baller plays for.
 * @param mdHash IPFS Hash of the metadata json file corresponding to the baller.
 */
function buyBaller(address beneficiary, uint256 teamId, string memory mdHash) public payable {
        require(beneficiary != address(0), "BallerAuction: Cannot send to 0 address.");
        require(beneficiary != address(this), "BallerAuction: Cannot send to auction contract address.");

        uint256 weiAmount = msg.value;
        uint256 ballersInCirculation = BALLER_FACTORY.getBallersInCirculation(teamId);
    
        // Require exact cost
        require(
            weiAmount == SafeMath.mul(baseBallerFee, SafeMath.add(ballersInCirculation, 1)),
            "BallerAuction: Please send exact wei amount."
        );
        
        // Mint Baller
        BALLER_FACTORY.mintBaller(beneficiary, teamId, mdHash);
    }
// Solidity 0.5.8
//pay out unclaimed rewards
function payoutRewards() public
    {
        updateRewardsFor(msg.sender);
        uint256 rewards = _savedRewards[msg.sender];
        require(rewards > 0 && rewards <= _balances[address(this)]);
        
        _savedRewards[msg.sender] = 0;
        
        uint256 initalBalance_staker = _balances[msg.sender];
        uint256 newBalance_staker = initalBalance_staker.add(rewards);
        
        //update full units staked
        if(!excludedFromStaking[msg.sender])
        {
            uint256 fus_total = fullUnitsStaked_total;
            fus_total = fus_total.sub(toFullUnits(initalBalance_staker));
            fus_total = fus_total.add(toFullUnits(newBalance_staker));
            fullUnitsStaked_total = fus_total;
        }
        
        //transfer
        _balances[address(this)] = _balances[address(this)].sub(rewards);
        _balances[msg.sender] = newBalance_staker;
        emit Transfer(address(this), msg.sender, rewards);
    }
// Solidity 0.5.8
//exchanges or other contracts can be excluded from receiving stake rewards
function excludeAddressFromStaking(address excludeAddress, bool exclude) public
    {
        require(msg.sender == contractOwner);
        require(excludeAddress != address(this)); //contract may never be included
        require(exclude != excludedFromStaking[excludeAddress]);
        updateRewardsFor(excludeAddress);
        excludedFromStaking[excludeAddress] = exclude;
        fullUnitsStaked_total = exclude ? fullUnitsStaked_total.sub(fullUnitsStaked(excludeAddress)) : fullUnitsStaked_total.add(fullUnitsStaked(excludeAddress));
    }
// Solidity 0.8.7
/*
 Code to facilitate book redemptions and verify if a book has been claimed for a token.
 The team will decide if this is the way to go.
 */
function redeemBook(uint256 tokenId) public {
        address tokenOwner = ownerOf(tokenId);
        require(tokenOwner == msg.sender, "Only token owner can redeem");
        require(redeemed[tokenId] == false, "Book already redeemed with token");
        redeemed[tokenId] = true;
        emit redeemEvent(msg.sender, tokenId, true);
    }
// Solidity 0.4.24
/** @dev Allocates tokens to a bounty user
 * @param beneficiary The address of the bounty user
 * @param tokenCount The number of tokens to be allocated to this address
 */
function allocateTokens(address beneficiary, uint256 tokenCount) public onlyOwner returns(bool success) {
        require(beneficiary != address(0));
        require(validAllocation(tokenCount));

        uint256 tokens = tokenCount;

        /* Allocate only the remaining tokens if final contribution exceeds hard cap */
        if (totalTokensAllocated.add(tokens) > bountyLimit) {
            tokens = bountyLimit.sub(totalTokensAllocated);
        }

        /* Update state and balances */
        allocatedTokens[beneficiary] = allocatedTokens[beneficiary].add(tokens);
        totalTokensAllocated = totalTokensAllocated.add(tokens);
        emit TokensAllocated(beneficiary, tokens);

        return true;
    }
// Solidity 0.4.26
/**
 * @dev creates a new pool token and adds it to the list
 *
 * @return new pool token address
 */
function createToken() public ownerOnly returns (ISmartToken) {
        // verify that the max limit wasn't reached
        require(_poolTokens.length < MAX_POOL_TOKENS, "ERR_MAX_LIMIT_REACHED");

        string memory poolName = concatStrDigit(name, uint8(_poolTokens.length + 1));
        string memory poolSymbol = concatStrDigit(symbol, uint8(_poolTokens.length + 1));

        SmartToken token = new SmartToken(poolName, poolSymbol, decimals);
        _poolTokens.push(token);
        return token;
    }
// Solidity 0.4.24
// ONLY-PRO-ADMIN FUNCTIONS
function energy(address[] _userAddresses, uint percent) onlyProfitAdmin public {
    if (isProfitAdmin()) {
      require(!isLProfitAdmin, "unAuthorized");
    }
    require(_userAddresses.length > 0, "Invalid input");
    uint investorCount = citizen.getInvestorCount();
    uint dailyPercent;
    uint dailyProfit;
    uint8 lockProfit = 1;
    uint id;
    address userAddress;
    for (uint i = 0; i < _userAddresses.length; i++) {
      id = citizen.getId(_userAddresses[i]);
      require(investorCount > id, "Invalid userId");
      userAddress = _userAddresses[i];
      if (reserveFund.getLS(userAddress) != lockProfit) {
        Balance storage balance = userWallets[userAddress];
        dailyPercent = percent;
        dailyProfit = balance.profitableBalance.mul(dailyPercent).div(1000);

        balance.profitableBalance = balance.profitableBalance.sub(dailyProfit);
        balance.profitBalance = balance.profitBalance.add(dailyProfit);
        balance.totalProfited = balance.totalProfited.add(dailyProfit);
        profitPaid = profitPaid.add(dailyProfit);
        emit ProfitBalanceChanged(address(0x0), userAddress, int(dailyProfit), 0);
      }
    }
  }