# Collateral inventory

`GET /stats/collateral` · Lithos client API · Statistics

Source: https://lithosprotocol.org/docs/api/get-collateral-stats

How many unspent boxes match the configured collateral script and token, what they hold in
total, and what they bid. This is protocol-wide inventory — not this client's spendable
balance, not mining income, and no promise that the local miner can use any given box.


`fees` is the live bid book. A miner spends whichever collateral box pays it most, so the
distribution there is what a lender is bidding against and `fees.bestNanoErg` is the bid to
beat. Read it with `/collateral/active`, which names the individual boxes behind it.

`queue` is the same for boxes still waiting. The queue activates boxes strictly in order, and live
boxes compete by bid in whole 0.001 ERG steps, so `queue.firstNanoErg`, the least bid in the step
above every queued bid, puts a new box ahead of every box queued before it.

`selection` is what lenders put in and got back over the retained history, by how each spent box
was taken: by bid, or through clearance once its box was `clearanceAge` blocks old. It covers the
Lithos blocks recorded since this release could read selections; `coveredBlocks` says how many.

Each background read looks at up to 1,000 boxes; hitting that cap sets `partial` and reports
only what was scanned. Check `status` and `observedAt` before showing the numbers as current:
loading and disabled responses hold placeholders, and a failed refresh keeps the previous
inventory under an `unavailable` status. The request never refreshes the inventory itself.

## Responses

### 200: The cached inventory, with freshness and completeness.

`CollateralStats`

- `status` (string, required, one of loading, disabled, ready, stale, unavailable): Freshness of the inventory. Only `ready` is current as of the last successful check.
- `observedAt` (integer · int64): When the inventory was read, in Unix milliseconds. Absent before the first successful read.
- `source` (MiningCursor): The processed chain point a statistics result was read from.
  - `height` (integer, required)
  - `blockId` (string, required)
  - `parentId` (string, required)
  - `timestamp` (integer · int64, required): The block's own timestamp in Unix milliseconds, not the time the client read it.
- `boxes` (integer, required): Unspent collateral boxes seen. A partial result counts only what was scanned.
- `nanoErg` (string, required): Exact total nanoERG in those boxes. Not a wallet balance and not mining income.
- `partial` (boolean, required): True when the scan hit its cap, or no complete observation exists yet.
- `fees` (CollateralFeeStats, required): The priority bids carried by the observed boxes — the book a miner picks from, since a miner spends whichever box pays it most. Percentiles cover every observed box, floor and bid alike, because that is the distribution a lender competes against. While most boxes sit at the floor the median is `0`, which is the honest answer rather than a gap in the data. `bestNanoErg` is the bid to beat. 
  - `atFloor` (integer, required): Boxes bidding nothing.
  - `bidding` (integer, required): Boxes offering the finder something.
  - `unreadable` (integer, required): Boxes whose R4 could not be read. Always 0 in practice — the contract writes it — and a non-zero value means the inventory counts more boxes than the distribution does.
  - `totalNanoErg` (string, required): An exact nonnegative integer as a decimal string. Parse it without going through a float.
  - `bestNanoErg` (string, required): An exact nonnegative integer as a decimal string. Parse it without going through a float.
  - `medianNanoErg` (string, required): An exact nonnegative integer as a decimal string. Parse it without going through a float.
  - `p90NanoErg` (string, required): An exact nonnegative integer as a decimal string. Parse it without going through a float.
  - `buckets` (CollateralFeeBucket[], required): The floor band first, then quarters of break-even, then everything above it.
    - `fromNanoErg` (string, required): An exact nonnegative integer as a decimal string. Parse it without going through a float.
    - `toNanoErg` (string): Absent on the open-ended top band, which holds every bid above break-even.
    - `boxes` (integer, required)
