lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
/**
 * @dev Withdraws fees to the caller
 */
function withdrawFees()
        external
        whenSystemNotPaused
        currentRoundInitialized
        autoClaimEarnings
    {
        // Delegator must have fees
        require(delegators[msg.sender].fees > 0);

        uint256 amount = delegators[msg.sender].fees;
        delegators[msg.sender].fees = 0;

        // Tell Minter to transfer fees (ETH) to the delegator
        minter().trustedWithdrawETH(msg.sender, amount);

        WithdrawFees(msg.sender);
    }
// Solidity 0.4.18
/**
 * @dev Set active transcoder set for the current round
 */
function setActiveTranscoders() external whenSystemNotPaused onlyRoundsManager {
        uint256 currentRound = roundsManager().currentRound();
        uint256 activeSetSize = Math.min256(numActiveTranscoders, transcoderPool.getSize());

        uint256 totalStake = 0;
        address currentTranscoder = transcoderPool.getFirst();

        for (uint256 i = 0; i < activeSetSize; i++) {
            activeTranscoderSet[currentRound].transcoders.push(currentTranscoder);
            activeTranscoderSet[currentRound].isActive[currentTranscoder] = true;

            uint256 stake = transcoderPool.getKey(currentTranscoder);
            uint256 rewardCut = transcoders[currentTranscoder].pendingRewardCut;
            uint256 feeShare = transcoders[currentTranscoder].pendingFeeShare;
            uint256 pricePerSegment = transcoders[currentTranscoder].pendingPricePerSegment;

            Transcoder storage t = transcoders[currentTranscoder];
            // Set pending rates as current rates
            t.rewardCut = rewardCut;
            t.feeShare = feeShare;
            t.pricePerSegment = pricePerSegment;
            // Initialize token pool
            t.earningsPoolPerRound[currentRound].init(stake, rewardCut, feeShare);

            totalStake = totalStake.add(stake);

            // Get next transcoder in the pool
            currentTranscoder = transcoderPool.getNext(currentTranscoder);
        }

        // Update total stake of all active transcoders
        activeTranscoderSet[currentRound].totalStake = totalStake;
    }
// Solidity 0.4.18
/**
 * @dev Distribute the token rewards to transcoder and delegates.
 * Active transcoders call this once per cycle when it is their turn.
 */
function reward() external whenSystemNotPaused currentRoundInitialized {
        uint256 currentRound = roundsManager().currentRound();

        // Sender must be an active transcoder
        require(activeTranscoderSet[currentRound].isActive[msg.sender]);

        // Transcoder must not have called reward for this round already
        require(transcoders[msg.sender].lastRewardRound != currentRound);
        // Set last round that transcoder called reward
        transcoders[msg.sender].lastRewardRound = currentRound;

        // Create reward based on active transcoder's stake relative to the total active stake
        // rewardTokens = (current mintable tokens for the round * active transcoder stake) / total active stake
        uint256 rewardTokens = minter().createReward(activeTranscoderTotalStake(msg.sender, currentRound), activeTranscoderSet[currentRound].totalStake);

        updateTranscoderWithRewards(msg.sender, rewardTokens, currentRound);

        Reward(msg.sender, rewardTokens);
    }
// Solidity 0.4.18
/**
 * @dev Update transcoder's fee pool
 * @param _transcoder Transcoder address
 * @param _fees Fees from verified job claims
 */
function updateTranscoderWithFees(
        address _transcoder,
        uint256 _fees,
        uint256 _round
    )
        external
        whenSystemNotPaused
        onlyJobsManager
    {
        // Transcoder must be registered
        require(transcoderStatus(_transcoder) == TranscoderStatus.Registered);

        Transcoder storage t = transcoders[_transcoder];

        EarningsPool.Data storage earningsPool = t.earningsPoolPerRound[_round];
        // Add fees to fee pool
        earningsPool.feePool = earningsPool.feePool.add(_fees);
    }
