{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/libraries/LockedBalance.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "library LockedBalance {\n  /// @dev Tracks an account's total lockup per expiration time.\n  struct Lockup {\n    uint32 expiration;\n    uint96 totalAmount;\n  }\n\n  struct Lockups {\n    /// @dev Mapping from key to lockups.\n    /// i) A key represents 2 lockups. The key for a lockup is `index / 2`.\n    ///     For instance, elements with index 25 and 24 would map to the same key.\n    /// ii) The `value` for the `key` is split into two 128bits which are used to store the metadata for a lockup.\n    mapping(uint256 => uint256) lockups;\n  }\n\n  // Masks used to split a uint256 into two equal pieces which represent two individual Lockups.\n  uint256 private constant last128BitsMask = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;\n  uint256 private constant first128BitsMask = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000;\n\n  // Masks used to retrieve or set the totalAmount value of a single Lockup.\n  uint256 private constant firstAmountBitsMask = 0xFFFFFFFF000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;\n  uint256 private constant secondAmountBitsMask = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000000;\n\n  /**\n   * @notice Clears the lockup at the index.\n   */\n  function del(Lockups storage lockups, uint256 index) internal {\n    unchecked {\n      if (index % 2 == 0) {\n        index /= 2;\n        lockups.lockups[index] = (lockups.lockups[index] & last128BitsMask);\n      } else {\n        index /= 2;\n        lockups.lockups[index] = (lockups.lockups[index] & first128BitsMask);\n      }\n    }\n  }\n\n  /**\n   * @notice Sets the Lockup at the provided index.\n   */\n  function set(\n    Lockups storage lockups,\n    uint256 index,\n    uint256 expiration,\n    uint256 totalAmount\n  ) internal {\n    unchecked {\n      uint256 lockedBalanceBits = totalAmount | (expiration << 96);\n      if (index % 2 == 0) {\n        // set first 128 bits.\n        index /= 2;\n        lockups.lockups[index] = (lockups.lockups[index] & last128BitsMask) | (lockedBalanceBits << 128);\n      } else {\n        // set last 128 bits.\n        index /= 2;\n        lockups.lockups[index] = (lockups.lockups[index] & first128BitsMask) | lockedBalanceBits;\n      }\n    }\n  }\n\n  /**\n   * @notice Sets only the totalAmount for a lockup at the index.\n   */\n  function setTotalAmount(\n    Lockups storage lockups,\n    uint256 index,\n    uint256 totalAmount\n  ) internal {\n    unchecked {\n      if (index % 2 == 0) {\n        index /= 2;\n        lockups.lockups[index] = (lockups.lockups[index] & firstAmountBitsMask) | (totalAmount << 128);\n      } else {\n        index /= 2;\n        lockups.lockups[index] = (lockups.lockups[index] & secondAmountBitsMask) | totalAmount;\n      }\n    }\n  }\n\n  /**\n   * @notice Returns the Lockup at the provided index.\n   * @dev To get the lockup stored in the *first* 128 bits (first slot/lockup):\n   *       - we remove the last 128 bits (done by >> 128)\n   *      To get the lockup stored in the *last* 128 bits (second slot/lockup):\n   *       - we take the last 128 bits (done by % (2**128))\n   *      Once the lockup is obtained:\n   *       - get `expiration` by peaking at the first 32 bits (done by >> 96)\n   *       - get `totalAmount` by peaking at the last 96 bits (done by % (2**96))\n   */\n  function get(Lockups storage lockups, uint256 index) internal view returns (Lockup memory balance) {\n    unchecked {\n      uint256 lockupMetadata = lockups.lockups[index / 2];\n      if (lockupMetadata == 0) {\n        return balance;\n      }\n      uint128 lockedBalanceBits;\n      if (index % 2 == 0) {\n        // use first 128 bits.\n        lockedBalanceBits = uint128(lockupMetadata >> 128);\n      } else {\n        // use last 128 bits.\n        lockedBalanceBits = uint128(lockupMetadata % (2**128));\n      }\n      // unpack the bits to retrieve the Lockup.\n      balance.expiration = uint32(lockedBalanceBits >> 96);\n      balance.totalAmount = uint96(lockedBalanceBits % (2**96));\n    }\n  }\n}"
}