lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.11
/**
 @dev Withdraw tokens previously staked on a slate that was accepted through slate governance.
 @param slateID The slate to withdraw the stake from
 */
function withdrawStake(uint slateID) public returns(bool) {
        require(slateID < slateCount(), "No slate exists with that slateID");

        // get slate
        Slate memory slate = slates[slateID];

        require(slate.status == SlateStatus.Accepted, "Slate has not been accepted");
        require(msg.sender == slate.staker, "Only the original staker can withdraw this stake");
        require(slate.stake > 0, "Stake has already been withdrawn");

        // Update slate and transfer tokens
        slates[slateID].stake = 0;
        require(token.transfer(slate.staker, slate.stake), "Failed to transfer tokens");

        emit StakeWithdrawn(slateID, slate.staker, slate.stake);
        return true;
    }
// Solidity 0.5.11
/**
 @dev Deposit `numToken` tokens into the Gatekeeper to use in voting
 Assumes that `msg.sender` has approved the Gatekeeper to spend on their behalf
 @param numTokens The number of tokens to devote to voting
 */
function depositVoteTokens(uint numTokens) public returns(bool) {
        require(isCurrentGatekeeper(), "Not current gatekeeper");
        address voter = msg.sender;

        // Voter must have enough tokens
        require(token.balanceOf(msg.sender) >= numTokens, "Insufficient token balance");

        // Transfer tokens to increase the voter's balance by `numTokens`
        uint originalBalance = voteTokenBalance[voter];
        voteTokenBalance[voter] = originalBalance.add(numTokens);

        // Must successfully transfer tokens from voter to this contract
        require(token.transferFrom(voter, address(this), numTokens), "Failed to transfer tokens");

        emit VotingTokensDeposited(voter, numTokens);
        return true;
    }
// Solidity 0.5.11
/**
 @dev Withdraw `numTokens` vote tokens to the caller and decrease voting power
 @param numTokens The number of tokens to withdraw
 */
function withdrawVoteTokens(uint numTokens) public returns(bool) {
        require(commitPeriodActive() == false, "Tokens locked during voting");

        address voter = msg.sender;

        uint votingRights = voteTokenBalance[voter];
        require(votingRights >= numTokens, "Insufficient vote token balance");

        // Transfer tokens to decrease the voter's balance by `numTokens`
        voteTokenBalance[voter] = votingRights.sub(numTokens);

        require(token.transfer(voter, numTokens), "Failed to transfer tokens");

        emit VotingTokensWithdrawn(voter, numTokens);
        return true;
    }
// Solidity 0.5.11
/**
 @dev Submit a commitment for the current ballot
 @param voter The voter to commit for
 @param commitHash The hash representing the voter's vote choices
 @param numTokens The number of vote tokens to use
 */
function commitBallot(address voter, bytes32 commitHash, uint numTokens) public {
        uint epochNumber = currentEpochNumber();

        require(commitPeriodActive(), "Commit period not active");

        require(didCommit(epochNumber, voter) == false, "Voter has already committed for this ballot");
        require(commitHash != 0, "Cannot commit zero hash");

        address committer = msg.sender;

        // Must be a delegate if not the voter
        if (committer != voter) {
            require(committer == delegate[voter], "Not a delegate");
            require(voteTokenBalance[voter] >= numTokens, "Insufficient tokens");
        } else {
            // If the voter doesn't have enough tokens for voting, deposit more
            if (voteTokenBalance[voter] < numTokens) {
                uint remainder = numTokens.sub(voteTokenBalance[voter]);
                depositVoteTokens(remainder);
            }
        }

        assert(voteTokenBalance[voter] >= numTokens);

        // Set the voter's commitment for the current ballot
        Ballot storage ballot = ballots[epochNumber];
        VoteCommitment memory commitment = VoteCommitment({
            commitHash: commitHash,
            numTokens: numTokens,
            committed: true,
            revealed: false
        });

        ballot.commitments[voter] = commitment;

        emit BallotCommitted(epochNumber, committer, voter, numTokens, commitHash);
    }
// Solidity 0.5.11
/**
 @dev Reveal ballots for multiple voters
 */
