A DeFi portfolio management system that automatically rebalances capital between different investment strategies based on performance metrics. Built on Solana using the Anchor framework.
- Portfolio Management: Initialize and manage investment portfolios
- Strategy Registry: Register strategies across different DeFi protocols
- Performance Engine: Mathematical scoring system with weighted formula:
- Yield Rate: 45% weight
- Capital Balance: 35% weight
- Inverse Volatility: 20% weight
- Ranking System: Percentile-based ranking with dynamic threshold calculation
- Capital Operations: Extract from underperformers, redistribute to top performers
- Portfolio: Main portfolio account with manager, thresholds, and totals
- Strategy: Individual strategy with performance metrics and protocol details
- CapitalPosition: Position tracking for different protocol types
- Multi-Protocol Support: Stable lending, yield farming, liquid staking
Performance Score = (Normalized Yield × 45%) + (Normalized Balance × 35%) + (Normalized Inverse Volatility × 20%)- Solend: Simple balance withdrawal with utilization-based fees
- Orca: LP token withdrawal using AMM mathematics (x*y=k formula)
- Marinade: Unstaking with epoch delays and penalty calculations
- Dynamic threshold calculation based on portfolio volatility
- Diversification constraints (max 40% single strategy allocation)
- Mathematical safety with overflow protection throughout
- Solana CLI: v1.18+
- Anchor Framework: v0.30.1
- Node.js: v18+
- Rust: Latest stable version
- Clone the repository
git clone https://github.com/your-username/portfolio-rebalancer
cd portfolio-rebalancer- Install dependencies
npm install
# or
yarn install- Build the program
anchor build# Terminal 1: Start Solana test validator
solana-test-validator# Terminal 2: Run the test suite
anchor test --skip-local-validatorThe tests demonstrate the complete rebalancing workflow:
- Initialize Portfolio - Create portfolio with manager and thresholds
- Register Strategies - Add 3 strategies across different protocols
- Deposit Capital - Fund strategies with test tokens
- Update Performance - Set different performance metrics
- Execute Ranking - Calculate scores and percentile rankings
- Extract Capital - Remove funds from underperformers
- Redistribute Capital - Allocate to top performers
- Withdraw from Strategy - Demonstrate withdraw functionality
initialize_portfolio- Create new portfolioregister_strategy- Add investment strategydeposit_to_strategy- Manager deposits fundswithdraw_from_strategy- Manager withdraws funds
update_performance- Update strategy metrics and calculate scoresexecute_ranking_cycle- Rank strategies and identify rebalancing targetsextract_capital- Remove capital from underperformersredistribute_capital- Allocate capital to top performers
- Simple deposit/withdrawal mechanics
- Utilization-based fee calculation
- Minimum 0.1 SOL deposit requirement
- LP token position management
- AMM mathematics for proportional withdrawals
- Slippage and fee calculations
- Minimum 0.5 SOL deposit requirement
- Staking/unstaking with epoch delays
- Validator commission handling
- Penalty calculations for immediate unstaking
- Minimum 1 SOL deposit requirement
This project is for assessment purposes to demonstrate Solana development skills in DeFi portfolio management.