> For the complete documentation index, see [llms.txt](https://docs.sperax.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sperax.io/master/technical-documents/smart-contracts/collateralmanager.md).

# CollateralManager

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

**Inherits:** ICollateralManager, Ownable

**Author:** Sperax Foundation

This contract manages the addition and removal of collateral, configuration of collateral strategies, and allocation percentages.

*Collateral Manager interacts with the Vault and various strategies for collateral management.*

## **State Variables**

### **collateralCompositionUsed**

```solidity
uint16 public collateralCompositionUsed;

```

### **VAULT**

```solidity
address public immutable VAULT;

```

### **collaterals**

```solidity
address[] private collaterals;

```

### **collateralInfo**

```solidity
mapping(address => CollateralData) public collateralInfo;

```

### **collateralStrategyInfo**

```solidity
mapping(address => mapping(address => StrategyData)) private collateralStrategyInfo;

```

### **collateralStrategies**

```solidity
mapping(address => address[]) private collateralStrategies;

```

## **Functions**

### **constructor**

*Constructor to initialize the Collateral Manager*

```solidity
constructor(address _vault);

```

**Parameters**

| Name    | Type    | Description                   |
| ------- | ------- | ----------------------------- |
| \_vault | address | Address of the Vault contract |

### **addCollateral**

Register a collateral for mint & redeem in USDs

```solidity
function addCollateral(address _collateral, CollateralBaseData memory _data) external onlyOwner;

```

**Parameters**

| Name         | Type               | Description                   |
| ------------ | ------------------ | ----------------------------- |
| \_collateral | address            | Address of the collateral     |
| \_data       | CollateralBaseData | Collateral configuration data |

### **updateCollateralData**

Update existing collateral configuration

```solidity
function updateCollateralData(address _collateral, CollateralBaseData memory _updateData) external onlyOwner;

```

**Parameters**

| Name         | Type               | Description                              |
| ------------ | ------------------ | ---------------------------------------- |
| \_collateral | address            | Address of the collateral                |
| \_updateData | CollateralBaseData | Updated configuration for the collateral |

### **removeCollateral**

Un-list a collateral

```solidity
function removeCollateral(address _collateral) external onlyOwner;

```

**Parameters**

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

### **addCollateralStrategy**

Add a new strategy to collateral

```solidity
function addCollateralStrategy(address _collateral, address _strategy, uint16 _allocationCap) external onlyOwner;

```

**Parameters**

| Name            | Type    | Description               |
| --------------- | ------- | ------------------------- |
| \_collateral    | address | Address of the collateral |
| \_strategy      | address | Address of the strategy   |
| \_allocationCap | uint16  | Allocation capacity       |

### **updateCollateralStrategy**

Update existing strategy for collateral

```solidity
function updateCollateralStrategy(address _collateral, address _strategy, uint16 _allocationCap) external onlyOwner;

```

**Parameters**

| Name            | Type    | Description               |
| --------------- | ------- | ------------------------- |
| \_collateral    | address | Address of the collateral |
| \_strategy      | address | Address of the strategy   |
| \_allocationCap | uint16  | Allocation capacity       |

### **removeCollateralStrategy**

Remove an existing strategy from collateral

*Ensure all the collateral is removed from the strategy before calling this Otherwise it will create error in collateral accounting*

```solidity
function removeCollateralStrategy(address _collateral, address _strategy) external onlyOwner;

```

**Parameters**

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

### **updateCollateralDefaultStrategy**

```solidity
function updateCollateralDefaultStrategy(address _collateral, address _strategy) external onlyOwner;

```

### **validateAllocation**

Validate allocation for a collateral

```solidity
function validateAllocation(address _collateral, address _strategy, uint256 _amount) external view returns (bool);

```

**Parameters**

| Name         | Type    | Description                     |
| ------------ | ------- | ------------------------------- |
| \_collateral | address | Address of the collateral       |
| \_strategy   | address | Address of the desired strategy |
| \_amount     | uint256 | Amount to be allocated.         |

**Returns**

| Name | Type | Description                        |
| ---- | ---- | ---------------------------------- |
|      | bool | True for valid allocation request. |

### **getFeeCalibrationData**

Get the required data for mint

```solidity
function getFeeCalibrationData(address _collateral) external view returns (uint16, uint16, uint16, uint256);

```

**Parameters**

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

**Returns**

| Name | Type    | Description                                                                               |
| ---- | ------- | ----------------------------------------------------------------------------------------- |
|      | uint16  | Base fee config for collateral (baseMintFee, baseRedeemFee, composition, totalCollateral) |
|      | uint16  |                                                                                           |
|      | uint16  |                                                                                           |
|      | uint256 |                                                                                           |

### **getMintParams**

Get the required data for mint

```solidity
function getMintParams(address _collateral) external view returns (CollateralMintData memory mintData);

```

**Parameters**

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

**Returns**

| Name     | Type               | Description |
| -------- | ------------------ | ----------- |
| mintData | CollateralMintData | mintData    |

### **getRedeemParams**

Get the required data for USDs redemption

```solidity
function getRedeemParams(address _collateral) external view returns (CollateralRedeemData memory redeemData);

```

**Parameters**

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

**Returns**

| Name       | Type                 | Description |
| ---------- | -------------------- | ----------- |
| redeemData | CollateralRedeemData | redeemData  |

### **getAllCollaterals**

Gets a list of all listed collaterals

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

```

**Returns**

| Name | Type       | Description                                           |
| ---- | ---------- | ----------------------------------------------------- |
|      | address\[] | List of addresses representing all listed collaterals |

### **getCollateralStrategies**

Gets a list of all strategies linked to a collateral

```solidity
function getCollateralStrategies(address _collateral) external view returns (address[] memory);

```

**Parameters**

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

**Returns**

| Name | Type       | Description                                                            |
| ---- | ---------- | ---------------------------------------------------------------------- |
|      | address\[] | List of addresses representing available strategies for the collateral |

### **isValidStrategy**

Verifies if a strategy is linked to a collateral

```solidity
function isValidStrategy(address _collateral, address _strategy) external view returns (bool);

```

**Parameters**

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

**Returns**

| Name | Type | Description                                                       |
| ---- | ---- | ----------------------------------------------------------------- |
|      | bool | True if the strategy is linked to the collateral, otherwise False |

### **getCollateralInStrategies**

Get the amount of collateral in all Strategies

```solidity
function getCollateralInStrategies(address _collateral) public view returns (uint256 amountInStrategies);

```

**Parameters**

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

**Returns**

| Name               | Type    | Description        |
| ------------------ | ------- | ------------------ |
| amountInStrategies | uint256 | amountInStrategies |

### **getCollateralInVault**

Get the amount of collateral in vault

```solidity
function getCollateralInVault(address _collateral) public view returns (uint256 amountInVault);

```

**Parameters**

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

**Returns**

| Name          | Type    | Description   |
| ------------- | ------- | ------------- |
| amountInVault | uint256 | amountInVault |

### **getCollateralInAStrategy**

Get the amount of collateral allocated in a strategy

```solidity
function getCollateralInAStrategy(address _collateral, address _strategy) public view returns (uint256 allocatedAmt);

```

**Parameters**

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

**Returns**

| Name         | Type    | Description      |
| ------------ | ------- | ---------------- |
| allocatedAmt | uint256 | Allocated amount |

## **Events**

### **CollateralAdded**

```solidity
event CollateralAdded(address collateral, CollateralBaseData data);

```

### **CollateralRemoved**

```solidity
event CollateralRemoved(address collateral);

```

### **CollateralInfoUpdated**

```solidity
event CollateralInfoUpdated(address collateral, CollateralBaseData data);

```

### **CollateralStrategyAdded**

```solidity
event CollateralStrategyAdded(address collateral, address strategy);

```

### **CollateralStrategyUpdated**

```solidity
event CollateralStrategyUpdated(address collateral, address strategy);

```

### **CollateralStrategyRemoved**

```solidity
event CollateralStrategyRemoved(address collateral, address strategy);

```

## **Errors**

### **CollateralExists**

```solidity
error CollateralExists();

```

### **CollateralDoesNotExist**

```solidity
error CollateralDoesNotExist();

```

### **CollateralStrategyExists**

```solidity
error CollateralStrategyExists();

```

### **CollateralStrategyMapped**

```solidity
error CollateralStrategyMapped();

```

### **CollateralStrategyNotMapped**

```solidity
error CollateralStrategyNotMapped();

```

### **CollateralNotSupportedByStrategy**

```solidity
error CollateralNotSupportedByStrategy();

```

### **CollateralAllocationPaused**

```solidity
error CollateralAllocationPaused();

```

### **CollateralStrategyInUse**

```solidity
error CollateralStrategyInUse();

```

### **AllocationPercentageLowerThanAllocatedAmt**

```solidity
error AllocationPercentageLowerThanAllocatedAmt();

```

### **IsDefaultStrategy**

```solidity
error IsDefaultStrategy();

```

## **Structs**

### **CollateralData**

```solidity
struct CollateralData {
    bool mintAllowed;
    bool redeemAllowed;
    bool allocationAllowed;
    bool exists;
    address defaultStrategy;
    uint16 baseMintFee;
    uint16 baseRedeemFee;
    uint16 downsidePeg;
    uint16 desiredCollateralComposition;
    uint16 collateralCapacityUsed;
    uint256 conversionFactor;
}

```

### **StrategyData**

```solidity
struct StrategyData {
    uint16 allocationCap;
    bool exists;
}
```
