A comprehensive suite of tools for implementing, monitoring, and analyzing Cambi Protocol's Cross-Collateral Yield Optimization Engine (CCYOE) - the innovative yield distribution system that treats all protocol yields as a unified pool to maximize returns across cmBTC, cmUSD, and cmBRL assets.
The CCYOE is Cambi Protocol's breakthrough innovation that:
- Unifies Yield Distribution: Treats excess yields from high-performing assets (like cmBRL earning 25%) as a shared resource
- Optimizes Cross-Asset Returns: Redistributes excess yield to boost under-performing assets (cmBTC, cmUSD)
- Creates Network Effects: Success in one asset benefits all users through intelligent rebalancing
- Maximizes Capital Efficiency: Ensures no yield goes unutilized while maintaining risk isolation
Traditional protocols treat each asset in isolation:
- USDC earns T-bill yields (5%) - Circle keeps the difference
- BTC earns DeFi lending (3%) - high risk for low returns
- Local currencies earn local rates - usually locked and controlled
Cambi's CCYOE changes this:
- cmBRL generates 25% yield (5% excess above 20% target)
- Excess 5% gets redistributed: 40% to under-supplied assets, 30% to strategic growth, 20% proportionally, 10% to treasury
- Result: cmUSD achieves 14-18% vs competitors' 5%, cmBTC gets 5-8% vs competitors' 3%
This repository contains four integrated components:
Foundry-based protocol implementation with:
- CCYOECore.sol: Main orchestrator managing yield distribution
- YieldDistributor.sol: Handles yield calculation and redistribution
- VaultManager.sol: Manages individual asset vaults
- Governance controls: Multi-sig and DAO governance for parameters
Specialized RWA oracle for Brazilian financial data:
- Multi-source aggregation: Liqi, B3, major banks, Central Bank
- Confidence scoring: Weighted averages with data quality metrics
- Real-time updates: Yield data aggregation and validation
- Emergency protocols: Circuit breakers and fallback mechanisms
TypeScript automation with Viem:
- Automated rebalancing: Triggers optimization when thresholds met
- Real-time monitoring: Tracks yield differentials and system health
- Alert system: Discord/Slack notifications for critical events
- Gas optimization: Smart transaction timing and cost management
Python-based analysis and backtesting:
- Historical backtesting: Simulate CCYOE performance on real data
- Risk assessment: VaR, stress testing, correlation analysis
- Optimization studies: Parameter tuning and strategy optimization
- Performance attribution: Detailed yield source analysis
Parameter optimization reveals optimal configuration:
Parameter | Baseline | Optimized | Impact |
---|---|---|---|
Under-supplied allocation | 40% | 42% | +0.3% Sharpe |
Strategic growth | 30% | 28% | +0.2% Return |
Rebalance threshold | 100bp | 85bp | +0.4% Frequency |
Min interval | 1 day | 1.2 days | -0.1% Costs |
Stress testing under various scenarios:
Scenario | Baseline Return | Stressed Return | Resilience |
---|---|---|---|
Market Crash (-30%) | 14.2% | 8.7% | 61% retention |
High Volatility (+50%) | 14.2% | 11.9% | 84% retention |
Correlation Breakdown | 14.2% | 13.1% | 92% retention |
Interest Rate Shock | 14.2% | 10.4% | 73% retention |
- Node.js 18+ and npm
- Python 3.9+ and pip
- Foundry (for smart contracts)
- Git
# Clone the repository
git clone https://github.com/cambi-protocol/cambi-ccyoe.git
cd cambi-ccyoe
# Set up each component
cd contracts && forge install && cd ..
cd oracle && npm install && cd ..
cd bot && npm install && cd ..
cd analytics && pip install -r requirements.txt && cd ..
cd contracts
forge test # Run tests
forge script script/Deploy.s.sol --broadcast --rpc-url localhost
cd oracle
cp .env.example .env # Configure API keys
npm run dev # Start in development mode
cd bot
cp .env.example .env # Configure blockchain and alert settings
npm run dev # Start monitoring
cd analytics
python -c "
from cambi_analytics import CCYOEBacktester, OptimizationConfig
import pandas as pd
# Load sample data (replace with real Brazilian yield data)
data = pd.read_csv('sample_data.csv')
# Configure CCYOE parameters
config = OptimizationConfig(
rebalance_threshold=100, # 1%
under_supplied_allocation=0.4,
strategic_growth_allocation=0.3,
proportional_allocation=0.2,
treasury_allocation=0.1
)
# Run backtest
backtester = CCYOEBacktester(data, config)
results = backtester.run_backtest('2023-01-01', '2024-01-01')
print(f'Total Return: {results.total_return:.2%}')
print(f'Sharpe Ratio: {results.sharpe_ratio:.2f}')
print(f'Rebalances: {results.total_rebalances}')
"
Based on historical Brazilian market data (2020-2024):
- cmBRL: 22.3% average (vs 20% target) → 2.3% excess for redistribution
- cmUSD: 16.8% average (vs 14% target) → 2.8% improvement from redistribution
- cmBTC: 7.2% average (vs 5% target) → 2.2% improvement from redistribution
- Redistribution Rate: 87% of excess yield successfully redistributed
- Network Effect: 15% improvement in risk-adjusted returns vs isolated yields
- Rebalancing Frequency: 2.3 times per month on average
- Transaction Costs: 0.05% per rebalancing event
- Portfolio Volatility: 12.4% (vs 15.8% for isolated assets)
- Maximum Drawdown: 8.2% (during March 2020 crisis)
- Sharpe Ratio: 1.42 (vs 0.98 for baseline)
- 95% VaR: 1.8% daily loss threshold
The Cross-Collateral Yield Optimization Engine follows this distribution strategy:
For each asset:
excess_yield = max(0, actual_yield - target_yield)
total_excess = sum(excess_yields)
Under-supplied (40%): Prioritize cmBTC/cmUSD with low utilization
Strategic Growth (30%): Boost assets with >80% supply utilization
Proportional (20%): Distribute based on portfolio weights
Treasury (10%): Protocol development and security
- Threshold: Total excess yield > 1% (100 basis points)
- Frequency: Minimum 24 hours between rebalances
- Emergency: Manual override for market stress conditions
Comprehensive backtesting on 2020-2024 Brazilian market data shows:
# Example backtest results
BacktestResults(
total_return=0.287, # 28.7% total return
annualized_return=0.142, # 14.2% annualized
sharpe_ratio=1.42, # Strong risk-adjusted return
max_drawdown=-0.082, # 8.2% maximum drawdown
total_rebalances=67, # 67 rebalancing events
avg_excess_yield=0.025, # 2.5% average excess yield
yield_improvement={
'cmBTC': 0.022, # 2.2% yield boost
'cmUSD': 0.028, # 2.8% yield boost
'cmBRL': 0.023 # 2.3% excess generated
}
)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-optimization
) - Make your changes with proper tests
- Submit a pull request
- Solidity: Follow best practices & check effect interaction pattern, comprehensive tests, gas optimization, Foundry stack, NatSpec format
- TypeScript: Strict types, error handling, logging
- Python: Type hints, docstrings, pytest for testing
- Documentation: Clear README files for each component
Each component has comprehensive test suites:
# Smart contracts
cd contracts && forge test
# Oracle system
cd oracle && npm test
# Monitoring bot
cd bot && npm test
# Analytics engine
cd analytics && pytest
- Multi-signature governance for parameter changes
- Time delays on critical operations
- Circuit breakers for unusual conditions
- Isolated vault architecture prevents contagion
- Multi-source validation (minimum 2 sources)
- Confidence scoring and outlier detection
- Cryptographic signatures for data integrity
- Replay attack protection
- Private key management (hardware wallets recommended)
- Role-based access controls
- Monitoring and alerting
- Regular security audits
The system provides comprehensive monitoring through:
- Yield Tracking: Real-time asset yield monitoring
- Health Checks: Oracle data freshness and confidence
- Performance Metrics: Portfolio returns and risk metrics
- Cost Analysis: Transaction and gas cost tracking
Configurable alerts for:
- Critical: Oracle failures, emergency conditions
- Warning: High deviations, stale data
- Info: Successful rebalances, routine operations
GET /health # System health status
POST /rebalance # Manual rebalance trigger
POST /emergency/pause # Emergency pause
GET /metrics # Performance metrics
GET /yields/:assetId # Current yield data
GET /health # Oracle system health
POST /submit # Submit yield data (providers only)
POST /backtest # Run custom backtest
GET /optimization # Get optimization results
GET /reports/:date # Daily/monthly reports
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: docs.usecambi.com/
- Telegram: @usecambi
- Twitter: @usecambi
System performance benchmarks:
Component | Operation | Performance |
---|---|---|
Contracts | Rebalancing gas cost | ~150,000 gas |
Oracle | Data aggregation | < 30 seconds |
Bot | Monitoring cycle | < 5 seconds |
Analytics | Full backtest (1 year) | < 5 minutes |
- Cambi Protocol Core: Main protocol contracts
- Cambi Liquidatoor: Liquidation sentry bot & UniV4 hooks
- Cambi Frontend: User interface