lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.6
/**
 * @notice ETH -> LBT & iDOL
 * @param bondGroupID is a bond group ID
 * @return poolID is a pool ID
 * @return IDOLAmount is iDOL amount obtained
 */
function issueLBTAndIDOL(uint256 bondGroupID)
        public
        override
        payable
        returns (
            bytes32,
            uint256,
            uint256
        )
    {
        (
            bytes32 solidBondID,
            bytes32[] memory liquidBondIDs
        ) = _findSBTAndLBTBondGroup(bondGroupID); // find SBT & LBT
        require(
            solidBondID != bytes32(0),
            "solid bond is not found in given bond group"
        );

        // 1. ETH -> SBT & LBTs
        uint256 bondAmount = _bondMakerContract.issueNewBonds{value: msg.value}(
            bondGroupID
        );

        // 2. SBT -> IDOL
        (address SBTAddress, , , ) = _bondMakerContract.getBond(solidBondID);
        (bytes32 poolID, uint256 IDOLAmount) = _swapSBT2IDOL(
            solidBondID,
            SBTAddress,
            bondAmount
        );

        // 3. IDOL reduction.
        //_reductionERC20(address(_IDOLContract), IDOLAmount);

        // 4. LBTs reduction.
        for (uint256 i = 0; i < liquidBondIDs.length; i++) {
            (address liquidAddress, , , ) = _bondMakerContract.getBond(
                liquidBondIDs[i]
            );
            _reductionERC20(liquidAddress, bondAmount);
            LogIssueLBT(liquidBondIDs[i], msg.sender, bondAmount);
        }
        return (poolID, bondAmount, IDOLAmount);
    }
// Solidity 0.6.6
/**
 * @notice ETH -> iDOL
 * @param bondGroupID is a bond group ID
 * @param timeout (uniswap)
 * @param isLimit (uniswap)
 */
function issueIDOLOnly(
        uint256 bondGroupID,
        uint256 timeout,
        bool isLimit
    ) public override payable {
        // 0. uses: ETH
        (
            bytes32 solidBondID,
            bytes32[] memory liquidBondIDs
        ) = _findSBTAndLBTBondGroup(bondGroupID); // find SBT & LBT
        require(
            solidBondID != bytes32(0),
            "solid bond is not found in given bond group"
        );

        // 1. ETH -> SBT & LBTs
        uint256 bondAmount = _bondMakerContract.issueNewBonds{value: msg.value}(
            bondGroupID
        );

        // 2. SBT -> IDOL
        (address SBTAddress, , , ) = _bondMakerContract.getBond(solidBondID);
        _swapSBT2IDOL(solidBondID, SBTAddress, bondAmount);

        // 3. IDOL reduction.
        //_reductionERC20(address(_IDOLContract), IDOLAmount);

        // 4. LBTs -> IDOL(+exchange)
        for (uint256 i = 0; i < liquidBondIDs.length; i++) {
            (address liquidAddress, , , ) = _bondMakerContract.getBond(
                liquidBondIDs[i]
            );
            // LBT -> IDOL(+exchange)
            _swapLBT2IDOL(liquidAddress, bondAmount, timeout, isLimit);
        }
    }
// Solidity 0.7.3
/*
 * return 5 values - the canClaim returns the number of claimerContract token that can claim
 */
function triBalanceOf(address addr) view public returns (uint nwoBal,uint moriesBal,uint lossamosBal,uint moriesCanClaim,uint lossamosCanClaim){
        uint moriesBal = mories.balanceOf(addr);
        uint lossamosBal=lossamos.balanceOf(addr);


        uint tokenId;
        uint moriesCanClaim = 0;
        
        for(uint i = 0; i < moriesBal; i++) {
            tokenId = mories.tokenOfOwnerByIndex(addr, i);
            if (!_exists(tokenId)) {moriesCanClaim++;}
        }

         
        uint lossamosCanClaim = 0;
        
        for(uint i = 0; i < lossamosBal; i++) {
            tokenId = lossamos.tokenOfOwnerByIndex(addr, i);
            if (canLosSamosClaim(tokenId)>0) {lossamosCanClaim++;}
        }

        return (balanceOf(addr),moriesBal,lossamosBal,moriesCanClaim,lossamosCanClaim);
    }
// Solidity 0.7.3
/**
 * Claim token for los samos owners 
 */
