> For the complete documentation index, see [llms.txt](https://v1.docs.blueberry.garden/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://v1.docs.blueberry.garden/developer-guides/contracts/vault/softvault.md).

# SoftVault

The Soft Vault contract allows users to lend and borrow tokens from/to Blueberry Money Market. SoftVault communicates with bTokens to lend and borrow underlying tokens from/to Blueberry Money Market. Underlying tokens can be ERC20 tokens listed by the Blueberry team, such as USDC, USDT, DAI, WETH, etc.

### Variables

The contract has the following variables:

* `bToken`: An instance of a cToken contract.
* `uToken`: An instance of an underlying token contract.
* `config`: An instance of Blueberry Protocol configuration contract.

### Events

The contract has the following events:

* `Deposited`: Emits when a user deposits an underlying token and receives share tokens.
* `Withdrawn`: Emits when a user withdraws an underlying token by redeeming share tokens.

### Functions

#### initialize

{% code overflow="wrap" %}

```solidity
function initialize(IProtocolConfig _config, ICErc20 _bToken, string memory _name, string memory _symbol) external initializer
```

{% endcode %}

The `initialize` function initializes the contract. It sets the contract owner, ERC20 name, ERC20 symbol, Blueberry Protocol configuration, bToken contract, and uToken contract.

#### decimals

{% code overflow="wrap" %}

```solidity
function decimals() public view override returns (uint8)
```

{% endcode %}

The `decimals` function returns the number of decimals of the bToken contract

#### deposit

{% code overflow="wrap" %}

```solidity
function deposit(uint256 amount) external override nonReentrant returns (uint256 shareAmount);
```

{% endcode %}

The `deposit` function allows users to deposit an underlying token and receive share tokens in exchange. It transfers the underlying token to the SoftVault contract, approves the transfer of the underlying token to the bToken contract, mints bTokens, and issues share tokens to the user. The function returns the amount of share tokens issued.

#### withdraw

{% code overflow="wrap" %}

```solidity
function withdraw(uint256 shareAmount) external override nonReentrant returns (uint256 withdrawAmount);
```

{% endcode %}

The `withdraw` function allows users to withdraw an underlying token by redeeming share tokens. It burns the share tokens from the user, redeems bTokens for the underlying token, cuts the vault withdraw fee if it's within the window (2 months), and transfers the underlying token to the user. The function returns the amount of underlying tokens transferred to the user.
