> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/reserve-protocol/reserve-index-dtf/llms.txt
> Use this file to discover all available pages before exploring further.

# FolioVersionRegistry Contract

> Tracks Folio implementation versions and manages version deprecation

## Overview

The **FolioVersionRegistry** contract maintains a registry of Folio implementation versions. It tracks which deployer contracts are available for creating new Folios and allows the protocol to deprecate insecure or outdated versions.

### Key Features

* **Version Tracking**: Maps version strings to FolioDeployer contracts
* **Latest Version**: Maintains pointer to most recent deployment
* **Deprecation**: Can mark versions as deprecated for security
* **Version Queries**: Retrieve deployer and implementation for any version

## Registration Functions

### Register Version

Register a new Folio version with its deployer.

<ParamField path="folioDeployer" type="IFolioDeployer">
  Address of the FolioDeployer contract for this version
</ParamField>

```solidity FolioVersionRegistry.sol theme={null}
function registerVersion(IFolioDeployer folioDeployer) external
```

<Info>
  The version string is automatically read from the deployer contract using `Versioned(address(folioDeployer)).version()`. Each version can only be registered once.
</Info>

<Warning>
  Only protocol owners can register new versions. The newly registered version automatically becomes the latest version.
</Warning>

### Deprecate Version

Mark a version as deprecated, preventing its use in UI and warning users.

<ParamField path="versionHash" type="bytes32">
  Keccak256 hash of the version string to deprecate
</ParamField>

```solidity FolioVersionRegistry.sol theme={null}
function deprecateVersion(bytes32 versionHash) external
```

<Warning>
  Deprecation is irreversible. This should only be used for versions with security issues or critical bugs. Requires owner or emergency council role.
</Warning>

## Query Functions

### Get Latest Version

Retrieve the most recently registered version.

```solidity FolioVersionRegistry.sol theme={null}
function getLatestVersion() external view returns (
    bytes32 versionHash,
    string memory version,
    IFolioDeployer folioDeployer,
    bool deprecated
)
```

**Returns:**

* `versionHash`: Keccak256 hash of version string
* `version`: Human-readable version string (e.g., "3.4.1")
* `folioDeployer`: Deployer contract address
* `deprecated`: Whether this version is deprecated

<Info>
  The latest version may be deprecated if it was the most recent registration before being flagged. Always check the `deprecated` flag.
</Info>

### Get Implementation for Version

Retrieve the Folio implementation address for a specific version.

<ParamField path="versionHash" type="bytes32">
  Version hash to look up
</ParamField>

```solidity FolioVersionRegistry.sol theme={null}
function getImplementationForVersion(
    bytes32 versionHash
) external view returns (address folio)
```

### Get Deployer

Direct mapping access to get deployer for a version hash.

```solidity FolioVersionRegistry.sol theme={null}
function deployments(bytes32 versionHash) external view returns (IFolioDeployer)
```

### Check Deprecation Status

Check if a version is deprecated.

```solidity FolioVersionRegistry.sol theme={null}
function isDeprecated(bytes32 versionHash) external view returns (bool)
```

## Events

<ResponseField name="VersionRegistered" type="event">
  Emitted when a new version is registered

  **Parameters:**

  * `versionHash` - Keccak256 hash of version string
  * `folioDeployer` - Deployer contract address
</ResponseField>

<ResponseField name="VersionDeprecated" type="event">
  Emitted when a version is deprecated

  **Parameters:**

  * `versionHash` - Hash of deprecated version
</ResponseField>

## Errors

<ResponseField name="VersionRegistry__ZeroAddress" type="error">
  Thrown when trying to register a zero address
</ResponseField>

<ResponseField name="VersionRegistry__InvalidCaller" type="error">
  Thrown when caller lacks required permissions
</ResponseField>

<ResponseField name="VersionRegistry__InvalidRegistration" type="error">
  Thrown when trying to register an already-registered version
</ResponseField>

<ResponseField name="VersionRegistry__AlreadyDeprecated" type="error">
  Thrown when trying to deprecate an already-deprecated version
</ResponseField>

<ResponseField name="VersionRegistry__Unconfigured" type="error">
  Thrown when querying an unregistered version
</ResponseField>

## Access Control

<ParamField path="roleRegistry" type="IRoleRegistry">
  Immutable reference to the RoleRegistry for permission checks
</ParamField>

**Permissions:**

* `registerVersion()`: Requires owner role
* `deprecateVersion()`: Requires owner or emergency council role

## Version Hash Calculation

Version hashes are calculated as:

```solidity theme={null}
bytes32 versionHash = keccak256(abi.encodePacked(version));
```

For example, version "3.4.1" becomes:

```solidity theme={null}
keccak256(abi.encodePacked("3.4.1"))
```

## Usage Example

```solidity theme={null}
// Register a new version
FolioDeployer deployer = new FolioDeployer(/* ... */);
versionRegistry.registerVersion(deployer);

// Query latest version
(
    bytes32 versionHash,
    string memory version,
    IFolioDeployer folioDeployer,
    bool deprecated
) = versionRegistry.getLatestVersion();

require(!deprecated, "Latest version is deprecated");

// Use the deployer to create a Folio
address newFolio = folioDeployer.deployFolio(/* ... */);

// If security issue found
versionRegistry.deprecateVersion(versionHash);
```

## Integration with Versioned Contract

<Info>
  All FolioDeployer contracts must inherit from the `Versioned` base contract, which implements a `version()` function returning a semantic version string.
</Info>

```solidity theme={null}
contract FolioDeployer is Versioned {
    // version() returns something like "3.4.1"
}
```

## Frontend Integration

<Info>
  Frontends should always check both if a version exists and whether it's deprecated before allowing users to deploy with it. Use `getLatestVersion()` to show the recommended version.
</Info>
