# ETH0 DaoCollateral

## High-Level Overview

The DaoCollateral contract is a fundamental component of the ETH0 ecosystem, designed to manage the collateralization, minting, and redemption of ETH0 tokens. It ensures that the circulating supply of ETH0 is always fully backed by collateral, providing transparency and security for ETH0 holders. The contract facilitates the swapping of collateral tokens for ETH0, redemption of ETH0 for collateral tokens, and implements a Counter Bank Run (CBR) mechanism for emergency situations.

## Contract Summary

**Inherited Contracts**<br>

* ReentrancyGuardUpgradeable (OZ): Prevents reentrant attacks on sensitive functions.
* PausableUpgradeable (OZ): Enables pausing of contract functionality by authorized accounts.
* EIP712Upgradeable (OZ): Implements EIP-712 for structured data hashing and signing.

## Functionality Breakdown

**Key Functionalities**<br>

1. M**inting and redeeming ETH0:**\
   The contract manages the collateralization of ETH0 by handling collateral tokens. When a user sends collateral, the DaoCollateral contract mints the equivalent amount of ETH0 stablecoins, and vice versa, allowing users to exchange their ETH0 stablecoins for collateral at the current exchange rate.

* Swap: Facilitates the conversion of collateral into ETH0. Upon initiating this function, users exchange their collateral tokens for ETH0 stablecoins directly.
* Redeem: Allows users to redeem their ETH0 stablecoins for collateral against a fee. By invoking this function, users exchange their ETH0 stablecoins for collateral at the current exchange rate.

2. **Counter Bank Run (CBR) Mechanism:**\
   The contract implements a Counter Bank Run mechanism that can be activated in emergency situations. When activated:

* The CBR coefficient is applied to reduce the amount of collateral returned during redemptions
* Swap functionality is automatically paused
* The system helps maintain protocol stability during market stress

3. **Role-Based Access Control**

The contract implements a role-based access control system for sensitive operations:

* **DEFAULT\_ADMIN\_ROLE**: Has the highest level of access, including the ability to manage CBR parameters and perform critical administrative tasks.
* **DAO\_REDEMPTION\_ROLE**: Required for special DAO redemption operations.
* **PAUSING\_CONTRACTS\_ROLE**: Grants the ability to pause specific contract functionalities in case of emergencies.
* **UNPAUSING\_CONTRACTS\_ROLE**: Grants the ability to unpause contract functionalities.

### Functions Description

**Public/External Functions**<br>

* `initialize`: Sets up the contract with initial parameters including registry information and redeem fee.
* `swap`: Allows users to swap collateral tokens for ETH0.
* `swapWithPermit`: Similar to swap but uses permit for approval.
* `redeem`: Enables users to redeem ETH0 for collateral tokens.
* `redeemDao`: Special redemption function for DAO operations. Only callable by DAO\_REDEMPTION\_ROLE.
* `activateCBR`: Activates the Counter Bank Run mechanism. Only callable by DEFAULT\_ADMIN\_ROLE.
* `deactivateCBR`: Deactivates the Counter Bank Run mechanism. Only callable by DEFAULT\_ADMIN\_ROLE.
* `setRedeemFee`: Sets the fee for redemption operations. Only callable by DEFAULT\_ADMIN\_ROLE.
* `pauseRedeem`, `pause`, `pauseSwap`: Pausing functions for specific operations. Only callable by PAUSING\_CONTRACTS\_ROLE.
* `unpause`, `unpauseRedeem`, `unpauseSwap`: Global unpausing functions. Only callable by UNPAUSING\_CONTRACTS\_ROLE.

### **Constants**

* `CONTRACT_REGISTRY_ACCESS`: Address of the registry access contract.
* `CONTRACT_TOKEN_MAPPING`: Address of the token mapping contract.
* `CONTRACT_ORACLE`: Address of the oracle contract.
* `CONTRACT_TREASURY`: Address of the treasury contract.
* `CONTRACT_ETH0`: Address of the ETH0 token contract.
* `CONTRACT_YIELD_TREASURY`: Address of the yield treasury contract.
* `DEFAULT_ADMIN_ROLE`: Role identifier for the default admin.
* `DAO_REDEMPTION_ROLE`: Role identifier for DAO redemption operations.
* `PAUSING_CONTRACTS_ROLE`: Role identifier for pausing contract operations.
* `UNPAUSING_CONTRACTS_ROLE`: Role identifier for unpausing contract operations.
* `MAX_REDEEM_FEE`: Maximum allowed redemption fee (25%).
* `BASIS_POINT_BASE`: Base value for basis point calculations (10000).
* `SCALAR_ONE`: Scalar value representing 1 in the contract's decimal system.

### Key Components

* **Oracle Integration**: Uses an oracle to fetch real-time price data for collateral tokens.
* **Token Mapping**: Manages the mapping of supported collateral tokens.
* **Access Control**: Implements role-based access control for administrative functions.
* **Treasury Management**: Handles the storage and distribution of collateral tokens.

### Safeguards Implementation

* **Pausability**: Allows pausing of critical functions in emergencies.
* **Reentrancy Protection**: Uses OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks.
* **Access Control**: Restricts sensitive operations to authorized roles.
* **CBR Mechanism**: Implements a Counter Bank Run mechanism for emergency situations.
* **Fee Management**: Implements a configurable redemption fee system with a maximum cap of 25%.


---

# 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://tech.usual.money/smart-contracts/protocol-contracts/eth0/eth0-daocollateral.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.
