> ## 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.

# FolioDeployer Contract

> Factory contract for deploying new Folio instances with optional governance

## Overview

The **FolioDeployer** contract is a factory that deploys new Folio instances. It supports two deployment patterns:

1. **Raw Folio**: Deploy with predefined roles for manual governance
2. **Governed Folio**: Deploy with full on-chain governance including timelock and voting

### Key Features

* Deterministic deployments using CREATE2
* Integrated governance setup (optional)
* Automatic role configuration
* Asset transfer and initialization

## Contract Details

```solidity FolioDeployer.sol theme={null}
contract FolioDeployer is IFolioDeployer, Versioned {
    address public immutable versionRegistry;
    address public immutable daoFeeRegistry;
    address public immutable trustedFillerRegistry;
    address public immutable folioImplementation;
    IGovernanceDeployer public immutable governanceDeployer;
}
```

## Deployment Functions

### Deploy Raw Folio

Deploy a Folio with predefined role assignments.

<ParamField path="basicDetails" type="FolioBasicDetails">
  Basic configuration including name, symbol, initial assets and shares
</ParamField>

<ParamField path="additionalDetails" type="FolioAdditionalDetails">
  Additional settings including fees, auction length, and mandate
</ParamField>

<ParamField path="folioFlags" type="FolioFlags">
  Feature flags for trusted filler, rebalance control, and bids
</ParamField>

<ParamField path="owner" type="address">
  Address to receive DEFAULT\_ADMIN\_ROLE
</ParamField>

<ParamField path="basketManagers" type="address[]">
  Addresses to receive REBALANCE\_MANAGER role
</ParamField>

<ParamField path="auctionLaunchers" type="address[]">
  Addresses to receive AUCTION\_LAUNCHER role
</ParamField>

<ParamField path="brandManagers" type="address[]">
  Addresses to receive BRAND\_MANAGER role
</ParamField>

<ParamField path="deploymentNonce" type="bytes32">
  Unique nonce for deterministic deployment
</ParamField>

```solidity FolioDeployer.sol theme={null}
function deployFolio(
    IFolio.FolioBasicDetails calldata basicDetails,
    IFolio.FolioAdditionalDetails calldata additionalDetails,
    IFolio.FolioFlags calldata folioFlags,
    address owner,
    address[] memory basketManagers,
    address[] memory auctionLaunchers,
    address[] memory brandManagers,
    bytes32 deploymentNonce
) public returns (Folio folio, address proxyAdmin)
```

<Info>
  The function automatically transfers the initial assets from msg.sender to the new Folio contract.
</Info>

### Deploy Governed Folio

Deploy a Folio with integrated on-chain governance.

<ParamField path="stToken" type="IVotes">
  Staking vault for governance voting power (use address(0) for self-governance)
</ParamField>

<ParamField path="basicDetails" type="FolioBasicDetails">
  Basic Folio configuration
</ParamField>

<ParamField path="additionalDetails" type="FolioAdditionalDetails">
  Additional Folio settings
</ParamField>

<ParamField path="folioFlags" type="FolioFlags">
  Feature flags
</ParamField>

<ParamField path="ownerGovParams" type="GovParams">
  Governance parameters for owner governor (reused for stToken if self-governed)
</ParamField>

<ParamField path="tradingGovParams" type="GovParams">
  Governance parameters for trading governor
</ParamField>

<ParamField path="govRoles" type="GovRoles">
  Role assignments including existing basket managers
</ParamField>

<ParamField path="deploymentNonce" type="bytes32">
  Unique deployment nonce
</ParamField>

```solidity FolioDeployer.sol theme={null}
function deployGovernedFolio(
    IVotes stToken,
    IFolio.FolioBasicDetails calldata basicDetails,
    IFolio.FolioAdditionalDetails calldata additionalDetails,
    IFolio.FolioFlags calldata folioFlags,
    IGovernanceDeployer.GovParams calldata ownerGovParams,
    IGovernanceDeployer.GovParams calldata tradingGovParams,
    GovRoles calldata govRoles,
    bytes32 deploymentNonce
) external returns (Folio folio, address proxyAdmin)
```

