> For the complete documentation index, see [llms.txt](https://docs.elara.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elara.fi/architecture/contract-architecture/staking-yield-accrual.md).

# Staking & Yield Accrual

Staking converts ELUSD into **sELUSD**, a share token whose price appreciates over time as yield is pushed on-chain. Users hold sELUSD to capture yield; unstaking burns shares and returns ELUSD at the current (higher) exchange rate.

## Overview

The staking system follows an ERC-4626-style share model:

* **Stake** ELUSD → receive sELUSD shares at the current exchange rate.
* **Hold** sELUSD → share price rises as `syncNAV()` mints new ELUSD into the pool.
* **Unstake** sELUSD → receive ELUSD at the now-higher exchange rate.

There are no lock periods. Users can stake and unstake at any time.

***

## Share price

The exchange rate between ELUSD and sELUSD is:

```
sharePrice = (accountedElUSD + VIRTUAL_ASSETS) × 1e18
             ─────────────────────────────────────────
             (totalSElUSD   + VIRTUAL_SHARES)
```

`VIRTUAL_ASSETS` and `VIRTUAL_SHARES` are both `1e12`. They ensure:

* An empty pool always returns a share price of exactly `1e18` (1:1).
* A dust first-deposit cannot manipulate the exchange rate for subsequent stakers (inflation-attack hardening).

Only three operations change `accountedElUSD`: `stake()`, `unstake()`, and `syncNAV()`. Direct token transfers to `ElUSDStake` are never reflected in share math.

***

## Staking

**Function:** `ElUSDStake.stake(uint256 amount) → uint256 shares`

```
shares = amount × (totalSElUSD + VIRTUAL_SHARES)
         ─────────────────────────────────────────
         (accountedElUSD + VIRTUAL_ASSETS)
```

ELUSD is transferred from the user to `ElUSDStake`, then sELUSD is minted to the user. `_totalAccountedElUSD` increases by `amount`.

Use `previewStake(amount)` to read the expected share count before transacting.

***

## Unstaking

**Function:** `ElUSDStake.unstake(uint256 shares) → uint256 amount`

```
amount = shares × (accountedElUSD + VIRTUAL_ASSETS)
         ─────────────────────────────────────────────
         (totalSElUSD + VIRTUAL_SHARES)
```

sELUSD is burned from the user; `_totalAccountedElUSD` decreases by `amount`; ELUSD is transferred to the user.

Use `previewUnstake(shares)` to read the expected ELUSD return before transacting.

***

## Yield accrual: `syncNAV()`

**Function:** `ElUSDStake.syncNAV()`, restricted to `YIELD_OPERATOR`

This function is called by an authorized backend operator **once per day**. It reads the on-chain NAV from `NAVAggregator`, computes the net yield since the last sync, deducts fees, and mints or burns ELUSD to reflect that yield in the share price.

### Yield isolation formula

Because the NAV also includes newly deposited vault collateral (which should not inflate the share price), the formula isolates only genuine venue returns:

```
grossYield = (navUsdNow − lastNavUsd) − (elUSDSupplyNow − lastElUSDTotalSupply)
```

New vault deposits increase both `navUsdNow` and `elUSDSupplyNow` by the same amount, so their difference is zero; deposits have no effect on share price.

### Fee deduction

Two fee types are deducted from `grossYield` before stakers receive their share:

| Fee             | Formula                                                                |
| --------------- | ---------------------------------------------------------------------- |
| Management fee  | `lastElUSDSupply × feePercent × elapsed / (10_000 × SECONDS_PER_YEAR)` |
| Performance fee | `max(0, grossYield) × feePercent / 10_000`                             |

Current fee schedule in the contracts: **1% management fee** and **30% performance fee**. Both are currently waived by Elara and Arken as a joint growth measure, so `_feeCollected` accrues nothing in practice today. The mechanism remains in place and fees will return once the fee model is reworked.

Fees are accumulated as USD accounting entries in `_feeCollected`; no tokens are minted at this point. When `collectFees()` is called by `CONTRACT_ADMIN`, the accrued amounts are swept to the fee recipient.

### Net yield application

After fee deduction:

* **Positive `netYield`** → `ElUSD.mint(elUSDStake, netYield)`: new ELUSD enters the pool, raising the share price for all current holders.
* **Negative `netYield`** → `ElUSD.burn(elUSDStake, |netYield|)`: ELUSD is removed from the pool, lowering the share price. This is the mechanism by which sELUSD holders bear strategy and NAV losses. A negative sync reduces the share price for all holders; there is no reserve fund or junior tranche that absorbs the loss first. Holders of unstaked ELUSD are unaffected.

### Staking & yield flow

```mermaid
sequenceDiagram
    participant User
    participant ElUSDStake
    participant ElUSD
    participant sElUSD
    participant NAVAggregator
    participant YieldOperator

    rect rgb(200, 230, 255)
        Note over User, sElUSD: Staking
        User->>ElUSDStake: stake(amount)
        ElUSDStake->>ElUSD: transferFrom(user, amount)
        ElUSDStake->>sElUSD: mint(user, shares)
        ElUSDStake-->>User: shares returned
    end

    rect rgb(255, 230, 200)
        Note over YieldOperator, NAVAggregator: Daily NAV sync
        YieldOperator->>ElUSDStake: syncNAV()
        ElUSDStake->>NAVAggregator: getNAV()
        Note over ElUSDStake: compute grossYield, deduct fees, get netYield
        ElUSDStake->>ElUSD: mint or burn netYield
        Note over ElUSDStake: share price updates for all holders
    end

    rect rgb(200, 255, 200)
        Note over User, ElUSD: Unstaking
        User->>ElUSDStake: unstake(shares)
        ElUSDStake->>sElUSD: burn(user, shares)
        ElUSDStake->>ElUSD: transfer(user, amount)
        ElUSDStake-->>User: ELUSD returned at new rate
    end
```

***

## NAVAggregator

`NAVAggregator` reads balances and positions from a configurable set of strategy adapters (Aave, Morpho, Pendle, Curve, Convex, Uniswap v3/v4, ERC-4626 vaults) plus treasury wallet balances, and sums them into a single USD NAV figure. `ElUSDStake.syncNAV()` calls `NAVAggregator.getNAV()` to get this figure.

***

## Key view functions

| Function                 | Returns                                       |
| ------------------------ | --------------------------------------------- |
| `sharePrice()`           | Current ELUSD per sELUSD share (18 dec)       |
| `previewStake(amount)`   | sELUSD shares received for `amount` ELUSD     |
| `previewUnstake(shares)` | ELUSD received for `shares` sELUSD            |
| `totalElUSD()`           | Total ELUSD accounted in the staking contract |
| `lastNavUsd()`           | NAV recorded at the last `syncNAV()`          |
| `lastSyncTimestamp()`    | Timestamp of the last `syncNAV()`             |
| `totalUncollectedFees()` | Accumulated USD fees not yet collected        |

***

## Key events

| Event                                    | When                  |
| ---------------------------------------- | --------------------- |
| `Staked(user, amount, shares)`           | User stakes ELUSD     |
| `Unstaked(user, shares, amount)`         | User unstakes sELUSD  |
| `NAVSynced(navUsd, netYield, timestamp)` | `syncNAV()` completes |
| `FeesCollected(amounts[])`               | Fee sweep executed    |
