project screenshot 1
project screenshot 2
project screenshot 3

CircuitsDAO

Stablecoin infrastructure deployed as an appchain powered by Protokit.

CircuitsDAO

Created At

ETHOnline 2024

Winner of

Mina Protocol - Best Mina application or library built using Protokit 3rd place

Project Description

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 Components

  1. Stablecoin (msUSD): The primary asset, designed to maintain a 1:1 peg with the US dollar.
  2. Collateral (MINA): The backing asset used to mint msUSD.
  3. Stability Pool: A liquidity pool that helps stabilize the system during price fluctuations.
  4. CircuitsDAO: A governing entity responsible for key parameter updates.
  5. Emergency Fund: A reserve to handle extreme market conditions.

Core Functionalities

  1. Minting 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.

  2. 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.

  3. 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.

  4. Fee System 4.1. Fees are collected on minting, burning, and transfers. 4.2. Fees are distributed between a treasury and an emergency fund.

  5. Governance 5.1. The CircuitsDAO can update critical parameters like the collateral price and ratio.

Advanced Features

  1. Depeg 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.

  2. Failsafes: 2.1. Emergency fund utilization in extreme scenarios. 2.2. System locking to prevent operations during high volatility.

  3. Scalability: 3.1. Uses UInt224 for large number handling, allowing for significant growth.

  4. MEV Protection: 4.1. Being an appchain, it's inherently protected from MEV (Miner Extractable Value) attacks.

  5. Verifiable State: 5.1. The entire state of the system is verifiable, enhancing transparency and trust.

Potential Use Cases

  1. Stable Asset for DeFi: msUSD could serve as a stable asset for various decentralized finance applications built on the MINA ecosystem.
  2. Trading Pair: It could be used as a stable trading pair against other cryptocurrencies.
  3. Store of Value: Users looking for stability within the Mina ecosystem could use msUSD.
  4. Cross-Border Transactions: As a stable asset, it could facilitate international transactions with reduced volatility risk.

Limitations and Considerations

  1. Centralization Risk: Reliance on CircuitsDAO for crucial updates introduces a degree of centralization.
  2. Collateral Volatility: The system's stability is tied to MINA's market performance.
  3. Complex Stabilization Mechanisms: The multi-layered approach, while robust, may be complex for average users to understand.
  4. Fixed Cooldown Period: The 15-day cooldown for burning might be restrictive in rapidly changing markets.
  5. 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.

How it's Made

Technical Implementation Overview : Implemented as a runtime module by Protokit.

Technical Implementation Details of msUSD Stablecoin System

1. Core Technology Stack

1.1. Primary Framework: Proto Kit

  • Proto 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 Protocol
  • Mina 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: TypeScript
  • The project is implemented in TypeScript, providing strong typing and modern JavaScript features. 1.4. Smart Contract Language: o1js
  • o1js 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 Implementation

2.1. Runtime Module

  • The entire stablecoin system is encapsulated in a single runtime module called msUSD.
  • 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 Management
  • Proto Kit's State and StateMap are extensively used for managing the system's state.
  • Examples include stableBalances, collateralBalances, stableSupply, etc.
  • These state variables are decorated with @state(), allowing them to be part of the appchain's global state. 2.3. Runtime Methods
  • Key functionalities are implemented as runtime methods, decorated with @runtimeMethod().
  • These methods include mint(), 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 Operations
  • The system uses UInt224 for handling large numbers with high precision.
  • Complex mathematical operations are implemented with careful consideration of potential overflow and underflow scenarios. 2.5. Zero-Knowledge Proofs
  • While 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 Kit

3.1. State Abstractions

  • Proto Kit's state abstractions (State and StateMap) are used to manage the appchain's state in a way that's compatible with Mina's zk-SNARK architecture. 3.2. Runtime Module Structure
  • The @runtimeModule() decorator from Proto Kit is used to define the msUSD class as a runtime module.
  • This structure allows the module to be easily integrated into the appchain ecosystem. 3.3. Transaction Handling
  • Proto Kit's transaction handling is leveraged in methods like mint() and burn(), where this.transaction.sender.value is used to identify the transaction sender. 3.4. Block Height Access
  • The appchain's block height is accessed using this.network.block.height, a feature provided by Proto Kit's runtime environment.

4. Notable Implementation Details

4.1. Dynamic Stabilization Mechanism

  • The stabilize() 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 Logic
  • The use of Provable.if() in methods like stabilizeLowPrice() and stabilizeHighPrice() allows for conditional logic that can be efficiently proved in zero-knowledge circuits. 4.3. Fee Distribution System
  • The distributeFee() method implements a sophisticated fee distribution system, allocating fees between a treasury and an emergency fund. 4.4. Precision Handling
  • Throughout the code, operations involving division are carefully managed to minimize precision loss, often scaling values by 1e18 before division.

5. Challenges and Solutions

5.1. Large Number Handling

  • Challenge: Dealing with large numbers in financial calculations.
  • Solution: Use of UInt224 type, allowing for a wide range of values while maintaining precision. 5.2. State Updates in Zero-Knowledge Setting
  • Challenge: 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 Contracts
  • Challenge: 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" Solutions

6.1. Price Oracle Simulation

  • In a production environment, an external price oracle would typically be used. Here, the price is updated manually via the updateCollateralPrice() method, simulating an oracle for the proof of concept. 6.2. Emergency Fund Mechanism
  • The 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 Calculation
  • The system dynamically adjusts reward rates based on price deviations, incentivizing stabilizing actions in a nuanced way.

Conclusion

The 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.

background image mobile

Join the mailing list

Get the latest news and updates