> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monolith.market/llms.txt
> Use this file to discover all available pages before exploring further.

# Vault

> ERC4626 vault implementation for yield farming

# Vault Contract

The Vault contract implements ERC4626 tokenized vault functionality for earning yield generated by borrower's interest.

[Contract implementation](https://github.com/MonolithMarket/Monolith/blob/main/src/Vault.sol)

## ERC4626 Standard Functions

### deposit

```solidity theme={null}
function deposit(uint256 assets, address receiver) public accrueInterest override returns (uint256 shares)
```

Deposits assets into the vault and mints corresponding vault shares to receiver.

**Parameters:**

* `assets`: Amount of underlying assets to deposit (in wei)
* `receiver`: Address to receive the vault shares

**Returns:**

* `shares`: Amount of vault shares minted

**Requirements:**

* `assets` must be > 0
* Caller must have approved vault for asset transfer
* If this is the first ever deposit into the vault, the minted shares must be at least `MIN_SHARES` (1e16); otherwise the transaction reverts

**Effects:**

* Transfers assets from caller to vault
* Mints shares to receiver
* Updates total assets
* Accrues interest before deposit
* On the first ever deposit, `MIN_SHARES` shares are burned from the receiver and sent to `address(0)` to initialize share pricing; the receiver's net minted shares are reduced by `MIN_SHARES`

***

### mint

```solidity theme={null}
function mint(uint256 shares, address receiver) public accrueInterest override returns (uint256 assets)
```

Mints exact amount of vault shares by depositing corresponding assets.

**Parameters:**

* `shares`: Exact amount of shares to mint
* `receiver`: Address to receive the vault shares

**Returns:**

* `assets`: Amount of assets required for the mint

**Requirements:**

* `shares` must be > 0
* Caller must have sufficient assets approved
* If this is the first ever mint into the vault, the requested `shares` must be at least `MIN_SHARES` (1e16); otherwise the transaction reverts

**Effects:**

* Calculates required assets based on current share price
* Transfers assets from caller to vault
* Mints exact shares to receiver
* On the first ever mint, `MIN_SHARES` shares are burned from the receiver and sent to `address(0)`; the corresponding `assets` are effectively reserved

***

### withdraw

```solidity theme={null}
function withdraw(
    uint256 assets,
    address receiver,
    address owner
) public accrueInterest override returns (uint256 shares)
```

Burns vault shares and returns corresponding assets to receiver.

**Parameters:**

* `assets`: Amount of assets to withdraw
* `receiver`: Address to receive the assets
* `owner`: Address that owns the shares (can be different from caller with approval)

**Returns:**

* `shares`: Amount of shares burned

**Requirements:**

* `assets` must be ≤ owner's balance
* If `owner != msg.sender`, caller must have withdrawal approval
* Vault must have sufficient assets

**Effects:**

* Burns shares from owner
* Transfers assets to receiver
* Updates total assets

***

### redeem

```solidity theme={null}
function redeem(
    uint256 shares,
    address receiver,
    address owner
) public accrueInterest override returns (uint256 assets)
```

Burns exact amount of vault shares and returns corresponding assets.

**Parameters:**

* `shares`: Amount of shares to redeem
* `receiver`: Address to receive the assets
* `owner`: Address that owns the shares

**Returns:**

* `assets`: Amount of assets returned

**Requirements:**

* `shares` must be ≤ owner's balance
* If `owner != msg.sender`, caller must have approval

**Effects:**

* Burns shares from owner
* Transfers assets to receiver
* Returns actual assets received (may differ due to rounding)

***

## View Functions

### totalAssets

```solidity theme={null}
function totalAssets() public view override returns (uint256)
```

Returns the total amount of underlying assets held by the vault.

**Returns:**

* `uint256`: Total assets in wei

**Note:** Returns the current `asset` token balance held by the vault contract.

***

### convertToShares

```solidity theme={null}
function convertToShares(uint256 assets) public view override returns (uint256)
```

Calculates the amount of shares that would be minted for given assets.

**Parameters:**

* `assets`: Amount of assets to convert

**Returns:**

* `uint256`: Equivalent shares amount

***

### convertToAssets

```solidity theme={null}
function convertToAssets(uint256 shares) public view override returns (uint256)
```

Calculates the amount of assets that would be returned for given shares.

**Parameters:**

* `shares`: Amount of shares to convert

**Returns:**

* `uint256`: Equivalent assets amount

***

### maxDeposit

```solidity theme={null}
function maxDeposit(address) public view override returns (uint256)
```

Returns the maximum amount of assets that can be deposited.

**Returns:**

* `uint256`: Maximum deposit amount (type(uint256).max if unlimited)

***

### maxMint

```solidity theme={null}
function maxMint(address) public view override returns (uint256)
```

Returns the maximum amount of shares that can be minted.

**Returns:**

* `uint256`: Maximum mint amount

***

### maxWithdraw

```solidity theme={null}
function maxWithdraw(address owner) public view override returns (uint256)
```

Returns the maximum amount of assets that can be withdrawn by owner.

**Parameters:**

* `owner`: Address to check withdrawal limit for

**Returns:**

* `uint256`: Maximum withdrawable assets

***

### maxRedeem

```solidity theme={null}
function maxRedeem(address owner) public view override returns (uint256)
```

Returns the maximum amount of shares that can be redeemed by owner.

**Parameters:**

* `owner`: Address to check redemption limit for

**Returns:**

* `uint256`: Maximum redeemable shares

***

### previewDeposit

```solidity theme={null}
function previewDeposit(uint256 assets) public view override returns (uint256)
```

Previews the amount of shares that would be minted for a deposit.

**Parameters:**

* `assets`: Amount of assets to deposit

**Returns:**

* `uint256`: Expected shares to receive

***

### previewMint

```solidity theme={null}
function previewMint(uint256 shares) public view override returns (uint256)
```

Previews the amount of assets required to mint given shares.

**Parameters:**

* `shares`: Amount of shares to mint

**Returns:**

* `uint256`: Required assets amount

***

### previewWithdraw

```solidity theme={null}
function previewWithdraw(uint256 assets) public view override returns (uint256)
```

Previews the amount of shares that would be burned for a withdrawal.

**Parameters:**

* `assets`: Amount of assets to withdraw

**Returns:**

* `uint256`: Shares to be burned

***

### previewRedeem

```solidity theme={null}
function previewRedeem(uint256 shares) public view override returns (uint256)
```

Previews the amount of assets that would be returned for redeeming shares.

**Parameters:**

* `shares`: Amount of shares to redeem

**Returns:**

* `uint256`: Assets to be received

***

## ERC20 Functions

The vault also implements standard ERC20 functions for shares:

* `name()`: Returns vault share token name
* `symbol()`: Returns vault share token symbol
* `decimals()`: Returns decimals (same as underlying asset)
* `totalSupply()`: Returns total vault shares
* `balanceOf(address)`: Returns shares balance of address
* `transfer(address,uint256)`: Transfers shares
* `allowance(address,address)`: Returns transfer allowance
* `approve(address,uint256)`: Approves share transfers
* `transferFrom(address,address,uint256)`: Transfers shares with approval

## Yield and Staking Features

### accrueInterest

```solidity theme={null}
function accrueInterest() external
```

Accrues interest from the underlying lender contract. Must be called before share calculations.

**Effects:**

* Updates vault's asset balance with accrued interest
* Maintains accurate share pricing

***

## Security Considerations

* All state-changing functions accrue interest first
* Share calculations use current total assets
* The first ever depositor forfeits `MIN_SHARES` (1e16 = 0.01 share units) which are burned to `address(0)` to prevent the ERC‑4626 inflation attack