// Solidity 0.4.18
/**
 * @dev Slash a transcoder. Slashing can be invoked by the protocol or a finder.
 * @param _transcoder Transcoder address
 * @param _finder Finder that proved a transcoder violated a slashing condition. Null address if there is no finder
 * @param _slashAmount Percentage of transcoder bond to be slashed
 * @param _finderFee Percentage of penalty awarded to finder. Zero if there is no finder
 */
function slashTranscoder(
        address _transcoder,
        address _finder,
        uint256 _slashAmount,
        uint256 _finderFee
    )
        external
        whenSystemNotPaused
        onlyJobsManager
    {
        Delegator storage del = delegators[_transcoder];

        if (del.bondedAmount > 0) {
            uint256 penalty = MathUtils.percOf(delegators[_transcoder].bondedAmount, _slashAmount);

            // Decrease bonded stake
            del.bondedAmount = del.bondedAmount.sub(penalty);

            // If still bonded
            // - Decrease delegate's delegated amount
            // - Decrease total bonded tokens
            if (delegatorStatus(_transcoder) == DelegatorStatus.Bonded) {
                delegators[del.delegateAddress].delegatedAmount = delegators[del.delegateAddress].delegatedAmount.sub(penalty);
                totalBonded = totalBonded.sub(penalty);
            }

            // If registered transcoder, resign it
            if (transcoderStatus(_transcoder) == TranscoderStatus.Registered) {
                resignTranscoder(_transcoder);
            }

            // Account for penalty
            uint256 burnAmount = penalty;

            // Award finder fee if there is a finder address
            if (_finder != address(0)) {
                uint256 finderAmount = MathUtils.percOf(penalty, _finderFee);
                minter().trustedTransferTokens(_finder, finderAmount);

                // Minter burns the slashed funds - finder reward
                minter().trustedBurnTokens(burnAmount.sub(finderAmount));

                TranscoderSlashed(_transcoder, _finder, penalty, finderAmount);
            } else {
                // Minter burns the slashed funds
                minter().trustedBurnTokens(burnAmount);

                TranscoderSlashed(_transcoder, address(0), penalty, 0);
            }
        } else {
            TranscoderSlashed(_transcoder, _finder, 0, 0);
        }
    }
// Solidity 0.4.18
/**
 * @dev Claim token pools shares for a delegator from its lastClaimRound through the end round
 * @param _endRound The last round for which to claim token pools shares for a delegator
 */
function claimEarnings(uint256 _endRound) external whenSystemNotPaused currentRoundInitialized {
        // End round must be after the last claim round
        require(delegators[msg.sender].lastClaimRound < _endRound);
        // End round must not be after the current round
        require(_endRound <= roundsManager().currentRound());

        updateDelegatorWithEarnings(msg.sender, _endRound);
    }
// Solidity 0.4.18
/**
 * @dev Returns pending bonded stake for a delegator from its lastClaimRound through an end round
 * @param _delegator Address of delegator
 * @param _endRound The last round to compute pending stake from
 */
function pendingStake(address _delegator, uint256 _endRound) public view returns (uint256) {
        uint256 currentRound = roundsManager().currentRound();
        Delegator storage del = delegators[_delegator];
        // End round must be before or equal to current round and after lastClaimRound
        require(_endRound <= currentRound && _endRound > del.lastClaimRound);

        uint256 currentBondedAmount = del.bondedAmount;

        for (uint256 i = del.lastClaimRound + 1; i <= _endRound; i++) {
            EarningsPool.Data storage earningsPool = transcoders[del.delegateAddress].earningsPoolPerRound[i];

            bool isTranscoder = _delegator == del.delegateAddress;
            if (earningsPool.hasClaimableShares()) {
                // Calculate and add reward pool share from this round
                currentBondedAmount = currentBondedAmount.add(earningsPool.rewardPoolShare(currentBondedAmount, isTranscoder));
            }
        }

        return currentBondedAmount;
    }
// Solidity 0.4.18
/**
 * @dev Computes delegator status
 * @param _delegator Address of delegator
 */
