# AlphaProVault

### deposit

```solidity
function deposit(
        uint256 amount0Desired,
        uint256 amount1Desired,
        uint256 amount0Min,
        uint256 amount1Min,
        address to
)
        external
        override
        nonReentrant
        returns (uint256 shares, uint256 amount0, uint256 amount1)
```

Deposit tokens in proportion to the vault's current holdings. These tokens will remain in the vault, and are not used for liquidity until the next rebalance.

#### Parameters:

<table><thead><tr><th width="234.33333333333326">Varible</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amount0Desired</code></td><td>uint256</td><td>The maximum amount of token0 to deposit.</td></tr><tr><td><code>amount1Desired</code></td><td>uint256</td><td>The maximum amount of token1 to deposit.</td></tr><tr><td><code>amount0Min</code></td><td>uint256</td><td>Transaction will revert if the amount of token0 deposited is less than this.</td></tr><tr><td><code>amount1Min</code></td><td>uint256</td><td>Transaction will revert if the amount of token1 deposited is less than this.</td></tr><tr><td><code>to</code></td><td>address</td><td>The recipient of vault shares minted by  the vault.</td></tr></tbody></table>

#### Returns:

<table><thead><tr><th width="130.33333333333326">Varible</th><th width="178">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>shares</code></td><td>uint256</td><td>The number of vault shares minted by the vault.</td></tr><tr><td><code>amount0</code></td><td>uint256</td><td>The amount of token0 deposited into the vault.</td></tr><tr><td><code>amount1</code></td><td>uint256</td><td>The amount of token1 deposited into the vault.</td></tr></tbody></table>

### withdraw

```solidity
function withdraw(
    uint256 shares,
    uint256 amount0Min,
    uint256 amount1Min,
    address to
) 
    external
    override
    nonReentrant
    returns (uint256 amount0, uint256 amount1)
```

Withdraws tokens in proportion to the vault's current holdings and the fees earned by the vault.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Varible</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>shares</td><td>uint256</td><td>The amount of shares to be burned.</td></tr><tr><td>amount0Min</td><td>uint256</td><td>Transaction will revert if the amount of token0 received by the withdrawer is smaller than this.</td></tr><tr><td>amount1Min</td><td>uint256</td><td>Transaction will revert if the amount of token1 received by the withdrawer is smaller than this.</td></tr><tr><td><code>to</code></td><td>address</td><td>The recipient of the tokens withdrawn.</td></tr></tbody></table>

#### Returns:

<table><thead><tr><th width="130.33333333333326">Varible</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>amount0</code></td><td>uint256</td><td>The amount of token0 sent to the recipient.</td></tr><tr><td><code>amount1</code></td><td>uint256</td><td>The amount of token1 sent to the recipient.</td></tr></tbody></table>

### rebalance

```solidity
function rebalance() external override nonReentrant
```

Updates the vault's positions. Anyone can call rebalance, unless the vault manager calls [`setRebalanceDelegate`](#setrebalancedelegate) to nominate a specific wallet to rebalance.

### checkCanRebalance

```solidity
function checkCanRebalance() public view override
```

