lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Burn cube tokens to withdraw ETH
 * @param cubeToken Which cube token to burn
 * @param cubeTokensIn Quantity of cube tokens to burn
 * @param recipient Address that receives the withdrawn ETH
 * @return ethOut Amount of ETH withdrawn
 */
function withdraw(
        CubeToken cubeToken,
        uint256 cubeTokensIn,
        address recipient
    ) external nonReentrant returns (uint256 ethOut) {
        CubeTokenParams storage _params = params[cubeToken];
        require(_params.added, "Not added");
        require(!_params.withdrawPaused, "Paused");
        require(cubeTokensIn > 0, "cubeTokensIn should be > 0");
        require(recipient != address(0), "Zero address");

        (uint256 price, uint256 _totalEquity) = _priceAndTotalEquity(cubeToken);
        _updatePrice(cubeToken, price);

        ethOut = _mulPrice(cubeTokensIn, price, _totalEquity, poolBalance());
        uint256 fees = _mulFee(ethOut, _params.depositWithdrawFee);
        ethOut = ethOut.sub(fees);

        // Make sure pool size isn't too small, otherwise there could be
        // rounding issues. Check total equity instead of pool balance since
        // pool balance is increased again by fees going back into pool.
        _totalEquity = _totalEquity.sub(cubeTokensIn.mul(price));
        require(_totalEquity >= MIN_TOTAL_EQUITY, "Min total equity exceeded");
        totalEquity = _totalEquity;

        uint256 protocolFees = _mulFee(fees, protocolFee);
        accruedProtocolFees = accruedProtocolFees.add(protocolFees);

        cubeToken.burn(msg.sender, cubeTokensIn);
        payable(recipient).transfer(ethOut);

        emit DepositOrWithdraw(cubeToken, msg.sender, recipient, false, cubeTokensIn, ethOut, protocolFees);
    }
// Solidity 0.6.12
/**
 * @notice Add a new cube token. Can only be called by governance.
 * @param spotSymbol Symbol of underlying token. Used to fetch price from oracle
 * @param inverse True means 3x short token. False means 3x long token.
 * @return address Address of cube token that was added
 */
function addCubeToken(
        string memory spotSymbol,
        bool inverse,
        uint256 depositWithdrawFee,
        uint256 maxPoolShare
    ) external onlyGovernance returns (address) {
        require(address(cubeTokensMap[spotSymbol][inverse]) == address(0), "Already added");

        bytes32 salt = keccak256(abi.encodePacked(spotSymbol, inverse));
        CubeToken cubeToken = CubeToken(Clones.cloneDeterministic(address(cubeTokenImpl), salt));
        cubeToken.initialize(address(this), spotSymbol, inverse);

        bytes32 currencyKey = feed.stringToBytes32(spotSymbol);
        uint256 spot = feed.getPrice(currencyKey);
        require(spot > 0, "Spot price should be > 0");

        params[cubeToken] = CubeTokenParams({
            currencyKey: currencyKey,
            inverse: inverse,
            depositPaused: false,
            withdrawPaused: false,
            updatePaused: false,
            added: true,
            depositWithdrawFee: depositWithdrawFee,
            maxPoolShare: maxPoolShare,
            initialSpotPrice: spot,
            lastPrice: 0,
            lastUpdated: 0
        });
        cubeTokensMap[spotSymbol][inverse] = cubeToken;
        cubeTokens.push(cubeToken);

        // Set `lastPrice` and `lastUpdated`
        update(cubeToken);
        assert(params[cubeToken].lastPrice > 0);
        assert(params[cubeToken].lastUpdated > 0);

        emit AddCubeToken(cubeToken, spotSymbol, inverse, currencyKey, spot);
        return address(cubeToken);
    }
// Solidity 0.6.12
/**
 * @notice Calculate ETH withdrawn when burning `cubeTokensIn` cube tokens.
 */
