USD0a DaoCollateral
High-Level Overview
The DaoCollateral contract is a crucial component of the USD0a ecosystem, designed to manage the collateralization, minting, and redemption of USD0a tokens. USD0a is a yield-bearing token that represents a proportional share of the total value of underlying collateral assets. The contract facilitates the swapping of collateral tokens (such as USCC, USTB, and USDC) for USD0a, redemption of USD0a for collateral tokens, and implements a Counter Bank Run (CBR) mechanism to protect the protocol during extreme market conditions.
Contract Summary
Inherited Contracts
ReentrancyGuardUpgradeable (OZ): Prevents reentrant attacks on sensitive functions.
PausableUpgradeable (OZ): Enables pausing of contract functionality by authorized accounts.
Functionality Breakdown
Key Functionalities
1. Minting and redeeming USD0a:
At its core, the contract accrues collaterals by routing trades accordingly. When a user sends collateral tokens, the daoCollateral contract mints the equivalent amount of USD0a tokens, and vice versa, allowing users to exchange their USD0a tokens for collaterals at the current exchange rate.
Swap: Facilitates the conversion of collateral tokens (such as USCC, USTB, and USDC) into USD0a tokens. Upon initiating this function, users exchange their collateral tokens for USD0a tokens directly. The amount of USD0a minted is calculated based on the current USD0a price in USD, which accounts for yield accumulation. Since USD0a is yield-bearing, its price increases over time depending on the collaterals price.
Redeem: Allows users to redeem their USD0a tokens against a fee. By invoking this function, users exchange their USD0a tokens for collateral tokens at the current exchange rate. The redemption fee is deducted from the amount and, when CBR is not active, is minted to the yield treasury to improve the collateralization ratio.
2. Counter Bank Run (CBR) Mechanism:
The Counter Bank Run mechanism is a protective feature that can be activated during extreme market conditions. When activated:
Swap functionality is automatically paused
Redemptions continue but at a reduced rate (determined by the CBR coefficient)
Redemption fees are burned instead of being sent to the yield treasury, helping to maintain the protocol's solvency
The CBR coefficient (between 0 and 1) determines the discount applied to redemptions
3. Role-Based Access Control
The contract implements a role-based access control system for sensitive operations:
CBR_OPERATOR_ROLE: Required to activate or deactivate the Counter Bank Run mechanism.
REDEEM_FEE_OPERATOR_ROLE: Allows setting of the redemption fee, which is crucial for managing protocol economics.
MIN_REDEEM_AMOUNT_SETTER_ROLE: Allows setting of the minimum redeem amount in USD0a, preventing dust redemptions.
DAO_REDEMPTION_ROLE: Grants the ability to perform fee-free redemptions for DAO 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.
These roles ensure that different levels of access are properly managed and that sensitive operations are restricted to authorized entities, enhancing the overall security and governance of the contract.
Functions Description
Public/External Functions
initialize: Sets up the contract with initial parameters including the registry contract and initial redeem fee.
swap: Allows users to swap collateral tokens for USD0a. The function calculates the USD value of the collateral tokens, determines the equivalent USD0a amount based on the current USD0a price, and mints USD0a to the user.
swapWithPermit: Similar to swap but uses permit for approval, enabling gasless approvals for supported tokens.
redeem: Enables users to redeem USD0a for collateral tokens. A redemption fee is deducted, and the net amount is used to calculate the collateral tokens returned. The fee is minted to the yield treasury (unless CBR is active).
redeemDao: Special redemption function for DAO operations that bypasses the redemption fee. Only callable by DAO_REDEMPTION_ROLE.
activateCBR: Activates the Counter Bank Run mechanism with a specified coefficient. Automatically pauses swap functionality. Only callable by CBR_OPERATOR_ROLE.
deactivateCBR: Deactivates the Counter Bank Run mechanism. Only callable by CBR_OPERATOR_ROLE.
setRedeemFee: Sets the fee for redemption operations (in basis points). Only callable by REDEEM_FEE_OPERATOR_ROLE.
setMinRedeemAmountInUSD0X: Sets the minimum amount of USD0a that can be redeemed. Only callable by MIN_REDEEM_AMOUNT_SETTER_ROLE.
pauseRedeem, pauseSwap, pause: Pausing functions for specific operations or the entire contract. Only callable by PAUSING_CONTRACTS_ROLE.
unpause, unpauseRedeem, unpauseSwap: Global unpausing functions. Only callable by UNPAUSING_CONTRACTS_ROLE.
Getter Functions
isCBROn: Returns whether the Counter Bank Run mechanism is currently active.
cbrCoef: Returns the current CBR coefficient.
redeemFee: Returns the current redemption fee in basis points.
minRedeemAmountInUSD0X: Returns the minimum amount of USD0a that can be redeemed.
isRedeemPaused: Returns whether redeem functionality is paused.
isSwapPaused: Returns whether swap functionality is paused.
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 holding collateral tokens.
CONTRACT_YIELD_TREASURY: Address of the treasury contract holding fee tokens.
CONTRACT_USD0X: Address of the USD0a token contract.
CBR_OPERATOR_ROLE: Role identifier for CBR operations.
REDEEM_FEE_OPERATOR_ROLE: Role identifier for setting redemption fees.
MIN_REDEEM_AMOUNT_SETTER_ROLE: Role identifier for setting minimum redeem amounts.
DAO_REDEMPTION_ROLE: Role identifier for DAO redemptions.
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 (2500 basis points = 25%).
SCALAR_ONE: Scalar value representing 1 in the contract's decimal system (1e18).
Key Components
Oracle Integration: Uses an oracle to fetch real-time price data for collateral tokens and USD0a.
Token Mapping: Manages the mapping of supported collateral tokens through the TokenMapping contract.
Access Control: Implements role-based access control for administrative functions through the RegistryAccess contract.
USD0a Price Integration: Interacts with the USD0a token contract to get the current USD0a price in USD, which accounts for yield accumulation and determines the exchange rate for swaps and redemptions.
Safeguards Implementation
Pausability: Allows pausing of critical functions (swap, redeem, or entire contract) in emergencies.
Reentrancy Protection: Uses OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks.
Access Control: Restricts sensitive operations to authorized roles.
Counter Bank Run (CBR): Provides a mechanism to protect the protocol during extreme market conditions by reducing redemption rates and pausing swaps.
Minimum Redeem Amount: Prevents dust redemptions that could be economically inefficient.
Price Validation: Ensures prices are non-zero before executing swaps or redemptions.
Amount Validation: Validates that amounts are non-zero, within acceptable ranges, and meet minimum thresholds.
Last updated
Was this helpful?