lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.6
// -------------------------------------------------------------------------------------------------------
// FUNCTIONS THAT SPLIT ALL BALANCE AND RETURN MONEY TO THE GUEST ----------------------------------------
function splitAllBalance(Booking storage booking,
        uint depositToHostPpm, uint cleaningToHostPpm, uint priceToHostPpm)
    internal {
        uint priceToHost = booking.price * priceToHostPpm / 1000000;
        uint depositToHost = booking.deposit * depositToHostPpm / 1000000;
        uint cleaningToHost = booking.cleaning * cleaningToHostPpm / 1000000;

        booking.hostWithdrawAllowance = priceToHost + cleaningToHost + depositToHost;
        booking.guestWithdrawAllowance =
            (booking.price - priceToHost) +
            (booking.deposit - depositToHost) +
            (booking.cleaning - cleaningToHost);
    }
// Solidity 0.5.6
// HELPERS FOR SPLITTING FUNDS ---------------------------------------------------------------------------
function getNights(Booking storage booking)
    internal view returns (uint nightsAlreadyOccupied, uint nightsTotal) {
        nightsTotal = (12 * 60 * 60 + booking.dateTo - booking.dateFrom) / (24 * 60 * 60);
        if (now <= booking.dateFrom) {
            nightsAlreadyOccupied = 0;
        } else {
            // first night is occupied when 1 second is passed after check-in, and so on
            nightsAlreadyOccupied = (24 * 60 * 60 - 1 + now - booking.dateFrom) / (24 * 60 * 60);
        }
        if (nightsAlreadyOccupied > nightsTotal) {
            nightsAlreadyOccupied = nightsTotal;
        }
    }
// Solidity 0.4.25
/**
 * An address can become a new seller only in case it has no tokens.
 * This is required to prevent stealing of tokens  from newSeller via
 * 2 calls of this function.
 */
function changeSeller(address newSeller) onlyOwner public returns (bool) {
        require(newSeller != address(0));
        require(seller != newSeller);

        // To prevent stealing of tokens from newSeller via 2 calls of changeSeller:
        require(balances[newSeller] == 0);

        address oldSeller = seller;
        uint256 unsoldTokens = balances[oldSeller];
        balances[oldSeller] = 0;
        balances[newSeller] = unsoldTokens;
        emit Transfer(oldSeller, newSeller, unsoldTokens);

        seller = newSeller;
        emit ChangeSellerEvent(oldSeller, newSeller);
        return true;
    }
// Solidity 0.4.24
// For Owner & Manager
function createMatch(uint _id, string _team, string _teamDetail, int32 _pointSpread, uint64 _startTime, uint64 _endTime)
    onlyOwner
    public {

        require(_startTime < _endTime);
        require(matches[_id].created == false);

        // Create new match
        Match memory _match = Match({
            created:true,
            team: _team,
            teamDetail: _teamDetail,
            pointSpread: _pointSpread,
            startTime: _startTime,
            endTime: _endTime,
            stakesOfWin: 0,
            stakesOfDraw: 0,
            stakesOfLoss: 0,
            result: Result.Unknown
            });

        // Insert into matches
        matches[_id] = _match;
        numMatches++;

        // Set event
        emit NewMatch(_id, _team, _teamDetail, _pointSpread, _startTime, _endTime);
    }
// Solidity 0.4.24
// For Player
function bet(uint _id, Result _result)
    validId(_id)
    validResult(_result)
    public
    payable {

        // Check value
        require(msg.value > 0);

        // Check match state
        Match storage _match = matches[_id];
        require(_match.result == Result.Unknown);
        require(_match.startTime <= now);
        require(_match.endTime >= now);

        // Update matches
        if (_result == Result.HomeWin) {
            _match.stakesOfWin = add(_match.stakesOfWin, msg.value);
        } else if (_result == Result.HomeDraw) {
            _match.stakesOfDraw = add(_match.stakesOfDraw, msg.value);
        } else if (_result == Result.HomeLoss) {
            _match.stakesOfLoss = add(_match.stakesOfLoss, msg.value);
        }

        // Update predictions
        Prediction storage _prediction = predictions[_id][msg.sender];
        if (_prediction.result == Result.Unknown) {
            _prediction.stake = msg.value;
            _prediction.result = _result;
        } else {
            require(_prediction.result == _result);
            _prediction.stake = add(_prediction.stake, msg.value);
        }

        // Set event
        emit Bet(msg.sender, _id, _result, msg.value, _match.stakesOfWin, _match.stakesOfDraw, _match.stakesOfLoss);
    }
