creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "lib/blueberry-core/contracts/money-market/BCollateralCapErc20Delegate.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"./BCollateralCapErc20.sol\";\n\n/**\n * @title Blueberry's BCollateralCapErc20Delegate Contract\n * @notice BTokens which wrap an EIP-20 underlying and are delegated to\n * @author Blueberry\n */\ncontract BCollateralCapErc20Delegate is BCollateralCapErc20 {\n    /**\n     * @notice Construct an empty delegate\n     */\n    constructor() public {}\n\n    /**\n     * @notice Called by the delegator on a delegate to initialize it for duty\n     * @param data The encoded bytes data for any initialization\n     */\n    function _becomeImplementation(bytes memory data) public {\n        // Shh -- currently unused\n        data;\n\n        // Shh -- we don't ever want this hook to be marked pure\n        if (false) {\n            implementation = address(0);\n        }\n\n        require(msg.sender == admin, \"admin only\");\n\n        // Set internal cash when becoming implementation\n        internalCash = getCashOnChain();\n\n        // Set BToken version in comptroller\n        ComptrollerInterfaceExtension(address(comptroller)).updateBTokenVersion(\n                address(this),\n                ComptrollerV1Storage.Version.COLLATERALCAP\n            );\n    }\n\n    /**\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\n     */\n    function _resignImplementation() public {\n        // Shh -- we don't ever want this hook to be marked pure\n        if (false) {\n            implementation = address(0);\n        }\n\n        require(msg.sender == admin, \"admin only\");\n    }\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/BCollateralCapErc20.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"./BToken.sol\";\nimport \"./ComptrollerInterfaceExtension.sol\";\nimport \"./ERC3156FlashLenderInterface.sol\";\nimport \"./ERC3156FlashBorrowerInterface.sol\";\n\n/**\n * @title Blueberry's BCollateralCapErc20 Contract\n * @notice BTokens which wrap an EIP-20 underlying with collateral cap\n * @author Blueberry\n */\ncontract BCollateralCapErc20 is BToken, BCollateralCapErc20Interface {\n    /**\n     * @notice Initialize the new money market\n     * @param underlying_ The address of the underlying asset\n     * @param comptroller_ The address of the Comptroller\n     * @param interestRateModel_ The address of the interest rate model\n     * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18\n     * @param name_ ERC-20 name of this token\n     * @param symbol_ ERC-20 symbol of this token\n     * @param decimals_ ERC-20 decimal precision of this token\n     */\n    function initialize(\n        address underlying_,\n        ComptrollerInterface comptroller_,\n        InterestRateModel interestRateModel_,\n        uint256 initialExchangeRateMantissa_,\n        string memory name_,\n        string memory symbol_,\n        uint8 decimals_\n    ) public {\n        // BToken initialize does the bulk of the work\n        super.initialize(\n            comptroller_,\n            interestRateModel_,\n            initialExchangeRateMantissa_,\n            name_,\n            symbol_,\n            decimals_\n        );\n\n        // Set underlying and sanity check it\n        underlying = underlying_;\n        EIP20Interface(underlying).totalSupply();\n    }\n\n    /*** User Interface ***/\n\n    /**\n     * @notice Sender supplies assets into the market and receives bTokens in exchange\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\n     * @param mintAmount The amount of the underlying asset to supply\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function mint(uint256 mintAmount) external returns (uint256) {\n        require(msg.sender == softVault, \"caller should be softvault\");\n        (uint256 err, ) = mintInternal(mintAmount, false);\n        require(err == 0, \"mint failed\");\n    }\n\n    /**\n     * @notice Sender redeems bTokens in exchange for the underlying asset\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\n     * @param redeemTokens The number of bTokens to redeem into underlying\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function redeem(uint256 redeemTokens) external returns (uint256) {\n        require(redeemInternal(redeemTokens, false) == 0, \"redeem failed\");\n    }\n\n    /**\n     * @notice Sender redeems bTokens in exchange for a specified amount of underlying asset\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\n     * @param redeemAmount The amount of underlying to redeem\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function redeemUnderlying(uint256 redeemAmount) external returns (uint256) {\n        require(\n            redeemUnderlyingInternal(redeemAmount, false) == 0,\n            \"redeem underlying failed\"\n        );\n    }\n\n    /**\n     * @notice Sender borrows assets from the protocol to their own address\n     * @param borrowAmount The amount of the underlying asset to borrow\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function borrow(uint256 borrowAmount) external returns (uint256) {\n        require(borrowInternal(borrowAmount, false) == 0, \"borrow failed\");\n    }\n\n    /**\n     * @notice Sender repays their own borrow\n     * @param repayAmount The amount to repay\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function repayBorrow(uint256 repayAmount) external returns (uint256) {\n        (uint256 err, ) = repayBorrowInternal(repayAmount, false);\n        require(err == 0, \"repay failed\");\n    }\n\n    /**\n     * @notice Sender repays a borrow belonging to borrower\n     * @param borrower the account with the debt being payed off\n     * @param repayAmount The amount to repay\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function repayBorrowBehalf(\n        address borrower,\n        uint256 repayAmount\n    ) external returns (uint256) {\n        (uint256 err, ) = repayBorrowBehalfInternal(\n            borrower,\n            repayAmount,\n            false\n        );\n        require(err == 0, \"repay behalf failed\");\n    }\n\n    /**\n     * @notice The sender liquidates the borrowers collateral.\n     *  The collateral seized is transferred to the liquidator.\n     * @param borrower The borrower of this bToken to be liquidated\n     * @param repayAmount The amount of the underlying borrowed asset to repay\n     * @param bTokenCollateral The market in which to seize collateral from the borrower\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function liquidateBorrow(\n        address borrower,\n        uint256 repayAmount,\n        BTokenInterface bTokenCollateral\n    ) external returns (uint256) {\n        (uint256 err, ) = liquidateBorrowInternal(\n            borrower,\n            repayAmount,\n            bTokenCollateral,\n            false\n        );\n        require(err == 0, \"liquidate borrow failed\");\n    }\n\n    /**\n     * @notice The sender adds to reserves.\n     * @param addAmount The amount fo underlying token to add as reserves\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _addReserves(uint256 addAmount) external returns (uint256) {\n        require(\n            _addReservesInternal(addAmount, false) == 0,\n            \"add reserves failed\"\n        );\n    }\n\n    /**\n     * @notice Set the given collateral cap for the market.\n     * @param newCollateralCap New collateral cap for this market. A value of 0 corresponds to no cap.\n     */\n    function _setCollateralCap(uint256 newCollateralCap) external {\n        require(msg.sender == admin, \"admin only\");\n\n        collateralCap = newCollateralCap;\n        emit NewCollateralCap(address(this), newCollateralCap);\n    }\n\n    /**\n     * @notice Absorb excess cash into reserves.\n     */\n    function gulp() external nonReentrant {\n        uint256 cashOnChain = getCashOnChain();\n        uint256 cashPrior = getCashPrior();\n\n        uint256 excessCash = sub_(cashOnChain, cashPrior);\n        totalReserves = add_(totalReserves, excessCash);\n        internalCash = cashOnChain;\n    }\n\n    /**\n     * @dev The amount of currency available to be lent.\n     * @param token The loan currency.\n     * @return The amount of `token` that can be borrowed.\n     */\n    function maxFlashLoan(address token) external view returns (uint256) {\n        uint256 amount = 0;\n        if (\n            token == underlying &&\n            ComptrollerInterfaceExtension(address(comptroller))\n                .flashloanAllowed(address(this), address(0), amount, \"\")\n        ) {\n            amount = getCashPrior();\n        }\n        return amount;\n    }\n\n    /**\n     * @notice Get the flash loan fees\n     * @param token The loan currency. Must match the address of this contract's underlying.\n     * @param amount amount of token to borrow\n     * @return The amount of `token` to be charged for the loan, on top of the returned principal.\n     */\n    function flashFee(\n        address token,\n        uint256 amount\n    ) external view returns (uint256) {\n        require(token == underlying, \"unsupported currency\");\n        require(\n            ComptrollerInterfaceExtension(address(comptroller))\n                .flashloanAllowed(address(this), address(0), amount, \"\"),\n            \"flashloan is paused\"\n        );\n        return _flashFee(token, amount);\n    }\n\n    /**\n     * @notice Flash loan funds to a given account.\n     * @param receiver The receiver address for the funds\n     * @param token The loan currency. Must match the address of this contract's underlying.\n     * @param amount The amount of the funds to be loaned\n     * @param data The other data\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function flashLoan(\n        ERC3156FlashBorrowerInterface receiver,\n        address token,\n        uint256 amount,\n        bytes calldata data\n    ) external nonReentrant returns (bool) {\n        require(amount > 0, \"invalid flashloan amount\");\n        require(token == underlying, \"unsupported currency\");\n        accrueInterest();\n        require(\n            ComptrollerInterfaceExtension(address(comptroller))\n                .flashloanAllowed(\n                    address(this),\n                    address(receiver),\n                    amount,\n                    data\n                ),\n            \"flashloan is paused\"\n        );\n        uint256 cashOnChainBefore = getCashOnChain();\n        uint256 cashBefore = getCashPrior();\n        require(cashBefore >= amount, \"insufficient cash\");\n\n        // 1. calculate fee, 1 bips = 1/10000\n        uint256 totalFee = _flashFee(token, amount);\n\n        // 2. transfer fund to receiver\n        doTransferOut(address(uint160(address(receiver))), amount, false);\n\n        // 3. update totalBorrows\n        totalBorrows = add_(totalBorrows, amount);\n\n        // 4. execute receiver's callback function\n        require(\n            receiver.onFlashLoan(\n                msg.sender,\n                underlying,\n                amount,\n                totalFee,\n                data\n            ) == keccak256(\"ERC3156FlashBorrowerInterface.onFlashLoan\"),\n            \"IERC3156: Callback failed\"\n        );\n\n        // 5. take amount + fee from receiver, then check balance\n        uint256 repaymentAmount = add_(amount, totalFee);\n        doTransferIn(address(receiver), repaymentAmount, false);\n\n        uint256 cashOnChainAfter = getCashOnChain();\n\n        require(\n            cashOnChainAfter == add_(cashOnChainBefore, totalFee),\n            \"inconsistent balance\"\n        );\n\n        // 6. update reserves and internal cash and totalBorrows\n        uint256 reservesFee = mul_ScalarTruncate(\n            Exp({mantissa: reserveFactorMantissa}),\n            totalFee\n        );\n        totalReserves = add_(totalReserves, reservesFee);\n        internalCash = add_(cashBefore, totalFee);\n        totalBorrows = sub_(totalBorrows, amount);\n\n        emit Flashloan(address(receiver), amount, totalFee, reservesFee);\n        return true;\n    }\n\n    /**\n     * @notice Get the flash loan fees\n     * @param token The loan currency. Must match the address of this contract's underlying.\n     * @param amount amount of token to borrow\n     * @return The amount of `token` to be charged for the loan, on top of the returned principal.\n     */\n    function _flashFee(\n        address token,\n        uint256 amount\n    ) internal view returns (uint256) {\n        return div_(mul_(amount, flashFeeBips), 10000);\n    }\n\n    /**\n     * @notice Register account collateral tokens if there is space.\n     * @param account The account to register\n     * @dev This function could only be called by comptroller.\n     * @return The actual registered amount of collateral\n     */\n    function registerCollateral(address account) external returns (uint256) {\n        // Make sure accountCollateralTokens of `account` is initialized.\n        initializeAccountCollateralTokens(account);\n\n        require(msg.sender == address(comptroller), \"comptroller only\");\n\n        uint256 amount = sub_(\n            accountTokens[account],\n            accountCollateralTokens[account]\n        );\n        return increaseUserCollateralInternal(account, amount);\n    }\n\n    /**\n     * @notice Unregister account collateral tokens if the account still has enough collateral.\n     * @dev This function could only be called by comptroller.\n     * @param account The account to unregister\n     */\n    function unregisterCollateral(address account) external {\n        // Make sure accountCollateralTokens of `account` is initialized.\n        initializeAccountCollateralTokens(account);\n\n        require(msg.sender == address(comptroller), \"comptroller only\");\n        require(\n            comptroller.redeemAllowed(\n                address(this),\n                account,\n                accountCollateralTokens[account]\n            ) == 0,\n            \"rejected\"\n        );\n\n        decreaseUserCollateralInternal(\n            account,\n            accountCollateralTokens[account]\n        );\n    }\n\n    /*** Safe Token ***/\n\n    /**\n     * @notice Gets internal balance of this contract in terms of the underlying.\n     *  It excludes balance from direct transfer.\n     * @dev This excludes the value of the current message, if any\n     * @return The quantity of underlying tokens owned by this contract\n     */\n    function getCashPrior() internal view returns (uint256) {\n        return internalCash;\n    }\n\n    /**\n     * @notice Gets total balance of this contract in terms of the underlying\n     * @dev This excludes the value of the current message, if any\n     * @return The quantity of underlying tokens owned by this contract\n     */\n    function getCashOnChain() internal view returns (uint256) {\n        EIP20Interface token = EIP20Interface(underlying);\n        return token.balanceOf(address(this));\n    }\n\n    /**\n     * @notice Initialize the account's collateral tokens. This function should be called in the beginning of every function\n     *  that accesses accountCollateralTokens or accountTokens.\n     * @param account The account of accountCollateralTokens that needs to be updated\n     */\n    function initializeAccountCollateralTokens(address account) internal {\n        /**\n         * If isCollateralTokenInit is false, it means accountCollateralTokens was not initialized yet.\n         * This case will only happen once and must be the very beginning. accountCollateralTokens is a new structure and its\n         * initial value should be equal to accountTokens if user has entered the market. However, it's almost impossible to\n         * check every user's value when the implementation becomes active. Therefore, it must rely on every action which will\n         * access accountTokens to call this function to check if accountCollateralTokens needed to be initialized.\n         */\n        if (!isCollateralTokenInit[account]) {\n            if (\n                ComptrollerInterfaceExtension(address(comptroller))\n                    .checkMembership(account, BToken(this))\n            ) {\n                accountCollateralTokens[account] = accountTokens[account];\n                totalCollateralTokens = add_(\n                    totalCollateralTokens,\n                    accountTokens[account]\n                );\n\n                emit UserCollateralChanged(\n                    account,\n                    accountCollateralTokens[account]\n                );\n            }\n            isCollateralTokenInit[account] = true;\n        }\n    }\n\n    /**\n     * @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and reverts in that case.\n     *      This will revert due to insufficient balance or insufficient allowance.\n     *      This function returns the actual amount received,\n     *      which may be less than `amount` if there is a fee attached to the transfer.\n     *\n     *      Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.\n     *            See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca\n     */\n    function doTransferIn(\n        address from,\n        uint256 amount,\n        bool isNative\n    ) internal returns (uint256) {\n        isNative; // unused\n\n        EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);\n        uint256 balanceBefore = EIP20Interface(underlying).balanceOf(\n            address(this)\n        );\n        token.transferFrom(from, address(this), amount);\n\n        bool success;\n        assembly {\n            switch returndatasize()\n            case 0 {\n                // This is a non-standard ERC-20\n                success := not(0) // set success to true\n            }\n            case 32 {\n                // This is a compliant ERC-20\n                returndatacopy(0, 0, 32)\n                success := mload(0) // Set `success = returndata` of external call\n            }\n            default {\n                // This is an excessively non-compliant ERC-20, revert.\n                revert(0, 0)\n            }\n        }\n        require(success, \"transfer failed\");\n\n        // Calculate the amount that was *actually* transferred\n        uint256 balanceAfter = EIP20Interface(underlying).balanceOf(\n            address(this)\n        );\n        uint256 transferredIn = sub_(balanceAfter, balanceBefore);\n        internalCash = add_(internalCash, transferredIn);\n        return transferredIn;\n    }\n\n    /**\n     * @dev Similar to EIP20 transfer, except it handles a False success from `transfer` and returns an explanatory\n     *      error code rather than reverting. If caller has not called checked protocol's balance, this may revert due to\n     *      insufficient cash held in this contract. If caller has checked protocol's balance prior to this call, and verified\n     *      it is >= amount, this should not revert in normal conditions.\n     *\n     *      Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.\n     *            See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca\n     */\n    function doTransferOut(\n        address payable to,\n        uint256 amount,\n        bool isNative\n    ) internal {\n        isNative; // unused\n\n        EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);\n        token.transfer(to, amount);\n\n        bool success;\n        assembly {\n            switch returndatasize()\n            case 0 {\n                // This is a non-standard ERC-20\n                success := not(0) // set success to true\n            }\n            case 32 {\n                // This is a complaint ERC-20\n                returndatacopy(0, 0, 32)\n                success := mload(0) // Set `success = returndata` of external call\n            }\n            default {\n                // This is an excessively non-compliant ERC-20, revert.\n                revert(0, 0)\n            }\n        }\n        require(success, \"transfer failed\");\n        internalCash = sub_(internalCash, amount);\n    }\n\n    /**\n     * @notice Get the amount of collateral tokens user would consume.\n     * @param amountTokens The amount of tokens that user would like to redeem, transfer, or seize\n     * @param account The account address\n     * @return The amount of collateral tokens to be consumed\n     */\n    function getCollateralTokens(\n        uint256 amountTokens,\n        address account\n    ) internal view returns (uint256) {\n        /**\n         * For every user, accountTokens must be greater than or equal to accountCollateralTokens.\n         * The buffer between the two values will be transferred first.\n         * bufferTokens = accountTokens[account] - accountCollateralTokens[account]\n         * collateralTokens = tokens - bufferTokens\n         */\n        uint256 bufferTokens = sub_(\n            accountTokens[account],\n            accountCollateralTokens[account]\n        );\n        uint256 collateralTokens = 0;\n        if (amountTokens > bufferTokens) {\n            collateralTokens = amountTokens - bufferTokens;\n        }\n        return collateralTokens;\n    }\n\n    /**\n     * @notice Transfer `tokens` tokens from `src` to `dst` by `spender`\n     * @dev Called by both `transfer` and `transferFrom` internally\n     * @param spender The address of the account performing the transfer\n     * @param src The address of the source account\n     * @param dst The address of the destination account\n     * @param tokens The number of tokens to transfer\n     * @return Whether or not the transfer succeeded\n     */\n    function transferTokens(\n        address spender,\n        address src,\n        address dst,\n        uint256 tokens\n    ) internal returns (uint256) {\n        // Make sure accountCollateralTokens of `src` and `dst` are initialized.\n        initializeAccountCollateralTokens(src);\n        initializeAccountCollateralTokens(dst);\n\n        uint256 collateralTokens = getCollateralTokens(tokens, src);\n\n        /**\n         * Since bufferTokens are not collateralized and can be transferred freely, we only check with comptroller\n         * whether collateralized tokens can be transferred.\n         */\n        require(\n            comptroller.transferAllowed(\n                address(this),\n                src,\n                dst,\n                collateralTokens\n            ) == 0,\n            \"rejected\"\n        );\n\n        /* Do not allow self-transfers */\n        require(src != dst, \"bad input\");\n\n        /* Get the allowance, infinite for the account owner */\n        uint256 startingAllowance = 0;\n        if (spender == src) {\n            startingAllowance = uint256(-1);\n        } else {\n            startingAllowance = transferAllowances[src][spender];\n        }\n\n        /* Do the calculations, checking for {under,over}flow */\n        accountTokens[src] = sub_(accountTokens[src], tokens);\n        accountTokens[dst] = add_(accountTokens[dst], tokens);\n        if (collateralTokens > 0) {\n            accountCollateralTokens[src] = sub_(\n                accountCollateralTokens[src],\n                collateralTokens\n            );\n            accountCollateralTokens[dst] = add_(\n                accountCollateralTokens[dst],\n                collateralTokens\n            );\n\n            emit UserCollateralChanged(src, accountCollateralTokens[src]);\n            emit UserCollateralChanged(dst, accountCollateralTokens[dst]);\n        }\n\n        /* Eat some of the allowance (if necessary) */\n        if (startingAllowance != uint256(-1)) {\n            transferAllowances[src][spender] = sub_(startingAllowance, tokens);\n        }\n\n        /* We emit a Transfer event */\n        emit Transfer(src, dst, tokens);\n\n        comptroller.transferVerify(address(this), src, dst, tokens);\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Get the account's bToken balances\n     * @param account The address of the account\n     */\n    function getBTokenBalanceInternal(\n        address account\n    ) internal view returns (uint256) {\n        if (isCollateralTokenInit[account]) {\n            return accountCollateralTokens[account];\n        } else {\n            /**\n             * If the value of accountCollateralTokens was not initialized, we should return the value of accountTokens.\n             */\n            return accountTokens[account];\n        }\n    }\n\n    /**\n     * @notice Increase user's collateral. Increase as much as we can.\n     * @param account The address of the account\n     * @param amount The amount of collateral user wants to increase\n     * @return The actual increased amount of collateral\n     */\n    function increaseUserCollateralInternal(\n        address account,\n        uint256 amount\n    ) internal returns (uint256) {\n        uint256 totalCollateralTokensNew = add_(totalCollateralTokens, amount);\n        if (\n            collateralCap == 0 ||\n            (collateralCap != 0 && totalCollateralTokensNew <= collateralCap)\n        ) {\n            // 1. If collateral cap is not set,\n            // 2. If collateral cap is set but has enough space for this user,\n            // give all the user needs.\n            totalCollateralTokens = totalCollateralTokensNew;\n            accountCollateralTokens[account] = add_(\n                accountCollateralTokens[account],\n                amount\n            );\n\n            emit UserCollateralChanged(\n                account,\n                accountCollateralTokens[account]\n            );\n            return amount;\n        } else if (collateralCap > totalCollateralTokens) {\n            // If the collateral cap is set but the remaining cap is not enough for this user,\n            // give the remaining parts to the user.\n            uint256 gap = sub_(collateralCap, totalCollateralTokens);\n            totalCollateralTokens = add_(totalCollateralTokens, gap);\n            accountCollateralTokens[account] = add_(\n                accountCollateralTokens[account],\n                gap\n            );\n\n            emit UserCollateralChanged(\n                account,\n                accountCollateralTokens[account]\n            );\n            return gap;\n        }\n        return 0;\n    }\n\n    /**\n     * @notice Decrease user's collateral. Reject if the amount can't be fully decrease.\n     * @param account The address of the account\n     * @param amount The amount of collateral user wants to decrease\n     */\n    function decreaseUserCollateralInternal(\n        address account,\n        uint256 amount\n    ) internal {\n        /*\n         * Return if amount is zero.\n         * Put behind `redeemAllowed` for accruing potential COMP rewards.\n         */\n        if (amount == 0) {\n            return;\n        }\n\n        totalCollateralTokens = sub_(totalCollateralTokens, amount);\n        accountCollateralTokens[account] = sub_(\n            accountCollateralTokens[account],\n            amount\n        );\n\n        emit UserCollateralChanged(account, accountCollateralTokens[account]);\n    }\n\n    struct MintLocalVars {\n        uint256 exchangeRateMantissa;\n        uint256 mintTokens;\n        uint256 actualMintAmount;\n    }\n\n    /**\n     * @notice User supplies assets into the market and receives bTokens in exchange\n     * @dev Assumes interest has already been accrued up to the current second\n     * @param minter The address of the account which is supplying the assets\n     * @param mintAmount The amount of the underlying asset to supply\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount.\n     */\n    function mintFresh(\n        address minter,\n        uint256 mintAmount,\n        bool isNative\n    ) internal returns (uint256, uint256) {\n        // Make sure accountCollateralTokens of `minter` is initialized.\n        initializeAccountCollateralTokens(minter);\n\n        /* Fail if mint not allowed */\n        require(\n            comptroller.mintAllowed(address(this), minter, mintAmount) == 0,\n            \"rejected\"\n        );\n\n        /*\n         * Return if mintAmount is zero.\n         * Put behind `mintAllowed` for accruing potential COMP rewards.\n         */\n        if (mintAmount == 0) {\n            return (uint256(Error.NO_ERROR), 0);\n        }\n\n        /* Verify market's block timestamp equals current block timestamp */\n        require(accrualBlockTimestamp == getBlockTimestamp(), \"market is stale\");\n\n        MintLocalVars memory vars;\n\n        vars.exchangeRateMantissa = exchangeRateStoredInternal();\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        /*\n         *  We call `doTransferIn` for the minter and the mintAmount.\n         *  Note: The bToken must handle variations between ERC-20 and ETH underlying.\n         *  `doTransferIn` reverts if anything goes wrong, since we can't be sure if\n         *  side-effects occurred. The function returns the amount actually transferred,\n         *  in case of a fee. On success, the bToken holds an additional `actualMintAmount`\n         *  of cash.\n         */\n        vars.actualMintAmount = doTransferIn(minter, mintAmount, isNative);\n\n        /*\n         * We get the current exchange rate and calculate the number of bTokens to be minted:\n         *  mintTokens = actualMintAmount / exchangeRate\n         */\n        vars.mintTokens = div_ScalarByExpTruncate(\n            vars.actualMintAmount,\n            Exp({mantissa: vars.exchangeRateMantissa})\n        );\n\n        /*\n         * We calculate the new total supply of bTokens and minter token balance, checking for overflow:\n         *  totalSupply = totalSupply + mintTokens\n         *  accountTokens[minter] = accountTokens[minter] + mintTokens\n         */\n        totalSupply = add_(totalSupply, vars.mintTokens);\n        accountTokens[minter] = add_(accountTokens[minter], vars.mintTokens);\n\n        /*\n         * We only allocate collateral tokens if the minter has entered the market.\n         */\n        if (\n            ComptrollerInterfaceExtension(address(comptroller)).checkMembership(\n                minter,\n                BToken(this)\n            )\n        ) {\n            increaseUserCollateralInternal(minter, vars.mintTokens);\n        }\n\n        /* We emit a Mint event, and a Transfer event */\n        emit Mint(minter, vars.actualMintAmount, vars.mintTokens);\n        emit Transfer(address(this), minter, vars.mintTokens);\n\n        /* We call the defense hook */\n        comptroller.mintVerify(\n            address(this),\n            minter,\n            vars.actualMintAmount,\n            vars.mintTokens\n        );\n\n        return (uint256(Error.NO_ERROR), vars.actualMintAmount);\n    }\n\n    struct RedeemLocalVars {\n        uint256 exchangeRateMantissa;\n        uint256 redeemTokens;\n        uint256 redeemAmount;\n        uint256 collateralTokens;\n    }\n\n    /**\n     * @notice User redeems bTokens in exchange for the underlying asset\n     * @dev Assumes interest has already been accrued up to the current second. Only one of redeemTokensIn or redeemAmountIn may be non-zero and it would do nothing if both are zero.\n     * @param redeemer The address of the account which is redeeming the tokens\n     * @param redeemTokensIn The number of bTokens to redeem into underlying\n     * @param redeemAmountIn The number of underlying tokens to receive from redeeming bTokens\n     * @param isNative The amount is in native or not\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function redeemFresh(\n        address payable redeemer,\n        uint256 redeemTokensIn,\n        uint256 redeemAmountIn,\n        bool isNative\n    ) internal returns (uint256) {\n        // Make sure accountCollateralTokens of `redeemer` is initialized.\n        initializeAccountCollateralTokens(redeemer);\n\n        require(redeemTokensIn == 0 || redeemAmountIn == 0, \"bad input\");\n\n        RedeemLocalVars memory vars;\n\n        /* exchangeRate = invoke Exchange Rate Stored() */\n        vars.exchangeRateMantissa = exchangeRateStoredInternal();\n\n        /* If redeemTokensIn > 0: */\n        if (redeemTokensIn > 0) {\n            /*\n             * We calculate the exchange rate and the amount of underlying to be redeemed:\n             *  redeemTokens = redeemTokensIn\n             *  redeemAmount = redeemTokensIn x exchangeRateCurrent\n             */\n            vars.redeemTokens = redeemTokensIn;\n            vars.redeemAmount = mul_ScalarTruncate(\n                Exp({mantissa: vars.exchangeRateMantissa}),\n                redeemTokensIn\n            );\n        } else {\n            /*\n             * We get the current exchange rate and calculate the amount to be redeemed:\n             *  redeemTokens = redeemAmountIn / exchangeRate\n             *  redeemAmount = redeemAmountIn\n             */\n            vars.redeemTokens = div_ScalarByExpTruncate(\n                redeemAmountIn,\n                Exp({mantissa: vars.exchangeRateMantissa})\n            );\n            vars.redeemAmount = redeemAmountIn;\n        }\n\n        vars.collateralTokens = getCollateralTokens(\n            vars.redeemTokens,\n            redeemer\n        );\n\n        /* redeemAllowed might check more than user's liquidity. */\n        require(\n            comptroller.redeemAllowed(\n                address(this),\n                redeemer,\n                vars.collateralTokens\n            ) == 0,\n            \"rejected\"\n        );\n\n        /* Verify market's block timestamp equals current block timestamp */\n        require(accrualBlockTimestamp == getBlockTimestamp(), \"market is stale\");\n\n        /* Reverts if protocol has insufficient cash */\n        require(getCashPrior() >= vars.redeemAmount, \"insufficient cash\");\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        /*\n         * We calculate the new total supply and redeemer balance, checking for underflow:\n         *  totalSupplyNew = totalSupply - redeemTokens\n         *  accountTokensNew = accountTokens[redeemer] - redeemTokens\n         */\n        totalSupply = sub_(totalSupply, vars.redeemTokens);\n        accountTokens[redeemer] = sub_(\n            accountTokens[redeemer],\n            vars.redeemTokens\n        );\n\n        /*\n         * We only deallocate collateral tokens if the redeemer needs to redeem them.\n         */\n        decreaseUserCollateralInternal(redeemer, vars.collateralTokens);\n\n        /*\n         * We invoke doTransferOut for the redeemer and the redeemAmount.\n         *  Note: The bToken must handle variations between ERC-20 and ETH underlying.\n         *  On success, the bToken has redeemAmount less of cash.\n         *  doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.\n         */\n        doTransferOut(redeemer, vars.redeemAmount, isNative);\n\n        /* We emit a Transfer event, and a Redeem event */\n        emit Transfer(redeemer, address(this), vars.redeemTokens);\n        emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens);\n\n        /* We call the defense hook */\n        comptroller.redeemVerify(\n            address(this),\n            redeemer,\n            vars.redeemAmount,\n            vars.redeemTokens\n        );\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Transfers collateral tokens (this market) to the liquidator.\n     * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another BToken.\n     *  Its absolutely critical to use msg.sender as the seizer bToken and not a parameter.\n     * @param seizerToken The contract seizing the collateral (i.e. borrowed bToken)\n     * @param liquidator The account receiving seized collateral\n     * @param borrower The account having collateral seized\n     * @param seizeTokens The number of bTokens to seize\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function seizeInternal(\n        address seizerToken,\n        address liquidator,\n        address borrower,\n        uint256 seizeTokens\n    ) internal returns (uint256) {\n        // Make sure accountCollateralTokens of `liquidator` and `borrower` are initialized.\n        initializeAccountCollateralTokens(liquidator);\n        initializeAccountCollateralTokens(borrower);\n\n        uint256 collateralTokens = getCollateralTokens(seizeTokens, borrower);\n\n        /* Fail if seize not allowed */\n        require(\n            comptroller.seizeAllowed(\n                address(this),\n                seizerToken,\n                liquidator,\n                borrower,\n                collateralTokens\n            ) == 0,\n            \"rejected\"\n        );\n\n        /* Fail if borrower = liquidator */\n        require(borrower != liquidator, \"invalid account pair\");\n\n        /*\n         * We calculate the new borrower and liquidator token balances and token collateral balances, failing on underflow/overflow:\n         *  accountTokens[borrower] = accountTokens[borrower] - seizeTokens\n         *  accountTokens[liquidator] = accountTokens[liquidator] + seizeTokens\n         *  accountCollateralTokens[borrower] = accountCollateralTokens[borrower] - collateralTokens\n         *  accountCollateralTokens[liquidator] = accountCollateralTokens[liquidator] + collateralTokens\n         */\n        accountTokens[borrower] = sub_(accountTokens[borrower], seizeTokens);\n        accountTokens[liquidator] = add_(\n            accountTokens[liquidator],\n            seizeTokens\n        );\n        if (collateralTokens > 0) {\n            accountCollateralTokens[borrower] = sub_(\n                accountCollateralTokens[borrower],\n                collateralTokens\n            );\n            accountCollateralTokens[liquidator] = add_(\n                accountCollateralTokens[liquidator],\n                collateralTokens\n            );\n\n            emit UserCollateralChanged(\n                borrower,\n                accountCollateralTokens[borrower]\n            );\n            emit UserCollateralChanged(\n                liquidator,\n                accountCollateralTokens[liquidator]\n            );\n        }\n\n        /* Emit a Transfer event */\n        emit Transfer(borrower, liquidator, seizeTokens);\n\n        /* We call the defense hook */\n        comptroller.seizeVerify(\n            address(this),\n            seizerToken,\n            liquidator,\n            borrower,\n            seizeTokens\n        );\n\n        return uint256(Error.NO_ERROR);\n    }\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/BToken.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"./ComptrollerInterface.sol\";\nimport \"./BTokenInterfaces.sol\";\nimport \"./ErrorReporter.sol\";\nimport \"./Exponential.sol\";\nimport \"./EIP20Interface.sol\";\nimport \"./EIP20NonStandardInterface.sol\";\nimport \"./InterestRateModel.sol\";\n\n/**\n * @title Blueberry's BToken Contract\n * @notice Abstract base for BTokens\n * @author Compound (Modifed by Blueberry)\n */\ncontract BToken is BTokenInterface, Exponential, TokenErrorReporter {\n    /**\n     * @notice Initialize the money market\n     * @param comptroller_ The address of the Comptroller\n     * @param interestRateModel_ The address of the interest rate model\n     * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18\n     * @param name_ EIP-20 name of this token\n     * @param symbol_ EIP-20 symbol of this token\n     * @param decimals_ EIP-20 decimal precision of this token\n     */\n    function initialize(\n        ComptrollerInterface comptroller_,\n        InterestRateModel interestRateModel_,\n        uint256 initialExchangeRateMantissa_,\n        string memory name_,\n        string memory symbol_,\n        uint8 decimals_\n    ) public {\n        require(msg.sender == admin, \"admin only\");\n        require(accrualBlockTimestamp == 0 && borrowIndex == 0, \"initialized\");\n\n        // Set initial exchange rate\n        initialExchangeRateMantissa = initialExchangeRateMantissa_;\n        require(initialExchangeRateMantissa > 0, \"invalid exchange rate\");\n\n        // Set the comptroller\n        uint256 err = _setComptroller(comptroller_);\n        require(err == uint256(Error.NO_ERROR), \"set comptroller failed\");\n\n        // Initialize block timestamp and borrow index (block timestamp mocks depend on comptroller being set)\n        accrualBlockTimestamp = getBlockTimestamp();\n        borrowIndex = mantissaOne;\n\n        // Set the interest rate model (depends on block timestamp / borrow index)\n        err = _setInterestRateModelFresh(interestRateModel_);\n        require(err == uint256(Error.NO_ERROR), \"set IRM failed\");\n\n        name = name_;\n        symbol = symbol_;\n        decimals = decimals_;\n\n        // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund)\n        _notEntered = true;\n    }\n\n    /**\n     * @notice Transfer `amount` tokens from `msg.sender` to `dst`\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     * @return Whether or not the transfer succeeded\n     */\n    function transfer(address dst, uint256 amount)\n        external\n        nonReentrant\n        returns (bool)\n    {\n        return\n            transferTokens(msg.sender, msg.sender, dst, amount) ==\n            uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Transfer `amount` tokens from `src` to `dst`\n     * @param src The address of the source account\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     * @return Whether or not the transfer succeeded\n     */\n    function transferFrom(\n        address src,\n        address dst,\n        uint256 amount\n    ) external nonReentrant returns (bool) {\n        return\n            transferTokens(msg.sender, src, dst, amount) ==\n            uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Approve `spender` to transfer up to `amount` from `src`\n     * @dev This will overwrite the approval amount for `spender`\n     *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)\n     * @param spender The address of the account which may transfer tokens\n     * @param amount The number of tokens that are approved (-1 means infinite)\n     * @return Whether or not the approval succeeded\n     */\n    function approve(address spender, uint256 amount) external returns (bool) {\n        address src = msg.sender;\n        transferAllowances[src][spender] = amount;\n        emit Approval(src, spender, amount);\n        return true;\n    }\n\n    /**\n     * @notice Get the current allowance from `owner` for `spender`\n     * @param owner The address of the account which owns the tokens to be spent\n     * @param spender The address of the account which may transfer tokens\n     * @return The number of tokens allowed to be spent (-1 means infinite)\n     */\n    function allowance(address owner, address spender)\n        external\n        view\n        returns (uint256)\n    {\n        return transferAllowances[owner][spender];\n    }\n\n    /**\n     * @notice Get the token balance of the `owner`\n     * @param owner The address of the account to query\n     * @return The number of tokens owned by `owner`\n     */\n    function balanceOf(address owner) external view returns (uint256) {\n        return accountTokens[owner];\n    }\n\n    /**\n     * @notice Get the underlying balance of the `owner`\n     * @dev This also accrues interest in a transaction\n     * @param owner The address of the account to query\n     * @return The amount of underlying owned by `owner`\n     */\n    function balanceOfUnderlying(address owner) external returns (uint256) {\n        Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()});\n        return mul_ScalarTruncate(exchangeRate, accountTokens[owner]);\n    }\n\n    /**\n     * @notice Get a snapshot of the account's balances, and the cached exchange rate\n     * @dev This is used by comptroller to more efficiently perform liquidity checks.\n     * @param account Address of the account to snapshot\n     * @return (possible error, token balance, borrow balance, exchange rate mantissa)\n     */\n    function getAccountSnapshot(address account)\n        external\n        view\n        returns (\n            uint256,\n            uint256,\n            uint256,\n            uint256\n        )\n    {\n        uint256 bTokenBalance = getBTokenBalanceInternal(account);\n        uint256 borrowBalance = borrowBalanceStoredInternal(account);\n        uint256 exchangeRateMantissa = exchangeRateStoredInternal();\n\n        return (\n            uint256(Error.NO_ERROR),\n            bTokenBalance,\n            borrowBalance,\n            exchangeRateMantissa\n        );\n    }\n\n    /**\n     * @dev Function to simply retrieve block timestamp\n     *  This exists mainly for inheriting test contracts to stub this result.\n     */\n    function getBlockTimestamp() internal view returns (uint256) {\n        return block.timestamp;\n    }\n\n    /**\n     * @notice Returns the current per-second borrow interest rate for this bToken\n     * @return The borrow interest rate per second, scaled by 1e18\n     */\n    function borrowRatePerSecond() external view returns (uint256) {\n        return\n            interestRateModel.getBorrowRate(\n                getCashPrior(),\n                totalBorrows,\n                totalReserves\n            );\n    }\n\n    /**\n     * @notice Returns the current per-second supply interest rate for this bToken\n     * @return The supply interest rate per second, scaled by 1e18\n     */\n    function supplyRatePerSecond() external view returns (uint256) {\n        return\n            interestRateModel.getSupplyRate(\n                getCashPrior(),\n                totalBorrows,\n                totalReserves,\n                reserveFactorMantissa\n            );\n    }\n\n    /**\n     * @notice Returns the estimated per-second borrow interest rate for this bToken after some change\n     * @return The borrow interest rate per second, scaled by 1e18\n     */\n    function estimateBorrowRatePerSecondAfterChange(uint256 change, bool repay)\n        external\n        view\n        returns (uint256)\n    {\n        uint256 cashPriorNew;\n        uint256 totalBorrowsNew;\n\n        if (repay) {\n            cashPriorNew = add_(getCashPrior(), change);\n            totalBorrowsNew = sub_(totalBorrows, change);\n        } else {\n            cashPriorNew = sub_(getCashPrior(), change);\n            totalBorrowsNew = add_(totalBorrows, change);\n        }\n        return\n            interestRateModel.getBorrowRate(\n                cashPriorNew,\n                totalBorrowsNew,\n                totalReserves\n            );\n    }\n\n    /**\n     * @notice Returns the estimated per-second supply interest rate for this bToken after some change\n     * @return The supply interest rate per second, scaled by 1e18\n     */\n    function estimateSupplyRatePerSecondAfterChange(uint256 change, bool repay)\n        external\n        view\n        returns (uint256)\n    {\n        uint256 cashPriorNew;\n        uint256 totalBorrowsNew;\n\n        if (repay) {\n            cashPriorNew = add_(getCashPrior(), change);\n            totalBorrowsNew = sub_(totalBorrows, change);\n        } else {\n            cashPriorNew = sub_(getCashPrior(), change);\n            totalBorrowsNew = add_(totalBorrows, change);\n        }\n\n        return\n            interestRateModel.getSupplyRate(\n                cashPriorNew,\n                totalBorrowsNew,\n                totalReserves,\n                reserveFactorMantissa\n            );\n    }\n\n    /**\n     * @notice Returns the current total borrows plus accrued interest\n     * @return The total borrows with interest\n     */\n    function totalBorrowsCurrent() external nonReentrant returns (uint256) {\n        accrueInterest();\n        return totalBorrows;\n    }\n\n    /**\n     * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex\n     * @param account The address whose balance should be calculated after updating borrowIndex\n     * @return The calculated balance\n     */\n    function borrowBalanceCurrent(address account)\n        external\n        nonReentrant\n        returns (uint256)\n    {\n        accrueInterest();\n        return borrowBalanceStored(account);\n    }\n\n    /**\n     * @notice Return the borrow balance of account based on stored data\n     * @param account The address whose balance should be calculated\n     * @return The calculated balance\n     */\n    function borrowBalanceStored(address account)\n        public\n        view\n        returns (uint256)\n    {\n        return borrowBalanceStoredInternal(account);\n    }\n\n    /**\n     * @notice Return the borrow balance of account based on stored data\n     * @param account The address whose balance should be calculated\n     * @return the calculated balance or 0 if error code is non-zero\n     */\n    function borrowBalanceStoredInternal(address account)\n        internal\n        view\n        returns (uint256)\n    {\n        /* Get borrowBalance and borrowIndex */\n        BorrowSnapshot storage borrowSnapshot = accountBorrows[account];\n\n        /* If borrowBalance = 0 then borrowIndex is likely also 0.\n         * Rather than failing the calculation with a division by 0, we immediately return 0 in this case.\n         */\n        if (borrowSnapshot.principal == 0) {\n            return 0;\n        }\n\n        /* Calculate new borrow balance using the interest index:\n         *  recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex\n         */\n        uint256 principalTimesIndex = mul_(\n            borrowSnapshot.principal,\n            borrowIndex\n        );\n        uint256 result = div_(\n            principalTimesIndex,\n            borrowSnapshot.interestIndex\n        );\n        return result;\n    }\n\n    /**\n     * @notice Accrue interest then return the up-to-date exchange rate\n     * @return Calculated exchange rate scaled by 1e18\n     */\n    function exchangeRateCurrent() public nonReentrant returns (uint256) {\n        accrueInterest();\n        return exchangeRateStored();\n    }\n\n    /**\n     * @notice Calculates the exchange rate from the underlying to the BToken\n     * @dev This function does not accrue interest before calculating the exchange rate\n     * @return Calculated exchange rate scaled by 1e18\n     */\n    function exchangeRateStored() public view returns (uint256) {\n        return exchangeRateStoredInternal();\n    }\n\n    /**\n     * @notice Calculates the exchange rate from the underlying to the BToken\n     * @dev This function does not accrue interest before calculating the exchange rate\n     * @return calculated exchange rate scaled by 1e18\n     */\n    function exchangeRateStoredInternal() internal view returns (uint256) {\n        uint256 _totalSupply = totalSupply;\n        if (_totalSupply == 0) {\n            /*\n             * If there are no tokens minted:\n             *  exchangeRate = initialExchangeRate\n             */\n            return initialExchangeRateMantissa;\n        } else {\n            /*\n             * Otherwise:\n             *  exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply\n             */\n            uint256 totalCash = getCashPrior();\n            uint256 cashPlusBorrowsMinusReserves = sub_(\n                add_(totalCash, totalBorrows),\n                totalReserves\n            );\n            uint256 exchangeRate = div_(\n                cashPlusBorrowsMinusReserves,\n                Exp({mantissa: _totalSupply})\n            );\n            return exchangeRate;\n        }\n    }\n\n    /**\n     * @notice Get cash balance of this bToken in the underlying asset\n     * @return The quantity of underlying asset owned by this contract\n     */\n    function getCash() external view returns (uint256) {\n        return getCashPrior();\n    }\n\n    /**\n     * @notice Applies accrued interest to total borrows and reserves\n     * @dev This calculates interest accrued from the last checkpointed second\n     *   up to the current block timestamp and writes new checkpoint to storage.\n     */\n    function accrueInterest() public returns (uint256) {\n        /* Remember the initial block timestamp */\n        uint256 currentBlockTimestamp = getBlockTimestamp();\n        uint256 accrualBlockTimestampPrior = accrualBlockTimestamp;\n\n        /* Short-circuit accumulating 0 interest */\n        if (accrualBlockTimestampPrior == currentBlockTimestamp) {\n            return uint256(Error.NO_ERROR);\n        }\n\n        /* Read the previous values out of storage */\n        uint256 cashPrior = getCashPrior();\n        uint256 borrowsPrior = totalBorrows;\n        uint256 reservesPrior = totalReserves;\n        uint256 borrowIndexPrior = borrowIndex;\n\n        /* Calculate the current borrow interest rate */\n        uint256 borrowRateMantissa = interestRateModel.getBorrowRate(\n            cashPrior,\n            borrowsPrior,\n            reservesPrior\n        );\n        require(\n            borrowRateMantissa <= borrowRateMaxMantissa,\n            \"borrow rate too high\"\n        );\n\n        /* Calculate the number of seconds elapsed since the last accrual */\n        uint256 timestampDelta = sub_(currentBlockTimestamp, accrualBlockTimestampPrior);\n\n        /*\n         * Calculate the interest accumulated into borrows and reserves and the new index:\n         *  simpleInterestFactor = borrowRate * timestampDelta\n         *  interestAccumulated = simpleInterestFactor * totalBorrows\n         *  totalBorrowsNew = interestAccumulated + totalBorrows\n         *  totalReservesNew = interestAccumulated * reserveFactor + totalReserves\n         *  borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex\n         */\n\n        Exp memory simpleInterestFactor = mul_(\n            Exp({mantissa: borrowRateMantissa}),\n            timestampDelta\n        );\n        uint256 interestAccumulated = mul_ScalarTruncate(\n            simpleInterestFactor,\n            borrowsPrior\n        );\n        uint256 totalBorrowsNew = add_(interestAccumulated, borrowsPrior);\n        uint256 totalReservesNew = mul_ScalarTruncateAddUInt(\n            Exp({mantissa: reserveFactorMantissa}),\n            interestAccumulated,\n            reservesPrior\n        );\n        uint256 borrowIndexNew = mul_ScalarTruncateAddUInt(\n            simpleInterestFactor,\n            borrowIndexPrior,\n            borrowIndexPrior\n        );\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        /* We write the previously calculated values into storage */\n        accrualBlockTimestamp = currentBlockTimestamp;\n        borrowIndex = borrowIndexNew;\n        totalBorrows = totalBorrowsNew;\n        totalReserves = totalReservesNew;\n\n        /* We emit an AccrueInterest event */\n        emit AccrueInterest(\n            cashPrior,\n            interestAccumulated,\n            borrowIndexNew,\n            totalBorrowsNew\n        );\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Sender supplies assets into the market and receives bTokens in exchange\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\n     * @param mintAmount The amount of the underlying asset to supply\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount.\n     */\n    function mintInternal(uint256 mintAmount, bool isNative)\n        internal\n        nonReentrant\n        returns (uint256, uint256)\n    {\n        accrueInterest();\n        // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to\n        return mintFresh(msg.sender, mintAmount, isNative);\n    }\n\n    /**\n     * @notice Sender redeems bTokens in exchange for the underlying asset\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\n     * @param redeemTokens The number of bTokens to redeem into underlying\n     * @param isNative The amount is in native or not\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function redeemInternal(uint256 redeemTokens, bool isNative)\n        internal\n        nonReentrant\n        returns (uint256)\n    {\n        accrueInterest();\n        // redeemFresh emits redeem-specific logs on errors, so we don't need to\n        return redeemFresh(msg.sender, redeemTokens, 0, isNative);\n    }\n\n    /**\n     * @notice Sender redeems bTokens in exchange for a specified amount of underlying asset\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\n     * @param redeemAmount The amount of underlying to receive from redeeming bTokens\n     * @param isNative The amount is in native or not\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function redeemUnderlyingInternal(uint256 redeemAmount, bool isNative)\n        internal\n        nonReentrant\n        returns (uint256)\n    {\n        accrueInterest();\n        // redeemFresh emits redeem-specific logs on errors, so we don't need to\n        return redeemFresh(msg.sender, 0, redeemAmount, isNative);\n    }\n\n    /**\n     * @notice Sender borrows assets from the protocol to their own address\n     * @param borrowAmount The amount of the underlying asset to borrow\n     * @param isNative The amount is in native or not\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function borrowInternal(uint256 borrowAmount, bool isNative)\n        internal\n        nonReentrant\n        returns (uint256)\n    {\n        accrueInterest();\n        // borrowFresh emits borrow-specific logs on errors, so we don't need to\n        return borrowFresh(msg.sender, borrowAmount, isNative);\n    }\n\n    struct BorrowLocalVars {\n        MathError mathErr;\n        uint256 accountBorrows;\n        uint256 accountBorrowsNew;\n        uint256 totalBorrowsNew;\n    }\n\n    /**\n     * @notice Users borrow assets from the protocol to their own address\n     * @param borrowAmount The amount of the underlying asset to borrow\n     * @param isNative The amount is in native or not\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function borrowFresh(\n        address payable borrower,\n        uint256 borrowAmount,\n        bool isNative\n    ) internal returns (uint256) {\n        /* Fail if borrow not allowed */\n        require(\n            comptroller.borrowAllowed(address(this), borrower, borrowAmount) ==\n                0,\n            \"rejected\"\n        );\n\n        /* Verify market's block timestamp equals current block timestamp */\n        require(accrualBlockTimestamp == getBlockTimestamp(), \"market is stale\");\n\n        /* Reverts if protocol has insufficient cash */\n        require(getCashPrior() >= borrowAmount, \"insufficient cash\");\n\n        BorrowLocalVars memory vars;\n\n        /*\n         * We calculate the new borrower and total borrow balances, failing on overflow:\n         *  accountBorrowsNew = accountBorrows + borrowAmount\n         *  totalBorrowsNew = totalBorrows + borrowAmount\n         */\n        vars.accountBorrows = borrowBalanceStoredInternal(borrower);\n        vars.accountBorrowsNew = add_(vars.accountBorrows, borrowAmount);\n        vars.totalBorrowsNew = add_(totalBorrows, borrowAmount);\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        /* We write the previously calculated values into storage */\n        accountBorrows[borrower].principal = vars.accountBorrowsNew;\n        accountBorrows[borrower].interestIndex = borrowIndex;\n        totalBorrows = vars.totalBorrowsNew;\n\n        /*\n         * We invoke doTransferOut for the borrower and the borrowAmount.\n         *  Note: The bToken must handle variations between ERC-20 and ETH underlying.\n         *  On success, the bToken borrowAmount less of cash.\n         *  doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.\n         */\n        doTransferOut(borrower, borrowAmount, isNative);\n\n        /* We emit a Borrow event */\n        emit Borrow(\n            borrower,\n            borrowAmount,\n            vars.accountBorrowsNew,\n            vars.totalBorrowsNew\n        );\n\n        /* We call the defense hook */\n        comptroller.borrowVerify(address(this), borrower, borrowAmount);\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Sender repays their own borrow\n     * @param repayAmount The amount to repay\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.\n     */\n    function repayBorrowInternal(uint256 repayAmount, bool isNative)\n        internal\n        nonReentrant\n        returns (uint256, uint256)\n    {\n        accrueInterest();\n        // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to\n        return repayBorrowFresh(msg.sender, msg.sender, repayAmount, isNative);\n    }\n\n    /**\n     * @notice Sender repays a borrow belonging to borrower\n     * @param borrower the account with the debt being payed off\n     * @param repayAmount The amount to repay\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.\n     */\n    function repayBorrowBehalfInternal(\n        address borrower,\n        uint256 repayAmount,\n        bool isNative\n    ) internal nonReentrant returns (uint256, uint256) {\n        accrueInterest();\n        // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to\n        return repayBorrowFresh(msg.sender, borrower, repayAmount, isNative);\n    }\n\n    struct RepayBorrowLocalVars {\n        Error err;\n        MathError mathErr;\n        uint256 repayAmount;\n        uint256 borrowerIndex;\n        uint256 accountBorrows;\n        uint256 accountBorrowsNew;\n        uint256 totalBorrowsNew;\n        uint256 actualRepayAmount;\n    }\n\n    /**\n     * @notice Borrows are repaid by another user (possibly the borrower).\n     * @param payer the account paying off the borrow\n     * @param borrower the account with the debt being payed off\n     * @param repayAmount the amount of underlying tokens being returned\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.\n     */\n    function repayBorrowFresh(\n        address payer,\n        address borrower,\n        uint256 repayAmount,\n        bool isNative\n    ) internal returns (uint256, uint256) {\n        /* Fail if repayBorrow not allowed */\n        require(\n            comptroller.repayBorrowAllowed(\n                address(this),\n                payer,\n                borrower,\n                repayAmount\n            ) == 0,\n            \"rejected\"\n        );\n\n        /* Verify market's block timestamp equals current block timestamp */\n        require(accrualBlockTimestamp == getBlockTimestamp(), \"market is stale\");\n\n        RepayBorrowLocalVars memory vars;\n\n        /* We remember the original borrowerIndex for verification purposes */\n        vars.borrowerIndex = accountBorrows[borrower].interestIndex;\n\n        /* We fetch the amount the borrower owes, with accumulated interest */\n        vars.accountBorrows = borrowBalanceStoredInternal(borrower);\n\n        /* If repayAmount == -1, repayAmount = accountBorrows */\n        if (repayAmount == uint256(-1)) {\n            vars.repayAmount = vars.accountBorrows;\n        } else {\n            vars.repayAmount = repayAmount;\n        }\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        /*\n         * We call doTransferIn for the payer and the repayAmount\n         *  Note: The bToken must handle variations between ERC-20 and ETH underlying.\n         *  On success, the bToken holds an additional repayAmount of cash.\n         *  doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred.\n         *   it returns the amount actually transferred, in case of a fee.\n         */\n        vars.actualRepayAmount = doTransferIn(\n            payer,\n            vars.repayAmount,\n            isNative\n        );\n\n        /*\n         * We calculate the new borrower and total borrow balances, failing on underflow:\n         *  accountBorrowsNew = accountBorrows - actualRepayAmount\n         *  totalBorrowsNew = totalBorrows - actualRepayAmount\n         */\n        vars.accountBorrowsNew = sub_(\n            vars.accountBorrows,\n            vars.actualRepayAmount\n        );\n        vars.totalBorrowsNew = sub_(totalBorrows, vars.actualRepayAmount);\n\n        /* We write the previously calculated values into storage */\n        accountBorrows[borrower].principal = vars.accountBorrowsNew;\n        accountBorrows[borrower].interestIndex = borrowIndex;\n        totalBorrows = vars.totalBorrowsNew;\n\n        /* We emit a RepayBorrow event */\n        emit RepayBorrow(\n            payer,\n            borrower,\n            vars.actualRepayAmount,\n            vars.accountBorrowsNew,\n            vars.totalBorrowsNew\n        );\n\n        /* We call the defense hook */\n        comptroller.repayBorrowVerify(\n            address(this),\n            payer,\n            borrower,\n            vars.actualRepayAmount,\n            vars.borrowerIndex\n        );\n\n        return (uint256(Error.NO_ERROR), vars.actualRepayAmount);\n    }\n\n    /**\n     * @notice The sender liquidates the borrowers collateral.\n     *  The collateral seized is transferred to the liquidator.\n     * @param borrower The borrower of this bToken to be liquidated\n     * @param repayAmount The amount of the underlying borrowed asset to repay\n     * @param bTokenCollateral The market in which to seize collateral from the borrower\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.\n     */\n    function liquidateBorrowInternal(\n        address borrower,\n        uint256 repayAmount,\n        BTokenInterface bTokenCollateral,\n        bool isNative\n    ) internal nonReentrant returns (uint256, uint256) {\n        accrueInterest();\n        require(\n            bTokenCollateral.accrueInterest() == uint256(Error.NO_ERROR),\n            \"accrue interest failed\"\n        );\n\n        // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to\n        return\n            liquidateBorrowFresh(\n                msg.sender,\n                borrower,\n                repayAmount,\n                bTokenCollateral,\n                isNative\n            );\n    }\n\n    struct LiquidateBorrowLocalVars {\n        uint256 repayBorrowError;\n        uint256 actualRepayAmount;\n        uint256 amountSeizeError;\n        uint256 seizeTokens;\n    }\n\n    /**\n     * @notice The liquidator liquidates the borrowers collateral.\n     *  The collateral seized is transferred to the liquidator.\n     * @param borrower The borrower of this bToken to be liquidated\n     * @param liquidator The address repaying the borrow and seizing collateral\n     * @param bTokenCollateral The market in which to seize collateral from the borrower\n     * @param repayAmount The amount of the underlying borrowed asset to repay\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount.\n     */\n    function liquidateBorrowFresh(\n        address liquidator,\n        address borrower,\n        uint256 repayAmount,\n        BTokenInterface bTokenCollateral,\n        bool isNative\n    ) internal returns (uint256, uint256) {\n        /* Fail if liquidate not allowed */\n        require(\n            comptroller.liquidateBorrowAllowed(\n                address(this),\n                address(bTokenCollateral),\n                liquidator,\n                borrower,\n                repayAmount\n            ) == 0,\n            \"rejected\"\n        );\n\n        /* Verify market's block timestamp equals current block timestamp */\n        require(accrualBlockTimestamp == getBlockTimestamp(), \"market is stale\");\n\n        /* Verify bTokenCollateral market's block timestamp equals current block timestamp */\n        require(\n            bTokenCollateral.accrualBlockTimestamp() == getBlockTimestamp(),\n            \"market is stale\"\n        );\n\n        /* Fail if borrower = liquidator */\n        require(borrower != liquidator, \"invalid account pair\");\n\n        /* Fail if repayAmount = 0 or repayAmount = -1 */\n        require(\n            repayAmount > 0 && repayAmount != uint256(-1),\n            \"invalid amount\"\n        );\n\n        LiquidateBorrowLocalVars memory vars;\n\n        /* Fail if repayBorrow fails */\n        (vars.repayBorrowError, vars.actualRepayAmount) = repayBorrowFresh(\n            liquidator,\n            borrower,\n            repayAmount,\n            isNative\n        );\n        require(\n            vars.repayBorrowError == uint256(Error.NO_ERROR),\n            \"repay borrow failed\"\n        );\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        /* We calculate the number of collateral tokens that will be seized */\n        (vars.amountSeizeError, vars.seizeTokens) = comptroller\n            .liquidateCalculateSeizeTokens(\n                address(this),\n                address(bTokenCollateral),\n                vars.actualRepayAmount\n            );\n        require(\n            vars.amountSeizeError == uint256(Error.NO_ERROR),\n            \"calculate seize amount failed\"\n        );\n\n        /* Revert if borrower collateral token balance < seizeTokens */\n        require(\n            bTokenCollateral.balanceOf(borrower) >= vars.seizeTokens,\n            \"seize too much\"\n        );\n\n        // If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call\n        uint256 seizeError;\n        if (address(bTokenCollateral) == address(this)) {\n            seizeError = seizeInternal(\n                address(this),\n                liquidator,\n                borrower,\n                vars.seizeTokens\n            );\n        } else {\n            seizeError = bTokenCollateral.seize(\n                liquidator,\n                borrower,\n                vars.seizeTokens\n            );\n        }\n\n        /* Revert if seize tokens fails (since we cannot be sure of side effects) */\n        require(seizeError == uint256(Error.NO_ERROR), \"token seizure failed\");\n\n        /* We emit a LiquidateBorrow event */\n        emit LiquidateBorrow(\n            liquidator,\n            borrower,\n            vars.actualRepayAmount,\n            address(bTokenCollateral),\n            vars.seizeTokens\n        );\n\n        /* We call the defense hook */\n        comptroller.liquidateBorrowVerify(\n            address(this),\n            address(bTokenCollateral),\n            liquidator,\n            borrower,\n            vars.actualRepayAmount,\n            vars.seizeTokens\n        );\n\n        return (uint256(Error.NO_ERROR), vars.actualRepayAmount);\n    }\n\n    /**\n     * @notice Transfers collateral tokens (this market) to the liquidator.\n     * @dev Will fail unless called by another bToken during the process of liquidation.\n     *  Its absolutely critical to use msg.sender as the borrowed bToken and not a parameter.\n     * @param liquidator The account receiving seized collateral\n     * @param borrower The account having collateral seized\n     * @param seizeTokens The number of bTokens to seize\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function seize(\n        address liquidator,\n        address borrower,\n        uint256 seizeTokens\n    ) external nonReentrant returns (uint256) {\n        return seizeInternal(msg.sender, liquidator, borrower, seizeTokens);\n    }\n\n    /*** Admin Functions ***/\n\n    /**\n     * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.\n     * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer.\n     * @param newPendingAdmin New pending admin.\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _setPendingAdmin(address payable newPendingAdmin)\n        external\n        returns (uint256)\n    {\n        // Check caller = admin\n        if (msg.sender != admin) {\n            return\n                fail(\n                    Error.UNAUTHORIZED,\n                    FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK\n                );\n        }\n\n        // Save current value, if any, for inclusion in log\n        address oldPendingAdmin = pendingAdmin;\n\n        // Store pendingAdmin with value newPendingAdmin\n        pendingAdmin = newPendingAdmin;\n\n        // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)\n        emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin);\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin\n     * @dev Admin function for pending admin to accept role and update admin\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _acceptAdmin() external returns (uint256) {\n        // Check caller is pendingAdmin and pendingAdmin ≠ address(0)\n        if (msg.sender != pendingAdmin || msg.sender == address(0)) {\n            return\n                fail(\n                    Error.UNAUTHORIZED,\n                    FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK\n                );\n        }\n\n        // Save current values for inclusion in log\n        address oldAdmin = admin;\n        address oldPendingAdmin = pendingAdmin;\n\n        // Store admin with value pendingAdmin\n        admin = pendingAdmin;\n\n        // Clear the pending value\n        pendingAdmin = address(0);\n\n        emit NewAdmin(oldAdmin, admin);\n        emit NewPendingAdmin(oldPendingAdmin, pendingAdmin);\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Sets a new comptroller for the market\n     * @dev Admin function to set a new comptroller\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _setComptroller(ComptrollerInterface newComptroller)\n        public\n        returns (uint256)\n    {\n        // Check caller is admin\n        if (msg.sender != admin) {\n            return\n                fail(\n                    Error.UNAUTHORIZED,\n                    FailureInfo.SET_COMPTROLLER_OWNER_CHECK\n                );\n        }\n\n        ComptrollerInterface oldComptroller = comptroller;\n        // Ensure invoke comptroller.isComptroller() returns true\n        require(newComptroller.isComptroller(), \"not comptroller\");\n\n        // Set market's comptroller to newComptroller\n        comptroller = newComptroller;\n\n        // Emit NewComptroller(oldComptroller, newComptroller)\n        emit NewComptroller(oldComptroller, newComptroller);\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh\n     * @dev Admin function to accrue interest and set a new reserve factor\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _setReserveFactor(uint256 newReserveFactorMantissa)\n        external\n        nonReentrant\n        returns (uint256)\n    {\n        accrueInterest();\n        // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to.\n        return _setReserveFactorFresh(newReserveFactorMantissa);\n    }\n\n    /**\n     * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual)\n     * @dev Admin function to set a new reserve factor\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _setReserveFactorFresh(uint256 newReserveFactorMantissa)\n        internal\n        returns (uint256)\n    {\n        // Check caller is admin\n        if (msg.sender != admin) {\n            return\n                fail(\n                    Error.UNAUTHORIZED,\n                    FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK\n                );\n        }\n\n        // Verify market's block timestamp equals current block timestamp\n        if (accrualBlockTimestamp != getBlockTimestamp()) {\n            return\n                fail(\n                    Error.MARKET_NOT_FRESH,\n                    FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK\n                );\n        }\n\n        // Check newReserveFactor ≤ maxReserveFactor\n        if (newReserveFactorMantissa > reserveFactorMaxMantissa) {\n            return\n                fail(\n                    Error.BAD_INPUT,\n                    FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK\n                );\n        }\n\n        uint256 oldReserveFactorMantissa = reserveFactorMantissa;\n        reserveFactorMantissa = newReserveFactorMantissa;\n\n        emit NewReserveFactor(\n            oldReserveFactorMantissa,\n            newReserveFactorMantissa\n        );\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice Accrues interest and reduces reserves by transferring from msg.sender\n     * @param addAmount Amount of addition to reserves\n     * @param isNative The amount is in native or not\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _addReservesInternal(uint256 addAmount, bool isNative)\n        internal\n        nonReentrant\n        returns (uint256)\n    {\n        accrueInterest();\n        // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to.\n        (uint256 error, ) = _addReservesFresh(addAmount, isNative);\n        return error;\n    }\n\n    /**\n     * @notice Add reserves by transferring from caller\n     * @dev Requires fresh interest accrual\n     * @param addAmount Amount of addition to reserves\n     * @param isNative The amount is in native or not\n     * @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees\n     */\n    function _addReservesFresh(uint256 addAmount, bool isNative)\n        internal\n        returns (uint256, uint256)\n    {\n        // totalReserves + actualAddAmount\n        uint256 totalReservesNew;\n        uint256 actualAddAmount;\n\n        // We fail gracefully unless market's block timestamp equals current block timestamp\n        if (accrualBlockTimestamp != getBlockTimestamp()) {\n            return (\n                fail(\n                    Error.MARKET_NOT_FRESH,\n                    FailureInfo.ADD_RESERVES_FRESH_CHECK\n                ),\n                actualAddAmount\n            );\n        }\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        /*\n         * We call doTransferIn for the caller and the addAmount\n         *  Note: The bToken must handle variations between ERC-20 and ETH underlying.\n         *  On success, the bToken holds an additional addAmount of cash.\n         *  doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred.\n         *  it returns the amount actually transferred, in case of a fee.\n         */\n\n        actualAddAmount = doTransferIn(msg.sender, addAmount, isNative);\n\n        totalReservesNew = add_(totalReserves, actualAddAmount);\n\n        // Store reserves[n+1] = reserves[n] + actualAddAmount\n        totalReserves = totalReservesNew;\n\n        /* Emit NewReserves(admin, actualAddAmount, reserves[n+1]) */\n        emit ReservesAdded(msg.sender, actualAddAmount, totalReservesNew);\n\n        /* Return (NO_ERROR, actualAddAmount) */\n        return (uint256(Error.NO_ERROR), actualAddAmount);\n    }\n\n    /**\n     * @notice Accrues interest and reduces reserves by transferring to admin\n     * @param reduceAmount Amount of reduction to reserves\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _reduceReserves(uint256 reduceAmount)\n        external\n        nonReentrant\n        returns (uint256)\n    {\n        accrueInterest();\n        // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to.\n        return _reduceReservesFresh(reduceAmount);\n    }\n\n    /**\n     * @notice Reduces reserves by transferring to admin\n     * @dev Requires fresh interest accrual\n     * @param reduceAmount Amount of reduction to reserves\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _reduceReservesFresh(uint256 reduceAmount)\n        internal\n        returns (uint256)\n    {\n        // totalReserves - reduceAmount\n        uint256 totalReservesNew;\n\n        // Check caller is admin\n        if (msg.sender != admin) {\n            return\n                fail(\n                    Error.UNAUTHORIZED,\n                    FailureInfo.REDUCE_RESERVES_ADMIN_CHECK\n                );\n        }\n\n        // We fail gracefully unless market's block timestamp equals current block timestamp\n        if (accrualBlockTimestamp != getBlockTimestamp()) {\n            return\n                fail(\n                    Error.MARKET_NOT_FRESH,\n                    FailureInfo.REDUCE_RESERVES_FRESH_CHECK\n                );\n        }\n\n        // Fail gracefully if protocol has insufficient underlying cash\n        if (getCashPrior() < reduceAmount) {\n            return\n                fail(\n                    Error.TOKEN_INSUFFICIENT_CASH,\n                    FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE\n                );\n        }\n\n        // Check reduceAmount ≤ reserves[n] (totalReserves)\n        if (reduceAmount > totalReserves) {\n            return\n                fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION);\n        }\n\n        /////////////////////////\n        // EFFECTS & INTERACTIONS\n        // (No safe failures beyond this point)\n\n        totalReservesNew = sub_(totalReserves, reduceAmount);\n\n        // Store reserves[n+1] = reserves[n] - reduceAmount\n        totalReserves = totalReservesNew;\n\n        // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred.\n        // Restrict reducing reserves in wrapped token. Implementations except `BWrappedNative` won't use parameter `isNative`.\n        doTransferOut(admin, reduceAmount, false);\n\n        emit ReservesReduced(admin, reduceAmount, totalReservesNew);\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh\n     * @dev Admin function to accrue interest and update the interest rate model\n     * @param newInterestRateModel the new interest rate model to use\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _setInterestRateModel(InterestRateModel newInterestRateModel)\n        public\n        returns (uint256)\n    {\n        accrueInterest();\n        // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to.\n        return _setInterestRateModelFresh(newInterestRateModel);\n    }\n\n    /**\n     * @notice updates the interest rate model (*requires fresh interest accrual)\n     * @dev Admin function to update the interest rate model\n     * @param newInterestRateModel the new interest rate model to use\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\n     */\n    function _setInterestRateModelFresh(InterestRateModel newInterestRateModel)\n        internal\n        returns (uint256)\n    {\n        // Used to store old model for use in the event that is emitted on success\n        InterestRateModel oldInterestRateModel;\n\n        // Check caller is admin\n        if (msg.sender != admin) {\n            return\n                fail(\n                    Error.UNAUTHORIZED,\n                    FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK\n                );\n        }\n\n        // We fail gracefully unless market's block timestamp equals current block timestamp\n        if (accrualBlockTimestamp != getBlockTimestamp()) {\n            return\n                fail(\n                    Error.MARKET_NOT_FRESH,\n                    FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK\n                );\n        }\n\n        // Track the market's current interest rate model\n        oldInterestRateModel = interestRateModel;\n\n        // Ensure invoke newInterestRateModel.isInterestRateModel() returns true\n        require(newInterestRateModel.isInterestRateModel(), \"invalid IRM\");\n\n        // Set the interest rate model to newInterestRateModel\n        interestRateModel = newInterestRateModel;\n\n        // Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel)\n        emit NewMarketInterestRateModel(\n            oldInterestRateModel,\n            newInterestRateModel\n        );\n\n        return uint256(Error.NO_ERROR);\n    }\n\n    /**\n     * @notice allows the admin update the softVault address\n     * @dev Admin function to set the soft vault address\n     * @param _softVault the address of the SoftVault this contract is connected to\n     */\n    function _setSoftVault(address _softVault) public returns (uint256) {\n        if (msg.sender != admin) {\n            return \n                fail(\n                    Error.UNAUTHORIZED,\n                    FailureInfo.SET_SOFT_VAULT_ADMIN_CHECK\n                );\n        }\n        softVault = _softVault;\n        return uint256(Error.NO_ERROR);\n    }\n\n    /*** Safe Token ***/\n\n    /**\n     * @notice Gets balance of this contract in terms of the underlying\n     * @dev This excludes the value of the current message, if any\n     * @return The quantity of underlying owned by this contract\n     */\n    function getCashPrior() internal view returns (uint256);\n\n    /**\n     * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee.\n     *  This may revert due to insufficient balance or insufficient allowance.\n     */\n    function doTransferIn(\n        address from,\n        uint256 amount,\n        bool isNative\n    ) internal returns (uint256);\n\n    /**\n     * @dev Performs a transfer out, ideally returning an explanatory error code upon failure rather than reverting.\n     *  If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract.\n     *  If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions.\n     */\n    function doTransferOut(\n        address payable to,\n        uint256 amount,\n        bool isNative\n    ) internal;\n\n    /**\n     * @notice Transfer `tokens` tokens from `src` to `dst` by `spender`\n     * @dev Called by both `transfer` and `transferFrom` internally\n     */\n    function transferTokens(\n        address spender,\n        address src,\n        address dst,\n        uint256 tokens\n    ) internal returns (uint256);\n\n    /**\n     * @notice Get the account's bToken balances\n     */\n    function getBTokenBalanceInternal(address account)\n        internal\n        view\n        returns (uint256);\n\n    /**\n     * @notice User supplies assets into the market and receives bTokens in exchange\n     * @dev Assumes interest has already been accrued up to the current second\n     */\n    function mintFresh(\n        address minter,\n        uint256 mintAmount,\n        bool isNative\n    ) internal returns (uint256, uint256);\n\n    /**\n     * @notice User redeems bTokens in exchange for the underlying asset\n     * @dev Assumes interest has already been accrued up to the current second\n     */\n    function redeemFresh(\n        address payable redeemer,\n        uint256 redeemTokensIn,\n        uint256 redeemAmountIn,\n        bool isNative\n    ) internal returns (uint256);\n\n    /**\n     * @notice Transfers collateral tokens (this market) to the liquidator.\n     * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another BToken.\n     *  Its absolutely critical to use msg.sender as the seizer bToken and not a parameter.\n     */\n    function seizeInternal(\n        address seizerToken,\n        address liquidator,\n        address borrower,\n        uint256 seizeTokens\n    ) internal returns (uint256);\n\n    /*** Reentrancy Guard ***/\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     */\n    modifier nonReentrant() {\n        require(_notEntered, \"re-entered\");\n        _notEntered = false;\n        _;\n        _notEntered = true; // get a gas-refund post-Istanbul\n    }\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/ComptrollerInterfaceExtension.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"./BToken.sol\";\nimport \"./ComptrollerStorage.sol\";\n\ninterface ComptrollerInterfaceExtension {\n    function checkMembership(address account, BToken bToken)\n        external\n        view\n        returns (bool);\n\n    function updateBTokenVersion(\n        address bToken,\n        ComptrollerV1Storage.Version version\n    ) external;\n\n    function flashloanAllowed(\n        address bToken,\n        address receiver,\n        uint256 amount,\n        bytes calldata params\n    ) external view returns (bool);\n\n    function getAccountLiquidity(address account)\n        external\n        view\n        returns (\n            uint256,\n            uint256,\n            uint256\n        );\n\n    function supplyCaps(address market) external view returns (uint256);\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/ERC3156FlashLenderInterface.sol": {
        "content": "pragma solidity 0.5.16;\nimport \"./ERC3156FlashBorrowerInterface.sol\";\n\ninterface ERC3156FlashLenderInterface {\n    /**\n     * @dev The amount of currency available to be lent.\n     * @param token The loan currency.\n     * @return The amount of `token` that can be borrowed.\n     */\n    function maxFlashLoan(address token) external view returns (uint256);\n\n    /**\n     * @dev The fee to be charged for a given loan.\n     * @param token The loan currency.\n     * @param amount The amount of tokens lent.\n     * @return The amount of `token` to be charged for the loan, on top of the returned principal.\n     */\n    function flashFee(address token, uint256 amount)\n        external\n        view\n        returns (uint256);\n\n    /**\n     * @dev Initiate a flash loan.\n     * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.\n     * @param token The loan currency.\n     * @param amount The amount of tokens lent.\n     * @param data Arbitrary data structure, intended to contain user-defined parameters.\n     */\n    function flashLoan(\n        ERC3156FlashBorrowerInterface receiver,\n        address token,\n        uint256 amount,\n        bytes calldata data\n    ) external returns (bool);\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/ERC3156FlashBorrowerInterface.sol": {
        "content": "pragma solidity 0.5.16;\n\ninterface ERC3156FlashBorrowerInterface {\n    /**\n     * @dev Receive a flash loan.\n     * @param initiator The initiator of the loan.\n     * @param token The loan currency.\n     * @param amount The amount of tokens lent.\n     * @param fee The additional amount of tokens to repay.\n     * @param data Arbitrary data structure, intended to contain user-defined parameters.\n     * @return The keccak256 hash of \"ERC3156FlashBorrower.onFlashLoan\"\n     */\n    function onFlashLoan(\n        address initiator,\n        address token,\n        uint256 amount,\n        uint256 fee,\n        bytes calldata data\n    ) external returns (bytes32);\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/ComptrollerInterface.sol": {
        "content": "pragma solidity 0.5.16;\n\ncontract ComptrollerInterface {\n    /// @notice Indicator that this is a Comptroller contract (for inspection)\n    bool public constant isComptroller = true;\n\n    /*** Assets You Are In ***/\n\n    function enterMarkets(address[] calldata bTokens)\n        external\n        returns (uint256[] memory);\n\n    function exitMarket(address bToken) external returns (uint256);\n\n    /*** Policy Hooks ***/\n\n    function mintAllowed(\n        address bToken,\n        address minter,\n        uint256 mintAmount\n    ) external returns (uint256);\n\n    function mintVerify(\n        address bToken,\n        address minter,\n        uint256 mintAmount,\n        uint256 mintTokens\n    ) external;\n\n    function redeemAllowed(\n        address bToken,\n        address redeemer,\n        uint256 redeemTokens\n    ) external returns (uint256);\n\n    function redeemVerify(\n        address bToken,\n        address redeemer,\n        uint256 redeemAmount,\n        uint256 redeemTokens\n    ) external;\n\n    function borrowAllowed(\n        address bToken,\n        address borrower,\n        uint256 borrowAmount\n    ) external returns (uint256);\n\n    function borrowVerify(\n        address bToken,\n        address borrower,\n        uint256 borrowAmount\n    ) external;\n\n    function repayBorrowAllowed(\n        address bToken,\n        address payer,\n        address borrower,\n        uint256 repayAmount\n    ) external returns (uint256);\n\n    function repayBorrowVerify(\n        address bToken,\n        address payer,\n        address borrower,\n        uint256 repayAmount,\n        uint256 borrowerIndex\n    ) external;\n\n    function liquidateBorrowAllowed(\n        address bTokenBorrowed,\n        address bTokenCollateral,\n        address liquidator,\n        address borrower,\n        uint256 repayAmount\n    ) external returns (uint256);\n\n    function liquidateBorrowVerify(\n        address bTokenBorrowed,\n        address bTokenCollateral,\n        address liquidator,\n        address borrower,\n        uint256 repayAmount,\n        uint256 seizeTokens\n    ) external;\n\n    function seizeAllowed(\n        address bTokenCollateral,\n        address bTokenBorrowed,\n        address liquidator,\n        address borrower,\n        uint256 seizeTokens\n    ) external returns (uint256);\n\n    function seizeVerify(\n        address bTokenCollateral,\n        address bTokenBorrowed,\n        address liquidator,\n        address borrower,\n        uint256 seizeTokens\n    ) external;\n\n    function transferAllowed(\n        address bToken,\n        address src,\n        address dst,\n        uint256 transferTokens\n    ) external returns (uint256);\n\n    function transferVerify(\n        address bToken,\n        address src,\n        address dst,\n        uint256 transferTokens\n    ) external;\n\n    /*** Liquidity/Liquidation Calculations ***/\n\n    function liquidateCalculateSeizeTokens(\n        address bTokenBorrowed,\n        address bTokenCollateral,\n        uint256 repayAmount\n    ) external view returns (uint256, uint256);\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/BTokenInterfaces.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"./ComptrollerInterface.sol\";\nimport \"./InterestRateModel.sol\";\nimport \"./ERC3156FlashBorrowerInterface.sol\";\n\ncontract BTokenStorage {\n    /**\n     * @dev Guard variable for re-entrancy checks\n     */\n    bool internal _notEntered;\n\n    /**\n     * @notice EIP-20 token name for this token\n     */\n    string public name;\n\n    /**\n     * @notice EIP-20 token symbol for this token\n     */\n    string public symbol;\n\n    /**\n     * @notice EIP-20 token decimals for this token\n     */\n    uint8 public decimals;\n\n    /**\n     * @notice Maximum borrow rate that can ever be applied (.0005% / block)\n     */\n\n    uint256 internal constant borrowRateMaxMantissa = 0.0005e16;\n\n    /**\n     * @notice Maximum fraction of interest that can be set aside for reserves\n     */\n    uint256 internal constant reserveFactorMaxMantissa = 1e18;\n\n    /**\n     * @notice Administrator for this contract\n     */\n    address payable public admin;\n\n    /**\n     * @notice Pending administrator for this contract\n     */\n    address payable public pendingAdmin;\n\n    /**\n     * @notice Contract which oversees inter-bToken operations\n     */\n    ComptrollerInterface public comptroller;\n\n    /**\n     * @notice Model which tells what the current interest rate should be\n     */\n    InterestRateModel public interestRateModel;\n\n    /**\n     * @notice Initial exchange rate used when minting the first BTokens (used when totalSupply = 0)\n     */\n    uint256 internal initialExchangeRateMantissa;\n\n    /**\n     * @notice Fraction of interest currently set aside for reserves\n     */\n    uint256 public reserveFactorMantissa;\n\n    /**\n     * @notice Block timestamp that interest was last accrued at\n     */\n    uint256 public accrualBlockTimestamp;\n\n    /**\n     * @notice Accumulator of the total earned interest rate since the opening of the market\n     */\n    uint256 public borrowIndex;\n\n    /**\n     * @notice Total amount of outstanding borrows of the underlying in this market\n     */\n    uint256 public totalBorrows;\n\n    /**\n     * @notice Total amount of reserves of the underlying held in this market\n     */\n    uint256 public totalReserves;\n\n    /**\n     * @notice Total number of tokens in circulation\n     */\n    uint256 public totalSupply;\n\n    /**\n     * @notice Official record of token balances for each account\n     */\n    mapping(address => uint256) internal accountTokens;\n\n    /**\n     * @notice Approved token transfer amounts on behalf of others\n     */\n    mapping(address => mapping(address => uint256)) internal transferAllowances;\n\n    /**\n     * @notice Container for borrow balance information\n     * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action\n     * @member interestIndex Global borrowIndex as of the most recent balance-changing action\n     */\n    struct BorrowSnapshot {\n        uint256 principal;\n        uint256 interestIndex;\n    }\n\n    /**\n     * @notice Mapping of account addresses to outstanding borrow balances\n     */\n    mapping(address => BorrowSnapshot) internal accountBorrows;\n\n    /**\n     * @notice Address of the SoftVault allowed to call mint and mint-related functions\n     */\n    address public softVault;\n}\n\ncontract BErc20Storage {\n    /**\n     * @notice Underlying asset for this BToken\n     */\n    address public underlying;\n\n    /**\n     * @notice Implementation address for this contract\n     */\n    address public implementation;\n}\n\ncontract BSupplyCapStorage {\n    /**\n     * @notice Internal cash counter for this BToken. Should equal underlying.balanceOf(address(this)) for BERC20.\n     */\n    uint256 public internalCash;\n}\n\ncontract BCollateralCapStorage {\n    /**\n     * @notice Total number of tokens used as collateral in circulation.\n     */\n    uint256 public totalCollateralTokens;\n\n    /**\n     * @notice Record of token balances which could be treated as collateral for each account.\n     *         If collateral cap is not set, the value should be equal to accountTokens.\n     */\n    mapping(address => uint256) public accountCollateralTokens;\n\n    /**\n     * @notice Check if accountCollateralTokens have been initialized.\n     */\n    mapping(address => bool) public isCollateralTokenInit;\n\n    /**\n     * @notice Collateral cap for this BToken, zero for no cap.\n     */\n    uint256 public collateralCap;\n}\n\n/*** Interface ***/\n\ncontract BTokenInterface is BTokenStorage {\n    /**\n     * @notice Indicator that this is a BToken contract (for inspection)\n     */\n    bool public constant isBToken = true;\n\n    /*** Market Events ***/\n\n    /**\n     * @notice Event emitted when interest is accrued\n     */\n    event AccrueInterest(\n        uint256 cashPrior,\n        uint256 interestAccumulated,\n        uint256 borrowIndex,\n        uint256 totalBorrows\n    );\n\n    /**\n     * @notice Event emitted when tokens are minted\n     */\n    event Mint(address minter, uint256 mintAmount, uint256 mintTokens);\n\n    /**\n     * @notice Event emitted when tokens are redeemed\n     */\n    event Redeem(address redeemer, uint256 redeemAmount, uint256 redeemTokens);\n\n    /**\n     * @notice Event emitted when underlying is borrowed\n     */\n    event Borrow(\n        address borrower,\n        uint256 borrowAmount,\n        uint256 accountBorrows,\n        uint256 totalBorrows\n    );\n\n    /**\n     * @notice Event emitted when a borrow is repaid\n     */\n    event RepayBorrow(\n        address payer,\n        address borrower,\n        uint256 repayAmount,\n        uint256 accountBorrows,\n        uint256 totalBorrows\n    );\n\n    /**\n     * @notice Event emitted when a borrow is liquidated\n     */\n    event LiquidateBorrow(\n        address liquidator,\n        address borrower,\n        uint256 repayAmount,\n        address bTokenCollateral,\n        uint256 seizeTokens\n    );\n\n    /*** Admin Events ***/\n\n    /**\n     * @notice Event emitted when pendingAdmin is changed\n     */\n    event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);\n\n    /**\n     * @notice Event emitted when pendingAdmin is accepted, which means admin is updated\n     */\n    event NewAdmin(address oldAdmin, address newAdmin);\n\n    /**\n     * @notice Event emitted when comptroller is changed\n     */\n    event NewComptroller(\n        ComptrollerInterface oldComptroller,\n        ComptrollerInterface newComptroller\n    );\n\n    /**\n     * @notice Event emitted when interestRateModel is changed\n     */\n    event NewMarketInterestRateModel(\n        InterestRateModel oldInterestRateModel,\n        InterestRateModel newInterestRateModel\n    );\n\n    /**\n     * @notice Event emitted when the reserve factor is changed\n     */\n    event NewReserveFactor(\n        uint256 oldReserveFactorMantissa,\n        uint256 newReserveFactorMantissa\n    );\n\n    /**\n     * @notice Event emitted when the reserves are added\n     */\n    event ReservesAdded(\n        address benefactor,\n        uint256 addAmount,\n        uint256 newTotalReserves\n    );\n\n    /**\n     * @notice Event emitted when the reserves are reduced\n     */\n    event ReservesReduced(\n        address admin,\n        uint256 reduceAmount,\n        uint256 newTotalReserves\n    );\n\n    /**\n     * @notice EIP20 Transfer event\n     */\n    event Transfer(address indexed from, address indexed to, uint256 amount);\n\n    /**\n     * @notice EIP20 Approval event\n     */\n    event Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 amount\n    );\n\n    /**\n     * @notice Failure event\n     */\n    event Failure(uint256 error, uint256 info, uint256 detail);\n\n    /*** User Interface ***/\n\n    function transfer(address dst, uint256 amount) external returns (bool);\n\n    function transferFrom(\n        address src,\n        address dst,\n        uint256 amount\n    ) external returns (bool);\n\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    function allowance(address owner, address spender)\n        external\n        view\n        returns (uint256);\n\n    function balanceOf(address owner) external view returns (uint256);\n\n    function balanceOfUnderlying(address owner) external returns (uint256);\n\n    function getAccountSnapshot(address account)\n        external\n        view\n        returns (\n            uint256,\n            uint256,\n            uint256,\n            uint256\n        );\n\n    function borrowRatePerSecond() external view returns (uint256);\n\n    function supplyRatePerSecond() external view returns (uint256);\n\n    function totalBorrowsCurrent() external returns (uint256);\n\n    function borrowBalanceCurrent(address account) external returns (uint256);\n\n    function borrowBalanceStored(address account) public view returns (uint256);\n\n    function exchangeRateCurrent() public returns (uint256);\n\n    function exchangeRateStored() public view returns (uint256);\n\n    function getCash() external view returns (uint256);\n\n    function accrueInterest() public returns (uint256);\n\n    function seize(\n        address liquidator,\n        address borrower,\n        uint256 seizeTokens\n    ) external returns (uint256);\n\n    /*** Admin Functions ***/\n\n    function _setPendingAdmin(address payable newPendingAdmin)\n        external\n        returns (uint256);\n\n    function _acceptAdmin() external returns (uint256);\n\n    function _setComptroller(ComptrollerInterface newComptroller)\n        public\n        returns (uint256);\n\n    function _setReserveFactor(uint256 newReserveFactorMantissa)\n        external\n        returns (uint256);\n\n    function _reduceReserves(uint256 reduceAmount) external returns (uint256);\n\n    function _setInterestRateModel(InterestRateModel newInterestRateModel)\n        public\n        returns (uint256);\n\n    function _setSoftVault(address _softVault) public returns (uint256);\n}\n\ncontract BErc20Interface is BErc20Storage {\n    /*** User Interface ***/\n\n    function mint(uint256 mintAmount) external returns (uint256);\n\n    function redeem(uint256 redeemTokens) external returns (uint256);\n\n    function redeemUnderlying(uint256 redeemAmount) external returns (uint256);\n\n    function borrow(uint256 borrowAmount) external returns (uint256);\n\n    function repayBorrow(uint256 repayAmount) external returns (uint256);\n\n    function repayBorrowBehalf(address borrower, uint256 repayAmount)\n        external\n        returns (uint256);\n\n    function liquidateBorrow(\n        address borrower,\n        uint256 repayAmount,\n        BTokenInterface bTokenCollateral\n    ) external returns (uint256);\n\n    function _addReserves(uint256 addAmount) external returns (uint256);\n}\n\ncontract BWrappedNativeInterface is BErc20Interface {\n    /**\n     * @notice Flash loan fee ratio\n     */\n    uint256 public constant flashFeeBips = 1;\n\n    /*** Market Events ***/\n\n    /**\n     * @notice Event emitted when a flashloan occurred\n     */\n    event Flashloan(\n        address indexed receiver,\n        uint256 amount,\n        uint256 totalFee,\n        uint256 reservesFee\n    );\n\n    /*** User Interface ***/\n\n    function mintNative() external payable returns (uint256);\n\n    function redeemNative(uint256 redeemTokens) external returns (uint256);\n\n    function redeemUnderlyingNative(uint256 redeemAmount)\n        external\n        returns (uint256);\n\n    function borrowNative(uint256 borrowAmount) external returns (uint256);\n\n    function repayBorrowNative() external payable returns (uint256);\n\n    function repayBorrowBehalfNative(address borrower)\n        external\n        payable\n        returns (uint256);\n\n    function liquidateBorrowNative(\n        address borrower,\n        BTokenInterface bTokenCollateral\n    ) external payable returns (uint256);\n\n    function flashLoan(\n        ERC3156FlashBorrowerInterface receiver,\n        address initiator,\n        uint256 amount,\n        bytes calldata data\n    ) external returns (bool);\n\n    function _addReservesNative() external payable returns (uint256);\n\n    function collateralCap() external view returns (uint256);\n\n    function totalCollateralTokens() external view returns (uint256);\n}\n\ncontract BCapableErc20Interface is BErc20Interface, BSupplyCapStorage {\n    /**\n     * @notice Flash loan fee ratio\n     */\n    uint256 public constant flashFeeBips = 1;\n\n    /*** Market Events ***/\n\n    /**\n     * @notice Event emitted when a flashloan occurred\n     */\n    event Flashloan(\n        address indexed receiver,\n        uint256 amount,\n        uint256 totalFee,\n        uint256 reservesFee\n    );\n\n    /*** User Interface ***/\n\n    function gulp() external;\n}\n\ncontract BCollateralCapErc20Interface is\n    BCapableErc20Interface,\n    BCollateralCapStorage\n{\n    /*** Admin Events ***/\n\n    /**\n     * @notice Event emitted when collateral cap is set\n     */\n    event NewCollateralCap(address token, uint256 newCap);\n\n    /**\n     * @notice Event emitted when user collateral is changed\n     */\n    event UserCollateralChanged(address account, uint256 newCollateralTokens);\n\n    /*** User Interface ***/\n\n    function registerCollateral(address account) external returns (uint256);\n\n    function unregisterCollateral(address account) external;\n\n    function flashLoan(\n        ERC3156FlashBorrowerInterface receiver,\n        address initiator,\n        uint256 amount,\n        bytes calldata data\n    ) external returns (bool);\n\n    /*** Admin Functions ***/\n\n    function _setCollateralCap(uint256 newCollateralCap) external;\n}\n\ncontract BDelegatorInterface {\n    /**\n     * @notice Emitted when implementation is changed\n     */\n    event NewImplementation(\n        address oldImplementation,\n        address newImplementation\n    );\n\n    /**\n     * @notice Called by the admin to update the implementation of the delegator\n     * @param implementation_ The address of the new implementation for delegation\n     * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation\n     * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation\n     */\n    function _setImplementation(\n        address implementation_,\n        bool allowResign,\n        bytes memory becomeImplementationData\n    ) public;\n}\n\ncontract BDelegateInterface {\n    /**\n     * @notice Called by the delegator on a delegate to initialize it for duty\n     * @dev Should revert if any issues arise which make it unfit for delegation\n     * @param data The encoded bytes data for any initialization\n     */\n    function _becomeImplementation(bytes memory data) public;\n\n    /**\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\n     */\n    function _resignImplementation() public;\n}\n\n/*** External interface ***/\n\n/**\n * @title Flash loan receiver interface\n */\ninterface IFlashloanReceiver {\n    function executeOperation(\n        address sender,\n        address underlying,\n        uint256 amount,\n        uint256 fee,\n        bytes calldata params\n    ) external;\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/ErrorReporter.sol": {
        "content": "pragma solidity 0.5.16;\n\ncontract ComptrollerErrorReporter {\n    enum Error {\n        NO_ERROR,\n        UNAUTHORIZED,\n        COMPTROLLER_MISMATCH,\n        INSUFFICIENT_SHORTFALL,\n        INSUFFICIENT_LIQUIDITY,\n        INVALID_CLOSE_FACTOR,\n        INVALID_COLLATERAL_FACTOR,\n        INVALID_LIQUIDATION_INCENTIVE,\n        MARKET_NOT_ENTERED, // no longer possible\n        MARKET_NOT_LISTED,\n        MARKET_ALREADY_LISTED,\n        MATH_ERROR,\n        NONZERO_BORROW_BALANCE,\n        PRICE_ERROR,\n        REJECTION,\n        SNAPSHOT_ERROR,\n        TOO_MANY_ASSETS,\n        TOO_MUCH_REPAY\n    }\n\n    enum FailureInfo {\n        ACCEPT_ADMIN_PENDING_ADMIN_CHECK,\n        ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK,\n        EXIT_MARKET_BALANCE_OWED,\n        EXIT_MARKET_REJECTION,\n        SET_CLOSE_FACTOR_OWNER_CHECK,\n        SET_CLOSE_FACTOR_VALIDATION,\n        SET_COLLATERAL_FACTOR_OWNER_CHECK,\n        SET_COLLATERAL_FACTOR_NO_EXISTS,\n        SET_COLLATERAL_FACTOR_VALIDATION,\n        SET_COLLATERAL_FACTOR_WITHOUT_PRICE,\n        SET_IMPLEMENTATION_OWNER_CHECK,\n        SET_LIQUIDATION_INCENTIVE_OWNER_CHECK,\n        SET_LIQUIDATION_INCENTIVE_VALIDATION,\n        SET_MAX_ASSETS_OWNER_CHECK,\n        SET_PENDING_ADMIN_OWNER_CHECK,\n        SET_PENDING_IMPLEMENTATION_OWNER_CHECK,\n        SET_PRICE_ORACLE_OWNER_CHECK,\n        SUPPORT_MARKET_EXISTS,\n        SUPPORT_MARKET_OWNER_CHECK,\n        SET_PAUSE_GUARDIAN_OWNER_CHECK\n    }\n\n    /**\n     * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary\n     * contract-specific code that enables us to report opaque error codes from upgradeable contracts.\n     **/\n    event Failure(uint256 error, uint256 info, uint256 detail);\n\n    /**\n     * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator\n     */\n    function fail(Error err, FailureInfo info) internal returns (uint256) {\n        emit Failure(uint256(err), uint256(info), 0);\n\n        return uint256(err);\n    }\n\n    /**\n     * @dev use this when reporting an opaque error from an upgradeable collaborator contract\n     */\n    function failOpaque(\n        Error err,\n        FailureInfo info,\n        uint256 opaqueError\n    ) internal returns (uint256) {\n        emit Failure(uint256(err), uint256(info), opaqueError);\n\n        return uint256(err);\n    }\n}\n\ncontract TokenErrorReporter {\n    enum Error {\n        NO_ERROR,\n        UNAUTHORIZED,\n        BAD_INPUT,\n        COMPTROLLER_REJECTION,\n        COMPTROLLER_CALCULATION_ERROR,\n        INTEREST_RATE_MODEL_ERROR,\n        INVALID_ACCOUNT_PAIR,\n        INVALID_CLOSE_AMOUNT_REQUESTED,\n        INVALID_COLLATERAL_FACTOR,\n        MATH_ERROR,\n        MARKET_NOT_FRESH,\n        MARKET_NOT_LISTED,\n        TOKEN_INSUFFICIENT_ALLOWANCE,\n        TOKEN_INSUFFICIENT_BALANCE,\n        TOKEN_INSUFFICIENT_CASH,\n        TOKEN_TRANSFER_IN_FAILED,\n        TOKEN_TRANSFER_OUT_FAILED\n    }\n\n    /*\n     * Note: FailureInfo (but not Error) is kept in alphabetical order\n     *       This is because FailureInfo grows significantly faster, and\n     *       the order of Error has some meaning, while the order of FailureInfo\n     *       is entirely arbitrary.\n     */\n    enum FailureInfo {\n        ACCEPT_ADMIN_PENDING_ADMIN_CHECK,\n        ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED,\n        BORROW_ACCRUE_INTEREST_FAILED,\n        BORROW_CASH_NOT_AVAILABLE,\n        BORROW_FRESHNESS_CHECK,\n        BORROW_MARKET_NOT_LISTED,\n        BORROW_COMPTROLLER_REJECTION,\n        LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED,\n        LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED,\n        LIQUIDATE_COLLATERAL_FRESHNESS_CHECK,\n        LIQUIDATE_COMPTROLLER_REJECTION,\n        LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED,\n        LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX,\n        LIQUIDATE_CLOSE_AMOUNT_IS_ZERO,\n        LIQUIDATE_FRESHNESS_CHECK,\n        LIQUIDATE_LIQUIDATOR_IS_BORROWER,\n        LIQUIDATE_REPAY_BORROW_FRESH_FAILED,\n        LIQUIDATE_SEIZE_COMPTROLLER_REJECTION,\n        LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER,\n        LIQUIDATE_SEIZE_TOO_MUCH,\n        MINT_ACCRUE_INTEREST_FAILED,\n        MINT_COMPTROLLER_REJECTION,\n        MINT_FRESHNESS_CHECK,\n        MINT_TRANSFER_IN_FAILED,\n        MINT_TRANSFER_IN_NOT_POSSIBLE,\n        REDEEM_ACCRUE_INTEREST_FAILED,\n        REDEEM_COMPTROLLER_REJECTION,\n        REDEEM_FRESHNESS_CHECK,\n        REDEEM_TRANSFER_OUT_NOT_POSSIBLE,\n        REDUCE_RESERVES_ACCRUE_INTEREST_FAILED,\n        REDUCE_RESERVES_ADMIN_CHECK,\n        REDUCE_RESERVES_CASH_NOT_AVAILABLE,\n        REDUCE_RESERVES_FRESH_CHECK,\n        REDUCE_RESERVES_VALIDATION,\n        REPAY_BEHALF_ACCRUE_INTEREST_FAILED,\n        REPAY_BORROW_ACCRUE_INTEREST_FAILED,\n        REPAY_BORROW_COMPTROLLER_REJECTION,\n        REPAY_BORROW_FRESHNESS_CHECK,\n        REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE,\n        SET_COLLATERAL_FACTOR_OWNER_CHECK,\n        SET_COLLATERAL_FACTOR_VALIDATION,\n        SET_COMPTROLLER_OWNER_CHECK,\n        SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED,\n        SET_INTEREST_RATE_MODEL_FRESH_CHECK,\n        SET_INTEREST_RATE_MODEL_OWNER_CHECK,\n        SET_MAX_ASSETS_OWNER_CHECK,\n        SET_SOFT_VAULT_ADMIN_CHECK,\n        SET_ORACLE_MARKET_NOT_LISTED,\n        SET_PENDING_ADMIN_OWNER_CHECK,\n        SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED,\n        SET_RESERVE_FACTOR_ADMIN_CHECK,\n        SET_RESERVE_FACTOR_FRESH_CHECK,\n        SET_RESERVE_FACTOR_BOUNDS_CHECK,\n        TRANSFER_COMPTROLLER_REJECTION,\n        TRANSFER_NOT_ALLOWED,\n        ADD_RESERVES_ACCRUE_INTEREST_FAILED,\n        ADD_RESERVES_FRESH_CHECK,\n        ADD_RESERVES_TRANSFER_IN_NOT_POSSIBLE\n    }\n\n    /**\n     * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary\n     * contract-specific code that enables us to report opaque error codes from upgradeable contracts.\n     **/\n    event Failure(uint256 error, uint256 info, uint256 detail);\n\n    /**\n     * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator\n     */\n    function fail(Error err, FailureInfo info) internal returns (uint256) {\n        emit Failure(uint256(err), uint256(info), 0);\n\n        return uint256(err);\n    }\n\n    /**\n     * @dev use this when reporting an opaque error from an upgradeable collaborator contract\n     */\n    function failOpaque(\n        Error err,\n        FailureInfo info,\n        uint256 opaqueError\n    ) internal returns (uint256) {\n        emit Failure(uint256(err), uint256(info), opaqueError);\n\n        return uint256(err);\n    }\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/Exponential.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"./CarefulMath.sol\";\n\n/**\n * @title Exponential module for storing fixed-precision decimals\n * @author Compound\n * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places.\n *         Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is:\n *         `Exp({mantissa: 5100000000000000000})`.\n */\ncontract Exponential is CarefulMath {\n    uint256 constant expScale = 1e18;\n    uint256 constant doubleScale = 1e36;\n    uint256 constant halfExpScale = expScale / 2;\n    uint256 constant mantissaOne = expScale;\n\n    struct Exp {\n        uint256 mantissa;\n    }\n\n    struct Double {\n        uint256 mantissa;\n    }\n\n    /**\n     * @dev Creates an exponential from numerator and denominator values.\n     *      Note: Returns an error if (`num` * 10e18) > MAX_INT,\n     *            or if `denom` is zero.\n     */\n    function getExp(uint256 num, uint256 denom)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        (MathError err0, uint256 scaledNumerator) = mulUInt(num, expScale);\n        if (err0 != MathError.NO_ERROR) {\n            return (err0, Exp({mantissa: 0}));\n        }\n\n        (MathError err1, uint256 rational) = divUInt(scaledNumerator, denom);\n        if (err1 != MathError.NO_ERROR) {\n            return (err1, Exp({mantissa: 0}));\n        }\n\n        return (MathError.NO_ERROR, Exp({mantissa: rational}));\n    }\n\n    /**\n     * @dev Adds two exponentials, returning a new exponential.\n     */\n    function addExp(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        (MathError error, uint256 result) = addUInt(a.mantissa, b.mantissa);\n\n        return (error, Exp({mantissa: result}));\n    }\n\n    /**\n     * @dev Subtracts two exponentials, returning a new exponential.\n     */\n    function subExp(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        (MathError error, uint256 result) = subUInt(a.mantissa, b.mantissa);\n\n        return (error, Exp({mantissa: result}));\n    }\n\n    /**\n     * @dev Multiply an Exp by a scalar, returning a new Exp.\n     */\n    function mulScalar(Exp memory a, uint256 scalar)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        (MathError err0, uint256 scaledMantissa) = mulUInt(a.mantissa, scalar);\n        if (err0 != MathError.NO_ERROR) {\n            return (err0, Exp({mantissa: 0}));\n        }\n\n        return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa}));\n    }\n\n    /**\n     * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer.\n     */\n    function mulScalarTruncate(Exp memory a, uint256 scalar)\n        internal\n        pure\n        returns (MathError, uint256)\n    {\n        (MathError err, Exp memory product) = mulScalar(a, scalar);\n        if (err != MathError.NO_ERROR) {\n            return (err, 0);\n        }\n\n        return (MathError.NO_ERROR, truncate(product));\n    }\n\n    /**\n     * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.\n     */\n    function mulScalarTruncateAddUInt(\n        Exp memory a,\n        uint256 scalar,\n        uint256 addend\n    ) internal pure returns (MathError, uint256) {\n        (MathError err, Exp memory product) = mulScalar(a, scalar);\n        if (err != MathError.NO_ERROR) {\n            return (err, 0);\n        }\n\n        return addUInt(truncate(product), addend);\n    }\n\n    /**\n     * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer.\n     */\n    function mul_ScalarTruncate(Exp memory a, uint256 scalar)\n        internal\n        pure\n        returns (uint256)\n    {\n        Exp memory product = mul_(a, scalar);\n        return truncate(product);\n    }\n\n    /**\n     * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.\n     */\n    function mul_ScalarTruncateAddUInt(\n        Exp memory a,\n        uint256 scalar,\n        uint256 addend\n    ) internal pure returns (uint256) {\n        Exp memory product = mul_(a, scalar);\n        return add_(truncate(product), addend);\n    }\n\n    /**\n     * @dev Divide an Exp by a scalar, returning a new Exp.\n     */\n    function divScalar(Exp memory a, uint256 scalar)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        (MathError err0, uint256 descaledMantissa) = divUInt(\n            a.mantissa,\n            scalar\n        );\n        if (err0 != MathError.NO_ERROR) {\n            return (err0, Exp({mantissa: 0}));\n        }\n\n        return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa}));\n    }\n\n    /**\n     * @dev Divide a scalar by an Exp, returning a new Exp.\n     */\n    function divScalarByExp(uint256 scalar, Exp memory divisor)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        /*\n          We are doing this as:\n          getExp(mulUInt(expScale, scalar), divisor.mantissa)\n\n          How it works:\n          Exp = a / b;\n          Scalar = s;\n          `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`\n        */\n        (MathError err0, uint256 numerator) = mulUInt(expScale, scalar);\n        if (err0 != MathError.NO_ERROR) {\n            return (err0, Exp({mantissa: 0}));\n        }\n        return getExp(numerator, divisor.mantissa);\n    }\n\n    /**\n     * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer.\n     */\n    function divScalarByExpTruncate(uint256 scalar, Exp memory divisor)\n        internal\n        pure\n        returns (MathError, uint256)\n    {\n        (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor);\n        if (err != MathError.NO_ERROR) {\n            return (err, 0);\n        }\n\n        return (MathError.NO_ERROR, truncate(fraction));\n    }\n\n    /**\n     * @dev Divide a scalar by an Exp, returning a new Exp.\n     */\n    function div_ScalarByExp(uint256 scalar, Exp memory divisor)\n        internal\n        pure\n        returns (Exp memory)\n    {\n        /*\n          We are doing this as:\n          getExp(mulUInt(expScale, scalar), divisor.mantissa)\n\n          How it works:\n          Exp = a / b;\n          Scalar = s;\n          `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`\n        */\n        uint256 numerator = mul_(expScale, scalar);\n        return Exp({mantissa: div_(numerator, divisor)});\n    }\n\n    /**\n     * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer.\n     */\n    function div_ScalarByExpTruncate(uint256 scalar, Exp memory divisor)\n        internal\n        pure\n        returns (uint256)\n    {\n        Exp memory fraction = div_ScalarByExp(scalar, divisor);\n        return truncate(fraction);\n    }\n\n    /**\n     * @dev Multiplies two exponentials, returning a new exponential.\n     */\n    function mulExp(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        (MathError err0, uint256 doubleScaledProduct) = mulUInt(\n            a.mantissa,\n            b.mantissa\n        );\n        if (err0 != MathError.NO_ERROR) {\n            return (err0, Exp({mantissa: 0}));\n        }\n\n        // We add half the scale before dividing so that we get rounding instead of truncation.\n        //  See \"Listing 6\" and text above it at https://accu.org/index.php/journals/1717\n        // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18.\n        (MathError err1, uint256 doubleScaledProductWithHalfScale) = addUInt(\n            halfExpScale,\n            doubleScaledProduct\n        );\n        if (err1 != MathError.NO_ERROR) {\n            return (err1, Exp({mantissa: 0}));\n        }\n\n        (MathError err2, uint256 product) = divUInt(\n            doubleScaledProductWithHalfScale,\n            expScale\n        );\n        // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero.\n        assert(err2 == MathError.NO_ERROR);\n\n        return (MathError.NO_ERROR, Exp({mantissa: product}));\n    }\n\n    /**\n     * @dev Multiplies two exponentials given their mantissas, returning a new exponential.\n     */\n    function mulExp(uint256 a, uint256 b)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        return mulExp(Exp({mantissa: a}), Exp({mantissa: b}));\n    }\n\n    /**\n     * @dev Multiplies three exponentials, returning a new exponential.\n     */\n    function mulExp3(\n        Exp memory a,\n        Exp memory b,\n        Exp memory c\n    ) internal pure returns (MathError, Exp memory) {\n        (MathError err, Exp memory ab) = mulExp(a, b);\n        if (err != MathError.NO_ERROR) {\n            return (err, ab);\n        }\n        return mulExp(ab, c);\n    }\n\n    /**\n     * @dev Divides two exponentials, returning a new exponential.\n     *     (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b,\n     *  which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)\n     */\n    function divExp(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (MathError, Exp memory)\n    {\n        return getExp(a.mantissa, b.mantissa);\n    }\n\n    /**\n     * @dev Truncates the given exp to a whole number value.\n     *      For example, truncate(Exp{mantissa: 15 * expScale}) = 15\n     */\n    function truncate(Exp memory exp) internal pure returns (uint256) {\n        // Note: We are not using careful math here as we're performing a division that cannot fail\n        return exp.mantissa / expScale;\n    }\n\n    /**\n     * @dev Checks if first Exp is less than second Exp.\n     */\n    function lessThanExp(Exp memory left, Exp memory right)\n        internal\n        pure\n        returns (bool)\n    {\n        return left.mantissa < right.mantissa;\n    }\n\n    /**\n     * @dev Checks if left Exp <= right Exp.\n     */\n    function lessThanOrEqualExp(Exp memory left, Exp memory right)\n        internal\n        pure\n        returns (bool)\n    {\n        return left.mantissa <= right.mantissa;\n    }\n\n    /**\n     * @dev returns true if Exp is exactly zero\n     */\n    function isZeroExp(Exp memory value) internal pure returns (bool) {\n        return value.mantissa == 0;\n    }\n\n    function safe224(uint256 n, string memory errorMessage)\n        internal\n        pure\n        returns (uint224)\n    {\n        require(n < 2**224, errorMessage);\n        return uint224(n);\n    }\n\n    function safe32(uint256 n, string memory errorMessage)\n        internal\n        pure\n        returns (uint32)\n    {\n        require(n < 2**32, errorMessage);\n        return uint32(n);\n    }\n\n    function add_(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (Exp memory)\n    {\n        return Exp({mantissa: add_(a.mantissa, b.mantissa)});\n    }\n\n    function add_(Double memory a, Double memory b)\n        internal\n        pure\n        returns (Double memory)\n    {\n        return Double({mantissa: add_(a.mantissa, b.mantissa)});\n    }\n\n    function add_(uint256 a, uint256 b) internal pure returns (uint256) {\n        return add_(a, b, \"addition overflow\");\n    }\n\n    function add_(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c >= a, errorMessage);\n        return c;\n    }\n\n    function sub_(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (Exp memory)\n    {\n        return Exp({mantissa: sub_(a.mantissa, b.mantissa)});\n    }\n\n    function sub_(Double memory a, Double memory b)\n        internal\n        pure\n        returns (Double memory)\n    {\n        return Double({mantissa: sub_(a.mantissa, b.mantissa)});\n    }\n\n    function sub_(uint256 a, uint256 b) internal pure returns (uint256) {\n        return sub_(a, b, \"subtraction underflow\");\n    }\n\n    function sub_(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        require(b <= a, errorMessage);\n        return a - b;\n    }\n\n    function mul_(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (Exp memory)\n    {\n        return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale});\n    }\n\n    function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory) {\n        return Exp({mantissa: mul_(a.mantissa, b)});\n    }\n\n    function mul_(uint256 a, Exp memory b) internal pure returns (uint256) {\n        return mul_(a, b.mantissa) / expScale;\n    }\n\n    function mul_(Double memory a, Double memory b)\n        internal\n        pure\n        returns (Double memory)\n    {\n        return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale});\n    }\n\n    function mul_(Double memory a, uint256 b)\n        internal\n        pure\n        returns (Double memory)\n    {\n        return Double({mantissa: mul_(a.mantissa, b)});\n    }\n\n    function mul_(uint256 a, Double memory b) internal pure returns (uint256) {\n        return mul_(a, b.mantissa) / doubleScale;\n    }\n\n    function mul_(uint256 a, uint256 b) internal pure returns (uint256) {\n        return mul_(a, b, \"multiplication overflow\");\n    }\n\n    function mul_(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        if (a == 0 || b == 0) {\n            return 0;\n        }\n        uint256 c = a * b;\n        require(c / a == b, errorMessage);\n        return c;\n    }\n\n    function div_(Exp memory a, Exp memory b)\n        internal\n        pure\n        returns (Exp memory)\n    {\n        return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)});\n    }\n\n    function div_(Exp memory a, uint256 b) internal pure returns (Exp memory) {\n        return Exp({mantissa: div_(a.mantissa, b)});\n    }\n\n    function div_(uint256 a, Exp memory b) internal pure returns (uint256) {\n        return div_(mul_(a, expScale), b.mantissa);\n    }\n\n    function div_(Double memory a, Double memory b)\n        internal\n        pure\n        returns (Double memory)\n    {\n        return\n            Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)});\n    }\n\n    function div_(Double memory a, uint256 b)\n        internal\n        pure\n        returns (Double memory)\n    {\n        return Double({mantissa: div_(a.mantissa, b)});\n    }\n\n    function div_(uint256 a, Double memory b) internal pure returns (uint256) {\n        return div_(mul_(a, doubleScale), b.mantissa);\n    }\n\n    function div_(uint256 a, uint256 b) internal pure returns (uint256) {\n        return div_(a, b, \"divide by zero\");\n    }\n\n    function div_(\n        uint256 a,\n        uint256 b,\n        string memory errorMessage\n    ) internal pure returns (uint256) {\n        require(b > 0, errorMessage);\n        return a / b;\n    }\n\n    function fraction(uint256 a, uint256 b)\n        internal\n        pure\n        returns (Double memory)\n    {\n        return Double({mantissa: div_(mul_(a, doubleScale), b)});\n    }\n\n    // implementation from https://github.com/Uniswap/uniswap-lib/commit/99f3f28770640ba1bb1ff460ac7c5292fb8291a0\n    // original implementation: https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687\n    function sqrt(uint256 x) internal pure returns (uint256) {\n        if (x == 0) return 0;\n        uint256 xx = x;\n        uint256 r = 1;\n\n        if (xx >= 0x100000000000000000000000000000000) {\n            xx >>= 128;\n            r <<= 64;\n        }\n        if (xx >= 0x10000000000000000) {\n            xx >>= 64;\n            r <<= 32;\n        }\n        if (xx >= 0x100000000) {\n            xx >>= 32;\n            r <<= 16;\n        }\n        if (xx >= 0x10000) {\n            xx >>= 16;\n            r <<= 8;\n        }\n        if (xx >= 0x100) {\n            xx >>= 8;\n            r <<= 4;\n        }\n        if (xx >= 0x10) {\n            xx >>= 4;\n            r <<= 2;\n        }\n        if (xx >= 0x8) {\n            r <<= 1;\n        }\n\n        r = (r + x / r) >> 1;\n        r = (r + x / r) >> 1;\n        r = (r + x / r) >> 1;\n        r = (r + x / r) >> 1;\n        r = (r + x / r) >> 1;\n        r = (r + x / r) >> 1;\n        r = (r + x / r) >> 1; // Seven iterations should be enough\n        uint256 r1 = x / r;\n        return (r < r1 ? r : r1);\n    }\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/EIP20Interface.sol": {
        "content": "pragma solidity 0.5.16;\n\n/**\n * @title ERC 20 Token Standard Interface\n *  https://eips.ethereum.org/EIPS/eip-20\n */\ninterface EIP20Interface {\n    function name() external view returns (string memory);\n\n    function symbol() external view returns (string memory);\n\n    function decimals() external view returns (uint8);\n\n    /**\n     * @notice Get the total number of tokens in circulation\n     * @return The supply of tokens\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @notice Gets the balance of the specified address\n     * @param owner The address from which the balance will be retrieved\n     * @return The balance\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    /**\n     * @notice Transfer `amount` tokens from `msg.sender` to `dst`\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     * @return Whether or not the transfer succeeded\n     */\n    function transfer(address dst, uint256 amount)\n        external\n        returns (bool success);\n\n    /**\n     * @notice Transfer `amount` tokens from `src` to `dst`\n     * @param src The address of the source account\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     * @return Whether or not the transfer succeeded\n     */\n    function transferFrom(\n        address src,\n        address dst,\n        uint256 amount\n    ) external returns (bool success);\n\n    /**\n     * @notice Approve `spender` to transfer up to `amount` from `src`\n     * @dev This will overwrite the approval amount for `spender`\n     *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)\n     * @param spender The address of the account which may transfer tokens\n     * @param amount The number of tokens that are approved (-1 means infinite)\n     * @return Whether or not the approval succeeded\n     */\n    function approve(address spender, uint256 amount)\n        external\n        returns (bool success);\n\n    /**\n     * @notice Get the current allowance from `owner` for `spender`\n     * @param owner The address of the account which owns the tokens to be spent\n     * @param spender The address of the account which may transfer tokens\n     * @return The number of tokens allowed to be spent (-1 means infinite)\n     */\n    function allowance(address owner, address spender)\n        external\n        view\n        returns (uint256 remaining);\n\n    event Transfer(address indexed from, address indexed to, uint256 amount);\n    event Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 amount\n    );\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/EIP20NonStandardInterface.sol": {
        "content": "pragma solidity 0.5.16;\n\n/**\n * @title EIP20NonStandardInterface\n * @dev Version of ERC20 with no return values for `transfer` and `transferFrom`\n *  See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca\n */\ninterface EIP20NonStandardInterface {\n    /**\n     * @notice Get the total number of tokens in circulation\n     * @return The supply of tokens\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @notice Gets the balance of the specified address\n     * @param owner The address from which the balance will be retrieved\n     * @return The balance\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    ///\n    /// !!!!!!!!!!!!!!\n    /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification\n    /// !!!!!!!!!!!!!!\n    ///\n\n    /**\n     * @notice Transfer `amount` tokens from `msg.sender` to `dst`\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     */\n    function transfer(address dst, uint256 amount) external;\n\n    ///\n    /// !!!!!!!!!!!!!!\n    /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification\n    /// !!!!!!!!!!!!!!\n    ///\n\n    /**\n     * @notice Transfer `amount` tokens from `src` to `dst`\n     * @param src The address of the source account\n     * @param dst The address of the destination account\n     * @param amount The number of tokens to transfer\n     */\n    function transferFrom(\n        address src,\n        address dst,\n        uint256 amount\n    ) external;\n\n    /**\n     * @notice Approve `spender` to transfer up to `amount` from `src`\n     * @dev This will overwrite the approval amount for `spender`\n     *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)\n     * @param spender The address of the account which may transfer tokens\n     * @param amount The number of tokens that are approved\n     * @return Whether or not the approval succeeded\n     */\n    function approve(address spender, uint256 amount)\n        external\n        returns (bool success);\n\n    /**\n     * @notice Get the current allowance from `owner` for `spender`\n     * @param owner The address of the account which owns the tokens to be spent\n     * @param spender The address of the account which may transfer tokens\n     * @return The number of tokens allowed to be spent\n     */\n    function allowance(address owner, address spender)\n        external\n        view\n        returns (uint256 remaining);\n\n    event Transfer(address indexed from, address indexed to, uint256 amount);\n    event Approval(\n        address indexed owner,\n        address indexed spender,\n        uint256 amount\n    );\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/InterestRateModel.sol": {
        "content": "pragma solidity 0.5.16;\n\n/**\n * @title Blueberry's InterestRateModel Interface\n * @author Compound (Modified by Blueberry)\n */\ncontract InterestRateModel {\n    /// @notice Indicator that this is an InterestRateModel contract (for inspection)\n    bool public constant isInterestRateModel = true;\n\n    /**\n     * @notice Calculates the current borrow interest rate per second\n     * @param cash The total amount of cash the market has\n     * @param borrows The total amount of borrows the market has outstanding\n     * @param reserves The total amount of reserves the market has\n     * @return The borrow rate per second (as a percentage, and scaled by 1e18)\n     */\n    function getBorrowRate(\n        uint256 cash,\n        uint256 borrows,\n        uint256 reserves\n    ) external view returns (uint256);\n\n    /**\n     * @notice Calculates the current supply interest rate per second\n     * @param cash The total amount of cash the market has\n     * @param borrows The total amount of borrows the market has outstanding\n     * @param reserves The total amount of reserves the market has\n     * @param reserveFactorMantissa The current reserve factor the market has\n     * @return The supply rate per second (as a percentage, and scaled by 1e18)\n     */\n    function getSupplyRate(\n        uint256 cash,\n        uint256 borrows,\n        uint256 reserves,\n        uint256 reserveFactorMantissa\n    ) external view returns (uint256);\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/ComptrollerStorage.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"./BToken.sol\";\nimport \"./PriceOracle/PriceOracle.sol\";\n\ncontract UnitrollerAdminStorage {\n    /**\n     * @notice Administrator for this contract\n     */\n    address public admin;\n\n    /**\n     * @notice Pending administrator for this contract\n     */\n    address public pendingAdmin;\n\n    /**\n     * @notice Active brains of Unitroller\n     */\n    address public comptrollerImplementation;\n\n    /**\n     * @notice Pending brains of Unitroller\n     */\n    address public pendingComptrollerImplementation;\n}\n\ncontract ComptrollerV1Storage is UnitrollerAdminStorage {\n    /**\n     * @notice Oracle which gives the price of any given asset\n     */\n    PriceOracle public oracle;\n\n    /**\n     * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow\n     */\n    uint256 public closeFactorMantissa;\n\n    /**\n     * @notice Multiplier representing the discount on collateral that a liquidator receives\n     */\n    uint256 public liquidationIncentiveMantissa;\n\n    /**\n     * @notice Per-account mapping of \"assets you are in\"\n     */\n    mapping(address => BToken[]) public accountAssets;\n\n    enum Version {\n        VANILLA,\n        COLLATERALCAP,\n        WRAPPEDNATIVE\n    }\n\n    struct Market {\n        /// @notice Whether or not this market is listed\n        bool isListed;\n        /**\n         * @notice Multiplier representing the most one can borrow against their collateral in this market.\n         *  For instance, 0.9 to allow borrowing 90% of collateral value.\n         *  Must be between 0 and 1, and stored as a mantissa.\n         */\n        uint256 collateralFactorMantissa;\n        /// @notice Per-market mapping of \"accounts in this asset\"\n        mapping(address => bool) accountMembership;\n        /// @notice BToken version\n        Version version;\n    }\n\n    /**\n     * @notice Official mapping of bTokens -> Market metadata\n     * @dev Used e.g. to determine if a market is supported\n     */\n    mapping(address => Market) public markets;\n\n    /**\n     * @notice The Guardian can pause certain actions as a safety mechanism.\n     *  Actions which allow users to remove their own assets cannot be paused.\n     *  Liquidation / seizing / transfer can only be paused globally, not by market.\n     */\n    address public guardian;\n    bool public _mintGuardianPaused;\n    bool public _borrowGuardianPaused;\n    bool public transferGuardianPaused;\n    bool public seizeGuardianPaused;\n    mapping(address => bool) public mintGuardianPaused;\n    mapping(address => bool) public borrowGuardianPaused;\n\n    struct CompMarketState {\n        /// @notice The market's last updated compBorrowIndex or compSupplyIndex\n        uint224 index;\n        /// @notice The block timestamp the index was last updated at\n        uint32 block;\n    }\n\n    /// @notice A list of all markets\n    BToken[] public allMarkets;\n\n    /// @notice The portion of compRate that each market currently receives\n    /// @dev This storage is deprecated.\n    mapping(address => uint256) public compSpeeds;\n\n    /// @notice The COMP market supply state for each market\n    /// @dev This storage is deprecated.\n    mapping(address => CompMarketState) public compSupplyState;\n\n    /// @notice The COMP market borrow state for each market\n    /// @dev This storage is deprecated.\n    mapping(address => CompMarketState) public compBorrowState;\n\n    /// @notice The COMP borrow index for each market for each supplier as of the last time they accrued COMP\n    /// @dev This storage is deprecated.\n    mapping(address => mapping(address => uint256)) public compSupplierIndex;\n\n    /// @notice The COMP borrow index for each market for each borrower as of the last time they accrued COMP\n    /// @dev This storage is deprecated.\n    mapping(address => mapping(address => uint256)) public compBorrowerIndex;\n\n    /// @notice The COMP accrued but not yet transferred to each user\n    /// @dev This storage is deprecated.\n    mapping(address => uint256) public compAccrued;\n\n    /// @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market.\n    address public borrowCapGuardian;\n\n    /// @notice Borrow caps enforced by borrowAllowed for each bToken address. Defaults to zero which corresponds to unlimited borrowing.\n    mapping(address => uint256) public borrowCaps;\n\n    /// @notice The supplyCapGuardian can set supplyCaps to any number for any market. Lowering the supply cap could disable supplying to the given market.\n    address public supplyCapGuardian;\n\n    /// @notice Supply caps enforced by mintAllowed for each bToken address. Defaults to zero which corresponds to unlimited supplying.\n    mapping(address => uint256) public supplyCaps;\n\n    /// @notice creditLimits allowed specific protocols to borrow and repay without collateral.\n    /// @dev This storage is deprecated.\n    mapping(address => uint256) internal _oldCreditLimits;\n\n    /// @notice flashloanGuardianPaused can pause flash loan as a safety mechanism.\n    mapping(address => bool) public flashloanGuardianPaused;\n\n    /// @notice liquidityMining the liquidity mining module that handles the LM rewards distribution.\n    address public liquidityMining;\n\n    /// @notice creditLimits allowed specific protocols to borrow and repay specific markets without collateral.\n    mapping(address => mapping(address => uint256)) internal _creditLimits;\n\n    /// @notice isMarketDelisted records the market which has been delisted by us.\n    mapping(address => bool) public isMarketDelisted;\n\n    /// @notice creditLimitManager is the role who is in charge of increasing the credit limit.\n    address public creditLimitManager;\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/CarefulMath.sol": {
        "content": "pragma solidity 0.5.16;\n\n/**\n * @title Careful Math\n * @author Compound\n * @notice Derived from OpenZeppelin's SafeMath library\n *         https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol\n */\ncontract CarefulMath {\n    /**\n     * @dev Possible error codes that we can return\n     */\n    enum MathError {\n        NO_ERROR,\n        DIVISION_BY_ZERO,\n        INTEGER_OVERFLOW,\n        INTEGER_UNDERFLOW\n    }\n\n    /**\n     * @dev Multiplies two numbers, returns an error on overflow.\n     */\n    function mulUInt(uint256 a, uint256 b)\n        internal\n        pure\n        returns (MathError, uint256)\n    {\n        if (a == 0) {\n            return (MathError.NO_ERROR, 0);\n        }\n\n        uint256 c = a * b;\n\n        if (c / a != b) {\n            return (MathError.INTEGER_OVERFLOW, 0);\n        } else {\n            return (MathError.NO_ERROR, c);\n        }\n    }\n\n    /**\n     * @dev Integer division of two numbers, truncating the quotient.\n     */\n    function divUInt(uint256 a, uint256 b)\n        internal\n        pure\n        returns (MathError, uint256)\n    {\n        if (b == 0) {\n            return (MathError.DIVISION_BY_ZERO, 0);\n        }\n\n        return (MathError.NO_ERROR, a / b);\n    }\n\n    /**\n     * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).\n     */\n    function subUInt(uint256 a, uint256 b)\n        internal\n        pure\n        returns (MathError, uint256)\n    {\n        if (b <= a) {\n            return (MathError.NO_ERROR, a - b);\n        } else {\n            return (MathError.INTEGER_UNDERFLOW, 0);\n        }\n    }\n\n    /**\n     * @dev Adds two numbers, returns an error on overflow.\n     */\n    function addUInt(uint256 a, uint256 b)\n        internal\n        pure\n        returns (MathError, uint256)\n    {\n        uint256 c = a + b;\n\n        if (c >= a) {\n            return (MathError.NO_ERROR, c);\n        } else {\n            return (MathError.INTEGER_OVERFLOW, 0);\n        }\n    }\n\n    /**\n     * @dev add a and b and then subtract c\n     */\n    function addThenSubUInt(\n        uint256 a,\n        uint256 b,\n        uint256 c\n    ) internal pure returns (MathError, uint256) {\n        (MathError err0, uint256 sum) = addUInt(a, b);\n\n        if (err0 != MathError.NO_ERROR) {\n            return (err0, 0);\n        }\n\n        return subUInt(sum, c);\n    }\n}\n"
      },
      "lib/blueberry-core/contracts/money-market/PriceOracle/PriceOracle.sol": {
        "content": "pragma solidity 0.5.16;\n\nimport \"../BToken.sol\";\n\ncontract PriceOracle {\n    /**\n     * @notice Get the underlying price of a bToken asset\n     * @param bToken The bToken to get the underlying price of\n     * @return The underlying asset price mantissa (scaled by 1e18).\n     *  Zero means the price is unavailable.\n     */\n    function getUnderlyingPrice(BToken bToken) external view returns (uint256);\n}\n"
      }
    },
    "settings": {
      "remappings": [
        "@blueberry/=lib/blueberry-core/contracts/",
        "@blueberry-stakevest/=lib/blueberry-stakevest/src/",
        "@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
        "@openzeppelin/contracts-upgradeable/=lib/blueberry-core/node_modules/@openzeppelin/contracts-upgradeable/",
        "src/=src/BlueberryContracts/",
        "openzeppelin-contracts-upgradeable/contracts/=lib/blueberry-stakevest/lib/openzeppelin-contracts-upgradeable/contracts/",
        "solady/=lib/blueberry-stakevest/lib/solady/",
        "@chainlink/=lib/blueberry-core/node_modules/@chainlink/",
        "@aave/=lib/blueberry-core/node_modules/@aave/",
        "@contracts/=lib/blueberry-core/contracts/",
        "@eth-optimism/=lib/blueberry-core/node_modules/@eth-optimism/contracts/",
        "@pendle/=lib/blueberry-core/node_modules/@pendle/",
        "@test/=lib/blueberry-core/test/foundry/",
        "@uniswap/=lib/blueberry-core/node_modules/@uniswap/",
        "base64-sol/=lib/blueberry-core/node_modules/base64-sol/",
        "blueberry-core/=lib/blueberry-core/",
        "blueberry-stakevest/=lib/blueberry-stakevest/",
        "ds-test/=lib/forge-std/lib/ds-test/src/",
        "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
        "eth-gas-reporter/=lib/blueberry-core/node_modules/eth-gas-reporter/",
        "forge-std/=lib/forge-std/src/",
        "hardhat-deploy/=lib/blueberry-core/node_modules/hardhat-deploy/",
        "hardhat/=lib/blueberry-core/node_modules/hardhat/",
        "openzeppelin-contracts/=lib/openzeppelin-contracts/",
        "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
        "openzeppelin/=lib/blueberry-stakevest/lib/openzeppelin-contracts-upgradeable/contracts/",
        "solidity-stringutils/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/",
        "v3-core/=lib/blueberry-stakevest/lib/v3-core/contracts/"
      ],
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "metadata": {
        "useLiteralContent": false
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "evmVersion": "istanbul",
      "libraries": {
        "lib/blueberry-core/contracts/libraries/UniV3/UniV3WrappedLibContainer.sol": {
          "UniV3WrappedLibContainer": "0x20EcE8E8848E887E6Db8Ba4F89C4CC9BFc8Ae13F"
        }
      }
    }
  }}