# Factory

## View Methods

### countVault

```solidity
function countVault() external view returns (uint256)
```

Returns the number of vaults from the factory.

**Return Value:**

| Type    | Description      |
| ------- | ---------------- |
| uint256 | number of vaults |

### getWhitelistedTokens

```solidity
function getWhitelistedTokens() external view returns (address[] memory)
```

Returns a list of all whitelisted token addresses.

**Return Value:**

| Type       | Description                     |
| ---------- | ------------------------------- |
| address\[] | addresses of whitelisted tokens |

### getFeesReceiver

```solidity
function getFeesReceiver(uint256 _feeType) external view returns (address)
```

Returns the address of the fees receiver.

**Call Parameters:**

| Name       | Type    | Description                                       |
| ---------- | ------- | ------------------------------------------------- |
| `_feeType` | uint256 | <p>0 corresponds to<br>managementFeesReceiver</p> |

**Return Value:**

| Type    | Description                             |
| ------- | --------------------------------------- |
| address | address of the fees receivercreateVault |

### isTokenWhitelisted

```solidity
function isTokenWhitelisted(address _token) public view returns (bool)
```

Checks if a token is whitelisted.

**Call Parameters:**

| Name      | Type    | Description              |
| --------- | ------- | ------------------------ |
| `_tokens` | address | token's address to check |

**Return Value:**

| Type | Description                                               |
| ---- | --------------------------------------------------------- |
| bool | returns `true` if the address of the token is whitelisted |

### getFactoryState

```solidity
function getFactoryState()
    external
    view
    returns (
        address[] memory,
        address,
        address,
        address,
        address,
        address
    )
```

Returns all parameters from the factory.

**Return Values:**

| Type       | Description                   |
| ---------- | ----------------------------- |
| address\[] | addresses of the vaults       |
| address    | address of the fees manager   |
| address    | address of the access manager |
| address    | address of the harvester      |
| address    | address of the proxy          |
| address    | address of the router         |

### getVaultState

```solidity
function getVaultState(address _vault)
    external
    view
    returns (
        VLib.Token[] memory vTokens,
        VLib.ConstantProps memory constantProps,
        VLib.HistoryProps memory historyProps,
        VLib.ConfigProps memory configProps,
        VLib.FeesProps memory feesProps,
        VLib.SecurityProps memory securityProps,
        uint256[] memory balances,
        uint256[] memory positions,
        uint256 vvl,
        uint256 sharePrice,
        uint256[2] memory ongoingFees
    )
```

Returns the parameters of a vault.

**Call Parameters:**

| Name     | Type    | Description          |
| -------- | ------- | -------------------- |
| `_vault` | address | address of the vault |

**Return Values:**

| Name            | Type               | Description                                          |
| --------------- | ------------------ | ---------------------------------------------------- |
| `vTokens`       | VLib.Token\[]      | list of the tokens managed by the vault              |
| `constantProps` | VLib.constantProps | constant parameters from the vault                   |
| `historyProps`  | VLib.HistoryProps  | previous parameters                                  |
| `configProps`   | VLib.ConfigProps   | main configuration parameters from the vault         |
| `feesProps`     | VLib.FeesProps     | fees parameter from the vault                        |
| `securityProps` | VLib.securityProps | security parameter from the vault                    |
| `balances`      | uint256            | amount of each assets in the vault                   |
| `positions`     | uint256            | positions from the vaults                            |
| `vvl`           | uint256            | vault's TVL                                          |
| `sharePrice`    | uint256            | share price                                          |
| `ongoingFees`   | uint256\[2]        | amount of management and performance fees to harvest |

### getVaultOngoingFees

<pre class="language-solidity"><code class="lang-solidity"><strong>function getVaultOngoingFees(address _vault) 
</strong><strong>    external 
</strong><strong>    view 
</strong><strong>    returns (
</strong><strong>        uint256 ongoingManagementFees, 
</strong><strong>        uint256 ongoingPerformanceFees
</strong><strong>    )
</strong></code></pre>

Returns the amount of fees to harvest according to a vault address.

**Call Parameters:**

| Name     | Type    | Description          |
| -------- | ------- | -------------------- |
| `_vault` | address | address of the vault |

**Return Values:**

| Name                     | Type    | Description                           |
| ------------------------ | ------- | ------------------------------------- |
| `ongoingManagementFees`  | uint256 | amount of management fees to harvest  |
| `ongoingPerformanceFees` | uint256 | amount of performance fees to harvest |

### getShareState

```solidity
function getShareState(address _vault)
    external
    view
    returns (
        address share,
        string memory name,
        string memory symbol,
        uint8 decimals,
        uint256 supply,
        bool transferable
    )
```

Returns the share parameters from a vault according to its address.

**Call Parameters:**

| Name     | Type    | Description          |
| -------- | ------- | -------------------- |
| `_vault` | address | address of the vault |

**Return Values:**

| Name           | Type    | Description                   |
| -------------- | ------- | ----------------------------- |
| `share`        | address | address of vault's share      |
| `name`         | string  | name of the vault's share     |
| `symbol`       | string  | symbol of vault's share       |
| `decimals`     | uint8   | vault's share decimals        |
| `supply`       | uint256 | vault's share supply          |
| `transferable` | bool    | vault's share transferability |

### getUserShareState

