lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.17
/**
 * @notice Accrues interest and reduces Fuse fees by transferring to Fuse
 * @param withdrawAmount Amount of fees to withdraw
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function _withdrawFuseFees(uint withdrawAmount) external nonReentrant(false) returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted Fuse fee withdrawal failed.
            return fail(Error(error), FailureInfo.WITHDRAW_FUSE_FEES_ACCRUE_INTEREST_FAILED);
        }
        // _withdrawFuseFeesFresh emits reserve-reduction-specific logs on errors, so we don't need to.
        return _withdrawFuseFeesFresh(withdrawAmount);
    }
// Solidity 0.5.17
/**
 * @notice Reduces Fuse fees by transferring to Fuse
 * @dev Requires fresh interest accrual
 * @param withdrawAmount Amount of fees to withdraw
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function _withdrawFuseFeesFresh(uint withdrawAmount) internal returns (uint) {
        // totalFuseFees - reduceAmount
        uint totalFuseFeesNew;

        // We fail gracefully unless market's block number equals current block number
        if (accrualBlockNumber != getBlockNumber()) {
            return fail(Error.MARKET_NOT_FRESH, FailureInfo.WITHDRAW_FUSE_FEES_FRESH_CHECK);
        }

        // Fail gracefully if protocol has insufficient underlying cash
        if (getCashPrior() < withdrawAmount) {
            return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.WITHDRAW_FUSE_FEES_CASH_NOT_AVAILABLE);
        }

        // Check withdrawAmount ≤ fuseFees[n] (totalFuseFees)
        if (withdrawAmount > totalFuseFees) {
            return fail(Error.BAD_INPUT, FailureInfo.WITHDRAW_FUSE_FEES_VALIDATION);
        }

        /////////////////////////
        // EFFECTS & INTERACTIONS
        // (No safe failures beyond this point)

        // We checked withdrawAmount <= totalFuseFees above, so this should never revert.
        totalFuseFeesNew = sub_(totalFuseFees, withdrawAmount);

        // Store fuseFees[n+1] = fuseFees[n] - withdrawAmount
        totalFuseFees = totalFuseFeesNew;

        // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.
        doTransferOut(address(fuseAdmin), withdrawAmount);

        return uint(Error.NO_ERROR);
    }
// Solidity 0.5.17
/**
 * @notice updates the cToken ERC20 name and symbol
 * @dev Admin function to update the cToken ERC20 name and symbol
 * @param _name the new ERC20 token name to use
 * @param _symbol the new ERC20 token symbol to use
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function _setNameAndSymbol(string calldata _name, string calldata _symbol) external {
        // Check caller is admin
        require(hasAdminRights(), "caller not admin");

        // Set ERC20 name and symbol
        name = _name;
        symbol = _symbol;
    }
// Solidity 0.5.17
/**
 * @dev Performs a Solidity function call using a low level `call`. A
 * plain `call` is an unsafe replacement for a function call: use this
 * function instead.
 * If `target` reverts with a revert reason, it is bubbled up by this
 * function (like regular Solidity function calls).
 * Returns the raw returned data. To convert to the expected return value,
 * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
 * @param data The call data (encoded using abi.encode or one of its variants).
 * @param errorMessage The revert string to return on failure.
 */
function _functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.call(data);

        if (!success) {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }

        return returndata;
    }
// Solidity 0.4.24
/**
 @dev Registers a new contribution, sets their share
 @param _sender The address of the wallet contributing
 @param _amount The amount that the owner has sent
 */
function contribute(address _sender, uint256 _amount) private {
        require(!locked, "Crowdsale period over, contribution is locked");
        require(!distributionActive, "Cannot contribute when distribution is active");
        require(_amount >= precisionMinimum, "Amount needs to be above the minimum contribution");
        require(hardCap >= _amount, "Your contribution is greater than the hard cap");
        require(_amount % precisionMinimum == 0, "Your amount isn't divisible by the minimum precision");
        require(hardCap >= totalContributed.add(_amount), "Your contribution would cause the total to exceed the hardcap");

        totalContributed = totalContributed.add(_amount);
        uint256 share = percent(_amount, valuation, 5);

        Owner storage o = owners[_sender];
        if (o.percentage != 0) { // Existing owner
            o.shareTokens = o.shareTokens.add(_amount);
            o.percentage = o.percentage.add(share);
        } else { // New owner
            require(ownerMap.insert(totalOwners, uint(_sender)) == false);
            o.key = totalOwners;
            totalOwners += 1;
            o.shareTokens = _amount;
            o.percentage = share;
        }

        if (!whitelist[msg.sender]) {
            whitelist[msg.sender] = true;
        }

        emit Contribution(_sender, share, _amount);
    }