// Solidity 0.8.7
//addMembers is adding members to the contract
function addMembers(address[] memory members, uint256[3][] memory membersTokens) external onlyOwner returns (bool) {
        require (members.length == membersTokens.length, "ClinTex: arrays of incorrect length");

        for (uint256 index = 0; index < members.length; index++){
            require(membersTokens[index][0] >= membersTokens[index][1], "ClinTex: there are more frozen tokens before the first date than on the balance");
            require(membersTokens[index][0] >= membersTokens[index][2], "ClinTex: there are more frozen tokens before the second date than on the balance");
            
            _mint(members[index], membersTokens[index][0]);
            
            _freezeTokens[members[index]].frozenTokensBeforeTheFirstDate = membersTokens[index][1];
            _freezeTokens[members[index]].frozenTokensBeforeTheSecondDate = membersTokens[index][2];
        }

        return true;
    }
// Solidity 0.8.7
//getFreezeTokens returns the number of frozen tokens on the account
function getFreezeTokens(address account, uint8 flag) public view returns (uint256) {
        require(account != address(0), "ClinTex: address must not be empty");
        require (flag < 2, "ClinTex: unknown flag");
        
        if (flag == 0) {
            return _freezeTokens[account].frozenTokensBeforeTheFirstDate;
        }
        return _freezeTokens[account].frozenTokensBeforeTheSecondDate;
    }
// Solidity 0.6.0
// Returns the number of naps token to boost
function calculateCost(uint256 level) public view returns(uint256) {
        uint256 cycles = calculateCycle.calculate(deployedTime,block.timestamp,napsDiscountRange);
        // Cap it to 5 times
        if(cycles > 5) {
            cycles = 5;
        }
        // // cost = initialCost * (0.9)^cycles = initial cost * (9^cycles)/(10^cycles)
        if (level == 1) {
            return napsLevelOneCost.mul(9 ** cycles).div(10 ** cycles);
        }else if(level == 2) {
            return napsLevelTwoCost.mul(9 ** cycles).div(10 ** cycles);
        }else if(level ==3) {
            return napsLevelThreeCost.mul(9 ** cycles).div(10 ** cycles);
        }
    }
// Solidity 0.8.7
//isTransferFreezeTokens returns true when transferring frozen tokens
function isTransferFreezeTokens(address account, uint256 amount) public view returns (bool) {
        if (block.timestamp > _secondUnfreezeDate){
            return false;
        }

        if (_firstUnfreezeDate < block.timestamp && block.timestamp < _secondUnfreezeDate) {
            if (balanceOf(account) - getFreezeTokens(account, 1) < amount) {
                return true;
            }
        }

        if (block.timestamp < _firstUnfreezeDate) {
            if (balanceOf(account) - getFreezeTokens(account, 0) < amount) {
                return true;
            }
        }
        return false;
    }
// Solidity 0.8.0
/**
 * This is the function that burns the MAHA and returns how much ARTH should
 * actually be spent.
 *
 * Note we are always selling tokenA.
 */
function conductChecks(
        uint112 reserveA,
        uint112 reserveB,
        uint256 priceALast,
        uint256 priceBLast,
        uint256 amountOutA,
        uint256 amountOutB,
        uint256 amountInA,
        uint256 amountInB,
        address from,
        address to
    ) external override onlyPair {
        // The to nd from address has to be whitelisted.
        require(whitelist[to], "ArthIncentiveControllerV2: FORBIDDEN");
        require(whitelist[from], "ArthIncentiveControllerV2: FORBIDDEN");
    }
