# LockHolderFactoryV1

### Overview <a href="#overview" id="overview"></a>

**LockHolderFactoryV1** This is an upgradeable contract that deploys new **LockHolder** contracts on the blockchain. It is integrated with the **DelegationManager** contract.

**Key Roles and Features:**

1. **Access Control:** Restricts **setAssuranceLockParameters** and **setMinLockVeEywa** calls to the **owner** of contract(`owner()`).
2. **Upgradeable via UUPS:** Uses **UUPSUpgradeable** and **OwnableUpgradeable** patterns, restricting contract upgrades to the owner.

***

### Inherited Contracts and Interfaces <a href="#inherited-contracts-and-interfaces" id="inherited-contracts-and-interfaces"></a>

* **UUPSUpgradeable (OpenZeppelin):**\
  Provides upgrade functionality under the UUPS proxy pattern, restricted to the contract owner.
* **OwnableUpgradeable (OpenZeppelin):**\
  Manages ownership, allowing only the owner to modify critical parameters and authorize upgrades.
* **ILockHolderFactoryV1:**\
  Defines core methods (e.g., `createLockHolder`) and events for this contract.

**Additional External References:**

* **ERC1967Proxy (OpenZeppelin):** A proxy implementation that stores the logic contract address in storage per EIP-1967.
* **LockHolderV1:** LockHolder contract.

***

### State Variables <a href="#state-variables" id="state-variables"></a>

* **`s_escrowManager (address)`**\
  Address of the EscrowManager contract.
* **`s_escrowVoteManager (address)`**\
  Address of the EscrowVoteManager contract.
* **`s_delegationManager (address)`**\
  Address of the DelegationManager contract.
* **`s_incentiveRewardsAggregator (address)`**\
  Address of the IncentiveRewardsAggregator contract.

***

### Constructor <a href="#constructor" id="constructor"></a>

```solidity
constructor() {
    _disableInitializers();
}
```

* **Description:**\
  Disables contract initializers to prevent re-initialization in a UUPS proxy context.

***

### External Functions (Defined by ILockHolderFactoryV1) <a href="#external-functions-defined-by-ilockholderfactoryv1" id="external-functions-defined-by-ilockholderfactoryv1"></a>

#### `initialize(...)` <a href="#initialize" id="initialize"></a>

```solidity
function initialize(
    address owner_, 
    address escrowManager_,
    address escrowVoteManager_,
    address delegationManager_,
    address incentiveRewardsAggregator_
) external initializer;
```

**Description:**\
Configures ownership, references, and initial state:

* References the EYWA NFT, escrow manager, escrow vote manager and delegation manager.

**Parameters:**

* `owner_`: The address of the contract owner.
* `escrowManager_`: The address of the escrow manager contract.
* `escrowVoteManager_`: The address of the escrow vote manager contract.
* `delegationManager_`: The address of the delegation manager contract.
* `incentiveRewardsAggregator_`: The address of the incentive rewards aggregator contract.

***

#### `createLockHolder()` <a href="#createlockholder" id="createlockholder"></a>

```solidity
function createLockHolder() external returns (address);
```

**Description:**\
The function deploys and initializes an upgradable LockHolder contract. Returns the address of the LockHolder contract.

**Checks:**

* sender must be a DelegationManager contract. Otherwise, `UnauthorizedCaller()` is thrown.

**Events:**

* Emits `LockHolderCreated(m_lockHolder, m_implementation)`.

***

### Events <a href="#events" id="events"></a>

* **`LockHolderCreated(address indexed lockHolder, address indexed implementation))`**\
  Emitted when a new LockHolder is created.

***

### Errors <a href="#errors" id="errors"></a>

* **`UnauthorizedCaller()`**\
  Thrown when the caller is not the delegation manager.

***

### Summary <a href="#summary" id="summary"></a>

**LockHolderFactoryV1** contract is an important part of the lock delegation architecture. It deploys a new **LockHolder** contract for each delegator-delegate pair, which provides the ability to reliably track the movement of delegated locks, manage them, and receive and distribute rewards.


---

# 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.crosscurve.fi/developer-documentation/guide-for-developers/technical-documentation-for-crosscurve-dao-smart-contracts/lockholderfactoryv1.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.
