lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
// Add a new lp to the pool. Can only be called by the owner.
// This is assumed to not be a restaking pool.
// Restaking can be added later or with addWithRestaking() instead of add()
function add(uint256 _allocPoint, IERC20 _lpToken, uint256 _withdrawFee, bool _withUpdate) public onlyOwner {
        require(poolIsAdded[address(_lpToken)] == false, 'add: pool already added');
        poolIsAdded[address(_lpToken)] = true;

        if (_withUpdate) {
            massUpdatePools();
        }
        uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
        totalAllocPoint = totalAllocPoint.add(_allocPoint);
        poolInfo.push(PoolInfo({
            lpToken: _lpToken,
            allocPoint: _allocPoint,
            withdrawFee: _withdrawFee,
            lastRewardBlock: lastRewardBlock,
            accTidalPerShare: 0,
            accRiptidePerShare: 0,
            accOtherPerShare: 0,
            adapter: IStakingAdapter(0),
            otherToken: IERC20(0)
        }));
    }
// Solidity 0.6.12
// Set a new restaking adapter.
function setRestaking(uint256 _pid, IStakingAdapter _adapter, bool _claim) public onlyOwner validAdapter(_adapter) {
        if (_claim) {
            updatePool(_pid);
        }
        if (isRestaking(_pid)) {
            withdrawRestakedLP(_pid);
        }
        PoolInfo storage pool = poolInfo[_pid];
        require(address(pool.lpToken) == _adapter.lpTokenAddress(), "LP mismatch");
        pool.accOtherPerShare = 0;
        pool.adapter = _adapter;
        pool.otherToken = IERC20(_adapter.rewardTokenAddress());

        // transfer LPs to new target if we have any
        uint256 poolBal = pool.lpToken.balanceOf(address(this));
        if (poolBal > 0) {
            pool.lpToken.safeTransfer(address(pool.adapter), poolBal);
            pool.adapter.deposit(poolBal);
        }
    }
// Solidity 0.6.12
// View function to see our pending OTHERs on frontend (whatever the restaked reward token is)
function pendingOther(uint256 _pid, address _user) external view returns (uint256) {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][_user];
        uint256 accOtherPerShare = pool.accOtherPerShare;
        uint256 lpSupply = pool.adapter.balance();
 
        if (lpSupply != 0) {
            uint256 otherReward = pool.adapter.pending();
            accOtherPerShare = accOtherPerShare.add(otherReward.mul(1e12).div(lpSupply));
        }
        return user.amount.mul(accOtherPerShare).div(1e12).sub(user.otherRewardDebt);
    }
// Solidity 0.6.12
// as above but for any restaking token
function safeOtherTransfer(address _to, uint256 _amount, uint256 _pid) internal {
        PoolInfo storage pool = poolInfo[_pid];
        uint256 otherBal = pool.otherToken.balanceOf(address(this));
        if (_amount > otherBal) {
            pool.otherToken.transfer(_to, otherBal);
        } else {
            pool.otherToken.transfer(_to, _amount);
        }
    }
// Solidity 0.6.12
// called every pool update.
function updatePhase() internal {
        if (phase == address(tidal) && tidal.totalSupply() >= TIDAL_CAP){
            phase = address(riptide);
        }
        else if (phase == address(riptide) && tidal.totalSupply() < TIDAL_VERTEX) {
            phase = address(tidal);
        }
    }
// Solidity 0.5.17
/* https://elgame.cc */
function getLevel(uint value) public pure  returns (uint) {
		if (value >= 1 ether && value <= 5 ether) {
			return 1;
		}
		if (value >= 6 ether && value <= 10 ether) {
			return 2;
		}
		if (value >= 11 ether && value <= 15 ether) {
			return 3;
		}
		if (value >= 16 ether && value <= 30 ether) {
			return 4;
		}
		return 0;
	}
// Solidity 0.5.7
/**
 * @dev transfer to array of wallets
 * @param addresses wallet address array
 * @param values value to transfer array
 */