function quoteWithdraw(CubeToken cubeToken, uint256 cubeTokensIn) external view returns (uint256) {
        (uint256 price, uint256 _totalEquity) = _priceAndTotalEquity(cubeToken);
        uint256 ethOut = _mulPrice(cubeTokensIn, price, _totalEquity, poolBalance());
        uint256 fees = _mulFee(ethOut, params[cubeToken].depositWithdrawFee);
        return ethOut.sub(fees);
    }
// Solidity 0.5.17
/**
 * @notice Get the underlying price of a listed cToken asset
 * @param cToken The cToken to get the underlying price of
 * @return The underlying asset price mantissa (scaled by 1e18)
 */
function getUnderlyingPrice(CToken cToken) public view returns (uint) {
        address cTokenAddress = address(cToken);
        if (cTokenAddress == cEthAddress) {
            // ether always worth 1
            return 1e18;
        }

        // Handle xSUSHI.
        if (cTokenAddress == cXSushiAddress) {
            uint exchangeRate = IXSushiExchangeRate(xSushiExRateAddress).getExchangeRate();
            return mul_(getTokenPrice(sushiAddress), Exp({mantissa: exchangeRate}));
        }

        address underlying = CErc20(cTokenAddress).underlying();

        // Handle LP tokens.
        if (areUnderlyingLPs[cTokenAddress]) {
            return getLPFairPrice(underlying);
        }

        // Handle Yvault tokens.
        if (yvTokens[underlying].isYvToken) {
            return getYvTokenPrice(underlying);
        }

        // Handle curve pool tokens.
        if (crvTokens[underlying].isCrvToken) {
            return getCrvTokenPrice(underlying);
        }

        return getTokenPrice(underlying);
    }
// Solidity 0.5.17
/**
 * @notice Get the price of a specific token. Return 1e18 is it's WETH.
 * @param token The token to get the price of
 * @return The price
 */
function getTokenPrice(address token) internal view returns (uint) {
        if (token == wethAddress) {
            // weth always worth 1
            return 1e18;
        }

        AggregatorV3Interface aggregator = aggregators[token];
        if (address(aggregator) != address(0)) {
            uint price = getPriceFromChainlink(aggregator);
            uint underlyingDecimals = EIP20Interface(token).decimals();
            return mul_(price, 10**(18 - underlyingDecimals));
        }
        return getPriceFromV1(token);
    }
// Solidity 0.5.17
/**
 * @notice Get price from ChainLink
 * @param aggregator The ChainLink aggregator to get the price of
 * @return The price
 */
function getPriceFromChainlink(AggregatorV3Interface aggregator) internal view returns (uint) {
        ( , int price, , , ) = aggregator.latestRoundData();
        require(price > 0, "invalid price");

        // Extend the decimals to 1e18.
        return mul_(uint(price), 10**(18 - uint(aggregator.decimals())));
    }
// Solidity 0.5.17
/**
 * @notice Get the fair price of a LP. We use the mechanism from Alpha Finance.
 *         Ref: https://blog.alphafinance.io/fair-lp-token-pricing/
 * @param pair The pair of AMM (Uniswap or SushiSwap)
 * @return The price
 */
function getLPFairPrice(address pair) internal view returns (uint) {
        address token0 = IUniswapV2Pair(pair).token0();
        address token1 = IUniswapV2Pair(pair).token1();
        uint totalSupply = IUniswapV2Pair(pair).totalSupply();
        (uint r0, uint r1, ) = IUniswapV2Pair(pair).getReserves();
        uint sqrtR = sqrt(mul_(r0, r1));
        uint p0 = getTokenPrice(token0);
        uint p1 = getTokenPrice(token1);
        uint sqrtP = sqrt(mul_(p0, p1));
        return div_(mul_(2, mul_(sqrtR, sqrtP)), totalSupply);
    }
// Solidity 0.5.17
/**
 * @notice Get price for Yvault tokens
 * @param token The Yvault token
 * @return The price
 */
