# VPOOL

## VPool

All Vesper pools are implementations of VPOOL. This contract performs the core functions for all Vesper pools, including deposits, withdrawals, fee calculation

### VERSION

```solidity
string VERSION
```

### MAX\_BPS

```solidity
uint256 MAX_BPS
```

### ONE\_YEAR

```solidity
uint256 ONE_YEAR
```

### UpdatedMaximumProfitAsFee

```solidity
event UpdatedMaximumProfitAsFee(uint256 oldMaxProfitAsFee, uint256 newMaxProfitAsFee)
```

### UpdatedMinimumDepositLimit

```solidity
event UpdatedMinimumDepositLimit(uint256 oldDepositLimit, uint256 newDepositLimit)
```

### Deposit

```solidity
event Deposit(address owner, uint256 shares, uint256 amount)
```

### Withdraw

```solidity
event Withdraw(address owner, uint256 shares, uint256 amount)
```

### UpdatedUniversalFee

```solidity
event UpdatedUniversalFee(uint256 oldUniversalFee, uint256 newUniversalFee)
```

### UpdatedPoolRewards

```solidity
event UpdatedPoolRewards(address previousPoolRewards, address newPoolRewards)
```

### UpdatedWithdrawFee

```solidity
event UpdatedWithdrawFee(uint256 previousWithdrawFee, uint256 newWithdrawFee)
```

### UniversalFeePaid

```solidity
event UniversalFeePaid(uint256 strategyDebt, uint256 profit, uint256 fee)
```

### constructor

```solidity
constructor(string _name, string _symbol, address _token) public
```

### initialize

```solidity
function initialize(string _name, string _symbol, address _token, address _poolAccountant) public
```

*Equivalent to a constructor for the proxy. It can be called only once per proxy.*

### deposit

```solidity
function deposit(uint256 _amount) external
```

Deposit ERC20 tokens and receive pool shares depending on the current share price.

| Name     | Type    | Description         |
| -------- | ------- | ------------------- |
| \_amount | uint256 | ERC20 token amount. |

### depositAndClaim

```solidity
function depositAndClaim(uint256 _amount) external
```

Deposit ERC20 tokens and claim rewards, if there are any.

| Name     | Type    | Description         |
| -------- | ------- | ------------------- |
| \_amount | uint256 | ERC20 token amount. |

### depositWithPermit

```solidity
function depositWithPermit(uint256 _amount, uint256 _deadline, uint8 _v, bytes32 _r, bytes32 _s) external
```

Deposit ERC20 tokens with permit, aka gasless approval.

| Name       | Type    | Description                             |
| ---------- | ------- | --------------------------------------- |
| \_amount   | uint256 | ERC20 token amount.                     |
| \_deadline | uint256 | The time at which signature will expire |
| \_v        | uint8   | The recovery byte of the signature      |
| \_r        | bytes32 | Half of the ECDSA signature pair        |
| \_s        | bytes32 | Half of the ECDSA signature pair        |

### whitelistedWithdraw

```solidity
function whitelistedWithdraw(uint256 _shares) external
```

Withdraw collateral based on given shares and the current share price. Burn remaining shares and return collateral. Claim rewards if there are any

*Deprecated method. Keeping this method here for backward compatibility.*

| Name     | Type    | Description                             |
| -------- | ------- | --------------------------------------- |
| \_shares | uint256 | Pool shares. It will be in 18 decimals. |

### withdraw

```solidity
function withdraw(uint256 _shares) external
```

Withdraw collateral based on given shares and the current share price. Burn remaining shares and return collateral.

| Name     | Type    | Description                             |
| -------- | ------- | --------------------------------------- |
| \_shares | uint256 | Pool shares. It will be in 18 decimals. |

### withdrawAndClaim

```solidity
function withdrawAndClaim(uint256 _shares) external
```

Withdraw collateral and claim rewards, if any.

| Name     | Type    | Description                             |
| -------- | ------- | --------------------------------------- |
| \_shares | uint256 | Pool shares. It will be in 18 decimals. |

### multiTransfer

```solidity
function multiTransfer(address[] _recipients, uint256[] _amounts) external returns (bool)
```

Transfer tokens to multiple recipients

*Address array and amount array are 1:1 and are in order.*

| Name         | Type       | Description                  |
| ------------ | ---------- | ---------------------------- |
| \_recipients | address\[] | array of recipient addresses |
| \_amounts    | uint256\[] | array of token amounts       |

