A decentralized stablecoin system implemented in Clarity that enables users to mint stablecoins using Bitcoin as collateral. The system maintains stability through overcollateralization and includes robust mechanisms for liquidation, debt management, and price oracle updates.
- Bitcoin collateralization with 150% minimum collateral ratio
- Automated liquidation system with 120% threshold
- Price oracle integration with freshness checks
- Collateral deposit and withdrawal mechanisms
- Stablecoin minting and burning
- Position management and health checks
- Comprehensive liquidation history tracking
- Minimum Collateralization Ratio: 150%
- Liquidation Threshold: 120%
- Minimum Deposit: 1,000,000 satoshis
- Price Validity Period: 144 blocks (~1 day)
Allows users to deposit Bitcoin as collateral.
- Requires amount to meet minimum deposit threshold
- Updates user's position with new collateral amount
Enables users to mint stablecoins against their deposited collateral.
- Checks price oracle freshness
- Ensures sufficient collateralization ratio
- Updates total supply and user's debt position
Allows users to repay their stablecoin debt.
- Verifies user has sufficient debt to repay
- Updates total supply and user's position
- Burns the repaid stablecoins
Enables users to withdraw their excess collateral.
- Verifies sufficient collateral exists
- Ensures withdrawal maintains minimum collateralization ratio
- Updates user's position
Restricted to price oracle for updating the Bitcoin price.
- Updates current price
- Records last update timestamp
Restricted to contract owner for updating the price oracle address.
- Updates price oracle principal
Returns user's current position including:
- Collateral amount
- Debt amount
- Last update timestamp
Calculates current collateralization ratio for a user's position.
Returns the current Bitcoin price from the oracle.
ERR-NOT-AUTHORIZED (1000)
: Caller lacks required permissionsERR-INSUFFICIENT-COLLATERAL (1001)
: Collateral ratio below minimumERR-BELOW-MINIMUM (1002)
: Deposit below minimum thresholdERR-INVALID-AMOUNT (1003)
: Invalid transaction amountERR-POSITION-NOT-FOUND (1004)
: User position doesn't existERR-ALREADY-LIQUIDATED (1005)
: Position already liquidatedERR-HEALTHY-POSITION (1006)
: Position health above liquidation thresholdERR-PRICE-EXPIRED (1007)
: Price oracle data too old
-
Price Oracle
- Price updates are time-bounded
- Only authorized oracle can update prices
- Price freshness checks prevent stale data usage
-
Collateralization
- Strict minimum collateral requirements
- Automated health checks on all position modifications
- Conservative liquidation threshold
-
Access Control
- Administrative functions restricted to authorized principals
- Clear separation between user and admin capabilities
- Built using Clarity smart contract language
- Maintains state using maps and data variables
- Implements proper error handling and validation
- Uses block height for temporal mechanics
- Deploy the contract to a Stacks blockchain
- Set up the initial price oracle
- Users can begin depositing Bitcoin as collateral
- Monitor position health and maintain proper collateralization
To work with this contract:
- Set up a Clarity development environment
- Deploy to testnet for initial testing
- Verify all error conditions and edge cases
- Test liquidation mechanisms with various price scenarios
- Validate oracle integration and price update mechanisms
- Maintain healthy collateralization ratios above 150%
- Monitor Bitcoin price movements
- Act quickly if positions approach liquidation threshold
- Understand liquidation mechanisms and risks
- Contract owner can update price oracle
- System parameters are defined as constants
- Any upgrades require new contract deployment