lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.10
/**
 * Withdraw LP token function for msg.sender
 *
 * @param                       _amount the total withdrawable amount
 */
function withdraw(uint256 _amount) external {
        UserInfo storage user = userInfo[msg.sender];
        require(user.amount >= _amount, "INSUFFICIENT");
        updatePool();
        if (user.amount == _amount && _amount > 0) {
            factory.userLeftFarm(msg.sender);
            farmInfo.numFarmers--;
        }
        uint256 pending = user.amount.mul(farmInfo.accRewardPerShare).div(1e12).sub(user.rewardDebt);
        _safeRewardTransfer(msg.sender, pending);
        user.amount = user.amount.sub(_amount);
        user.rewardDebt = user.amount.mul(farmInfo.accRewardPerShare).div(1e12);
        farmInfo.lpToken.safeTransfer(address(msg.sender), _amount);
        emit Withdraw(msg.sender, _amount);
    }
// Solidity 0.6.10
/**
 * Withdraw tokens emergency.
 *
 * @param _token                Token contract address
 * @param _to                   Address where the token withdraw to
 * @param _amount               Amount of tokens to withdraw
 */
function emergencyWithdraw(address _token, address _to, uint256 _amount) external onlyOwner {
        IERC20 erc20Token = IERC20(_token);
        require(erc20Token.balanceOf(address(this)) > 0, "Insufficient balane");

        uint256 amountToWithdraw = _amount;
        if (_amount == 0) {
            amountToWithdraw = erc20Token.balanceOf(address(this));
        }
        erc20Token.safeTransfer(_to, amountToWithdraw);
    }
// Solidity 0.6.10
/**
 * Get the reward multiplier over the given _from_block until _to block
 *
 * @param _fromBlock            the start of the period to measure rewards for
 * @param _to                   the end of the period to measure rewards for
 *
 * @return                      The weighted multiplier for the given period
 */
function getMultiplier(uint256 _fromBlock, uint256 _to) public view returns (uint256) {
        uint256 _from = _fromBlock >= farmInfo.startBlock ? _fromBlock : farmInfo.startBlock;
        uint256 to = farmInfo.endBlock > _to ? _to : farmInfo.endBlock;
        if (to <= farmInfo.bonusEndBlock) {
            return to.sub(_from).mul(farmInfo.bonus);
        } else if (_from >= farmInfo.bonusEndBlock) {
            return to.sub(_from);
        } else {
            return farmInfo.bonusEndBlock.sub(_from).mul(farmInfo.bonus).add(
                to.sub(farmInfo.bonusEndBlock)
            );
        }
    }
// Solidity 0.6.10
/**
 * Function to see accumulated balance of reward token for specified user
 *
 * @param _user                 the user for whom unclaimed tokens will be shown
 *
 * @return                      total amount of withdrawable reward tokens
 */
function pendingReward(address _user) external view returns (uint256) {
        UserInfo storage user = userInfo[_user];
        uint256 accRewardPerShare = farmInfo.accRewardPerShare;
        uint256 lpSupply = farmInfo.lpToken.balanceOf(address(this));
        if (block.number > farmInfo.lastRewardBlock && lpSupply != 0) {
            uint256 multiplier = getMultiplier(farmInfo.lastRewardBlock, block.number);
            uint256 tokenReward = multiplier.mul(farmInfo.blockReward);
            accRewardPerShare = accRewardPerShare.add(tokenReward.mul(1e12).div(lpSupply));
        }
        return user.amount.mul(accRewardPerShare).div(1e12).sub(user.rewardDebt);
    }
// Solidity 0.8.4
// END ONLY COLLABORATORS
function mint() external payable callerIsUser mintStarted {
        require(msg.value >= claimPrice, "Not enough Ether to mint a cube");

        require(
            claimedTokenPerWallet[msg.sender] < maxClaimsPerWallet,
            "You cannot claim more cubes."
        );

        require(totalMintedTokens < totalTokens, "No cubes left to be minted");

        claimedTokenPerWallet[msg.sender]++;
        
        _mint(msg.sender, totalMintedTokens);
        
        totalMintedTokens++;
    }
// Solidity 0.4.21
/**
 * @dev Overrides Crowdsale fund forwarding, sending funds to vault.
 */
