-
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
Bitcoin-Backed Stablecoin Smart Contract Implementation #1
Open
nicholas-source
wants to merge
21
commits into
main
Choose a base branch
from
feature/add-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
- Imported SIP-010 token trait for token standard compliance. - Defined error code constants for various error scenarios: - ERR-NOT-AUTHORIZED - ERR-INSUFFICIENT-BALANCE - ERR-INVALID-COLLATERAL - ERR-UNDERCOLLATERALIZED - ERR-ORACLE-PRICE-UNAVAILABLE - ERR-LIQUIDATION-FAILED - ERR-MINT-LIMIT-EXCEEDED - ERR-INVALID-PARAMETERS
- Defined CONTRACT-OWNER constant. - Added stablecoin configuration variables: - stablecoin-name - stablecoin-symbol - total-supply - collateralization-ratio - liquidation-threshold
- Defined governance parameters: - mint-fee-bps (0.5% minting fee) - redemption-fee-bps (0.5% redemption fee) - max-mint-limit (limit to prevent excessive minting)
- Defined btc-price-oracles map to store authorized price oracles. - Defined last-btc-price map to store the latest BTC price with timestamp.
- Defined vaults map to store vault details: - owner: principal - id: uint - collateral-amount: uint (BTC collateral) - stablecoin-minted: uint (minted stablecoin amount) - created-at: uint (timestamp of vault creation)
- Defined vault-counter variable to track the number of vaults. - Implemented add-btc-price-oracle function to add authorized BTC price oracles: - Checks if the sender is the contract owner. - Adds the oracle to the btc-price-oracles map.
- Implemented update-btc-price function to update the BTC price: - Checks if the sender is an authorized BTC price oracle. - Updates the last-btc-price map with the new price and timestamp.
- Implemented get-latest-btc-price function to retrieve the latest BTC price from the last-btc-price map.
- Implemented create-vault function to create a new vault: - Generates a new vault ID by incrementing the vault counter. - Validates that the collateral amount is greater than zero. - Increments the vault counter. - Stores the new vault details in the vaults map. - Returns the new vault ID.
- Implemented mint-stablecoin function to mint stablecoins against a vault's collateral: - Retrieves vault details. - Gets the latest BTC price. - Calculates the maximum mintable amount based on the collateral. - Validates minting conditions to ensure sufficient collateral and adherence to mint limits. - Updates the vault with the minted amount. - Updates the total supply of stablecoins.
- Implemented liquidate-vault function to handle vault liquidation: - Retrieves vault details. - Gets the latest BTC price. - Calculates the current collateralization ratio. - Checks if the vault is below the liquidation threshold. - Seizes collateral and burns minted stablecoins. - Updates the total supply of stablecoins. - Removes the vault from the vaults map.
- Implemented redeem-stablecoin function to redeem stablecoins: - Retrieves vault details. - Validates the redemption amount against the minted stablecoins. - Updates the vault with the redeemed amount. - Updates the total supply of stablecoins.
- Implemented update-collateralization-ratio function: - Checks if the sender is the contract owner. - Validates the new ratio to be within the acceptable range (100% to 300%). - Updates the collateralization ratio.
- Implemented get-vault-details function to retrieve details of a specific vault: - Takes vault-owner and vault-id as parameters. - Returns the vault details from the vaults map.
- Implemented get-total-supply function to retrieve the total supply of stablecoins: - Returns the value of the total-supply variable.
…ing in vault calculations
…val logic for clarity
…C price management
… branch - Added comprehensive overview of the Bitcoin-backed stablecoin system. - Detailed features including vault management, security, and oracle integration. - Described key components of the contract architecture. - Included error handling scenarios. - Documented key functions: create-vault, mint-stablecoin, redeem-stablecoin, liquidate-vault, and governance functions. - Listed configuration parameters and security considerations. - Provided installation and deployment steps. - Suggested potential improvements. - Added disclaimer, license, and contributing 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 pull request introduces a comprehensive Bitcoin-backed stablecoin smart contract for the Stacks blockchain, implementing a robust crypto-collateralized stablecoin system with advanced security and governance mechanisms.
Key Features
Detailed Changes
Contract Architecture
Security Enhancements
Core Functionality
Vault Management
create-vault
: Generate unique vaults with Bitcoin collateralmint-stablecoin
: Mint stablecoins against collateralized vaultsredeem-stablecoin
: Redeem and burn stablecoinsliquidate-vault
: Handle undercollateralized vault scenariosOracle and Price Management
add-btc-price-oracle
: Add trusted price oraclesupdate-btc-price
: Update Bitcoin price with timestampget-latest-btc-price
: Retrieve most recent priceGovernance Functions
update-collateralization-ratio
: Dynamically adjust system parametersget-vault-details
get-total-supply
Configuration Parameters
Testing
Notes
Future Improvements
Checklist