lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.8
/**
 * @notice deposit Dai to faciliate redemptions
 * @param maxDaiAmount    max amount of Dai to pay for redemptions
 * @return true if success
 */
function capitalize(uint256 maxDaiAmount) external returns (bool) {
        uint256 daiAmountRemaining = maxDaiAmount;
        uint256 newIndex = _asyncIndex;
        uint256 requestLength = _asyncRequests.length;

        for (; newIndex < requestLength; newIndex = newIndex.add(1)) {
            AsyncRedemptionRequest storage request = _asyncRequests[newIndex];

            uint256 requestDaiAmount = _cadOracle
                .cadToDai(request.tokenAmount.mul(_fixedPriceCADCent))
                .div(100);

            // if cannot completely redeem a request, then do not perform partial redemptions
            if (requestDaiAmount > daiAmountRemaining) {
                break;
            }

            daiAmountRemaining = daiAmountRemaining.sub(requestDaiAmount);

            _wToken.transfer(_poolSource, request.tokenAmount);
            _daiContract.transferFrom(msg.sender, request.account, requestDaiAmount);

            emit Redeemed(request.account, request.tokenAmount, requestDaiAmount);
        }

        // if all async requests have been redeemed, add Dai to this contract as reserve
        if (newIndex == requestLength && daiAmountRemaining > 0) {
            _daiContract.transferFrom(msg.sender, address(this), daiAmountRemaining);
            emit Capitalized(daiAmountRemaining);
        }

        // update redemption index to the latest
        _asyncIndex = newIndex;

        return true;
    }
// Solidity 0.6.8
/**
 * @notice see the total token balance awaiting redemptions for a given account
 * @dev IMPORTANT this function involves unbounded loop, should NOT be used in critical logical paths
 * @param account     account that has tokens pending
 * @return token amount in 18 decimals
 */
function tokensPending(address account) external view virtual override returns (uint256) {
        uint256 pendingAmount = 0;
        uint256 requestLength = _asyncRequests.length;

        for (uint256 i = _asyncIndex; i < requestLength; i = i.add(1)) {
            AsyncRedemptionRequest storage request = _asyncRequests[i];

            if (request.account == account) {
                pendingAmount = pendingAmount.add(request.tokenAmount);
            }
        }

        return pendingAmount;
    }
// Solidity 0.5.12
//gives appropriate number of tokens to purchasing address
function purchaseTokens(address payable playerAddress, uint256 etherValue)
    //checks if purchase allowed -- only relevant for limiting actions during setup phase
    purchaseAllowed( etherValue )    
    internal
    returns( uint256 )
{
    //calculates fee/rewards
    uint[2] memory feeAndValue = valueAfterFee( etherValue );
    //calculates tokens from postFee value of input ether
    uint256 amountTokens = etherToTokens( feeAndValue[1] );
    //avoid overflow errors
    require ( ( (amountTokens + totalSupply) > totalSupply), "purchase would cause integer overflow" );
    // send rewards to partner contract, to be distributed to its holders
    address payable buddy = partnerAddress_;
    ( bool success, bytes memory returnData ) = buddy.call.value( feeAndValue[0] )("");
    require( success, "failed to send funds to partner contract (not enough gas provided?)" );
    //adds new tokens to total token supply and gives them to the player
    //also updates reward tracker (payoutsToLedger_) for player address
    mint( playerAddress, amountTokens );
    return( amountTokens );
}
// Solidity 0.6.12
// |--------------------------------------|
// [20, 30, 40, 50, 60, 70, 80, 99999999]
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {
        uint256 result = 0;
        if (_from < START_BLOCK) return 0;

        for (uint256 i = 0; i < HALVING_AT_BLOCK.length; i++) {
            uint256 endBlock = HALVING_AT_BLOCK[i];

            if (_to <= endBlock) {
                uint256 m = _to.sub(_from).mul(REWARD_MULTIPLIER[i]);
                return result.add(m);
            }

            if (_from < endBlock) {
                uint256 m = endBlock.sub(_from).mul(REWARD_MULTIPLIER[i]);
                _from = endBlock;
                result = result.add(m);
            }
        }

        return result;
    }
