# User Lifecycle

#### 1. Open account

* `AccountManager.openAccount(owner) -> accountId`
* initialize owner permissions

#### 2. Deposit collateral

Flow:

1. user approves adapter
2. `AccountManager.deposit(accountId, profileId, amount)`
3. adapter pulls token into custody
4. adapter notifies Ledger: `lock(profileId, accountId, amount)`

Requirements:

* deposits allowed even if oracle is stale (depositing reduces risk)
* collateral enabled flag must be true

#### 3. Mint rwaUSD

Flow:

1. `AccountManager.mint(accountId, profileId, amtRwaUsd, to)`
2. `FeeAccumulator.accrue(profileId)` updates index
3. Ledger computes new principal delta corresponding to desired minted amount (or mints in principal units directly; pick one and keep consistent)
4. Ledger checks:
   * oracle status `OK`
   * cap not exceeded
   * post-mint safety check passes
   * min position threshold satisfied
5. Ledger:
   * increases principal
   * mints rwaUSD to `to`

**Note on units:**\
The cleanest approach is to mint in **current-liability units** (what user sees), then convert to principal internally using the current index. That prevents user confusion and keeps UI consistent.

#### 4. Repay (burn rwaUSD)

Flow:

1. user approves rwaUSD spending
2. `AccountManager.repay(accountId, profileId, amtRwaUsd, from)`
3. accrue index
4. Ledger reduces liability by burning rwaUSD
5. principal decreases accordingly
6. if principal hits zero, account is debt-free for that profile

Repayments must always be allowed, even in restricted mode.

#### 5. Withdraw collateral

Flow:

1. `AccountManager.withdraw(accountId, profileId, amount, to)`
2. accrue index
3. Ledger checks post-withdraw safety
4. Ledger decreases locked collateral
5. adapter transfers tokens to `to`

Withdrawals are risk-increasing and must be blocked when:

* oracle status not `OK` (policy choice: either block or require higher margin)
* system is paused
* account is under unwind


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.multipli.fi/technical-architecture/user-lifecycle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
