# 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;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sperax.io/master/technical-documents/smart-contracts/fee-calculator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