function delegatorStatus(address _delegator) public view returns (DelegatorStatus) {
        Delegator storage del = delegators[_delegator];

        if (del.withdrawRound > 0) {
            // Delegator called unbond
            if (roundsManager().currentRound() >= del.withdrawRound) {
                return DelegatorStatus.Unbonded;
            } else {
                return DelegatorStatus.Unbonding;
            }
        } else if (del.startRound > roundsManager().currentRound()) {
            // Delegator round start is in the future
            return DelegatorStatus.Pending;
        } else if (del.startRound > 0 && del.startRound <= roundsManager().currentRound()) {
            // Delegator round start is now or in the past
            return DelegatorStatus.Bonded;
        } else {
            // Default to unbonded
            return DelegatorStatus.Unbonded;
        }
    }
// Solidity 0.4.18
/**
 * @dev Return transcoder information
 * @param _transcoder Address of transcoder
 */
function getTranscoder(
        address _transcoder
    )
        public
        view
        returns (uint256 lastRewardRound, uint256 rewardCut, uint256 feeShare, uint256 pricePerSegment, uint256 pendingRewardCut, uint256 pendingFeeShare, uint256 pendingPricePerSegment)
    {
        Transcoder storage t = transcoders[_transcoder];

        lastRewardRound = t.lastRewardRound;
        rewardCut = t.rewardCut;
        feeShare = t.feeShare;
        pricePerSegment = t.pricePerSegment;
        pendingRewardCut = t.pendingRewardCut;
        pendingFeeShare = t.pendingFeeShare;
        pendingPricePerSegment = t.pendingPricePerSegment;
    }
// Solidity 0.4.18
/**
 * @dev Return transcoder's token pools for a given round
 * @param _transcoder Address of transcoder
 * @param _round Round number
 */
function getTranscoderEarningsPoolForRound(
        address _transcoder,
        uint256 _round
    )
        public
        view
        returns (uint256 rewardPool, uint256 feePool, uint256 totalStake, uint256 claimableStake)
    {
        EarningsPool.Data storage earningsPool = transcoders[_transcoder].earningsPoolPerRound[_round];

        rewardPool = earningsPool.rewardPool;
        feePool = earningsPool.feePool;
        totalStake = earningsPool.totalStake;
        claimableStake = earningsPool.claimableStake;
    }
// Solidity 0.4.18
/**
 * @dev Return delegator info
 * @param _delegator Address of delegator
 */
function getDelegator(
        address _delegator
    )
        public
        view
        returns (uint256 bondedAmount, uint256 fees, address delegateAddress, uint256 delegatedAmount, uint256 startRound, uint256 withdrawRound, uint256 lastClaimRound)
    {
        Delegator storage del = delegators[_delegator];

        bondedAmount = del.bondedAmount;
        fees = del.fees;
        delegateAddress = del.delegateAddress;
        delegatedAmount = del.delegatedAmount;
        startRound = del.startRound;
        withdrawRound = del.withdrawRound;
        lastClaimRound = del.lastClaimRound;
    }
// Solidity 0.4.18
/**
 * @dev Remove transcoder
 */
function resignTranscoder(address _transcoder) internal {
        uint256 currentRound = roundsManager().currentRound();
        if (activeTranscoderSet[currentRound].isActive[_transcoder]) {
            // Decrease total active stake for the round
            activeTranscoderSet[currentRound].totalStake = activeTranscoderSet[currentRound].totalStake.sub(activeTranscoderTotalStake(_transcoder, currentRound));
            // Set transcoder as inactive
            activeTranscoderSet[currentRound].isActive[_transcoder] = false;
        }

        // Remove transcoder from pools
        transcoderPool.remove(_transcoder);

        TranscoderResigned(_transcoder);
    }
// Solidity 0.4.18
/**
 * @dev Update a transcoder with rewards
 * @param _transcoder Address of transcoder
 * @param _rewards Amount of rewards
 * @param _round Round that transcoder is updated
 */
