lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.6
/**
 * @notice allows a keeper to activate/register themselves after bonding
 */
function activate() external {
        require(bondings[msg.sender] != 0, "Keep3r::activate: bond first");
        require(bondings[msg.sender] < now, "Keep3r::activate: still bonding");
        if (firstSeen[msg.sender] == 0) {
          firstSeen[msg.sender] = now;
          keeperList.push(msg.sender);
          lastJob[msg.sender] = now;
        }
        keepers[msg.sender] = true;
        totalBonded = totalBonded.add(pendingbonds[msg.sender]);
        bonds[msg.sender] = bonds[msg.sender].add(pendingbonds[msg.sender]);
        pendingbonds[msg.sender] = 0;
        emit KeeperBonded(msg.sender, block.number, block.timestamp, bonds[msg.sender]);
    }
// Solidity 0.6.6
/**
 * @notice withdraw funds after unbonding has finished
 */
function withdraw() external {
        require(unbondings[msg.sender] != 0, "Keep3r::withdraw: unbond first");
        require(unbondings[msg.sender] < now, "Keep3r::withdraw: still unbonding");
        require(!disputes[msg.sender], "Keep3r::withdraw: pending disputes");

        _transferTokens(address(this), msg.sender, partialUnbonding[msg.sender]);
        emit KeeperUnbound(msg.sender, block.number, block.timestamp, partialUnbonding[msg.sender]);
        partialUnbonding[msg.sender] = 0;
    }
// Solidity 0.6.6
/**
 * @notice slash a keeper for downtime
 * @param keeper the address being slashed
 */
function down(address keeper) external {
        require(keepers[msg.sender], "Keep3r::down: not a keeper");
        require(keepers[keeper], "Keep3r::down: keeper not registered");
        require(lastJob[keeper].add(DOWNTIME) < now, "Keep3r::down: keeper safe");
        uint _slash = bonds[keeper].mul(DOWNTIMESLASH).div(BASE);
        bonds[keeper] = bonds[keeper].sub(_slash);
        bonds[msg.sender] = bonds[msg.sender].add(_slash);
        _moveDelegates(delegates[msg.sender], msg.sender, _slash);
        lastJob[keeper] = now;
        lastJob[msg.sender] = now;
        emit KeeperSlashed(keeper, msg.sender, block.number, _slash);
    }
// Solidity 0.5.3
/// @notice establish an interval if none exists
function ensureInterval() public notHalted {
    if (intervals[latest].end > block.number) return;

    Interval storage interval = intervals[latest];
    (uint feeEarned, uint ethEarned) = calculateIntervalEarning(interval.start, interval.end);
    interval.generatedFEE = feeEarned.plus(ethEarned.div(weiPerFEE));
    FEE2Distribute = FEE2Distribute.plus(interval.generatedFEE);
    if (ethEarned.div(weiPerFEE) > 0) FEE.sendTokens(address(this), ethEarned.div(weiPerFEE));
    emit FeeCalculated(interval.generatedFEE, feeEarned, ethEarned, interval.start, interval.end, latest);
    if (ethEarned > 0) address(wallet).transfer(ethEarned);

    uint diff = (block.number - intervals[latest].end) % intervalSize;
    latest += 1;
    intervals[latest].start = intervals[latest - 1].end;
    intervals[latest].end = block.number - diff + intervalSize;
    emit NewInterval(intervals[latest].start, intervals[latest].end, latest);
  }
// Solidity 0.4.25
/**
 * @dev Create a new proposal.
 * @param _contract Proposal contract address
 * @return uint ProposalID
 */
function pushProposal(address _contract) onlyOwner public returns (uint) {
        if(proposalCounter != 0)
        require (pastProposalTimeRules (), "You need to wait 90 days before submitting a new proposal.");
        require (!proposalPending, "Another proposal is pending.");

        uint _contractType = IcaelumVoting(_contract).getContractType();
        proposalList[proposalCounter] = Proposals(_contract, 0, now, 0, VOTE_TYPE(_contractType));

        emit NewProposal(proposalCounter);
        
        proposalCounter++;
        proposalPending = true;

        return proposalCounter.sub(1);
    }
// Solidity 0.4.25
/**
 * @dev Internal function that handles the proposal after it got accepted.
 * This function determines if the proposal is a token or team member proposal and executes the corresponding functions.
 * @return uint Returns the proposal ID.
 */