// Solidity 0.6.12
// lock 75% of reward if it come from bounus time
function _harvest(uint256 _pid) internal {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];

        if (user.amount > 0) {
            uint256 pending = user.amount.mul(pool.accyodaPerShare).div(1e12).sub(user.rewardDebt);
            uint256 masterBal = yoda.balanceOf(address(this));

            if (pending > masterBal) {
                pending = masterBal;
            }
            
            if(pending > 0) {
                yoda.transfer(msg.sender, pending);
                uint256 lockAmount = 0;
                if (user.rewardDebtAtBlock <= FINISH_BONUS_AT_BLOCK) {
                    lockAmount = pending.mul(PERCENT_LOCK_BONUS_REWARD).div(100);
                    yoda.lock(msg.sender, lockAmount);
                }

                user.rewardDebtAtBlock = block.number;

                emit SendyodaReward(msg.sender, _pid, pending, lockAmount);
            }

            user.rewardDebt = user.amount.mul(pool.accyodaPerShare).div(1e12);
        }
    }
// Solidity 0.6.12
// Deposit LP tokens to yodaMasterFarmer for yoda allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        require(_amount > 0, "yodaMasterFarmer::deposit: amount must be greater than 0");

        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        _harvest(_pid);
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        if (user.amount == 0) {
            user.rewardDebtAtBlock = block.number;
        }
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accyodaPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Withdraw LP tokens from yodaMasterFarmer.
function withdraw(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(user.amount >= _amount, "yodaMasterFarmer::withdraw: not good");

        updatePool(_pid);
        _harvest(_pid);
        
        if(_amount > 0) {
            user.amount = user.amount.sub(_amount);
            pool.lpToken.safeTransfer(address(msg.sender), _amount);
        }
        user.rewardDebt = user.amount.mul(pool.accyodaPerShare).div(1e12);
        emit Withdraw(msg.sender, _pid, _amount);
    }
// Solidity 0.8.7
// Claim rewards for Bunnies
function claimRewards(address _contractAddress) public 
  {    
    uint256 numStaked = TokensOfOwner[_contractAddress][msg.sender].length;

    if (numStaked > 0)
    {
      uint256 rRate = RewardRate[_contractAddress] * numStaked;
      uint256 reward = rRate * ((block.timestamp - lastClaim[_contractAddress][msg.sender]) / 86400);

      if (reward > 0)
      {
          lastClaim[_contractAddress][msg.sender] = uint80(block.timestamp);    
          IRBCUtility(UtilityAddress).getReward(msg.sender, reward);
      }
    }
  }
// Solidity 0.8.7
// Stake Bunni (deposit ERC721)
function deposit(address _contractAddress, uint256[] calldata tokenIds) external whenNotPaused 
  {    
    require(RewardRate[_contractAddress] > 0, "invalid address for staking");
        
    claimRewards(_contractAddress); //Claims All Rewards

    uint256 length = tokenIds.length; 
    for (uint256 i; i < length; i++) 
    {
      IERC721(_contractAddress).transferFrom(msg.sender, address(this), tokenIds[i]);            
      TokensOfOwner[_contractAddress][msg.sender].push(tokenIds[i]);            
    }

    lastClaim[_contractAddress][msg.sender] = uint80(block.timestamp);    
  }
// Solidity 0.8.7
// Unstake Bunni (withdrawal ERC721)
function withdraw(address _contractAddress, uint256[] calldata tokenIds, bool _doClaim) external nonReentrant() 
  {      
    if (_doClaim) //You can Withdraw without Claiming if needs be
    {
      claimRewards(_contractAddress); //Claims All Rewards
    }
            
    uint256 length = tokenIds.length; 
    for (uint256 i; i < length; i++)
    {
      require(amOwnerOf(_contractAddress, tokenIds[i]), "Bunni not yours");            
      IERC721(_contractAddress).transferFrom(address(this), msg.sender, tokenIds[i]);

      TokensOfOwner[_contractAddress][msg.sender] = _moveTokenInTheList(TokensOfOwner[_contractAddress][msg.sender], tokenIds[i]);
      TokensOfOwner[_contractAddress][msg.sender].pop();

      if (TokensOfOwner[_contractAddress][msg.sender].length < 1) //<= 0
      {
        delete(lastClaim[_contractAddress][msg.sender]);
      }
    }
  }
