# 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.


---

# 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://v1.docs.blueberry.garden/developer-guides/contracts/vault/softvault.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.
