{
    "Function": "slitherConstructorConstantVariables",
    "File": "tokenomics/contracts/Depository.sol",
    "Parent Contracts": [
        "tokenomics/contracts/interfaces/IErrorsTokenomics.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract Depository is IErrorsTokenomics {\n    event OwnerUpdated(address indexed owner);\n    event TokenomicsUpdated(address indexed tokenomics);\n    event TreasuryUpdated(address indexed treasury);\n    event BondCalculatorUpdated(address indexed bondCalculator);\n    event CreateBond(address indexed token, uint256 indexed productId, address indexed owner, uint256 bondId,\n        uint256 amountOLAS, uint256 tokenAmount, uint256 maturity);\n    event RedeemBond(uint256 indexed productId, address indexed owner, uint256 bondId);\n    event CreateProduct(address indexed token, uint256 indexed productId, uint256 supply, uint256 priceLP,\n        uint256 vesting);\n    event CloseProduct(address indexed token, uint256 indexed productId, uint256 supply);\n\n    // Minimum bond vesting value\n    uint256 public constant MIN_VESTING = 1 days;\n    // Depository version number\n    string public constant VERSION = \"1.0.1\";\n    \n    // Owner address\n    address public owner;\n    // Individual bond counter\n    // We assume that the number of bonds will not be bigger than the number of seconds\n    uint32 public bondCounter;\n    // Bond product counter\n    // We assume that the number of products will not be bigger than the number of seconds\n    uint32 public productCounter;\n\n    // OLAS token address\n    address public immutable olas;\n    // Tkenomics contract address\n    address public tokenomics;\n    // Treasury contract address\n    address public treasury;\n    // Bond Calculator contract address\n    address public bondCalculator;\n\n    // Mapping of bond Id => account bond instance\n    mapping(uint256 => Bond) public mapUserBonds;\n    // Mapping of product Id => bond product instance\n    mapping(uint256 => Product) public mapBondProducts;\n\n    /// @dev Depository constructor.\n    /// @param _olas OLAS token address.\n    /// @param _treasury Treasury address.\n    /// @param _tokenomics Tokenomics address.\n    constructor(address _olas, address _tokenomics, address _treasury, address _bondCalculator)\n    {\n        owner = msg.sender;\n\n        // Check for at least one zero contract address\n        if (_olas == address(0) || _tokenomics == address(0) || _treasury == address(0) || _bondCalculator == address(0)) {\n            revert ZeroAddress();\n        }\n        olas = _olas;\n        tokenomics = _tokenomics;\n        treasury = _treasury;\n        bondCalculator = _bondCalculator;\n    }\n\n    /// @dev Changes the owner address.\n    /// @param newOwner Address of a new owner.\n    /// #if_succeeds {:msg \"Changing owner\"} old(owner) == msg.sender ==> owner == newOwner;\n    function changeOwner(address newOwner) external {\n        // Check for the contract ownership\n        if (msg.sender != owner) {\n            revert OwnerOnly(msg.sender, owner);\n        }\n\n        // Check for the zero address\n        if (newOwner == address(0)) {\n            revert ZeroAddress();\n        }\n\n        owner = newOwner;\n        emit OwnerUpdated(newOwner);\n    }\n\n    /// @dev Changes various managing contract addresses.\n    /// @param _tokenomics Tokenomics address.\n    /// @param _treasury Treasury address.\n    /// #if_succeeds {:msg \"tokenomics changed\"} _tokenomics != address(0) ==> tokenomics == _tokenomics;\n    /// #if_succeeds {:msg \"treasury changed\"} _treasury != address(0) ==> treasury == _treasury;\n    function changeManagers(address _tokenomics, address _treasury) external {\n        // Check for the contract ownership\n        if (msg.sender != owner) {\n            revert OwnerOnly(msg.sender, owner);\n        }\n\n        // Change Tokenomics contract address\n        if (_tokenomics != address(0)) {\n            tokenomics = _tokenomics;\n            emit TokenomicsUpdated(_tokenomics);\n        }\n        // Change Treasury contract address\n        if (_treasury != address(0)) {\n            treasury = _treasury;\n            emit TreasuryUpdated(_treasury);\n        }\n    }\n\n    /// @dev Changes Bond Calculator contract address\n    /// #if_succeeds {:msg \"bondCalculator changed\"} _bondCalculator != address(0) ==> bondCalculator == _bondCalculator;\n    function changeBondCalculator(address _bondCalculator) external {\n        // Check for the contract ownership\n        if (msg.sender != owner) {\n            revert OwnerOnly(msg.sender, owner);\n        }\n\n        if (_bondCalculator != address(0)) {\n            bondCalculator = _bondCalculator;\n            emit BondCalculatorUpdated(_bondCalculator);\n        }\n    }\n\n    /// @dev Creates a new bond product.\n    /// @param token LP token to be deposited for pairs like OLAS-DAI, OLAS-ETH, etc.\n    /// @param priceLP LP token price with 18 additional decimals.\n    /// @param supply Supply in OLAS tokens.\n    /// @param vesting Vesting period (in seconds).\n    /// @return productId New bond product Id.\n    /// #if_succeeds {:msg \"productCounter increases\"} productCounter == old(productCounter) + 1;\n    /// #if_succeeds {:msg \"isActive\"} mapBondProducts[productId].supply > 0 && mapBondProducts[productId].vesting == vesting;\n    function create(address token, uint256 priceLP, uint256 supply, uint256 vesting) external returns (uint256 productId) {\n        // Check for the contract ownership\n        if (msg.sender != owner) {\n            revert OwnerOnly(msg.sender, owner);\n        }\n\n        // Check for the pool liquidity as the LP price being greater than zero\n        if (priceLP == 0) {\n            revert ZeroValue();\n        }\n\n        // Check the priceLP limit value\n        if (priceLP > type(uint160).max) {\n            revert Overflow(priceLP, type(uint160).max);\n        }\n\n        // Check that the supply is greater than zero\n        if (supply == 0) {\n            revert ZeroValue();\n        }\n\n        // Check the supply limit value\n        if (supply > type(uint96).max) {\n            revert Overflow(supply, type(uint96).max);\n        }\n\n        // Check the vesting minimum limit value\n        if (vesting < MIN_VESTING) {\n            revert LowerThan(vesting, MIN_VESTING);\n        }\n\n        // Check for the maturity time overflow for the current timestamp\n        uint256 maturity = block.timestamp + vesting;\n        if (maturity > type(uint32).max) {\n            revert Overflow(maturity, type(uint32).max);\n        }\n\n        // Check if the LP token is enabled\n        if (!ITreasury(treasury).isEnabled(token)) {\n            revert UnauthorizedToken(token);\n        }\n\n        // Check if the bond amount is beyond the limits\n        if (!ITokenomics(tokenomics).reserveAmountForBondProgram(supply)) {\n            revert LowerThan(ITokenomics(tokenomics).effectiveBond(), supply);\n        }\n\n        // Push newly created bond product into the list of products\n        productId = productCounter;\n        mapBondProducts[productId] = Product(uint160(priceLP), uint32(vesting), token, uint96(supply));\n        // Even if we create a bond product every second, 2^32 - 1 is enough for the next 136 years\n        productCounter = uint32(productId + 1);\n        emit CreateProduct(token, productId, supply, priceLP, vesting);\n    }\n\n    /// @dev Closes bonding products.\n    /// @notice This will terminate programs regardless of their vesting time.\n    /// @param productIds Set of product Ids.\n    /// @return closedProductIds Set of closed product Ids.\n    /// #if_succeeds {:msg \"productCounter not touched\"} productCounter == old(productCounter);\n    /// #if_succeeds {:msg \"success closed\"} forall (uint k in productIds) mapBondProducts[productIds[k]].vesting == 0 && mapBondProducts[productIds[k]].supply == 0;\n    function close(uint256[] memory productIds) external returns (uint256[] memory closedProductIds) {\n        // Check for the contract ownership\n        if (msg.sender != owner) {\n            revert OwnerOnly(msg.sender, owner);\n        }\n\n        // Calculate the number of closed products\n        uint256 numProducts = productIds.length;\n        uint256[] memory ids = new uint256[](numProducts);\n        uint256 numClosedProducts;\n        // Traverse to close all possible products\n        for (uint256 i = 0; i < numProducts; ++i) {\n            uint256 productId = productIds[i];\n            // Check if the product is still open by getting its supply amount\n            uint256 supply = mapBondProducts[productId].supply;\n            // The supply is greater than zero only if the product is active, otherwise it is already closed\n            if (supply > 0) {\n                // Refund unused OLAS supply from the product if it was not used by the product completely\n                ITokenomics(tokenomics).refundFromBondProgram(supply);\n                address token = mapBondProducts[productId].token;\n                delete mapBondProducts[productId];\n\n                ids[numClosedProducts] = productIds[i];\n                ++numClosedProducts;\n                emit CloseProduct(token, productId, supply);\n            }\n        }\n\n        // Get the correct array size of closed product Ids\n        closedProductIds = new uint256[](numClosedProducts);\n        for (uint256 i = 0; i < numClosedProducts; ++i) {\n            closedProductIds[i] = ids[i];\n        }\n    }\n\n    /// @dev Deposits tokens in exchange for a bond from a specified product.\n    /// @param productId Product Id.\n    /// @param tokenAmount Token amount to deposit for the bond.\n    /// @return payout The amount of OLAS tokens due.\n    /// @return maturity Timestamp for payout redemption.\n    /// @return bondId Id of a newly created bond.\n    /// #if_succeeds {:msg \"token is valid\"} mapBondProducts[productId].token != address(0);\n    /// #if_succeeds {:msg \"input supply is non-zero\"} old(mapBondProducts[productId].supply) > 0 && mapBondProducts[productId].supply <= type(uint96).max;\n    /// #if_succeeds {:msg \"vesting is non-zero\"} mapBondProducts[productId].vesting > 0 && mapBondProducts[productId].vesting + block.timestamp <= type(uint32).max;\n    /// #if_succeeds {:msg \"bond Id\"} bondCounter == old(bondCounter) + 1 && bondCounter <= type(uint32).max;\n    /// #if_succeeds {:msg \"payout\"} old(mapBondProducts[productId].supply) == mapBondProducts[productId].supply + payout;\n    /// #if_succeeds {:msg \"OLAS balances\"} IToken(mapBondProducts[productId].token).balanceOf(treasury) == old(IToken(mapBondProducts[productId].token).balanceOf(treasury)) + tokenAmount;\n    function deposit(uint256 productId, uint256 tokenAmount) external\n        returns (uint256 payout, uint256 maturity, uint256 bondId)\n    {\n        // Check the token amount\n        if (tokenAmount == 0) {\n            revert ZeroValue();\n        }\n\n        // Get the bonding product\n        Product storage product = mapBondProducts[productId];\n\n        // Check for the product supply, which is zero if the product was closed or never existed\n        uint256 supply = product.supply;\n        if (supply == 0) {\n            revert ProductClosed(productId);\n        }\n\n        // Calculate the bond maturity based on its vesting time\n        maturity = block.timestamp + product.vesting;\n        // Check for the time limits\n        if (maturity > type(uint32).max) {\n            revert Overflow(maturity, type(uint32).max);\n        }\n\n        // Get the LP token address\n        address token = product.token;\n\n        // Calculate the payout in OLAS tokens based on the LP pair with the discount factor (DF) calculation\n        // Note that payout cannot be zero since the price LP is non-zero, otherwise the product would not be created\n        payout = IGenericBondCalculator(bondCalculator).calculatePayoutOLAS(tokenAmount, product.priceLP);\n\n        // Check for the sufficient supply\n        if (payout > supply) {\n            revert ProductSupplyLow(token, productId, payout, supply);\n        }\n\n        // Decrease the supply for the amount of payout\n        supply -= payout;\n        product.supply = uint96(supply);\n\n        // Create and add a new bond, update the bond counter\n        bondId = bondCounter;\n        mapUserBonds[bondId] = Bond(msg.sender, uint96(payout), uint32(maturity), uint32(productId));\n        bondCounter = uint32(bondId + 1);\n\n        // Deposit that token amount to mint OLAS tokens in exchange\n        ITreasury(treasury).depositTokenForOLAS(msg.sender, tokenAmount, token, payout);\n\n        // Close the product if the supply becomes zero\n        if (supply == 0) {\n            delete mapBondProducts[productId];\n            emit CloseProduct(token, productId, supply);\n        }\n\n        emit CreateBond(token, productId, msg.sender, bondId, payout, tokenAmount, maturity);\n    }\n\n    /// @dev Redeems account bonds.\n    /// @param bondIds Bond Ids to redeem.\n    /// @return payout Total payout sent in OLAS tokens.\n    /// #if_succeeds {:msg \"payout > 0\"} payout > 0;\n    /// #if_succeeds {:msg \"msg.sender is the only owner\"} old(forall (uint k in bondIds) mapUserBonds[bondIds[k]].account == msg.sender);\n    /// #if_succeeds {:msg \"accounts deleted\"} forall (uint k in bondIds) mapUserBonds[bondIds[k]].account == address(0);\n    /// #if_succeeds {:msg \"payouts are zeroed\"} forall (uint k in bondIds) mapUserBonds[bondIds[k]].payout == 0;\n    /// #if_succeeds {:msg \"maturities are zeroed\"} forall (uint k in bondIds) mapUserBonds[bondIds[k]].maturity == 0;\n    function redeem(uint256[] memory bondIds) external returns (uint256 payout) {\n        for (uint256 i = 0; i < bondIds.length; ++i) {\n            // Get the amount to pay and the maturity status\n            uint256 pay = mapUserBonds[bondIds[i]].payout;\n            bool matured = block.timestamp >= mapUserBonds[bondIds[i]].maturity;\n\n            // Revert if the bond does not exist or is not matured yet\n            if (pay == 0 || !matured) {\n                revert BondNotRedeemable(bondIds[i]);\n            }\n\n            // Check that the msg.sender is the owner of the bond\n            if (mapUserBonds[bondIds[i]].account != msg.sender) {\n                revert OwnerOnly(msg.sender, mapUserBonds[bondIds[i]].account);\n            }\n\n            // Increase the payout\n            payout += pay;\n\n            // Get the productId\n            uint256 productId = mapUserBonds[bondIds[i]].productId;\n\n            // Delete the Bond struct and release the gas\n            delete mapUserBonds[bondIds[i]];\n            emit RedeemBond(productId, msg.sender, bondIds[i]);\n        }\n\n        // Check for the non-zero payout\n        if (payout == 0) {\n            revert ZeroValue();\n        }\n\n        // No reentrancy risk here since it's the last operation, and originated from the OLAS token\n        // No need to check for the return value, since it either reverts or returns true, see the ERC20 implementation\n        IToken(olas).transfer(msg.sender, payout);\n    }\n\n    /// @dev Gets an array of active or inactive product Ids.\n    /// @param active Flag to select active or inactive products.\n    /// @return productIds Product Ids.\n    function getProducts(bool active) external view returns (uint256[] memory productIds) {\n        // Calculate the number of existing products\n        uint256 numProducts = productCounter;\n        bool[] memory positions = new bool[](numProducts);\n        uint256 numSelectedProducts;\n        // Traverse to find requested products\n        for (uint256 i = 0; i < numProducts; ++i) {\n            // Product is always active if its supply is not zero, and inactive otherwise\n            if ((active && mapBondProducts[i].supply > 0) || (!active && mapBondProducts[i].supply == 0)) {\n                positions[i] = true;\n                ++numSelectedProducts;\n            }\n        }\n\n        // Form active or inactive products index array\n        productIds = new uint256[](numSelectedProducts);\n        uint256 numPos;\n        for (uint256 i = 0; i < numProducts; ++i) {\n            if (positions[i]) {\n                productIds[numPos] = i;\n                ++numPos;\n            }\n        }\n    }\n\n    /// @dev Gets activity information about a given product.\n    /// @param productId Product Id.\n    /// @return status True if the product is active.\n    function isActiveProduct(uint256 productId) external view returns (bool status) {\n        status = (mapBondProducts[productId].supply > 0);\n    }\n\n    /// @dev Gets bond Ids for the account address.\n    /// @param account Account address to query bonds for.\n    /// @param matured Flag to get matured bonds only or all of them.\n    /// @return bondIds Bond Ids.\n    /// @return payout Cumulative expected OLAS payout.\n    /// #if_succeeds {:msg \"matured bonds\"} matured == true ==> forall (uint k in bondIds)\n    /// mapUserBonds[bondIds[k]].account == account && block.timestamp >= mapUserBonds[bondIds[k]].maturity;\n    function getBonds(address account, bool matured) external view\n        returns (uint256[] memory bondIds, uint256 payout)\n    {\n        // Check the address\n        if (account == address(0)) {\n            revert ZeroAddress();\n        }\n\n        uint256 numAccountBonds;\n        // Calculate the number of pending bonds\n        uint256 numBonds = bondCounter;\n        bool[] memory positions = new bool[](numBonds);\n        // Record the bond number if it belongs to the account address and was not yet redeemed\n        for (uint256 i = 0; i < numBonds; ++i) {\n            // Check if the bond belongs to the account\n            // If not and the address is zero, the bond was redeemed or never existed\n            if (mapUserBonds[i].account == account) {\n                // Check if requested bond is not matured but owned by the account address\n                if (!matured ||\n                    // Or if the requested bond is matured, i.e., the bond maturity timestamp passed\n                    block.timestamp >= mapUserBonds[i].maturity)\n                {\n                    positions[i] = true;\n                    ++numAccountBonds;\n                    // The payout is always bigger than zero if the bond exists\n                    payout += mapUserBonds[i].payout;\n                }\n            }\n        }\n\n        // Form pending bonds index array\n        bondIds = new uint256[](numAccountBonds);\n        uint256 numPos;\n        for (uint256 i = 0; i < numBonds; ++i) {\n            if (positions[i]) {\n                bondIds[numPos] = i;\n                ++numPos;\n            }\n        }\n    }\n\n    /// @dev Calculates the maturity and payout to claim for a single bond.\n    /// @param bondId The account bond Id.\n    /// @return payout The payout amount in OLAS.\n    /// @return matured True if the payout can be redeemed.\n    function getBondStatus(uint256 bondId) external view returns (uint256 payout, bool matured) {\n        payout = mapUserBonds[bondId].payout;\n        // If payout is zero, the bond has been redeemed or never existed\n        if (payout > 0) {\n            matured = block.timestamp >= mapUserBonds[bondId].maturity;\n        }\n    }\n\n    /// @dev Gets current reserves of OLAS / totalSupply of LP tokens.\n    /// @param token Token address.\n    /// @return priceLP Resulting reserveX / totalSupply ratio with 18 decimals.\n    function getCurrentPriceLP(address token) external view returns (uint256 priceLP) {\n        return IGenericBondCalculator(bondCalculator).getCurrentPriceLP(token);\n    }\n}"
}