The Yield Aggregator Protocol is a decentralized yield optimization contract designed to maximize returns by automatically allocating user funds across different yield farming opportunities. It optimizes investment performance by selecting the best strategies based on Annual Percentage Yields (APY) and other risk metrics. The protocol is implemented in Clarity, a language specifically designed for smart contracts on the Stacks blockchain.
- Automated Yield Optimization: Funds are strategically allocated across multiple yield farming strategies based on predefined rules and APY comparisons.
- Emergency Shutdown: A security feature allowing the contract owner to shut down protocol operations in case of emergencies.
- Flexible Strategy Management: New strategies can be added, updated, enabled, or disabled, and allocation criteria can be customized.
- User Deposits and Withdrawals: Users can deposit assets into the protocol and withdraw funds based on their share allocation.
To deploy and interact with this contract, ensure you have the following tools installed:
- Stacks CLI or another tool compatible with Clarity development
- Stacks wallet address for contract ownership and deployment
Clone the repository and navigate to the contract directory:
git clone https://github.com/rich-b-art/yield-aggregator-protocol.git
cd yield-aggregator-protocol
Deploy the contract on the Stacks blockchain testnet or mainnet using the Stacks CLI:
clarity-cli launch yield-aggregator.clar
Upon deployment, the contract initializes with default variables, including contract-owner
, emergency-shutdown
, total-value-locked
, performance-fee
, management-fee
, max-strategies
, and token-contract
.
The contract-owner
is set as the contract deployer, and only this principal can perform administrative tasks.
Constants are used to manage protocol parameters such as contract-name
, ERR-NOT-AUTHORIZED
, and ERR-INSUFFICIENT-BALANCE
, providing readable error handling.
contract-owner
: Set at deployment; only the owner can perform administrative functions.emergency-shutdown
: Boolean to pause all contract activity in emergencies.total-value-locked
: Tracks the total value locked in the protocol.performance-fee
andmanagement-fee
: Fees collected on user deposits and withdrawals, adjustable by the contract owner.
Strategies
: Stores details about each yield farming strategy, including name, protocol, APY, and risk score.UserDeposits
: Manages user-specific data, including total deposits and token shares.StrategyAllocations
: Holds allocation details, such as minimum/maximum deposit requirements for each strategy.
- Deposit - Allows users to deposit funds into the protocol.
- Withdraw - Users can withdraw their allocated share tokens and underlying assets.
- Add Strategy - Adds a new yield strategy with specific parameters.
- Update Strategy APY - Allows the contract owner to update the APY of a strategy.
- Toggle Emergency Shutdown - Enables or disables emergency shutdown mode.
- Set Token Contract - Sets the token contract for managing deposits and withdrawals.
- Get Strategy List - Returns the list of available strategy IDs.
- Get Strategy Info - Provides details about a specific strategy.
- Get User Info - Returns deposit information for a specific user.
- Get Total TVL - Retrieves the total value locked in the protocol.
- Calculate Best Strategy - Identifies the best strategy based on APY and other metrics.
These functions manage internal calculations and validations, such as verifying the contract owner, calculating share tokens, and reallocating funds across strategies.
- Authorization: Only the contract owner can add strategies, update parameters, and toggle emergency shutdown.
- Emergency Shutdown: In the event of critical issues, the contract can be paused to protect user assets.
- Error Handling: Error codes provide detailed feedback on failed operations to improve transparency and debugging.
Test the protocol by writing and running test cases in a Clarity-compatible testing environment, such as Clarinet or clarity-cli
. Ensure all scenarios are covered, including deposit, withdrawal, strategy updates, and emergency shutdown activation.
This project is licensed under the MIT License.