# Espresso Fund Flow Controller

`EspressoFundFlowController` manages deposits and withdrawals for Espresso staking vaults, including unbonding, restaking, and reward management. It coordinates with the strategy and withdrawal pool contracts and exposes functions for vault and reward state queries.

## View Functions

### strategy

Returns the address of the staking strategy contract.

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

#### Return Values

| Name     | Type    | Description              |
| -------- | ------- | ------------------------ |
| strategy | address | Staking strategy address |

### withdrawalPool

Returns the address of the withdrawal pool contract.

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

#### Return Values

| Name           | Type    | Description             |
| -------------- | ------- | ----------------------- |
| withdrawalPool | address | Withdrawal pool address |

### depositController

Returns the address authorized to deposit queued tokens into vaults.

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

#### Return Values

| Name              | Type    | Description                |
| ----------------- | ------- | -------------------------- |
| depositController | address | Deposit controller address |

### minTimeBetweenUnbonding

Returns the minimum number of seconds between unbonding calls.

```solidity
function minTimeBetweenUnbonding() public view returns (uint64)
```

#### Return Values

| Name                    | Type   | Description                       |
| ----------------------- | ------ | --------------------------------- |
| minTimeBetweenUnbonding | uint64 | Minimum seconds between unbonding |

### timeOfLastUnbond

Returns the time of the last unbonding call.

```solidity
function timeOfLastUnbond() public view returns (uint64)
```

#### Return Values

| Name             | Type   | Description            |
| ---------------- | ------ | ---------------------- |
| timeOfLastUnbond | uint64 | Time of last unbonding |

### shouldDepositQueuedTokens

Returns whether tokens should be deposited and the amount available for deposit.

```solidity
function shouldDepositQueuedTokens() external view returns (bool, uint256)
```

#### Return Values

| Name       | Type    | Description                           |
| ---------- | ------- | ------------------------------------- |
| canDeposit | bool    | true if deposit is allowed            |
| amount     | uint256 | Amount of tokens available to deposit |

### shouldUnbondVaults

Returns whether vaults should be unbonded.

```solidity
function shouldUnbondVaults() external view returns (bool)
```

#### Return Values

| Name         | Type | Description                 |
| ------------ | ---- | --------------------------- |
| shouldUnbond | bool | true if unbonding is needed |

### shouldWithdrawVaults

Returns whether vaults are unbonded and ready to be withdrawn from, and the list of withdrawable vaults.

```solidity
function shouldWithdrawVaults() external view returns (bool, uint256[] memory)
```

#### Return Values

| Name        | Type       | Description                    |
| ----------- | ---------- | ------------------------------ |
| canWithdraw | bool       | true if withdrawal is possible |
| vaultIds    | uint256\[] | List of withdrawable vault IDs |

### getVaultDeposits

Returns a list of total deposits for all vaults.

```solidity
function getVaultDeposits() external view returns (uint256[] memory)
```

#### Return Values

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

### getVaultRewards

Returns a list of unclaimed rewards for all vaults.

```solidity
function getVaultRewards() external view returns (uint256[] memory)
```

#### Return Values

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

### getUnbondingVaults

Returns a list of currently unbonding vaults.

```solidity
function getUnbondingVaults() external view returns (uint256[] memory)
```

#### Return Values

| Name     | Type       | Description              |
| -------- | ---------- | ------------------------ |
| vaultIds | uint256\[] | List of unbonding vaults |

### getWithdrawableVaults

Returns a list of currently withdrawable vaults.

```solidity
function getWithdrawableVaults() public view returns (uint256[] memory)
```

#### Return Values

| Name     | Type       | Description                 |
| -------- | ---------- | --------------------------- |
| vaultIds | uint256\[] | List of withdrawable vaults |

### getInactiveVaults

Returns a list of inactive vaults (validators that have exited).

```solidity
function getInactiveVaults() public view returns (uint256[] memory)
```

#### Return Values

| Name     | Type       | Description             |
| -------- | ---------- | ----------------------- |
| vaultIds | uint256\[] | List of inactive vaults |

### getInactiveWithdrawableVaults

Returns a list of inactive and currently withdrawable vaults.

```solidity
function getInactiveWithdrawableVaults() public view returns (uint256[] memory)
```

#### Return Values

| Name     | Type       | Description                          |
| -------- | ---------- | ------------------------------------ |
| vaultIds | uint256\[] | List of inactive withdrawable vaults |

## Write Functions

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

### unbondVaults

Unbonds vaults if needed.

```solidity
function unbondVaults() external
```

### forceUnbondVaults

Unbonds vaults to rebalance deposits between vaults.

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

#### Parameters

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

### withdrawVaults

Withdraws from vaults and triggers withdrawal pool upkeep if needed.

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

#### Parameters

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

### restakeRewards

Restakes vault rewards for given vaults.

```solidity
function restakeRewards(uint256[] calldata _vaultIds, uint256[] calldata _lifetimeRewards, bytes[] calldata _authData) external
```

#### Parameters

| Name              | Type       | Description                            |
| ----------------- | ---------- | -------------------------------------- |
| \_vaultIds        | uint256\[] | List of vault IDs                      |
| \_lifetimeRewards | uint256\[] | Lifetime rewards values for each vault |
| \_authData        | bytes\[]   | Authorization data for each vault      |

### withdrawRewards

Withdraws vault rewards for given vaults.

```solidity
function withdrawRewards(uint256[] calldata _vaultIds, uint256[] calldata _lifetimeRewards, bytes[] calldata _authData) external
```

#### Parameters

| Name              | Type       | Description                            |
| ----------------- | ---------- | -------------------------------------- |
| \_vaultIds        | uint256\[] | List of vault IDs                      |
| \_lifetimeRewards | uint256\[] | Lifetime rewards values for each vault |
| \_authData        | bytes\[]   | Authorization data for each vault      |

### setDepositController

Sets the address authorized to deposit queued tokens.

```solidity
function setDepositController(address _depositController) external
```

#### Parameters

| Name                | Type    | Description                |
| ------------------- | ------- | -------------------------- |
| \_depositController | address | Deposit controller address |

### setMinTimeBetweenUnbonding

Sets the minimum time between unbonding calls.

```solidity
function setMinTimeBetweenUnbonding(uint64 _minTimeBetweenUnbonding) external
```

#### Parameters

| Name                      | Type   | Description                       |
| ------------------------- | ------ | --------------------------------- |
| \_minTimeBetweenUnbonding | uint64 | Minimum seconds between unbonding |
