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

# Supply assets

> Deposit hub assets through the controller to earn interest and enable collateral.

Supply assets to earn variable supply interest and, when the spoke allows, use
them as collateral.

Supplying lets you:

* Create or fund a spoke-bound account
* Accrue supply index growth (scaled balances)
* Borrow against collateralizable listings

<Tip>
  App path: [Getting started](/docs/stellar-lending/getting-started). Integrators call
  the controller only.
</Tip>

## Supplying

1. Identify the market (`HubAssetKey`)
2. Confirm the spoke allows collateral / supply
3. Authorize token transfer to the pool
4. Call `supply`

### Identify the market

Use `HubAssetKey { hub_id, asset }`. Confirm pool listing and spoke `SpokeAsset`
flags (`collateral`, not paused/frozen for increases, caps).

### Call shape

```rust theme={"system"}
supply(
  caller: Address,
  account_id: u64,   // 0 = create account
  spoke_id: u32,     // required; must match existing account spoke
  assets: Vec<(HubAssetKey, i128)>,
) -> u64             // account_id
```

```bash theme={"system"}
stellar contract invoke \
  --id <CONTROLLER> \
  --source-account <CALLER> \
  --network testnet \
  -- supply \
  --caller <CALLER> \
  --account_id 0 \
  --spoke_id 1 \
  --assets '[[{"hub_id":1,"asset":"<USDC>"}, "10000000000"]]'
```

### Preconditions

* `caller` authorizes the call and the token transfer.
* The market exists and its hub is active.
* The account's spoke lists the asset and marks it collateralizable.
* Supply caps and the position limit (at most **5** supply positions) have
  headroom.
* Neither the protocol nor the listing is blocking entry.
* Every amount is strictly positive. Zero is rejected — unlike `withdraw`, it is
  not a sentinel here.

<Note>
  **Anyone can supply into someone else's account, but only narrowly.** A caller
  who is neither the owner nor a delegate may add **only** to assets the account
  already holds a supply position in. Anything else is `#44 NotAuthorized`. This
  stops a third party from filling up an account's 5 supply-position slots.

  Creating an account (`account_id = 0`) skips the check, because the caller
  becomes the owner.
</Note>

The amount credited is **measured, not requested**. A token that delivers less
than it is sent credits only what arrived.

### Common errors

| Error                          | Cause                                                                 | Fix                                                                           |
| ------------------------------ | --------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `#104 NotCollateral`           | The spoke listing does not allow this asset as collateral.            | Use a collateralizable asset, or a spoke that allows it.                      |
| `#311 SpokeSupplyCapReached`   | The spoke's supply cap is full.                                       | Supply less, or wait for headroom. A cap of `0` means no new exposure at all. |
| `#109 PositionLimitExceeded`   | The account already holds 5 supply positions.                         | Consolidate first.                                                            |
| `#315 SpokeAssetPaused`        | The listing is paused. This blocks exits too, not just entry.         | Wait for governance to unpause.                                               |
| `#316 SpokeAssetFrozen`        | The listing is frozen. Entry only — you can still withdraw and repay. | Wait, or use another asset.                                                   |
| `#310 SpokeMismatch`           | `spoke_id` does not match the account's stored spoke.                 | Pass the account's own spoke. It never changes.                               |
| `#44 NotAuthorized`            | Third-party supply into an asset the account does not already hold.   | Supply an asset it already has, or have the owner call.                       |
| `#51 SupplyRoundsToZeroShares` | The amount is too small to mint one scaled share.                     | Supply more.                                                                  |
| `#14 AmountMustBePositive`     | An amount is zero or negative.                                        | Use a positive amount.                                                        |