// Solidity 0.5.17
/**
 * @dev Initializer that sets supported ERC20 contract addresses and supported pools for each supported token.
 */
function initialize() public initializer {
        // Initialize base contracts
        Ownable.initialize(msg.sender);
        
        // Add supported currencies
        addSupportedCurrency("DAI", 0x6B175474E89094C44Da98b954EedeAC495271d0F, 18);
        addPoolToCurrency("DAI", RariFundController.LiquidityPool.dYdX);
        addPoolToCurrency("DAI", RariFundController.LiquidityPool.Compound);
        addPoolToCurrency("DAI", RariFundController.LiquidityPool.Aave);
        addPoolToCurrency("DAI", RariFundController.LiquidityPool.yVault);
        addSupportedCurrency("USDC", 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 6);
        addPoolToCurrency("USDC", RariFundController.LiquidityPool.dYdX);
        addPoolToCurrency("USDC", RariFundController.LiquidityPool.Compound);
        addPoolToCurrency("USDC", RariFundController.LiquidityPool.Aave);
        addPoolToCurrency("USDC", RariFundController.LiquidityPool.yVault);
        addSupportedCurrency("USDT", 0xdAC17F958D2ee523a2206206994597C13D831ec7, 6);
        addPoolToCurrency("USDT", RariFundController.LiquidityPool.Compound);
        addPoolToCurrency("USDT", RariFundController.LiquidityPool.Aave);
        addPoolToCurrency("USDT", RariFundController.LiquidityPool.yVault);
        addSupportedCurrency("TUSD", 0x0000000000085d4780B73119b644AE5ecd22b376, 18);
        addPoolToCurrency("TUSD", RariFundController.LiquidityPool.Aave);
        addPoolToCurrency("TUSD", RariFundController.LiquidityPool.yVault);
        addSupportedCurrency("BUSD", 0x4Fabb145d64652a948d72533023f6E7A623C7C53, 18);
        addPoolToCurrency("BUSD", RariFundController.LiquidityPool.Aave);
        addSupportedCurrency("sUSD", 0x57Ab1ec28D129707052df4dF418D58a2D46d5f51, 18);
        addPoolToCurrency("sUSD", RariFundController.LiquidityPool.Aave);
        addSupportedCurrency("mUSD", 0xe2f2a5C287993345a840Db3B0845fbC70f5935a5, 18);
        addPoolToCurrency("mUSD", RariFundController.LiquidityPool.mStable);

        // Initialize raw fund balance cache (can't set initial values in field declarations with proxy storage)
        _rawFundBalanceCache = -1;
    }
// Solidity 0.5.17
/**
 * @dev Upgrades RariFundManager.
 * Sends data to the new contract and sets the new RariFundToken minter.
 * @param newContract The address of the new RariFundManager contract.
 */
function upgradeFundManager(address newContract) external onlyOwner {
        require(fundDisabled, "This fund manager contract must be disabled before it can be upgraded.");

        // Pass data to the new contract
        FundManagerData memory data;

        data = FundManagerData(
            _netDeposits,
            _rawInterestAccruedAtLastFeeRateChange,
            _interestFeesGeneratedAtLastFeeRateChange,
            _interestFeesClaimed
        );

        RariFundManager(newContract).setFundManagerData(data);

        // Update RariFundToken minter
        if (_rariFundTokenContract != address(0)) {
            rariFundToken.addMinter(newContract);
            rariFundToken.renounceMinter();
        }

        emit FundManagerUpgraded(newContract);
    }
// Solidity 0.5.17
/**
 * @dev Upgrades RariFundManager.
 * Sets data receieved from the old contract.
 * @param data The data from the old contract necessary to initialize the new contract.
 */