| Name | Type | Description |
| ---- | ---- | ----------- |
| \[0] | bool | true/false  |

### reportEarning

```solidity
function reportEarning(uint256 _profit, uint256 _loss, uint256 _payback) external
```

Strategy call this in regular interval. Only strategy function.

| Name      | Type    | Description                                                                                                                                                                                               |
| --------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_profit  | uint256 | yield generated by strategy. Strategy get performance fee on this amount                                                                                                                                  |
| \_loss    | uint256 | Reduce debt ,also reduce debtRatio, increase loss in record.                                                                                                                                              |
| \_payback | uint256 | strategy willing to payback outstanding above debtLimit. no performance fee on this amount. when governance has reduced debtRatio of strategy, strategy will report profit and payback amount separately. |

### reportLoss

```solidity
function reportLoss(uint256 _loss) external
```

Report loss outside of rebalance activity.

*Some strategies pay deposit fee thus realizing loss at deposit. For example: Curve's 3pool has some slippage due to deposit of one asset in 3pool. Strategy may want report this loss instead of waiting for next rebalance.*

| Name   | Type    | Description                       |
| ------ | ------- | --------------------------------- |
| \_loss | uint256 | Loss that strategy want to report |

### sweepERC20

```solidity
function sweepERC20(address _fromToken) external
```

*Transfer given ERC20 token to governor*

| Name        | Type    | Description            |
| ----------- | ------- | ---------------------- |
| \_fromToken | address | Token address to sweep |

### availableCreditLimit

```solidity
function availableCreditLimit(address _strategy) external view returns (uint256)
```

Get available credit limit of strategy. This is the amount strategy can borrow from pool

*Available credit limit is calculated based on current debt of pool and strategy, current debt limit of pool and strategy. credit available = min(pool's debt limit, strategy's debt limit, max debt per rebalance) when some strategy do not pay back outstanding debt, this impact credit line of other strategy if totalDebt of pool >= debtLimit of pool*

| Name       | Type    | Description      |
| ---------- | ------- | ---------------- |
| \_strategy | address | Strategy address |

### calculateUniversalFee

```solidity
function calculateUniversalFee(uint256 _profit) external view returns (uint256 _fee)
```

Calculate universal fee for calling strategy. This is only strategy function.

*Earn strategies will call this during rebalance.*

### excessDebt

```solidity
function excessDebt(address _strategy) external view returns (uint256)
```

Debt above current debt limit

| Name       | Type    | Description         |
| ---------- | ------- | ------------------- |
| \_strategy | address | Address of strategy |

### getStrategies

```solidity
function getStrategies() external view returns (address[])
```

### totalDebt

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

Get total debt of pool

### totalDebtOf

```solidity
function totalDebtOf(address _strategy) external view returns (uint256)
```

Get total debt of given strategy

| Name       | Type    | Description      |
| ---------- | ------- | ---------------- |
| \_strategy | address | Strategy address |

### totalDebtRatio

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

Get total debt ratio. Total debt ratio helps us keep buffer in pool

### calculateMintage

```solidity
function calculateMintage(uint256 _amount) public view returns (uint256 _shares)
```

Calculate how much shares user will get for given amount. Also return externalDepositFee if any.

*Amount should be >= minimum deposit limit which default to 1*

| Name     | Type    | Description       |
| -------- | ------- | ----------------- |
| \_amount | uint256 | Collateral amount |

| Name     | Type    | Description                        |
| -------- | ------- | ---------------------------------- |
| \_shares | uint256 | Amount of share that user will get |

### getWithdrawQueue

```solidity
function getWithdrawQueue() public view returns (address[])
```

### pricePerShare

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

Get price per share

*Return value will be in token defined decimals.*

### strategy

```solidity
function strategy(address _strategy) public view returns (bool _active, uint256 _interestFee, uint256 _debtRate, uint256 _lastRebalance, uint256 _totalDebt, uint256 _totalLoss, uint256 _totalProfit, uint256 _debtRatio, uint256 _externalDepositFee)
```

### tokensHere

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

*Returns the token stored in the pool. It will be in token defined decimals.*

### totalValue

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

Returns sum of token locked in other contracts and token stored in the pool. It will be in token defined decimals.

### \_beforeBurning

