lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.16
// this low-level function should be called from a contract which performs important safety checks
function mint(address to) external lock returns (uint liquidity) {
        (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
        uint balance0 = IERC20(token0).balanceOf(address(this));
        uint balance1 = IERC20(token1).balanceOf(address(this));
        uint amount0 = balance0.sub(_reserve0);
        uint amount1 = balance1.sub(_reserve1);

        bool feeOn = _mintFee(_reserve0, _reserve1);
        uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
        if (_totalSupply == 0) {
            liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
           _mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
        } else {
            liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
        }
        require(liquidity > 0, 'ImpulsevenSwapV2: INSUFFICIENT_LIQUIDITY_MINTED');
        _mint(to, liquidity);

        _update(balance0, balance1, _reserve0, _reserve1);
        if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
        emit Mint(msg.sender, amount0, amount1);
    }
// Solidity 0.8.10
/**
 * Realize $CARROT earnings and optionally unstake tokens.
 * @param tokenIds the IDs of the tokens to claim earnings from
 * @param unstake whether or not to unstake ALL of the tokens listed in tokenIds
 * @param membership wheather user is membership or not
 * @param seed account seed
 * @param sig signature
 */
function claimRewardsAndUnstake(uint16[] calldata tokenIds, bool unstake, bool membership, uint48 expiration, uint256 seed, bytes memory sig) external whenNotPaused nonReentrant _eosOnly _updateEarnings {
    require(isValidSignature(msg.sender, membership, expiration, seed, sig), "invalid signature");

    uint128 reward;
    IFoxGameNFT.Kind kind;
    uint48 time = uint48(block.timestamp);
    for (uint8 i = 0; i < tokenIds.length; i++) {
      kind = _getKind(tokenIds[i]);
      if (kind == IFoxGameNFT.Kind.RABBIT) {
        reward += _claimRabbitsFromKeep(tokenIds[i], unstake, time, seed);
      } else if (kind == IFoxGameNFT.Kind.FOX) {
        reward += _claimFoxFromDen(tokenIds[i], unstake, seed);
      } else { // HUNTER
        reward += _claimHunterFromCabin(tokenIds[i], unstake, time);
      }
    }
    if (reward != 0) {
      foxCarrot.mint(msg.sender, reward);
    }
  }
// Solidity 0.6.12
/**
 * @dev onlyManyOwners modifier helper
 */
function checkHowManyOwners(uint howMany) internal returns(bool) {
        if (insideCallSender == msg.sender) {
            require(howMany <= insideCallCount, "checkHowManyOwners: nested owners modifier check require more owners");
            return true;
        }

        uint ownerIndex = ownersIndices[msg.sender] - 1;
        require(ownerIndex < owners.length, "checkHowManyOwners: msg.sender is not an owner");
        bytes32 operation = keccak256(abi.encodePacked(msg.data, ownersGeneration));

        require((votesMaskByOperation[operation] & (2 ** ownerIndex)) == 0, "checkHowManyOwners: owner already voted for the operation");
        votesMaskByOperation[operation] |= (2 ** ownerIndex);
        uint operationVotesCount = votesCountByOperation[operation] + 1;
        votesCountByOperation[operation] = operationVotesCount;
        if (operationVotesCount == 1) {
            allOperationsIndicies[operation] = allOperations.length;
            allOperations.push(operation);
            emit OperationCreated(operation, howMany, owners.length, msg.sender);
        }
        emit OperationUpvoted(operation, operationVotesCount, howMany, owners.length, msg.sender);

        // If enough owners confirmed the same operation
        if (votesCountByOperation[operation] == howMany) {
            deleteOperation(operation);
            emit OperationPerformed(operation, howMany, owners.length, msg.sender);
            return true;
        }

        return false;
    }
// Solidity 0.6.12
/**
 * @dev Used to delete cancelled or performed operation
 * @param operation defines which operation to delete
 */
function deleteOperation(bytes32 operation) internal {
        uint index = allOperationsIndicies[operation];
        if (index < allOperations.length - 1) { // Not last
            allOperations[index] = allOperations[allOperations.length - 1];
            allOperationsIndicies[allOperations[index]] = index;
        }
        //allOperations.length-1
        allOperations.push(allOperations[allOperations.length-1]);

        delete votesMaskByOperation[operation];
        delete votesCountByOperation[operation];
        delete allOperationsIndicies[operation];
    }
// Solidity 0.6.12
/**
 * @dev Allows owners to change their mind by cacnelling votesMaskByOperation operations
 * @param operation defines which operation to delete
 */
function cancelPending(bytes32 operation) public onlyAnyOwner {
        uint ownerIndex = ownersIndices[msg.sender] - 1;
        require((votesMaskByOperation[operation] & (2 ** ownerIndex)) != 0, "cancelPending: operation not found for this user");
        votesMaskByOperation[operation] &= ~(2 ** ownerIndex);
        uint operationVotesCount = votesCountByOperation[operation] - 1;
        votesCountByOperation[operation] = operationVotesCount;
        emit OperationDownvoted(operation, operationVotesCount, owners.length, msg.sender);
        if (operationVotesCount == 0) {
            deleteOperation(operation);
            emit OperationCancelled(operation, msg.sender);
        }
    }
// Solidity 0.6.12
/**
 * @dev Allows owners to change ownership
 * @param newOwners defines array of addresses of new owners
 * @param newHowManyOwnersDecide defines how many owners can decide
 */
function transferOwnershipWithHowMany(address[] memory newOwners, uint256 newHowManyOwnersDecide) public onlyManyOwners {
        require(newOwners.length > 0, "transferOwnershipWithHowMany: owners array is empty");
        require(newOwners.length <= 256, "transferOwnershipWithHowMany: owners count is greater then 256");
        require(newHowManyOwnersDecide > 0, "transferOwnershipWithHowMany: newHowManyOwnersDecide equal to 0");
        require(newHowManyOwnersDecide <= newOwners.length, "transferOwnershipWithHowMany: newHowManyOwnersDecide exceeds the number of owners");

        // Reset owners reverse lookup table
        for (uint j = 0; j < owners.length; j++) {
            delete ownersIndices[owners[j]];
        }
        for (uint i = 0; i < newOwners.length; i++) {
            require(newOwners[i] != address(0), "transferOwnershipWithHowMany: owners array contains zero");
            require(ownersIndices[newOwners[i]] == 0, "transferOwnershipWithHowMany: owners array contains duplicates");
            ownersIndices[newOwners[i]] = i + 1;
        }
        
        emit OwnershipTransferred(owners, howManyOwnersDecide, newOwners, newHowManyOwnersDecide);
        owners = newOwners;
        howManyOwnersDecide = newHowManyOwnersDecide;
        // allOperations.length = 0;
        allOperations.push(allOperations[0]);
        ownersGeneration++;
    }
// Solidity 0.5.16
/// @notice this function is used to send ES as prepaid for PET
/// @dev some ES already in prepaid required
/// @param _addresses: address array to send prepaid ES for PET
/// @param _amounts: prepaid ES for PET amounts to send to corresponding addresses
function sendPrepaidESDifferent(
    address[] memory _addresses,
    uint256[] memory _amounts
  ) public {
    for(uint256 i = 0; i < _addresses.length; i++) {
      /// @notice subtracting amount from sender prepaidES
      prepaidES[msg.sender] = prepaidES[msg.sender].sub(_amounts[i]);

      /// @notice then incrementing the amount into receiver's prepaidES
      prepaidES[_addresses[i]] = prepaidES[_addresses[i]].add(_amounts[i]);
    }
  }
// Solidity 0.5.16
/// @notice this function is used by anyone to create a new PET
/// @param _planId: id of PET in staker portfolio
/// @param _monthlyCommitmentAmount: PET monthly commitment amount in exaES
function newPET(
    uint256 _planId,
    uint256 _monthlyCommitmentAmount
  ) public {
    /// @notice enforcing that the plan should be active
    require(
      petPlans[_planId].isPlanActive
      , 'PET plan is not active'
    );

    /// @notice enforcing that monthly commitment by the staker should be more than
    ///   minimum monthly commitment in the selected plan
    require(
      _monthlyCommitmentAmount >= petPlans[_planId].minimumMonthlyCommitmentAmount
      , 'low monthlyCommitmentAmount'
    );

    /// @notice adding the PET to staker's pets storage
    pets[msg.sender].push(PET({
      planId: _planId,
      monthlyCommitmentAmount: _monthlyCommitmentAmount,
      initTimestamp: now,
      lastAnnuityWithdrawlMonthId: 0,
      appointeeVotes: 0,
      numberOfAppointees: 0
    }));

    /// @notice emiting an event
    emit NewPET(
      msg.sender,
      pets[msg.sender].length - 1,
      _monthlyCommitmentAmount
    );
  }
// Solidity 0.5.16
/// @notice this function is used by deployer to create plans for new PETs
/// @param _minimumMonthlyCommitmentAmount: minimum PET monthly amount in exaES
/// @param _monthlyBenefitFactorPerThousand: this is per 1000; i.e 200 for 20%
function createPETPlan(
    uint256 _minimumMonthlyCommitmentAmount,
    uint256 _monthlyBenefitFactorPerThousand
  ) public onlyDeployer {

    /// @notice adding the petPlan to storage
    petPlans.push(PETPlan({
      isPlanActive: true,
      minimumMonthlyCommitmentAmount: _minimumMonthlyCommitmentAmount,
      monthlyBenefitFactorPerThousand: _monthlyBenefitFactorPerThousand
    }));

    /// @notice emitting an event
    emit NewPETPlan(
      _minimumMonthlyCommitmentAmount,
      _monthlyBenefitFactorPerThousand,
      petPlans.length - 1
    );
  }
// Solidity 0.5.16
/// @notice this function is used to update nominee status of a wallet address in PET
/// @param _petId: id of PET in staker portfolio.
/// @param _nomineeAddress: eth wallet address of nominee.
/// @param _newNomineeStatus: true or false, whether this should be a nominee or not.
function toogleNominee(
    uint256 _petId,
    address _nomineeAddress,
    bool _newNomineeStatus
  ) public {
    /// @notice updating nominee status
    pets[msg.sender][_petId].nominees[_nomineeAddress] = _newNomineeStatus;

    /// @notice emiting event for UI and other applications
    emit NomineeUpdated(msg.sender, _petId, _nomineeAddress, _newNomineeStatus);
  }
// Solidity 0.5.16
/// @notice this function is used to update appointee status of a wallet address in PET
/// @param _petId: id of PET in staker portfolio.
/// @param _appointeeAddress: eth wallet address of appointee.
/// @param _newAppointeeStatus: true or false, should this have appointee rights or not.
function toogleAppointee(
    uint256 _petId,
    address _appointeeAddress,
    bool _newAppointeeStatus
  ) public {
    PET storage _pet = pets[msg.sender][_petId];

    /// @notice if not an appointee already and _newAppointeeStatus is true, adding appointee
    if(!_pet.appointees[_appointeeAddress] && _newAppointeeStatus) {
      _pet.numberOfAppointees = _pet.numberOfAppointees.add(1);
      _pet.appointees[_appointeeAddress] = true;
    }

    /// @notice if already an appointee and _newAppointeeStatus is false, removing appointee
    else if(_pet.appointees[_appointeeAddress] && !_newAppointeeStatus) {
      _pet.appointees[_appointeeAddress] = false;
      _pet.numberOfAppointees = _pet.numberOfAppointees.sub(1);
    }

    emit AppointeeUpdated(msg.sender, _petId, _appointeeAddress, _newAppointeeStatus);
  }
// Solidity 0.5.16
/// @notice this function is used by appointee to vote that nominees can withdraw early
/// @dev need to be appointee, set by staker themselves
/// @param _stakerAddress: address of initiater of this PET.
/// @param _petId: id of PET in staker portfolio.
function appointeeVote(
    address _stakerAddress,
    uint256 _petId
  ) public {
    PET storage _pet = pets[_stakerAddress][_petId];

    /// @notice checking if appointee has rights to cast a vote
    require(_pet.appointees[msg.sender]
      , 'should be appointee to cast vote'
    );

    /// @notice removing appointee's rights to vote again
    _pet.appointees[msg.sender] = false;

    /// @notice adding a vote to PET
    _pet.appointeeVotes = _pet.appointeeVotes.add(1);

    /// @notice emit that appointee has voted
    emit AppointeeVoted(_stakerAddress, _petId, msg.sender);
  }
// Solidity 0.5.16
/// @notice this function is used by contract to get nominee's allowed timestamp
/// @param _stakerAddress: address of staker who has a PET
/// @param _petId: id of PET in staker address portfolio
/// @param _annuityMonthId: this is the month for which timestamp to find
/// @return nominee allowed timestamp
function getNomineeAllowedTimestamp(
    address _stakerAddress,
    uint256 _petId,
    uint256 _annuityMonthId
  ) public view returns (uint256) {
    PET storage _pet = pets[_stakerAddress][_petId];
    uint256 _allowedTimestamp = _pet.initTimestamp
      + (12 + _annuityMonthId - 1) * EARTH_SECONDS_IN_MONTH;

    /// @notice if tranasction sender is not the staker, then more delay to _allowedTimestamp
    if(msg.sender != _stakerAddress) {
      if(_pet.appointeeVotes > _pet.numberOfAppointees.div(2)) {
        _allowedTimestamp += EARTH_SECONDS_IN_MONTH * 6;
      } else {
        _allowedTimestamp += EARTH_SECONDS_IN_MONTH * 12;
      }
    }

    return _allowedTimestamp;
  }
// Solidity 0.5.16
/// @notice this function is used to get total annuity benefits between two months
/// @param _stakerAddress: address of staker who has a PET
/// @param _petId: id of PET in staker address portfolio
/// @param _startAnnuityMonthId: this is the month (inclusive) to start from
/// @param _endAnnuityMonthId: this is the month (inclusive) to stop at
function getSumOfMonthlyAnnuity(
    address _stakerAddress,
    uint256 _petId,
    uint256 _startAnnuityMonthId,
    uint256 _endAnnuityMonthId
  ) public view returns (uint256) {
    /// @notice get the storage references of staker's PET and Plan
    PET storage _pet = pets[_stakerAddress][_petId];
    PETPlan storage _petPlan = petPlans[_pet.planId];

    uint256 _totalDeposits;

    /// @notice calculating both deposits for every month and adding it
    for(uint256 _i = _startAnnuityMonthId; _i <= _endAnnuityMonthId; _i++) {
      uint256 _modulo = _i%12;
      uint256 _depositAmountIncludingPET = _getTotalDepositedIncludingPET(_pet.monthlyDepositAmount[_modulo==0?12:_modulo], _pet.monthlyCommitmentAmount);

      _totalDeposits = _totalDeposits.add(_depositAmountIncludingPET);
    }

    /// @notice calculating annuity from total both deposits done
    return _totalDeposits.mul(_petPlan.monthlyBenefitFactorPerThousand).div(1000);
  }
// Solidity 0.5.16
/// @notice calculating power booster amount
/// @param _stakerAddress: address of staker who has PET
/// @param _petId: id of PET in staket address portfolio
/// @return single power booster amount
function calculatePowerBoosterAmount(
    address _stakerAddress,
    uint256 _petId
  ) public view returns (uint256) {
    /// @notice get the storage reference of staker's PET
    PET storage _pet = pets[_stakerAddress][_petId];

    uint256 _totalDepositedIncludingPET;

    /// @notice calculating total deposited by staker and pet in all 12 months
    for(uint256 _i = 1; _i <= 12; _i++) {
      uint256 _depositAmountIncludingPET = _getTotalDepositedIncludingPET(
        _pet.monthlyDepositAmount[_i],
        _pet.monthlyCommitmentAmount
      );

      _totalDepositedIncludingPET = _totalDepositedIncludingPET.add(_depositAmountIncludingPET);
    }

    return _totalDepositedIncludingPET.div(12);
  }
// Solidity 0.5.16
/// @notice this function is used internally to burn penalised booster tokens
/// @param _stakerAddress: address of staker who has a PET
/// @param _petId: id of PET in staker address portfolio
function _burnPenalisedPowerBoosterTokens(
    address _stakerAddress,
    uint256 _petId
  ) private {
    /// @notice get the storage references of staker's PET
    PET storage _pet = pets[_stakerAddress][_petId];

    uint256 _unachieveTargetCount;

    /// @notice calculating number of unacheived targets
    for(uint256 _i = 1; _i <= 12; _i++) {
      if(_pet.monthlyDepositAmount[_i] < _pet.monthlyCommitmentAmount) {
        _unachieveTargetCount++;
      }
    }

    uint256 _powerBoosterAmount = calculatePowerBoosterAmount(_stakerAddress, _petId);

    /// @notice burning the unacheived power boosters
    uint256 _burningAmount = _powerBoosterAmount.mul(_unachieveTargetCount);
    token.burn(_burningAmount);

    // @notice emitting an event
    emit BoosterBurn(_stakerAddress, _petId, _burningAmount);
  }
// Solidity 0.5.16
/// @notice this function is used by contract to get total deposited amount including PET
/// @param _amount: amount of ES which is deposited
/// @param _monthlyCommitmentAmount: commitment amount of staker
/// @return staker plus pet deposit amount based on acheivement of commitment
function _getTotalDepositedIncludingPET(
    uint256 _amount,
    uint256 _monthlyCommitmentAmount
  ) private pure returns (uint256) {
    uint256 _petAmount;

    /// @notice if there is topup then add half of topup to pet
    if(_amount > _monthlyCommitmentAmount) {
      uint256 _topupAmount = _amount.sub(_monthlyCommitmentAmount);
      _petAmount = _monthlyCommitmentAmount.add(_topupAmount.div(2));
    }
    /// @notice otherwise if amount is atleast half of commitment and at most commitment
    ///   then take staker amount as the pet amount
    else if(_amount >= _monthlyCommitmentAmount.div(2)) {
      _petAmount = _amount;
    }

    /// @notice finally sum staker amount and pet amount and return it
    return _amount.add(_petAmount);
  }
// Solidity 0.5.17
// **PUBLIC PAYABLE functions**
// Example: _collToken = Eth, _borrowToken = USDC
function deposit(
        address _collToken, address _cCollToken, uint _collAmount, address _borrowToken, address _cBorrowToken, uint _borrowAmount
    ) public payable authCheck {
        // add _cCollToken to market
        enterMarketInternal(_cCollToken);

        // mint _cCollToken
        mintInternal(_collToken, _cCollToken, _collAmount);

        // borrow and withdraw _borrowToken
        if (_borrowToken != address(0)) {
            borrowInternal(_borrowToken, _cBorrowToken, _borrowAmount);
        }
    }
// Solidity 0.5.17
// Example: _collToken = Eth, _borrowToken = USDC
function withdraw(
        address _collToken, address _cCollToken, uint256 cAmountRedeem, address _borrowToken, address _cBorrowToken, uint256 amountRepay
    ) public payable authCheck returns (uint256) {
        // repayBorrow _cBorrowToken
        paybackInternal(_borrowToken, _cBorrowToken, amountRepay);

        // redeem _cCollToken
        return redeemInternal(_collToken, _cCollToken, cAmountRedeem);
    }
// Solidity 0.6.3
/// @notice Adds to governance contract staking reward tokens to be sent to vote process participants.
/// @param _reward Amount of staking rewards token in wei
function notifyRewardAmount(uint256 _reward)
        external
        onlyRewardDistribution
        override
        updateReward(address(0))
    {
        IERC20(rewardsToken).safeTransferFrom(_msgSender(), address(this), _reward);
        if (block.timestamp >= periodFinish) {
            rewardRate = _reward.div(DURATION);
        } else {
            uint256 remaining = periodFinish.sub(block.timestamp);
            uint256 leftover = remaining.mul(rewardRate);
            rewardRate = _reward.add(leftover).div(DURATION);
        }
        lastUpdateTime = block.timestamp;
        periodFinish = block.timestamp.add(DURATION);
        emit RewardAdded(_reward);
    }
// Solidity 0.6.3
/// @notice Creates a proposal to vote
/// @param _executor Executor contract address
/// @param _hash IPFS hash of the proposal document
function propose(address _executor, string memory _hash) public {
        require(votesOf(_msgSender()) > minimum, "<minimum");
        proposals[proposalCount] = Proposal({
            id: proposalCount,
            proposer: _msgSender(),
            totalForVotes: 0,
            totalAgainstVotes: 0,
            start: block.number,
            end: period.add(block.number),
            executor: _executor,
            hash: _hash,
            totalVotesAvailable: totalVotes,
            quorum: 0,
            quorumRequired: quorum,
            open: true
        });
        emit NewProposal(
            proposalCount,
            _msgSender(),
            block.number,
            period,
            _executor
        );
        proposalCount++;
        voteLock[_msgSender()] = lock.add(block.number);
    }
// Solidity 0.6.3
/// @notice Called by third party to execute the proposal conditions
/// @param _id ID of the proposal
function execute(uint256 _id) public {
        (uint256 _for, uint256 _against, uint256 _quorum) = getStats(_id);
        require(proposals[_id].quorumRequired < _quorum, "!quorum");
        require(proposals[_id].end < block.number , "!end");
        if (proposals[_id].open) {
            tallyVotes(_id);
        }
        IExecutor(proposals[_id].executor).execute(_id, _for, _against, _quorum);
    }
// Solidity 0.6.3
/// @notice Called by anyone to obtain the voting process statistics for specific proposal
/// @param _id ID of the proposal
/// @return _for 'For' percentage in base points
/// @return _against 'Against' percentage in base points
/// @return _quorum Current quorum percentage in base points
function getStats(uint256 _id)
        public
        view
        returns(
            uint256 _for,
            uint256 _against,
            uint256 _quorum
        )
    {
        _for = proposals[_id].totalForVotes;
        _against = proposals[_id].totalAgainstVotes;
        uint256 _total = _for.add(_against);
        if (_total == 0) {
          _quorum = 0;
        } else {
          _for = _for.mul(10000).div(_total);
          _against = _against.mul(10000).div(_total);
          _quorum = _total.mul(10000).div(proposals[_id].totalVotesAvailable);
        }
    }
// Solidity 0.6.3
/// @notice Nullify (revoke) all the votes staked by msg.sender
function revoke() public {
        require(voters[_msgSender()], "!voter");
        voters[_msgSender()] = false;

        /// @notice Edge case dealt with in openzeppelin trySub methods.
        /// The case should be impossible, but this is defi.
        (,totalVotes) = totalVotes.trySub(votes[_msgSender()]);

        emit RevokeVoter(_msgSender(), votes[_msgSender()], totalVotes);
        votes[_msgSender()] = 0;
    }
// Solidity 0.5.4
/* Public Functions - Start */
function register(
    address _tenant,
    address[] memory _creators,
    address[] memory _admins,
    uint8 _quorum
  ) public returns (bool success) {
    require(
      msg.sender == _tenant || msg.sender == Ownable(_tenant).owner(),
      "ONLY_TENANT_OR_TENANT_OWNER"
    );

    return _register(_tenant, _creators, _admins, _quorum);
  }