# Polygon Strategy

`PolygonStrategy` is a staking strategy that manages multiple `PolygonVault` contracts by tracking the balance of each and moving tokens in and out of them.

## View Functions

### token

Returns the address of the staking token (POL).

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

#### Return Values

| Name  | Type    | Description       |
| ----- | ------- | ----------------- |
| token | address | POL token address |

### stakingPool

Returns the address of the staking pool that controls this strategy.

```solidity
function stakingPool() public view returns (address)
```

#### Return Values

| Name        | Type    | Description          |
| ----------- | ------- | -------------------- |
| stakingPool | address | Staking pool address |

### stakeManager

Returns the address of the Polygon stake manager contract.

```solidity
function stakeManager() public view returns (address)
```

#### Return Values

| Name         | Type    | Description           |
| ------------ | ------- | --------------------- |
| stakeManager | address | Stake manager address |

### fundFlowController

Returns the address of the fund flow controller contract.

```solidity
function fundFlowController() public view returns (address)
```

#### Return Values

| Name               | Type    | Description                  |
| ------------------ | ------- | ---------------------------- |
| fundFlowController | address | Fund flow controller address |

### validatorMEVRewardsPool

Returns the address of the MEV rewards pool contract.

```solidity
function validatorMEVRewardsPool() public view returns (address)
```

#### Return Values

| Name                    | Type    | Description              |
| ----------------------- | ------- | ------------------------ |
| validatorMEVRewardsPool | address | MEV rewards pool address |

### validatorMEVRewardsPercentage

Returns the percentage of MEV rewards validators will receive (basis points).

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

#### Return Values

| Name                          | Type    | Description             |
| ----------------------------- | ------- | ----------------------- |
| validatorMEVRewardsPercentage | uint256 | Validator MEV rewards % |

### vaultImplementation

Returns the address of the vault implementation contract.

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

#### Return Values

| Name                | Type    | Description                  |
| ------------------- | ------- | ---------------------------- |
| vaultImplementation | address | Vault implementation address |

### validatorRemoval

Returns the current validator removal state.

```solidity
function validatorRemoval() public view returns (bool isActive, uint64 validatorId, uint128 queuedWithdrawals)
```

#### Return Values

| Name              | Type    | Description          |
| ----------------- | ------- | -------------------- |
| isActive          | bool    | If removal is active |
| validatorId       | uint64  | Validator ID         |
| queuedWithdrawals | uint128 | Queued withdrawals   |

### totalQueued

Returns the total number of tokens queued for deposit into vaults.

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

#### Return Values

| Name        | Type    | Description         |
| ----------- | ------- | ------------------- |
| totalQueued | uint256 | Total queued tokens |

### numVaultsUnbonding

Returns the total number of vaults currently unbonding.

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

#### Return Values

| Name               | Type    | Description                |
| ------------------ | ------- | -------------------------- |
| numVaultsUnbonding | uint256 | Number of vaults unbonding |

### validatorWithdrawalIndex

Returns the index of validator to withdraw from on next withdrawal.

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

#### Return Values

| Name                     | Type    | Description                |
| ------------------------ | ------- | -------------------------- |
| validatorWithdrawalIndex | uint256 | Validator withdrawal index |

### canDeposit

Returns the available deposit room for this strategy.

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

#### Return Values

| Name       | Type    | Description            |
| ---------- | ------- | ---------------------- |
| canDeposit | uint256 | Available deposit room |

### canWithdraw

Returns the available withdrawal room for this strategy.

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

#### Return Values

| Name        | Type    | Description               |
| ----------- | ------- | ------------------------- |
| canWithdraw | uint256 | Available withdrawal room |

### 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 deposits |

### getMaxDeposits

Returns the maximum that can be deposited into this strategy.

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

#### Return Values

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

### getMinDeposits

Returns the minimum that must remain in this strategy.

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

#### Return Values

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

### getValidators

Returns a list of all validators.

```solidity
function getValidators() external view returns (Validator[] memory)
```

#### Return Values

| Name       | Type         | Description        |
| ---------- | ------------ | ------------------ |
| validators | Validator\[] | List of validators |

### getVaults

Returns a list of all vaults controlled by this contract.

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

#### Return Values

| Name   | Type             | Description    |
| ------ | ---------------- | -------------- |
| vaults | IPolygonVault\[] | List of vaults |

### getDepositChange

Returns the deposit change since deposits were last updated.

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

#### Return Values

| Name          | Type | Description              |
| ------------- | ---- | ------------------------ |
| depositChange | int  | Change in total deposits |

### getFees

Returns a list of all fees and fee receivers.

```solidity
function getFees() external view returns (Fee[] memory)
```

#### Return Values

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

### staked

Returns whether an account should receive validator rewards (used by the validator MEV rewards pool).

```solidity
function staked(address _account) public view returns (uint256)
```

#### Parameters

| Name      | Type    | Description     |
| --------- | ------- | --------------- |
| \_account | address | Account address |

#### Return Values

| Name   | Type    | Description                |
| ------ | ------- | -------------------------- |
| staked | uint256 | 1 if eligible, 0 otherwise |

### totalStaked

Returns the total number of active validators (used by the validator MEV rewards pool).

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

#### Return Values

| Name        | Type    | Description          |
| ----------- | ------- | -------------------- |
| totalStaked | uint256 | Number of validators |