function getYvTokenPrice(address token) internal view returns (uint) {
        YvTokenInfo memory yvTokenInfo = yvTokens[token];
        require(yvTokenInfo.isYvToken, "not a Yvault token");

        uint pricePerShare;
        address underlying;
        if (yvTokenInfo.version == YvTokenVersion.V1) {
            pricePerShare = YVaultV1Interface(token).getPricePerFullShare();
            underlying = YVaultV1Interface(token).token();
        } else {
            pricePerShare = YVaultV2Interface(token).pricePerShare();
            underlying = YVaultV2Interface(token).token();
        }

        uint underlyingPrice;
        if (crvTokens[underlying].isCrvToken) {
            underlyingPrice = getCrvTokenPrice(underlying);
        } else {
            underlyingPrice = getTokenPrice(underlying);
        }
        return mul_(underlyingPrice, Exp({mantissa: pricePerShare}));
    }
// Solidity 0.5.17
/**
 * @notice Get price for curve pool tokens
 * @param token The curve pool token
 * @return The price
 */
function getCrvTokenPrice(address token) internal view returns (uint) {
        CrvTokenInfo memory crvTokenInfo = crvTokens[token];
        require(crvTokenInfo.isCrvToken, "not a curve pool token");

        uint virtualPrice = CurveSwapInterface(crvTokenInfo.curveSwap).get_virtual_price();
        if (crvTokenInfo.poolTpye == CurvePoolType.ETH) {
            return virtualPrice;
        }

        // We treat USDC as USD and convert the price to ETH base.
        uint usdEthPrice = getTokenPrice(usdcAddress) / 1e12;
        return mul_(usdEthPrice, Exp({mantissa: virtualPrice}));
    }
// Solidity 0.5.17
/**
 * @notice Set ChainLink aggregators for multiple cTokens
 * @param tokenAddresses The list of underlying tokens
 * @param sources The list of ChainLink aggregator sources
 */
function _setAggregators(address[] calldata tokenAddresses, address[] calldata sources) external {
        require(msg.sender == admin || msg.sender == guardian, "only the admin or guardian may set the aggregators");
        require(tokenAddresses.length == sources.length, "mismatched data");
        for (uint i = 0; i < tokenAddresses.length; i++) {
            if (sources[i] != address(0)) {
                require(msg.sender == admin, "guardian may only clear the aggregator");
            }
            aggregators[tokenAddresses[i]] = AggregatorV3Interface(sources[i]);
            emit AggregatorUpdated(tokenAddresses[i], sources[i]);
        }
    }
// Solidity 0.5.17
/**
 * @notice See assets as LP tokens for multiple cTokens
 * @param cTokenAddresses The list of cTokens
 * @param isLP The list of cToken properties (it's LP or not)
 */
function _setLPs(address[] calldata cTokenAddresses, bool[] calldata isLP) external {
        require(msg.sender == admin, "only the admin may set LPs");
        require(cTokenAddresses.length == isLP.length, "mismatched data");
        for (uint i = 0; i < cTokenAddresses.length; i++) {
            areUnderlyingLPs[cTokenAddresses[i]] = isLP[i];
            emit IsLPUpdated(cTokenAddresses[i], isLP[i]);
        }
    }
// Solidity 0.5.17
/**
 * @notice See assets as Yvault tokens for multiple cTokens
 * @param tokenAddresses The list of underlying tokens
 * @param version The list of vault version
 */
function _setYVaultTokens(address[] calldata tokenAddresses, YvTokenVersion[] calldata version) external {
        require(msg.sender == admin, "only the admin may set Yvault tokens");
        require(tokenAddresses.length == version.length, "mismatched data");
        for (uint i = 0; i < tokenAddresses.length; i++) {
            // Sanity check to make sure version is right.
            if (version[i] == YvTokenVersion.V1) {
                YVaultV1Interface(tokenAddresses[i]).getPricePerFullShare();
            } else {
                YVaultV2Interface(tokenAddresses[i]).pricePerShare();
            }

            yvTokens[tokenAddresses[i]] = YvTokenInfo({isYvToken: true, version: version[i]});
            emit SetYVaultToken(tokenAddresses[i], version[i]);
        }
    }
