> For the complete documentation index, see [llms.txt](https://docs.unstable.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unstable.money/developers/price-oracle.md).

# Price Oracle

The Price Oracle component is a critical part of the Unstable Protocol, providing price data for collateral assets that is used to calculate collateralization ratios, determine liquidation events, and facilitate redemptions.

## Oracle Interface

All oracles in the Unstable Protocol implement the `IZkOracle` interface:

```solidity
interface IZkOracle {
    // Returns the address of the asset
    function assetAddress() external view returns (address);
    
    // Returns the redemption rate (contract rate) in underlying terms
    function getRedemptionRate() external view returns (uint256);
    
    // Returns the market rate in underlying terms
    function getMarketRate() external view returns (uint256);
}
```

| Action                  | Description                | Function              |
| ----------------------- | -------------------------- | --------------------- |
| **Get Market Rate**     | Get current market rate    | `getMarketRate()`     |
| **Get Redemption Rate** | Get redemption rate        | `getRedemptionRate()` |
| **Check Depeg Status**  | Check if asset is depegged | `isDepegged()`        |

## Example: Get Asset Prices

```solidity
// Get the market price of the collateral
uint256 marketPrice = IVault(vaultAddress).getMarketRate();

// Get the redemption rate (typically lower than market)
uint256 redemptionRate = IVault(vaultAddress).getRedemptionRate();

// Check if asset is depegged
bool depegged = IVault(vaultAddress).isDepegged();
```

## Redemption Rate vs. Market Rate

* **Redemption Rate**: The contract rate at which the collateral can be redeemed for the underlying asset.
* **Market Rate**: The current market price of the collateral, which may differ from the redemption rate.

The protocol can be configured to use either rate through the `useMarketRate` setting in the UnstableConfigurator.

## Depeg Detection

The oracle system includes a mechanism to detect when a collateral asset has depegged from its expected value:

* **Depeg Threshold**: A parameter that determines the maximum allowed divergence between redemption and market rates.
* If the divergence exceeds this threshold, minting with that collateral can be automatically paused.

## Oracle Implementation

Oracles can be implemented in various ways:

1. **Direct Integration**: For assets with on-chain price data
2. **Chainlink Oracles**: For reliable, decentralized price feeds
3. **Custom ZkOracles**: For assets requiring more complex verification


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.unstable.money/developers/price-oracle.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