Check whether the vault can rebalance. Revert with an [error code ](https://learn.charm.fi/charm/technical-references/error-codes)if it cannot.

### getTwap

```solidity
function getTwap() public view returns (int24)
```

Fetches the time-weighted average price in ticks from Uniswap pool.

#### Returns:

<table><thead><tr><th width="130.33333333333326">Varible</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>int24</td><td>the time-weighted average price in ticks.</td></tr></tbody></table>

### getTotalAmounts

```solidity
function getTotalAmounts() 
    public 
    view override 
    returns (uint256 total0, uint256 total1)
```

Calculates the vault's total holdings of token0 and token1 - ie how much of each token the vault would hold if it withdrew all its liquidity from Uniswap. Includes owed fees but excludes the proportion of fees that will be paid to the protocol and vault manager.

#### Returns:

<table><thead><tr><th width="116.33333333333326">Varible</th><th width="141">Type</th><th>Description</th></tr></thead><tbody><tr><td>total0</td><td>uint256</td><td>The total amount of total0 held by the vault.</td></tr><tr><td>total1</td><td>uint256</td><td>The total amount of total1 held by the vault.</td></tr></tbody></table>

### getBalance0

```solidity
function getBalance0() public view override returns (uint256)
```

The amount of unused token0 held by the vault.

#### Returns:

<table><thead><tr><th width="109.33333333333326">Varible</th><th width="123">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>uint256</td><td>The balance of token0 in the vault not used in any position. All of this balance minus the protocol and manager fees will be deposited into Uniswap when <a href="#rebalance"><code>rebalance</code></a> is called.</td></tr></tbody></table>

### getBalance1

```solidity
function getBalance1() public view override returns (uint256)
```

The amount of unused token1 held by the vault.

#### Returns:

<table><thead><tr><th width="106.33333333333326">Varible</th><th width="123">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>uint256</td><td>The balance of token1 in the vault not used in any position. All of this balance minus the protocol and manager fees will be deposited into Uniswap when <a href="#rebalance">rebalance</a> is called.</td></tr></tbody></table>

### collectProtocol

```solidity
collectProtocol(address to) external
```

Collects all the uncollected protocol fees accrued by the vault. Can only be called by Charm Governance.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Varible</th><th width="203">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>to</code></td><td>address</td><td>The protocol fees' recipient.</td></tr></tbody></table>

### collectManager

```solidity
collectManager(address to) external onlyManager
```

Collects all the uncollected manager fees accrued by the vault. Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Varible</th><th width="203">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>to</code></td><td>address</td><td>The manager fees' recipient.</td></tr></tbody></table>

### sweep

```solidity
function sweep(
    IERC20Upgradeable token
    uint256 amount
    address to
) 
    external onlyManager 
```

Removes tokens accidentally sent to this vault. Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Varible</th><th width="203">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>token</code></td><td>IERC20Upgradeable</td><td>The ERC-20 token to be removed from the vault. Revert if <code>token</code> is <a href="#pool-variables"><code>token0</code></a> or <a href="#pool-variables"><code>token1</code></a>.</td></tr><tr><td><code>amount</code></td><td>uint256</td><td>amount of tokens to sweep.</td></tr><tr><td><code>to</code></td><td>address</td><td>The recipient of the token swept.</td></tr></tbody></table>

### setBaseThreshold

```solidity
function setBaseThreshold(int24 _baseThreshold) external onlyManager
```

Setting the [`baseThreshold`.](#setbasethreshold) Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Varible</th><th width="143">Type</th><th>Description</th></tr></thead><tbody><tr><td>_baseThreshold</td><td>int24</td><td>The width of the <a href="../../../manage-liquidity/user-guides/vault-parameters#base-order-width-basethreshold">base-order</a> in ticks.</td></tr></tbody></table>

### setLimitThreshold

```solidity
function setLimitThreshold(int24 _baseThreshold) external onlyManager
```

Setting the [`limitThreshold`](#setlimitthreshold). Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="183.33333333333326">Varible</th><th width="127">Type</th><th>Description</th></tr></thead><tbody><tr><td>_limitThreshold</td><td>int24</td><td>The width of the <a href="../../../manage-liquidity/user-guides/vault-parameters#limit-order-width-limitthreshold">limit-order</a> in ticks.</td></tr></tbody></table>

### setFullRangeWeight

```solidity
function setFullRangeWeight(uint256 _fullRangeWeight) external onlyManager
```

Setting the  [`fullRangeWeight` ](#setfullrangeweight). Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Varible</th><th width="114">Type</th><th>Description</th></tr></thead><tbody><tr><td>_fullRangeWeight</td><td>uint256</td><td>The maximum % of total liquidity deposited into a <a href="../../../manage-liquidity/user-guides/vault-parameters#full-range-weight-fullrangeweight">Full-Range Position</a>, with 1 unit of <code>_fullRangeWeight</code> = 1e-4 % full-range liquidity.</td></tr></tbody></table>

### setPeriod

```solidity
function setPeriod(uint256 _period) external onlyManager
```

Setting the rebalancing [`period`](#setperiod). Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="150.33333333333326">Varible</th><th width="113">Type</th><th>Description</th></tr></thead><tbody><tr><td>_period</td><td>uint256</td><td>Rebalance will revert if the time interval (in seconds) between rebalances is less than _period.</td></tr></tbody></table>

### setMinTickMove

```solidity
function setMinTickMove(int24 _minTickMove) external onlyManager
```

Setting the [minimum tick movement](https://learn.charm.fi/charm/manage-liquidity/user-guides/vault-parameters#minimum-tick-movement-mintickmove) between rebalance. Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Varible</th><th width="103">Type</th><th>Description</th></tr></thead><tbody><tr><td>_minTickMove</td><td>int24</td><td>Rebalance will revert if the price difference since the last rebalance is less than the _minTickMove.</td></tr></tbody></table>

### setTwapDuration

```solidity
function setTwapDuration(uint32 _twapDuration) external onlyManager
```

Setting the Security Parameter to [calculate the TWAP](https://learn.charm.fi/charm/manage-liquidity/user-guides/vault-parameters#twap-duration-twapduration). Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Variable</th><th width="119">Type</th><th>Description</th></tr></thead><tbody><tr><td>_twapDuration</td><td>uint32</td><td>The time period in seconds over which the TWAP is calculated. </td></tr></tbody></table>

### setMaxTwapDeviation

```solidity
function setMaxTwapDeviation(int24 _maxTwapDeviation) external onlyManagersol
```

Setting the Security Parameter that determines the maximum [TWAP deviation](https://learn.charm.fi/charm/manage-liquidity/user-guides/vault-parameters#twap-deviation-maxtwapdeviation). Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="220.33333333333326">Variable</th><th width="119">Type</th><th>Description</th></tr></thead><tbody><tr><td>_maxTwapDeviation</td><td>int24</td><td>Rebalance will revert if the spot price deviates from the TWAP by at least this amount.</td></tr></tbody></table>

### setMaxTotalSupply

```solidity
function setMaxTotalSupply(uint256 _maxTotalSupply) external onlyManager
```

Setting the Information Parameter that determines a vault's [maximum capacity](https://learn.charm.fi/charm/manage-liquidity/user-guides/vault-parameters#max-capacity-maxtotalsupply). Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="187.33333333333326">Variable</th><th width="119">Type</th><th>Description</th></tr></thead><tbody><tr><td>_maxTotalSupply</td><td>uint256</td><td>The maximum shares the vault can mint. <code>Deposit</code> will revert if the total amount of vault shares after a deposit is more than the<code>_maxTotalSupply.</code></td></tr></tbody></table>

### emergencyBurn

```solidity
function emergencyBurn(
    int24 tickLower,
    int24 tickUpper,
    uint128 liquidity
) 
    external onlyManager 
```

[Removes the vault's liquidity](https://learn.charm.fi/charm/manage-liquidity/user-guides/other-features#emergency-burn) in a given range. Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="177.33333333333326">Variable</th><th width="119">Type</th><th>Description</th></tr></thead><tbody><tr><td>tickLower</td><td>int24</td><td>The lower limit of the range to remove liquidity. </td></tr><tr><td>tickUpper</td><td>int24</td><td>The upper limit of the range to remove liquidity. </td></tr><tr><td>liquidity</td><td>uint128</td><td>The amount of liquidity to remove.</td></tr></tbody></table>

### setManager

```solidity
function setManager(address _manager) external onlyManager
```

The first step to [change](https://learn.charm.fi/charm/manage-liquidity/user-guides/other-features#changing-the-vault-manager) a vault's manager. Can only called by the vault manager.

#### Parameters:

<table><thead><tr><th width="173.33333333333326">Variable</th><th width="123">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>_manager</code></td><td>address</td><td>The address of the new vault manager. The changes will not take effect until the new address calls <a href="#acceptmanager"><code>acceptManager</code></a>.</td></tr></tbody></table>

### acceptManager

```solidity
function acceptManager() external
```

The second step to [change](https://learn.charm.fi/charm/manage-liquidity/user-guides/other-features#changing-the-vault-manager) a vault manager. Can only be called by the address assigned to [\_manager](#setmanager).

#### State Changes:

<table data-full-width="false"><thead><tr><th width="188">Variable</th><th width="176">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>manager</code></td><td>address</td><td>Setting the value of <code>manager</code> as the address of the new vault manager.</td></tr></tbody></table>

### setManagerFee

```solidity
function setManagerFee(uint256 _pendingManagerFee) external onlyManager 
```

Setting a [fee](https://learn.charm.fi/charm/manage-liquidity/user-guides/other-features#setting-a-vault-manager-fee) for the vault manager, as a % of fees received from Uniswap. Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="240.33333333333331">Variable</th><th width="94">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>_pendingManagerFee</code></td><td>uint256</td><td><p>The amount of manager fees as a % of fees earned by the vault, with 1 unit of fees = 1e-4 % of fees earned. </p><p></p><p>The maximum manager fee is 20000 units (20%).<br><br>The fee will take effect from the next rebalance.</p></td></tr></tbody></table>

### setRebalanceDelegate

```solidity
function setRebalanceDelegate(address _rebalanceDelegate) external onlyManager
```

Switch on/off [private rebalancing](https://learn.charm.fi/charm/manage-liquidity/user-guides/other-features#private-rebalancing). Can only be called by the vault manager.

#### Parameters:

<table><thead><tr><th width="235.33333333333331">Variable</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>_rebalanceDelegate</code></td><td>address</td><td>Setting an address other than the Zero Address will switch on private rebalancing, which means only <code>rebalanceDelegate</code> and the vault manager's address can call rebalance.</td></tr></tbody></table>

### **Getter functions for public variables**

Getter functions are automatically generated for the following public variables:

#### Pool Variables

<table><thead><tr><th width="195">Variable</th><th width="217">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>pool</code></td><td>IUniswapV3Pool</td><td>The pool for which the vault is managing the liquidity.</td></tr><tr><td><code>token0</code></td><td>IERC20Upgradeable</td><td>The first ERC-20 token within the <code>pool.</code></td></tr><tr><td><code>token1</code></td><td>IERC20Upgradeable</td><td>The second ERC-20 token within the <code>pool.</code></td></tr><tr><td><code>tickSpacing</code></td><td>int24</td><td>The distance between initializable ticks within the <code>pool</code></td></tr></tbody></table>

#### Vault Variables

<table><thead><tr><th width="219">Variable</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>string</td><td>The name of the vault shares representing the vault</td></tr><tr><td><code>symbol</code></td><td>string</td><td>The symbol of the vault shares representing the vault</td></tr><tr><td><code>maxTotalSupply</code></td><td>uint256</td><td>The maximum vault shares that can be mined by the vault.</td></tr><tr><td>MINIMUM_LIQUIDITY</td><td>uint256</td><td>The minimum vault shares minted by the vault.</td></tr></tbody></table>

#### Protocol Variables

<table><thead><tr><th>Variable</th><th width="216">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>factory</code></td><td>AlphaProVaultFactory</td><td>The Alpha Vaults factory contract used to create liquidity vaults</td></tr><tr><td><code>protocolFee</code></td><td>uint256</td><td>The protocol fee applied to this vault.</td></tr><tr><td><code>accruedProtocolFees0</code></td><td>uint256</td><td>Total amount of uncollected protocol fees within the vault.</td></tr><tr><td><code>accruedProtocolFees1</code></td><td>uint256</td><td>Total amount of uncollected protocol fees within the vault.</td></tr></tbody></table>

#### Strategy Variables

<table><thead><tr><th width="230">Variable</th><th width="130">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>fullRangeWeight</code></td><td>uint256</td><td>The maximum % of full range liquidity held by the vault, with 1 unit of <code>fullRangeWeight</code> = 1e-4 % full-range liquidity.</td></tr><tr><td><code>baseThreshold</code></td><td>int24</td><td>The width of the <a href="../../../manage-liquidity/user-guides/vault-parameters#base-order-width-basethreshold">base-order</a> in ticks.</td></tr><tr><td><code>limitThreshold</code></td><td>int24</td><td>The width of the <a href="../../../manage-liquidity/user-guides/vault-parameters#limit-order-width-limitthreshold">limit-order</a> in ticks.</td></tr><tr><td><code>period</code></td><td>uint256</td><td>Rebalance will revert if the time interval (in seconds) between rebalances is less than period.</td></tr><tr><td><code>lastTimestamp</code></td><td>uint256</td><td>The time stamp of the last rebalance.</td></tr><tr><td><code>lastTick</code></td><td>int24</td><td>The market price of the tokens within the pool at the latest rebalance.</td></tr><tr><td><code>fullLower</code></td><td>int24</td><td>The lower limit of a full range position.</td></tr><tr><td><code>fullUpper</code></td><td>int24</td><td>The upper limit of a full range position.</td></tr><tr><td><code>baseLower</code></td><td>int24</td><td>The lower limit of the <a href="../../../manage-liquidity/user-guides/vault-parameters#base-order-width-basethreshold">base-order</a> selected by the vault at rebalance.</td></tr><tr><td><code>baseUpper</code></td><td>int24</td><td>The upper limit of the <a href="../../../manage-liquidity/user-guides/vault-parameters#base-order-width-basethreshold">base-order</a> selected by the vault at rebalance.</td></tr><tr><td><code>limitLower</code></td><td>int24</td><td>The lower limit of the <a href="../../../manage-liquidity/user-guides/vault-parameters#limit-order-width-limitthreshold">limit-order</a> selected by the vault at rebalance.</td></tr><tr><td><code>limitUpper</code></td><td>int24</td><td>The upper limit of the <a href="../../../manage-liquidity/user-guides/vault-parameters#limit-order-width-limitthreshold">limit-order</a> selected by the vault at rebalance.</td></tr></tbody></table>

#### Security Variables

<table><thead><tr><th width="243"></th><th width="110"></th><th></th></tr></thead><tbody><tr><td><code>maxTwapDeviation</code></td><td>int24</td><td>Rebalance will revert if the spot price deviates from the TWAP by this amount.</td></tr><tr><td><code>twapDuration</code></td><td>uint32</td><td>The time period in seconds over which the TWAP is calculated. </td></tr></tbody></table>

#### Gas Optimization Variables

<table><thead><tr><th width="190"></th><th width="122"></th><th></th></tr></thead><tbody><tr><td><code>minTickMove</code></td><td>int24</td><td>Rebalance will revert if the price movements since the last rebalance is less than the _minTickMove.</td></tr></tbody></table>

#### Vault Manager Variables

<table><thead><tr><th width="259.3333333333333">Variable</th><th width="134">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>manager</code></td><td>address</td><td>The address of the vault manager.</td></tr><tr><td><code>pendingManager</code></td><td>address</td><td>The provisional address of the vault manager. Not finalised until <a href="#acceptmanager"><code>acceptManager</code></a> is called.</td></tr><tr><td><code>rebalanceDelegate</code></td><td>address</td><td>If<code>rebalanceDelegate</code> is the Zero Address, anyone can call rebalance.<br><br>Otherwise, only <code>rebalanceDelegate</code> and the vault manager's address can call rebalance.</td></tr><tr><td><code>managerFee</code></td><td>uint256</td><td>The vault manager fee applied to this vault.</td></tr><tr><td><code>pendingManagerFee</code></td><td>uint256</td><td>The manager fee to be applied at the next rebalance, after the fee was changed using <a href="#setmanagerfee"><code>setManagerFee</code></a></td></tr><tr><td><code>accruedManagerFees0</code></td><td>uint256</td><td>Total amount of uncollected manager fees within the vault.</td></tr><tr><td><code>accruedManagerFees1</code></td><td>uint256</td><td>Total amount of uncollected manager fees within the vault.</td></tr></tbody></table>