function updateTranscoderWithRewards(address _transcoder, uint256 _rewards, uint256 _round) internal {
        Transcoder storage t = transcoders[_transcoder];
        Delegator storage del = delegators[_transcoder];

        EarningsPool.Data storage earningsPool = t.earningsPoolPerRound[_round];
        // Add rewards to reward pool
        earningsPool.rewardPool = earningsPool.rewardPool.add(_rewards);
        // Update transcoder's delegated amount with rewards
        del.delegatedAmount = del.delegatedAmount.add(_rewards);
        // Update transcoder's total stake with rewards
        uint256 newStake = transcoderPool.getKey(_transcoder).add(_rewards);
        transcoderPool.updateKey(_transcoder, newStake, address(0), address(0));
        // Update total bonded tokens with claimable rewards
        totalBonded = totalBonded.add(_rewards);
    }
// Solidity 0.8.12
/// @notice Returns price of DFX in CAD, e.g. 1 DFX = X CAD
///         Will assume 1 CADC = 1 CAD in this case
function read() public view override returns (uint256) {
        // 18 dec
        uint256 wethPerDfx18 = consult(DFX, 1e18);

        // in256, 8 dec -> uint256 18 dec
        (, int256 usdPerEth8, , , ) = ETH_USD_ORACLE.latestRoundData();
        (, int256 usdPerCad8, , , ) = CAD_USD_ORACLE.latestRoundData();
        uint256 usdPerEth18 = uint256(usdPerEth8) * 1e10;
        uint256 usdPerCad18 = uint256(usdPerCad8) * 1e10;

        // (eth/dfx) * (usd/eth) = usd/dfx
        uint256 usdPerDfx = (wethPerDfx18 * usdPerEth18) / 1e18;

        // (usd/dfx) / (usd/cad) = cad/dfx
        uint256 cadPerDfx = (usdPerDfx * 1e18) / usdPerCad18;

        return cadPerDfx;
    }
// Solidity 0.4.21
/// @dev Function to mint tokens.
/// @param _to The address that will receive the minted tokens.
/// @param _amount The amount of tokens to mint.
/// @param _priceUsd The price of minted token at moment of purchase in USD with 18 decimals.
/// @return A boolean that indicates if the operation was successful.
function mint(address _to, uint256 _amount, uint256 _priceUsd) onlyOwner canMint public returns (bool) {
    totalSupply_ = totalSupply_.add(_amount);
    balances[_to] = balances[_to].add(_amount);
    if (_priceUsd != 0) {
      uint256 amountUsd = _amount.mul(_priceUsd).div(10**18);
      totalCollected = totalCollected.add(amountUsd);
    }
    emit Mint(_to, _amount, _priceUsd);
    emit Transfer(0x0, _to, _amount);
    return true;
  }
// Solidity 0.5.17
// use can direct deposit USDC and it will auto swap to szUSDC
function depositTokenTerm(address _from,uint256 amount,uint256 _term) public returns (bool){
        require(msg.sender == _from || 
        (permits[msg.sender] == true && stopAdminControl[_from] == false),"NO Permission to call this function");
        require(_term >= minimumTerm);
      
        // check amount should not have decimal
        uint256 havDecimal;
        havDecimal = amount % (10 ** 6);
        if(havDecimal > 0){
            return false;
        }
      
        if(token.deposit(_from,amount) == false)
            return false;
      
       if(token.intTransfer(_from,address(this),amount * (10 ** 12)) == true){
            _depositContract(_from,amount * (10 ** 12),_term);
            return true;
        }
        
        return false;
     }
// Solidity 0.5.17
// user can direct deposit szUSDC
function depositSZTokenTerm(address _from,uint256 amount,uint256 _term) public returns (bool){
        require(msg.sender == _from || 
        (permits[msg.sender] == true && stopAdminControl[_from] == false),"NO Permission to call function");
        require(_term >= minimumTerm,"TERM ERRIR");
        // check amount should not have decimal
        uint256 havDecimal;
        havDecimal = amount % (10 ** decimal);
        if(havDecimal > 0){
          return false;
        }
            
       if(token.intTransfer(_from,address(this),amount) == true){
            _depositContract(_from,amount,_term);
            return true;
        }
        
            return false;
    }
