# OracleRegistry

**Inherits:** IOracleRegistry, Auth2Step, ERC165

Canonical registry for ERC-7726-compatible price oracles Registry itself conforms to ERC-7726 (exposes `getQuote`) Owner seeds initial oracles on deploy; every subsequent oracle must be scheduled, then committed ≥ `ORACLE_UPDATE_DELAY` seconds later. A user (or its owner) may temporarily override with the pending oracle until the commit executes, enabling instant adoption if desired. Owner may disable any active oracle; `getQuote` then reverts unless a user override is in place

## State Variables

### ORACLE\_UPDATE\_DELAY

Mandatory delay (seconds) before a scheduled oracle can be committed

```solidity
uint256 public immutable ORACLE_UPDATE_DELAY;
```

### \_oracles

Registry mapping: base → quote → oracle data

```solidity
mapping(address base => mapping(address quote => OracleData oracleData)) internal _oracles;
```

### oracleOverrides

Per‑vault oracle overrides: user → base → quote → oracle

```solidity
mapping(address user => mapping(address base => mapping(address quote => IOracle))) public oracleOverrides;
```

## Functions

### requiresUserAuth

```solidity
modifier requiresUserAuth(address user);
```

### constructor

```solidity
constructor(address initialOwner, Authority initialAuthority, uint256 oracleUpdateDelay)
    Auth2Step(initialOwner, initialAuthority);
```

### addOracle

Adds an oracle for the provided base and quote assets

*MUST REVERT if not called by the authorized address*

```solidity
function addOracle(address base, address quote, IOracle oracle) external requiresAuth;
```

**Parameters**

| Name     | Type      | Description         |
| -------- | --------- | ------------------- |
| `base`   | `address` | Base asset address  |
| `quote`  | `address` | Quote asset address |
| `oracle` | `IOracle` | Oracle to add       |

### scheduleOracleUpdate

Schedules an oracle update for the base/quote asset pair The update process is a two-step process: first, the new oracle data is set using this function; second, the update is committed using the commitOracleUpdate function

*MUST REVERT if not called by the authorized address*

```solidity
function scheduleOracleUpdate(address base, address quote, IOracle oracle) external requiresAuth;
```

**Parameters**

| Name     | Type      | Description         |
| -------- | --------- | ------------------- |
| `base`   | `address` | Base asset address  |
| `quote`  | `address` | Quote asset address |
| `oracle` | `IOracle` | Oracle to schedule  |

### commitOracleUpdate

Commits the oracle update for the base/quote asset pair Can be called by anyone after the update process is initiated using `scheduleOracleUpdate` and the update delay has passed

*MUST REVERT if the update is not initiated*

```solidity
function commitOracleUpdate(address base, address quote) external;
```

**Parameters**

| Name    | Type      | Description         |
| ------- | --------- | ------------------- |
| `base`  | `address` | Base asset address  |
| `quote` | `address` | Quote asset address |

### cancelScheduledOracleUpdate

Cancels the scheduled update for the base/quote asset pair

*MUST REVERT if not called by the authorized address*

```solidity
function cancelScheduledOracleUpdate(address base, address quote) external requiresAuth;
```

**Parameters**

| Name    | Type      | Description         |
| ------- | --------- | ------------------- |
| `base`  | `address` | Base asset address  |
| `quote` | `address` | Quote asset address |

### disableOracle

Disables the oracle for the base/quote asset pair

*Performs a soft delete to forbid calling `addOracle` with the same base and quote assets and avoid front-running attack*

```solidity
function disableOracle(address base, address quote, IOracle oracle) external requiresAuth;
```

**Parameters**

| Name     | Type      | Description                   |
| -------- | --------- | ----------------------------- |
| `base`   | `address` | Base asset address            |
| `quote`  | `address` | Quote asset address           |
| `oracle` | `IOracle` | Oracle that is to be disabled |

### acceptPendingOracle

Allows a user to accept the pending oracle for a given base/quote pair during the delay period Can be called by the user to use the new oracle early

*MUST REVERT if the caller is not the user or its owner*

```solidity
function acceptPendingOracle(address base, address quote, address user, IOracle oracle)
    external
    requiresUserAuth(user);
```

**Parameters**

| Name     | Type      | Description                                |
| -------- | --------- | ------------------------------------------ |
| `base`   | `address` | Base asset address                         |
| `quote`  | `address` | Quote asset address                        |
| `user`   | `address` | Vault that is accepting the pending oracle |
| `oracle` | `IOracle` | Oracle that is to be accepted              |

### removeOracleOverride

