# Vault Deployment

## Smart contracts deployment

### 1. StrategVault & ERC3525 deployment

The vault creation is done by calling `deployNewVault` on the `StrategUserInteractions` contract:

<pre class="language-solidity"><code class="lang-solidity"><strong>function deployNewVault(string _name, string _symbol, address _asset, uint256 _middlewareStrategy, uint256 _bufferSize, uint256 _creatorFees, uint256 _harvestFees, string _ipfsHash) external nonpayable
</strong></code></pre>

where

* &#x20;`_name` and `_symbol` *are ERC20 corresponding attributes*&#x20;
* `_asset` is the vault asset
* `_middlewareStrategy`, `_creatorFees` *and*  `_harvestFees` are vault configuration described [here](https://developers.strateg.io/core-protocol/vault-configuration)
* `_ipfsHash`  IPFS hash of the file containing vault's metadatas

When a vault is created, an ERC3525 contract is also deployed. This ERC3525 token is used for defining the current owner of the vault (tokenId 1), who has the authority to modify vaults parameters and manage the distribution of creator fees through the values assigned to different tokenIds of the ERC3525.

### 2. Position manager deployment

If the need need position manager(s) in its strategy, they have to be deployed  after the vault deployment to set the vault as the owner of itself.

To have more informations about position managers, check in [borrow module documentation](https://developers.strateg.io/borrow-module)

### 3. Vault strategy setup

Each vault's strategy comprises two lists of blocks: one for executing the strategy itself and another for executing the harvest process.&#x20;

A "[block](https://developers.strateg.io/core-protocol/broken-reference)" is a standardized contract that performs a specific action on a DeFi protocol. There are two types of blocks: StrategyBlock and HarvestBlock, each dedicated to execution in their respective block lists.&#x20;

For blocks to be utilized in vaults, they must first be registered in the block registry.

So, after being deployed,  a vault need to have a strategy configured by calling `setVaultStrategy` on the `StrategUserInteractions` contract

```solidity
setVaultStrategy(
    address vault,
    address[] memory _positionManagers,
    address[] memory _stratBlocks,
    bytes[] memory _stratBlocksParameters,
    bool[] memory _isFinalBlock,
    address[] memory _harvestBlocks,
    bytes[] memory _harvestBlocksParameters
) external;
```

where:&#x20;

* `_vault` is the vault's address
* `_positionManagers`: List of position managers owned by the vault. This addresses have the possibility to call protected function in the position manager rebalance context.
* `_stratBlocks`: Ordered list of block addresses executed on the strategy execution.&#x20;
* `_stratBlocksParameters`: Ordered list of bytes containing encoded parameters of block in the same index in `_stratBlocks` list
* `_isFinalBlock`: Ordered list of boolean to set a block in the stratBlocks as a final block. This is used only on strategy exit. When a block is a final block, it will receive the real percent to exit else it will receive 100% as exit percentage. &#x20;
* `_harvestBlocks`: Ordered list of block addresses executed on the harvest execution.&#x20;
* `_harvestBlocksParameters`: Ordered list of bytes containing encoded parameters of block in the same index in harvestBlocks list

**NB**: Since the vault strategy is setup, it will be immutable.&#x20;

### 4. Edit Vault parameters

A Vault has many configuration editable by its owner (described [here](https://developers.strateg.io/core-protocol/vault-configuration)) and to change them after the vault deployment, the vault owner have to call the following function:

```solidity
function editVaultParams(
    address _vault,
    IStrategVault.StrategVaultSettings[] memory _settings,
    bytes[] memory _data
) public
```

where:

* `_vault` is the vault's address
* `_settings` is the ordered list of setting ids to edits
* `_data` is the ordered list of settings data to apply on the vault

### 5. Give StrategOperatingPaymentToken operation allowance

The gas cost of vaults operations isn't handle by the protocol.

To be operated, a vault need to have a minimal operation approval from an address holding StrategOperatingPaymentToken tokens.

Basically, SOPT is a wrapped gas token giving the possibility to operator to get refunded of operation gas cost. See this [section](https://developers.strateg.io/core-protocol/vault-operations) to have more information
