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

# GovernanceDeployer Contract

> Factory contract for deploying staking vaults with integrated governance and timelock

## Overview

The **GovernanceDeployer** contract is a factory that deploys complete governance systems with a single transaction. It creates a StakingVault (voting token), Governor, and Timelock Controller, all properly configured and connected.

### Key Features

* **One-Transaction Deployment**: Creates entire governance stack atomically
* **Deterministic Addresses**: Uses CREATE2 for predictable contract addresses
* **Staking Vault Integration**: Deploys ERC4626 staking vaults with voting power
* **Timelock Control**: Governor proposals execute through a timelock
* **Guardian Roles**: Supports guardian addresses with cancellation powers

### Architecture

GovernanceDeployer uses minimal proxy clones (EIP-1167) for gas-efficient deployments:

* **Governor Implementation**: Clone of FolioGovernor
* **Timelock Implementation**: Clone of TimelockControllerUpgradeable
* **StakingVault Implementation**: Clone of StakingVault

## Deployment Functions

### Deploy Governed Staking Token

Deploy a complete governance system with a new staking vault.

<ParamField path="name" type="string">
  Name of the staking vault token
</ParamField>

<ParamField path="symbol" type="string">
  Symbol of the staking vault token
</ParamField>

<ParamField path="underlying" type="IERC20">
  Underlying token that will be staked
</ParamField>

<ParamField path="govParams" type="GovParams">
  Governance parameters including voting periods, thresholds, and guardians
</ParamField>

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

```solidity GovernanceDeployer.sol theme={null}
function deployGovernedStakingToken(
    string memory name,
    string memory symbol,
    IERC20 underlying,
    IGovernanceDeployer.GovParams calldata govParams,
    bytes32 deploymentNonce
) external returns (
    StakingVault stToken,
    address governor,
    address timelock
)
```

<Info>
  This function deploys all three contracts (StakingVault, Governor, Timelock) and configures them to work together. The timelock becomes the owner of the staking vault.
</Info>

### Deploy Governance With Timelock

Deploy only the Governor and Timelock (for existing voting tokens).

<ParamField path="govParams" type="GovParams">
  Governance parameters
</ParamField>

<ParamField path="stToken" type="IVotes">
  Existing voting token to use
</ParamField>

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

```solidity GovernanceDeployer.sol theme={null}
function deployGovernanceWithTimelock(
    IGovernanceDeployer.GovParams calldata govParams,
    IVotes stToken,
    bytes32 deploymentNonce
) public returns (address governor, address timelock)
```

## Governance Parameters

The `GovParams` struct configures all governance settings:

<ParamField path="votingDelay" type="uint48">
  Delay before voting begins after proposal creation (seconds)
</ParamField>

<ParamField path="votingPeriod" type="uint32">
  Duration of voting period (seconds)
</ParamField>

<ParamField path="proposalThreshold" type="uint256">
  Minimum voting power required to create a proposal (D18 format)
</ParamField>

<ParamField path="quorumThreshold" type="uint256">
  Minimum voting power required for quorum (D18 format)
</ParamField>

<ParamField path="timelockDelay" type="uint256">
  Delay before approved proposals can be executed (seconds)
</ParamField>

<ParamField path="guardians" type="address[]">
  Addresses that can cancel malicious proposals
</ParamField>

## Default Configuration

<ParamField path="DEFAULT_REWARD_PERIOD" type="uint256" default="3.5 days">
  Half-life for reward distribution in staking vaults
</ParamField>

<ParamField path="DEFAULT_UNSTAKING_DELAY" type="uint256" default="1 week">
  Delay before unstaked tokens can be withdrawn
</ParamField>

## Events

<ResponseField name="DeployedGovernedStakingToken" type="event">
  Emitted when a complete governance system with staking vault is deployed

  **Parameters:**

  * `underlying` - Underlying token address
  * `stToken` - Deployed staking vault address
  * `governor` - Deployed governor address
  * `timelock` - Deployed timelock address
</ResponseField>

<ResponseField name="DeployedGovernance" type="event">
  Emitted when governance (without new staking vault) is deployed

  **Parameters:**

  * `stToken` - Voting token address
  * `governor` - Deployed governor address
  * `timelock` - Deployed timelock address
</ResponseField>

## Implementation Addresses

<ParamField path="governorImplementation" type="address">
  Immutable address of the FolioGovernor implementation to clone
</ParamField>

<ParamField path="timelockImplementation" type="address">
  Immutable address of the TimelockController implementation to clone
</ParamField>

<ParamField path="stakingVaultImplementation" type="address">
  Immutable address of the StakingVault implementation to clone
</ParamField>

## Usage Example

```solidity theme={null}
// Example governance parameters
IGovernanceDeployer.GovParams memory params = IGovernanceDeployer.GovParams({
    votingDelay: 1 days,
    votingPeriod: 7 days,
    proposalThreshold: 100e18,  // 100 tokens
    quorumThreshold: 1000e18,   // 1000 tokens
    timelockDelay: 2 days,
    guardians: new address[](0)
});

// Deploy complete governance system
(StakingVault stToken, address governor, address timelock) = 
    deployer.deployGovernedStakingToken(
        "Staked FOL",
        "stFOL",
        folToken,
        params,
        bytes32(0)
    );
```

<Warning>
  The deployer temporarily holds admin rights on the timelock but renounces them after granting guardian roles. This ensures proper decentralization.
</Warning>