// Solidity 0.5.17
/**
 * @notice See assets as curve pool tokens for multiple cTokens
 * @param tokenAddresses The list of underlying tokens
 * @param poolType The list of curve pool type (ETH or USD base only)
 * @param swap The list of curve swap address
 */
function _setCurveTokens(address[] calldata tokenAddresses, CurvePoolType[] calldata poolType, address[] calldata swap) external {
        require(msg.sender == admin, "only the admin may set curve pool tokens");
        require(tokenAddresses.length == poolType.length && tokenAddresses.length == swap.length, "mismatched data");
        for (uint i = 0; i < tokenAddresses.length; i++) {
            // Sanity check to make sure version is right.
            require(CurveSwapInterface(swap[i]).lp_token() == tokenAddresses[i], "incorrect pool");

            crvTokens[tokenAddresses[i]] = CrvTokenInfo({isCrvToken: true, poolTpye: poolType[i], curveSwap: swap[i]});
            emit SetCurveToken(tokenAddresses[i], poolType[i], swap[i]);
        }
    }
// Solidity 0.8.7
//
// Dessert distribution for each OCM# (j)
//
// If offset is 0, 15 Dessert3s at j = 364, 1301, 1453, 1527, 1601, 1629, 2214, 4097, 5227, 5956, 6694, 6754, 7442, 9132, 9850
// Overall distribution of Desserts is 15 Dessert3, 4485 Dessert2, 5500 Dessert1
//
function dessert(uint256 j) public view returns (uint256) {
        require(counter > 0, "Dessert not served");
        require(j>0 && j<10001, 'error');
        j = (j + offset) % 10000; // this is the fair and random offset from the VRF
        uint256 r = (uint256(keccak256(abi.encode(j.toString())))) % 10000; // this is the fixed sequence with the desired rarity distribution
        if (r < 8) {
            return 3; // Dessert3
        } else if (r >= 5538) {
            return 2; // Dessert2
        } else {
            return 1; // Dessert1
        }
    }
// Solidity 0.6.8
// return a * b
function mul(uint256 a, uint256 b) public pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        require(c / a == b, "mul overflow");
        return c;
    }
// Solidity 0.6.8
// return the greatest uint256 less than or equal to the square root of a
function sqrt(uint256 a) public pure returns (uint256) {
        uint256 result = 0;
        uint256 bit = 1 << 254; // the second to top bit
        while (bit > a) {
            bit >>= 2;
        }
        while (bit != 0) {
            uint256 sum = result + bit;
            result >>= 1;
            if (a >= sum) {
                a -= sum;
                result += bit;
            }
            bit >>= 2;
        }
        return result;
    }
// Solidity 0.6.8
/// @dev call token.approve(this, _tokens) before this
/// @notice sells tokens for eth; if there is not enough eth in the exchange,
/// or amount of tokens is too big, only appropriate amount of tokens will be used for sale;
/// reverts if balance of the exchange is greater than 5*10^24 tokens
function sell(uint256 _tokens) public {
        uint256 tokensBefore = Erc20(token).balanceOf(address(this));
        require(tokensBefore <= maxAmount, "big balance");
        uint256 tokensAfter = tokensBefore.add(_tokens);
        if (tokensAfter > maxAmount) {
            tokensAfter = maxAmount;
            _tokens = tokensAfter.sub(tokensBefore);
        }

        uint256 sum = s(tokensBefore, tokensAfter);
        if (sum > address(this).balance) {
            sum = address(this).balance;
            tokensAfter = v(tokensBefore, false, sum);
            _tokens = tokensAfter.sub(tokensBefore);
        }

        Erc20(token).transferFrom(msg.sender, address(this), _tokens);
        msg.sender.transfer(sum);
        emit Sell(msg.sender, sum);
    }
// Solidity 0.6.8
/// @notice feel free to clean from all spam tokens,
/// grab free tokens if there is too much of them
function clean(address _contract, uint256 _value) public {
        if (_contract == token) {
            uint256 tokens = Erc20(token).balanceOf(address(this));
            require(tokens > maxAmount, "no free tokens");
            require(_value <= tokens.sub(maxAmount), "big _value");
        }
        Erc20(_contract).transfer(msg.sender, _value);
    }
