{
    "Function": "deposit",
    "File": "tokenomics/contracts/Depository.sol",
    "Parent Contracts": [
        "tokenomics/contracts/interfaces/IErrorsTokenomics.sol"
    ],
    "High-Level Calls": [
        "ITreasury",
        "IGenericBondCalculator"
    ],
    "Internal Calls": [
        "revert Overflow(uint256,uint256)",
        "revert ZeroValue()",
        "revert ProductSupplyLow(address,uint256,uint256,uint256)",
        "revert ProductClosed(uint256)"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "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    }"
}