# Oracle and Routing

The oracle exists to avoid routing based on a single momentary rate.

Divigent's yield oracle reads rate data from Aave V3 and Morpho, records observations into a circular buffer, computes a 4-hour time-weighted average rate (TWAR), and returns the preferred route for new deposits.

## Observation Mechanics

Every successful observation does three things:

1. It accumulates the previous spot rates over the elapsed time since the last observation.
2. It reads a new Aave spot rate from Aave's `currentLiquidityRate`.
3. It derives a new Morpho interval rate from consecutive share-price observations.

Morpho's rate is based on the change in `convertToAssets(...)` between observations. If the share price is flat or down, the interval Morpho rate is treated as zero and the previous baseline is retained.

## Oracle Parameters

| Parameter                            | Value               |
| ------------------------------------ | ------------------- |
| TWAR window                          | 4 hours             |
| Minimum observation interval         | 5 minutes           |
| Checkpoint buffer                    | 48 slots (circular) |
| Freshness limit                      | 2 hours             |
| Default minimum routing differential | 20 bps              |
| Routing differential range           | 10 bps to 100 bps   |
| Differential adjustment timelock     | 24 hours            |

## Computing The Optimal Route

When the router asks for the optimal vault, the oracle computes each venue's TWAR from cumulative observations. If there is not enough observation history, it falls back to current spot rates.

Routing then follows this rule:

* If neither venue is safe, the oracle reverts.
* Morpho wins only if Morpho is safe, Morpho's TWAR is greater than Aave's TWAR, and the difference is at least the configured minimum differential.
* Otherwise Aave is the conservative default, as long as Aave is safe.

After the oracle returns a recommendation, the router still applies deposit-capacity checks. If the recommended venue cannot accept the amount, the router can try the alternate venue. See [Deposit Flow](/divigent-docs/protocol/deposit.md).

## Why TWAR

Spot rates can move for reasons that do not represent durable yield:

* temporary utilisation spikes;
* single-block conditions;
* market imbalance;
* short-lived vault behaviour.

Routing solely on the latest spot rate would make deposits more reactive and easier to distort. The TWAR design favours sustained relative advantage over momentary headline APY.

## Safety Checks

Each venue has an independent safety heuristic that runs before the rate comparison:

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

A venue that fails its safety check is removed from routing regardless of rate.

## Governance and Timelocks

Oracle parameter changes are governed through timelocked admin paths. Adjustments to the minimum routing differential follow a 24-hour timelock. This prevents reactive parameter changes from being used to game routing.


---

# 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/oracle-and-routing.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.
