> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mystockline.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Market hours

> Gate risk-up UI on EquityOracle.regime(). Only LIVE should enable borrow and withdraw.

The core already enforces the action table. Your UI should match it so users do not send a revert.

Addresses: [Addresses](/resources/addresses) for the factory and each book's oracle on [Books](/concepts/books-and-tiers).

<Steps>
  <Step title="Resolve the book's oracle">
    ```typescript theme={"system"}
    import { parseAbi } from "viem"
    import { addresses } from "./addresses" // Addresses, testnet

    const registryAbi = parseAbi([
      "function book(uint16 id) view returns (address collateral, address oracle, uint16 issuerId, uint16 tierId, uint128 borrowCap, bool borrowingEnabled, bool exists)",
    ])

    const bookId = 8
    const book = await client.readContract({
      address: addresses.registry,
      abi: registryAbi,
      functionName: "book",
      args: [bookId],
    })
    ```
  </Step>

  <Step title="Read regime and price">
    Enum: `LIVE=0`, `DARK=1`, `HALTED=2`, `CA_WINDOW=3`, `SEQ_DOWN=4`.

    <CodeGroup>
      ```typescript theme={"system"}
      const oracleAbi = parseAbi([
        "function regime() view returns (uint8)",
        "function price() view returns (uint256)",
      ])

      const regime = await client.readContract({
        address: book.oracle,
        abi: oracleAbi,
        functionName: "regime",
      })

      const canIncreaseRisk = regime === 0
      const canLiquidate = regime === 0 || regime === 1

      let price: bigint | null = null
      try {
        price = await client.readContract({
          address: book.oracle,
          abi: oracleAbi,
          functionName: "price",
        })
      } catch {
        price = null // HALTED, CA_WINDOW, SEQ_DOWN, or dark past maxDarkDuration
      }
      ```

      ```solidity theme={"system"}
      enum Regime { LIVE, DARK, HALTED, CA_WINDOW, SEQ_DOWN }

      interface IEquityOracle {
          function regime() external view returns (Regime);
          function price() external view returns (uint256);
      }

      function borrowEnabled(IEquityOracle oracle) internal view returns (bool) {
          return oracle.regime() == Regime.LIVE;
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Gate the UI">
    Match the app copy. Market closed: disable the borrow slider, keep repay and add stock.

    | Control                 | Enable when                                            |
    | ----------------------- | ------------------------------------------------------ |
    | Borrow, take stock back | `LIVE` and not paused and `borrowingEnabled`           |
    | Repay, add stock        | always                                                 |
    | Show haircut banner     | `DARK`                                                 |
    | Show price paused       | `HALTED`, `CA_WINDOW`, `SEQ_DOWN`, or `price()` revert |
  </Step>
</Steps>

## What can go wrong

* `price()` reverts with `PriceUnavailable(regime)` or `DarkDurationExceeded`. Catch it. Do not retry-spam.
* A zero `sequencerFeed` never yields `SEQ_DOWN`. Check the oracle immutables before you build a sequencer banner.
* Cross-book accounts: each book has its own oracle. Gate per book, then AND for a multi-stock borrow.
* `borrowingEnabled` is independent of regime. Both must be true to borrow.

The core already enforces the action table. Your UI should match it so users do not send a revert.

Enum: LIVE=0, DARK=1, HALTED=2, CA\_WINDOW=3, SEQ\_DOWN=4. Only LIVE should enable borrow and withdraw. Repay and add stock always. Show a haircut banner in DARK. Show price paused when `price()` reverts.

`price()` reverts with `PriceUnavailable(regime)` or `DarkDurationExceeded`. Catch it. Do not retry-spam.

A zero `sequencerFeed` never yields SEQ\_DOWN. Check the oracle immutables before you build a sequencer banner. ARCHITECTURE.md lists sequencer as required. The code makes it optional.

## Regime table

| `regime()`  | Value | `price()`                                           | Borrow, withdraw | Liquidate | Repay, add stock |
| ----------- | ----- | --------------------------------------------------- | ---------------- | --------- | ---------------- |
| `LIVE`      | 0     | Fresh feed                                          | Yes              | Yes       | Yes              |
| `DARK`      | 1     | Friday close minus [haircut](/resources/parameters) | No               | Yes       | Yes              |
| `HALTED`    | 2     | Reverts                                             | No               | No        | Yes              |
| `CA_WINDOW` | 3     | Reverts                                             | No               | No        | Yes              |
| `SEQ_DOWN`  | 4     | Reverts                                             | No               | No        | Yes              |

Next: [Oracle](/concepts/oracle), [Market hours for users](/using/market-hours).