- `error` (string): Short failure summary. Details stay in the client log.
- `queue` (CollateralQueueStats): The bids of the boxes waiting in the queue, read with the live inventory.
  - `boxes` (integer, required): Queued boxes seen, including any whose bid could not be read.
  - `bidding` (integer, required): Queued boxes bidding above the floor.
  - `unreadable` (integer, required): Queued boxes whose fee channel could not be read. Left out of every bid figure.
  - `bestNanoErg` (string, required): The highest priority fee in the queue, `0` when every box is at the floor.
  - `bestStepBoxes` (integer, required): Queued boxes whose bid falls in the same 0.001 ERG step as the best, which tie with it once live.
  - `firstNanoErg` (string, required): The least priority fee in the step above the best queued bid. A box bidding it is taken ahead of every box queued before it, unless one of those reaches the clearance age first.
  - `partial` (boolean, required): True when the queue held more boxes than one read takes (1,000).
- `selection` (CollateralSelectionStats)
  - `lithosBlocks` (integer · int64, required): Lithos blocks in the retained history.
  - `coveredBlocks` (integer · int64, required): Of those, the blocks whose selection was recorded. The rest were recorded before this release, or the index does not show their activation.
  - `fromHeight` (integer): The first retained height.
  - `clearanceAge` (integer, required): Blocks a live box must age before any client takes it first whatever it bids, as this release ships it.
  - `bid` (CollateralPathStats, required): What the lenders of boxes taken one way put in and got back. Cost is the queue box: the principal and the whole priority fee. What came back is the block reward less re-emission, and the block's fees, both paid to the lender's key. 
    - `boxes` (integer · int64, required)
    - `meanPriorityFeeNanoErg` (string): Absent with no boxes.
    - `meanWaitBlocks` (integer · int64): Mean blocks from the block that included the queue box to the one that spent the collateral. Absent with no boxes.
    - `costNanoErg` (string, required)
    - `receivedNanoErg` (string, required)
    - `netNanoErg` (string, required): What came back less the cost. Signed.
    - `aprPercent` (number · double): The net over every box's ERG locked from its queue box's block until its reward unlocks, 720 blocks after the spend, as a simple yearly rate at 262,800 blocks a year. Pooled, so a large box weighs more than a small one. ERG only: the LIT permit is left out. Absent with nothing locked. 
  - `clearance` (CollateralPathStats, required): What the lenders of boxes taken one way put in and got back. Cost is the queue box: the principal and the whole priority fee. What came back is the block reward less re-emission, and the block's fees, both paid to the lender's key. 

## Example request

```bash
curl -X GET "http://localhost:9000/stats/collateral"
```

## Example response

```json
{
  "status": "loading",
  "observedAt": 0,
  "source": {
    "height": 0,
    "blockId": "string",
    "parentId": "string",
    "timestamp": 0
  },
  "boxes": 0,
  "nanoErg": "0",
  "partial": true,
  "fees": {
    "atFloor": 0,
    "bidding": 0,
    "unreadable": 0,
    "totalNanoErg": "1000000000",
    "bestNanoErg": "1000000000",
    "medianNanoErg": "1000000000",
    "p90NanoErg": "1000000000",
    "buckets": [
      {
        "fromNanoErg": "1000000000",
        "toNanoErg": "0",
        "boxes": 0
      }
    ]
  },
  "error": "string",
  "queue": {
    "boxes": 0,
    "bidding": 0,
    "unreadable": 0,
    "bestNanoErg": "string",
    "bestStepBoxes": 0,
    "firstNanoErg": "string",
    "partial": true
  },
  "selection": {
    "lithosBlocks": 0,
    "coveredBlocks": 0,
    "fromHeight": 0,
    "clearanceAge": 0,
    "bid": {
      "boxes": 0,
      "meanPriorityFeeNanoErg": "string",
      "meanWaitBlocks": 0,
      "costNanoErg": "string",
      "receivedNanoErg": "string",
      "netNanoErg": "string",
      "aprPercent": 0
    },
    "clearance": {
      "boxes": 0,
      "meanPriorityFeeNanoErg": "string",
      "meanWaitBlocks": 0,
      "costNanoErg": "string",
      "receivedNanoErg": "string",
      "netNanoErg": "string",
      "aprPercent": 0
    }
  }
}
```
