A multi-protocol CDP (Collateralized Debt Position) platform that accepts yield-bearing tokens from various DeFi protocols as collateral. Users can deposit assets like stETH (Lido), aUSDC (Aave), cDAI (Compound) and borrow stablecoins while continuing to earn yield on their collateral.
- Multi-Protocol Support: Accept yield-bearing tokens from Aave, Lido, Compound, and more
- Yield Preservation: Continue earning yield on deposited collateral
- Zield Receipt Tokens: Receive protocol-specific receipt tokens (zstETH, zaUSDC, etc.)
- Flexible Collateral: Mix and match different yield-bearing tokens
- Aggregated APY: View weighted average yield across all positions
- Health Factor Monitoring: Real-time position health tracking
- Liquidation Protection: 150% collateralization ratio with 125% liquidation threshold
contracts/
βββ src/
β βββ MultiProtocolCDP.sol # Main CDP contract
β βββ VaultRegistry.sol # Protocol adapter registry
β βββ ZieldToken.sol # Receipt token implementation
β βββ adapters/
β β βββ AaveAdapter.sol # Aave V3 adapter
β β βββ LidoAdapter.sol # Lido staking adapter
β β βββ CompoundAdapter.sol # Compound V3 adapter
β βββ interfaces/
β βββ IProtocolAdapter.sol # Adapter interface
βββ script/
β βββ Deploy.s.sol # Deployment script
βββ test/
β βββ MultiProtocolCDP.t.sol # Contract tests
βββ foundry.toml # Foundry configuration
- MultiProtocolCDP: Main contract handling deposits, withdrawals, borrowing, and repayments
- VaultRegistry: Central registry managing protocol adapters and token whitelisting
- ZieldToken: ERC20 receipt tokens representing user collateral positions
- AaveAdapter: Handles Aave V3 aTokens (aUSDC, aDAI, etc.)
- LidoAdapter: Manages Lido stETH positions
- CompoundAdapter: Integrates with Compound V3 cTokens
- Foundry
- Git
# Clone the repository
git clone <repository-url>
cd contracts
# Install dependencies
forge install
# Build contracts
forge build- Copy environment example:
cp .env.example .env- Configure
.env:
PRIVATE_KEY=your_private_key_here
BASE_TESTNET_RPC_URL=https://base-sepolia.drpc.org
BASE_TESTNET_RPC_BACKUP=https://sepolia.base.org
BASE_EXPLORER_API_KEY=your_basescan_api_keyRun the test suite:
# Run all tests
forge test
# Run tests with verbosity
forge test -vvv
# Run specific test
forge test --match-test testDepositCollateral
# Generate gas report
forge test --gas-report
# Check coverage
forge coverageUsing the deployment script:
# Make deploy script executable
chmod +x deploy.sh
# Run deployment
./deploy.shOr manually with Forge:
forge script script/Deploy.s.sol:DeployScript \
--rpc-url $BASE_TESTNET_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
--verify \
--etherscan-api-key $BASE_EXPLORER_API_KEY \
-vvvforge verify-contract <CONTRACT_ADDRESS> \
src/MultiProtocolCDP.sol:MultiProtocolCDP \
--chain-id 84532 \
--etherscan-api-key $BASE_EXPLORER_API_KEY \
--constructor-args $(cast abi-encode "constructor(address,address,address)" <REGISTRY> <STABLECOIN> <ORACLE>)// Approve yield token
IERC20(stETH).approve(address(cdp), amount);
// Deposit stETH as collateral
cdp.depositCollateral(stETH, amount);// Check max borrow amount
uint256 maxBorrow = cdp.getMaxBorrow(msg.sender);
// Borrow zUSD
cdp.borrow(borrowAmount);// Approve stablecoin
IERC20(zUSD).approve(address(cdp), repayAmount);
// Repay debt
cdp.repay(repayAmount);// Withdraw collateral (if health factor allows)
cdp.withdrawCollateral(stETH, withdrawAmount);// Get health factor (returns percentage, e.g., 150 = 150%)
uint256 healthFactor = cdp.getHealthFactor(msg.sender);
// Get total collateral value
uint256 collateralValue = cdp.getTotalCollateralValue(msg.sender);
// Get aggregated APY
uint256 weightedApy = cdp.getTotalApy(msg.sender);| Parameter | Value | Description |
|---|---|---|
| Collateral Ratio | 150% | Minimum collateralization required |
| Liquidation Threshold | 125% | Health factor triggers liquidation |
| Liquidation Penalty | 10% | Penalty for liquidated positions |
- β ReentrancyGuard on all state-changing functions
- β SafeERC20 for token transfers
- β Ownable access control
- β Input validation and error handling
- β Health factor checks before borrowing/withdrawing
# Start local Anvil node
anvil
# Deploy to local node
forge script script/Deploy.s.sol:DeployScript \
--rpc-url http://127.0.0.1:8545 \
--private-key $PRIVATE_KEY \
--broadcast# Format code
forge fmt
# Check formatting
forge fmt --check# Generate docs
forge doc
# Serve docs locally
forge doc --serve --port 3000After deployment, update with your contract addresses:
MultiProtocolCDP: 0x...
VaultRegistry: 0x...
Stablecoin (zUSD): 0x...
Adapters:
AaveAdapter: 0x...
LidoAdapter: 0x...
CompoundAdapter: 0x...
Yield Tokens:
stETH: 0x...
aUSDC: 0x...
cDAI: 0x...
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base.