function setFundManagerData(FundManagerData calldata data) external {
        require(_authorizedFundManagerDataSource != address(0) && msg.sender == _authorizedFundManagerDataSource, "Caller is not an authorized source.");
        _netDeposits = data.netDeposits;
        _rawInterestAccruedAtLastFeeRateChange = data.rawInterestAccruedAtLastFeeRateChange;
        _interestFeesGeneratedAtLastFeeRateChange = data.interestFeesGeneratedAtLastFeeRateChange;
        _interestFeesClaimed = data.interestFeesClaimed;
        _interestFeeRate = RariFundManager(_authorizedFundManagerDataSource).getInterestFeeRate();
        _withdrawalFeeRate = RariFundManager(_authorizedFundManagerDataSource).getWithdrawalFeeRate();
    }
// Solidity 0.5.17
/**
 * @dev Returns the fund controller's balance of the specified currency in the specified pool.
 * @dev Ideally, we can add the `view` modifier, but Compound's `getUnderlyingBalance` function (called by `CompoundPoolController.getBalance`) potentially modifies the state.
 * @param pool The index of the pool.
 * @param currencyCode The currency code of the token.
 */
function getPoolBalance(RariFundController.LiquidityPool pool, string memory currencyCode) internal returns (uint256) {
        if (!rariFundController.hasCurrencyInPool(pool, currencyCode)) return 0;

        if (_cachePoolBalances || _cacheDydxBalances) {
            if (pool == RariFundController.LiquidityPool.dYdX) {
                address erc20Contract = _erc20Contracts[currencyCode];
                require(erc20Contract != address(0), "Invalid currency code.");
                if (_dydxBalancesCache.length == 0) (_dydxTokenAddressesCache, _dydxBalancesCache) = rariFundController.getDydxBalances();
                for (uint256 i = 0; i < _dydxBalancesCache.length; i++) if (_dydxTokenAddressesCache[i] == erc20Contract) return _dydxBalancesCache[i];
                revert("Failed to get dYdX balance of this currency code.");
            } else if (_cachePoolBalances) {
                uint8 poolAsUint8 = uint8(pool);
                if (_poolBalanceCache[currencyCode][poolAsUint8] == 0) _poolBalanceCache[currencyCode][poolAsUint8] = rariFundController._getPoolBalance(pool, currencyCode);
                return _poolBalanceCache[currencyCode][poolAsUint8];
            }
        }

        return rariFundController._getPoolBalance(pool, currencyCode);
    }
// Solidity 0.5.17
/**
 * @notice Returns the fund's raw total balance (all RFT holders' funds + all unclaimed fees) of the specified currency.
 * @dev Ideally, we can add the `view` modifier, but Compound's `getUnderlyingBalance` function (called by `RariFundController.getPoolBalance`) potentially modifies the state.
 * @param currencyCode The currency code of the balance to be calculated.
 */
function getRawFundBalance(string memory currencyCode) public returns (uint256) {
        address erc20Contract = _erc20Contracts[currencyCode];
        require(erc20Contract != address(0), "Invalid currency code.");

        IERC20 token = IERC20(erc20Contract);
        uint256 totalBalance = token.balanceOf(_rariFundControllerContract);
        for (uint256 i = 0; i < _poolsByCurrency[currencyCode].length; i++)
            totalBalance = totalBalance.add(getPoolBalance(_poolsByCurrency[currencyCode][i], currencyCode));

        return totalBalance;
    }
// Solidity 0.5.17
/**
 * @dev Returns the fund's raw total balance (all RFT holders' funds + all unclaimed fees) of all currencies in USD (scaled by 1e18).
 * Accepts prices in USD as a parameter to avoid calculating them every time.
 * Ideally, we can add the `view` modifier, but Compound's `getUnderlyingBalance` function (called by `getRawFundBalance`) potentially modifies the state.
 */
function getRawFundBalance(uint256[] memory pricesInUsd) public cacheDydxBalances returns (uint256) {
        uint256 totalBalance = 0;

        for (uint256 i = 0; i < _supportedCurrencies.length; i++) {
            string memory currencyCode = _supportedCurrencies[i];
            uint256 balance = getRawFundBalance(currencyCode);
            uint256 balanceUsd = balance.mul(pricesInUsd[i]).div(10 ** _currencyDecimals[currencyCode]);
            totalBalance = totalBalance.add(balanceUsd);
        }

        return totalBalance;
    }