## Deployment Process

### Raw Folio Deployment

1. **CREATE2 Deployment**: Deploys FolioProxyAdmin and FolioProxy deterministically
2. **Asset Transfer**: Transfers initial assets from caller to Folio
3. **Initialization**: Calls Folio.initialize() with provided parameters
4. **Role Setup**: Grants roles to specified addresses
5. **Renounce**: Deployer renounces admin role (unless deployer is owner)

```solidity Example Deployment theme={null}
// Deploy a basic Folio
FolioDeployer deployer = FolioDeployer(DEPLOYER_ADDRESS);

IFolio.FolioBasicDetails memory basicDetails = IFolio.FolioBasicDetails({
    name: "My Index Folio",
    symbol: "MIF",
    assets: [DAI, USDC, USDT],
    amounts: [1000e18, 1000e6, 1000e6],
    initialShares: 3000e18
});

(Folio folio, address proxyAdmin) = deployer.deployFolio(
    basicDetails,
    additionalDetails,
    folioFlags,
    owner,
    basketManagers,
    auctionLaunchers,
    brandManagers,
    keccak256("unique-salt")
);
```

### Governed Folio Deployment

1. **Folio Deployment**: Uses deployFolio() internally with temporary owner
2. **Governance Deployment**: Creates governor and timelock for ownership
3. **Optional Trading Governance**: Creates separate governor for rebalancing (if no existing basket managers)
4. **Role Transfer**: Swaps ownership to timelock
5. **ProxyAdmin Transfer**: Transfers upgrade control to timelock

<Tip>
  For self-governed Folios (stToken = address(0)), a new StakingVault is deployed using the Folio shares as the underlying asset.
</Tip>

## Events

<ResponseField name="FolioDeployed" type="event">
  Emitted when a raw Folio is deployed

  **Parameters:**

  * `owner` - Admin address
  * `folio` - Deployed Folio address
  * `proxyAdmin` - ProxyAdmin address
</ResponseField>

<ResponseField name="GovernedFolioDeployed" type="event">
  Emitted when a governed Folio is deployed

  **Parameters:**

  * `stToken` - Staking token address
  * `folio` - Deployed Folio address
  * `ownerGovernor` - Owner governor address
  * `ownerTimelock` - Owner timelock address
  * `tradingGovernor` - Trading governor address
  * `tradingTimelock` - Trading timelock address
</ResponseField>

## Data Structures

### GovRoles

```solidity FolioDeployer.sol theme={null}
struct GovRoles {
    address[] existingBasketManagers;
    address[] auctionLaunchers;
    address[] brandManagers;
}
```

<ParamField path="existingBasketManagers" type="address[]">
  Existing basket managers (pass empty array to deploy trading governor)
</ParamField>

<ParamField path="auctionLaunchers" type="address[]">
  Addresses for AUCTION\_LAUNCHER role
</ParamField>

<ParamField path="brandManagers" type="address[]">
  Addresses for BRAND\_MANAGER role
</ParamField>

## Constructor

```solidity FolioDeployer.sol theme={null}
constructor(
    address _daoFeeRegistry,
    address _versionRegistry,
    address _trustedFillerRegistry,
    IGovernanceDeployer _governanceDeployer
)
```

The constructor:

1. Sets immutable registry addresses
2. Deploys the Folio implementation contract
3. Stores the governance deployer reference

## Deterministic Addresses

Deployments use CREATE2 for deterministic addresses:

```solidity Deployment Salt Calculation theme={null}
bytes32 deploymentSalt = keccak256(
    abi.encode(
        msg.sender,
        keccak256(
            abi.encode(
                basicDetails,
                additionalDetails,
                folioFlags,
                owner,
                basketManagers,
                auctionLaunchers,
                brandManagers
            )
        ),
        deploymentNonce
    )
);
```

<Warning>
  Changing any parameter (including the order of role arrays) will result in a different deployment address.
</Warning>