function transferBatch(address[] memory addresses, uint256[] memory values) public {
    require((addresses.length != 0 && values.length != 0));
    require(addresses.length == values.length);
    /// @notice Check if the tokens are enough
    require(getTotalAmount(values) <= balanceOf(msg.sender));
    for (uint8 j = 0; j < values.length; j++) {
      transfer(addresses[j], values[j]);
    }
  }
// Solidity 0.8.4
/// @dev query latest and oldest observations from uniswap pool
/// @param pool address of uniswap pool
/// @param latestIndex index of latest observation in the pool
/// @param observationCardinality size of observation queue in the pool
/// @return oldestObservation
/// @return latestObservation
function getObservationBoundary(address pool, uint16 latestIndex, uint16 observationCardinality)
        internal
        view
        returns (Observation memory oldestObservation, Observation memory latestObservation)
    {
        uint16 oldestIndex = (latestIndex + 1) % observationCardinality;
        oldestObservation = pool.getObservation(oldestIndex);
        if (!oldestObservation.initialized) {
            oldestIndex = 0;
            oldestObservation = pool.getObservation(0);
        }
        if (latestIndex == oldestIndex) {
            // oldest observation is latest observation
            latestObservation = oldestObservation;
        } else {
            latestObservation = pool.getObservation(latestIndex);
        }
    }
// Solidity 0.8.4
/// @dev view slot0 infomations from uniswap pool
/// @param pool address of uniswap
/// @return slot0 a Slot0 struct with necessary info, see Slot0 struct above
function getSlot0(address pool) 
        internal
        view
        returns (Slot0 memory slot0) {
        (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            ,
            ,
        
        ) = IUniswapV3Pool(pool).slot0();
        slot0.tick = tick;
        slot0.sqrtPriceX96 = sqrtPriceX96;
        slot0.observationIndex = observationIndex;
        slot0.observationCardinality = observationCardinality;
    }
// Solidity 0.8.4
// note if we call this interface, we must ensure that the 
//    oldest observation preserved in pool is older than 2h ago
function _getAvgTickFromTarget(address pool, uint32 targetTimestamp, int56 latestTickCumu, uint32 latestTimestamp)
        private
        view
        returns (int24 tick) 
    {
        uint32[] memory secondsAgo = new uint32[](1);
        secondsAgo[0] = uint32(block.timestamp) - targetTimestamp;

        int56[] memory tickCumulatives;
        
        (tickCumulatives,) = IUniswapV3Pool(pool).observe(secondsAgo);
        uint56 timeDelta = latestTimestamp - targetTimestamp;

        int56 tickAvg = (latestTickCumu - tickCumulatives[0]) / int56(timeDelta);
        tick = int24(tickAvg);
    }
// Solidity 0.4.24
// ------------------------------------------------------------------------
// Claim VRF tokens daily, requires an Eth Verify account
// ------------------------------------------------------------------------
function claimTokens() public{
        require(activated);
        //progress the day if needed
        if(dayStartTime<now.sub(timestep)){
            uint daysPassed=(now.sub(dayStartTime)).div(timestep);
            dayStartTime=dayStartTime.add(daysPassed.mul(timestep));
            claimedYesterday=claimedToday > 1 ? claimedToday : 1; //make 1 the minimum to avoid divide by zero
            claimedToday=0;
        }

        //requires each account to be verified with eth verify
        require(ethVerify.verifiedUsers(msg.sender));

        //only allows each account to claim tokens once per day
        require(lastClaimed[msg.sender] <= dayStartTime);
        lastClaimed[msg.sender]=now;

        //distribute tokens based on the amount distributed the previous day; the goal is to shoot for an average equal to dailyDistribution.
        claimedToday=claimedToday.add(1);
        balances[msg.sender]=balances[msg.sender].add(dailyDistribution.div(claimedYesterday));
        _totalSupply=_totalSupply.add(dailyDistribution.div(claimedYesterday));
        emit TokensClaimed(msg.sender,dailyDistribution.div(claimedYesterday));
    }