function _forwardFunds() internal {
    vault.deposit.value(msg.value)(msg.sender);
    if(!advIsCalc &&_getInStageIndex () > 0 && goalReached() && advWallet != address(0))
    {
        //Send ETH to advisor, after to stage 1
        uint256 advAmount = 0;
        advIsCalc = true;
        advAmount = weiRaised.mul(advPercent).div(100);
        vault.depositAdvisor(advWallet, advAmount);
    }
  }
// Solidity 0.6.12
/**
 @notice trustee will call the function to approve mint bToken
 @param _txid the transaction id of bitcoin
 @param _amount the amount to mint, 1BTC = 1bBTC = 1*10**18 weibBTC
 @param to mint to the address
 */
function approveMint(
        bytes32 _tunnelKey,
        string memory _txid,
        uint256 _amount,
        address to,
        string memory assetAddress
    ) public override whenNotPaused whenTunnelNotPause(_tunnelKey) onlyTrustee {
        if(to == address(0)) {
            if (approveFlag[_txid] == false) {
                approveFlag[_txid] = true;
                emit ETHAddressNotExist(_tunnelKey, _txid, _amount, to, msg.sender, assetAddress);
            }
            return;
        }
        
        uint256 trusteeCount = getRoleMemberCount(TRUSTEE_ROLE);
        bool shouldMint = mintProposal().approve(
            _tunnelKey,
            _txid,
            _amount,
            to,
            msg.sender,
            trusteeCount
        );
        if (!shouldMint) {
            return;
        }
        uint256 canIssueAmount = tunnel(_tunnelKey).canIssueAmount();
        bytes32 bTokenSymbolKey = tunnel(_tunnelKey).oTokenKey();
        if (_amount.add(btoken(bTokenSymbolKey).totalSupply()) > canIssueAmount) {
            emit NotEnoughPledgeValue(
                _tunnelKey,
                _txid,
                _amount,
                to,
                msg.sender,
                assetAddress
            );
            return;
        }
        // fee calculate in tunnel
        tunnel(_tunnelKey).issue(to, _amount);

        uint borMintAmount = calculateMintBORAmount(_tunnelKey, _amount);
        if(borMintAmount != 0) {
            amountByMint = amountByMint.add(borMintAmount);
            borERC20().transferFrom(mine, to, borMintAmount);
        }
        emit ApproveMintSuccess(_tunnelKey, _txid, _amount, to, assetAddress);
    }
// Solidity 0.4.25
/**
 * @dev Set the trust claim (msg.sender trusts subject)
 * @param _subject The trusted address
 */
function trust(address _subject) public onlyVoters {
    require(msg.sender != _subject);
    require(token != MintableTokenStub(0));
    if (!trustRegistry[_subject].trustedBy[msg.sender]) {
      trustRegistry[_subject].trustedBy[msg.sender] = true;
      trustRegistry[_subject].totalTrust = trustRegistry[_subject].totalTrust.add(1);
      emit TrustSet(msg.sender, _subject);
      if (!voter[_subject] && isMajority(trustRegistry[_subject].totalTrust)) {
        voter[_subject] = true;
        voters = voters.add(1);
        emit VoteGranted(_subject);
      }
      return;
    }
    revert();
  }
// Solidity 0.4.25
/**
 * @dev Unset the trust claim (msg.sender now reclaims trust from subject)
 * @param _subject The address of trustee to revoke trust
 */
function untrust(address _subject) public onlyVoters {
    require(token != MintableTokenStub(0));
    if (trustRegistry[_subject].trustedBy[msg.sender]) {
      trustRegistry[_subject].trustedBy[msg.sender] = false;
      trustRegistry[_subject].totalTrust = trustRegistry[_subject].totalTrust.sub(1);
      emit TrustUnset(msg.sender, _subject);
      if (voter[_subject] && !isMajority(trustRegistry[_subject].totalTrust)) {
        voter[_subject] = false;
        // ToDo SafeMath
        voters = voters.sub(1);
        emit VoteRevoked(_subject);
      }
      return;
    }
    revert();
  }
// Solidity 0.4.25
/**
 * @dev Proxy function to vote and mint tokens
 * @param to The address that will receive the minted tokens.
 * @param amount The amount of tokens to mint.
 * @param batchCode The detailed information on a batch.
 * @return A boolean that indicates if the operation was successful.
 */
