# Oracle

### setExternalOracle

Defines the underlying asset symbol and oracle address for a pool. Only called by the owner.

```javascript
function setExternalOracle(string[] calldata symbols, address[] calldata oracles_) external onlyOwner 
```

**Params:**

| **Name**  | **Type** | **Description**                                   |
| --------- | -------- | ------------------------------------------------- |
| symbols   | string   | The asset symbol for which to retrieve price feed |
| oracles\_ | address  | The external oracle address                       |

### setFixPrice

Sets the price for an asset.

```javascript
function setFixPrice(string memory symbol, uint256 ts, uint256 price) external onlyOwner 
```

**Params:**

| **Name** | **Type**                                                        | **Description**                               |
| -------- | --------------------------------------------------------------- | --------------------------------------------- |
| symbol   | string The symbol of the asset for which the price is being set |                                               |
| ts       | uint256                                                         | The timestamp associated with the asset price |
| price    | uint256                                                         | The retrieved price of the asset              |

### getPriceByExternal

Gets and computes price from external oracles

```javascript
function getPriceByExternal(address cOracleAddr, uint256 ts) external view returns (uint256 price, uint256 actualTs)
```

**Params:**

| **Name**    | **Type** | **Description**                                 |
| ----------- | -------- | ----------------------------------------------- |
| cOracleAddr | address  | The contract address for a chainlink price feed |
| ts          | uint256  | Timestamp for the asset price                   |

**Returns:**

| **Name** | **Type** | **Description**                                           |
| -------- | -------- | --------------------------------------------------------- |
| price    | uint256  | The retrieved price                                       |
| actualTs | uint256  | The timestamp at which the price is updated by the oracle |

### \_getPrice

This internal helper function retrieves the underlying price from an external oracle.

```javascript
    function _getPrice(
        AggregatorV3Interface cOracle,
        uint80 id,
        uint256 ts,
        uint256 decimalDiff
    )
        private
        view
        returns (uint256 finalPrice, uint256 finalTs)
```

**Params:**

| **Name**    | **Type**              | **Description**                                        |
| ----------- | --------------------- | ------------------------------------------------------ |
| cOracle     | AggregatorV3Interface | Oracle interface for retrieving price feed             |
| id          | uint80                | The roundId using which price is retrieved             |
| ts          | uint256               | Timestamp for the asset price                          |
| decimalDiff | uint256               | Precision differences for the number of decimal places |

**Returns:**

| **Name**   | **Type** | **Description**                                           |
| ---------- | -------- | --------------------------------------------------------- |
| finalPrice | uint256  | The computed price                                        |
| finalTs    | uint256  | The timestamp at which the price is updated by the oracle |

### getCOracle

Returns the address of the chainlink oracle for an underlying asset

```javascript
function getCOracle(string memory symbol) public view returns (address)
```

**Params:**

| **Name** | **Type** | **Description**                                          |
| -------- | -------- | -------------------------------------------------------- |
| symbol   | string   | The symbol of the asset for which the price is being set |

**Returns:**

| **Type** | **Description**                                 |
| -------- | ----------------------------------------------- |
| address  | The contract address for a chainlink price feed |

### \_getPhaseIdFromRoundId

Returns the phaseId from the given roundId used by the external oracle

```javascript
function _getPhaseIdFromRoundId(uint80 roundId) internal pure returns (uint80) 
```

**Params:**

| **Name** | **Type** | **Description**   |
| -------- | -------- | ----------------- |
| roundId  | uint80   | The given roundId |

**Returns:**

| **Type** | **Description**                 |
| -------- | ------------------------------- |
| uint80   | The phaseId for the given round |

### \_getStartRoundId

Returns the start roundId given a phaseId

```javascript
function _getStartRoundId(uint80 phaseId) internal pure returns (uint80)
```

**Params:**

| **Name** | **Type** | **Description**   |
| -------- | -------- | ----------------- |
| phaseId  | uint80   | The given phaseId |

**Returns:**

| **Type** | **Description**   |
| -------- | ----------------- |
| uint80   | The start roundId |

### \_getPriceInPhase

Helper for getting the

```javascript
    function _getPriceInPhase(
        AggregatorV3Interface cOracle,
        uint80 start,
        uint80 end,
        uint256 ts,
        uint256 decimalDiff
    )
        internal
        view
        returns (uint256 price, uint256 actualTs)
```

**Params:**

| **Name**    | **Type**              | **Description**                                        |
| ----------- | --------------------- | ------------------------------------------------------ |
| cOracle     | AggregatorV3Interface | Oracle interface for retrieving price feed             |
| start       | uint80                | The start phaseId                                      |
| end         | uint80                | The end phaseId                                        |
| ts          | uint256               | Timestamp for the underlying price                     |
| decimalDiff | uint256               | Precision differences for the number of decimal places |

**Returns:**

| **Name** | **Type** | **Description**                                           |
| -------- | -------- | --------------------------------------------------------- |
| Price    | uint256  | The computed price                                        |
| actualTs | uint256  | The timestamp at which the price is updated by the oracle |


---

# 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.divergence-protocol.com/technical-reference/core/oracle.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.