function handleLastProposal () internal returns (uint) {
        uint _ID = proposalCounter.sub(1);

        proposalList[_ID].acceptedOn = now;
        proposalPending = false;

        address _address;
        uint _required;
        uint _valid;
        uint _type;
        (_address, _required, _valid, _type) = getTokenProposalDetails(_ID);

        if(_type == uint(VOTE_TYPE.TOKEN)) {
            addToWhitelist(_address,_required,_valid);
        }

        if(_type == uint(VOTE_TYPE.TEAM)) {
            if(_required != 0) {
                for (uint i = 0; i < _required; i++) {
                    addMasternode(_address);
                }
            } else {
                addMasternode(_address);
            }
            updateMasternodeAsTeamMember(_address);
        }
        
        emit ProposalAccepted(_ID);
        
        return _ID;
    }
// Solidity 0.4.25
/**
 * @dev Checks if the last proposal allowed voting time has expired and it's not accepted.
 * @return bool
 */
function LastProposalCanDiscard () public view returns (bool) {
        
        uint daysBeforeDiscard = IcaelumVoting(proposalList[proposalCounter - 1].tokenContract).getExpiry();
        uint entryDate = proposalList[proposalCounter - 1].proposedOn;
        uint expiryDate = entryDate + (daysBeforeDiscard * 1 days);

        if (now >= expiryDate)
        return true;
    }
// Solidity 0.4.25
/**
 * @dev Allow any masternode user to become a voter.
 */
function becomeVoter() public  {
        require (isMasternodeOwner(msg.sender), "User has no masternodes");
        require (!voterMap[msg.sender].isVoter, "User Already voted for this proposal");

        voterMap[msg.sender].owner = msg.sender;
        voterMap[msg.sender].isVoter = true;
        votersCount = votersCount + 1;

        if (isTeamMember(msg.sender))
        votersCountTeam = votersCountTeam + 1;
    }
// Solidity 0.4.25
/**
 * @dev Allow voters to submit their vote on a proposal. Voters can only cast 1 vote per proposal.
 * If the proposed vote is about adding Team members, only Team members are able to vote.
 * A proposal can only be published if the total of votes is greater then MINIMUM_VOTERS_NEEDED.
 * @param proposalID proposalID
 */
function voteProposal(uint proposalID) public returns (bool success) {
        require(voterMap[msg.sender].isVoter, "Sender not listed as voter");
        require(proposalID >= 0, "No proposal was selected.");
        require(proposalID <= proposalCounter, "Proposal out of limits.");
        require(voterProposals[proposalID] != msg.sender, "Already voted.");


        if(proposalList[proposalID].proposalType == VOTE_TYPE.TEAM) {
            require (isTeamMember(msg.sender), "Restricted for team members");
            voterProposals[proposalID] = msg.sender;
            proposalList[proposalID].totalVotes++;

            if(reachedMajorityForTeam(proposalID)) {
                // This is the prefered way of handling vote results. It costs more gas but prevents tampering.
                // If gas is an issue, you can comment handleLastProposal out and call it manually as onlyOwner.
                handleLastProposal();
                return true;
            }
        } else {
            require(votersCount >= MINIMUM_VOTERS_NEEDED, "Not enough voters in existence to push a proposal");
            voterProposals[proposalID] = msg.sender;
            proposalList[proposalID].totalVotes++;

            if(reachedMajority(proposalID)) {
                // This is the prefered way of handling vote results. It costs more gas but prevents tampering.
                // If gas is an issue, you can comment handleLastProposal out and call it manually as onlyOwner.
                handleLastProposal();
                return true;
            }
        }


    }
// Solidity 0.4.25
/**
 * @notice Add a new token as accepted payment method.
 * @param _token Token contract address.
 * @param _amount Required amount of this Token as collateral
 * @param daysAllowed How many days will we accept this token?
 */
function addToWhitelist(address _token, uint _amount, uint daysAllowed) internal {
        _whitelistTokens storage newToken = acceptedTokens[_token];
        newToken.tokenAddress = _token;
        newToken.requiredAmount = _amount;
        newToken.timestamp = now;
        newToken.validUntil = now + (daysAllowed * 1 days);
        newToken.active = true;

        tokensList.push(_token);
    }
// Solidity 0.4.25
/**
 * @notice Public function that allows any user to deposit accepted tokens as collateral to become a masternode.
 * @param token Token contract address
 * @param amount Amount to deposit
 */
