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

> Supply collateral through the controller and verify the resulting account balance.

Supply transfers tokens from the caller to the pool and records collateral on a
lending account. Use the [quickstart](/docs/stellar-lending/dev/quickstart) for a first
transaction, or follow this guide to add supply to an integration.

## Prepare the account and assets

Pass `account_id = 0` to create an account in `Normal` mode. The call returns its
id and mints the position NFT to `caller`. For an existing account, pass its id
and stored `spoke_id`; the spoke cannot change.

Each entry is `(HubAssetKey, amount)`, where `HubAssetKey` is `{ hub_id, asset }`
and `amount` is a strictly positive integer in token base units. Duplicate
market entries are summed in first-appearance order.

Before submitting, check that:

* The market exists on an active hub and is listed on the account's spoke.
* The listing is collateralizable, unfrozen, and unpaused, and the protocol is unpaused.
* Supply caps and position limits leave enough headroom.
* A collateral asset below 3 decimals is the account's only supply market.
* The caller holds and authorizes the tokens being supplied.

An owner or active delegate can add a supply position. Other callers may add
only to a market that already has a supply position in the account. See
[account authority](/docs/stellar-lending/dev/accounts-and-risk).

Supply generally needs no oracle prices. A risk-parameter refresh that makes
liquidation terms less favorable on an indebted account can require valuation;
unusable prices then revert the transaction. See
[risk-parameter refresh](/docs/stellar-lending/dev/accounts-and-risk#risk-parameter-refresh).

## Build and authorize the call

```rust theme={"system"}
supply(
    caller: Address,
    account_id: u64,
    spoke_id: u32,
    assets: Vec<(HubAssetKey, i128)>,
) -> u64
```

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

This example supplies 1,000 tokens at 7 decimals. Set `CONTROLLER`, `IDENTITY`,
and `CALLER_ADDRESS` as in the [quickstart](/docs/stellar-lending/dev/quickstart).
Replace the spoke, hub, and token inputs for the selected network.

The caller authorizes the controller call and one token transfer per aggregated
market from `caller` to the pool. Wallet integrations prepare the transaction
before signing. Contract integrations pre-authorize the nested transfer with
[`authorize_as_current_contract`](/docs/stellar-lending/dev/vault-integrations#authorize-supply).

The pool credits the amount actually received. Supply shares round down; a
payment too small to mint a share reverts.

## Verify the supply

Persist the returned account id. Read `get_account_positions(account_id)` and
`get_collateral_amount(account_id, hub_asset)` to confirm the supplied balance.
The balance view includes accrued interest and returns token base units with
half-up rounding. It is a display balance, not a full-withdrawal payout.
Use the v1 [position arrays](/docs/stellar-lending/dev/integrator-api#position-fields) for
portfolio rendering; direct views are useful for transaction reconciliation.

The controller emits `UpdatePositionBatchEvent` at
`["position", "batch_update"]`, with `Supply` legs. The pool emits
`PoolMarketStateBatchEvent` at `["market", "batch_state_update"]`.

## Common errors

| Error | Cause | Fix |
| - | - | - |
| `#104 NotCollateral` | Spoke asset cannot be used as collateral. | Use a collateralizable asset or another spoke. |
| `#311 SpokeSupplyCapReached` | Spoke supply cap exceeded. | Supply less or wait for cap headroom. |
| `#109 PositionLimitExceeded` | Account already holds max supply positions. | Consolidate positions or wait for a limit change. |
| `#315 SpokeAssetPaused` | Spoke asset is paused. | Wait for governance to unpause or use another asset. |
| `#316 SpokeAssetFrozen` | The listing is frozen: entry blocked, exit still open. | Withdraw and repay still work on a frozen asset. |
| `#51 SupplyRoundsToZeroShares` | The amount is too small to mint one scaled share. | Supply more. |

Continue with [Borrow](/docs/stellar-lending/dev/borrow), or use
[Withdraw](/docs/stellar-lending/dev/withdraw) to remove supplied collateral.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.