// Solidity 0.5.17
/**
 * @notice Returns the total balance in USD (scaled by 1e18) of `account`.
 * @dev Ideally, we can add the `view` modifier, but Compound's `getUnderlyingBalance` function (called by `getRawFundBalance`) potentially modifies the state.
 * @param account The account whose balance we are calculating.
 */
function balanceOf(address account) external returns (uint256) {
        uint256 rftTotalSupply = rariFundToken.totalSupply();
        if (rftTotalSupply == 0) return 0;
        uint256 rftBalance = rariFundToken.balanceOf(account);
        uint256 fundBalanceUsd = getFundBalance();
        uint256 accountBalanceUsd = rftBalance.mul(fundBalanceUsd).div(rftTotalSupply);
        return accountBalanceUsd;
    }
// Solidity 0.5.17
/**
 * @notice Returns an array of currency codes currently accepted for deposits.
 */
function getAcceptedCurrencies() external view returns (string[] memory) {
        uint256 arrayLength = 0;
        for (uint256 i = 0; i < _supportedCurrencies.length; i++) if (_acceptedCurrencies[_supportedCurrencies[i]]) arrayLength++;
        string[] memory acceptedCurrencies = new string[](arrayLength);
        uint256 index = 0;

        for (uint256 i = 0; i < _supportedCurrencies.length; i++) if (_acceptedCurrencies[_supportedCurrencies[i]]) {
            acceptedCurrencies[index] = _supportedCurrencies[i];
            index++;
        }

        return acceptedCurrencies;
    }
// Solidity 0.5.17
/**
 * @dev Marks `currencyCodes` as accepted or not accepted.
 * @param currencyCodes The currency codes to mark as accepted or not accepted.
 * @param accepted An array of booleans indicating if each of `currencyCodes` is to be accepted.
 */
function setAcceptedCurrencies(string[] calldata currencyCodes, bool[] calldata accepted) external onlyRebalancer {
        require (currencyCodes.length > 0 && currencyCodes.length == accepted.length, "Lengths of arrays must be equal and both greater than 0.");
        for (uint256 i = 0; i < currencyCodes.length; i++) _acceptedCurrencies[currencyCodes[i]] = accepted[i];
    }
// Solidity 0.5.17
/**
 * @dev Returns the amount of RFT to burn for a withdrawal (used by `_withdrawFrom`).
 * @param from The address from which RFT will be burned.
 * @param amountUsd The amount of the withdrawal in USD
 */
function getRftBurnAmount(address from, uint256 amountUsd) internal returns (uint256) {
        uint256 rftTotalSupply = rariFundToken.totalSupply();
        uint256 fundBalanceUsd = getFundBalance();
        require(fundBalanceUsd > 0, "Fund balance is zero.");
        uint256 rftAmount = amountUsd.mul(rftTotalSupply).div(fundBalanceUsd);
        require(rftAmount <= rariFundToken.balanceOf(from), "Your RFT balance is too low for a withdrawal of this amount.");
        require(rftAmount > 0, "Withdrawal amount is so small that no RFT would be burned.");
        return rftAmount;
    }
// Solidity 0.5.17
/**
 * @dev Internal function to withdraw funds from pools if necessary for `RariFundController` to hold at least `amount` of actual tokens.
 * This function was separated from `_withdrawFrom` to avoid the stack going too deep.
 * @param currencyCode The currency code of the token to be withdrawn.
 * @param amount The minimum amount of tokens that must be held by `RariFundController` after withdrawing.
 * @return The actual amount withdrawn after potential yVault withdrawal fees.
 */