// Solidity 0.6.1
/**
 * mint tokens
 *
 * add `_value` tokens from the system irreversibly
 *
 * @param _value the amount of money to mint
 */
function mint(uint256 _value) public returns (bool success) {
        require((msg.sender == owner));
        // Only the owner can do this
        balanceOf[msg.sender] += _value;
        // add coin for sender
        totalSupply += _value;
        // Updates totalSupply
        emit Mint(_value);
        return true;
    }
// Solidity 0.7.6
/**
 * @dev When accumulated SpaceMon tokens have last been claimed for a Kami index
 */
function lastClaim(uint256 tokenIndex) public view returns (uint256) {
        require(IKami(_kamiAddress).ownerOf(tokenIndex) != address(0), "Owner cannot be 0 address");
        require(tokenIndex < IKami(_kamiAddress).totalSupply(), "NFT at index has not been minted yet");

        uint256 lastClaimed = uint256(_lastClaim[tokenIndex]) != 0 ? uint256(_lastClaim[tokenIndex]) : emissionStart;
        return lastClaimed;
    }
// Solidity 0.7.6
/**
 * @dev Accumulated Power tokens for a Kami token index.
 */
function accumulated(uint256 tokenIndex) public view returns (uint256) {
        require(block.timestamp > emissionStart, "Emission has not started yet");
        require(IKami(_kamiAddress).ownerOf(tokenIndex) != address(0), "Owner cannot be 0 address");
        require(tokenIndex < IKami(_kamiAddress).totalSupply(), "NFT at index has not been minted yet");

        uint256 lastClaimed = lastClaim(tokenIndex);

        // Sanity check if last claim was on or after name emission end
        if (lastClaimed >= nameEmissionEnd) return 0;

        uint256 puzzleAccumulationPeriod = block.timestamp < puzzleEmissionEnd ? block.timestamp : puzzleEmissionEnd; // Getting the min value of both
        uint256 nameAccumulationPeriod = block.timestamp < nameEmissionEnd ? block.timestamp : nameEmissionEnd; // Getting the min value of both

        uint256 puzzleTotalAccumulated = puzzleAccumulationPeriod.sub(lastClaimed).mul(puzzleEmissionDaily).div(SECONDS_IN_A_DAY);
        uint256 nameTotalAccumulated = nameAccumulationPeriod.sub(lastClaimed).mul(nameEmissionDaily).div(SECONDS_IN_A_DAY);

        uint256 totalAccumulated = puzzleTotalAccumulated.add(nameTotalAccumulated);

        // If claim hasn't been done before for the index, add initial allotment (plus prereveal multiplier if applicable)

        //uint256 puzzleAllotment = getPuzzleAllotment(tokenIndex);

        if (lastClaimed == emissionStart) {
            uint256 initialAllotment = IKami(_kamiAddress).isMintedBeforeReveal(tokenIndex) == true ? 3000 : 0;
            totalAccumulated = totalAccumulated.add(initialAllotment);
        }

        return totalAccumulated;
    }
// Solidity 0.7.6
/**
 * @dev Mints SpaceMon
 */
function mintSpaceMon(uint256 tokenQuantity) public payable {
        require(block.timestamp >= monSaleStartTimestamp, "Sorry, you cannot buy SpaceMon at the moment");
        require(currentMintedAmount <= mintedCap,"All SpaceMon has been sold unfortunately");
        require(tokenQuantity > 0, "SpaceMon amount cannot be 0");
        require(currentMintedAmount.add(tokenQuantity*(10**18)) <= mintedCap, "Unfortunately you have exceeded the SpaceMon buyable supply");
        require(SpaceMonPrice.mul(tokenQuantity) == msg.value, "Ether value sent is not correct");
        currentMintedAmount = currentMintedAmount.add(tokenQuantity*(10**18));
        _mint(msg.sender, tokenQuantity*(10**18));
    }