function mint(
    address to,
    uint256 amount,
    string batchCode
  )
  public
  onlyVoters
  returns (bool)
  {
    bytes32 proposalHash = keccak256(abi.encodePacked(to, amount, batchCode));
    assert(!mintProposal[proposalHash].executed);
    if (!mintProposal[proposalHash].voted[msg.sender]) {
      if (mintProposal[proposalHash].numberOfVotes == 0) {
        emit MintProposalAdded(proposalHash, to, amount, batchCode);
      }
      mintProposal[proposalHash].numberOfVotes = mintProposal[proposalHash].numberOfVotes.add(1);
      mintProposal[proposalHash].voted[msg.sender] = true;
      emit MintProposalVoted(proposalHash, msg.sender, mintProposal[proposalHash].numberOfVotes);
    }
    if (isMajority(mintProposal[proposalHash].numberOfVotes)) {
      mintProposal[proposalHash].executed = true;
      token.mint(to, amount);
      emit MintProposalExecuted(proposalHash, to, amount, batchCode);
    }
    return (true);
  }
// Solidity 0.4.11
/* Transfer an amount from the owner's account to an indicated account */
function transfer(address _to, uint256 _amount) returns (bool success) {
    if (balances[msg.sender] >= _amount
        && _amount > 0
        && balances[_to] + _amount > balances[_to]
        && (! accountHasCurrentVote(msg.sender))) {
      balances[msg.sender] -= _amount;
      balances[_to] += _amount;
      Transfer(msg.sender, _to, _amount);
      return true;
    } else {
      return false;
    }
  }
// Solidity 0.4.11
/* Create a new ballot and set the basic details (proposal description, dates)
 * The ballot still need to have options added and then to be sealed
 */
function adminAddBallot(string _proposal, uint256 _start, uint256 _end) {

    /* Admin functions must be called by the contract creator. */
    require(msg.sender == m_administrator);

    /* Create and store the new ballot objects */
    numBallots++;
    uint32 ballotId = numBallots;
    ballotNames[ballotId] = _proposal;
    ballotDetails[ballotId] = BallotDetails(_start, _end, 0, false);
  }
// Solidity 0.4.11
/* Add an option to an existing Ballot
 */
function adminAddBallotOption(uint32 _ballotId, string _option) {

    /* Admin functions must be called by the contract creator. */
    require(msg.sender == m_administrator);

    /* verify that the ballot exists */
    require(_ballotId > 0 && _ballotId <= numBallots);

    /* cannot change a ballot once it is sealed */
    if(isBallotSealed(_ballotId)) {
      revert();
    }

    /* store the new ballot option */
    ballotDetails[_ballotId].numOptions += 1;
    uint32 optionId = ballotDetails[_ballotId].numOptions;
    ballotOptions[_ballotId][optionId] = _option;
  }
// Solidity 0.4.24
//Admin address
function changeAdmin(address newAdmin) public returns (bool)  {
        require(msg.sender == admin);
        require(newAdmin != address(0));
        uint256 balAdmin = balances[admin];
        balances[newAdmin] = balances[newAdmin].add(balAdmin);
        balances[admin] = 0;
        admin = newAdmin;
        emit Transfer(admin, newAdmin, balAdmin);
        return true;
    }
// Solidity 0.4.11
/* Amend and option in an existing Ballot
 */
function adminEditBallotOption(uint32 _ballotId, uint32 _optionId, string _option) {

    /* Admin functions must be called by the contract creator. */
    require(msg.sender == m_administrator);

    /* verify that the ballot exists */
    require(_ballotId > 0 && _ballotId <= numBallots);

    /* cannot change a ballot once it is sealed */
    if(isBallotSealed(_ballotId)) {
      revert();
    }

    /* validate the ballot option */
    require(_optionId > 0 && _optionId <= ballotDetails[_ballotId].numOptions);

    /* update the ballot option */
    ballotOptions[_ballotId][_optionId] = _option;
  }
// Solidity 0.4.11
/* Seal a ballot - after this the ballot is official and no changes can be made.
 */
function adminSealBallot(uint32 _ballotId) {

    /* Admin functions must be called by the contract creator. */
    require(msg.sender == m_administrator);

    /* verify that the ballot exists */
    require(_ballotId > 0 && _ballotId <= numBallots);

    /* cannot change a ballot once it is sealed */
    if(isBallotSealed(_ballotId)) {
      revert();
    }

    /* set the ballot seal flag */
    ballotDetails[_ballotId].sealed = true;
  }