// Solidity 0.4.24
/**
 @dev Manually set a share directly, used to set the LinkPool members as owners
 @param _owner Wallet address of the owner
 @param _value The equivalent contribution value
 */
function setOwnerShare(address _owner, uint256 _value) public onlyOwner() {
        require(!locked, "Can't manually set shares, it's locked");
        require(!distributionActive, "Cannot set owners share when distribution is active");

        Owner storage o = owners[_owner];
        if (o.shareTokens == 0) {
            whitelist[_owner] = true;
            require(ownerMap.insert(totalOwners, uint(_owner)) == false);
            o.key = totalOwners;
            totalOwners += 1;
        }
        o.shareTokens = _value;
        o.percentage = percent(_value, valuation, 5);
    }
// Solidity 0.4.24
/**
 @dev Transfer part or all of your ownership to another address
 @param _receiver The address that you're sending to
 @param _amount The amount of ownership to send, for your balance refer to `ownerShareTokens`
 */
function sendOwnership(address _receiver, uint256 _amount) public onlyWhitelisted() {
        Owner storage o = owners[msg.sender];
        Owner storage r = owners[_receiver];

        require(o.shareTokens > 0, "You don't have any ownership");
        require(o.shareTokens >= _amount, "The amount exceeds what you have");
        require(!distributionActive, "Distribution cannot be active when sending ownership");
        require(_amount % precisionMinimum == 0, "Your amount isn't divisible by the minimum precision amount");

        o.shareTokens = o.shareTokens.sub(_amount);

        if (o.shareTokens == 0) {
            o.percentage = 0;
            require(ownerMap.remove(o.key) == true);
        } else {
            o.percentage = percent(o.shareTokens, valuation, 5);
        }
        if (r.shareTokens == 0) {
            whitelist[_receiver] = true;
            require(ownerMap.insert(totalOwners, uint(_receiver)) == false);
            totalOwners += 1;
        }
        r.shareTokens = r.shareTokens.add(_amount);
        r.percentage = r.percentage.add(percent(_amount, valuation, 5));

        emit OwnershipTransferred(msg.sender, _receiver, _amount);
    }
// Solidity 0.4.24
/**
 @dev Start the distribution phase in the contract so owners can claim their tokens
 @param _token The token address to start the distribution of
 */
function distributeTokens(address _token) public onlyWhitelisted() {
        require(!distributionActive, "Distribution is already active");
        distributionActive = true;

        ERC677 erc677 = ERC677(_token);

        uint256 currentBalance = erc677.balanceOf(this) - tokenBalance[_token];
        require(currentBalance > distributionMinimum, "Amount in the contract isn't above the minimum distribution limit");

        totalDistributions++;
        Distribution storage d = distributions[totalDistributions]; 
        d.owners = ownerMap.size();
        d.amount = currentBalance;
        d.token = _token;
        d.claimed = 0;
        totalReturned[_token] += currentBalance;

        emit TokenDistributionActive(_token, currentBalance, totalDistributions, d.owners);
    }
// Solidity 0.4.24
/**
 @dev Claim tokens by a owner address to add them to their balance
 @param _owner The address of the owner to claim tokens for
 */
function claimTokens(address _owner) public {
        Owner storage o = owners[_owner];
        Distribution storage d = distributions[totalDistributions]; 

        require(o.shareTokens > 0, "You need to have a share to claim tokens");
        require(distributionActive, "Distribution isn't active");
        require(!d.claimedAddresses[_owner], "Tokens already claimed for this address");

        address token = d.token;
        uint256 tokenAmount = d.amount.mul(o.percentage).div(100000);
        o.balance[token] = o.balance[token].add(tokenAmount);
        tokenBalance[token] = tokenBalance[token].add(tokenAmount);

        d.claimed++;
        d.claimedAddresses[_owner] = true;

        emit ClaimedTokens(_owner, token, tokenAmount, d.claimed, totalDistributions);

        if (d.claimed == d.owners) {
            distributionActive = false;
            emit TokenDistributionComplete(token, totalOwners);
        }
    }