function revealManyBallots(
        uint256 epochNumber,
        address[] memory _voters,
        bytes[] memory _ballots,
        uint[] memory _salts
    ) public {
        uint numBallots = _voters.length;
        require(
            _salts.length == _voters.length && _ballots.length == _voters.length,
            "Inputs must have the same length"
        );

        for (uint i = 0; i < numBallots; i++) {
            // extract resources, firstChoices, secondChoices from the ballot
            (
                address[] memory resources,
                uint[] memory firstChoices,
                uint[] memory secondChoices
            ) = abi.decode(_ballots[i], (address[], uint[], uint[]));

            revealBallot(epochNumber, _voters[i], resources, firstChoices, secondChoices, _salts[i]);
        }
    }
// Solidity 0.5.11
/**
 @dev Get the number of second-choice votes cast for the given slate and resource
 @param epochNumber The epoch
 @param resource The resource
 @param slateID The slate
 */
function getSecondChoiceVotes(uint epochNumber, address resource, uint slateID) public view returns(uint) {
        // for each option that isn't this one, get the second choice votes
        Contest storage contest = ballots[epochNumber].contests[resource];
        uint numSlates = contest.stakedSlates.length;
        uint votes = 0;
        for (uint i = 0; i < numSlates; i++) {
            uint otherSlateID = contest.stakedSlates[i];
            if (otherSlateID != slateID) {
                SlateVotes storage v = contest.votes[otherSlateID];
                // get second-choice votes for the target slate
                votes = votes.add(v.secondChoiceVotes[slateID]);
            }
        }
        return votes;
    }
// Solidity 0.5.11
/**
 @dev Get the details of the specified contest
 */
function contestDetails(uint256 epochNumber, address resource) external view
        returns(
            ContestStatus status,
            uint256[] memory allSlates,
            uint256[] memory stakedSlates,
            uint256 lastStaked,
            uint256 voteWinner,
            uint256 voteRunnerUp,
            uint256 winner
        ) {
        Contest memory c =  ballots[epochNumber].contests[resource];

        status = c.status;
        allSlates = c.slates;
        stakedSlates = c.stakedSlates;
        lastStaked = c.lastStaked;
        voteWinner = c.voteLeader;
        voteRunnerUp = c.voteRunnerUp;
        winner = c.winner;
    }
// Solidity 0.5.11
/**
 @dev Send tokens of the rejected slates to the token capacitor.
 @param epochNumber The epoch
 @param resource The resource
 */
function donateChallengerStakes(uint256 epochNumber, address resource, uint256 startIndex, uint256 count) public {
        Contest storage contest = ballots[epochNumber].contests[resource];
        require(contest.status == ContestStatus.Finalized, "Contest is not finalized");

        uint256 numSlates = contest.stakedSlates.length;
        require(contest.stakesDonated != numSlates, "All stakes donated");

        // If there are still stakes to be donated, continue
        require(startIndex == contest.stakesDonated, "Invalid start index");

        uint256 endIndex = startIndex.add(count);
        require(endIndex <= numSlates, "Invalid end index");

        address stakeDonationAddress = parameters.getAsAddress("stakeDonationAddress");
        IDonationReceiver donationReceiver = IDonationReceiver(stakeDonationAddress);
        bytes memory stakeDonationHash = "Qmepxeh4KVkyHYgt3vTjmodB5RKZgUEmdohBZ37oKXCUCm";

        for (uint256 i = startIndex; i < endIndex; i++) {
            uint256 slateID = contest.stakedSlates[i];
            Slate storage slate = slates[slateID];
            if (slate.status != SlateStatus.Accepted) {
                uint256 donationAmount = slate.stake;
                slate.stake = 0;

                // Only donate for non-zero amounts
                if (donationAmount > 0) {
                    require(
                        token.approve(address(donationReceiver), donationAmount),
                        "Failed to approve Gatekeeper to spend tokens"
                    );
                    donationReceiver.donate(address(this), donationAmount, stakeDonationHash);
                }
            }
        }

        // Update state
        contest.stakesDonated = endIndex;
    }
// Solidity 0.5.11
/**
 @dev Request permission to perform the action described in the metadataHash
 @param metadataHash A reference to metadata about the action
 */
