# Vaults

Vaults are used to earn rewards. Tokens such as imUSD or Feeder Pool tokens can be deposited to earn additional MTA rewards. On Polygon the contract `HeadlessRewardToken` is used. This allows for accrual of 2 Rewards and does not contain the Boost functionality that is present on Ethereum Mainnet. Contracts are upgradable.

{% hint style="warning" %}
The Feeder Pool Vault for mUSD/FRAX has been developed by frax.finance and is not part of these docs.
{% endhint %}

The following table lays out the currently deployed vaults and what contract is used.

{% tabs %}
{% tab title="Polygon" %}

| Vault                                                                                                                                 | Address                                                                                                                  |
| ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| [imUSD Vault](https://github.com/mstable/mStable-contracts/blob/master/contracts/rewards/staking/StakingRewardsWithPlatformToken.sol) | [0x32aba856dc5ffd5a56bcd182b13380e5c855aa29](https://polygonscan.com/address/0x32aba856dc5ffd5a56bcd182b13380e5c855aa29) |
| mUSD/FRAX Feeder Pool Vault (FRAX Contract)                                                                                           | [0xc425fd9ed3c892d849c9e1a971516da1c1b29696](https://polygonscan.com/address/0xc425fd9ed3c892d849c9e1a971516da1c1b29696) |
| {% endtab %}                                                                                                                          |                                                                                                                          |
| {% endtabs %}                                                                                                                         |                                                                                                                          |

## imUSD Vault

### stake()

`function stake (uint256 _amount) external`

Stakes a given amount of the StakingToken for the sender

| Parameter | Type    | Description           |
| --------- | ------- | --------------------- |
| `_amount` | uint256 | Units of StakingToken |

### stake()

`function stake (address _beneficiary, uint256 _amount) external`

Stakes a given amount of the StakingToken for a given beneficiary

| Parameter      | Type    | Description                                |
| -------------- | ------- | ------------------------------------------ |
| `_beneficiary` | address | Staked tokens are credited to this address |
| `_amount`      | uint256 | Units of StakingToken                      |

### exit()

`function exit () external`

Withdraws stake from pool and claims any rewards

### withdraw()

`function withdraw (uint256 _amount) external`

Withdraws given stake amount from the pool

### withdrawAndUnwrap()

`function withdrawAndUnwrap (uint256 _amount, uint256 _minAmountOut, address _output, address _beneficiary, address _router, bool _isBassetOut) external returns (uint256 outputQuantity)`

Redeems staked interest-bearing asset tokens for either bAsset or fAsset tokens. Withdraws a given staked amount of interest-bearing assets from the vault, redeems the interest-bearing asset for the underlying mAsset and either

1. Redeems the underlying mAsset tokens for bAsset tokens.
2. Swaps the underlying mAsset tokens for fAsset tokens in a Feeder Pool.

| Parameter       | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                      |      |
| --------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---- |
| `_amount`       | uint256 | Units of the staked interest-bearing asset tokens to withdraw. eg imUSD or imBTC.                                                                                                                                                                                                                                                                                                                |      |
| `_minAmountOut` | uint256 | Minimum units of `output` tokens to be received by the beneficiary. This is to the same decimal places as the `output` token.                                                                                                                                                                                                                                                                    |      |
| `_output`       | address | <p>Asset to receive in exchange for the redeemed mAssets. This can be a bAsset or a fAsset. For example: <br>    - bAssets (USDC, DAI, sUSD or USDT) or fAssets (GUSD, BUSD, alUSD, FEI or RAI) for mainnet imUSD Vault.</p><p>- bAssets (USDC, DAI or USDT) or fAsset FRAX for Polygon imUSD Vault.</p><p>- bAssets (WBTC, sBTC or renBTC) or fAssets (HBTC or TBTCV2) for mainnet imBTC Vault. | </p> |
| `_beneficiary`  | address | Address to send `output` tokens to.                                                                                                                                                                                                                                                                                                                                                              |      |
| `_router`       | address | mAsset address if the `output` is a bAsset. Feeder Pool address if the `output` is a fAsset.                                                                                                                                                                                                                                                                                                     |      |
| `_isBassetOut`  | bool    | `true` if `output` is a bAsset. `false` if `output` is a fAsset                                                                                                                                                                                                                                                                                                                                  |      |

### claimReward()

`function claimReward () external`

Claims outstanding rewards (both platform and native) for the sender. First updates outstanding reward allocation and then transfers.

### claimRewardOnly()

`function claimRewardOnly () external`

Claims outstanding rewards for the sender. Only the native rewards token, and not the platform rewards

### getRewardToken()

`function getRewardToken () external returns (contract IERC20)`

Gets the RewardsToken

### getPlatformToken()

`function getPlatformToken () external returns (contract IERC20)`

Gets the PlatformToken

### lastTimeRewardApplicable()

`function lastTimeRewardApplicable () public returns (uint256)`

Gets the last applicable timestamp for this reward period

### rewardPerToken()

`function rewardPerToken () public returns (uint256, uint256)`

Calculates the amount of unclaimed rewards a user has earned

### earned()

`function earned (address _account) public returns (uint256, uint256)`

Calculates the amount of unclaimed rewards a user has earned

| Parameter  | Type    | Description  |
| ---------- | ------- | ------------ |
| `_account` | address | User address |

### notifyRewardAmount()

`function notifyRewardAmount (uint256 _reward) external`

Notifies the contract that new rewards have been added. Calculates an updated rewardRate based on the rewards in period.

| Parameter | Type    | Description                                           |
| --------- | ------- | ----------------------------------------------------- |
| `_reward` | uint256 | Units of RewardToken that have been added to the pool |

### totalSupply()

`function totalSupply () public returns (uint256)`

Get the total amount of the staked token

### balanceOf()

`function balanceOf (address _account) public returns (uint256)`

Get the balance of a given account

<table data-header-hidden><thead><tr><th width="403.3333333333333">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>Parameter</td><td>Type</td><td>Description</td></tr><tr><td><code>_account</code></td><td>address</td><td>User for which to retrieve balance</td></tr></tbody></table>