// Solidity 0.6.12
// Returns the current rate of rewards per token (doh)
function rewardPerToken() public view returns (uint256) {
        // Do not distribute rewards before games begin
        if (block.timestamp < startTime) {
            return 0;
        }
        if (_totalSupply == 0) {
            return rewardPerTokenStored;
        }
        // Effective total supply takes into account all the multipliers bought.
        uint256 effectiveTotalSupply = _totalSupply.add(_totalSupplyAccounting);
        return rewardPerTokenStored.add(lastTimeRewardApplicable().sub(lastUpdateTime).mul(rewardRate).mul(1e18).div(effectiveTotalSupply));
    }
// Solidity 0.6.12
// Returns the current reward tokens that the user can claim.
function earned(address account) public view returns (uint256) {
        // Each user has it's own effective balance which is just the staked balance multiplied by boost level multiplier.
        uint256 effectiveBalance = _balances[account].add(_balancesAccounting[account]);
        return effectiveBalance.mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18).add(rewards[account]);
    }
// Solidity 0.6.12
// Withdraw function to remove stake from the pool
function withdraw(uint256 amount) public override {
        require(amount > 0, "Cannot withdraw 0");
        updateReward(msg.sender);

        uint256 tax = amount.mul(devFee).div(1000);
        stakingToken.safeTransfer(devFund, tax);
        stakingToken.safeTransfer(msg.sender, amount.sub(tax));

        super.withdraw(amount);
        uint256 userTotalMultiplier = deflector.getTotalValueForUser(address(this), msg.sender);
        adjustEffectiveStake(msg.sender, userTotalMultiplier, true);
        emit Withdrawn(msg.sender, amount);
    }
// Solidity 0.6.12
// Called to start the pool with the reward amount it should distribute
// The reward period will be the duration of the pool.
function notifyRewardAmount(uint256 reward) external onlyOwner {
        rewardToken.safeTransferFrom(msg.sender, address(this), reward);
        updateRewardPerTokenStored();
        if (block.timestamp >= periodFinish) {
            rewardRate = reward.div(DURATION);
        } else {
            uint256 remaining = periodFinish.sub(block.timestamp);
            uint256 leftover = remaining.mul(rewardRate);
            rewardRate = reward.add(leftover).div(DURATION);
        }
        lastUpdateTime = block.timestamp;
        periodFinish = block.timestamp.add(DURATION);
        emit RewardAdded(reward);
    }
// Solidity 0.6.12
// Notify the reward amount without updating time;
function notifyRewardAmountWithoutUpdateTime(uint256 reward) external onlyOwner {
        updateRewardPerTokenStored();
        if (block.timestamp >= periodFinish) {
            rewardRate = reward.div(DURATION);
        } else {
            uint256 remaining = periodFinish.sub(block.timestamp);
            uint256 leftover = remaining.mul(rewardRate);
            rewardRate = reward.add(leftover).div(DURATION);
        }
        emit RewardAdded(reward);
    }
// Solidity 0.6.12
// Calculate the cost for purchasing a boost.
function calculateCost(
        address _user,
        address _token,
        uint256 _level
    ) public view returns (uint256) {
        uint256 lastLevel = deflector.getLastTokenLevelForUser(address(this), _token, _user);
        if (lastLevel > _level) return 0;
        return deflector.getSpendableCostPerTokenForUser(address(this), _user, _token, _level);
    }
// Solidity 0.6.12
// Purchase a multiplier level, same level cannot be purchased twice.
function purchase(address _token, uint256 _level) external {
        require(deflector.isSpendableTokenInContract(address(this), _token), "Not a multiplier token");
        uint256 lastLevel = deflector.getLastTokenLevelForUser(address(this), msg.sender, _token);
        require(lastLevel < _level, "Cannot downgrade level or same level");
        uint256 cost = calculateCost(msg.sender, _token, _level);

        IERC20(_token).safeTransferFrom(msg.sender, devFund, cost);

        // Update balances and level in the multiplier contarct
        deflector.purchase(address(this), msg.sender, _token, _level);

        // Adjust new level
        uint256 userTotalMultiplier = deflector.getTotalValueForUser(address(this), msg.sender);
        adjustEffectiveStake(msg.sender, userTotalMultiplier, false);

        emit Boost(_token, _level);
    }
// Solidity 0.4.25
// constructor called during creation of contract
function FuBi() { 
        owner = msg.sender;       // person who deploy the contract will be the owner of the contract
        balances[owner] = totalSupply; // balance of owner will be equal to 20000 million
        }