Allows a user to remove the oracle override for a given base/quote pair

*MUST REVERT if the caller is not the user or its owner*

```solidity
function removeOracleOverride(address base, address quote, address user) external requiresUserAuth(user);
```

**Parameters**

| Name    | Type      | Description                             |
| ------- | --------- | --------------------------------------- |
| `base`  | `address` | Base asset address                      |
| `quote` | `address` | Quote asset address                     |
| `user`  | `address` | The vault address removing the override |

### getQuote

Returns the value of `baseAmount` of `base` in `quote` terms

*MUST round down towards 0 MUST revert with `OracleUnsupportedPair` if not capable to provide data for the specified `base` and `quote` pair MUST revert with `OracleUntrustedData` if not capable to provide data within a degree of confidence publicly specified*

```solidity
function getQuote(uint256 baseAmount, address base, address quote) external view virtual returns (uint256);
```

**Parameters**

| Name         | Type      | Description                                         |
| ------------ | --------- | --------------------------------------------------- |
| `baseAmount` | `uint256` | The amount of `base` to convert                     |
| `base`       | `address` | The asset that the user needs to know the value for |
| `quote`      | `address` | The asset in which the user needs to value the base |

**Returns**

| Name     | Type      | Description                                                      |
| -------- | --------- | ---------------------------------------------------------------- |
| `<none>` | `uint256` | quoteAmount The value of `baseAmount` of `base` in `quote` terms |

### getQuoteForUser

Returns the value of the base asset in terms of the quote asset with using the provided oracle data for the provided user (respects user-specific overrides)

```solidity
function getQuoteForUser(uint256 baseAmount, address base, address quote, address user)
    external
    view
    virtual
    returns (uint256);
```

**Parameters**

| Name         | Type      | Description          |
| ------------ | --------- | -------------------- |
| `baseAmount` | `uint256` | Amount of base asset |
| `base`       | `address` | Base asset address   |
| `quote`      | `address` | Quote asset address  |
| `user`       | `address` | Vault address        |

**Returns**

| Name     | Type      | Description                                         |
| -------- | --------- | --------------------------------------------------- |
| `<none>` | `uint256` | value of the base asset in terms of the quote asset |

### getOracleData

Return oracle metadata for base/quote

```solidity
function getOracleData(address base, address quote) external view virtual returns (OracleData memory);
```

**Parameters**

| Name    | Type      | Description         |
| ------- | --------- | ------------------- |
| `base`  | `address` | Base asset address  |
| `quote` | `address` | Quote asset address |

**Returns**

| Name     | Type         | Description      |
| -------- | ------------ | ---------------- |
| `<none>` | `OracleData` | data Oracle data |

### supportsInterface

*See {IERC165-supportsInterface}.*

```solidity
function supportsInterface(bytes4 interfaceId) public view override returns (bool);
```

### \_getOracleForVault

Get the oracle for a user

*Returns the current oracle if active or deprecated with no override reverts if the oracle is disabled and no override is set*

```solidity
function _getOracleForVault(address user, address base, address quote) internal view returns (IOracle);
```

**Parameters**

| Name    | Type      | Description                            |
| ------- | --------- | -------------------------------------- |
| `user`  | `address` | The user address to get the oracle for |
| `base`  | `address` | The base token address                 |
| `quote` | `address` | The quote token address                |

**Returns**

| Name     | Type      | Description                            |
| -------- | --------- | -------------------------------------- |
| `<none>` | `IOracle` | The oracle instance for the given pair |

### \_validateOracle

Validate that an oracle can convert one base token to a non‑zero quote token

*Implicitly checks zero address because the getQuote call reverts*

```solidity
function _validateOracle(IOracle oracle, address base, address quote) internal view;
```

**Parameters**

| Name     | Type      | Description             |
| -------- | --------- | ----------------------- |
| `oracle` | `IOracle` | The oracle to validate  |
| `base`   | `address` | The base token address  |
| `quote`  | `address` | The quote token address |

### \_getDecimals

Determine the decimals of an asset

*Defaults to 18 if the asset is not an ERC20*

```solidity
function _getDecimals(address asset) internal view returns (uint8);
```

**Parameters**

| Name    | Type      | Description                           |
| ------- | --------- | ------------------------------------- |
| `asset` | `address` | The asset address to get decimals for |

**Returns**

| Name     | Type    | Description               |
| -------- | ------- | ------------------------- |
| `<none>` | `uint8` | The decimals of the asset |


---

# 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.aera.finance/the-protocol/periphery/oracleregistry.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.