```solidity
function getUserShareState(address _vault, address _user)
    external
    view
    returns (
        address share,
        uint256 balance,
        uint256 allowanceToVault
    )
```

Returns user's share information according to the vault's address and the user address.

**Call Parameters:**

| Name     | Type    | Description          |
| -------- | ------- | -------------------- |
| `_vault` | address | address of the vault |
| `_user`  | address | address of the user  |

**Return Values:**

| Name               | Type    | Description                              |
| ------------------ | ------- | ---------------------------------------- |
| `share`            | address | address of vault's share                 |
| `balance`          | uint256 | amount of share in user's wallet         |
| `allowanceToVault` | uint256 | allowance between the user and the vault |

### getRolesPerVault

```solidity
function getRolesPerVault(address _vault)
    external
    view
    returns (
        bytes32[3] memory,
        address[] memory,
        address[] memory,
        address[] memory
    )
```

Returns the roles names and the addresses of the admins, strategists and harvesters according to a vault address.

**Call Parameters:**

| Name     | Type    | Description          |
| -------- | ------- | -------------------- |
| `_vault` | address | address of the vault |

**Return Values:**

| Type        | Description                   |
| ----------- | ----------------------------- |
| bytes32\[3] | list of roles names           |
| address\[]  | list of admins addresses      |
| address\[]  | list of strategists addresses |
| address\[]  | list of harvesters addresses  |

## Write Methods

### createVault

```solidity
function createVault(
    address[] calldata _tokensAddresses,
    VLib.CreationProps calldata _creationProps,
    VLib.FeesProps calldata _feesProps,
    VLib.SecurityProps calldata _securityProps
) external
```

Creates a vault with the parameters requested.

{% hint style="info" %}
This method can only be called by address with **VAULT\_CREATOR\_ROLE**.
{% endhint %}

**Call Parameters:**

| Name               | Type               | Description            |
| ------------------ | ------------------ | ---------------------- |
| `_tokensAddresses` | address\[]         | all manageable assets  |
| `_creationProps`   | VLib.CreationProps | main vault information |
| `_feesProps`       | VLib.FeesProps     | fees parameters        |
| `_securityProps`   | VLib.SecurityProps | security parameters    |

### setAccessManager

```solidity
function setAccessManager(address _newAccesslolManager) external
```

Settles the new AccessManager.&#x20;

{% hint style="info" %}
This method can only be called by the contract **owner**.
{% endhint %}

**Call Parameters:**

| Name                | Type    | Description                      |
| ------------------- | ------- | -------------------------------- |
| `_newAccessManager` | address | address of the new AccessManager |

### setFeesManager

```solidity
function setFeesManager(address _newFeesManager) external
```

Settles the new FeesManager.&#x20;

{% hint style="info" %}
This method can only be called by the contract **owner**.
{% endhint %}

**Call Parameters:**

| Name              | Type    | Description                    |
| ----------------- | ------- | ------------------------------ |
| `_newFeesManager` | address | address of the new FeesManager |

### setHarvester

```solidity
function setHarvester(address _newHarvester) external
```

Settles the new Harvester.&#x20;

{% hint style="info" %}
This method can only be called by the contract **owner**.
{% endhint %}

**Call Parameters:**

| Name            | Type    | Description                  |
| --------------- | ------- | ---------------------------- |
| `_newHarvester` | address | address of the new Harvester |

### setSwapContracts

```solidity
function setSwapContracts(address _newSwapRouter, address _newSwapProxy) external
```

Settles the new aggregator proxy and router.&#x20;

{% hint style="info" %}
This method can only be called by the contract **owner**.
{% endhint %}

**Call Parameters:**

| Name             | Type    | Description               |
| ---------------- | ------- | ------------------------- |
| `_newSwapRouter` | address | address of the new router |
| `_newSwapProxy`  | address | address of the new proxy  |

### setSwapAdapter

<pre class="language-solidity"><code class="lang-solidity"><strong>function setSwapAdapter(address _newSwapAdapter) external
</strong></code></pre>

Settles the new swap adapter.&#x20;

{% hint style="info" %}
This method can only be called by the contract **owner**.
{% endhint %}

**Call Parameters:**

| Name              | Type    | Description                     |
| ----------------- | ------- | ------------------------------- |
| `_newSwapAdapter` | address | address of the new swap adapter |

### addTokenAndPriceFeedsToWL

```solidity
function addTokensAndPriceFeedsToWL(
    address[] calldata _tokens, 
    address[] calldata _priceFeeds
) external
```

Whitelists a tokens and their oracles for vaults.&#x20;

{% hint style="info" %}
This method can only be called by the contract **owner**.
{% endhint %}

**Call Parameters:**

| Name          | Type       | Description                                |
| ------------- | ---------- | ------------------------------------------ |
| `_token`      | address\[] | list of tokens addresses to whitelist      |
| `_priceFeeds` | address\[] | list token's oracle addresses to whitelist |

### removeTokensFromWhitelist

```solidity
function removeTokensFromWhitelist(address[] calldata _tokens) external
```

Removes tokens and their oracles from the whitelist.&#x20;

{% hint style="info" %}
This method can only be called by the contract **owner**.
{% endhint %}

**Parameters:**

| Name      | Type       | Description                        |
| --------- | ---------- | ---------------------------------- |
| `_tokens` | address\[] | list of tokens addresses to remove |

###
