Current Status: In Development
- Network: Polygon Amoy Testnet (Chain ID: 80002)
- Status: Core Implementation Complete
- Last Updated: 2025-11-09
An ERC-4626 vault that automates Aave v3 position management with Chainlink Automation to prevent liquidations.
- Architecture - System design and components
- Development Guide - Local setup and testing
- Deployment Guide - Deployment instructions
- Implementation Plan - Project roadmap
- Automated Health Factor Management: Monitors and maintains healthy positions on Aave v3
- Chainlink Automation: Integrated with Chainlink Keepers for automated rebalancing
- Gas Efficient: Optimized for minimal gas usage
- Secure: Implements OpenZeppelin's security patterns
- Test Coverage: Comprehensive test suite with 85%+ coverage
- Decentralized: Non-custodial and permissionless
# Clone the repository
git clone https://github.com/Moses-main/aave-autopilot.git
cd aave-autopilot
# Install dependencies
foundryup
forge install
# Set up environment
cp .env.example .env
# Edit .env with your configurationEdit the .env file with your configuration:
# Sepolia RPC URL
RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY
# Contract Addresses (Sepolia)
USDC=0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8
A_USDC=0x16dA4541aD1807f4443d92D26044C1147406EB10
AAVE_POOL=0x6Ae43d3271fF6888e7Fc43Fd7321a503fF738951
AAVE_DATA_PROVIDER=0x9B2F5546AaE6fC2eE3BEaD55c59eB7eD8648aFe1
ETH_USD_PRICE_FEED=0x694AA1769357215DE4FAC081bf1f309aDC325306
LINK_TOKEN=0x779877A7B0D9E8603169DdbD7836e478b4624789
KEEPER_REGISTRY=0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2
# Deployment
PRIVATE_KEY=your_private_key_here
ETHERSCAN_API_KEY=your_etherscan_api_key_here# Run unit tests
forge test
# Run tests with gas report
forge test --gas-reportFor detailed deployment instructions, see the Deployment Guide.
This project is licensed under the MIT License - see the LICENSE file for details.
- Aave for the lending protocol
- Chainlink for price feeds and keepers
- OpenZeppelin for secure smart contract libraries
- Foundry for the development framework
0x
5000000000000000000
$YOUR_ADDRESS
- Current Deployment:
- Contract Address: 0x4e9A9676b3E24E406a42710A06120561D5A9A045
- Network: Ethereum Sepolia Testnet (Chain ID: 11155111)
- Explorer: View on Sepolia Etherscan
- Aave V3 Pool: 0x6Ae43d3...
- Chainlink Keeper Registry: 0xE16Df59B...
- LINK Token: 0x779877A7...
- USDC Token: 0x94a9D9AC...
- aUSDC Token: 0x16dA4541...
- Deployment TX: View on Etherscan
- The contract must be deployed and funded with LINK tokens
- You'll need the contract address and owner private key
# Load environment variables
source .env
# Fund the contract with 10 LINK (18 decimals)
cast send $LINK_TOKEN \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
"transfer(address,uint256)" \
0xaFf8c2337df3A7ce17525E6aa1BABCbb926F1421 \
10000000000000000000 # 10 LINK
# Verify LINK balance
cast call $LINK_TOKEN \
--rpc-url $RPC_URL \
"balanceOf(address)" \
0xcDe14d966e546D70F9B0b646c203cFC1BdC2a961# Load environment variables
source .env
# Approve Keeper Registry to spend LINK
export KEEPER_REGISTRY=0xE16Df59B403e9B01F5f28a3b09a4e71c9F3509dF
cast send $LINK_TOKEN \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
"approve(address,uint256)" \
$KEEPER_REGISTRY \
1000000000000000000 # 1 LINK
# Register with Chainlink Keepers
forge script script/RegisterWithKeepers.s.sol \
--rpc-url $RPC_URL \
--broadcast \
-vvvv# Check if the contract is registered
cast call $KEEPER_REGISTRY \
--rpc-url $RPC_URL \
"getUpkeepCount()"
# Check the registered upkeep (replace 0 with your upkeep ID if known)
cast call $KEEPER_REGISTRY \
--rpc-url $RPC_URL \
"getUpkeep(uint256)" \
0- Deposit funds to trigger position monitoring
- Simulate price movement to test rebalancing
- Verify Keeper execution in Tenderly dashboard
Example registration parameters:
- Name: AaveAutopilot Keeper
- Gas Limit: 500,000
- Trigger Type: Custom Logic
- Check Data: Encoded user address (or empty for all users)
- Gas Lane: 500 gwei
- Amount: 5 LINK
This code has not been audited. Use at your own risk.
- Reentrancy protection with OpenZeppelin's ReentrancyGuard
- Role-based access control
- Pausable functionality for emergency stops
- Input validation
- Secure token handling with OpenZeppelin's SafeERC20
- The keeper may not be able to rebalance if gas prices are extremely high
- The contract doesn't handle all edge cases of Aave v3's complex liquidation mechanics
- The keeper may need to be topped up with ETH for gas costs
MIT
The AAVE Autopilot Vault provides a simple interface for users to deposit USDC, which is then automatically supplied to AAVE v3 to earn yield. The vault actively manages the health factor of the position and automatically rebalances when necessary to prevent liquidations, providing a hands-off DeFi experience.
- Automated Health Factor Management: Continuously monitors and maintains optimal health factor (target: 1.5x, minimum: 1.05x)
- Chainlink Price Feeds: Uses real-time ETH/USD price data for accurate collateral valuation
- Chainlink Keepers Integration: Automated rebalancing when health factor falls below threshold (1.1x)
- Gas Optimization: Optimized for network's gas efficiency with minimal external calls
- Test Coverage: 85%+
- Audit Status: Pending
- Mainnet Readiness: Under Review
- Sepolia Testnet (Previous):
0xA076ecA49434a4475a9FF716c2E9f20ccc453c20
- Core smart contract development
- Comprehensive test suite
- Ethereum Sepolia deployment
- Security audit
- Mainnet deployment
- Frontend integration
- DAO governance
- Foundry (latest version recommended)
- Node.js v16+ (for deployment scripts)
- Git
- Slither (for static analysis, optional)
# Clone the repository
git clone https://github.com/Moses-main/aave-autopilot.git
cd aave-autopilot
# Install Foundry (if not already installed)
curl -L https://foundry.paradigm.xyz | bash
foundryup
# Install dependencies
forge install
# Build the project
forge build# Run all tests
forge test -vvv
# Run tests with gas reporting
forge test --gas-report
# Run specific test
forge test --match-test testDeposit -vvv- Create a
.envfile in the project root:
# Required
PRIVATE_KEY=your_private_key_here
RPC_URL=https://virtual.mainnet.eu.rpc.tenderly.co/your-api-key
# Optional (for verification)
ETHERSCAN_API_KEY=your_etherscan_api_key
# Testnet Configuration ( Sepolia ETH)
USDC=0x036CbD53842c5426634e7929541eC2318f3dCF7e
AAVE_POOL=0x6dcb6D1E0D487EDAE6B45D1d1B86e1A4AD8d4a2C
AAVE_DATA_PROVIDER=0x2d8A3C5677189723C4cB8873CfC9C8976FDF38Ac
A_USDC=0x4C5aE35b3f16fAcaA5a41f4Ba145D9aD887e8a5a
ETH_USD_PRICE_FEED=0x71041DDDAd094AE566B4d4cd0FA6C97e45B01E60Contract Address: 0x4e9A9676b3E24E406a42710A06120561D5A9A045
Constructor Parameters:
- USDC: 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8
- AAVE_POOL: 0x6Ae43d3271fF6888e7Fc43Fd7321a503fF738951
- AAVE_DATA_PROVIDER: 0x9B2F5546AaE6fC2eE3BEaD55c59eB7eD8648aFe1
- A_USDC: 0x16dA4541aD1807f4443d92D26044C1147406EB10
- ETH_USD_PRICE_FEED: 0x694AA1769357215DE4FAC081bf1f309aDC325306
- Keeper Registry: 0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2
- LINK Token: 0x779877A7B0D9E8603169DdbD7836e478b4624789
- Keeper Update Interval: 1 hour
- Health Factor Target: 1.5x
- Health Factor Threshold: 1.1x
- Max Slippage: 1%
- Deploy the contract:
# Load environment variables
source .env
# Deploy using Forge Script
forge script script/Deploy.s.sol:DeployScript \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY \
-vvvvFor mainnet deployment, update the contract addresses in the deployment script to the mainnet addresses and run:
forge script script/Deploy.s.sol:DeployScript \
--rpc-url $MAINNET_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY \
--slow- Ensure your
.envfile is properly configured with Mainnet settings - Run the deployment script:
forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast --verify -vvvv
After deployment, verify your contract on Etherscan using the following command:
forge verify-contract \
--chain-id 1 \
--num-of-optimizations 200 \
--watch \
--constructor-args $(cast abi-encode "constructor(address,string,string,address,address,address,address,address)" \
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
"Aave Autopilot Vault" \
"aAuto-USDC" \
0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2 \
0x7B4EB56E7CD4b454BA8fF71E4518426369a138a3 \
0x98C23E9d8f34FEFb1B7BD6a91B7BB122F4e16F5c \
0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 \
0xE16Df59B403e9B01F5f28a3b09a4e71c9F3509dF) \
--compiler-version v0.8.20+commit.a1b79de6 \
--etherscan-api-key $ETHERSCAN_API_KEY \
<YOUR_DEPLOYED_CONTRACT_ADDRESS> \
src/AaveAutopilot.sol:AaveAutopilotforge verify-contract \
--chain-id 11155111 \
--compiler-version v0.8.20+commit.a1b79de6 \
--constructor-args $(cast abi-encode "constructor(address,string,string,address,address,address,address)" \
0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238 \
"Aave Autopilot USDC" \
"apUSDC" \
0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951 \
0x3e9708D80F7b3e431180130bF478987472f950aF \
0x16dA4541aD1807f4443d92D26044C1147406EB80 \
0x694AA1769357215DE4FAC081bf1f309aDC325306 \
0x03a33E8A69f1A5b61178f70BC5c8E674aB571334) \
--num-of-optimizations 200 \
AaveAutopilot \
0xaE2202566bE5325e2A5746b66E13F0D6f7E248b6 \
--verifier etherscan \
--etherscan-api-key $ETHERSCAN_API_KEY
2. Deploy the contract:
```bash
forge script script/Deploy.s.sol:DeployScript --rpc-url $RPC_URL --broadcast --verify -vvvv- AaveAutopilot:
0xaE2202566bE5325e2A5746b66E13F0D6f7E248b6 - USDC:
0x036CbD53842c5426634e7929541eC2318f3dCF7e - Aave Pool:
0x6dcb6d1e0d487edae6b45d1d1b86e1a4ad8d4a2c - ETH/USD Price Feed:
0x71041dddad094ae566b4d4cd0fa6c97e45b01e60
- User approves USDC spending by the vault
- User deposits USDC into the vault
- Vault supplies USDC to AAVE v3
- Vault receives aUSDC tokens in return
- User receives vault shares representing their deposit
- User requests withdrawal of USDC
- Vault calculates the share of aUSDC to redeem
- Vault withdraws USDC from AAVE v3
- USDC is transferred to the user's wallet
- User's vault shares are burned
- Chainlink Keeper calls
checkUpkeep()at regular intervals - If health factor < threshold,
performUpkeep()is triggered - Vault automatically repays debt or adjusts collateral to maintain target health factor
- Transaction is submitted by the Keeper network
βββββββββββββββββββ βββββββββββββββ βββββββββββββββββ
β β β β β β
β AAVE Autopilot ββββββΊβ AAVE v3 ββββββΊβ Chainlink β
β Vault (ERC4626)β β Protocol β β Price Feeds β
β β β β β β
ββββββββββ¬βββββββββ βββββββββββββββ βββββββββββββββββ
β
β βββββββββββββββββββββββββββββββββ
β β β
βββΊβ Chainlink Keepers Network β
β (Automated Rebalancing) β
β β
βββββββββββββββββββββββββββββββββ
deposit(uint256 assets, address receiver)- Deposit USDC and receive vault sharesmint(uint256 shares, address receiver)- Mint vault shares by depositing USDCwithdraw(uint256 assets, address receiver, address owner)- Withdraw USDC by burning vault sharesredeem(uint256 shares, address receiver, address owner)- Redeem vault shares for USDC
checkUpkeep(bytes calldata)- Checks if the vault needs rebalancingperformUpkeep(bytes calldata)- Executes the rebalancing logicgetCurrentHealthFactor()- Returns the current health factorgetCurrentPosition()- Returns the current position details
pause()- Pause all deposits and withdrawals (emergency only)unpause()- Unpause the contractsetKeeper(address)- Update the keeper addresssetHealthFactorThresholds(uint256, uint256)- Update health factor thresholds
- Comprehensive test coverage (>85%)
- Automated security analysis with Slither and MythX
- Formal verification of critical functions
- Smart contract risks
- Oracle risks (price feed manipulation)
- AAVE protocol risks
- Keeper network reliability
- Pause functionality for critical issues
- Timelock for parameter updates
- Multi-sig admin controls
- Average deposit: ~150k gas
- Average withdrawal: ~180k gas
- Rebalancing: ~250k-500k gas (varies with position size)
Based on current AAVE v3 rates and historical performance:
- Estimated ETH APY: 2-4% (USDC supply)
- Additional yield from leverage: 3-6%
- Net APY after fees: 4-8%
- Complete security audit
- Deploy to ETH MAINNET
- Implement frontend dashboard
- Add multi-collateral support
- Cross-chain deployment (Optimism, Arbitrum)
- Advanced strategies (LP positions, yield optimization)
- DAO governance
- Permissionless strategy marketplace
- Advanced risk management
- Institutional features
-
Approve USDC for Deposit (if using Sepolia USDC):
cast send 0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8 \ "approve(address,uint256)" \ 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ 1000000 \ --private-key $PRIVATE_KEY \ --rpc-url $RPC_URL
-
Deposit USDC:
cast send 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ "deposit(uint256,address)" \ 1000000 \ 0xYourWalletAddress \ --private-key $PRIVATE_KEY \ --rpc-url $RPC_URL
-
Check Your Balance:
cast call 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ "balanceOf(address)(uint256)" \ 0xYourWalletAddress \ --rpc-url $RPC_URL
-
Withdraw USDC:
cast send 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ "withdraw(uint256,address,address)" \ 500000 \ 0xYourWalletAddress \ 0xYourWalletAddress \ --private-key $PRIVATE_KEY \ --rpc-url $RPC_URL
-
Check Total Assets:
cast call 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ "totalAssets()(uint256)" \ --rpc-url $RPC_URL
-
Check Health Factor:
cast call 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ "getHealthFactor()(uint256)" \ --rpc-url $RPC_URL
-
Check Keeper Status:
# Check if checkUpkeep returns true cast call 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ "checkUpkeep(bytes)(bool,bytes)" \ 0x \ --rpc-url $RPC_URL
-
Deposit Events:
cast logs --from-block 0 --to latest \ --address 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ --topic 0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7 \ --rpc-url $RPC_URL -
Withdraw Events:
cast logs --from-block 0 --to latest \ --address 0xA076ecA49434a4475a9FF716c2E9f20ccc453c20 \ --topic 0x5b8f46461c1dd69fb968f1a003acee221ea3e19540e350233b612ddb43433b55 \ --rpc-url $RPC_URL
-
Insufficient Gas:
- Ensure you have enough Sepolia ETH for gas fees
- Get test ETH from a Sepolia faucet
-
Transaction Reverted:
- Check the error message in the transaction receipt
- Verify token approvals and balances
- Ensure you're using the correct contract addresses
-
Keeper Not Triggering:
- Check if the contract has enough LINK
- Verify the upkeep is registered on Chainlink Keepers App
- Ensure
checkUpkeepreturnstrue
This project is licensed under the MIT License - see the LICENSE file for details.
For support or questions, please open an issue on GitHub.
- AAVE team for the amazing lending protocol
- Chainlink for price feeds and keepers
- OpenZeppelin for battle-tested contracts
### Test
```shell
$ forge test
$ forge fmt$ forge snapshot$ anvil$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>$ cast <subcommand>$ forge --help
$ anvil --help
$ cast --help