## Write Functions

### deposit

Deposits tokens from the staking pool into this strategy.

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

#### Parameters

| Name     | Type    | Description       |
| -------- | ------- | ----------------- |
| \_amount | uint256 | Amount to deposit |

### withdraw

Withdraws tokens from this strategy and sends them to staking pool.

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

#### Parameters

| Name     | Type    | Description        |
| -------- | ------- | ------------------ |
| \_amount | uint256 | Amount to withdraw |

### depositQueuedTokens

Deposits queued tokens into vaults.

```solidity
function depositQueuedTokens(uint256[] calldata _vaultIds, uint256[] calldata _amounts) external
```

#### Parameters

| Name       | Type       | Description                  |
| ---------- | ---------- | ---------------------------- |
| \_vaultIds | uint256\[] | List of vault IDs            |
| \_amounts  | uint256\[] | Amounts to deposit per vault |

### unbond

Unbonds token deposits in vaults.

```solidity
function unbond(uint256 _toUnbond) external
```

#### Parameters

| Name       | Type    | Description      |
| ---------- | ------- | ---------------- |
| \_toUnbond | uint256 | Amount to unbond |

### forceUnbond

Unbonds token deposits in vaults (used to rebalance between vaults).

```solidity
function forceUnbond(uint256[] calldata _vaultIds, uint256[] calldata _amounts) external
```

#### Parameters

| Name       | Type       | Description                 |
| ---------- | ---------- | --------------------------- |
| \_vaultIds | uint256\[] | List of vault IDs           |
| \_amounts  | uint256\[] | Amounts to unbond per vault |

### unstakeClaim

Claims and withdraws tokens from vaults that are unbonded.

```solidity
function unstakeClaim(uint256[] calldata _vaultIds) external
```

#### Parameters

| Name       | Type       | Description       |
| ---------- | ---------- | ----------------- |
| \_vaultIds | uint256\[] | List of vault IDs |

### updateDeposits

Updates deposit accounting and calculates fees on newly earned rewards.

```solidity
function updateDeposits(bytes calldata) external returns (int256 depositChange, address[] memory receivers, uint256[] memory amounts)
```

#### Return Values

| Name          | Type       | Description                          |
| ------------- | ---------- | ------------------------------------ |
| depositChange | int256     | Change in deposits since last update |
| receivers     | address\[] | List of fee receivers                |
| amounts       | uint256\[] | List of fee amounts                  |

### restakeRewards

Restakes rewards in the polygon staking contract for given vaults.

```solidity
function restakeRewards(uint256[] calldata _vaultIds) external
```

#### Parameters

| Name       | Type       | Description       |
| ---------- | ---------- | ----------------- |
| \_vaultIds | uint256\[] | List of vault IDs |

### addValidator

Adds a new validator.

```solidity
function addValidator(address _pool, address _rewardsReceiver) external
```

#### Parameters

| Name              | Type    | Description                    |
| ----------------- | ------- | ------------------------------ |
| \_pool            | address | Validator shares pool address  |
| \_rewardsReceiver | address | Validator MEV rewards receiver |

### queueValidatorRemoval

Queues a validator for removal.

```solidity
function queueValidatorRemoval(uint256 _validatorId) external
```

#### Parameters

| Name          | Type    | Description  |
| ------------- | ------- | ------------ |
| \_validatorId | uint256 | Validator ID |

### finalizeValidatorRemoval

Finalizes a queued validator removal.

```solidity
function finalizeValidatorRemoval() external
```

### upgradeVaults

Upgrades vaults to a new implementation contract.

```solidity
function upgradeVaults(address[] calldata _vaults, bytes[] memory _data) external
```

#### Parameters

| Name     | Type       | Description                      |
| -------- | ---------- | -------------------------------- |
| \_vaults | address\[] | List of vault addresses          |
| \_data   | bytes\[]   | Encoded function calls per vault |

### addFee

Adds a new fee.

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

#### Parameters

| Name             | Type    | Description          |
| ---------------- | ------- | -------------------- |
| \_receiver       | address | Fee receiver address |
| \_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 | Fee index            |
| \_receiver       | address | Fee receiver address |
| \_feeBasisPoints | uint256 | Fee in basis points  |

### setValidatorMEVRewardsPool

Sets the validator MEV rewards pool.

```solidity
function setValidatorMEVRewardsPool(address _validatorMEVRewardsPool) external
```

#### Parameters

| Name                      | Type    | Description              |
| ------------------------- | ------- | ------------------------ |
| \_validatorMEVRewardsPool | address | MEV rewards pool address |

### setValidatorMEVRewardsPercentage

Sets the percentage of MEV rewards that validators receive.

```solidity
function setValidatorMEVRewardsPercentage(uint256 _validatorMEVRewardsPercentage) external
```

#### Parameters

| Name                            | Type    | Description             |
| ------------------------------- | ------- | ----------------------- |
| \_validatorMEVRewardsPercentage | uint256 | Validator MEV rewards % |

### 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 | Vault implementation address |

### setFundFlowController

Sets the fund flow controller.

```solidity
function setFundFlowController(address _fundFlowController) external
```

#### Parameters

| Name                 | Type    | Description                  |
| -------------------- | ------- | ---------------------------- |
| \_fundFlowController | address | Fund flow controller address |
