# HardVault

The Hard Vault contract is designed to hold LP (Liquidity Provider) tokens as collateral. The contract is ERC1155 compliant, which means that the underlying LP tokens are identified by casted tokenId from token address.

### State Variables

The Hard Vault contract has the following state variables:

* `config`: The address of the protocol configuration contract.

### Events

The Hard Vault contract emits the following events:&#x20;

* `Deposited`: Emitted when a user deposits LP tokens into the vault.
* `Withdrawn`: Emitted when a user withdraws LP tokens from the vault.

### Functions

#### initialize

{% code overflow="wrap" %}

```solidity
initialize(IProtocolConfig _config) external initializer
```

{% endcode %}

The `initialize` function is an initializer function that is called when the contract is deployed. It initializes the state variables of the contract.

**Parameters:**

* `_config`(IProtocolConfig): The address of the protocol configuration contract.

#### \_encodeTokenId

{% code overflow="wrap" %}

```solidity
_encodeTokenId(address uToken) internal pure returns (uint)
```

{% endcode %}

The `_encodeTokenId` function takes an underlying token address and encodes it into a token ID.

**Parameters:**

* `uToken`(address): The address of the underlying token.

#### \_decodeTokenId

{% code overflow="wrap" %}

```solidity
_decodeTokenId(uint tokenId) internal pure returns (address)
```

{% endcode %}

The `_decodeTokenId` function takes a token ID and decodes it into an underlying token address.

**Parameters:**

* `tokenId`(uint): The token ID to decode.

#### balanceOfERC20

{% code overflow="wrap" %}

```solidity
balanceOfERC20(address token, address user) external view override returns (uint256)
```

{% endcode %}

The `balanceOfERC20` function returns the balance of an underlying ERC20 token for a given user.

**Parameters:**

* `token`: The address of the ERC20 token.
* `user`: The address of the user.

#### getUnderlyingToken

{% code overflow="wrap" %}

```solidity
getUnderlyingToken(uint256 tokenId) external pure override returns (address token)
```

{% endcode %}

The `getUnderlyingToken` function returns the underlying ERC20 token address for a given ERC1155 token ID.

**Parameters:**

* `tokenId`: The ERC1155 token ID.

#### deposit

{% code overflow="wrap" %}

```solidity
deposit(address token, uint256 amount) external override nonReentrant returns (uint256 shareAmount)
```

{% endcode %}

The `deposit` function allows a user to deposit underlying assets into the vault and issue share tokens.

**Parameters:**

* `token`: The address of the underlying token to deposit.
* `amount`: The amount of underlying tokens to deposit.

#### withdraw

{% code overflow="wrap" %}

```solidity
withdraw(address token, uint256 shareAmount) external override nonReentrant returns (uint256 withdrawAmount)
```

{% endcode %}

The `withdraw` function allows a user to withdraw underlying assets from the vault.

**Parameters:**

* `token`: The address of the underlying token to withdraw.
* `shareAmount`: The amount of share tokens to redeem.
