# IPriceAndFeeCalculator

Interface for the unit price provider

## Functions

### setInitialPrice

Set the initial price state for the vault

```solidity
function setInitialPrice(address vault, uint128 price, uint32 timestamp) external;
```

**Parameters**

| Name        | Type      | Description                           |
| ----------- | --------- | ------------------------------------- |
| `vault`     | `address` | Address of the vault                  |
| `price`     | `uint128` | New unit price                        |
| `timestamp` | `uint32`  | Timestamp when the price was measured |

### setThresholds

Set vault thresholds

```solidity
function setThresholds(
    address vault,
    uint16 minPriceToleranceRatio,
    uint16 maxPriceToleranceRatio,
    uint16 minUpdateIntervalMinutes,
    uint8 maxPriceAge,
    uint8 maxUpdateDelayDays
) external;
```

**Parameters**

| Name                       | Type      | Description                                                                |
| -------------------------- | --------- | -------------------------------------------------------------------------- |
| `vault`                    | `address` | Address of the vault                                                       |
| `minPriceToleranceRatio`   | `uint16`  | Minimum ratio (of a price decrease) in basis points                        |
| `maxPriceToleranceRatio`   | `uint16`  | Maximum ratio (of a price increase) in basis points                        |
| `minUpdateIntervalMinutes` | `uint16`  | The minimum interval between updates in minutes                            |
| `maxPriceAge`              | `uint8`   | Max delay between when a vault was priced and when the price is acceptable |
| `maxUpdateDelayDays`       | `uint8`   | Max delay between two price updates                                        |

### setUnitPrice

Set the unit price for the vault in numeraire terms

```solidity
function setUnitPrice(address vault, uint128 price, uint32 timestamp) external;
```

**Parameters**

| Name        | Type      | Description                           |
| ----------- | --------- | ------------------------------------- |
| `vault`     | `address` | Address of the vault                  |
| `price`     | `uint128` | New unit price                        |
| `timestamp` | `uint32`  | Timestamp when the price was measured |

### pauseVault

Pause the vault

```solidity
function pauseVault(address vault) external;
```

**Parameters**

| Name    | Type      | Description          |
| ------- | --------- | -------------------- |
| `vault` | `address` | Address of the vault |

### unpauseVault

Unpause the vault

*MUST revert if price or timestamp don't exactly match last update*

```solidity
function unpauseVault(address vault, uint128 price, uint32 timestamp) external;
```

**Parameters**

| Name        | Type      | Description                           |
| ----------- | --------- | ------------------------------------- |
| `vault`     | `address` | Address of the vault                  |
| `price`     | `uint128` | Expected price of the last update     |
| `timestamp` | `uint32`  | Expected timestamp of the last update |

### resetHighestPrice

Resets the highest price for a vault to the current price

```solidity
function resetHighestPrice(address vault) external;
```

**Parameters**

| Name    | Type      | Description          |
| ------- | --------- | -------------------- |
| `vault` | `address` | Address of the vault |

### convertUnitsToToken

Convert units to token amount

```solidity
function convertUnitsToToken(address vault, IERC20 token, uint256 unitsAmount)
    external
    view
    returns (uint256 tokenAmount);
```

**Parameters**

| Name          | Type      | Description          |
| ------------- | --------- | -------------------- |
| `vault`       | `address` | Address of the vault |
| `token`       | `IERC20`  | Address of the token |
| `unitsAmount` | `uint256` | Amount of units      |

**Returns**

| Name          | Type      | Description      |
| ------------- | --------- | ---------------- |
| `tokenAmount` | `uint256` | Amount of tokens |

### convertUnitsToTokenIfActive

Convert units to token amount if vault is not paused

*MUST revert if vault is paused*

```solidity
function convertUnitsToTokenIfActive(address vault, IERC20 token, uint256 unitsAmount, Math.Rounding rounding)
    external
    view
    returns (uint256 tokenAmount);
```

**Parameters**