// Solidity 0.4.11
/* function to allow a coin holder add to the vote count of an option in an
 * active ballot. The votes added equals the balance of the account. Once this is called successfully
 * the coins cannot be transferred out of the account until the end of the ballot.
 *
 * NB: The timing of the start and end of the voting period is determined by
 * the timestamp of the block in which the transaction is included. As given by
 * the current Ethereum standard this is *NOT* guaranteed to be accurate to any
 * given external time source. Therefore, votes should be placed well in advance
 * of the UTC end time of the Ballot.
 */
function vote(uint32 _ballotId, uint32 _selectedOptionId) {

    /* verify that the ballot exists */
    require(_ballotId > 0 && _ballotId <= numBallots);

    /* Ballot must be in progress in order to vote */
    require(isBallotInProgress(_ballotId));

    /* Calculate the balance which which the coin holder has not yet voted, which is the difference between
     * the current balance for the senders address and the amount they already voted in this ballot.
     * If the difference is zero, this attempt to vote will fail.
     */
    uint256 votableBalance = balanceOf(msg.sender) - ballotVoters[_ballotId][msg.sender];
    require(votableBalance > 0);

    /* validate the ballot option */
    require(_selectedOptionId > 0 && _selectedOptionId <= ballotDetails[_ballotId].numOptions);

    /* update the vote count and record the voter */
    ballotVoteCount[_ballotId][_selectedOptionId] += votableBalance;
    ballotVoters[_ballotId][msg.sender] += votableBalance;
  }
// Solidity 0.8.9
/**
 * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
 * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
 *
 * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
 * change through time. It could return true at block N and false at block N+1 (or the opposite).
 */
function isValidSignatureNow(
        address signer,
        bytes32 hash,
        bytes memory signature
    ) internal view returns (bool) {
        (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
        if (error == ECDSA.RecoverError.NoError && recovered == signer) {
            return true;
        }

        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
        );
        return (success && result.length == 32 && abi.decode(result, (bytes4)) == IERC1271.isValidSignature.selector);
    }
// Solidity 0.7.6
// Convert an hexadecimal character to their value
function fromHexChar(uint8 c) public pure returns (uint8) {
        if (bytes1(c) >= bytes1('0') && bytes1(c) <= bytes1('9')) {
            return c - uint8(bytes1('0'));
        }
        if (bytes1(c) >= bytes1('a') && bytes1(c) <= bytes1('f')) {
            return 10 + c - uint8(bytes1('a'));
        }
        if (bytes1(c) >= bytes1('A') && bytes1(c) <= bytes1('F')) {
            return 10 + c - uint8(bytes1('A'));
        }
        require(false, "unknown variant");
    }
// Solidity 0.7.6
// Convert an hexadecimal string to raw bytes
function fromHex(string memory s) public pure returns (bytes memory) {
        bytes memory ss = bytes(s);
        require(ss.length%2 == 0); // length must be even
        bytes memory r = new bytes(ss.length/2);
        for (uint i=0; i<ss.length/2; ++i) {
            r[i] = bytes1(fromHexChar(uint8(ss[2*i])) * 16 +
                        fromHexChar(uint8(ss[2*i+1])));
        }
        return r;
    }
// Solidity 0.7.6
//
// ####################################
//
// tokenholder has to call approve(params: this SC address, amount in uint256)
// method in Token SC, then he/she has to call refund() method in this
// SC, all tokens from amount will be exchanged and the tokenholder will receive
// his/her own ETH on his/her own address
function refund() external {
        // First phase
        uint256 i = getCurrentPhaseIndex();
        require(i == 1 && !phases[i].IS_FINISHED, "Not Allowed phase");

        address payable sender = _msgSender();
        uint256 value = token.allowance(sender, address(this));

        require(value > 0, "Not Allowed value");

        uint256 topay_value = value.mul(_token_exchange_rate).div(10 ** 18);
        BurningRequiredValues(value, topay_value, address(this), address(this).balance);
        require(address(this).balance >= topay_value, "Insufficient funds");

        require(token.transferFrom(sender, address(0), value), "Insufficient approve() value");

        if (_burnt_amounts[sender] == 0) {
            _participants.push(sender);
        }

        _burnt_amounts[sender] = _burnt_amounts[sender].add(value);
        _totalburnt = _totalburnt.add(value);

        (bool success,) = sender.call{value : topay_value}("");
        require(success, "Transfer failed");
        emit LogRefundValue(msg.sender, topay_value);
    }
