# Fee Calculator

[Git Source](https://github.com/Sperax/USDs-v2/blob/ff71faf9d7e40d2b2764e5e8f2acc631f31489aa/contracts/vault/FeeCalculator.sol)

**Inherits:** IFeeCalculator

**Author:** Sperax Foundation

*A contract that calculates fees for minting and redeeming USDs.*

## **State Variables**

### **LOWER\_THRESHOLD**

```solidity
uint16 private constant LOWER_THRESHOLD = 5000;

```

### **UPPER\_THRESHOLD**

```solidity
uint16 private constant UPPER_THRESHOLD = 15000;

```

### **DISCOUNT\_FACTOR**

```solidity
uint16 private constant DISCOUNT_FACTOR = 2;

```

### **PENALTY\_MULTIPLIER**

```solidity
uint16 private constant PENALTY_MULTIPLIER = 2;

```

### **CALIBRATION\_GAP**

```solidity
uint32 private constant CALIBRATION_GAP = 1 days;

```

### **COLLATERAL\_MANAGER**

```solidity
ICollateralManager public immutable COLLATERAL_MANAGER;

```

### **collateralFee**

```solidity
mapping(address => FeeData) public collateralFee;

```

## **Functions**

### **constructor**

```solidity
constructor(address _collateralManager);

```

### **calibrateFee**

Calibrates fee for a particular collateral

```solidity
function calibrateFee(address _collateral) external;

```

**Parameters**

| Name         | Type    | Description                       |
| ------------ | ------- | --------------------------------- |
| \_collateral | address | Address of the desired collateral |

### **getMintFee**

Calculates fee to be collected for minting

```solidity
function getMintFee(address _collateral) external view returns (uint256);

```

**Parameters**

| Name         | Type    | Description |
| ------------ | ------- | ----------- |
| \_collateral | address |             |

**Returns**

| Name | Type    | Description         |
| ---- | ------- | ------------------- |
|      | uint256 | (uint256) baseFeeIn |

### **getRedeemFee**

Calculates fee to be collected for redeeming

```solidity
function getRedeemFee(address _collateral) external view returns (uint256);

```

**Parameters**

| Name         | Type    | Description |
| ------------ | ------- | ----------- |
| \_collateral | address |             |

**Returns**

| Name | Type    | Description          |
| ---- | ------- | -------------------- |
|      | uint256 | (uint256) baseFeeOut |

### **calibrateFeeForAll**

Calibrates fee for all the collaterals registered

```solidity
function calibrateFeeForAll() public;

```

### **\_calibrateFee**

Helper function for calibrating fee for a collateral

```solidity
function _calibrateFee(address _collateral) private;

```

**Parameters**

| Name         | Type    | Description                       |
| ------------ | ------- | --------------------------------- |
| \_collateral | address | Address of the desired collateral |

## **Events**

### **FeeCalibrated**

```solidity
event FeeCalibrated(address indexed collateral, uint16 mintFee, uint16 redeemFee);

```

## **Errors**

### **InvalidCalibration**

```solidity
error InvalidCalibration();

```

## **Structs**

### **FeeData**

```solidity
struct FeeData {
    uint32 nextUpdate;
    uint16 mintFee;
    uint16 redeemFee;
}
```
