# SpotOracle

[Git Source](https://github.com/Ion-Protocol/ion-protocol/blob/88cc595825f1dc2eb738fb93e172a3e8ab7a5c43/src/oracles/spot/SpotOracle.sol)

The `SpotOracle` is supposed to reflect the current market price of a collateral asset. It is used by `IonPool` to determine the health factor of a vault as a user is opening or closing a position. NOTE: The price data provided by this contract is not used by the liquidation module at all. The spot price will also always be bounded by the collateral's corresponding reserve oracle price to ensure that a user can never open position that is directly liquidatable.

### [State Variables](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#state-variables" id="state-variables"></a>

#### [LTV](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#ltv" id="ltv"></a>

```
uint256 public immutable LTV;
```

#### [RESERVE\_ORACLE](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#reserve_oracle" id="reserve_oracle"></a>

```
ReserveOracle public immutable RESERVE_ORACLE;
```

### [Functions](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#functions" id="functions"></a>

#### [constructor](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#constructor" id="constructor"></a>

Creates a new `SpotOracle` instance.

```
constructor(uint256 _ltv, address _reserveOracle);
```

**Parameters**

| Name             | Type      | Description                                |
| ---------------- | --------- | ------------------------------------------ |
| `_ltv`           | `uint256` | Loan to value ratio for the collateral.    |
| `_reserveOracle` | `address` | Address for the associated reserve oracle. |

#### [getPrice](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#getprice" id="getprice"></a>

Gets the price of the collateral asset in ETH.

*Overridden by collateral specific spot oracle contracts.*

```
function getPrice() public view virtual returns (uint256 price);
```

**Returns**

| Name    | Type      | Description                 |
| ------- | --------- | --------------------------- |
| `price` | `uint256` | of the asset in ETH. \[WAD] |

#### [getSpot](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#getspot" id="getspot"></a>

Gets the risk-adjusted market price.

```
function getSpot() external view returns (uint256 spot);
```

**Returns**

| Name   | Type      | Description                     |
| ------ | --------- | ------------------------------- |
| `spot` | `uint256` | The risk-adjusted market price. |

### [Errors](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#errors" id="errors"></a>

#### [InvalidLtv](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#invalidltv" id="invalidltv"></a>

```
error InvalidLtv(uint256 ltv);
```

#### [InvalidReserveOracle](https://docs.ionprotocol.io/devs/smart-contract-architecture/oracles/spot/broken-reference) <a href="#invalidreserveoracle" id="invalidreserveoracle"></a>

```
error InvalidReserveOracle();
```