function requestPermission(bytes memory metadataHash) public returns(uint) {
        require(isCurrentGatekeeper(), "Not current gatekeeper");
        require(metadataHash.length > 0, "metadataHash cannot be empty");
        address resource = msg.sender;
        uint256 epochNumber = currentEpochNumber();

        require(slateSubmissionPeriodActive(resource), "Submission period not active");

        // If the request is created in epoch n, expire at the start of epoch n + 2
        uint256 expirationTime = epochStart(epochNumber.add(2));

        // Create new request
        Request memory r = Request({
            metadataHash: metadataHash,
            resource: resource,
            approved: false,
            expirationTime: expirationTime,
            epochNumber: epochNumber
        });

        // Record request and return its ID
        uint requestID = requestCount();
        requests.push(r);

        emit PermissionRequested(epochNumber, resource, requestID, metadataHash);
        return requestID;
    }
// Solidity 0.5.11
/**
 @dev Update a slate and its associated requests
 @param slateID The slate to update
 */
function acceptSlate(uint slateID) private {
        // Mark the slate as accepted
        Slate storage s = slates[slateID];
        s.status = SlateStatus.Accepted;

        // Record the incumbent
        if (incumbent[s.resource] != s.recommender) {
            incumbent[s.resource] = s.recommender;
        }

        // mark all of its requests as approved
        uint[] memory requestIDs = s.requests;
        for (uint i = 0; i < requestIDs.length; i++) {
            uint requestID = requestIDs[i];
            requests[requestID].approved = true;
        }
    }
// Solidity 0.7.6
// --- Prepare ---
// Sets the two deployer dependencies. This needs to be called by the deployUsr
function prepare(address lender_, address borrower_, address oracle_, address[] memory poolAdmins_) public {
        require(deployUsr == msg.sender);
        
        borrowerDeployer = BorrowerDeployerLike(borrower_);
        lenderDeployer = LenderDeployerLike_1(lender_);
        oracle = oracle_;
        poolAdmins = poolAdmins_;

        deployUsr = address(0); // disallow the deploy user to call this more than once.
    }
// Solidity 0.7.6
// --- Deploy ---
// After going through the deploy process on the lender and borrower method, this method is called to connect
// lender and borrower contracts.
function deploy() public {
        require(address(borrowerDeployer) != address(0) && address(lenderDeployer) != address(0) && deployed == false);
        deployed = true;

        address reserve_ = lenderDeployer.reserve();
        address shelf_ = borrowerDeployer.shelf();

        // Borrower depends
        DependLike_3(borrowerDeployer.collector()).depend("reserve", reserve_);
        DependLike_3(borrowerDeployer.shelf()).depend("lender", reserve_);
        DependLike_3(borrowerDeployer.shelf()).depend("reserve", reserve_);

        // Lender depends
        address navFeed = borrowerDeployer.feed();

        DependLike_3(reserve_).depend("shelf", shelf_);
        DependLike_3(lenderDeployer.assessor()).depend("navFeed", navFeed);

        // Lender wards
        if (oracle != address(0)) AuthLike_3(navFeed).rely(oracle);

        // directly relying governance so it can be used to directly add/remove pool admins without going through the root
        PoolAdminLike poolAdmin = PoolAdminLike(lenderDeployer.poolAdmin());
        PoolAdminLike(poolAdmin).rely(governance);

        for (uint i = 0; i < poolAdmins.length; i++) {
            PoolAdminLike(poolAdmin).relyAdmin(poolAdmins[i]);
        }
    }
// Solidity 0.8.13
////////////////////
/// @notice get all nfts of a person
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.3
// transferOwnership add a pending owner
function transferOwnership(address newOwner) public override onlyOwner {
        require(!isBlackListed[newOwner], "Pending owner can not be in blackList");
        require(newOwner != owner(), "Pending owner and current owner need to be different");
        require(newOwner != address(0), "Pending owner can not be zero address");

        _pendingOwner = newOwner;

        emit TransferOwnerShip(newOwner);
    }
// Solidity 0.8.3
// acceptOwnership allows the pending owner to accept the ownership of the SPWN token contract
// along with grant new owner MINT_BURN_ROLE role and remove MINT_BURN_ROLE from old owner
function acceptOwnership() public {
        require(_pendingOwner != address(0), "Please set pending owner first");
        require(_pendingOwner == msg.sender, "Only pending owner is able to accept the ownership");
        require(!isBlackListed[msg.sender], "Pending owner can not be in blackList");

        address oldOwner = owner();

        _owner = _pendingOwner;

        _setupRole(DEFAULT_ADMIN_ROLE, _pendingOwner);
        _grantAccess(MINT_BURN_ROLE, _pendingOwner);

        _revokeAccess(MINT_BURN_ROLE, oldOwner);
        _revokeAccess(DEFAULT_ADMIN_ROLE, oldOwner);

        emit AcceptOwnerShip(oldOwner, _pendingOwner);

        _pendingOwner = address(0);
    }
