# Save Wrapper

The Save Wrapper bundles utility functions together to simplify multiple interactions with mStable's smart contract calls into one single call. This contract is immutable.

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

| Name                                                                                                                        | Contract                                                                                                             | Address                                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| [Save Wrapper](https://github.com/mstable/mStable-contracts/blob/master/contracts%2Fsavings%2Fperipheral%2FSaveWrapper.sol) | [SaveWrapper](https://github.com/mstable/mStable-contracts/blob/master/contracts/savings/peripheral/SaveWrapper.sol) | [0xfd8932F4887E39D8EeD05dc407924124026bD902](https://polygonscan.com/address/0xfd8932F4887E39D8EeD05dc407924124026bD902) |
| {% endtab %}                                                                                                                |                                                                                                                      |                                                                                                                          |
| {% endtabs %}                                                                                                               |                                                                                                                      |                                                                                                                          |

## Functions

### saveAndStake()

`function saveAndStake (address _mAsset, address _save, address _vault, uint256 _amount) external`

Simply saves an mAsset and then into the vault

| Parameter | Type    | Description                           |
| --------- | ------- | ------------------------------------- |
| `_mAsset` | address | mAsset address                        |
| `_save`   | address | Save address                          |
| `_vault`  | address | Boosted Savings Vault address         |
| `_amount` | uint256 | Units of mAsset to deposit to savings |

### saveAndStake()

`function saveAndStake (address _mAsset, address _save, address _vault, uint256 _amount, address _referrer) external`

Simply saves an mAsset and then into the vault

| Parameter   | Type    | Description                           |
| ----------- | ------- | ------------------------------------- |
| `_mAsset`   | address | mAsset address                        |
| `_save`     | address | Save address                          |
| `_vault`    | address | Boosted Savings Vault address         |
| `_amount`   | uint256 | Units of mAsset to deposit to savings |
| `_referrer` | address | Referrer address for this deposit.    |

### saveViaMint()

`function saveViaMint (address _mAsset, address _bAsset, address _save, address _vault, uint256 _amount, uint256 _minOut, bool _stake) external`

Mints an mAsset and then deposits to Save/Savings Vault

| Parameter | Type    | Description                                   |
| --------- | ------- | --------------------------------------------- |
| `_mAsset` | address | mAsset address                                |
| `_bAsset` | address | bAsset address                                |
| `_save`   | address | Save address                                  |
| `_vault`  | address | Boosted Savings Vault address                 |
| `_amount` | uint256 | Amount of bAsset to mint with                 |
| `_minOut` | uint256 | Min amount of mAsset to get back              |
| `_stake`  | bool    | Add the imAsset to the Boosted Savings Vault? |

### saveViaMint()

`function saveViaMint (address _mAsset, address _bAsset, address _save, address _vault, uint256 _amount, uint256 _minOut, bool _stake, address _referrer) external`

Mints an mAsset and then deposits to Save/Savings Vault

| Parameter   | Type    | Description                                  |
| ----------- | ------- | -------------------------------------------- |
| `_mAsset`   | address | mAsset address                               |
| `_bAsset`   | address | bAsset address                               |
| `_save`     | address | Save address                                 |
| `_vault`    | address | Boosted Savings Vault address                |
| `_amount`   | uint256 | Amount of bAsset to mint with                |
| `_minOut`   | uint256 | Min amount of mAsset to get back             |
| `_stake`    | bool    | Add the imAsset to the Boosted Savings Vault |
| `_referrer` | address | Referrer address for this deposit.           |

### saveViaSwap()

`function saveViaSwap (address _mAsset, address _save, address _vault, address _feeder, address _fAsset, uint256 _fAssetQuantity, uint256 _minOutputQuantity, bool _stake) external`

Swaps fAsset for mAsset and then deposits to Save/Savings Vault

| Parameter            | Type    | Description                                      |
| -------------------- | ------- | ------------------------------------------------ |
| `_mAsset`            | address | mAsset address                                   |
| `_save`              | address | Save address                                     |
| `_vault`             | address | Boosted Savings Vault address                    |
| `_feeder`            | address | Feeder Pool address                              |
| `_fAsset`            | address | fAsset address                                   |
| `_fAssetQuantity`    | uint256 | Quantity of fAsset sent                          |
| `_minOutputQuantity` | uint256 | Min amount of mAsset to be swapped and deposited |
| `_stake`             | bool    | Deposit the imAsset in the Savings Vault?        |

### saveViaSwap()

`function saveViaSwap (address _mAsset, address _save, address _vault, address _feeder, address _fAsset, uint256 _fAssetQuantity, uint256 _minOutputQuantity, bool _stake, address _referrer) external`

Swaps fAsset for mAsset and then deposits to Save/Savings Vault

| Parameter            | Type    | Description                                      |
| -------------------- | ------- | ------------------------------------------------ |
| `_mAsset`            | address | mAsset address                                   |
| `_save`              | address | Save address                                     |
| `_vault`             | address | Boosted Savings Vault address                    |
| `_feeder`            | address | Feeder Pool address                              |
| `_fAsset`            | address | fAsset address                                   |
| `_fAssetQuantity`    | uint256 | Quantity of fAsset sent                          |
| `_minOutputQuantity` | uint256 | Min amount of mAsset to be swapped and deposited |
| `_stake`             | bool    | Deposit the imAsset in the Savings Vault?        |
| `_referrer`          | address | Referrer address for this deposit.               |

### saveViaUniswapETH()

`function saveViaUniswapETH (address _mAsset, address _save, address _vault, address _uniswap, uint256 _amountOutMin, address[] _path, uint256 _minOutMStable, bool _stake) external`

Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset, optionally staking in the Boosted Savings Vault

| Parameter        | Type       | Description                              |
| ---------------- | ---------- | ---------------------------------------- |
| `_mAsset`        | address    | mAsset address                           |
| `_save`          | address    | Save address                             |
| `_vault`         | address    | Boosted vault address                    |
| `_uniswap`       | address    | Uniswap router address                   |
| `_amountOutMin`  | uint256    | Min uniswap output in bAsset units       |
| `_path`          | address\[] | Sell path on Uniswap (e.g. \[WETH, DAI]) |
| `_minOutMStable` | uint256    | Min amount of mAsset to receive          |
| `_stake`         | bool       | Add the imAsset to the Savings Vault?    |

### saveViaUniswapETH()

`function saveViaUniswapETH (address _mAsset, address _save, address _vault, address _uniswap, uint256 _amountOutMin, address[] _path, uint256 _minOutMStable, bool _stake, address _referrer) external`

Buys a bAsset on Uniswap with ETH, then mints imAsset via mAsset,optionally staking in the Boosted Savings Vault

| Parameter        | Type       | Description                              |
| ---------------- | ---------- | ---------------------------------------- |
| `_mAsset`        | address    | mAsset address                           |
| `_save`          | address    | Save address                             |
| `_vault`         | address    | Boosted vault address                    |
| `_uniswap`       | address    | Uniswap router address                   |
| `_amountOutMin`  | uint256    | Min uniswap output in bAsset units       |
| `_path`          | address\[] | Sell path on Uniswap (e.g. \[WETH, DAI]) |
| `_minOutMStable` | uint256    | Min amount of mAsset to receive          |
| `_stake`         | bool       | Add the imAsset to the Savings Vault?    |
| `_referrer`      | address    | Referrer address for this deposit.       |

### estimate\_saveViaUniswapETH()

`function estimate_saveViaUniswapETH (address _mAsset, address _uniswap, uint256 _ethAmount, address[] _path) external returns (uint256 out)`

Gets estimated mAsset output from a WETH > bAsset > mAsset trade

| Parameter    | Type       | Description                              |
| ------------ | ---------- | ---------------------------------------- |
| `_mAsset`    | address    | mAsset address                           |
| `_uniswap`   | address    | Uniswap router address                   |
| `_ethAmount` | uint256    | ETH amount to sell                       |
| `_path`      | address\[] | Sell path on Uniswap (e.g. \[WETH, DAI]) |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.mstable.org/polygon/save-wrapper.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