| Name          | Type            | Description          |
| ------------- | --------------- | -------------------- |
| `vault`       | `address`       | Address of the vault |
| `token`       | `IERC20`        | Address of the token |
| `unitsAmount` | `uint256`       | Amount of units      |
| `rounding`    | `Math.Rounding` | The rounding mode    |

**Returns**

| Name          | Type      | Description      |
| ------------- | --------- | ---------------- |
| `tokenAmount` | `uint256` | Amount of tokens |

### convertTokenToUnits

Convert token amount to units

```solidity
function convertTokenToUnits(address vault, IERC20 token, uint256 tokenAmount)
    external
    view
    returns (uint256 unitsAmount);
```

**Parameters**

| Name          | Type      | Description          |
| ------------- | --------- | -------------------- |
| `vault`       | `address` | Address of the vault |
| `token`       | `IERC20`  | Address of the token |
| `tokenAmount` | `uint256` | Amount of tokens     |

**Returns**

| Name          | Type      | Description     |
| ------------- | --------- | --------------- |
| `unitsAmount` | `uint256` | Amount of units |

### convertTokenToUnitsIfActive

Convert token amount to units if vault is not paused

*MUST revert if vault is paused*

```solidity
function convertTokenToUnitsIfActive(address vault, IERC20 token, uint256 tokenAmount, Math.Rounding rounding)
    external
    view
    returns (uint256 unitsAmount);
```

**Parameters**

| Name          | Type            | Description          |
| ------------- | --------------- | -------------------- |
| `vault`       | `address`       | Address of the vault |
| `token`       | `IERC20`        | Address of the token |
| `tokenAmount` | `uint256`       | Amount of tokens     |
| `rounding`    | `Math.Rounding` | The rounding mode    |

**Returns**

| Name          | Type      | Description     |
| ------------- | --------- | --------------- |
| `unitsAmount` | `uint256` | Amount of units |

### convertUnitsToNumeraire

Convert units to numeraire token amount

```solidity
function convertUnitsToNumeraire(address vault, uint256 unitsAmount) external view returns (uint256 numeraireAmount);
```

**Parameters**

| Name          | Type      | Description          |
| ------------- | --------- | -------------------- |
| `vault`       | `address` | Address of the vault |
| `unitsAmount` | `uint256` | Amount of units      |

**Returns**

| Name              | Type      | Description         |
| ----------------- | --------- | ------------------- |
| `numeraireAmount` | `uint256` | Amount of numeraire |

### getVaultState

Return the state of the vault

```solidity
function getVaultState(address vault) external view returns (VaultPriceState memory, VaultAccruals memory);
```

**Parameters**

| Name    | Type      | Description          |
| ------- | --------- | -------------------- |
| `vault` | `address` | Address of the vault |

**Returns**

| Name     | Type              | Description                                   |
| -------- | ----------------- | --------------------------------------------- |
| `<none>` | `VaultPriceState` | vaultPriceState The price state of the vault  |
| `<none>` | `VaultAccruals`   | vaultAccruals The accruals state of the vault |

### getVaultsPriceAge

Returns the age of the last submitted price for a vault

```solidity
function getVaultsPriceAge(address vault) external view returns (uint256);
```

**Parameters**

| Name    | Type      | Description          |
| ------- | --------- | -------------------- |
| `vault` | `address` | Address of the vault |

**Returns**

| Name     | Type      | Description                                                                      |
| -------- | --------- | -------------------------------------------------------------------------------- |
| `<none>` | `uint256` | priceAge The difference between block.timestamp and vault's unit price timestamp |

### isVaultPaused

Check if a vault is paused

```solidity
function isVaultPaused(address vault) external view returns (bool);
```

**Parameters**

| Name    | Type      | Description              |
| ------- | --------- | ------------------------ |
| `vault` | `address` | The address of the vault |

**Returns**

| Name     | Type   | Description                                  |
| -------- | ------ | -------------------------------------------- |
| `<none>` | `bool` | True if the vault is paused, false otherwise |

## Events

### ThresholdsSet

Emitted when thresholds are set for a vault

