{
    "Function": "_removeFromLockedBalance",
    "File": "contracts/FETH.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "LockedBalance",
        "LockedBalance",
        "LockedBalance",
        "LockedBalance",
        "LockedBalance",
        "LockedBalance"
    ],
    "Internal Calls": [
        "revert FETH_Escrow_Not_Found()",
        "revert FETH_Insufficient_Escrow(uint256)",
        "revert FETH_Escrow_Expired()",
        "revert FETH_Insufficient_Escrow(uint256)"
    ],
    "Library Calls": [
        "setTotalAmount",
        "setTotalAmount",
        "get",
        "del",
        "get",
        "get"
    ],
    "Low-Level Calls": [],
    "Code": "function _removeFromLockedBalance(\n    address account,\n    uint256 expiration,\n    uint256 amount\n  ) private returns (AccountInfo storage) {\n    if (expiration < block.timestamp) {\n      revert FETH_Escrow_Expired();\n    }\n\n    AccountInfo storage accountInfo = accountToInfo[account];\n    uint256 escrowIndex = accountInfo.lockupStartIndex;\n    LockedBalance.Lockup memory escrow = accountInfo.lockups.get(escrowIndex);\n\n    if (escrow.expiration == expiration) {\n      // If removing from the first bucket, we may be able to delete it\n      if (escrow.totalAmount == amount) {\n        accountInfo.lockups.del(escrowIndex);\n\n        // Bump the escrow start index unless it's the last one\n        if (accountInfo.lockups.get(escrowIndex + 1).expiration != 0) {\n          // The number of escrow buckets will never overflow 32 bits.\n          unchecked {\n            ++accountInfo.lockupStartIndex;\n          }\n        }\n      } else {\n        if (escrow.totalAmount < amount) {\n          revert FETH_Insufficient_Escrow(escrow.totalAmount);\n        }\n        // The require above ensures balance will not underflow.\n        unchecked {\n          accountInfo.lockups.setTotalAmount(escrowIndex, escrow.totalAmount - amount);\n        }\n      }\n    } else {\n      // Removing from the 2nd+ bucket\n      while (true) {\n        // The number of escrow buckets will never overflow 32 bits.\n        unchecked {\n          ++escrowIndex;\n        }\n        escrow = accountInfo.lockups.get(escrowIndex);\n        if (escrow.expiration == expiration) {\n          if (amount > escrow.totalAmount) {\n            revert FETH_Insufficient_Escrow(escrow.totalAmount);\n          }\n          // The require above ensures balance will not underflow.\n          unchecked {\n            accountInfo.lockups.setTotalAmount(escrowIndex, escrow.totalAmount - amount);\n          }\n          // We may have an entry with 0 totalAmount but expiration will be set\n          break;\n        }\n        if (escrow.expiration == 0) {\n          revert FETH_Escrow_Not_Found();\n        }\n      }\n    }\n\n    emit BalanceUnlocked(account, expiration, amount);\n    return accountInfo;\n  }"
}