function claimNTokens(uint[] memory tokenIds,ClaimerContract claimerContract, uint claimRatio,uint startIndex,uint maxSupply,uint firtsTokenId) public {
        
        require(claimIsActive, "Claim must be active");
        require(tokenIds.length>0, "Must claim at least one token.");
        require(totalSupply().add(tokenIds.length*claimRatio) <= MAX_TOKEN, "Purchase would exceed max supply.");
        
        for(uint i = 0; i < tokenIds.length; i++) {
                require(tokenIds[i]>=firtsTokenId,"Requested TokenId is above lower bound");
                require(tokenIds[i] <firtsTokenId+ maxSupply,"Requested TokenId is below upper bound"); 
                require(claimerContract.ownerOf(tokenIds[i]) == msg.sender, "Must own the requested tokenId to claim a NWO");
                uint _claimedTokendId = startIndex + tokenIds[i];    
                require(!_exists(_claimedTokendId), "One of the NWO has already been claimed");
        }
       

        for(uint i = 0; i < tokenIds.length; i++) {
                for(uint j = 0; j <claimRatio;j++) {
                    uint claimedTokendId = startIndex + tokenIds[i]  + j*maxSupply;
                    if (!_exists(claimedTokendId)) {
                        _safeMint(msg.sender, claimedTokendId);
                    }    
                }
        }
      
        trySetStartingIndexBlock();
    }
// Solidity 0.4.19
/**
 * Internal transfer, only can be called by this contract
 *
 * @param _from - address of the contract
 * @param _to - address of the investor
 * @param _value - tokens for the investor
 */
function _transfer(address _from, address _to, uint256 _value) internal
    {
        // Prevent transfer to 0x0 address. Use burn() instead
        require(_to != 0x0);
        // Check if the sender has enough
        require(balanceOf[_from] >= _value);
        // Check for overflows
        require(balanceOf[_to].add(_value) > balanceOf[_to]);
        // Save this for an assertion in the future
        uint previousBalances = balanceOf[_from].add(balanceOf[_to]);
        // Subtract from the sender
        balanceOf[_from] = balanceOf[_from].sub(_value);
        // Add the same to the recipient
        balanceOf[_to] = balanceOf[_to].add(_value);

        Transfer(_from, _to, _value);
        // Asserts are used to use static analysis to find bugs in your code. They should never fail
        assert(balanceOf[_from].add(balanceOf[_to]) == previousBalances);
    }
// Solidity 0.4.19
/*
 *  Make discount
 */
function countDiscount(uint256 amount) internal
        returns(uint256)
    {
        uint256 _amount = (amount.mul(DEC)).div(buyPrice);

        if (1 == stage) {
            _amount = _amount.add(withDiscount(_amount, ICO.discount));
        }
        else if (2 == stage)
        {
            if (now <= ICO.startDate + 1 days)
            {
                if (0 == ICO.discountFirstDayICO) {
                    ICO.discountFirstDayICO = 20;
                }
                _amount = _amount.add(withDiscount(_amount, ICO.discountFirstDayICO));
            }
            else
            {
                _amount = _amount.add(withDiscount(_amount, ICO.discount));
            }
        }
        else if (3 == stage) {
            _amount = _amount.add(withDiscount(_amount, ICO.discount));
        }

        return _amount;
    }
// Solidity 0.4.19
/**
 * Expanding of the functionality
 *
 * @param _numerator - Numerator - value (10000)
 * @param _denominator - Denominator - value (10000)
 *
 * example: price 1000 tokens by 1 ether = changeRate(1, 1000)
 */
function changeRate(uint256 _numerator, uint256 _denominator) public onlyOwner
        returns (bool success)
    {
        if (_numerator == 0) _numerator = 1;
        if (_denominator == 0) _denominator = 1;

        buyPrice = (_numerator.mul(DEC)).div(_denominator);

        return true;
    }
// Solidity 0.4.19
/*
 * Function show in contract what is now
 *
 */
function crowdSaleStatus() internal constant
        returns (string)
    {
        if (1 == stage) {
            return "Pre-ICO";
        } else if(2 == stage) {
            return "ICO first stage";
        } else if (3 == stage) {
            return "ICO second stage";
        } else if (4 >= stage) {
            return "feature stage";
        }

        return "there is no stage at present";
    }
// Solidity 0.4.19
/*
 * Seles manager
 *
 */
