# ProtocolConfig

This contract defines a set of configurable parameters that are used throughout the protocol. It also defines a set of setter functions for these parameters that can be called by the contract owner.

### State Variables

The state variables of this contract are as follows:

* `feeManager`: an instance of the `IFeeManager` interface that manages the fees charged by the protocol.
* `depositFee`: a `uint256` that represents the deposit fee charged by the protocol as a percentage of the deposited amount (default is 0.5% or 50 basis points).
* `withdrawFee`: a `uint256` that represents the withdrawal fee charged by the protocol as a percentage of the withdrawn amount (default is 0.5% or 50 basis points).
* `rewardFee`: a `uint256` that represents the reward fee charged by the protocol as a percentage of the total reward amount (default is 10% or 1000 basis points).
* `withdrawVaultFee`: a `uint256` that represents the withdrawal fee charged by the protocol's liquidity vault (default is 1% or 100 basis points).
* `withdrawVaultFeeWindow`: a `uint256` that represents the time window during which the withdrawal fee charged by the protocol's liquidity vault is applied (default is 60 days).
* `withdrawVaultFeeWindowStartTime`: a `uint256` that represents the start time of the window during which the withdrawal fee charged by the protocol's liquidity vault is applied (default is 0).
* `maxSlippageOfClose`: a `uint256` that represents the maximum slippage of converting withdrawn reserves to debt tokens when closing a position (default is 3% or 300 basis points).
* `treasuryFeeRate`: a `uint256` that represents the percentage of the deposit/withdraw fee that is directed to the protocol's treasury (default is 0.15% or 30 basis points). \***NOT UTILIZED IN THIS VERSION YET\***
* `blbStablePoolFeeRate`: a `uint256` that represents the percentage of the deposit/withdraw fee that is directed to the protocol's stability pool (default is 0.175% or 35 basis points). \***NOT UTILIZED IN THIS VERSION YET\***
* `treasury`: an `address` that represents the wallet address of the protocol's treasury.
* `blbUsdcIchiVault`: an `address` that represents the address of the protocol's fee split for ICHI vault. \***NOT UTILIZED IN THIS VERSION YET\***
* `blbStabilityPool`: an `address` that represents the address \***NOT UTILIZED IN THIS VERSION YET\***

### Functions&#x20;

#### initialize

{% code overflow="wrap" %}

```solidity
function initialize(address treasury_) external initializer
```

{% endcode %}

This function is the initializer function which is called once when the contract is deployed. It sets the initial values for the contract's state variables such as depositFee, withdrawFee, rewardFee, treasuryFeeRate, blbStablePoolFeeRate, blbIchiVaultFeeRate, withdrawVaultFee, maxSlippageOfClose, and treasury. The `treasury_` argument is used to set the treasury address for the contract.

#### startVaultWithdrawFee

{% code overflow="wrap" %}

```solidity
function startVaultWithdrawFee() external onlyOwner
```

{% endcode %}

This function is called by the owner to start the timer for the vault withdraw fee window. It sets the `withdrawVaultFeeWindowStartTime` to the current block timestamp.

#### setDepositFee

{% code overflow="wrap" %}

```solidity
function setDepositFee(uint256 depositFee_) external onlyOwner
```

{% endcode %}

This function is called by the owner to set the deposit fee on isolated collateral provided when opening a leverage position. It sets the deposit fee to the specified `depositFee_` argument, which is capped at 20%.

#### setWithdrawFee

{% code overflow="wrap" %}

```solidity
function setWithdrawFee(uint256 withdrawFee_) external onlyOwner
```

{% endcode %}

This function is called by the owner to set the withdraw fee on isolated collateral provided when opening a leverage position. It sets the withdraw fee to the specified `withdrawFee_` argument, which is capped at 20%.

#### setWithdrawVaultFeeWindow

```solidity
function setWithdrawFeeWindow(uint256 withdrawVaultFeeWindow_) external onlyOwner
```

This function is called by the owner to set the withdraw fee window for vaults on collateral supplied to vaults. It sets the window to the specified `withdrawVaultFeeWindow_` argument, which is capped at 60 days.

#### setMaxSlippageOfClose

{% code overflow="wrap" %}

```solidity
function setMaxSlippageOfClose(uint256 slippage_) external onlyOwner 
```

{% endcode %}

This function is called by the owner to set the maximum slippage of converting withdrawn reserves to debt tokens when closing position. It sets the `maxSlippageOfClose` to the specified `slippage_` argument, which is capped at 20%.

#### setRewardFee

{% code overflow="wrap" %}

```solidity
function setRewardFee(uint256 rewardFee_) external onlyOwner 
```

{% endcode %}

This function is called by the owner to set the reward fee. This fee applies to any rewards that are earned through a leverage position. It sets the reward fee to the specified `rewardFee_` argument, which is capped at 20%.

#### setFeeDistribution  \*Not Used in this version yet\*

{% code overflow="wrap" %}

```solidity
setFeeDistribution(uint256 treasuryFeeRate_, uint256 blbStablePoolFeeRate_, uint256 blbIchiVaultFeeRate_) external onlyOwner
```

{% endcode %}

This function is called by the owner to set the fee distribution rates. It sets the `treasuryFeeRate`, `blbStablePoolFeeRate`, and `blbIchiVaultFeeRate` variables to the specified arguments, and checks that the sum of these values is equal to the `DENOMINATOR` constant defined in the `BlueBerryConst.sol` library.

#### setTreasuryWallet

{% code overflow="wrap" %}

```solidity
 function setTreasuryWallet(address treasury_) external onlyOwner
```

{% endcode %}

This function is called by the owner to set the treasury address for the contract. It sets the `treasury` variable to the specified `treasury_` argument.

#### setFeeManager

{% code overflow="wrap" %}

```solidity
function setFeeManager(address feeManager_) external onlyOwner 
```

{% endcode %}

This function is called by the owner to set the fee manager address for the contract. It sets the `feeManager` variable to the specified `feeManager_` argument.

#### setBlbUsdcIchiVault \*Not used in this version yet\*

{% code overflow="wrap" %}

```solidity
function setBlbUsdcIchiVault(address vault_) external onlyOwner
```

{% endcode %}

This function is called by the owner to set the $BLB liquidity pool against stablecoins address for the contract. It sets the `blbUsdcIchiVault` variable to the specified `vault_` argument.

#### setBlbStabilityPool \*Not used in this version yet\*

{% code overflow="wrap" %}

```solidity
function setBlbStabilityPool(address pool_) external onlyOwner
```

{% endcode %}

This function is called by the owner to set the $BLB liquidity pool against stablecoins address for the contract. It sets the `blbStabilityPool` variable to the specified `pool_` argument.