```solidity
function _beforeBurning(uint256 _share) private returns (uint256 _actualWithdrawn, bool _isPartial)
```

*Before burning hook. withdraw amount from strategies*

### \_calculateShares

```solidity
function _calculateShares(uint256 _amount) private view returns (uint256)
```

*Calculate shares to mint/burn based on the current share price and given amount.*

| Name     | Type    | Description                                             |
| -------- | ------- | ------------------------------------------------------- |
| \_amount | uint256 | Collateral amount in collateral token defined decimals. |

| Name | Type    | Description                |
| ---- | ------- | -------------------------- |
| \[0] | uint256 | share amount in 18 decimal |

### \_calculateUniversalFee

```solidity
function _calculateUniversalFee(address _strategy, uint256 _profit) private view returns (uint256 _fee)
```

*Calculate universal fee based on strategy's TVL, profit earned and duration between rebalance and now.*

### \_calculateUniversalFee

```solidity
function _calculateUniversalFee(uint256 _lastRebalance, uint256 _totalDebt, uint256 _profit) private view returns (uint256 _fee)
```

### migrateStrategy

```solidity
function migrateStrategy(address _old, address _new) external
```

Migrate existing strategy to new strategy.

*Migrating strategy aka old and new strategy should be of same type.*

| Name  | Type    | Description                        |
| ----- | ------- | ---------------------------------- |
| \_old | address | Address of strategy being migrated |
| \_new | address | Address of new strategy            |

### setup

```solidity
function setup() external
```

OnlyGovernor:: Helper function for V5 upgrade

### updateMaximumProfitAsFee

```solidity
function updateMaximumProfitAsFee(uint256 _newMaxProfitAsFee) external
```

Only Governor:: Update maximum profit that can be used as universal fee

| Name                | Type    | Description           |
| ------------------- | ------- | --------------------- |
| \_newMaxProfitAsFee | uint256 | New max profit as fee |

### updateMinimumDepositLimit

```solidity
function updateMinimumDepositLimit(uint256 _newLimit) external
```

Only Governor:: Update minimum deposit limit

| Name       | Type    | Description               |
| ---------- | ------- | ------------------------- |
| \_newLimit | uint256 | New minimum deposit limit |

### updateUniversalFee

```solidity
function updateUniversalFee(uint256 _newUniversalFee) external
```

Update universal fee for this pool

*Format: 1500 = 15% fee, 100 = 1%*

| Name              | Type    | Description       |
| ----------------- | ------- | ----------------- |
| \_newUniversalFee | uint256 | new universal fee |

### updatePoolRewards

```solidity
function updatePoolRewards(address _newPoolRewards) external
```

Update pool rewards address for this pool

| Name             | Type    | Description              |
| ---------------- | ------- | ------------------------ |
| \_newPoolRewards | address | new pool rewards address |

### pause

```solidity
function pause() external
```

### unpause

```solidity
function unpause() external
```

### shutdown

```solidity
function shutdown() external
```

### open

```solidity
function open() external
```

### keepers

```solidity
function keepers() external view returns (address[])
```

Return list of keepers

### isKeeper

```solidity
function isKeeper(address _address) external view returns (bool)
```

### addKeeper

```solidity
function addKeeper(address _keeperAddress) external
```

Add given address in keepers list.

| Name            | Type    | Description            |
| --------------- | ------- | ---------------------- |
| \_keeperAddress | address | keeper address to add. |

### removeKeeper

```solidity
function removeKeeper(address _keeperAddress) external
```

Remove given address from keepers list.

| Name            | Type    | Description               |
| --------------- | ------- | ------------------------- |
| \_keeperAddress | address | keeper address to remove. |

### maintainers

```solidity
function maintainers() external view returns (address[])
```

Return list of maintainers

### isMaintainer

```solidity
function isMaintainer(address _address) external view returns (bool)
```

### addMaintainer

```solidity
function addMaintainer(address _maintainerAddress) external
```

Add given address in maintainers list.

| Name                | Type    | Description                |
| ------------------- | ------- | -------------------------- |
| \_maintainerAddress | address | maintainer address to add. |

### removeMaintainer

```solidity
function removeMaintainer(address _maintainerAddress) external
```

Remove given address from maintainers list.

| Name                | Type    | Description                   |
| ------------------- | ------- | ----------------------------- |
| \_maintainerAddress | address | maintainer address to remove. |