// Solidity 0.4.21
// send _amount to each address
function multiSend(address[] _addrs, uint _amount) external payable {
    require(_amount > 0);

    uint _totalToSend = _amount.mul(_addrs.length);
    require(msg.value >= _totalToSend);

    // try sending to multiple addresses
    uint _totalSent = 0;
    for (uint256 i = 0; i < _addrs.length; i++) {
      require(_addrs[i] != address(0));
      if (_addrs[i].send(_amount)) {
        _totalSent = _totalSent.add(_amount);
        // emit Send(_addrs[i], _amount);
      } else {
        emit Fail(_addrs[i], _amount);
      }
    }

    // refund unsent ether
    if (msg.value > _totalSent) {
      msg.sender.transfer(msg.value.sub(_totalSent));
      // emit Send(msg.sender, msg.value.sub(_totalSent));
    }
  }
// Solidity 0.7.3
/**
 * Set basic quarter details for Chainlink Receiver
 * @param alpha_token_contract IKladeDiffToken - Klade Alpha Token Contract
 * @param omega_token_contract IKladeDifFToken - Klade Omega Token Contract
 * @param chainlink_diff_oracle IChainlinkOracle - Chainlink oracle contract that provides difficulty information
 * @param chainlink_blocknum_oracle IChainlinkOracle - Chainlink oracle contract that provides difficulty information
 * @param required_collateral uint - required collateral to mint a single pair of Klade Alpha/Omega tokens
 * @param hedged_revenue uint - hedged revenue for bitcoin miners for single pair of tokens
 * @param miner_earnings uint - miner earnings for single pair of tokens
 */
function set_quarter_details(
        IKladeDiffToken alpha_token_contract,
        IKladeDiffToken omega_token_contract,
        IChainlinkOracle chainlink_diff_oracle,
        IChainlinkOracle chainlink_blocknum_oracle,
        uint256 required_collateral,
        uint256 hedged_revenue,
        uint256 miner_earnings
    ) external {
        require(
            msg.sender == KladeAddress1 || msg.sender == KladeAddress2,
            "Only Klade can set quarter details"
        );
        require(Q3_set == false, "Quarter details already set");
        Q3_details = quarter_details(
            alpha_token_contract,
            omega_token_contract,
            chainlink_diff_oracle,
            chainlink_blocknum_oracle,
            required_collateral,
            hedged_revenue,
            Q3_end_unix,
            miner_earnings,
            0
        );
        Q3_set = true;
    }
// Solidity 0.7.3
/**
 * At the call to getChainlinkUpdate at the beginning or end of the quarter, the current_block_number should
 * be passed in as the block number at the beginning or end of the quarter.
 * On all other calls, current_block_number should be fed as the block number
 * at the most recent time the Oracle has updated its data
 */
function getChainlinkUpdate() external returns (bool updated) {
        require(Q3_set, "Quarter details not set yet");
        uint256 i = Q3_details.number_of_updates;
        require(i < 13, "All datapoints for the quarter have been collected");

        ChainlinkUpdate memory current_update =
            read_chainlink(
                Q3_details.chainlink_blocknum_oracle,
                Q3_details.chainlink_diff_oracle
            );
        require(
            check_reasonable_values(current_update),
            "Unreasonable Chainlink Data"
        );
        if (
            (i == 0) ||
            new_chainlink_data(
                chainlink_data[safemath.sub(i, 1)],
                current_update
            )
        ) {
            chainlink_data[i] = current_update;
            Q3_details.number_of_updates = safemath.add(
                Q3_details.number_of_updates,
                1
            );
            if (i > 0) {
                Q3_details.intermediateActualMinerEarnings = safemath.add(
                    Q3_details.intermediateActualMinerEarnings,
                    additional_miner_earnings(
                        chainlink_data[safemath.sub(i, 1)],
                        current_update
                    )
                );
            }
            return true;
        }
        return false;
    }
// Solidity 0.7.3
/**
 * Checks if the current_update has updated difficulty and block_number values
 * compared to last_update. If either the difficulty or the block_number has
 * not been updated by Chainlink, this returns false.
 * @param last_update ChainlinkUpdate - previous update data returned by Chainlink Oracle
 * @param current_update ChainlinkUpdate - most recent update data returned by Chainlink Oracle
 */
