# Deposit

A deposit starts with USDC and ends with dvUSDC.

Wallets can use the standard approval flow or `depositWithPermit`, which combines an EIP-2612 USDC permit with the deposit call.

```mermaid
sequenceDiagram
    participant W as Wallet
    participant R as VaultRouter
    participant O as YieldOracle
    participant V as Aave or Morpho
    participant T as dvUSDC

    W->>R: deposit(amount, wallet, minSharesOut)
    R->>R: Check wallet/operator, pause state, amount, TVL cap
    R->>W: Pull USDC
    R->>O: recordObservation()
    R->>O: Check freshness and optimal route
    R->>R: Apply safety and capacity gates
    R->>V: Supply or deposit USDC
    R->>T: Mint dvUSDC to wallet
    R->>R: Increase costBasisUSDC[wallet]
```

## Step-By-Step

1. The caller must be the wallet or an approved operator.
2. New deposits must not be paused.
3. The amount must be at least the minimum deposit size (10 USDC).
4. The post-deposit TVL must fit inside the current TVL cap.
5. The router snapshots total vault assets and dvUSDC supply before pulling funds.
6. USDC is pulled from the wallet into the router.
7. The router attempts to record a fresh oracle observation.
8. The router rejects the deposit if the oracle is stale.
9. The oracle returns a recommended venue.
10. The router checks whether that venue is both oracle-safe and able to accept the amount.
11. If the recommended venue fails, the router tries the alternate venue.
12. If neither route passes, the deposit reverts with `NoSafeRoute`.
13. USDC is supplied to Aave or deposited into Morpho.
14. dvUSDC is minted using the pre-deposit asset and supply snapshot.
15. The wallet's USDC cost basis increases by the deposit amount.

## Route Selection Gates

The router applies two independent gates before routing into a venue.

**Oracle safety:**

* Aave must pass the utilisation heuristic.
* Morpho must pass the share-price peg check.

**Amount capacity:**

* Aave must be supply-enabled and show enough current USDC liquidity.
* Morpho must report enough `maxDeposit` capacity.

The oracle recommendation is not blindly followed. The router only routes into a venue that can pass both the safety signal and the amount-specific capacity check. If the oracle's preferred venue fails either gate, the router tries the other venue.

For the underlying TWAR mechanics, see [Oracle and Routing](/divigent-docs/protocol/oracle-and-routing.md).

## Slippage Protection

The `minSharesOut` parameter bounds dvUSDC issuance. If the deposit would mint fewer shares than `minSharesOut`, the call reverts. This protects depositors against unexpected share-price movement between transaction submission and execution.

## Common Reverts

| Error                 | Cause                                                          |
| --------------------- | -------------------------------------------------------------- |
| `NotAuthorized`       | Caller is not the wallet or an approved operator.              |
| `DepositsPaused`      | Emergency multisig has paused new deposits.                    |
| `BelowMinimumDeposit` | Amount is less than the 10 USDC minimum.                       |
| `TVLCapExceeded`      | Deposit would push protocol TVL above the current cap.         |
| `OracleStale`         | No oracle observation within the freshness window.             |
| `NoSafeRoute`         | Neither Aave nor Morpho passed both safety and capacity gates. |
| `SlippageExceeded`    | Minted shares fell below `minSharesOut`.                       |


---

# 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://divigent.gitbook.io/divigent-docs/protocol/deposit.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.