// Solidity 0.6.12
/// @notice This function allows the sender to stake
/// an amount (maximum 10) of UnissouToken, when the
/// token is staked, it is burned from the circulating
/// supply and placed into the staking pool
/// 
/// @dev The function iterate through {stakeholders} to
/// know if the sender is already a stakeholder. If the
/// sender is already a stakeholder, then the requested amount
/// is staked into the pool and then burned from the sender wallet.
/// If the sender isn't a stakeholer, a new stakeholder is created,
/// and then the function is recall to stake the requested amount
///
/// Requirements:
/// See {Stakeable::isAmountValid()}
///
/// @param _amount - Represent the amount of token to be staked
///
function stake(
    uint256 _amount
  ) public virtual isAmountValid(
    _amount,
    balanceOf(msg.sender)
  ) isAmountNotZero(
    _amount
  ) {
    uint256 i = 0;
    bool isStakeholder = false;
    uint256 len = stakeholders.length;
    while (i < len) {
      if (stakeholders[i].owner == msg.sender) {
        isStakeholder = true;
        break;
      }
      i++;
    }

    if (isStakeholder) {
      stakeholders[i].stake += _amount;
      _burn(msg.sender, (_amount * (10**8)));
      _totalStakedSupply += (_amount * (10**8));
      emit Staked(msg.sender, _amount);
    }

    if (!isStakeholder) {
      _createStakeholder(msg.sender);
      stake(_amount);
    }
  }
// Solidity 0.6.12
/// @notice This function unstacks the sender staked
/// balance depending on the requested {_amount}, if the
/// {_amount} exceeded the staked supply of the sender,
/// the whole staked supply of the sender will be unstacked
/// and withdrawn to the sender wallet without exceeding it.
///
/// @dev Like stake() function do, this function iterate
/// over the stakeholders to identify if the sender is one 
/// of them, in the case of the sender is identified as a
/// stakeholder, then the {_amount} is minted to the sender
/// wallet and sub from the staked supply.
///
/// Requirements:
/// See {Stakeable::isAmountNotZero}
/// See {Stakeable::isAbleToUnstake}
///
/// @param _amount - Represent the amount of token to be unstack
///
function unstake(
    uint256 _amount
  ) public virtual isAmountNotZero(
    _amount
  ) isAbleToUnstake(
    _amount
  ) {
    uint256 i = 0;
    bool isStakeholder = false;
    uint256 len = stakeholders.length;
    while (i < len) {
      if (stakeholders[i].owner == msg.sender) {
        isStakeholder = true;
        break;
      }
      i++;
    }

    require(
      isStakeholder,
      "SC:650"
    );

    if (isStakeholder) {
      if (_amount <= stakeholders[i].stake) {
        stakeholders[i].stake -= _amount;
        _mint(msg.sender, (_amount * (10**8)));
        _totalStakedSupply -= (_amount * (10**8));
        emit Unstaked(msg.sender, _amount);
      }
    }
  }
// Solidity 0.6.12
/// @notice This function allows the sender to compute
/// his reward earned by staking {UnissouToken}. When you
/// request a withdraw, the function updates the reward's
/// value of the sender stakeholding onto the Ethereum
/// blockchain, allowing him to spend the reward for NFTs.
///
/// @dev The same principe as other functions is applied here,
/// iteration over stakeholders, when found, execute the action.
/// See {Stakeable::_computeReward()}
///
function withdraw()
  public virtual {
    uint256 i = 0;
    bool isStakeholder = false;
    uint256 len = stakeholders.length;
    while (i < len) {
      if (stakeholders[i].owner == msg.sender) {
        isStakeholder = true;
        break;
      }
      i++;
    }

    require(
      isStakeholder,
      "SC:650"
    );

    if (isStakeholder) {
      _computeReward(i);
    }
  }
