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

# Stellar lending accounts and risk

> Account storage, spoke binding, position limits, and risk gates in Stellar Lending.

A `u64` account holds supply and borrow positions keyed by `HubAssetKey`. Every
account is bound to a spoke id `>= 1`; the spoke defines which assets the account
can use and with which risk parameters.

**Read first:** [Markets](/stellar-lending/dev/markets).

## Storage

Account state is split across three controller records:

| Record                        | Holds                                      |
| ----------------------------- | ------------------------------------------ |
| `AccountMeta(account_id)`     | Owner, active spoke id, and position mode. |
| `SupplyPositions(account_id)` | `Map<HubAssetKey, AccountPositionRaw>`.    |
| `BorrowPositions(account_id)` | `Map<HubAssetKey, DebtPositionRaw>`.       |

```rust theme={"system"}
Account {
  owner: Address,
  spoke_id: u32,
  mode: PositionMode,
  supply_positions: Map<HubAssetKey, AccountPositionRaw>,
  borrow_positions: Map<HubAssetKey, DebtPositionRaw>,
}
```

Existing-account operations require the owner or an authorized delegate, except
for intentionally open flows such as repay and liquidation.

## Positions

Supply and debt positions store scaled RAY balances. The live token amount is
reconstructed from the current pool index:

```text theme={"system"}
supply_actual = scaled_supply * supply_index / RAY
borrow_actual = scaled_debt * borrow_index / RAY
```

Supply positions also store the collateral risk parameters used by LTV,
health-factor, and liquidation math.

## Spoke Risk

The account's spoke provides `SpokeAsset(spoke_id, HubAssetKey)` configuration:

* collateral and borrow flags;
* paused and frozen flags;
* LTV;
* liquidation threshold;
* liquidation bonus and protocol fee;
* spoke-level supply and borrow caps;
* optional oracle override.

There is no account category boost mode in the current protocol.

## Position Limits

An account can hold a bounded number of supply and borrow positions. Governance
updates those limits through timelock. Exceeding either side reverts
`#109 PositionLimitExceeded`.

## Risk Gates

| Gate                      | When                                     | Rule                                                                  |
| ------------------------- | ---------------------------------------- | --------------------------------------------------------------------- |
| LTV                       | Borrow and indebted withdrawal           | Weighted collateral must cover total debt.                            |
| Health factor             | Borrow, indebted withdrawal, liquidation | `HF = weighted_collateral / total_debt`; `HF < 1e18` is liquidatable. |
| Minimum borrow collateral | Any account with debt                    | LTV-weighted collateral must stay above the configured USD floor.     |

Borrow and indebted withdrawal use strict oracle policy. Repay and debt-free
withdrawal are de-risking flows.

## Position Modes

`PositionMode` gates strategy entrypoints:

| Mode       | Meaning                         |
| ---------- | ------------------------------- |
| `Normal`   | Standard supply and borrow.     |
| `Multiply` | Leveraged collateral/debt loop. |
| `Long`     | Directional long strategy.      |
| `Short`    | Directional short strategy.     |

## Next

<CardGroup cols={2}>
  <Card title="Risk parameters" icon="sliders" href="/stellar-lending/dev/risk-parameters">
    Units, ranges, and configured values for market and spoke risk parameters.
  </Card>

  <Card title="Health factor" icon="heart-pulse" href="/stellar-lending/dev/health-factor">
    Health-factor formula and WAD examples.
  </Card>

  <Card title="Liquidations" icon="scale-balanced" href="/stellar-lending/dev/liquidations">
    Liquidation rules after health factor drops below one.
  </Card>

  <Card title="Strategies" icon="layer-group" href="/stellar-lending/dev/strategies">
    Strategy modes and route-driven account flows.
  </Card>
</CardGroup>