function paymentManager(address sender, uint256 value) internal
    {
        uint256 discountValue = countDiscount(value);
        bool conf = confirmSell(discountValue);

        if (conf) {

            sell(sender, discountValue);

            weisRaised = weisRaised.add(value);

            if (now >= ICO.endDate) {
                pauseInternal();
                CrowdSaleFinished(crowdSaleStatus()); // if time is up
            }

        } else {

            sell(sender, ICO.tokens); // sell tokens which has been accessible

            weisRaised = weisRaised.add(value);

            pauseInternal();
            CrowdSaleFinished(crowdSaleStatus());  // if tokens sold
        }
    }
// Solidity 0.4.19
/*
 * Function for start crowdsale (any)
 *
 * @param _tokens - How much tokens will have the crowdsale - amount humanlike value (10000)
 * @param _startDate - When crowdsale will be start - unix timestamp (1512231703 )
 * @param _endDate - When crowdsale will be end - humanlike value (7) same as 7 days
 * @param _discount - Discount for the crowd - humanlive value (7) same as 7 %
 * @param _discount - Discount for the crowds first day - humanlive value (7) same as 7 %
 */
function startCrowd(uint256 _tokens, uint _startDate, uint _endDate, uint8 _discount, uint8 _discountFirstDayICO) public onlyOwner
    {
        require(_tokens * DEC <= avaliableSupply);  // require to set correct tokens value for crowd
        ICO = Ico (_tokens * DEC, _startDate, _startDate + _endDate * 1 days , _discount, _discountFirstDayICO);
        stage = stage.add(1);
        unpauseInternal();
    }
// Solidity 0.4.18
// @notice Allow pre-approved user to take ownership of a token
// @param _tokenId The ID of the Token that can be transferred if this call succeeds.
function takeOwnership(uint256 _tokenId) public {
        address newOwner = msg.sender;
        address oldOwner = tokenIndexToOwner[_tokenId];

        // Safety check to prevent against an unexpected 0x0 default.
        require(_addressNotNull(newOwner));

        // Making sure transfer is approved
        require(_approved(newOwner, _tokenId));

        _transfer(oldOwner, newOwner, _tokenId);
    }
// Solidity 0.4.18
// @dev Creates a new promo Token with the given name, with given _price and assignes it to an address.
function createPromoToken(address _owner, string _name, uint256 _price) public onlyCOO {
        require(promoCreatedCount < PROMO_CREATION_LIMIT);

        address tokenOwner = _owner;
        if (tokenOwner == address(0)) {
            tokenOwner = cooAddress;
        }

        if (_price <= 0) {
            _price = startingPrice;
        }

        promoCreatedCount++;
        uint256 newTokenId = tokensContract.createToken(_name, tokenOwner);
        tokenIndexToPrice[newTokenId] = startingPrice;

        Birth(newTokenId, _name, _owner);
    }
// Solidity 0.6.12
/**
 Delegate votes from signatory to `delegatee`.
 
 @param delegatee The address to delegate votes to.
 @param nonce The contract state required for signature matching.
 @param expiry The time at which to expire the signature.
 @param v The recovery byte of the signature.
 @param r Half of the ECDSA signature pair.
 @param s Half of the ECDSA signature pair.
 */
function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external {
    bytes32 domainSeparator = keccak256(
      abi.encode(
        DOMAIN_TYPEHASH,
        keccak256(bytes(name())),
        getChainId(),
        address(this)));

    bytes32 structHash = keccak256(
      abi.encode(
          DELEGATION_TYPEHASH,
          delegatee,
          nonce,
          expiry));

    bytes32 digest = keccak256(
      abi.encodePacked(
        "\x19\x01",
        domainSeparator,
        structHash));

    address signatory = ecrecover(digest, v, r, s);
    require(signatory != address(0), "Invalid signature.");
    require(nonce == nonces[signatory]++, "Invalid nonce.");
    require(now <= expiry, "Signature expired.");
    return _delegate(signatory, delegatee);
  }
// Solidity 0.6.12
/**
 An internal function to actually perform the delegation of votes.
 
 @param delegator The address delegating to `delegatee`.
 @param delegatee The address receiving delegated votes.
 */
function _delegate(address delegator, address delegatee) internal {
    address currentDelegate = _delegates[delegator];
    uint256 delegatorBalance = balanceOf(delegator);
    _delegates[delegator] = delegatee;
    /* console.log('a-', currentDelegate, delegator, delegatee); */
    emit DelegateChanged(delegator, currentDelegate, delegatee);

    _moveDelegates(currentDelegate, delegatee, delegatorBalance);
  }