// Solidity 0.8.3
// internal function _revokeAccess revokes account with given role
function _revokeAccess(bytes32 role, address account) internal {
        if (DEFAULT_ADMIN_ROLE == role) {
            require(account != owner(), "owner can not revoke himself from admin role");
        }

        revokeRole(role, account);

        emit RoleRevoked(role, account, owner());
    }
// Solidity 0.5.0
/**
 * Destroy tokens
 *
 * Remove `_value` tokens from the system irreversibly
 *
 * @param Account address
 *
 * @param _value the amount of money to burn
 * 
 * Safely check if total supply is not overdrawn
 */
function burnFrom(address Account, uint256 _value) public returns (bool success) {
        require (LockList[msg.sender] == false,"ERC20: User Locked !");    
        require (LockList[Account] == false,"ERC20: Owner Locked !");    
        uint256 stage;
        require(Account != address(0), "ERC20: Burn from the zero address");
        
        //Safely substract amount to be burned from callers allowance
        _approve(Account, msg.sender, _allowance[Account][msg.sender].sub(_value,"ERC20: burn amount exceeds allowance"));
        
        //Do not allow burn if Accounts tokens are locked.
        stage=balanceOf[Account].sub(_value,"ERC20: Transfer amount exceeds allowance");
        require(stage>=LockedTokens[Account],"ERC20: Burn amount exceeds accounts locked amount");
        balanceOf[Account] =stage ;            // Subtract from the sender
        
        //Deduct burn amount from totalSupply
        totalSupply=totalSupply.sub(_value,"ERC20: Burn Amount exceeds totalSupply");
       
        emit Burn(Account, _value);
        emit Transfer(Account, address(0), _value);

        return true;
    }
// Solidity 0.5.0
/**
 * Set allowance for other address
 *
 * Allows `_spender` to spend no more than `_value` tokens in your behalf
 * Emits Approval Event
 * @param _spender The address authorized to spend
 * @param _value the max amount they can spend
 */
function approve(address _spender, uint256 _value) public
        returns (bool success) {
        uint256 unapprovbal;

        // Do not allow approval if amount exceeds locked amount
        unapprovbal=balanceOf[msg.sender].sub(_value,"ERC20: Allowance exceeds balance of approver");
        require(unapprovbal>=LockedTokens[msg.sender],"ERC20: Approval amount exceeds locked amount ");
       
       
        _allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }
// Solidity 0.8.0
// --------------------------------------------------------
//          FUNCTION HANDLER
// --------------------------------------------------------
function withdraw() public {
        uint256 tokenPending = 0;
        bool isWithdraw = false;

        require(block.timestamp - timestampLastReceived >= 5 * month, 'You can not withdraw token now');

        for(uint8 i = 0; i < 13 ; i++) {
            if( times[i] != true ) {
                times[i] = true;
                isWithdraw = true;
                tokenPending = i == 0 ? totalFBSDistributor.mul(percents[i]).div(100) : totalFBSDistributor.mul(percents[i] - percents[i-1]).div(100);
                break;
            }
        }

        if( isWithdraw ) {
            timestampLastReceived = timestampLastReceived.add(5 * month);
            for(uint8 j = 0; j < 10; j++) {
                sendTransferToken(address_admin[j], tokenPending.div(10));
            }

            emit Withdraw(tokenPending);
        }
    }
// Solidity 0.5.17
// --- Approve by signature ---
function permit(address holder, address spender, uint256 nonce, uint256 expiry,
                    bool allowed, uint8 v, bytes32 r, bytes32 s) external
    {
        bytes32 digest =
            keccak256(abi.encodePacked(
                "\x19\x01",
                DOMAIN_SEPARATOR,
                keccak256(abi.encode(PERMIT_TYPEHASH,
                                     holder,
                                     spender,
                                     nonce,
                                     expiry,
                                     allowed))
        ));

        require(holder != address(0), "invalid-address-0");
        require(holder == ecrecover(digest, v, r, s), "invalid-permit");
        require(expiry == 0 || now <= expiry, "permit-expired");
        require(nonce == nonces[holder]++, "invalid-nonce");
        uint256 amount = allowed ? uint256(-1) : 0;
        allowance[holder][spender] = amount;
        emit Approval(holder, spender, amount);
    }
