
CitreaFi: A Decentralized Financial Ecosystem
Empowering Decentralized Finance with Seamless Bitcoin Interoperability.
About
The problem it solves ### The Problem It Solves **1. Limited Bitcoin Interoperability:** Bitcoin lacks smart contract support, restricting its DeFi utility. CitreaFi bridges Bitcoin seamlessly into the Citrea blockchain using a light Bitcoin client, enabling its use in decentralized finance. **2. Fragmented and Inefficient DeFi Access:** Users face high costs and complexity across multiple platforms. CitreaFi offers a unified solution for trading, lending, payments, and governance, simplifying DeFi access. **3. Risky Asset Valuation:** DeFi protocols relying on single oracles are prone to manipulation. CitreaFi uses aggregated oracles for transparent and reliable pricing. **4. Untapped Bitcoin Liquidity:** Bitcoin’s vast liquidity remains underutilized in DeFi. CitreaFi tokenizes Bitcoin as `cBTC`, unlocking its potential for lending, trading, and collateralization. --- ### Use Cases 1. **Bitcoin Bridging:** - Seamlessly convert Bitcoin to `cBTC` for DeFi use. 2. **Decentralized Trading:** - Swap assets (`cBTC` ↔ `cUSD`) on the AMM DEX. 3. **Collateralized Lending:** - Borrow stablecoins (`cUSD`) using `cBTC` as collateral. 4. **Payments in cUSD or cBTC:** - Facilitate direct payments using stablecoins or Bitcoin-backed tokens with secure, on-chain settlement. 5. **On-Chain Governance:** - Vote on protocol changes using `cGOV` tokens. 6. **Market Risk Management:** - Ensure price stability with robust insurance and oracle systems. --- ### How CitreaFi Makes DeFi Better - **Streamlined Access:** Combines trading, lending, payments, and governance in one platform. - **Enhanced Security:** Light Bitcoin client and aggregated oracles reduce risks. - **Transparent Governance:** Users shape protocol changes through on-chain voting. - **Unlocks Bitcoin Utility:** Enables Bitcoin holders to engage in DeFi without intermediaries. - **Efficient Payments:** Simplifies payments and settlements with stablecoin and Bitcoin-backed tokens.
How it's made
Challenges we ran into ### Challenges I Ran Into **1. Handling Oracle Aggregation for Reliable Pricing:** Relying on a single oracle introduces risks like manipulation or downtime. Aggregating multiple oracles was a challenge due to varying response formats and delays in fetching real-time prices. **Solution:** The `AggregatorOracle` was designed to collect prices from multiple sources and compute the median value. A simple bubble sort was used for demonstration purposes but can be replaced with optimized sorting algorithms for production use. --- **2. Ensuring Stable Collateral Management:** Managing collateral ratios dynamically in `StableCoin.sol` was tricky, especially under volatile market conditions. Incorrect liquidation penalties or delays in price updates could destabilize the system. **Solution:** We implemented `CollateralManager` to centralize collateral settings, pulling data from the `AggregatorOracle` for accurate pricing. Liquidation logic was fine-tuned with rigorous testing to handle edge cases. --- **3. Payment Integration with Diverse Use Cases:** Building a generic `PaymentGateway` that supports both `cBTC` and `cUSD` required careful handling of token conversions and ensuring compatibility with external payment flows. **Solution:** The `PaymentGateway` was built with modularity in mind, supporting token swaps through the DEX and enabling payments directly from the user's wallet. Flexibility for future integrations with payment systems was retained. --- **4. Testing Across Multiple Contracts:** Coordinating interactions between `AMMDEX`, `StableCoin`, `PriceOracle`, and governance contracts required comprehensive integration tests to simulate real-world usage. **Solution:** Using Hardhat, we created deployment scripts and wrote test cases to verify interactions across contracts, ensuring seamless functionality. Incremental testing allowed us to identify and resolve issues early in the development cycle.