Implement BitYield Pro Core Protocol Architecture#1
Open
peter-curl wants to merge 11 commits intomainfrom
Open
Implement BitYield Pro Core Protocol Architecture#1peter-curl wants to merge 11 commits intomainfrom
peter-curl wants to merge 11 commits intomainfrom
Conversation
…isted tokens - Introduced `user-deposits` map to track user deposit amounts and last deposit block. - Added `user-rewards` map to manage pending and claimed rewards for users. - Defined `protocols` map to store protocol details, including name, status, and APY. - Implemented `strategy-allocations` map for managing protocol-specific allocation percentages. - Created `whitelisted-tokens` map to track approved tokens for the protocol.
- Implemented `sip-010-trait` to define the SIP-010 token standard interface for seamless Bitcoin asset integration. - Added `is-contract-owner` private function to verify contract ownership. - Introduced validation functions: - `is-valid-protocol-id` to ensure protocol IDs are within valid range. - `is-valid-apy` to validate APY values against defined limits. - `is-valid-name` to check for valid protocol names.
…cols - Implemented `add-protocol` function to allow the contract owner to add new protocols with a unique ID, name, and initial APY. - Includes validation for protocol ID, name, and APY. - Ensures the protocol does not already exist before adding. - Initializes the protocol as active with a default allocation of 0. - Added `update-protocol-status` function to enable the contract owner to activate or deactivate existing protocols. - Validates protocol ID and ensures the protocol exists before updating its status.
- Implemented `update-protocol-apy` function to allow the contract owner to update the APY of an existing protocol. - Includes validation for protocol ID, existence, and APY range. - Ensures secure updates by merging the new APY into the protocol's data. - Added `validate-token` private function to verify if a token is whitelisted and approved. - Checks the token's contract against the `whitelisted-tokens` map. - Ensures only approved tokens can interact with the protocol.
- Added `deposit` function to handle user deposits securely: - Validates the token using the `validate-token` function to ensure it is whitelisted and approved. - Enforces deposit constraints, including minimum and maximum deposit limits. - Prevents deposits during emergency shutdowns. - Transfers tokens safely from the user to the contract using `safe-token-transfer`. - Updates user deposit records in the `user-deposits` map, including the deposit amount and block height. - Adjusts the protocol's total TVL (`total-tvl`) to reflect the new deposit. - Invokes `rebalance-protocols` to ensure proper allocation across strategies.
- Implemented `withdraw` function to allow users to withdraw their deposited tokens: - Validates the token using `validate-token` to ensure it is whitelisted and approved. - Ensures the withdrawal amount does not exceed the user's current deposit. - Updates the `user-deposits` map to reflect the reduced deposit amount. - Adjusts the protocol's total TVL (`total-tvl`) to account for the withdrawal. - Transfers tokens securely back to the user using `safe-token-transfer`. - Added `safe-token-transfer` private function to handle token transfers: - Validates the token before initiating the transfer. - Calls the SIP-010 `transfer` function to move tokens between accounts.
- Implemented `calculate-rewards` private function: - Computes user rewards based on their deposit amount, weighted APY, and the number of blocks passed. - Uses a formula to ensure accurate APY-based reward distribution over time. - Added `claim-rewards` public function: - Allows users to claim their accumulated rewards. - Validates the token using `validate-token` to ensure it is whitelisted and approved. - Ensures the calculated rewards are greater than zero before proceeding. - Updates the `user-rewards` map to reset pending rewards and increment claimed rewards. - Transfers the calculated rewards securely to the user using the SIP-010 `transfer` function.
- Implemented `rebalance-protocols` private function: - Ensures total protocol allocations do not exceed 100% (10,000 basis points). - Validates allocation consistency across all protocols. - Added `get-weighted-apy` private function: - Calculates the weighted average APY across all active protocols based on their allocations. - Introduced `get-weighted-protocol-apy` private function: - Computes the weighted APY for a specific protocol, considering its allocation and active status. - Added getter functions: - `get-protocol`: Retrieves protocol details by protocol ID. - `get-user-deposit`: Fetches user deposit details, including amount and last deposit block.
- Implemented `get-total-tvl` read-only function: - Retrieves the current total value locked (TVL) in the protocol. - Added `is-whitelisted` read-only function: - Checks if a given token is whitelisted and approved for use in the protocol. - Introduced admin functions: - `set-platform-fee`: Allows the contract owner to update the platform fee rate, with a maximum limit of 10% (1,000 basis points). - `set-emergency-shutdown`: Enables the contract owner to toggle the emergency shutdown state. - `whitelist-token`: Allows the contract owner to whitelist a token by marking it as approved. - Added helper functions: - `get-protocol-list`: Returns a predefined list of supported protocol IDs. - `get-protocol-allocation`: Retrieves the allocation percentage for a specific protocol.
- Updated `deposit` function to use `stacks-block-height` instead of `block-height` for consistency with Stacks terminology. - Adjusted `claim-rewards` function to calculate rewards based on `stacks-block-height` for accurate block-based reward distribution.
- Detailed overview of BitYield Pro's functionality, including multi-protocol yield strategies, SIP-010 compliance, and risk management. - Key features section highlighting deposit limits, emergency shutdown, and transparent fee structure. - Technical specifications covering contract architecture, key variables, and SIP-010 integration. - Core functionality explained for deposit/withdrawal management, yield strategy management, reward calculation, and protocol administration. - Security architecture section detailing risk management, emergency shutdown, and token whitelisting. - Validation framework for APY range, protocol ID validation, and deposit sanity checks.
This file contains hidden or 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
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 introduces the foundational architecture for BitYield Pro - a decentralized yield optimization protocol designed for Bitcoin DeFi on Stacks L2. The implementation establishes secure multi-strategy yield generation with institutional-grade risk parameters while maintaining full SIP-010 compliance.
Key Value Propositions
Bitcoin-Centric Design
Enterprise-Grade Security
Protocol-Owner Controls
Technical Implementation
Core Components
user-depositsmap + min/max SAT validationArchitectural Flow
graph TD A[User Deposit] --> B{Token Whitelist Check} B -->|Approved| C[TVL Update] C --> D[Protocol Rebalance] D --> E[Yield Generation] E --> F[Reward Accrual] F --> G[Claim Execution]Changes Included
Protocol Infrastructure
Data Architecture
user-deposits,user-rewards)protocols,strategy-allocations)whitelisted-tokens)Economic Controls
calculate-rewardswith APY/block/TVL factorssafe-token-transferwith pre-validation checksrebalance-protocolsallocation enforcerAdmin Governance
platform-fee-rateparameterizationNotes for Reviewers
Bitcoin Alignment
stacks-block-heightfor L1 syncUpgrade Path
Risk Disclosure