// Solidity 0.6.8
/// @dev reverts if balance of the exchange is greater than 5*10^24 tokens
/// @return eth/10^18 to receive from sale of provided number of tokens/10^18
function tokensToEthForSale(uint256 _tokens) public view returns (uint256) {
        uint256 tokensBefore = Erc20(token).balanceOf(address(this));
        require(tokensBefore <= maxAmount, "big balance");
        uint256 tokensAfter = tokensBefore.add(_tokens);
        if (tokensAfter > maxAmount) {
            tokensAfter = maxAmount;
        }

        uint256 sum = s(tokensBefore, tokensAfter);
        if (sum > address(this).balance) {
            return address(this).balance;
        }
        return sum;
    }
// Solidity 0.6.8
/// @dev reverts if there is not enough eth in the exchange,
/// or amount of tokens is too big,
/// or balance of the exchange is greater than 5*10^24 tokens
/// @return amount of tokens/10^18 required to get desired amount of eth/10^18
function ethToTokensForSale(uint256 _eth) public view returns (uint256) {
        uint256 tokensBefore = Erc20(token).balanceOf(address(this));
        require(tokensBefore <= maxAmount, "big balance");
        require(_eth <= address(this).balance, "big _eth");
        uint256 tokensAfter = v(tokensBefore, false, _eth);
        return tokensAfter.sub(tokensBefore);
    }
// Solidity 0.6.8
// v0 - current volume in tokens
// require v0 <= 5*10^24, check this before!
// isV0Right - bool, if true, returns v <= v0, else returns v >= v0
// s - sum in wei
// returns volume v in tokens, reverts if s is too big
// 0 <= v <= 5*10^24
function v(uint256 v0, bool isV0Right, uint256 s) private pure returns (uint256) {
        uint256 d = 10**50;
        if (isV0Right) {
            d = d.add(s.mul(4*10**25)).sub(Math.sub(10**25, v0).mul(v0).mul(4));
        } else {
            d = d.sub(s.mul(4*10**25)).sub(Math.sub(10**25, v0).mul(v0).mul(4));
        }
        return Math.sub(5*10**24, d.sqrt().div(2));
    }
// Solidity 0.4.26
/**
 * recover '_from' address by signature
 */
function testVerify(bytes32 s, bytes32 r, uint8 v, address _to, uint256 _value, uint256 _fee, uint256 _nonce) internal view returns (address) {
        Unit memory _msgobj = Unit({
        to : _to,
        value : _value,
        fee : _fee,
        nonce : _nonce
        });
        return ecrecover(hashUnit(_msgobj), v, r, s);
    }
// Solidity 0.4.26
/**
 * burn the specific signature from the signatures
 *
 * Requirement:
 * - sender(Caller) should be signer of that specific signature
 */
function burnTransaction(bytes32 s, bytes32 r, uint8 v, address _to, uint256 _value, uint256 _fee, uint256 _nonce) validAddress(_to, "_to address is not valid") public {
        require(!signatures[s], "this signature is burned or done before");
        address from = testVerify(s, r, v, _to, _value, _fee, _nonce);
        require(from == msg.sender, "you're not permitted to burn this signature");
        signatures[s] = true;
    }
// Solidity 0.4.26
/**
 * check if the transferPreSigned is valid or not!?
 *
 * Requirement:
 * - '_to' can not be zero address.
 */
function validTransaction(bytes32 s, bytes32 r, uint8 v, address _to, uint256 _value, uint256 _fee, uint256 _nonce) validAddress(_to, "_to address is not valid") view public returns (bool, address) {
        address from = testVerify(s, r, v, _to, _value, _fee, _nonce);
        require(!isBlackListed[from], "from address is blacklisted");
        return (from != address(0) && !signatures[s] && balances[from] >= _value.add(_fee), from);
    }
// Solidity 0.4.26
/**
 * submit the transferPreSigned
 *
 * Requirement:
 * - '_to' can not be zero address.
 * signature must be unused
 */
