# IOracleRegistry

**Inherits:** IOracle

Interface for an Oracle Registry

## Functions

### addOracle

Adds an oracle for the provided base and quote assets

*MUST REVERT if not called by the authorized address*

*MUST REVERT if the oracle is already set*

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

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

*MUST REVERT if the oracle data is already scheduled for an update*

*MUST REVERT if the oracle data is the same as the current oracle*

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

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

*MUST REVERT if the update delay has not passed*

```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*

*MUST REVERT if the update is not initiated*

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

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

*MUST REVERT if not called by the authorized address*

*MUST REVERT if the oracle data is not set*

*MUST REVERT if the oracle data is already disabled*

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

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

*MUST REVERT if the oracle is not set*

*MUST REVERT if current pending oracle doesn't match the oracle to be accepted*

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

**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;
```

**Parameters**

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

### 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
    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 returns (OracleData memory data);
```

**Parameters**

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

**Returns**

| Name   | Type         | Description |
| ------ | ------------ | ----------- |
| `data` | `OracleData` | Oracle data |

## Events

### OracleSet

Emitted when an oracle is added

```solidity
event OracleSet(address indexed base, address indexed quote, IOracle indexed oracle);
```

**Parameters**

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

### OracleScheduled

Emitted when an oracle update is scheduled

```solidity
event OracleScheduled(
    address indexed base, address indexed quote, IOracle indexed pendingOracle, uint32 commitTimestamp
);
```

**Parameters**

| Name              | Type      | Description                                        |
| ----------------- | --------- | -------------------------------------------------- |
| `base`            | `address` | Base asset address                                 |
| `quote`           | `address` | Quote asset address                                |
| `pendingOracle`   | `IOracle` | Pending oracle                                     |
| `commitTimestamp` | `uint32`  | The timestamp when the oracle data can be commited |

### OracleUpdateCancelled

Emitted when an oracle update is cancelled

```solidity
event OracleUpdateCancelled(address indexed base, address indexed quote);
```

**Parameters**

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

### OracleDisabled

Emitted when an oracle is disabled

```solidity
event OracleDisabled(address indexed base, address indexed quote, IOracle indexed oracle);
```

**Parameters**

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

### PendingOracleAccepted

Emitted when a user accepts an oracle update early

```solidity
event PendingOracleAccepted(address indexed user, address indexed base, address indexed quote, IOracle oracle);
```

**Parameters**

| Name     | Type      | Description                                        |
| -------- | --------- | -------------------------------------------------- |
| `user`   | `address` | Address of the user which accepted the oracle data |
| `base`   | `address` | Base asset address                                 |
| `quote`  | `address` | Quote asset address                                |
| `oracle` | `IOracle` | Oracle which was accepted                          |

### OracleOverrideRemoved

Emitted when an oracle override is removed

```solidity
event OracleOverrideRemoved(address indexed user, address indexed base, address indexed quote);
```

**Parameters**

| Name    | Type      | Description                                           |
| ------- | --------- | ----------------------------------------------------- |
| `user`  | `address` | Address of the user which removed the oracle override |
| `base`  | `address` | Base asset address                                    |
| `quote` | `address` | Quote asset address                                   |

## Errors

### AeraPeriphery\_\_CallerIsNotAuthorized

```solidity
error AeraPeriphery__CallerIsNotAuthorized();
```

### AeraPeriphery\_\_OracleMismatch

```solidity
error AeraPeriphery__OracleMismatch();
```

### AeraPeriphery\_\_CommitTimestampNotReached

```solidity
error AeraPeriphery__CommitTimestampNotReached();
```

### AeraPeriphery\_\_OracleUpdateDelayTooLong

```solidity
error AeraPeriphery__OracleUpdateDelayTooLong();
```

### AeraPeriphery\_\_OracleConvertsOneBaseTokenToZeroQuoteTokens

```solidity
error AeraPeriphery__OracleConvertsOneBaseTokenToZeroQuoteTokens(address base, address quote);
```

### AeraPeriphery\_\_NoPendingOracleUpdate

```solidity
error AeraPeriphery__NoPendingOracleUpdate();
```

### AeraPeriphery\_\_OracleIsDisabled

```solidity
error AeraPeriphery__OracleIsDisabled(address base, address quote, IOracle oracle);
```

### AeraPeriphery\_\_CannotScheduleOracleUpdateForTheSameOracle

```solidity
error AeraPeriphery__CannotScheduleOracleUpdateForTheSameOracle();
```

### AeraPeriphery\_\_OracleUpdateAlreadyScheduled

```solidity
error AeraPeriphery__OracleUpdateAlreadyScheduled();
```

### AeraPeriphery\_\_ZeroAddressOracle

```solidity
error AeraPeriphery__ZeroAddressOracle();
```

### AeraPeriphery\_\_OracleNotSet

```solidity
error AeraPeriphery__OracleNotSet();
```

### AeraPeriphery\_\_OracleAlreadySet

```solidity
error AeraPeriphery__OracleAlreadySet();
```

### AeraPeriphery\_\_OracleAlreadyDisabled

```solidity
error AeraPeriphery__OracleAlreadyDisabled();
```

### AeraPeriphery\_\_ZeroAddressOwner

```solidity
error AeraPeriphery__ZeroAddressOwner();
```