function depositCollateral(address token, uint amount) public {
        require(isAcceptedToken(token), "ERC20 not authorised");  // Should be a token from our list
        require(amount == getAcceptedTokenAmount(token));         // The amount needs to match our set amount
        require(isValid(token));                                  // It should be called within the setup timeframe

        tokens[token][msg.sender] = tokens[token][msg.sender].add(amount);

        require(StandardToken(token).transferFrom(msg.sender, this, amount), "error with token");
        emit Deposit(token, msg.sender, amount, tokens[token][msg.sender]);

        addMasternode(msg.sender);
    }
// Solidity 0.4.25
/**
 * @notice Public function that allows any user to withdraw deposited tokens and stop as masternode
 * @param token Token contract address
 * @param amount Amount to withdraw
 */
function withdrawCollateral(address token, uint amount) public {
        require(token != 0); // token should be an actual address
        require(isAcceptedToken(token), "ERC20 not authorised"); // Should be a token from our list
        require(isMasternodeOwner(msg.sender)); // The sender must be a masternode prior to withdraw
        require(tokens[token][msg.sender] == amount); // The amount must be exactly whatever is deposited

        uint amountToWithdraw = tokens[token][msg.sender];
        tokens[token][msg.sender] = 0;

        deleteMasternode(getLastPerUser(msg.sender));

        if (!StandardToken(token).transfer(msg.sender, amountToWithdraw)) revert();
        emit Withdraw(token, msg.sender, amountToWithdraw, amountToWithdraw);
    }
// Solidity 0.4.25
/**
 * @dev Add a user as masternode. Called as internal since we only add masternodes by depositing collateral or by voting.
 * @param _candidate Candidate address
 * @return uint Masternode index
 */
function addMasternode(address _candidate) internal returns(uint) {
        userByIndex[masternodeCounter].accountOwner = _candidate;
        userByIndex[masternodeCounter].isActive = true;
        userByIndex[masternodeCounter].startingRound = masternodeRound + 1;
        userByIndex[masternodeCounter].storedIndex = masternodeCounter;

        userByAddress[_candidate].accountOwner = _candidate;
        userByAddress[_candidate].indexcounter.push(masternodeCounter);

        userArray.push(userArray.length);
        masternodeCounter++;

        emit NewMasternode(_candidate, now);
        return masternodeCounter - 1; //
    }
// Solidity 0.4.25
/**
 * @dev Remove a specific masternode
 * @param _masternodeID ID of the masternode to remove
 */
function deleteMasternode(uint _masternodeID) internal returns(bool success) {

        uint rowToDelete = userByIndex[_masternodeID].storedIndex;
        uint keyToMove = userArray[userArray.length - 1];

        userByIndex[_masternodeID].isActive = userByIndex[_masternodeID].isActive = (false);
        userArray[rowToDelete] = keyToMove;
        userByIndex[keyToMove].storedIndex = rowToDelete;
        userArray.length = userArray.length - 1;

        removeFromUserCounter(_masternodeID);

        emit RemovedMasternode(userByIndex[_masternodeID].accountOwner, now);

        return true;
    }
// Solidity 0.4.25
/**
 * @dev Internal function to remove a masternode from a user address if this address holds multpile masternodes
 * @param index MasternodeID
 */
function removeFromUserCounter(uint index)  internal returns(uint[]) {
        address belong = isPartOf(index);

        if (index >= userByAddress[belong].indexcounter.length) return;

        for (uint i = index; i<userByAddress[belong].indexcounter.length-1; i++){
            userByAddress[belong].indexcounter[i] = userByAddress[belong].indexcounter[i+1];
        }

        delete userByAddress[belong].indexcounter[userByAddress[belong].indexcounter.length-1];
        userByAddress[belong].indexcounter.length--;
        return userByAddress[belong].indexcounter;
    }
// Solidity 0.4.25
/**
 * @dev Primary contract function to update the current user and prepare the next one.
 * A number of steps have been token to ensure the contract can never run out of gas when looping over our masternodes.
 */
function setMasternodeCandidate() internal returns(address) {

        uint hardlimitCounter = 0;

        while (getFollowingCandidate() == 0x0) {
            // We must return a value not to break the contract. Require is a secondary killswitch now.
            require(hardlimitCounter < 6, "Failsafe switched on");
            // Choose if loop over revert/require to terminate the loop and return a 0 address.
            if (hardlimitCounter == 5) return (0);
            masternodeRound = masternodeRound + 1;
            masternodeCandidate = 0;
            hardlimitCounter++;
        }

        if (masternodeCandidate == masternodeCounter - 1) {
            masternodeRound = masternodeRound + 1;
            masternodeCandidate = 0;
        }

        for (uint i = masternodeCandidate; i < masternodeCounter; i++) {
            if (userByIndex[i].isActive) {
                if (userByIndex[i].startingRound == masternodeRound) {
                    updateMasternode(i);
                    masternodeCandidate = i;
                    return (userByIndex[i].accountOwner);
                }
            }
        }

        masternodeRound = masternodeRound + 1;
        return (0);

    }