// Solidity 0.6.12
/**
 An internal function to move delegated vote amounts between addresses.
 
 @param srcRep the previous representative who received delegated votes.
 @param dstRep the new representative to receive these delegated votes.
 @param amount the amount of delegated votes to move between representatives.
 */
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
    if (srcRep != dstRep && amount > 0) {

      // Decrease the number of votes delegated to the previous representative.
      if (srcRep != address(0)) {
        uint32 srcRepNum = numCheckpoints[srcRep];
        uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
        uint256 srcRepNew = srcRepOld.sub(amount);
        _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
      }

      // Increase the number of votes delegated to the new representative.
      if (dstRep != address(0)) {
        uint32 dstRepNum = numCheckpoints[dstRep];
        uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
        uint256 dstRepNew = dstRepOld.add(amount);
        _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
      }
    }
  }
// Solidity 0.6.12
/**
 An internal function to write a checkpoint of modified vote amounts.
 This function is guaranteed to add at most one checkpoint per block.
 
 @param delegatee The address whose vote count is changed.
 @param nCheckpoints The number of checkpoints by address `delegatee`.
 @param oldVotes The prior vote count of address `delegatee`.
 @param newVotes The new vote count of address `delegatee`.
 */
function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint256 oldVotes, uint256 newVotes) internal {
    uint32 blockNumber = safe32(block.number, "Block number exceeds 32 bits.");

    if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
      checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
    } else {
      checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
      numCheckpoints[delegatee] = nCheckpoints + 1;
    }

    emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
  }
// Solidity 0.8.4
// Add a new launchpad project to the pool. Can only be called by the owner.
function add( IERC20 _launchToken,IERC20 _payToken, uint256 _timeStart, uint256 _timeEnd , uint256 _tokenAmount,uint256 _priceBasedPayToken,uint256 _maxPerAddress,
        uint256 _launchMaxPay, uint256 _releaseStart, uint256 _lockPeriod) public onlyGovernor {
        
        require( _timeStart > block.timestamp && _timeEnd > _timeStart, "invalid time limit");
        
        launchPadInfo.push(LaunchPadInfo({
            launchStatus : 0,
            launchToken : _launchToken,
            payToken : _payToken,
            timeStart : _timeStart,
            timeEnd : _timeEnd,
            tokenAmount : _tokenAmount,
            priceBasedPayToken : _priceBasedPayToken,
            maxPerAddress : _maxPerAddress,
            launchMaxPay : _launchMaxPay,
            releaseStart : _releaseStart,
            lockPeriod : _lockPeriod,
            totalAmount : 0
        }));
        
    }
// Solidity 0.8.4
//user deposit to enter launchpad
function deposit(uint8 _pid, uint256 _amount) public {
        LaunchPadInfo storage pool = launchPadInfo[_pid];
        UserInfo storage user = userInfo[_pid][ msg.sender ];

        require( pool.launchStatus == 1 , "invalid status");

        require( pool.timeEnd > block.timestamp, "invalid time");

        //deposit
        TransferHelper.safeTransferFrom( address(pool.payToken), msg.sender, address(this), _amount);
        user.paidAmount = user.paidAmount.add(_amount);

        pool.totalAmount = pool.totalAmount.add(_amount);
        emit Deposited( msg.sender, _pid, address(pool.payToken), _amount);
    }
// Solidity 0.8.4
//claim release reward token
function claimReward(uint8 _pid) public {
        LaunchPadInfo storage pool = launchPadInfo[_pid];
        UserInfo storage user = userInfo[_pid][ msg.sender ];

        if( user.lockedAmount > user.pickedAmount ){
            uint256 _pickedAmount = 0;

            if( block.timestamp > pool.releaseStart ){
                _pickedAmount = user.lockedAmount.mul(block.timestamp.sub(pool.releaseStart)).div(pool.lockPeriod);
                if( _pickedAmount > user.lockedAmount ){
                    _pickedAmount = user.lockedAmount;
                }
                _pickedAmount = _pickedAmount.sub( user.pickedAmount );
                user.pickedAmount = user.pickedAmount.add(_pickedAmount);
                TransferHelper.safeTransfer( address(pool.launchToken), msg.sender , _pickedAmount );
            }
        }
    }
