{
    "Function": "_marketLockupFor",
    "File": "contracts/FETH.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "LockedBalance",
        "LockedBalance",
        "LockedBalance",
        "Math"
    ],
    "Internal Calls": [
        "revert FETH_Too_Much_ETH_Provided()",
        "revert FETH_Expiration_Too_Far_In_Future()",
        "revert FETH_Insufficient_Available_Funds(uint256)",
        "_freeFromEscrow",
        "revert FETH_Must_Lockup_Non_Zero_Amount()",
        "revert FETH_Cannot_Deposit_For_Lockup_With_Address_Zero()"
    ],
    "Library Calls": [
        "set",
        "get",
        "setTotalAmount",
        "ceilDiv"
    ],
    "Low-Level Calls": [],
    "Code": "function _marketLockupFor(address account, uint256 amount) private returns (uint256 expiration) {\n    if (account == address(0)) {\n      revert FETH_Cannot_Deposit_For_Lockup_With_Address_Zero();\n    }\n    if (amount == 0) {\n      revert FETH_Must_Lockup_Non_Zero_Amount();\n    }\n\n    // Block timestamp in seconds is small enough to never overflow\n    unchecked {\n      // Lockup expires after 24 hours, rounded up to the next hour for a total of [24-25) hours\n      expiration = lockupDuration + block.timestamp.ceilDiv(lockupInterval) * lockupInterval;\n    }\n\n    // Update available escrow\n    // Always free from escrow to ensure the max bucket count is <= 25\n    AccountInfo storage accountInfo = _freeFromEscrow(account);\n    if (msg.value < amount) {\n      // The check above prevents underflow with delta.\n      unchecked {\n        uint256 delta = amount - msg.value;\n        if (accountInfo.freedBalance < delta) {\n          revert FETH_Insufficient_Available_Funds(accountInfo.freedBalance);\n        }\n        // The check above prevents underflow of freed balance.\n        accountInfo.freedBalance -= uint96(delta);\n      }\n    } else if (msg.value != amount) {\n      // There's no reason to send msg.value more than the amount being locked up\n      revert FETH_Too_Much_ETH_Provided();\n    }\n\n    // Add to locked escrow\n    unchecked {\n      // The number of buckets is always < 256 bits.\n      for (uint256 escrowIndex = accountInfo.lockupStartIndex; ; ++escrowIndex) {\n        LockedBalance.Lockup memory escrow = accountInfo.lockups.get(escrowIndex);\n        if (escrow.expiration == 0) {\n          if (expiration > type(uint32).max) {\n            revert FETH_Expiration_Too_Far_In_Future();\n          }\n          // Amount (ETH) will always be < 96 bits.\n          accountInfo.lockups.set(escrowIndex, expiration, amount);\n          break;\n        }\n        if (escrow.expiration == expiration) {\n          // Total ETH will always be < 96 bits.\n          accountInfo.lockups.setTotalAmount(escrowIndex, escrow.totalAmount + amount);\n          break;\n        }\n      }\n    }\n\n    emit BalanceLocked(account, expiration, amount, msg.value);\n  }"
}