# Community VCS

`CommunityVCS` is a staking strategy that manages many `CommunityVault` contracts by tracking the balance of each and moving tokens in and out of them.

## View Functions

### token

Returns the token this strategy supports

```solidity
function token() external view returns (address)
```

#### Return Values

| Name  | Type    | Description      |
| ----- | ------- | ---------------- |
| token | address | Address of token |

### canDeposit

Returns the available deposit room for this strategy

```solidity
function canDeposit() public view returns (uint256)
```

#### Return Values

| Name        | Type    | Description                  |
| ----------- | ------- | ---------------------------- |
| depositRoom | uint256 | Amount that can be deposited |

### canWithdraw

Returns the available withdrawal room for this strategy

```solidity
function canWithdraw() public view returns (uint256)
```

#### Return Values

| Name           | Type    | Description                  |
| -------------- | ------- | ---------------------------- |
| withdrawalRoom | uint256 | Amount that can be withdrawn |

### pendingFees

Returns the total amount of fees that will be paid on the next call to `updateDeposits`

```solidity
function pendingFees() external view returns (uint256)
```

#### Return Values

| Name      | Type    | Description                         |
| --------- | ------- | ----------------------------------- |
| totalFees | uint256 | Amount of tokens to be paid as fees |

### getTotalDeposits

Returns the total amount of deposits in this strategy

```solidity
function getTotalDeposits() public view returns (uint256)
```

#### Return Values

| Name          | Type    | Description                      |
| ------------- | ------- | -------------------------------- |
| totalDeposits | uint256 | Total amount of tokens deposited |

### getMaxDeposits

Returns the maximum amount of tokens this strategy can hold

*Accounts for total current deposits + current additional vault space + current space in the Chainlink*

```solidity
function getMaxDeposits() public view returns (uint256)
```

#### Return Values

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| maxDeposits | uint256 | Maximum token deposits |

### getMinDeposits

Returns the minimum amount of tokens that must remain in this strategy

```solidity
function getMinDeposits() public view returns (uint256)
```

#### Return Values

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| minDeposits | uint256 | Minimum token deposits |

### checkUpkeep

Returns whether a new batch of vaults should be deployed

```solidity
function checkUpkeep(bytes) external view returns (bool, bytes)
```

#### Return Values

| Name         | Type | Description                                      |
| ------------ | ---- | ------------------------------------------------ |
| upkeepNeeded | bool | Whether a new batch of vaults should be deployed |

### getDepositChange

Returns the deposit change since the last call to `updateDeposits` (ignores stakes/withdraws)

```solidity
function getDepositChange() public view returns (int256)
```

#### Return Values

| Name          | Type   | Description                    |
| ------------- | ------ | ------------------------------ |
| depositChange | int256 | Change in total token deposits |

### getVaults

Returns a list of all vaults controlled by this contract

```solidity
function getVaults() external view returns (address[] memory)
```

#### Return Values

| Name   | Type       | Description             |
| ------ | ---------- | ----------------------- |
| vaults | address\[] | List of vault addresses |

### getVaultDepositLimits

Returns the vault deposit limits

```solidity
function getVaultDepositLimits() public view returns (uint256, uint256)
```

#### Return Values

| Name        | Type    | Description                                      |
| ----------- | ------- | ------------------------------------------------ |
| minDeposits | uint256 | minimum amount of deposits that a vault can hold |
| maxDeposits | uint256 | maximum amount of deposits that a vault can hold |

### vaultImplementation

Returns the address of the vault implementation contract this strategy will use for new vaults

```solidity
function vaultImplementation() external view returns (address)
```

#### Return Values

| Name                | Type    | Description                              |
| ------------------- | ------- | ---------------------------------------- |
| vaultImplementation | address | Address of vault implementation contract |

### vaultDeploymentThreshold

Returns the minimum number of non-full vaults before a new batch is deployed

```solidity
function vaultDeploymentThreshold() external view returns (uint256)
```

#### Return Values

| Name                     | Type    | Description                |
| ------------------------ | ------- | -------------------------- |
| vaultDeploymentThreshold | uint256 | Vault deployment threshold |

### vaultDeploymentAmount

Returns the amount of vaults to deploy when threshold is met

```solidity
function vaultDeploymentAmount() external view returns (uint256)
```

#### Return Values

| Name                  | Type    | Description      |
| --------------------- | ------- | ---------------- |
| vaultDeploymentAmount | uint256 | number of vaults |

### getFees

Returns a list of all fees

```solidity
function getFees() external view returns (struct VaultControllerStrategy.Fee[])
```

#### Return Values

| Name | Type                                  | Description  |
| ---- | ------------------------------------- | ------------ |
| fees | struct VaultControllerStrategy.Fee\[] | List of fees |

### stakeController

Returns the address of the Chainlink staking contract

```solidity
function stakeController() external view returns (address)
```

#### Return Values

| Name            | Type    | Description                 |
| --------------- | ------- | --------------------------- |
| stakeController | address | address of staking contract |

## Write Functions

### deposit

Deposits tokens from the staking pool into vaults

```solidity
function deposit(uint256 _amount, bytes _data) external
```

#### Parameters

