<!--
Sitemap:
- [Overview](/index): Introducing Rocky
- [Products](/introduction/products): Stablecoins & Savings
- [Use Cases](/introduction/use-cases): Concrete use cases of Rocky
- [How it Works](/products/how-it-works/): Rocky is a stablecoins protocol allowing the creation of decentralized, capital-efficient and over-collateralized stablecoins built using a modular & upgradabl…
- [Rocketizer Module](/products/how-it-works/rocketizer-module): Explaining the Rocketizer Module
- [Savings Module](/products/how-it-works/savings-module): The Rocky Savings Module allows Rocky stablecoin holders to earn a native yield based on returns generated by the protocol on the assets backing the stablecoin…
- [Flashloan Module](/products/how-it-works/flashloan-module): Flash loans (also called One Block Borrows) are special transactions that allow the borrowing of an asset, as long as the borrowed amount (and a fee) is return…
- [Stablecoins & Savings](/products/stablecoins-and-savings/): Introducing Rocky Stablecoins
- [USDr & sUSDr](/products/stablecoins-and-savings/usdr-and-susdr/): Explaining USDr & sUSDr
- [Implementation](/products/stablecoins-and-savings/usdr-and-susdr/implementation): Detailing current USDr production implementation
- [Fee Distribution](/products/stablecoins-and-savings/usdr-and-susdr/fee-distribution): Rocky generated fees by the USDr codebase are distributed as follow:
- [Licensing](/products/licensing): Rocky is divided into three different repositories, each with its own license:
- [Proof of Solvency](/security/proof-of-solvency): Rocky Proof of Solvency
- [Hypernative](/security/hypernative): Hypernative is a leading real-time security platform that unites alerting and threat prevention with a sharp focus on early detection of on-chain threats and a…
- [Keepers](/security/keepers): Role and responsibilities of Keepers in maintaining Rocky protocol operations
- [Audits](/security/audits): A breakdown of security reviews covering deployed smart contracts of Rocky
- [Multisigs](/security/multisigs): A breakdown of multisigs used in Rocky
- [Introduction](/developers-hub/introduction): [https://github.com/rocky-protocol](https://github.com/rocky-protocol)\ \ TBA
- [Rocketizer Module](/developers-hub/rocketizer-module)
- [Savings Module](/developers-hub/savings-module)
- [Flashloan Module](/developers-hub/flashloan-module)
- [Onchain Tools](/developers-hub/onchain-tools/): A Breakdown of Available Onchain Tools
- [Oracles](/developers-hub/onchain-tools/oracles/): Explore Rocky price feeds deployed by third party protocols.
- [DIA](/developers-hub/onchain-tools/oracles/dia): More details on DIA Oracles
- [Offchain Tools](/developers-hub/offchain-tools/): TBA
- [Dune](/developers-hub/offchain-tools/dune): TBA
- [Build on Rocky](/developers-hub/build-on-rocky/): The goal of these guides is to help developers, such as third-party protocols, arbitrageurs, or keepers; understand and build on-top of Rocky.
- [Rocketizer Module Integration](/developers-hub/build-on-rocky/rocketizer-module-integration): The Rocketizer Module serves as the core minting and burning engine for Rocky stablecoins.
- [Savings Module Integration](/developers-hub/build-on-rocky/savings-module-integration): The Savings module provides a yield-bearing vault system built on the ERC4626 standard, allowing users to deposit Rocky stablecoins and earn interest through a…
- [Flashloan Module Integration](/developers-hub/build-on-rocky/flashloan-module-integration): The Flashloan module serves as the core minting and burning engine for Rocky stablecoins.
- [Addresses](/developers-hub/addresses/): - [USDr](/developers-hub/addresses/usdr): USDr contract addresses on Sei
- [USDr](/developers-hub/addresses/usdr): USDr contract addresses on Sei
- [User Guides](/resources/user-guides): TBA
-->

# 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 |

:::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.
:::

### 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.

:::info
The sUSDr/USD value can also be retrieved using the chainlink-compatible adapter [smart contract](#assets-data) for sUSDr/USD.
:::

## 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.

:::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.
:::

### Adapter Contracts

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