// Solidity 0.4.23
//allow owner to transfer surplus
function ownerTransfer(address to, uint value)
    public
    onlyOwner
  {
    uint current_balance_all = 0;
    for (uint i = 0; i < accounts.length; i++)
      current_balance_all += account_data[accounts[i]].current_balance;
    require(getBalance() > current_balance_all && value <= getBalance() - current_balance_all);
    if (we_test_token.transfer(to, value))
      emit OwnerTransfer(to, value);
  }
// Solidity 0.8.4
// Check what tokenIds are owned by a given wallets
function walletOfOwner(address _owner) external view returns (uint256[] memory) {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory tokenIds = new uint256[](ownerTokenCount);
        for (uint256 i; i < ownerTokenCount; i++) {
            tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokenIds;
    }
// Solidity 0.8.4
// Gives the tokenURI for a given tokenId
function tokenURI(uint256 tokenId) public view override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory currentBaseURI = _baseURI();

        // If not revealed, show non-revealed image
        if (!revealed) {
            return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI)) : "";
        }
        // else, show revealed image
        return
            bytes(currentBaseURI).length > 0
                ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
                : "";
    }
// Solidity 0.8.4
// Will be used to gift the team 
function gift(uint256 _mintAmount, address destination) external onlyOwner {
        require(_mintAmount > 0, "need to mint at least 1 NFT");
        uint256 supply = totalSupply();
        require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");

        for (uint256 i = 1; i <= _mintAmount; i++) {
            addressMintedBalance[destination]++;
            _safeMint(destination, supply + i);
        }
    }
// Solidity 0.4.16
// count number of bytes required to represent an unsigned integer
function count_bytes(uint256 n) constant internal returns (uint256 c) {
        uint i = 0;
        uint mask = 1;
        while (n >= mask) {
            i += 1;
            mask *= 256;
        }

        return i;
    }
// Solidity 0.4.16
// Spec: Send `value` amount of tokens from address `from` to address `to`
function transferFrom(address from, address to, uint256 value) public returns (bool success) {
        address spender = msg.sender;
        if(value <= s_allowances[from][spender] && internalTransfer(from, to, value)) {
            s_allowances[from][spender] -= value;
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.4.16
// Spec: Allow `spender` to withdraw from your account, multiple times, up
// to the `value` amount. If this function is called again it overwrites the
// current allowance with `value`.
function approve(address spender, uint256 value) public returns (bool success) {
        address owner = msg.sender;
        if (value != 0 && s_allowances[owner][spender] != 0) {
            return false;
        }
        s_allowances[owner][spender] = value;
        Approval(owner, spender, value);
        return true;
    }
// Solidity 0.4.16
// Destroys `value` child contracts and updates s_tail.
//
// This function is affected by an issue in solc: https://github.com/ethereum/solidity/issues/2999
// The `mk_contract_address(this, i).call();` doesn't forward all available gas, but only GAS - 25710.
// As a result, when this line is executed with e.g. 30000 gas, the callee will have less than 5000 gas
// available and its SELFDESTRUCT operation will fail leading to no gas refund occurring.
// The remaining ~29000 gas left after the call is enough to update s_tail and the caller's balance.
// Hence tokens will have been destroyed without a commensurate gas refund.
// Fortunately, there is a simple workaround:
// Whenever you call free, freeUpTo, freeFrom, or freeUpToFrom, ensure that you pass at least
// 25710 + `value` * (1148 + 5722 + 150) gas. (It won't all be used)
function destroyChildren(uint256 value) internal {
        uint256 tail = s_tail;
        // tail points to slot behind the last contract in the queue
        for (uint256 i = tail + 1; i <= tail + value; i++) {
            mk_contract_address(this, i).call();
        }

        s_tail = tail + value;
    }
// Solidity 0.4.16
// Frees `value` sub-tokens owned by address `from`. Requires that `msg.sender`
// has been approved by `from`.
// You should ensure that you pass at least 25710 + `value` * (1148 + 5722 + 150) gas
// when calling this function. For details, see the comment above `destroyChilden`.
function freeFrom(address from, uint256 value) public returns (bool success) {
        address spender = msg.sender;
        uint256 from_balance = s_balances[from];
        if (value > from_balance) {
            return false;
        }

        mapping(address => uint256) from_allowances = s_allowances[from];
        uint256 spender_allowance = from_allowances[spender];
        if (value > spender_allowance) {
            return false;
        }

        destroyChildren(value);

        s_balances[from] = from_balance - value;
        from_allowances[spender] = spender_allowance - value;

        return true;
    }