| Name     | Type    | Description                 |
| -------- | ------- | --------------------------- |
| \_amount | uint256 | Amount to deposit           |
| \_data   | bytes   | Encoded vault deposit order |

### withdraw

Withdraws tokens from vaults and sends them to the staking pool

```solidity
function withdraw(uint256 _amount, bytes _data) external
```

#### Parameters

| Name     | Type    | Description                    |
| -------- | ------- | ------------------------------ |
| \_amount | uint256 | Amount to withdraw             |
| \_data   | bytes   | Encoded vault withdrawal order |

### performUpkeep

Deploys a new batch of vaults

```solidity
function performUpkeep(bytes _performData) external
```

### addVaults

Deploys a new batch of vaults

```solidity
function addVaults(uint256 _numVaults) external
```

#### Parameters

| Name        | Type    | Description                |
| ----------- | ------- | -------------------------- |
| \_numVaults | uint256 | Number of vaults to deploy |

### updateDeposits

Updates the total deposit amount for reward distribution and calculates applicable fees

```solidity
function updateDeposits() external returns (address[] receivers, uint256[] amounts)
```

#### Return Values

| Name      | Type       | Description           |
| --------- | ---------- | --------------------- |
| receivers | address\[] | List of fee receivers |
| amounts   | uint256\[] | List of fee amounts   |

### updateVaultGroups

Executes a vault group update

*Re-unbonds all vaults in the current vault group and increments the current vault group*

```solidity
function updateVaultGroups(uint256[] _curGroupVaultsToUnbond, uint256 _curGroupTotalDepositRoom, uint256 _nextGroup,
uint256 _nextGroupTotalUnbonded) external
```

#### Parameters

| Name                       | Type       | Description                                                 |
| -------------------------- | ---------- | ----------------------------------------------------------- |
| \_curGroupVaultsToUnbond   | uint256\[] | list of vaults to unbond in current vault group             |
| \_curGroupTotalDepositRoom | uint256\[] | total deposit room across all vaults in current vault group |
| \_nextGroup                | uint256\[] | index of next vault group                                   |
| \_nextGroupTotalUnbonded   | uint256\[] | total unbonded across all vaults in next vault group        |

### upgradeVaults

Upgrades vaults to a new implementation contract

```solidity
function upgradeVaults(uint256 _startIndex, uint256 _numVaults, bytes _data) external
```

#### Parameters

| Name         | Type    | Description                                                 |
| ------------ | ------- | ----------------------------------------------------------- |
| \_startIndex | uint256 | Index of first vault to upgrade                             |
| \_numVaults  | uint256 | Number of vaults to upgrade starting at \_startIndex        |
| \_data       | bytes   | Optional encoded function call to be executed after upgrade |

### setWithdrawalIndexes

Manually sets the withdrawal index for each vault group

```solidity
function setWithdrawalIndexes(uint64 _withdrawalIndexes) external
```

#### Parameters

| Name                | Type      | Description                                     |
| ------------------- | --------- | ----------------------------------------------- |
| \_withdrawalIndexes | uint64\[] | list of withdrawal indexes for each vault group |

### addFee

Adds a new fee

```solidity
function addFee(address _receiver, uint256 _feeBasisPoints) external
```

#### Parameters

| Name             | Type    | Description             |
| ---------------- | ------- | ----------------------- |
| \_receiver       | address | Address of fee receiver |
| \_feeBasisPoints | uint256 | Fee in basis points     |

### updateFee

Updates an existing fee

```solidity
function updateFee(uint256 _index, address _receiver, uint256 _feeBasisPoints) external
```

#### Parameters

| Name             | Type    | Description             |
| ---------------- | ------- | ----------------------- |
| \_index          | uint256 | Index of fee            |
| \_receiver       | address | Address of fee receiver |
| \_feeBasisPoints | uint256 | Fee in basis points     |

### setVaultDeploymentParams

Sets the vault deployment parameters

```solidity
function setVaultDeploymentParams(uint256 _vaultDeploymentThreshold, uint256 _vaultDeploymentAmount) external
```

#### Parameters

| Name                       | Type    | Description                                                      |
| -------------------------- | ------- | ---------------------------------------------------------------- |
| \_vaultDeploymentThreshold | uint256 | Minimum number of non-full vaults before a new batch is deployed |
| \_vaultDeploymentAmount\_  | uint256 | Amount of vaults to deploy when threshold is met                 |

### setVaultImplementation

Sets a new vault implementation contract to be used when deploying/upgrading vaults

```solidity
function setVaultImplementation(address _vaultImplementation) external
```

#### Parameters

| Name                  | Type    | Description                        |
| --------------------- | ------- | ---------------------------------- |
| \_vaultImplementation | address | Address of implementation contract |

### setMaxDepositSizeBP

Sets the basis point amount of the remaing deposit room in the Chainlink staking contract\
that can be deposited at once

```solidity
function setMaxDepositSizeBP(uint256 _maxDeposits) external
```

#### Parameters

| Name               | Type    | Description                      |
| ------------------ | ------- | -------------------------------- |
| \_maxDepositSizeBP | uint256 | Maximum basis point deposit size |


---

# 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.stake.link/link-staking-contracts/communityvcs.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.
