-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Bitcoin-Pegged Stablecoin Smart Contract #1
Open
gbebo-del
wants to merge
14
commits into
main
Choose a base branch
from
feature/add-smart-contract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…contract - Added `CONTRACT-OWNER` constant to represent the contract owner. - Added `PRECISION` constant to define 6 decimal places of precision. - Defined error constants for various error scenarios: - `ERR-UNAUTHORIZED` for unauthorized actions. - `ERR-INSUFFICIENT-RESERVES` for insufficient reserves. - `ERR-INVALID-AMOUNT` for invalid amounts. - `ERR-PRICE-DEVIATION` for price deviation errors. - `ERR-MINT-FAILED` for minting failures. - `ERR-BURN-FAILED` for burning failures.
- Implemented `get-btc-price` read-only function to return a simulated BTC price of $50,000.
- Added `btc-stable-coin` fungible token definition. - Initialized `total-reserves` data variable to track reserves. - Set `collateralization-ratio` data variable to 100% for over-collateralization.
- Added `mint-stablecoin` public function to mint new stablecoins. - Validates mint parameters and updates reserves. - Mints tokens based on the current BTC price and specified amount.
- Added `redeem-stablecoin` public function to redeem stablecoins for BTC. - Validates redemption parameters and updates reserves. - Burns tokens based on the current BTC price and specified amount.
- Implemented `can-mint` private function to check if minting is possible based on reserves and collateralization ratio. - Calculates the maximum mintable amount and validates against the current total supply.
- Added `liquidate` public function to handle liquidation of underwater positions. - Validates liquidation conditions and burns the specified amount of tokens.
- Implemented `update-collateralization-ratio` public function. - Allows the contract owner to update the collateralization ratio within a specified range (100% to 200%). - Validates the new ratio and updates the `collateralization-ratio` variable.
- Implemented `get-total-reserves` read-only function to retrieve the total reserves. - Implemented `get-stablecoin-supply` read-only function to retrieve the total supply of the stablecoin.
…in supply retrieval
…ation for liquidation
… from main branch - Overview of the smart contract functionality and features. - Detailed technical specifications including constants and error codes. - Documentation of core functions: minting, redemption, and liquidation. - Administrative functions for updating collateralization ratio. - View functions for retrieving total reserves and stablecoin supply. - Security considerations and usage examples. - Development and testing guidelines. - Limitations and future improvements. - Contribution guidelines.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements a complete Bitcoin-pegged stablecoin system in Clarity, featuring minting, redemption, and liquidation mechanisms with proper over-collateralization controls.
Changes
Implementation Details
Core Components
System Constants and Error Handling
CONTRACT-OWNER
for administrative controlPRECISION
constant for 6-decimal place accuracyPrice Oracle Integration
get-btc-price
function simulating a $50,000 BTC priceToken and Reserve Management
btc-stable-coin
fungible tokentotal-reserves
Core Functions
mint-stablecoin
with collateralization checksredeem-stablecoin
with proper reserve managementcan-mint
validation functionAdministrative Controls
Test Results
clarinet console output: Contract identifier: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.bitcoin-pegged Public functions verified: - get-btc-price - get-stablecoin-supply - get-total-reserves - liquidate - mint-stablecoin - redeem-stablecoin - update-collateralization-ratio
Testing
Security Considerations
Documentation
Backwards Compatibility
Deployment Plan
TODO Before Merge
Checklist
Additional Notes
The current implementation uses a simulated BTC price feed. For production deployment, this should be replaced with a proper oracle integration.
Reviewers