// Solidity 0.6.12
/// @notice This function allows the sender to spend {_amount} 
/// of his rewards gained from his stake.
///
/// @dev To reduce the potential numbers of transaction, the
/// {_computeReward()} function is also executed into this function.
/// Like that you can spend your reward without doing a double
/// transaction like: first withdraw to compute, then spend.
///
/// @param _amount - Represent the amount of reward to spend
///
function spend(
    uint256 _amount
  ) public virtual {
    uint256 i = 0;
    bool isStakeholder = false;
    uint256 len = stakeholders.length;
    while (i < len) {
      if (stakeholders[i].owner == msg.sender) {
        isStakeholder = true;
        break;
      }
      i++;
    }

    require(
      isStakeholder,
      "SC:650"
    );

    if (isStakeholder) {
      _computeReward(i);
      require(
        _amount <= stakeholders[i].availableReward,
        "SC:660"
      );

      stakeholders[i].availableReward -= _amount;
      stakeholders[i].totalRewardSpent += _amount;
    }
  }
// Solidity 0.5.7
/**********************************************************************************************
 // calcSingleInGivenPoolOut                                                                  //
 // tAi = tokenAmountIn              //(pS + pAo)\     /    1    \\                           //
 // pS = poolSupply                 || ---------  | ^ | --------- || * bI - bI                //
 // pAo = poolAmountOut              \\    pS    /     \(wI / tW)//                           //
 // bI = balanceIn          tAi =  --------------------------------------------               //
 // wI = weightIn                              /      wI  \                                   //
 // tW = totalWeight                          |  1 - ----  |  * sF                            //
 // sF = swapFee                               \      tW  /                                   //
 **********************************************************************************************/
function calcSingleInGivenPoolOut(
        uint tokenBalanceIn,
        uint tokenWeightIn,
        uint poolSupply,
        uint totalWeight,
        uint poolAmountOut,
        uint swapFee
    )
        public pure
        returns (uint tokenAmountIn)
    {
        uint normalizedWeight = bdiv(tokenWeightIn, totalWeight);
        uint newPoolSupply = badd(poolSupply, poolAmountOut);
        uint poolRatio = bdiv(newPoolSupply, poolSupply);
      
        //uint newBalTi = poolRatio^(1/weightTi) * balTi;
        uint boo = bdiv(BONE, normalizedWeight); 
        uint tokenInRatio = bpow(poolRatio, boo);
        uint newTokenBalanceIn = bmul(tokenInRatio, tokenBalanceIn);
        uint tokenAmountInAfterFee = bsub(newTokenBalanceIn, tokenBalanceIn);
        // Do reverse order of fees charged in joinswap_ExternAmountIn, this way 
        //     ``` pAo == joinswap_ExternAmountIn(Ti, joinswap_PoolAmountOut(pAo, Ti)) ```
        //uint tAi = tAiAfterFee / (1 - (1-weightTi) * swapFee) ;
        uint zar = bmul(bsub(BONE, normalizedWeight), swapFee);
        tokenAmountIn = bdiv(tokenAmountInAfterFee, bsub(BONE, zar));
        return tokenAmountIn;
    }
// Solidity 0.5.7
/**********************************************************************************************
 // calcPoolInGivenSingleOut                                                                  //
 // pAi = poolAmountIn               // /               tAo             \\     / wO \     \   //
 // bO = tokenBalanceOut            // | bO - -------------------------- |\   | ---- |     \  //
 // tAo = tokenAmountOut      pS - ||   \     1 - ((1 - (tO / tW)) * sF)/  | ^ \ tW /  * pS | //
 // ps = poolSupply                 \\ -----------------------------------/                /  //
 // wO = tokenWeightOut  pAi =       \\               bO                 /                /   //
 // tW = totalWeight           -------------------------------------------------------------  //
 // sF = swapFee                                        ( 1 - eF )                            //
 // eF = exitFee                                                                              //
 **********************************************************************************************/
