> ## Documentation Index
> Fetch the complete documentation index at: https://docs.story.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# EvenSplitGroupPool

The EvenSplitGroupPool is a contract that implements the IGroupRewardPool interface and manages the distribution of rewards among IP members within a group. It uses an even split mechanism to distribute rewards fairly among all members.

## State Variables

### ROYALTY\_MODULE

```solidity theme={null}
IRoyaltyModule public immutable ROYALTY_MODULE
```

The address of the protocol-wide Royalty Module.

### GROUPING\_MODULE

```solidity theme={null}
IGroupingModule public immutable GROUPING_MODULE
```

The address of the protocol-wide Grouping Module.

### GROUP\_IP\_ASSET\_REGISTRY

```solidity theme={null}
IGroupIPAssetRegistry public immutable GROUP_IP_ASSET_REGISTRY
```

The address of the protocol-wide Group IP Asset Registry.

### MAX\_GROUP\_SIZE

```solidity theme={null}
uint32 public constant MAX_GROUP_SIZE = 1_000
```

The maximum number of IP members allowed in a group.

### GroupInfo

```solidity theme={null}
struct GroupInfo {
    address token;
    uint32 totalMembers;
    uint128 pendingBalance;
    uint128 accRewardPerIp;
    uint256 averageRewardShare;
}
```

Storage structure for the GroupInfo:

* `token`: The reward token for the group, defined by the license terms attached to the group IP
* `totalMembers`: Total number of IPs in the group
* `pendingBalance`: Pending balance to be added to accRewardPerIp
* `accRewardPerIp`: Accumulated rewards per IP, times MAX\_GROUP\_SIZE
* `averageRewardShare`: The average reward share per IP, only increases as new IPs join with higher minimum share

## Functions

### initialize

```solidity theme={null}
function initialize(address accessManager) public initializer
```

Initializes the EvenSplitGroupPool contract.

**Parameters:**

* `accessManager`: The address of the protocol admin roles contract.

### addIp

```solidity theme={null}
function addIp(
    address groupId,
    address ipId,
    uint256 minimumGroupRewardShare
) external onlyGroupingModule returns (uint256 totalGroupRewardShare)
```

Adds an IP to the group pool. Only the GroupingModule can call this function.

**Parameters:**

* `groupId`: The group ID.
* `ipId`: The IP ID.
* `minimumGroupRewardShare`: The minimum group reward share the IP expects to be added to the group.

**Returns:**

* `totalGroupRewardShare`: The total group reward share after adding the IP.

### removeIp

```solidity theme={null}
function removeIp(address groupId, address ipId) external onlyGroupingModule
```

Removes an IP from the group pool. Only the GroupingModule can call this function.

**Parameters:**

* `groupId`: The group ID.
* `ipId`: The IP ID.

### depositReward

```solidity theme={null}
function depositReward(address groupId, address token, uint256 amount) external onlyGroupingModule
```

Deposits reward to the group pool directly.

**Parameters:**

* `groupId`: The group ID.
* `token`: The reward token.
* `amount`: The amount of reward.

### getAvailableReward

```solidity theme={null}
function getAvailableReward(
    address groupId,
    address token,
    address[] calldata ipIds
) external view returns (uint256[] memory)
```

Returns the reward for each IP in the group.

**Parameters:**

* `groupId`: The group ID.
* `token`: The reward token.
* `ipIds`: The IP IDs.

**Returns:**

* `uint256[] memory`: The rewards for each IP.

### distributeRewards

```solidity theme={null}
function distributeRewards(
    address groupId,
    address token,
    address[] calldata ipIds
) external whenNotPaused onlyGroupingModule returns (uint256[] memory rewards)
```

Distributes rewards to the given IP accounts in the pool.

**Parameters:**

* `groupId`: The group ID.
* `token`: The reward tokens.
* `ipIds`: The IP IDs.

**Returns:**

* `rewards`: An array containing the reward amounts distributed to each IP.

### getTotalIps

```solidity theme={null}
function getTotalIps(address groupId) external view returns (uint256)
```

Returns the total number of IPs in the group.

**Parameters:**

* `groupId`: The group ID.

**Returns:**

* `uint256`: The total number of IPs in the group.

### getIpAddedTime

```solidity theme={null}
function getIpAddedTime(address groupId, address ipId) external view returns (uint256)
```

Returns the timestamp when an IP was added to the group.

**Parameters:**

* `groupId`: The group ID.
* `ipId`: The IP ID.

**Returns:**

* `uint256`: The timestamp when the IP was added to the group.

### getIpRewardDebt

```solidity theme={null}
function getIpRewardDebt(address groupId, address token, address ipId) external view returns (uint256)
```

Returns the reward debt of an IP in the group.

**Parameters:**

* `groupId`: The group ID.
* `token`: The reward token.
* `ipId`: The IP ID.

**Returns:**

* `uint256`: The reward debt of the IP.

### isIPAdded

```solidity theme={null}
function isIPAdded(address groupId, address ipId) external view returns (bool)
```

Checks if an IP is added to the group.

**Parameters:**

* `groupId`: The group ID.
* `ipId`: The IP ID.

**Returns:**

* `bool`: True if the IP is added to the group, false otherwise.

### getMinimumRewardShare

```solidity theme={null}
function getMinimumRewardShare(address groupId, address ipId) external view returns (uint256)
```

Returns the minimum reward share of an IP in the group.

**Parameters:**

* `groupId`: The group ID.
* `ipId`: The IP ID.

**Returns:**

* `uint256`: The minimum reward share of the IP.

### getTotalAllocatedRewardShare

```solidity theme={null}
function getTotalAllocatedRewardShare(address groupId) external view returns (uint256)
```

Returns the total allocated reward share of the group.

**Parameters:**

* `groupId`: The group ID.

**Returns:**

* `uint256`: The total allocated reward share of the group.
