# Convex 3Crv Vaults

ERC-4626 vaults that deposits Curve 3Pool LP tokens (3Crv) in a Curve 3Pool-based Metapool, eg musd3Crv; deposits the Metapool LP token in a [Convex](https://www.convexfinance.com/) pool; and stakes the Convex LP token, eg cvxmusd3Crv, for CRV and CVX rewards.

The Convex rewards are swapped for a Curve 3Pool token, eg DAI, USDC or USDT, using the `Liquidator` module and donated back to the vault. On donation back to the vault, the DAI, USDC or USDT is deposited into the underlying Curve Metapool; the Curve Metapool LP token is deposited into the corresponding Convex pool and the Convex LP token staked.

## Capabilities

* [ERC-4626](https://eips.ethereum.org/EIPS/eip-4626) compliant tokenized vault.
* [ERC-20](https://eips.ethereum.org/EIPS/eip-20) compliant token.
* Invests 3Crv assets in a Curve Metapool and LP token staked in Convex for boosted returns.
* Sandwich attack protection on ERC4626 operations `deposit`, `mint`, `withdraw` and `redeem`.
* Liquidation of Convex rewards like CRV and CVX for more reinvested 3Crv assets.
* Front-running protection against liquidation of rewards by streaming the increase in assets per share.
* Fee charged on liquidated Convex rewards.
* Vault operations are pausable by the `Governor`.
* Emergency asset recovery by the `Governor`. This will be removed after 2 months.
* Vault configuration is controlled by a protocol `Governor`. This includes:
  * Setting the slippage limits for mint, deposit, redeem and withdraw.
  * Setting the account that receives the liquidation fee.
* Initially the `Governor` can upgrade the contracts via a proxy without a time delay. After 6 weeks, this will be changed to a one week time delay.

## Contract Interface

See mStable's metavaults github repository for [contract diagrams](https://github.com/mstable/metavaults/tree/develop/contracts/vault/liquidity/convex#convex-vault-for-3pool-based-curve-metapools-3crv-1) and [process diagrams](https://github.com/mstable/metavaults/tree/develop/contracts/vault/liquidity/convex#processes).

See [general-erc-4626-vault-interface](https://developers.mstable.org/meta-vaults/general-erc-4626-vault-interface "mention") for the standard ERC-4626 functions.

### Variables

#### ASSET\_SCALE

```solidity
uint256 ASSET_SCALE
```

3CRV token scale

#### VIRTUAL\_PRICE\_SCALE

```solidity
uint256 VIRTUAL_PRICE_SCALE
```

#### metapool

```solidity
address metapool
```

Curve.fi pool the 3Crv asset is deposited into. eg musd3CRV, MIM-3LP3CRV-f or usdp3CRV.

#### metapoolToken

```solidity
address metapoolToken
```

Curve.fi Metapool liquidity provider token. eg Curve.fi MUSD/3Crv (musd3CRV)

#### metapoolTokenScale

```solidity
uint256 metapoolTokenScale
```

Scale of the metapool liquidity provider token. eg 1e18 if 18 decimal places.

#### basePool

```solidity
address basePool
```

Curve's 3Pool used as a base pool by the Curve metapools.

#### booster

```solidity
contract IConvexBooster booster
```

Convex's Booster contract that contains the Curve.fi LP pools.

#### convexPoolId

```solidity
uint256 convexPoolId
```

Convex's pool identifier. eg 14 for the musd3CRV pool.

#### baseRewardPool

```solidity
contract IConvexRewardsPool baseRewardPool
```

Convex's base rewards contract for staking Convex's LP token. eg staking cvxmusd3CRV

#### DAI

```solidity
address DAI
```

#### USDC

```solidity
address USDC
```

#### USDT

```solidity
address USDT
```

#### redeemSlippage

```solidity
uint256 redeemSlippage
```

Redeem slippage in basis points i.e. 1% = 100

#### depositSlippage

```solidity
uint256 depositSlippage
```

Deposit slippage in basis points i.e. 1% = 100

#### withdrawSlippage

```solidity
uint256 withdrawSlippage
```

Withdraw slippage in basis points i.e. 1% = 100

#### mintSlippage

```solidity
uint256 mintSlippage
```

Mint slippage in basis points i.e. 1% = 100

### Functions

#### liquidateVault

```solidity
function liquidateVault(uint256 minAssets) external
```

Governor liquidates all the vault's assets and send to the governor. Only to be used in an emergency. eg whitehat protection against a hack.

**Parameters**

<table><thead><tr><th width="126.33333333333331">Name</th><th width="96">Type</th><th>Description</th></tr></thead><tbody><tr><td>minAssets</td><td>uint256</td><td>Minimum amount of asset tokens to receive from removing liquidity from the Curve 3Pool. This provides sandwich attack protection.</td></tr></tbody></table>

#### resetAllowances

```solidity
function resetAllowances() external
```

Approves Curve's 3Pool contract to transfer assets (DAI, USDC or USDT) from this vault. Also approves the underlying Meta Vault to transfer 3Crv from this vault.

#### setDonateToken

```solidity
function setDonateToken(address __donateToken) external
```

Vault manager or governor sets the token the rewards are swapped for and donated back to the vault.

**Parameters**

<table><thead><tr><th width="168.33333333333331">Name</th><th width="123">Type</th><th>Description</th></tr></thead><tbody><tr><td>__donateToken</td><td>address</td><td>a token in the 3Pool (DAI, USDC or USDT).</td></tr></tbody></table>

#### setRedeemSlippage

```solidity
function setRedeemSlippage(uint256 _slippage) external
```

Governor function to set redeem slippage.

**Parameters**

<table><thead><tr><th width="121">Name</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>_slippage</td><td>uint256</td><td>Redeem slippage to apply as basis points i.e. 1% = 100</td></tr></tbody></table>

#### setDepositSlippage

```solidity
function setDepositSlippage(uint256 _slippage) external
```

Governor function to set deposit slippage.

**Parameters**

<table><thead><tr><th width="147.33333333333331">Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>_slippage</td><td>uint256</td><td>Deposit slippage to apply as basis points i.e. 1% = 100</td></tr></tbody></table>

#### setWithdrawSlippage

```solidity
function setWithdrawSlippage(uint256 _slippage) external
```

Governor function to set withdraw slippage.

**Parameters**

<table><thead><tr><th width="137.33333333333331">Name</th><th width="119">Type</th><th>Description</th></tr></thead><tbody><tr><td>_slippage</td><td>uint256</td><td>Withdraw slippage to apply as basis points i.e. 1% = 100</td></tr></tbody></table>

#### setMintSlippage

```solidity
function setMintSlippage(uint256 _slippage) external
```

Governor function to set mint slippage.

**Parameters**

<table><thead><tr><th width="140.33333333333331">Name</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td>_slippage</td><td>uint256</td><td>Mint slippage to apply as basis points i.e. 1% = 100</td></tr></tbody></table>