function transferPreSigned(bytes32 s, bytes32 r, uint8 v, address _to, uint256 _value, uint256 _fee, uint256 _nonce) validAddress(_to, "_to address is not valid") public returns (bool){
        require(signatures[s] == false, "signature has been used");
        address from = testVerify(s, r, v, _to, _value, _fee, _nonce);
        require(from != address(0), "signature is wrong");
        require(!isBlackListed[from], "from address is blacklisted");
        balances[from] = balances[from].sub(_value.add(_fee));
        balances[_to] = balances[_to].add(_value);
        balances[msg.sender] = balances[msg.sender].add(_fee);
        signatures[s] = true;
        emit Transfer(from, _to, _value);
        emit Transfer(from, msg.sender, _fee);
        emit TransferPreSigned(from, _to, msg.sender, _value, _fee);
        return true;
    }
// Solidity 0.4.26
/**
 * sender(caller) vote for transfer `_from' address to '_to' address in board of directors
 *
 * Requirement:
 * - sender(Caller) and _from` should be in the board of directors.
 * - `_to` shouldn't be in the board of directors
 */
function transferAuthority(uint256 from, address to) notInBoD(to, "_to address is already in board of directors") isAuthority(msg.sender, "you are not permitted to vote for transfer") public {
        require(from < BoDAddresses.length);
        if (BoDAddresses[from] == msg.sender) {
            transferAuth(from, to);
            return;
        }
        require(!transferObject.voted[msg.sender]);

        if (transferObject.from != from || transferObject.to != to) {
            transferObject.transferCounter = 0;
            for (uint j = 0; j < BoDAddresses.length; j++) {
                transferObject.voted[BoDAddresses[j]] = false;
            }
        }
        if (transferObject.transferCounter == 0) {
            transferObject.from = from;
            transferObject.to = to;
            
        }
        transferObject.transferCounter++;
        transferObject.voted[msg.sender] = true;
        if (transferObject.transferCounter == BoDAddresses.length - 1) {
            transferAuth(from, to);
        }
    }
// Solidity 0.4.26
/**
 * this function is called if all of board of directors vote for the transfer `_from`->`_to'.
 */
function transferAuth(uint256 from, address to) private {
        for (uint j = 0; j < BoDAddresses.length; j++) {
            transferObject.voted[BoDAddresses[j]] = false;
        }
        emit AuthorityTransfer(BoDAddresses[from], to);
        BoDAddresses[from] = to;
        transferObject.transferCounter = 0;
        
    }
// Solidity 0.4.26
/**
 * Transfer token from sender(caller) to '_to' account
 *
 * Requirements:
 *
 * - `_to` cannot be the zero address.
 * - the sender(caller) must have a balance of at least `_value`.
 */
function transfer(address _to, uint256 _value) validAddress(_to, "_to address is not valid") smallerOrLessThan(_value, balances[msg.sender], "transfer value should be smaller than your balance") public returns (bool) {
        require(!isBlackListed[msg.sender], "from address is blacklisted");
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        emit Transfer(msg.sender, _to, _value);
        return true;
    }
// Solidity 0.4.26
/**
 * sender(caller) transfer '_value' token to '_to' address from '_from' address
 *
 * Requirements:
 *
 * - `_to` and `_from` cannot be the zero address.
 * - `_from` must have a balance of at least `_value` .
 * - the sender(caller) must have allowance for `_from`'s tokens of at least `_value`.
 */
function transferFrom(address _from, address _to, uint256 _value) validAddress(_from, "_from address is not valid") validAddress(_to, "_to address is not valid") public returns (bool) {
        require(_value<=allowances[_from][msg.sender], "_value should be smaller than your allowance");
        require(_value<=balances[_from],"_value should be smaller than _from's balance");
        require(!isBlackListed[_from], "from address is blacklisted");
        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);
        allowances[_from][msg.sender] = allowances[_from][msg.sender].sub(_value);
        emit Transfer(_from, _to, _value);
        return true;
    }