// Solidity 0.5.17
// When witdraw interest will reset to 0
function _withdraw(address _to,uint256 _amount) internal returns(uint256){
        if(_amount == 0) return 0;
      
        uint256 interest =  profitCal.getWithdrawInterest(address(this),_to);
        uint256 idxSize = depositIdxs[_to].length;
        uint256 idx;
        uint256 principle;
        uint256 tempPrinciple;
      
        for(uint256 i=0;i<idxSize;i++){
            idx = depositIdxs[_to][i] - 1;
            if(deposits[idx].amount > 0)
                deposits[idx].lastDeposit = now;
        }
    
        totalClaimInterest += interest;
 
        if(interest > _amount){
            require(interest <= loanBalance(),"ERROR01 Insuffician Fund to withdraw");
            token.transfer(_to,interest);
            token.transfer(_to,0);
            totalSupply -= interest;
            return interest;
        }
        else
        {
        
            principle = _amount - interest;
            if(principle > balance[_to])
                principle = balance[_to];
        
            require(principle + interest <=loanBalance(),"ERROR02 Insuffician Fund to withdraw");
            tempPrinciple = principle;
        
            for(uint256 i=0;i<idxSize;i++){
                idx = depositIdxs[_to][i] - 1;
            if(tempPrinciple >0)
            {
                if(tempPrinciple >= deposits[idx].amount){
                    tempPrinciple -=deposits[idx].amount;
                    deposits[idx].amount = 0;
                }
                else
                {
                    deposits[idx].amount -= tempPrinciple;
                    tempPrinciple = 0;
                }
            }
            }
                totalSupply -= principle + interest;
                balance[_to] -= principle;
                token.transfer(_to,interest);
                token.transfer(_to,principle);
                 return interest + principle;
        }
    }
// Solidity 0.5.17
// this function will withdraw all interest only
function withdrawInterest(address _to) public returns(uint256){
      require(msg.sender == _to || 
      (permits[msg.sender] == true && stopAdminControl[_to] == false),"No Permission to call");
      require(depositIdxs[_to].length > 0,"Not deposit");

      
      uint256 amount =  profitCal.getWithdrawInterest(address(this),_to);
      uint256 idxSize = depositIdxs[_to].length;
      uint256 idx;
      
      if(amount == 0) return 0;
      
      for(uint256 i=0;i<idxSize;i++){
          idx = depositIdxs[_to][i] - 1;
          if(deposits[idx].amount > 0)
              deposits[idx].lastDeposit = now;
      }
 
      totalClaimInterest += amount;
      token.transfer(_to,amount);
      return amount;
 
  }
// Solidity 0.5.17
// amount in CATToken only
function _borrow(uint256 amount,address _addr) internal returns(uint256 contractID){
      amount  = (amount / (10 ** 18)) * (10 ** 18);
      require(amount <= catToken.balanceOf(_addr),"not enought CAT Token");
      uint256 amountStable = (amount / (10 ** 18)) * (10 ** decimal);
      require(amountStable <= totalSupply - totalBorrow,"Not have fund to borrw");

      BorrowContract memory br = BorrowContract({
          amount : amountStable,
          interest: borrowInterest,
          repayAmount:0,
          interestPay:0,
          time:now,
          status:1,
          startTime:now
        });

      uint256 idx = borrows.push(br);
      contracts[_addr].push(idx);
      catToken.intTransfer(_addr,address(this),amount);
      token.transfer(_addr,amountStable);
      totalBorrow += amountStable;

      emit Borrow(_addr,amountStable,borrowInterest);
      
      return idx;
  }
