> ## 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.

# Borrow assets

> Borrow hub assets against spoke-eligible collateral through the controller.

Borrow from a hub-asset market against collateral on the same account’s spoke.

Borrowing lets you:

* Open scaled debt that accrues borrow interest
* Receive tokens to `to` or the caller
* Stay solvent under LTV and health-factor gates

<Warning>
  Post-borrow health factor must stay at or above `1` WAD. Every priced asset on
  the account must resolve a valid price, or the call reverts.
</Warning>

## Borrowing

1. Open or select an account with eligible collateral
2. Choose borrowable `HubAssetKey` listings on that spoke
3. Size the borrow under caps, liquidity, and HF
4. Call `borrow`

### Call shape

```rust theme={"system"}
borrow(
  caller: Address,
  account_id: u64,
  borrows: Vec<(HubAssetKey, i128)>,
  to: Option<Address>,
)
```

```bash theme={"system"}
stellar contract invoke \
  --id <CONTROLLER> \
  --source-account <CALLER> \
  --network testnet \
  -- borrow \
  --caller <CALLER> \
  --account_id 42 \
  --borrows '[[{"hub_id":1,"asset":"<USDC>"}, "1000000000"]]' \
  --to null
```

`to` only changes where the tokens land. **The debt is always booked to
`account_id`**, whoever receives the funds.

### Preconditions

* `caller` holds the account's position NFT, or is an active delegate on it.
  (A delegate must be an address governance already approved as a position
  manager — it is not a separate authority level.)
* The spoke lists the asset and marks it borrowable, and the listing is not
  blocking entry.
* The spoke's borrow cap, the market's cash, and its max-utilization ceiling all
  leave headroom.
* After the borrow: the LTV gate holds, health factor stays at or above `1e18`,
  and LTV-weighted collateral stays above the minimum-borrow floor.
* Every priced asset on the account resolves a valid price. A stale or
  disagreeing feed reverts the whole call.

### Common errors

| Error                            | Cause                                                                       | Fix                                         |
| -------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------- |
| `#107 AssetNotBorrowable`        | The spoke listing does not allow borrowing this asset.                      | Borrow an allowed asset.                    |
| `#100 InsufficientCollateral`    | The LTV gate or health factor fails after the borrow.                       | Borrow less, or add collateral.             |
| `#126 MinBorrowCollateralNotMet` | LTV-weighted collateral is below the floor (about `$5`) while debt remains. | Add collateral, or repay in full.           |
| `#312 SpokeBorrowCapReached`     | The spoke's borrow cap is full.                                             | Borrow less, or wait for headroom.          |
| `#112 InsufficientLiquidity`     | The market's cash is below what you asked for.                              | Borrow less, or wait for repayments.        |
| `#127 UtilizationAboveMax`       | The borrow would push utilization past the market's ceiling.                | Borrow less, or wait for more supply.       |
| `#47 BorrowRoundsToZeroShares`   | The amount is too small to mint one scaled debt share.                      | Borrow more.                                |
| `#44 NotAuthorized`              | Caller is neither the NFT holder nor an active delegate.                    | Call as the owner, or get a delegate grant. |
| `#310 SpokeMismatch`             | The asset is not on the account's spoke.                                    | Borrow from the account's own spoke.        |
| `#205` / `#206`                  | An asset's price is unusable — stale, or two sources disagree.              | Retry once the feed recovers.               |

<Note>
  Caps are set **per spoke**, not per market. The same market can have different
  borrow headroom depending on which spoke your account sits on.
</Note>
