Skip to content
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
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
37bebf9
Added error code constants and SIP-010 token trait import
nicholas-source Nov 21, 2024
6f51a07
Added contract owner and stablecoin configuration variables
nicholas-source Nov 21, 2024
76e1d40
Added governance parameters for stablecoin
nicholas-source Nov 21, 2024
7fed9d1
Added oracles and price feeds for BTC
nicholas-source Nov 21, 2024
6b28f28
Added vault structure for managing collateral and stablecoin minting
nicholas-source Nov 21, 2024
c7fe484
Added vault counter and function to add BTC price oracles
nicholas-source Nov 21, 2024
9a9b673
Added function to update BTC price
nicholas-source Nov 21, 2024
0fc53d2
Added read-only function to get the latest BTC price
nicholas-source Nov 21, 2024
6174fc0
Added function to create a new vault
nicholas-source Nov 21, 2024
c78a3f3
Added function to mint stablecoin
nicholas-source Nov 21, 2024
8bde4bd
Added liquidation mechanism for undercollateralized vaults
nicholas-source Nov 21, 2024
ba194ba
Added redemption mechanism for stablecoins
nicholas-source Nov 21, 2024
304bc76
Added governance function to update collateralization ratio
nicholas-source Nov 21, 2024
8ed992e
Added read-only function to get vault details
nicholas-source Nov 21, 2024
7c43eba
Added read-only function to get total supply
nicholas-source Nov 21, 2024
dde666d
Refactored trait definition for SIP-010 token and updated price handl…
nicholas-source Nov 21, 2024
133823d
Updated stablecoin symbol to a 5-character format
nicholas-source Nov 21, 2024
a9f62f3
Refactored stablecoin symbol definition and improved BTC price retrie…
nicholas-source Nov 21, 2024
d8dbca7
Enhanced error handling and validation across vault operations and BT…
nicholas-source Nov 21, 2024
32a0c25
Add vault ID validation to enhance security in vault operations
nicholas-source Nov 21, 2024
fd67d99
Updated README with detailed overview and key functions from the main…
nicholas-source Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions Clarinet.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
[project]
name = "bitcoin-backed-stablecoin"
description = ""
name = 'bitcoin-backed-stablecoin'
description = ''
authors = []
telemetry = true
cache_dir = "./.cache"

# [contracts.counter]
# path = "contracts/counter.clar"

cache_dir = './.cache'
requirements = []
[contracts.backed-stablecoin]
path = 'contracts/backed-stablecoin.clar'
clarity_version = 2
epoch = 2.5
[repl.analysis]
passes = ["check_checker"]
check_checker = { trusted_sender = false, trusted_caller = false, callee_filter = false }
passes = ['check_checker']

# Check-checker settings:
# trusted_sender: if true, inputs are trusted after tx_sender has been checked.
# trusted_caller: if true, inputs are trusted after contract-caller has been checked.
# callee_filter: if true, untrusted data may be passed into a private function without a
# warning, if it gets checked inside. This check will also propagate up to the
# caller.
# More informations: https://www.hiro.so/blog/new-safety-checks-in-clarinet
[repl.analysis.check_checker]
strict = false
trusted_sender = false
trusted_caller = false
callee_filter = false
152 changes: 152 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Bitcoin-Backed Stablecoin Smart Contract

## Overview

This Clarity smart contract implements a Bitcoin-backed stablecoin system on the Stacks blockchain, providing a robust mechanism for creating, minting, redeeming, and liquidating crypto-collateralized stablecoins.

## Features

- **Vault Management**

- Create Bitcoin-collateralized vaults
- Mint stablecoins against Bitcoin collateral
- Redeem stablecoins
- Liquidate undercollateralized vaults

- **Advanced Security**

- Strict authorization checks
- Input validation
- Comprehensive error handling
- Configurable governance parameters

- **Oracle Integration**
- Multiple price oracle support
- Bitcoin price tracking
- Price update mechanism

## Contract Architecture

### Key Components

1. **Vaults**

- Unique vault creation for each user
- Tracks collateral amount, minted stablecoins, and vault creation timestamp
- Supports multiple vaults per user

2. **Stablecoin Configuration**

- Configurable name and symbol
- Dynamic total supply management
- Adjustable collateralization ratio

3. **Governance**
- Contract owner controls critical parameters
- Ability to update collateralization ratio
- Oracle management

### Error Handling

The contract includes detailed error codes for various scenarios:

- Unauthorized actions
- Insufficient balances
- Invalid collateral
- Undercollateralization
- Oracle price unavailability
- Liquidation failures
- Minting limit exceedance

## Key Functions

### `create-vault`

- Creates a new vault for a user
- Requires valid collateral amount
- Generates a unique vault ID

### `mint-stablecoin`

- Allows minting stablecoins against collateral
- Validates:
- Vault ownership
- Collateralization ratio
- Minting limits
- Oracle price

### `redeem-stablecoin`

- Enables users to redeem stablecoins
- Reduces vault's minted amount
- Updates total supply

### `liquidate-vault`

- Triggers vault liquidation when collateralization falls below threshold
- Prevents self-liquidation
- Removes undercollateralized vault

### Governance Functions

- `add-btc-price-oracle`: Add trusted price oracles
- `update-btc-price`: Update Bitcoin price
- `update-collateralization-ratio`: Adjust system parameters

## Configuration Parameters

- **Collateralization**

- Minimum ratio: 150%
- Liquidation threshold: 125%

- **Fees**

- Minting fee: 0.5%
- Redemption fee: 0.5%

- **Limits**
- Maximum mint limit: 1,000,000 tokens
- Maximum Bitcoin price: 1,000,000,000,000

## Security Considerations

- Strict access controls
- Price oracle validation
- Comprehensive input validation
- Prevents excessive vault and token creation
- Configurable liquidation mechanisms

## Installation and Deployment

### Prerequisites

- Stacks blockchain
- Clarity smart contract support
- Bitcoin price oracle infrastructure

### Deployment Steps

1. Deploy the contract on Stacks
2. Configure initial parameters
3. Add trusted price oracles
4. Set initial collateralization ratio

## Potential Improvements

- Dynamic fee adjustments
- More granular liquidation mechanisms
- Enhanced oracle redundancy
- Cross-chain collateral support

## Disclaimer

This smart contract is provided as-is. Users and developers should conduct thorough audits and testing before production use.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Contributing

We welcome contributions to DAF Smart Contract! Please see our [Guide](CONTRIBUTING.md) for details on how to get started.
Loading