# LockHolderV1

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

**LockHolderV1** is an upgradeable contract integrated with **DelegationManager**, **EscrowManager**, **EscrowVoteManager**, **IncentiveRewardsAggregatorV1**. For each delegator-delegate pair, a different LockHolder contract is deployed, with delegated locks in the balance. Through the LockHolder contract the proxied call of functions of **EscrowManager**, **EscrowVoteManager** counters, as well as collection and distribution of incentive rewards takes place.

**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.
* **ILockHolderV1:**\
  Defines core methods (e.g., `boost`, `deboost`, `extend`) and events for this contract.

**Additional External References:**

* **SafeERC20, IERC20 (OpenZeppelin):** Handles secure ERC20 operations for distributing and approving token transfers.
* **IIncentiveRewardsAggregatorV1:** Aggregates lists of reward tokens.
* **IEscrowVoteManagerV1:** Receives gauge emission amounts and coordinates gauge reward distribution.
* **IEscrowManager:** Holds locked token data and checks voting power and freeze logic.

***

### Constants <a href="#constants" id="constants"></a>

```solidity
uint256 private constant PRECISION = 100_000;
```

* **PRECISION**: The divisior for percentage math.

***

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

* **`s_delegationManager (address)`**\
  address of the delegation manager contract.
* **`s_escrowVoteManager (IEscrowVoteManagerV1)`**\
  IEscrowVoteManagerV1 interface for the escrow vote manager contract.
* **`s_incentiveRewardsAggregator (IIncentiveRewardsAggregatorV1)`**\
  IIncentiveRewardsAggregatorV1 Interface for the incentive rewards aggregator 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 ILockHolderV1) <a href="#external-functions-defined-by-ilockholderv1" id="external-functions-defined-by-ilockholderv1"></a>

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

```solidity
function initialize(
    address owner_,
    address delegationManager_,
    IEscrowManager escrowManager_,
    IEscrowVoteManagerV1 escrowVoteManager_,
    IIncentiveRewardsAggregatorV1 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.
* `delegationManager_`: The address of the delegation manager contract.
* `escrowManager_`: The address of the escrow manager contract.
* `escrowVoteManager_`: The address of the escrow vote manager contract.
* `incentiveRewardsAggregator_`: The address of the incentive rewards aggregator contract.

***

#### `claimIncentives(address delegator_, address delegatee_, uint256 percentIncentive_)` <a href="#claimincentives-address-delegator_-address-delegatee_-uint256-percentincentive" id="claimincentives-address-delegator_-address-delegatee_-uint256-percentincentive"></a>

```solidity
function claimIncentives(
    address delegator_, 
    address delegatee_, 
    uint256 percentIncentive_
) external;
```

**Description:**\
Function for claim and distributing incentives. The function queries arrays with the addresses of the reward tokens and the size of the reward for each of them on the **IncentiveRewardsAggregatorV1** contract Then for each **IncentiveRewardsDistributor** it claim incentives, calculates on the basis of `percentIncentive_` what parts of it should be received by `delegator_` and `delegatee_` and distributes incentives between them.

**Parameters:**

* `delegator_`: The delegator's address.
* `delegatee_`: The delegate's address.
* `percentIncentive_`: The percentage of the incentive reward received by the delegate.

**Checks:**

* The function must be called by the **DelegationManager** contract. Otherwise, `UnauthorizedCaller()` is thrown.

***

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

* **`UnauthorizedCaller()`**\
  Thrown when the caller is not authorized to perform the action.

***

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

**LockHolderV1** contract is an important and necessary part of the lock delegation and self-delegation architecture. It allows for diverse and flexible interaction and integration with all contracts in the system.


---

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