// Solidity 0.4.25
/**
 * @dev Helper function to loop through our masternodes at start and return the correct round
 */
function getFollowingCandidate() internal view returns(address _address) {
        uint tmpRound = masternodeRound;
        uint tmpCandidate = masternodeCandidate;

        if (tmpCandidate == masternodeCounter - 1) {
            tmpRound = tmpRound + 1;
            tmpCandidate = 0;
        }

        for (uint i = masternodeCandidate; i < masternodeCounter; i++) {
            if (userByIndex[i].isActive) {
                if (userByIndex[i].startingRound == tmpRound) {
                    tmpCandidate = i;
                    return (userByIndex[i].accountOwner);
                }
            }
        }

        tmpRound = tmpRound + 1;
        return (0);
    }
// Solidity 0.4.25
/**
 * @dev Calculate and set the reward schema for Caelum.
 * Each mining phase is decided by multiplying the MINING_PHASE_DURATION_BLOCKS with factor 10.
 * Depending on the outcome (solidity always rounds), we can detect the current stage of mining.
 * First stage we cut the rewards to 5% to prevent instamining.
 * Last stage we leave 2% for miners to incentivize keeping miners running.
 */
function calculateRewardStructures() internal {
        //ToDo: Set
        uint _global_reward_amount = getMiningReward();
        uint getStageOfMining = miningEpoch / MINING_PHASE_DURATION_BLOCKS * 10;

        if (getStageOfMining < 10) {
            rewardsProofOfWork = _global_reward_amount / 100 * 5;
            rewardsMasternode = 0;
            return;
        }

        if (getStageOfMining > 90) {
            rewardsProofOfWork = _global_reward_amount / 100 * 2;
            rewardsMasternode = _global_reward_amount / 100 * 98;
            return;
        }

        uint _mnreward = (_global_reward_amount / 100) * getStageOfMining;
        uint _powreward = (_global_reward_amount - _mnreward);

        setBaseRewards(_powreward, _mnreward);
    }
// Solidity 0.4.25
//help debug mining software
function checkMintSolution(
        uint256 nonce,
        bytes32 challenge_digest,
        bytes32 challenge_number,
        uint testTarget
    )
    public view returns(bool success) {
        bytes32 digest = keccak256(challenge_number, msg.sender, nonce);
        if (uint256(digest) > testTarget) revert();
        return (digest == challenge_digest);
    }
// Solidity 0.6.6
/// @notice returns how much RCN is required for a given pay
function getPayCostWithFee(
        ITokenConverter _converter,
        IERC20 _fromToken,
        bytes32 _requestId,
        uint256 _amount,
        bytes calldata _oracleData
    ) external returns (uint256) {
        (uint256 amount, uint256 fee) = _getRequiredRcnPay(_requestId, _amount, _oracleData);

        return _converter.getPriceConvertTo(
            _fromToken,
            debtEngineToken,
            amount + fee
        );
    }
// Solidity 0.6.6
/// @notice returns how much RCN is required for a given lend
function _getRequiredRcnLend(
        Cosigner _cosigner,
        bytes32 _requestId,
        bytes memory _oracleData,
        bytes memory _cosignerData
    ) internal returns (uint256) {
        // Load request amount
        uint256 amount = loanManager.getAmount(_requestId);

        // If loan has a cosigner, sum the cost
        if (_cosigner != Cosigner(0)) {
            amount = amount.add(
                _cosigner.cost(
                    address(loanManager),
                    uint256(_requestId),
                    _cosignerData,
                    _oracleData
                )
            );
        }

        // Convert amount in currency to amount in tokens
        RateOracle oracle = loanManager.getOracle(_requestId);
        if (oracle == RateOracle(0)) {
            return amount;
        }

        (uint256 tokens, uint256 equivalent) = oracle.readSample(_oracleData);

        emit ReadedOracle(oracle, tokens, equivalent);

        return tokens.mult(amount).divCeil(equivalent);
    }
// Solidity 0.4.24
/**
 * Constructor function
 * Setup the owner
 */
