# Oracles

Contract to get asset prices and manage price sources.

The source code is available on Aave's [<mark style="color:blue;">GitHub</mark>](https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/misc/AaveOracle.sol).

{% hint style="info" %}
This contract is owned by Tydro
{% endhint %}

### Write Methods

#### setAssetSources

```
function setAssetSources(address[] calldata assets, address[] calldata sources) external override onlyAssetListingOrPoolAdmins
```

Sets the price sources for given list of assets.

This method can only be called by a POOL\_ADMIN or ASSET\_LISTING\_ADMIN. Please look at the [ACLManager](/developers/smart-contracts/aclmanager.md) contract for further details on system roles.

**Input Parameters:**

| Name    | Type       | Description                                                                                |
| ------- | ---------- | ------------------------------------------------------------------------------------------ |
| assets  | address\[] | The addresses of the assets for which source is being set                                  |
| sources | address\[] | The address of the source of each asset. Length of assets and sources array should be same |

#### setFallbackOracle

```
function setFallbackOracle(address fallbackOracle) external override onlyAssetListingOrPoolAdmins
```

Sets/updates the fallbackOracle.

This method can only be called by a POOL\_ADMIN or ASSET\_LISTING\_ADMIN. Please look at the [ACLManager](/developers/smart-contracts/aclmanager.md) contract for further details on system roles.

**Input Parameters:**

| Name           | Type    | Description                        |
| -------------- | ------- | ---------------------------------- |
| fallbackOracle | address | The address of the fallback oracle |

### View Methods

#### getAssetPrice

```
function getAssetPrice(address asset) public view override returns (uint256)
```

Returns the price of the supported asset in [<mark style="color:blue;">BASE\_CURRENCY</mark>](https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/interfaces/IPriceOracleGetter.sol) of the Tydro market in wei.

**Input Parameters:**

| Name  | Type    | Description              |
| ----- | ------- | ------------------------ |
| asset | address | The address of the asset |

**Return Values:**

| Type    | Description                                                         |
| ------- | ------------------------------------------------------------------- |
| uint256 | The price of the asset in BASE\_CURRENCY of the Tydro market in wei |

#### getAssetsPrices

```
function getAssetsPrices(address[] calldata assets) external view override returns (uint256[] memory)
```

Returns a list of prices from a list of the supported assets addresses in [<mark style="color:blue;">BASE\_CURRENCY</mark>](https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/interfaces/IPriceOracleGetter.sol) of the Tydro market. All prices are in wei.

**Input Parameters:**

| Name   | Type       | Description                                                   |
| ------ | ---------- | ------------------------------------------------------------- |
| assets | address\[] | The list of assets addresses for which price is being queried |

**Return Values:**

| Type       | Description                                                                 |
| ---------- | --------------------------------------------------------------------------- |
| uint256\[] | The prices of the given assets in BASE\_CURRENCY of the Tydro market in wei |

#### getSourceOfAsset

```
function getSourceOfAsset(address asset) external view override returns (address)
```

Returns the address of the price source for an asset address.

**Input Parameters:**

| Name  | Type    | Description              |
| ----- | ------- | ------------------------ |
| asset | address | The address of the asset |

**Return Values:**

| Type    | Description               |
| ------- | ------------------------- |
| address | The address of the source |

#### getFallbackOracle

```
function getFallbackOracle() external view returns (address)
```

Returns the address of the fallback oracle.

**Return Values:**

| Type    | Description                        |
| ------- | ---------------------------------- |
| address | The address of the fallback oracle |

## PriceOracleSentinel

The PriceOracleSentinel contract validates if the operations are allowed depending on the PriceOracle health.

This feature introduces a grace period for liquidations and disables borrowing under specific circumstances.

This feature has been specifically designed for L2s to handle eventual downtime of the sequencer (but can be extended to handle other cases, even on L1s, in the future).

Once the PriceOracle gets up after an outage or downtime, users can make their positions healthy during a grace period. The PriceOracle is considered healthy once its completely up and the grace period has passed.

The source code is available on [<mark style="color:blue;">Github</mark>](https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/misc/PriceOracleSentinel.sol).

### Write Methods

#### setSequencerOracle

```
function setSequencerOracle(address newSequencerOracle) external onlyPoolAdmin
```

Updates the address of the sequencer oracle.

This method can only be called by PoolAdmin.

This method can only be called by the *Role Admin*, responsible for managing the [POOL\_ADMIN](/developers/smart-contracts/aclmanager.md#pool_admin) role.

**Input Parameters:**

| Name               | Type    | Description                                       |
| ------------------ | ------- | ------------------------------------------------- |
| newSequencerOracle | address | The address of the new Sequencer Oracle to be set |

#### setGracePeriod

```
function setGracePeriod(uint256 newGracePeriod) public onlyRiskOrPoolAdmins
```

Updates the duration of the grace period.

Can only be called by PoolAdmin or RiskAdmin.

**Input Parameters:**

| Name           | Type    | Description                                 |
| -------------- | ------- | ------------------------------------------- |
| newGracePeriod | uint256 | The duration of new grace period in seconds |

### View Methods

#### isBorrowAllowed

```
function isBorrowAllowed() external view override returns (bool)
```

Returns true if the borrow operation is allowed. The operation is not allowed when PriceOracleis down or the grace period has not passed.

**Return Values:**

| Type | Description                                                                                                          |
| ---- | -------------------------------------------------------------------------------------------------------------------- |
| bool | Returns true if the borrow operation is allowed (the PriceOracle is up and grace period has passed), false otherwise |

#### isLiquidationAllowed

```
function isLiquidationAllowed() external view override returns (bool)
```

Returns true if the liquidation operation is allowed. The operation is not allowed when PriceOracle is down or the grace period has not passed.

**Return Values:**

| Type | Description                                                                                                               |
| ---- | ------------------------------------------------------------------------------------------------------------------------- |
| bool | Returns true if the liquidation operation is allowed (the PriceOracle is up and grace period has passed), false otherwise |

#### getSequencerOracle

```
function getSequencerOracle() external view returns (address)
```

Returns the SequencerOracle.

**Return Values:**

| Type    | Description                                  |
| ------- | -------------------------------------------- |
| address | The address of the sequencer oracle contract |

#### getGracePeriod

```
function getGracePeriod() external view returns (uint256)
```

Returns the grace period.

**Return Values:**

| Type    | Description                                 |
| ------- | ------------------------------------------- |
| uint256 | The duration of the grace period in seconds |


---

# 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.tydro.com/developers/smart-contracts/oracles.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.