// Solidity 0.4.24
/**
 @dev Withdraw tokens from your contract balance
 @param _token The token address for token claiming
 @param _amount The amount of tokens to withdraw
 */
function withdrawTokens(address _token, uint256 _amount) public {
        require(_amount > 0, "You have requested for 0 tokens to be withdrawn");

        Owner storage o = owners[msg.sender];
        Distribution storage d = distributions[totalDistributions]; 

        if (distributionActive && !d.claimedAddresses[msg.sender]) {
            claimTokens(msg.sender);
        }
        require(o.balance[_token] >= _amount, "Amount requested is higher than your balance");

        o.balance[_token] = o.balance[_token].sub(_amount);
        tokenBalance[_token] = tokenBalance[_token].sub(_amount);

        ERC677 erc677 = ERC677(_token);
        require(erc677.transfer(msg.sender, _amount) == true);

        emit TokenWithdrawal(_token, msg.sender, _amount);
    }
// Solidity 0.4.24
/**
 @dev Credit to Rob Hitchens: https://stackoverflow.com/a/42739843
 */
function percent(uint numerator, uint denominator, uint precision) private pure returns (uint quotient) {
        uint _numerator = numerator * 10 ** (precision+1);
        uint _quotient = ((_numerator / denominator) + 5) / 10;
        return ( _quotient);
    }
// Solidity 0.4.26
//depositRate    /1000
function getDepositRate(uint value, uint day) public view returns(uint){
        if(day == 5){
            if(value >= 1 * ethWei && value <= 3 * ethWei){
                return 8;
            }
            if(value >= 4 * ethWei && value <= 6 * ethWei){
                return 10;
            }
            if(value >= 7 * ethWei && value <= 10 * ethWei){
                return 12;
            }
        }
        return 0;
    }
// Solidity 0.4.26
//shareLevel   
function getShareLevel(uint value) public view returns(uint){
        if(value >=1 * ethWei && value <=3 * ethWei){
            return 1;
        }
        if(value >=4 * ethWei && value<=6 * ethWei){
            return 2;
        }
        if(value >=7 * ethWei && value <=10 * ethWei){
            return 3;
        }
    }
// Solidity 0.4.26
//shareRate     /100
function getShareRate(uint level,uint times) public view returns(uint){
        if(level == 1 && times == 1){ 
            
            return 50;
            
        }if(level == 2 && times == 1){
            
            return 50;
            
        }if(level == 2 && times == 2){
            
            return 20;
            
        }if(level == 2 && times == 3){
            
            return 10;
            
        }
        if(level == 3) {
            if(times == 1){
                
                return 70;
                
            }if(times == 2){
                
                return 30;
                
            }if(times == 3){
                
                return 20;
                
            }if(times >= 4){
                
                return 10;
                
            }if(times >= 5 && times <= 10){
                
                return 5;
                
            }if(times >= 11 && times <=20){
                
                return 3;
                
            }if(times >= 21){
                
                return 1;
                
            }
        } 
        return 0;
        
    }
// Solidity 0.6.12
/*
 * manualEpochInit can be used by anyone to initialize an epoch based on the previous one
 * This is only applicable if there was no action (deposit/withdraw) in the current epoch.
 * Any deposit and withdraw will automatically initialize the current and next epoch.
 */
function manualEpochInit(address[] memory tokens, uint128 epochId) public whenNotPaused {
        require(epochId <= getCurrentEpoch(), "STK:E-306");


        for (uint i = 0; i < tokens.length; i++) {
            Pool storage p = poolSize[tokens[i]][epochId];
            if (epochId == 0) {
                p.size = uint256(0);
                p.set = true;
            } else {
                require(!epochIsInitialized(tokens[i], epochId), "STK:E-002");
                require(epochIsInitialized(tokens[i], epochId - 1), "STK:E-305");
                p.size = poolSize[tokens[i]][epochId - 1].size;
                p.set = true;
            }
        }

        emit ManualEpochInit(msg.sender, epochId, tokens);
    }
