{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/vaults/FungibleAssetVaultForDAO.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [
        "keccak256(bytes)"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract FungibleAssetVaultForDAO is\n    AccessControlUpgradeable,\n    ReentrancyGuardUpgradeable\n{\n    using SafeERC20Upgradeable for IERC20Upgradeable;\n    using SafeERC20Upgradeable for IStableCoin;\n\n    event Deposit(address indexed user, uint256 depositAmount);\n    event Borrow(address indexed user, uint256 borrowAmount);\n    event Repay(address indexed user, uint256 repayAmount);\n    event Withdraw(address indexed user, uint256 withdrawAmount);\n\n    struct Rate {\n        uint128 numerator;\n        uint128 denominator;\n    }\n\n    bytes32 public constant WHITELISTED_ROLE = keccak256(\"WHITELISTED_ROLE\");\n\n    /// @dev This contract can handle unwrapped ETH if `address(0)` is passed as the `_collateralAsset`\n    /// parameter in the {initialize} function\n    address internal constant ETH = address(0);\n\n    address public collateralAsset;\n    IStableCoin public stablecoin;\n    /// @dev We store the value of a single unit of the collateral asset `10 ** decimals`\n    /// instead of fetching it everytime to save gas\n    uint256 private _collateralUnit;\n\n    IAggregatorV3Interface public oracle;\n\n    Rate public creditLimitRate;\n\n    /// @notice Amount of deposited collateral\n    uint256 public collateralAmount;\n    /// @notice Outstanding debt\n    uint256 public debtAmount;\n\n    /// @param _collateralAsset The address of the collateral asset - `address(0)` for ETH\n    /// @param _stablecoin PUSD address\n    /// @param _oracle Chainlink price feed for `_collateralAsset`/USD\n    /// @param _creditLimitRate Max outstanding debt to collateral ratio\n    function initialize(\n        address _collateralAsset,\n        IStableCoin _stablecoin,\n        IAggregatorV3Interface _oracle,\n        Rate memory _creditLimitRate\n    ) external initializer {\n        __AccessControl_init();\n        __ReentrancyGuard_init();\n\n        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);\n\n        setCreditLimitRate(_creditLimitRate);\n\n        collateralAsset = _collateralAsset;\n        stablecoin = _stablecoin;\n        if (_collateralAsset == ETH) {\n            _collateralUnit = 1 ether;\n        } else {\n            _collateralUnit = 10**IERC20Decimals(_collateralAsset).decimals();\n        }\n\n        oracle = _oracle;\n    }\n\n    /// @notice Allows members of the `DEFAULT_ADMIN_ROLE` to change the max outstanding debt to collateral ratio\n    /// @param _creditLimitRate The new ratio\n    function setCreditLimitRate(Rate memory _creditLimitRate) public onlyRole(DEFAULT_ADMIN_ROLE) {\n        require(\n            _creditLimitRate.denominator > 0 &&\n                //denominator can be equal to the numerator in some cases (stablecoins used as collateral)\n                _creditLimitRate.denominator >= _creditLimitRate.numerator,\n            \"invalid_rate\"\n        );\n        creditLimitRate = _creditLimitRate;\n    }\n\n    /// @dev Returns the USD price of one unit of collateral asset, using 18 decimals precision\n    /// @return The USD price\n    function _collateralPriceUsd() internal view returns (uint256) {\n        int256 answer = oracle.latestAnswer();\n        uint8 decimals = oracle.decimals();\n\n        require(answer > 0, \"invalid_oracle_answer\");\n\n        //check chainlink's precision and convert it to 18 decimals\n        return\n            decimals > 18\n                ? uint256(answer) / 10**(decimals - 18)\n                : uint256(answer) * 10**(18 - decimals);\n    }\n\n    /// @dev Returns the USD value of `amount` units of collateral, using 18 decimals precision\n    /// @param amount The amount of collateral to calculate the value of\n    /// @return The USD value\n    function _getCollateralValue(uint256 amount)\n        internal\n        view\n        returns (uint256)\n    {\n        return (amount * _collateralPriceUsd()) / _collateralUnit;\n    }\n\n    /// @notice Returns the max debt for `amount` of collateral\n    /// @param amount The amount of collateral to calculate max debt for\n    /// @return Max debt value for `amount`\n    function getCreditLimit(uint256 amount) public view returns (uint256) {\n        uint256 collateralValue = _getCollateralValue(amount);\n        return\n            (collateralValue * creditLimitRate.numerator) /\n            creditLimitRate.denominator;\n    }\n\n    /// @notice Allows members of the `WHITELISTED_ROLE` to deposit `amount` of collateral\n    /// @dev Emits a {Deposit} event\n    /// @param amount The amount of collateral to deposit\n    function deposit(uint256 amount) external payable onlyRole(WHITELISTED_ROLE) {\n        require(amount > 0, \"invalid_amount\");\n\n        if (collateralAsset == ETH) {\n            require(msg.value == amount, \"invalid_msg_value\");\n        } else {\n            require(msg.value == 0, \"non_zero_eth_value\");\n            IERC20Upgradeable(collateralAsset).safeTransferFrom(\n                msg.sender,\n                address(this),\n                amount\n            );\n        }\n\n        collateralAmount += amount;\n\n        emit Deposit(msg.sender, amount);\n    }\n\n    /// @notice Allows members of the `WHITELISTED_ROLE` to borrow `amount` of PUSD against the deposited collateral\n    /// @dev Emits a {Borrow} event\n    /// @param amount The amount of PUSD to borrow\n    function borrow(uint256 amount) external onlyRole(WHITELISTED_ROLE) nonReentrant {\n        require(amount > 0, \"invalid_amount\");\n\n        uint256 creditLimit = getCreditLimit(collateralAmount);\n        uint256 newDebtAmount = debtAmount + amount;\n        require(newDebtAmount <= creditLimit, \"insufficient_credit\");\n\n        debtAmount = newDebtAmount;\n        stablecoin.mint(msg.sender, amount);\n\n        emit Borrow(msg.sender, amount);\n    }\n\n    /// @notice Allows members of the `WHITELISTED_ROLE` to repay `amount` of debt using PUSD\n    /// @dev Emits a {Repay} event\n    /// @param amount The amount of debt to repay\n    function repay(uint256 amount) external onlyRole(WHITELISTED_ROLE) nonReentrant {\n        require(amount > 0, \"invalid_amount\");\n\n        amount = amount > debtAmount ? debtAmount : amount;\n\n        debtAmount -= amount;\n        stablecoin.burnFrom(msg.sender, amount);\n\n        emit Repay(msg.sender, amount);\n    }\n\n    /// @notice Allows members of the `WHITELISTED_ROLE` to withdraw `amount` of deposited collateral\n    /// @dev Emits a {Withdraw} event\n    /// @param amount The amount of collateral to withdraw\n    function withdraw(uint256 amount) external onlyRole(WHITELISTED_ROLE) nonReentrant {\n        require(amount > 0 && amount <= collateralAmount, \"invalid_amount\");\n\n        uint256 creditLimit = getCreditLimit(collateralAmount - amount);\n        require(creditLimit >= debtAmount, \"insufficient_credit\");\n\n        collateralAmount -= amount;\n\n        if (collateralAsset == ETH) payable(msg.sender).transfer(amount);\n        else\n            IERC20Upgradeable(collateralAsset).safeTransfer(msg.sender, amount);\n\n        emit Withdraw(msg.sender, amount);\n    }\n\n    uint256[50] private __gap;\n}"
}