function withdrawFromPoolsIfNecessary(string memory currencyCode, uint256 amount) internal returns (uint256) {
        // Check contract balance of token and withdraw from pools if necessary
        address erc20Contract = _erc20Contracts[currencyCode];
        IERC20 token = IERC20(erc20Contract);
        uint256 contractBalance = token.balanceOf(_rariFundControllerContract);

        for (uint256 i = 0; i < _poolsByCurrency[currencyCode].length; i++) {
            if (contractBalance >= amount) break;
            RariFundController.LiquidityPool pool = _poolsByCurrency[currencyCode][i];
            uint256 poolBalance = getPoolBalance(pool, currencyCode);
            if (poolBalance <= 0) continue;
            uint256 amountLeft = amount.sub(contractBalance);
            bool withdrawAll = amountLeft >= poolBalance;
            uint256 poolAmount = withdrawAll ? poolBalance : amountLeft;
            rariFundController.withdrawFromPoolOptimized(pool, currencyCode, poolAmount, withdrawAll);

            if (pool == RariFundController.LiquidityPool.dYdX) {
                for (uint256 j = 0; j < _dydxBalancesCache.length; j++) if (_dydxTokenAddressesCache[j] == erc20Contract) _dydxBalancesCache[j] = poolBalance.sub(poolAmount);
            } else _poolBalanceCache[currencyCode][uint8(pool)] = poolBalance.sub(poolAmount);

            contractBalance = contractBalance.add(poolAmount);
        }

        require(amount <= contractBalance, "Available balance not enough to cover amount even after withdrawing from pools.");
        uint256 realContractBalance = token.balanceOf(_rariFundControllerContract);
        return realContractBalance < amount ? realContractBalance : amount;
    }
// Solidity 0.5.17
/**
 * @dev Withdraws multiple currencies from the Rari Yield Pool to `msg.sender` (RariFundProxy) in exchange for RFT burned from `from`.
 * You may only withdraw currencies held by the fund (see `getRawFundBalance(string currencyCode)`).
 * Please note that you must approve RariFundManager to burn of the necessary amount of RFT.
 * @param from The address from which RFT will be burned.
 * @param currencyCodes The currency codes of the tokens to be withdrawn.
 * @param amounts The amounts of the tokens to be withdrawn.
 * @return Array of amounts withdrawn after fees.
 */
function withdrawFrom(address from, string[] calldata currencyCodes, uint256[] calldata amounts) external onlyProxy cachePoolBalances returns (uint256[] memory) {
        // Input validation
        require(currencyCodes.length > 0 && currencyCodes.length == amounts.length, "Lengths of currency code and amount arrays must be greater than 0 and equal.");
        uint256[] memory pricesInUsd = rariFundPriceConsumer.getCurrencyPricesInUsd();

        // Manually cache raw fund balance (no need to check if set previously because the function is external)
        _rawFundBalanceCache = toInt256(getRawFundBalance(pricesInUsd));

        // Make withdrawals
        uint256[] memory amountsAfterFees = new uint256[](currencyCodes.length);
        for (uint256 i = 0; i < currencyCodes.length; i++) amountsAfterFees[i] = _withdrawFrom(from, currencyCodes[i], amounts[i], pricesInUsd);

        // Reset _rawFundBalanceCache
        _rawFundBalanceCache = -1;

        // Return amounts withdrawn after fees
        return amountsAfterFees;
    }
// Solidity 0.5.17
/**
 * @dev Sets the fee rate on interest.
 * @param rate The proportion of interest accrued to be taken as a service fee (scaled by 1e18).
 */
function setInterestFeeRate(uint256 rate) external fundEnabled onlyOwner cacheRawFundBalance {
        require(rate != _interestFeeRate, "This is already the current interest fee rate.");
        require(rate <= 1e18, "The interest fee rate cannot be greater than 100%.");
        _depositFees();
        _interestFeesGeneratedAtLastFeeRateChange = getInterestFeesGenerated(); // MUST update this first before updating _rawInterestAccruedAtLastFeeRateChange since it depends on it 
        _rawInterestAccruedAtLastFeeRateChange = getRawInterestAccrued();
        _interestFeeRate = rate;
    }