# MaverickV2VotingEscrow

**Inherits:** [VotingEscrow](https://docs.mav.xyz/technical-reference/maverick-v2/v2-contracts/maverick-v2-reward-contracts/votingescrowbase/votingescrow)

Provides staking, vote power history, vote delegation, and incentive disbursement to ve holders.

*`VotingEscrow` contract provides details on the staking and delegation features.*

Incentive disbursement can take place in any token and happens when a user permissionlessly creates a new incentive batch for a specified amount of incentive tokens, timepoint, stake duration, and associated ERC-20 token. An incentive batch is a reward of incentives put up by the caller at a certain timepoint. The incentive batch is claimable by ve holders after the timepoint has passed. The ve holders will receive their incentive pro rata of their vote balance (`pastbalanceOf`) at that timepoint. The incentivizer can specify that users have to stake the resulting incentive for a given `stakeDuration` number of seconds. `stakeDuration` can either be zero, meaning that no staking is required on redemption, or can be a number between `MIN_STAKE_DURATION()` and `MAX_STAKE_DURATION()`.

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

#### \_incentiveBatches <a href="#incentivebatches" id="incentivebatches"></a>

```solidity
mapping(uint256 => IncentiveSpecification) private _incentiveBatches;
```

#### \_tokenIncentiveTotals <a href="#tokenincentivetotals" id="tokenincentivetotals"></a>

```solidity
mapping(IERC20 => TokenIncentiveTotals) private _tokenIncentiveTotals;
```

#### incentiveBatchCount <a href="#incentivebatchcount" id="incentivebatchcount"></a>

This function retrieves the total number of created incentive batches.

```solidity
uint256 public incentiveBatchCount;
```

### Functions <a href="#functions" id="functions"></a>

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

```solidity
constructor(string memory __name, string memory __symbol) VotingEscrow(__name, __symbol);
```

#### createIncentiveBatch <a href="#createincentivebatch" id="createincentivebatch"></a>

This function creates a new incentive batch for a specified amount of incentive tokens, timepoint, stake duration, and associated ERC-20 token. An incentive batch is a reward of incentives put up by the caller at a certain timepoint. The incentive batch is claimable by ve holders after the timepoint has passed. The ve holders will receive their incentive pro rata of their vote balance (`pastbalanceOf`) at that timepoint. The incentivizer can specify that users have to stake the resulting incentive for a given `stakeDuration` number of seconds. `stakeDuration` can either be zero, meaning that no staking is required on redemption, or can be a number between `MIN_STAKE_DURATION()` and `MAX_STAKE_DURATION()`.

```solidity
function createIncentiveBatch(uint128 amount, uint48 timepoint, uint128 stakeDuration, IERC20 incentiveToken)
    public
    returns (uint256 index);
```

**Parameters**

| Name             | Type      | Description                                                                                |
| ---------------- | --------- | ------------------------------------------------------------------------------------------ |
| `amount`         | `uint128` | The total amount of incentive tokens to be distributed in the batch.                       |
| `timepoint`      | `uint48`  | The timepoint at which the incentive batch starts accruing rewards.                        |
| `stakeDuration`  | `uint128` | The duration of the lockup period required to be eligible for the incentive batch rewards. |
| `incentiveToken` | `IERC20`  | The address of the ERC20 token used for the incentive rewards.                             |

**Returns**

| Name    | Type      | Description                                     |
| ------- | --------- | ----------------------------------------------- |
| `index` | `uint256` | The index of the newly created incentive batch. |

#### claimFromIncentiveBatch <a href="#claimfromincentivebatch" id="claimfromincentivebatch"></a>

This function allows claiming rewards from a specific incentive batch, without extending any lockups.

```solidity
function claimFromIncentiveBatch(uint256 batchIndex) public returns (Lockup memory lockup, uint128 claimAmount);
```

**Parameters**

| Name         | Type      | Description                                                   |
| ------------ | --------- | ------------------------------------------------------------- |
| `batchIndex` | `uint256` | The index of the incentive batch from which to claim rewards. |

**Returns**

| Name          | Type      | Description                                                                                                                                |
| ------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `lockup`      | `Lockup`  | A Lockup struct containing details about the user's lockup that might have been affected by the claim (see struct definition for details). |
| `claimAmount` | `uint128` | The amount of tokens claimed from the incentive batch.                                                                                     |

#### claimFromIncentiveBatchAndExtend <a href="#claimfromincentivebatchandextend" id="claimfromincentivebatchandextend"></a>

This function allows claiming rewards from a specific incentive batch while simultaneously extending a lockup with the claimed tokens.

```solidity
function claimFromIncentiveBatchAndExtend(uint256 batchIndex, uint256 lockupId)
    public
    returns (Lockup memory lockup, uint128 claimAmount);
```

**Parameters**

| Name         | Type      | Description                                                   |
| ------------ | --------- | ------------------------------------------------------------- |
| `batchIndex` | `uint256` | The index of the incentive batch from which to claim rewards. |
| `lockupId`   | `uint256` | The ID of the lockup to be extended with the claimed tokens.  |

**Returns**

| Name          | Type      | Description                                                                                                      |
| ------------- | --------- | ---------------------------------------------------------------------------------------------------------------- |
| `lockup`      | `Lockup`  | A Lockup struct containing details about the updated lockup after extension (see struct definition for details). |
| `claimAmount` | `uint128` | The amount of tokens claimed from the incentive batch.                                                           |

#### incentiveTotals <a href="#incentivetotals" id="incentivetotals"></a>

This function retrieves the total incentive information for a specific ERC-20 token.

```solidity
function incentiveTotals(IERC20 incentiveToken) external view returns (TokenIncentiveTotals memory totals);
```

**Parameters**

| Name             | Type     | Description |
| ---------------- | -------- | ----------- |
| `incentiveToken` | `IERC20` |             |

**Returns**

| Name     | Type                   | Description                                                                                                        |
| -------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `totals` | `TokenIncentiveTotals` | A TokenIncentiveTotals struct containing details about the token's incentives (see struct definition for details). |

#### claimInformation <a href="#claiminformation" id="claiminformation"></a>

This function retrieves claim information for a specific account and incentive batch index.

```solidity
function claimInformation(address account, uint256 batchIndex) public view returns (ClaimInformation memory info);
```

**Parameters**

| Name         | Type      | Description                                                               |
| ------------ | --------- | ------------------------------------------------------------------------- |
| `account`    | `address` | The address of the account for which to retrieve claim information.       |
| `batchIndex` | `uint256` | The index of the incentive batch for which to retrieve claim information. |

**Returns**

| Name   | Type               | Description                                                                                                                          |
| ------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| `info` | `ClaimInformation` | A ClaimInformation struct containing details about the account's claims for the specified batch (see struct definition for details). |

#### \_claim <a href="#claim" id="claim"></a>

```solidity
function _claim(uint256 batchIndex)
    internal
    returns (uint128 claimAmount, uint256 stakeDuration, IERC20 incentiveToken);
```

### Structs <a href="#structs" id="structs"></a>

#### IncentiveSpecification <a href="#incentivespecification" id="incentivespecification"></a>

```solidity
struct IncentiveSpecification {
    uint128 totalIncentives;
    uint128 stakeDuration;
    uint48 claimTimepoint;
    IERC20 incentiveToken;
    mapping(address => bool) hasClaimed;
}
```

<br>