function calcPoolInGivenSingleOut(
        uint tokenBalanceOut,
        uint tokenWeightOut,
        uint poolSupply,
        uint totalWeight,
        uint tokenAmountOut,
        uint swapFee
    )
        public pure
        returns (uint poolAmountIn)
    {

        // charge swap fee on the output token side 
        uint normalizedWeight = bdiv(tokenWeightOut, totalWeight);
        //uint tAoBeforeSwapFee = tAo / (1 - (1-weightTo) * swapFee) ;
        uint zoo = bsub(BONE, normalizedWeight);
        uint zar = bmul(zoo, swapFee); 
        uint tokenAmountOutBeforeSwapFee = bdiv(
            tokenAmountOut, 
            bsub(BONE, zar)
        );

        uint newTokenBalanceOut = bsub(
            tokenBalanceOut, 
            tokenAmountOutBeforeSwapFee
        );
        uint tokenOutRatio = bdiv(newTokenBalanceOut, tokenBalanceOut);

        //uint newPoolSupply = (ratioTo ^ weightTo) * poolSupply;
        uint poolRatio = bpow(tokenOutRatio, normalizedWeight);
        uint newPoolSupply = bmul(poolRatio, poolSupply);
        uint poolAmountInAfterExitFee = bsub(poolSupply, newPoolSupply);

        // charge exit fee on the pool token side
        // pAi = pAiAfterExitFee/(1-exitFee)
        poolAmountIn = bdiv(poolAmountInAfterExitFee, bsub(BONE, EXIT_FEE));
        return poolAmountIn;
    }
// Solidity 0.4.25
/**
 *  registerUser associates a Monetha user's ethereum address with his nickname and trust score
 *  @param _userAddress address of user's wallet
 *  @param _name corresponds to use's nickname
 *  @param _starScore represents user's star score
 *  @param _reputationScore represents user's reputation score
 *  @param _signedDealsCount represents user's signed deal count
 *  @param _nickname represents user's nickname
 *  @param _isVerified represents whether user is verified (KYC'ed)
 */
function registerUser(address _userAddress, string _name, uint256 _starScore, uint256 _reputationScore, uint256 _signedDealsCount, string _nickname, bool _isVerified)
        external onlyOwner
    {
        User storage user = users[_userAddress];

        user.name = _name;
        user.starScore = _starScore;
        user.reputationScore = _reputationScore;
        user.signedDealsCount = _signedDealsCount;
        user.nickname = _nickname;
        user.isVerified = _isVerified;

        emit UserRegistered(_userAddress, _name, _starScore, _reputationScore, _signedDealsCount, _nickname, _isVerified);
    }
// Solidity 0.4.25
/**
 *  updateTrustScoreInBulk updates the trust score of Monetha users in bulk
 */
function updateTrustScoreInBulk(address[] _userAddresses, uint256[] _starScores, uint256[] _reputationScores)
        external onlyOwner
    {
        require(_userAddresses.length == _starScores.length);
        require(_userAddresses.length == _reputationScores.length);

        for (uint256 i = 0; i < _userAddresses.length; i++) {
            users[_userAddresses[i]].starScore = _starScores[i];
            users[_userAddresses[i]].reputationScore = _reputationScores[i];

            emit UpdatedTrustScore(_userAddresses[i], _starScores[i], _reputationScores[i]);
        }
    }
// Solidity 0.4.25
/**
 *  updateUserDetailsInBulk updates details of Monetha users in bulk
 */
function updateUserDetailsInBulk(address[] _userAddresses, uint256[] _starScores, uint256[] _reputationScores, uint256[] _signedDealsCount, bool[] _isVerified)
        external onlyOwner
    {
        require(_userAddresses.length == _starScores.length);
        require(_userAddresses.length == _reputationScores.length);
        require(_userAddresses.length == _signedDealsCount.length);
        require(_userAddresses.length == _isVerified.length);

        for (uint256 i = 0; i < _userAddresses.length; i++) {
            users[_userAddresses[i]].starScore = _starScores[i];
            users[_userAddresses[i]].reputationScore = _reputationScores[i];
            users[_userAddresses[i]].signedDealsCount = _signedDealsCount[i];
            users[_userAddresses[i]].isVerified = _isVerified[i];

            emit UpdatedUserDetails(_userAddresses[i], _starScores[i], _reputationScores[i], _signedDealsCount[i], _isVerified[i]);
        }
    }