// Solidity 0.6.12
/**
 * @dev Adds a new pool. Admin only
 *
 * Params:
 * _allocPoint: the allocation points to be assigned to this pool
 * _lpToken: the token that this pool accepts
 * _withUpdate: whether or not to update all pools
 */
function add(
        uint256 _allocPoint,
        IERC20 _lpToken,
        bool _withUpdate
    ) public onlyAdmin isInitialized {
        if (_withUpdate) {
            massUpdatePools();
        }
        uint256 lastRewardBlock =
            block.number > startBlock ? block.number : startBlock;
        totalAllocPoint = totalAllocPoint.add(_allocPoint);
        poolInfo.push(
            PoolInfo({
                lpToken: _lpToken,
                allocPoint: _allocPoint,
                lastRewardBlock: lastRewardBlock,
                accStarsPerShare: 0,
                poolSupply: 0
            })
        );
    }
// Solidity 0.6.12
/**
 * @dev View function to see pending Stars on frontend.
 *
 * Params:
 * _user: address of the stars to view the pending rewards for.
 */
function pendingStars(uint256 _pid, address _user)
        external
        view
        isInitialized
        returns (uint256)
    {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][_user];

        if (pool.poolSupply == 0) {
            return 0;
        }

        uint256 currRateEndStarsPerShare =
            accStarsPerShareAtCurrRate(
                uint256(block.number).sub(startBlock),
                pool.poolSupply
            );
        uint256 currRateStartStarsPerShare =
            accStarsPerShareAtCurrRate(
                pool.lastRewardBlock.sub(startBlock),
                pool.poolSupply
            );
        uint256 starsReward =
            (currRateEndStarsPerShare.sub(currRateStartStarsPerShare))
                .mul(pool.allocPoint)
                .div(totalAllocPoint);

        uint256 pendingAccStarsPerShare =
            pool.accStarsPerShare.add(starsReward);
        return
            user.amount.mul(pendingAccStarsPerShare).div(1e12).sub(
                user.rewardDebt
            );
    }
// Solidity 0.6.12
/**
 * @dev An internal function to calculate the total accumulated Stars per
 * share, assuming the stars per share remained the same since staking
 * began.
 *
 * Params:
 * blocks: The number of blocks to calculate for
 */
function accStarsPerShareAtCurrRate(uint256 blocks, uint256 poolSupply)
        public
        view
        returns (uint256)
    {
        if (blocks > epochs[2]) {
            return
                totalStarsPerEpoch[0]
                    .add(totalStarsPerEpoch[1])
                    .add(totalStarsPerEpoch[2])
                    .mul(1e12)
                    .div(poolSupply);
        } else if (blocks > epochs[1]) {
            uint256 currTierRewards =
                (blocks.sub(epochs[1]).mul(rewardAmounts[2]));
            return
                totalStarsPerEpoch[0]
                    .add(totalStarsPerEpoch[1])
                    .add(currTierRewards)
                    .mul(1e12)
                    .div(poolSupply);
        } else if (blocks > epochs[0]) {
            uint256 currTierRewards =
                (blocks.sub(epochs[0]).mul(rewardAmounts[1]));
            return
                totalStarsPerEpoch[0].add(currTierRewards).mul(1e12).div(
                    poolSupply
                );
        } else {
            return blocks.mul(rewardAmounts[0]).mul(1e12).div(poolSupply);
        }
    }
// Solidity 0.6.12
/**
 * @dev A function for the front-end to see information about the current
 rewards.
 */
function starsPerBlock()
        public
        view
        isInitialized
        returns (uint256 amount)
    {
        uint256 blocks = uint256(block.number).sub(startBlock);
        if (blocks >= epochs[2]) {
            return 0;
        } else if (blocks >= epochs[1]) {
            return rewardAmounts[2];
        } else if (blocks >= epochs[0]) {
            return rewardAmounts[1];
        } else {
            return rewardAmounts[0];
        }
    }