# DIA

## Oracles Implementation

### Contracts

The contracts fetch datas from:

| Blockchain | Contract Address                                                                                                         |
| ---------- | ------------------------------------------------------------------------------------------------------------------------ |
| Sei        | [0x32fFe7A0A14F95373bd720Be210AA6C2E94eFCEA](https://seiscan.io/address/0x32fFe7A0A14F95373bd720Be210AA6C2E94eFCEA#code) |

### Gas Wallets

Gas wallets are used to push data to oracle contracts. To ensure uninterrupted oracle operation, Rocky Labs is maintaining sufficient gas in them. Anyone can monitor the wallets below to ensure they remain adequately funded at all times.

| Blockchain | Contract Address                                                                                                    |
| ---------- | ------------------------------------------------------------------------------------------------------------------- |
| Sei        | [0xa245ae8df06f276f1de1d8fb9155e5dc73083ab5](https://seiscan.io/address/0xa245ae8df06f276f1de1d8fb9155e5dc73083ab5) |

### Oracles Configuration

Settings that dictate how the oracle computes and updates data.

|                                   |                                                                                                                                                                                                                              |
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Pricing Methodology               | Volume Weighted Average Price with Interquartile Range Filter (more details [here](https://www.diadata.org/docs/nexus/reference/pricing-methodologies/vwapir-volume-weighted-average-price-with-interquartile-range-filter)) |
| Deviation (%) & Refresh Frequency | 0.5% & 120 Seconds                                                                                                                                                                                                           |
| Heartbeat                         | 12 Hours                                                                                                                                                                                                                     |

### Assets Data

Available assets on the oracles and the Chainlink AggregatorV3Interface compatible contracts for each asset feed.

| Blockchain | Price Feed | Contract Address                                                                                                                 | Type        | Deviation (%) & Refresh Frequency | Hearbeat |
| ---------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------- | ----------- | --------------------------------- | -------- |
| Sei        | USDr/USD   | [0x42D1059364DF819Ae90bD86Dc2E80e7C28D1beD7](https://seiscan.io/address/0x42D1059364DF819Ae90bD86Dc2E80e7C28D1beD7#code)         | Fundamental | 0.5% & 120 Seconds                | 12 hours |
| Sei        | sUSDr/USD  | [0x6dcFc2A34A4C7F937e5d4eDfA6b6E69791a33295](https://seiscan.io/address/0x6dcFc2A34A4C7F937e5d4eDfA6b6E69791a33295#readContract) | Fundamental | 0.5% & 120 Seconds                | 12 hours |

{% hint style="info" %}
The pricing methodology fetches the fair redemption price of the USDr. In order to maximize security, this pricing methodology is deliberately pessimistic to ensure that no manipulation is possible. This means that the price of the USDr reported by the oracle may be slightly below its actual price.
{% endhint %}

### Data Sources

| Blockchain | Data Source | Contract Address                                                                                                         |
| ---------- | ----------- | ------------------------------------------------------------------------------------------------------------------------ |
| Sei        | USDr/USD    | [0x7b90821232074285a9ee9bee868bcc36231f8e32](https://seiscan.io/address/0x7b90821232074285a9ee9bee868bcc36231f8e32#code) |
| Sei        | sUSDr/USD   | [0xc0029b98f09c9062056c14c0329d3a114a098617](https://seiscan.io/address/0xc0029b98f09c9062056c14c0329d3a114a098617#code) |

## How the Oracle Works

The fair value oracle aggregates the fair USDr price from where the Rocketizer & Savings Modules are deployed and derives a chain-specific USDr/USD & sUSDr/USD value from it. The detailed data flow looks like this:

1. Each of the chains from which the aggregated USDr feed is comprised is queried for its current fair redemption value based on its backing assets and on the amount of USDr minted on that chain.
2. After collecting the chain-specific USDr redemption values and volumes, the average USDr redemption value (or price) is calculated by weighting the individual data points by the respective on-chain volume.
3. This aggregated USDr/USD value is then written into each deployed oracle and can be retrieved by calling the `getValue()` function with USDr/USD as parameter.
4. The aggregated USDr/USD value can also be retrieved using the chainlink-compatible adapter smart contract for USDr/USD.
5. The chain-local sUSDr/USD price (i.e. the redemption value of sUSDr on the chain where the query happens, based on the aggregated USDr price) can be queried by calling the `getSusdrPrice()` function.

{% hint style="info" %}
The sUSDr/USD value can also be retrieved using the chainlink-compatible adapter [smart contract](#assets-data) for sUSDr/USD.
{% endhint %}

## How to Access Data

### DIAParallelOracle (Solidity)

The following is the list of available methods on the `DIAParallelOracle` contract.

#### getValue()

```
function getValue(string memory key) public view returns (uint128 price, uint128 timestamp)
```

* For USDr/USD: Returns the global USDr price (aggregated fair value from all chains) in USD.
* For sUSDr/USD: Returns the chain-specific sUSDr price in USD using the specific chain's vault exchange rate based on the global USDr price (equivalent to calling `getSusdpPrice()`).

Parameters:

* `key (string)`: the exchange pair identifier (\`USDr/USD\` or \`sUSDr/USD\`)

Return Values:

* `price (uint128)`: The asset price in 18 decimals.
* `timestamp (uint128)`: Unix timestamp of the latest price update.

#### getSusdpPrice()

```
function getSusdpPrice() public view returns (uint256)
```

Calculates the chain-specific sUSDr price using the global USDr price across all chains and the specific chain's vault exchange rate. This is automatically called when using `getValue("sUSDr/USD")`.

`Return Value (uint256)`: The chain-specific sUSDr price in 18 decimals.

{% hint style="info" %}
The function name may suggests that the price obtained could be for USDp rather than USDr. The contract was forked from Parallel, which uses exactly the same codebase as Rocky. DIA deployed the contract without changing the function name, however the function does return the price of USDr.
{% endhint %}

### Adapter Contracts

To consume price data from oracles, you can use the adapter [smart contracts](https://docs.rocky.cash/developers-hub/onchain-tools/oracles). This allows to access the same methods on the AggregatorV3Interface such as `getRoundData` & `latestRoundData`.


---

# 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.rocky.cash/developers-hub/onchain-tools/oracles/dia.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.