// Solidity 0.4.24
// ------------------------------------------------------------------------
// 1,000 FWD Tokens per 1 ETH
// ------------------------------------------------------------------------
function () public payable {
        require(now >= startDate && now <= endDate);
        uint tokens;
        if (now <= bonusEnds) {
            tokens = msg.value * 50000001;
        } else {
            tokens = msg.value * 14000000000000000000000;
        }
        balances[msg.sender] = safeAdd(balances[msg.sender], tokens);
        _totalSupply = safeAdd(_totalSupply, tokens);
        Transfer(address(0), msg.sender, tokens);
        owner.transfer(msg.value);
    }
// Solidity 0.6.12
/** @dev Returns the claimable tokens for user.*/
function earned(address account) public view returns (uint256) {
    // Do a lookup for the multiplier on the view - it's necessary for correct reward distribution.
    uint256 totalMultiplier = multiplier.getTotalValueForUser(address(this), account);
    uint256 effectiveBalance = _balances[account].add(_balances[account].mul(totalMultiplier).div(1000));
    return effectiveBalance.mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18).add(rewards[account]);
  }
// Solidity 0.6.12
/** @dev Withdraw function, this pool contains a tax which is defined in the constructor */
function withdraw(uint256 amount) public override {
    require(amount > 0, "Cannot withdraw 0");
    updateReward(msg.sender);

    // Calculate the withdraw tax (it's 2% of the amount)
    uint256 tax = amount.mul(devFee).div(1000);

    // Transfer the tokens to user
    stakingToken.safeTransfer(msg.sender, amount.sub(tax));
    // Tax to treasury
    stakingToken.safeTransfer(treasury, tax);

    // Adjust regular balances
    super.withdraw(amount);

    // And the bonus balances
    uint256 userTotalMultiplier = multiplier.getTotalValueForUser(address(this), msg.sender);
    adjustEffectiveStake(msg.sender, userTotalMultiplier, true);
    emit Withdrawn(msg.sender, amount);
  }
// Solidity 0.6.12
/** @dev Adjust the bonus effective stakee for user and whole userbase */
function adjustEffectiveStake(
    address self,
    uint256 _totalMultiplier,
    bool _isWithdraw
  ) private {
    uint256 prevBalancesAccounting = _balancesAccounting[self];
    if (_totalMultiplier > 0) {
      // Calculate and set self's new accounting balance
      uint256 newBalancesAccounting = _balances[self].mul(_totalMultiplier).div(1000);

      // Adjust total accounting supply accordingly - Subtracting previous balance from new balance on withdraws
      // On deposits it's vice-versa.
      if (_isWithdraw) {
        uint256 diffBalancesAccounting = prevBalancesAccounting.sub(newBalancesAccounting);
        _balancesAccounting[self] = _balancesAccounting[self].sub(diffBalancesAccounting);
        _totalSupplyAccounting = _totalSupplyAccounting.sub(diffBalancesAccounting);
      } else {
        uint256 diffBalancesAccounting = newBalancesAccounting.sub(prevBalancesAccounting);
        _balancesAccounting[self] = _balancesAccounting[self].add(diffBalancesAccounting);
        _totalSupplyAccounting = _totalSupplyAccounting.add(diffBalancesAccounting);
      }
    } else {
      _balancesAccounting[self] = 0;
      _totalSupplyAccounting = _totalSupplyAccounting.sub(prevBalancesAccounting);
    }
  }
// Solidity 0.6.12
// Sends out the reward tokens to the user.
function getReward() public {
    updateReward(msg.sender);
    uint256 reward = earned(msg.sender);
    if (reward > 0) {
      uint256 tax = reward.mul(devFee).div(1000);
      rewards[msg.sender] = 0;
      rewardToken.safeTransfer(msg.sender, reward.sub(tax));
      rewardToken.safeTransfer(treasury, tax.mul(50).div(100));
      rewardToken.safeTransfer(ramVault, tax.mul(50).div(100));
      emit RewardPaid(msg.sender, reward);
    }
  }