function PriIcoSale2(address _sendAddress, uint _goalEthers, uint _dividendRate, address _tokenAddress, address _whiteListAddress) public {
        require(_sendAddress != address(0));
        require(_tokenAddress != address(0));
        require(_whiteListAddress != address(0));
        
        owner = msg.sender; // set owner
        beneficiary = _sendAddress; // set beneficiary 
        fundingEthGoal = _goalEthers * 1 ether; // set goal ethereu
        pricePerEther = _dividendRate; // set price per ether
        
        tokenReward = Token(_tokenAddress); // set token address
        whiteListMge = WhiteList(_whiteListAddress); // set whitelist address
        
    }
// Solidity 0.8.9
/**
 * @notice Airdrop creator is able to withdraw unclaimed tokens after expiration date is over
 */
function withdrawTokensFromExpiredAirdrop(uint256 airdropId) external {
        require(!isPaused[2], "Paused");
        AirDrop storage airDrop = airDrops[airdropId];
        require(address(airDrop.token) != address(0), "Airdrop with given Id doesn't exists");
        require(airDrop.creator == msg.sender, "Only airdrop creator can withdraw");
        require(airDrop.expirationTimestamp < block.timestamp, "Airdrop isn't expired yet");
        require(airDrop.amount > 0, "Airdrop balance is empty");
        uint256 amount = airDrop.amount;
        airDrop.amount = 0;
        airDrop.token.safeTransferFrom(address(this), msg.sender, airDrop.tokenId, amount, "");
    }
// Solidity 0.8.9
/**
 * @notice Admin is able to withdraw tokens unclaimed by creators 1 month after expiration date is over
 */
function adminWithdrawTokensFromExpiredAirdrop(uint256 airdropId) external onlyOwner {
        AirDrop storage airDrop = airDrops[airdropId];
        require(address(airDrop.token) != address(0), "Airdrop with given Id doesn't exists");
        require(airDrop.expirationTimestamp + DEFAULT_ADMIN_WITHDRAWAL < block.timestamp,
            "need to wait creator withdrawal expiration");
        require(airDrop.amount > 0, "Airdrop balance is empty");
        uint256 amount = airDrop.amount;
        airDrop.amount = 0;
        airDrop.token.safeTransferFrom(address(this), msg.sender, airDrop.tokenId, amount, "");
    }
// Solidity 0.5.13
/**
 * @dev Use reserve to swap Token for rewardToken between accounts
 *
 * @param sender account to deduct token from
 * @param receiver account to add rewardToken to
 * @param amount Token amount to exchange for rewardToken
 * @param finOp financial opportunity to swap tokens for
 */
function swapTokenForReward(
        address sender,
        address receiver,
        uint256 amount,
        address finOp
    ) internal validFinOp(finOp) {
        // require sender has sufficient balance
        require(balanceOf(sender) >= amount, "insufficient balance");

        // calculate rewardToken value for depositToken amount
        uint256 rewardAmount = _toRewardToken(amount, finOp);

        // require reserve
        require(rewardTokenBalance(RESERVE, finOp) >= rewardAmount, "not enough rewardToken in reserve");

        // sub from sender and add to reserve for depositToken
        _subBalance(sender, amount);
        _addBalance(RESERVE, amount);

        // sub from reserve and add to sender for rewardToken
        _subRewardBalance(RESERVE, rewardAmount, finOp);
        _addRewardBalance(receiver, rewardAmount, finOp);

        // emit event
        emit SwapTokenForReward(sender, receiver, amount, finOp);
    }
// Solidity 0.5.13
/**
 * @dev Use reserve to swap rewardToken for Token between accounts
 *
 * @param sender account to swap rewardToken from
 * @param receiver account to add Token to
 * @param tokenAmount token amount to receive for Token
 * @param finOp financial opportunity
 */
function swapRewardForToken(
        address sender,
        address receiver,
        uint256 tokenAmount,
        address finOp
    ) internal validFinOp(finOp) {
        // ensure reserve has enough balance
        require(balanceOf(RESERVE) >= tokenAmount, "not enough depositToken in reserve");

        uint256 rewardAmount = _toRewardToken(tokenAmount, finOp);

        // require sufficient balance
        require (rewardTokenBalance(sender, finOp) >= rewardAmount, "insufficient rewardToken balance");

        // sub account and add reserve for rewardToken
        _subRewardBalance(sender, rewardAmount, finOp);
        _addRewardBalance(RESERVE, rewardAmount, finOp);

        // sub account and add reserve for Token
        _subBalance(RESERVE, tokenAmount);
        _addBalance(receiver, tokenAmount);

        // emit event
        emit SwapRewardForToken(sender, receiver, rewardAmount, finOp);
    }