← Back to home

CircuitsDAO

TypeScriptJavaScript

Stablecoin infrastructure deployed as an appchain powered by Protokit.

Screenshots

CircuitsDAO screenshot 1
CircuitsDAO screenshot 2
CircuitsDAO screenshot 3

Problem Statement

Overview This project implements an overcollateralized stablecoin system called msUSD as an appchain using the Proto Kit framework. It's designed to maintain a stable value pegged to the US dollar, using MINA as collateral. The system incorporates various mechanisms to ensure stability, manage risk, and handle extreme market conditions.Key ComponentsStablecoin (msUSD): The primary asset, designed to maintain a 1:1 peg with the US dollar.Collateral (MINA): The backing asset used to mint msUSD.Stability Pool: A liquidity pool that helps stabilize the system during price fluctuations.CircuitsDAO: A governing entity responsible for key parameter updates.Emergency Fund: A reserve to handle extreme market conditions.Core FunctionalitiesMinting and Burning 1.1. Minting: Users can create new msUSD by providing MINA as collateral. The amount of collateral required is determined by the current collateral ratio and MINA/USD price. 1.2. Burning: Users can redeem their msUSD for MINA collateral, subject to a 15-day cooldown period after minting.Price Stability Mechanisms 2.1. Price Checks: The system regularly checks the msUSD price and can lock or unlock based on predefined thresholds. 2.2. Stability Pool Operations: 2.2.1. For low prices: Burns msUSD from the stability pool. 2.2.2. For high prices: Mints new msUSD into the stability pool. 2.3. Dynamic Reward Rates: Adjusts reward rates based on price deviations to incentivize stabilizing actions. 2.4. Emergency Fund Utilization: In extreme cases, uses reserved funds to stabilize the price.Liquidity Provision 3.1. Users can provide liquidity to the stability pool in the form of MINA or msUSD. 3.2. Liquidity providers can withdraw their contributions.Fee System 4.1. Fees are collected on minting, burning, and transfers. 4.2. Fees are distributed between a treasury and an emergency fund.Governance 5.1. The CircuitsDAO can update critical parameters like the collateral price and ratio.Advanced FeaturesDepeg Tolerance: 1.1. System locking mechanism for extreme price deviations. 1.2. Multi-tiered stabilization approach (stability pool, emergency funds). 1.3. Dynamic reward rates to incentivize corrective actions.Failsafes: 2.1. Emergency fund utilization in extreme scenarios. 2.2. System locking to prevent operations during high volatility.Scalability: 3.1. Uses UInt224 for large number handling, allowing for significant growth.MEV Protection: 4.1. Being an appchain, it's inherently protected from MEV (Miner Extractable Value) attacks.Verifiable State: 5.1. The entire state of the system is verifiable, enhancing transparency and trust.Potential Use CasesStable Asset for DeFi: msUSD could serve as a stable asset for various decentralized finance applications built on the MINA ecosystem.Trading Pair: It could be used as a stable trading pair against other cryptocurrencies.Store of Value: Users looking for stability within the Mina ecosystem could use msUSD.Cross-Border Transactions: As a stable asset, it could facilitate international transactions with reduced volatility risk.Limitations and ConsiderationsCentralization Risk: Reliance on CircuitsDAO for crucial updates introduces a degree of centralization.Collateral Volatility: The system's stability is tied to MINA's market performance.Complex Stabilization Mechanisms: The multi-layered approach, while robust, may be complex for average users to understand.Fixed Cooldown Period: The 15-day cooldown for burning might be restrictive in rapidly changing markets.No Partial Collateral Release: Users must burn all their msUSD to release collateral, which might be inconvenient.Conclusion The msUSD system represents a sophisticated approach to creating a stable asset in the cryptocurrency space. Its design incorporates multiple layers of stabilization mechanisms and failsafes, aiming to maintain peg stability even in volatile market conditions. While it offers robust features for stability and transparency, it also comes with inherent risks and complexities that users and developers should be aware of. As an appchain, it benefits from enhanced security and verifiability, potentially making it an attractive option for those seeking a stable asset within the MINA ecosystem.

Solution