// Solidity 0.6.12
/*
 * Returns the valid balance of a user that was taken into consideration in the total pool size for the epoch
 * A deposit will only change the next epoch balance.
 * A withdraw will decrease the current epoch (and subsequent) balance.
 */
function getEpochUserBalance(address user, address token, uint128 epochId) public view returns (uint256) {
        Checkpoint[] storage checkpoints = balanceCheckpoints[user][token];

        // if there are no checkpoints, it means the user never deposited any tokens, so the balance is 0
        if (checkpoints.length == 0 || epochId < checkpoints[0].epochId) {
            return 0;
        }

        uint min = 0;
        uint max = checkpoints.length - 1;

        // shortcut for blocks newer than the latest checkpoint == current balance
        if (epochId >= checkpoints[max].epochId) {
            return getCheckpointEffectiveBalance(checkpoints[max]);
        }

        // binary search of the value in the array
        while (max > min) {
            uint mid = (max + min + 1) / 2;
            if (checkpoints[mid].epochId <= epochId) {
                min = mid;
            } else {
                max = mid - 1;
            }
        }

        return getCheckpointEffectiveBalance(checkpoints[min]);
    }
// Solidity 0.6.12
/*
 * Returns the total amount of `tokenAddress` that was locked from beginning to end of epoch identified by `epochId`
 */
function getEpochPoolSize(address tokenAddress, uint128 epochId) public view returns (uint256) {
        // Premises:
        // 1. it's impossible to have gaps of uninitialized epochs
        // - any deposit or withdraw initialize the current epoch which requires the previous one to be initialized
        if (epochIsInitialized(tokenAddress, epochId)) {
            return poolSize[tokenAddress][epochId].size;
        }

        // epochId not initialized and epoch 0 not initialized => there was never any action on this pool
        if (!epochIsInitialized(tokenAddress, 0)) {
            return 0;
        }

        // epoch 0 is initialized => there was an action at some point but none that initialized the epochId
        // which means the current pool size is equal to the current balance of token held by the staking contract
        IERC20 token = IERC20(tokenAddress);
        return token.balanceOf(address(this));
    }
// Solidity 0.6.12
/*
 * Returns the percentage of time left in the current epoch
 */
function currentEpochMultiplier() public view returns (uint128) {
        uint128 currentEpoch = getCurrentEpoch();
        uint256 currentEpochEnd = epoch1Start + currentEpoch * epochDuration;
        uint256 timeLeft = currentEpochEnd - block.timestamp;
        uint128 multiplier = uint128(timeLeft * BASE_MULTIPLIER / epochDuration);

        return multiplier;
    }
// Solidity 0.4.21
/**
 * Set new owner for the smart contract.
 * May only be called by smart contract owner.
 *
 * @param _address of new or existing owner of the smart contract
 * @param _value boolean stating if the _address should be an owner or not
 */
function setOwner (address _address, bool _value) public {
    require (owners[msg.sender]);
    // if removing the _address from owners list, make sure owner is not 
    // removing himself (which could lead to an ownerless contract).
    require (_value == true || _address != msg.sender);

    owners[_address] = _value;
  }
// Solidity 0.4.21
/**
 * Initialize the token holders by contract owner
 *
 * @param _to addresses to allocate token for
 * @param _value number of tokens to be allocated
 */
function initAccounts (address [] _to, uint256 [] _value) public {
      require (owners[msg.sender]);
      require (_to.length == _value.length);
      for (uint256 i=0; i < _to.length; i++){
          uint256 amountToAdd;
          uint256 amountToSub;
          if (_value[i] > accounts[_to[i]]){
            amountToAdd = safeSub(_value[i], accounts[_to[i]]);
          }else{
            amountToSub = safeSub(accounts[_to[i]], _value[i]);
          }
          accounts [supplyOwner] = safeAdd (accounts [supplyOwner], amountToSub);
          accounts [supplyOwner] = safeSub (accounts [supplyOwner], amountToAdd);
          accounts [_to[i]] = _value[i];
          if (amountToAdd > 0){
            emit Transfer (supplyOwner, _to[i], amountToAdd);
          }
      }
  }