function new_chainlink_data(
        ChainlinkUpdate memory last_update,
        ChainlinkUpdate memory current_update
    ) internal pure returns (bool new_data) {
        bool new_difficulty_data =
            current_update.diff_roundID != last_update.diff_roundID;
        bool new_blocknum_data =
            current_update.blocknum_roundID != last_update.blocknum_roundID;
        return new_difficulty_data && new_blocknum_data;
    }
// Solidity 0.7.3
/**
 * Calls Chainlink's Oracles, gets the latest data, and returns it.
 * @param blocknum_oracle IChainlinkOracle - Chainlink block number oracle
 * @param diff_oracle IChainlinkOracle - Chainlink difficulty number oracle
 */
function read_chainlink(
        IChainlinkOracle blocknum_oracle,
        IChainlinkOracle diff_oracle
    ) internal view returns (ChainlinkUpdate memory latest) {
        uint80 updated_roundID_diff;
        int256 current_diff;
        uint256 startedAt;
        uint256 updatedAt;
        uint80 answeredInRound;
        int256 current_blocknum;
        uint80 updated_roundID_blocknum;

        (
            updated_roundID_blocknum,
            current_blocknum,
            startedAt,
            updatedAt,
            answeredInRound
        ) = blocknum_oracle.latestRoundData();

        (
            updated_roundID_diff,
            current_diff,
            startedAt,
            updatedAt,
            answeredInRound
        ) = diff_oracle.latestRoundData();

        return
            ChainlinkUpdate(
                uint256(current_blocknum),
                uint256(current_diff),
                updated_roundID_blocknum,
                updated_roundID_diff
            );
    }
// Solidity 0.7.3
/**
 * Revenue (in WBTC base units) for 10 TH/s over the blocks from startBlock to endBlock
 * does not account for if there is a halving in between a difficulty update.
 * should not be relevant for Q3 2021
 * @param last_update ChainlinkUpdate - previous update data returned by Chainlink Oracle
 * @param current_update ChainlinkUpdate - most recent update data returned by Chainlink Oracle
 */
function additional_miner_earnings(
        ChainlinkUpdate memory last_update,
        ChainlinkUpdate memory current_update
    ) internal view returns (uint256 earnings) {
        uint256 startBlock = last_update.block_number;
        uint256 startDiff = last_update.difficulty;
        uint256 endBlock = current_update.block_number;
        uint256 endDiff = current_update.difficulty;

        require(
            endBlock >= startBlock,
            "Latest Block Number is less than last block number"
        );
        uint256 last_diff_update_block = get_last_diff_update(endBlock);
        if (last_diff_update_block <= startBlock) {
            return
                safemath.mul(
                    safemath.sub(endBlock, startBlock),
                    earnings_on_block(endDiff, startBlock)
                );
        } else {
            uint256 total =
                safemath.mul(
                    safemath.sub(last_diff_update_block, startBlock),
                    earnings_on_block(startDiff, startBlock)
                );
            total = safemath.add(
                total,
                safemath.mul(
                    safemath.sub(endBlock, last_diff_update_block),
                    earnings_on_block(endDiff, endBlock)
                )
            );
            return total;
        }
    }
// Solidity 0.7.3
/**
 * Check that the values that are trying to be added to the ChainlinkData 
 * for a quarter actually makes sense. 
 * Returns True if the update seems reasonable and returns false if the update
 * values seems unreasonable
 * Very generous constraints that are just sanity checks.
 * @param update ChainlinkUpdate - A chainlink update with block number and difficulty data
 */
function check_reasonable_values(ChainlinkUpdate memory update)
        internal
        view
        returns (bool reasonable)
    {
        uint256 update_diff = update.difficulty;
        uint256 update_block_number = update.block_number;
        uint256 number_of_updates = Q3_details.number_of_updates;
        if (
            (update_diff > maxValidDifficulty) ||
            (update_diff < minValidDifficulty)
        ) {
            return false;
        }
        if (
            (update_block_number > maxValidBlockNum) ||
            (update_block_number < minValidBlockNum)
        ) {
            return false;
        }
        if (number_of_updates > 0) {
            uint256 last_update_block_number =
                chainlink_data[safemath.sub(number_of_updates, 1)].block_number;
            if (update_block_number <= last_update_block_number) {
                return false;
            }
            if (
                update_block_number >
                safemath.add(
                    last_update_block_number,
                    maxValidBlockNumberIncrease
                )
            ) {
                return false;
            }
        }
        return true;
    }