Technical Implementation Overview : Implemented as a runtime module by Protokit.Technical Implementation Details of msUSD Stablecoin System1. Core Technology Stack1.1. Primary Framework: Proto KitProto Kit is a development framework specifically designed for building appchains with the positives of the Mina Protocol.It provides a robust set of tools and abstractions for state management, runtime modules, and zero-knowledge proof integration. 1.2. Blockchain Platform: Mina ProtocolMina is known for its succinct blockchain architecture, allowing for a constant-sized blockchain regardless of transaction volume.It uses zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Argument of Knowledge) for transaction verification. 1.3. Programming Language: TypeScriptThe project is implemented in TypeScript, providing strong typing and modern JavaScript features. 1.4. Smart Contract Language: o1jso1js is used for writing smart contracts that can be executed on the Mina blockchain.It allows for the creation of zero-knowledge circuits, crucial for the privacy and efficiency features of the Mina Protocol.2. Key Components and Their Implementation2.1. Runtime ModuleThe entire stablecoin system is encapsulated in a single runtime module calledmsUSD.This module is decorated with@runtimeModule(), a Proto Kit decorator that sets up the necessary infrastructure for the module to run on the appchain. 2.2. State ManagementProto Kit'sStateandStateMapare extensively used for managing the system's state.Examples includestableBalances,collateralBalances,stableSupply, etc.These state variables are decorated with@state(), allowing them to be part of the appchain's global state. 2.3. Runtime MethodsKey functionalities are implemented as runtime methods, decorated with@runtimeMethod().These methods includemint(),burn(),transfer(),stabilize(), etc.They define the core logic of the stablecoin system and can be called as transactions on the appchain. 2.4. Mathematical OperationsThe system usesUInt224for handling large numbers with high precision.Complex mathematical operations are implemented with careful consideration of potential overflow and underflow scenarios. 2.5. Zero-Knowledge ProofsWhile not explicitly shown in the code snippet, the use of o1js implies that certain operations can be proved using zk-SNARKs.This is particularly important for maintaining the privacy and efficiency guarantees of the Mina Protocol.3. Integration with Proto Kit3.1. State AbstractionsProto Kit's state abstractions (StateandStateMap) are used to manage the appchain's state in a way that's compatible with Mina's zk-SNARK architecture. 3.2. Runtime Module StructureThe@runtimeModule()decorator from Proto Kit is used to define themsUSDclass as a runtime module.This structure allows the module to be easily integrated into the appchain ecosystem. 3.3. Transaction HandlingProto Kit's transaction handling is leveraged in methods likemint()andburn(), wherethis.transaction.sender.valueis used to identify the transaction sender. 3.4. Block Height AccessThe appchain's block height is accessed usingthis.network.block.height, a feature provided by Proto Kit's runtime environment.4. Notable Implementation Details4.1. Dynamic Stabilization MechanismThestabilize()method implements a multi-tiered approach to maintain the stablecoin's peg.It dynamically adjusts the supply based on the current price, using both the stability pool and emergency funds when necessary. 4.2. Provable Conditional LogicThe use ofProvable.if()in methods likestabilizeLowPrice()andstabilizeHighPrice()allows for conditional logic that can be efficiently proved in zero-knowledge circuits. 4.3. Fee Distribution SystemThedistributeFee()method implements a sophisticated fee distribution system, allocating fees between a treasury and an emergency fund. 4.4. Precision HandlingThroughout the code, operations involving division are carefully managed to minimize precision loss, often scaling values by 1e18 before division.5. Challenges and Solutions5.1. Large Number HandlingChallenge: Dealing with large numbers in financial calculations.Solution: Use ofUInt224type, allowing for a wide range of values while maintaining precision. 5.2. State Updates in Zero-Knowledge SettingChallenge: Updating state in a way that's compatible with zk-SNARKs.Solution: Leveraging Proto Kit's state management tools, which are designed to work within Mina's zero-knowledge architecture. 5.3. Complex Financial Logic in Smart ContractsChallenge: Implementing sophisticated financial mechanisms within the constraints of blockchain and zero-knowledge proofs.Solution: Careful design of the stabilization and fee distribution systems, broken down into provable operations.6. Unique Aspects and "Hacky" Solutions6.1. Price Oracle SimulationIn a production environment, an external price oracle would typically be used. Here, the price is updated manually via theupdateCollateralPrice()method, simulating an oracle for the proof of concept. 6.2. Emergency Fund MechanismThe implementation of an emergency fund that can be automatically utilized in extreme market conditions is a novel approach to maintaining stability. 6.3. Dynamic Reward Rate CalculationThe system dynamically adjusts reward rates based on price deviations, incentivizing stabilizing actions in a nuanced way.ConclusionThe msUSD stablecoin system leverages the unique features of the Mina Protocol and Proto Kit to create a sophisticated financial instrument. By utilizing zero-knowledge proofs, it aims to provide a stable asset with enhanced privacy and efficiency. The implementation demonstrates a careful balance between complex financial logic and the constraints of blockchain technology, particularly in a zero-knowledge setting.

Hackathon

ETHOnline 2024

2024

Prizes

  • 🏆

    Best Mina application or library built using Protokit3rd place

    Mina Protocol

Contributors