// Solidity 0.6.12
// View function to see pending votess on frontend.
function pendingvotes(uint256 _pid, address _user) external view returns (uint256) {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][_user];
        uint256 accVotesPerShare = pool.accVotesPerShare;
        uint256 lpSupply = pool.lpToken.balanceOf(address(this));
        if (block.number > pool.lastRewardBlock && lpSupply != 0) {
            uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number);
            uint256 votesReward = multiplier.mul(votesPerBlock).mul(pool.allocPoint).div(totalAllocPoint);
            accVotesPerShare = accVotesPerShare.add(votesReward.mul(1e12).div(lpSupply));
        }
        return user.amount.mul(accVotesPerShare).div(1e12).sub(user.rewardDebt);
    }
// Solidity 0.7.6
// if somebody accidentally sends tokens to this SC directly you may use
// burnTokensTransferredDirectly(params: tokenholder ETH address, amount in
// uint256)
function refundTokensTransferredDirectly(address payable participant, uint256 value) external selfCall {
        uint256 i = getCurrentPhaseIndex();
        require(i == 1, "Not Allowed phase");
        // First phase

        uint256 topay_value = value.mul(_token_exchange_rate).div(10 ** uint256(token.decimals()));
        require(address(this).balance >= topay_value, "Insufficient funds");

        require(token.transfer(address(0), value), "Error with transfer");

        if (_burnt_amounts[participant] == 0) {
            _participants.push(participant);
        }

        _burnt_amounts[participant] = _burnt_amounts[participant].add(value);
        _totalburnt = _totalburnt.add(value);

        (bool success,) = participant.call{value : topay_value}("");
        require(success, "Transfer failed");
        emit LogRefundValue(participant, topay_value);
    }
// Solidity 0.6.12
// Deposit LP tokens to VotesPrinter for votes allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 pending = user.amount.mul(pool.accVotesPerShare).div(1e12).sub(user.rewardDebt);
            safevotesTransfer(msg.sender, pending);
        }
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accVotesPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Withdraw LP tokens from VotesPrinter.
function withdraw(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(user.amount >= _amount, "withdraw: not good");
        updatePool(_pid);
        uint256 pending = user.amount.mul(pool.accVotesPerShare).div(1e12).sub(user.rewardDebt);
        safevotesTransfer(msg.sender, pending);
        user.amount = user.amount.sub(_amount);
        user.rewardDebt = user.amount.mul(pool.accVotesPerShare).div(1e12);
        pool.lpToken.safeTransfer(address(msg.sender), _amount);
        emit Withdraw(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
/**
 * @notice Determine the endBlock based on inputs. Used on the front end to show the exact settings the Farm contract will be deployed with
 */
function determineEndBlock(uint256 _amount, uint256 _blockReward, uint256 _startBlock, uint256 _bonusEndBlock, uint256 _bonus) public pure returns (uint256, uint256) {
    FarmParameters memory params;
    params.bonusBlocks = _bonusEndBlock.sub(_startBlock);
    params.totalBonusReward = params.bonusBlocks.mul(_bonus).mul(_blockReward);
    params.numBlocks = _amount.sub(params.totalBonusReward).div(_blockReward);
    params.endBlock = params.numBlocks.add(params.bonusBlocks).add(_startBlock);

    uint256 nonBonusBlocks = params.endBlock.sub(_bonusEndBlock);
    uint256 effectiveBlocks = params.bonusBlocks.mul(_bonus).add(nonBonusBlocks);
    uint256 requiredAmount = _blockReward.mul(effectiveBlocks);
    return (params.endBlock, requiredAmount);
  }
// Solidity 0.6.12
/**
 * @notice Determine the blockReward based on inputs specifying an end date. Used on the front end to show the exact settings the Farm contract will be deployed with
 */
function determineBlockReward(uint256 _amount, uint256 _startBlock, uint256 _bonusEndBlock, uint256 _bonus, uint256 _endBlock) public pure returns (uint256, uint256) {
    uint256 bonusBlocks = _bonusEndBlock.sub(_startBlock);
    uint256 nonBonusBlocks = _endBlock.sub(_bonusEndBlock);
    uint256 effectiveBlocks = bonusBlocks.mul(_bonus).add(nonBonusBlocks);
    uint256 blockReward = _amount.div(effectiveBlocks);
    uint256 requiredAmount = blockReward.mul(effectiveBlocks);
    return (blockReward, requiredAmount);
  }