```solidity
event ThresholdsSet(
    address indexed vault,
    uint16 minPriceToleranceRatio,
    uint16 maxPriceToleranceRatio,
    uint16 minUpdateIntervalMinutes,
    uint8 maxPriceAge
);
```

**Parameters**

| Name                       | Type      | Description                                                                |
| -------------------------- | --------- | -------------------------------------------------------------------------- |
| `vault`                    | `address` | The address of the vault                                                   |
| `minPriceToleranceRatio`   | `uint16`  | Minimum ratio (of a price decrease) in basis points                        |
| `maxPriceToleranceRatio`   | `uint16`  | Maximum ratio (of a price increase) in basis points                        |
| `minUpdateIntervalMinutes` | `uint16`  | The minimum interval between updates in minutes                            |
| `maxPriceAge`              | `uint8`   | Max delay between when a vault was priced and when the price is acceptable |

### UnitPriceUpdated

Emitted when a vault's unit price is updated

```solidity
event UnitPriceUpdated(address indexed vault, uint128 price, uint32 timestamp);
```

**Parameters**

| Name        | Type      | Description                              |
| ----------- | --------- | ---------------------------------------- |
| `vault`     | `address` | The address of the vault                 |
| `price`     | `uint128` | The new unit price                       |
| `timestamp` | `uint32`  | The timestamp when the price was updated |

### VaultPausedChanged

Emitted when a vault's paused state is changed

```solidity
event VaultPausedChanged(address indexed vault, bool paused);
```

**Parameters**

| Name     | Type      | Description                 |
| -------- | --------- | --------------------------- |
| `vault`  | `address` | The address of the vault    |
| `paused` | `bool`    | Whether the vault is paused |

### HighestPriceReset

Emitted when a vault's highest price is reset

```solidity
event HighestPriceReset(address indexed vault, uint128 newHighestPrice);
```

**Parameters**

| Name              | Type      | Description              |
| ----------------- | --------- | ------------------------ |
| `vault`           | `address` | The address of the vault |
| `newHighestPrice` | `uint128` | The new highest price    |

## Errors

### Aera\_\_StalePrice

```solidity
error Aera__StalePrice();
```

### Aera\_\_TimestampMustBeAfterLastUpdate

```solidity
error Aera__TimestampMustBeAfterLastUpdate();
```

### Aera\_\_TimestampCantBeInFuture

```solidity
error Aera__TimestampCantBeInFuture();
```

### Aera\_\_ZeroAddressOracleRegistry

```solidity
error Aera__ZeroAddressOracleRegistry();
```

### Aera\_\_InvalidMaxPriceToleranceRatio

```solidity
error Aera__InvalidMaxPriceToleranceRatio();
```

### Aera\_\_InvalidMinPriceToleranceRatio

```solidity
error Aera__InvalidMinPriceToleranceRatio();
```

### Aera\_\_InvalidMaxPriceAge

```solidity
error Aera__InvalidMaxPriceAge();
```

### Aera\_\_InvalidMaxUpdateDelayDays

```solidity
error Aera__InvalidMaxUpdateDelayDays();
```

### Aera\_\_ThresholdNotSet

```solidity
error Aera__ThresholdNotSet();
```

### Aera\_\_VaultPaused

```solidity
error Aera__VaultPaused();
```

### Aera\_\_VaultNotPaused

```solidity
error Aera__VaultNotPaused();
```

### Aera\_\_UnitPriceMismatch

```solidity
error Aera__UnitPriceMismatch();
```

### Aera\_\_TimestampMismatch

```solidity
error Aera__TimestampMismatch();
```

### Aera\_\_VaultAlreadyInitialized

```solidity
error Aera__VaultAlreadyInitialized();
```

### Aera\_\_VaultNotInitialized

```solidity
error Aera__VaultNotInitialized();
```

### Aera\_\_InvalidPrice

```solidity
error Aera__InvalidPrice();
```

### Aera\_\_CurrentPriceAboveHighestPrice

```solidity
error Aera__CurrentPriceAboveHighestPrice();
```


---

# 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/core/ipriceandfeecalculator.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.