// Solidity 0.4.24
/**
 * @notice Default implementation of verifyTransfer used by SecurityToken
 * If the transfer request comes from the STO, it only checks that the investor is in the whitelist
 * If the transfer request comes from a token holder, it checks that:
 * a) Both are on the whitelist
 * b) Seller's sale lockup period is over
 * c) Buyer's purchase lockup is over
 * @param _from Address of the sender
 * @param _to Address of the receiver
 */
function verifyTransfer(address _from, address _to, uint256 /*_amount*/, bytes /* _data */, bool /* _isTransfer */) public returns(Result) {
        if (!paused) {
            if (allowAllTransfers) {
                //All transfers allowed, regardless of whitelist
                return Result.VALID;
            }
            if (allowAllBurnTransfers && (_to == address(0))) {
                return Result.VALID;
            }
            if (allowAllWhitelistTransfers) {
                //Anyone on the whitelist can transfer, regardless of time
                return (_onWhitelist(_to) && _onWhitelist(_from)) ? Result.VALID : Result.NA;
            }
            if (allowAllWhitelistIssuances && _from == issuanceAddress) {
                if (!whitelist[_to].canBuyFromSTO && _isSTOAttached()) {
                    return Result.NA;
                }
                return _onWhitelist(_to) ? Result.VALID : Result.NA;
            }
            //Anyone on the whitelist can transfer provided the blocknumber is large enough
            /*solium-disable-next-line security/no-block-members*/
            return ((_onWhitelist(_from) && whitelist[_from].fromTime <= now) &&
                (_onWhitelist(_to) && whitelist[_to].toTime <= now)) ? Result.VALID : Result.NA; /*solium-disable-line security/no-block-members*/
        }
        return Result.NA;
    }
// Solidity 0.4.24
/**
 * @notice Adds or removes addresses from the whitelist.
 * @param _investor is the address to whitelist
 * @param _fromTime is the moment when the sale lockup period ends and the investor can freely sell his tokens
 * @param _toTime is the moment when the purchase lockup period ends and the investor can freely purchase tokens from others
 * @param _expiryTime is the moment till investors KYC will be validated. After that investor need to do re-KYC
 * @param _canBuyFromSTO is used to know whether the investor is restricted investor or not.
 */
function modifyWhitelist(
        address _investor,
        uint256 _fromTime,
        uint256 _toTime,
        uint256 _expiryTime,
        bool _canBuyFromSTO
    )
        public
        withPerm(WHITELIST)
    {
        //Passing a _time == 0 into this function, is equivalent to removing the _investor from the whitelist
        whitelist[_investor] = TimeRestriction(_fromTime, _toTime, _expiryTime, _canBuyFromSTO);
        /*solium-disable-next-line security/no-block-members*/
        emit ModifyWhitelist(_investor, now, msg.sender, _fromTime, _toTime, _expiryTime, _canBuyFromSTO);
    }
// Solidity 0.4.24
/**
 * @notice Adds or removes addresses from the whitelist.
 * @param _investors List of the addresses to whitelist
 * @param _fromTimes An array of the moment when the sale lockup period ends and the investor can freely sell his tokens
 * @param _toTimes An array of the moment when the purchase lockup period ends and the investor can freely purchase tokens from others
 * @param _expiryTimes An array of the moment till investors KYC will be validated. After that investor need to do re-KYC
 * @param _canBuyFromSTO An array of boolean values
 */
function modifyWhitelistMulti(
        address[] _investors,
        uint256[] _fromTimes,
        uint256[] _toTimes,
        uint256[] _expiryTimes,
        bool[] _canBuyFromSTO
    ) public withPerm(WHITELIST) {
        require(_investors.length == _fromTimes.length, "Mismatched input lengths");
        require(_fromTimes.length == _toTimes.length, "Mismatched input lengths");
        require(_toTimes.length == _expiryTimes.length, "Mismatched input lengths");
        require(_canBuyFromSTO.length == _toTimes.length, "Mismatched input length");
        for (uint256 i = 0; i < _investors.length; i++) {
            modifyWhitelist(_investors[i], _fromTimes[i], _toTimes[i], _expiryTimes[i], _canBuyFromSTO[i]);
        }
    }