-
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 BTC Lending Protocol Smart Contract #1
Open
savi-auto
wants to merge
17
commits into
main
Choose a base branch
from
feature/implementation
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
- Added title, summary, and description metadata to the smart contract. - Defined protocol parameters including CONTRACT-OWNER, MIN-COLLATERAL-RATIO, LIQUIDATION-THRESHOLD, LIQUIDATION-PENALTY, PRICE-VALIDITY-PERIOD, and MAX-FEE-PERCENTAGE.
- Defined error codes for various failure scenarios including authorization, balance, amount validation, collateral requirements, loan existence, liquidation, price validity, zero amount, and fee limits.
- Defined data variables to track the protocol state including `protocol-paused`, `total-loans`, `total-collateral`, and `protocol-fee-percentage`.
- Defined data variables `btc-price-in-cents` and `last-price-update` to store the BTC price and the timestamp of the last price update.
- Defined maps `collateral-balances` and `borrow-balances` to track the collateral and borrowed balances for each user.
- Added `validate-amount` to ensure the amount is greater than zero. - Added `check-authorization` to verify if the transaction sender is the contract owner. - Added `check-protocol-active` to ensure the protocol is not paused.
- Added `get-loan` to retrieve loan details for a user. - Added `get-collateral-balance` to get the collateral balance of a user.
- Added `get-borrow-balance` to retrieve the borrow balance of a user. - Added `get-current-collateral-ratio` to calculate the current collateral ratio for a user.
- Added `is-price-valid` to check if the BTC price is still valid based on the last update. - Added `get-protocol-stats` to retrieve the current protocol statistics including total loans, total collateral, current fee, and paused state.
- Added `update-btc-price` to allow the contract owner to update the BTC price and the timestamp of the last price update.
- Added `deposit-collateral` to allow users to deposit collateral into the protocol. The function checks if the protocol is active, validates the amount, transfers the collateral, updates the user's collateral balance, and updates the total collateral in the protocol.
- Added `borrow` to allow users to borrow against their collateral. The function checks if the protocol is active, validates the amount, ensures the price is valid, checks if the user has an existing loan, verifies the collateral ratio, updates the loan and borrow balances, and increments the total loans in the protocol.
- Added `repay-loan` to allow users to repay their loans. The function checks if the protocol is active, validates the amount, calculates the interest due, transfers the total due amount, updates or deletes the loan and borrow balances, and decrements the total loans in the protocol.
- Added `liquidate` to allow the protocol to liquidate under-collateralized loans. The function checks if the protocol is active, verifies the loan and collateral ratio, calculates the liquidation value, transfers the liquidation amount, clears the loan, updates the protocol state, and returns any remaining collateral to the user.
- Added `update-protocol-fee` to allow the contract owner to update the protocol fee percentage. The function checks authorization, validates the new fee against the maximum allowed fee, and updates the protocol fee percentage.
- Added `toggle-protocol-pause` to allow the contract owner to pause or unpause the protocol. The function checks authorization and toggles the `protocol-paused` state.
- Provided an overview of the BTC Lending Protocol, including key features and technical specifications. - Detailed the core functions, including user functions, read-only functions, and administrative functions. - Included usage examples for depositing collateral, borrowing, repaying loans, and liquidating positions. - Highlighted security considerations and contributing guidelines. - Added licensing information.
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 comprehensive decentralized lending protocol on the Stacks blockchain. The protocol enables users to deposit STX as collateral, borrow against it, and participate in liquidations, with built-in governance functionality and price oracle integration.
Features Added
Core Protocol Infrastructure
Lending Functions
Administrative Features
Read-Only Functions
Technical Implementation
Protocol Parameters
Test Coverage
Clarinet Console Output
Security Considerations
Testing Instructions
Deployment Plan
Documentation
Checklist
Future Improvements
Please review and provide feedback on the implementation, particularly regarding:
Tag: @protocol-team @security-team