AavePM - Aave Position Manager


🧪 ALPHA TESTING PHASE 🧪


1. Overview

Docs Site: https://eridianalpha.github.io/aave-position-manager

A smart contract manager for Aave positions.

  1. Set a desired Health Factor.
  2. Send assets (ETH, WETH, wstETH, or USDC) to the contract.
  3. Reinvest and rebalance the position to maintain the desired Health Factor, either manually or with a bot.
  4. Borrow and withdraw USDC from the position while maintaining the desired Health Factor.

1.1. Key Functions

1.1.1. Owner Functions

FunctionRestrictionsDescription
upgradeToAndCallOWNER_ROLEUpgrade the contract.
updateContractAddressOWNER_ROLEUpdate the specified contract address.
updateTokenAddressOWNER_ROLEUpdate the specified token address.
updateUniswapV3PoolOWNER_ROLEUpdate the specified Uniswap V3 pool.
updateManagerDailyInvocationLimitOWNER_ROLEUpdate the daily invocation limit for the manager role.

1.1.2. Manager Functions

FunctionRestrictionsDescription
rebalanceMANAGER_ROLERebalance the Aave position to the desired Health Factor.
reinvestMANAGER_ROLEReinvest the Aave position to the desired Health Factor target.
deleverageMANAGER_ROLEDeleverage the Aave position by paying back all reinvested debt.
aaveSupplyFromContractBalanceMANAGER_ROLESupply all the collateral from the contract balance to Aave.
aaveRepayUSDCFromContractBalanceMANAGER_ROLERepay Aave position debt using all the USDC from the contract balance.
withdrawTokensFromContractBalanceMANAGER_ROLEWithdraw all the specified tokens from the contract to the specified owner.
aaveBorrowAndWithdrawUSDCMANAGER_ROLEBorrow USDC from Aave and withdraw to the specified owner.
aaveWithdrawWstETHMANAGER_ROLEWithdraw wstETH collateral from the Aave position to the specified owner.
aaveClosePositionMANAGER_ROLEClose the Aave position by repaying all debt and withdrawing all collateral to the specified owner.
updateHealthFactorTargetMANAGER_ROLESet the desired Health Factor target.
updateSlippageToleranceMANAGER_ROLESet the slippage tolerance for Uniswap V3 swaps.
rescueEthMANAGER_ROLERescue ETH from the contract to the specified owner.
delegateCallHelperMANAGER_ROLEExecute a delegate call to the specified module.

2. WebApp

A WebApp is being developed to allow easy interaction with the smart contract and will be linked here when available.

3. Installation

3.1. Clone repository

git clone https://github.com/EridianAlpha/aave-position-manager.git

3.2. Install Dependencies

This should happen automatically when first running a command, but the installation can be manually triggered with the following commands:

git submodule init
git submodule update
make install

3.3. Create the .env file

Use the .env.example file as a template to create a .env file.

3.4. Configure Ethernal (optional)

Configure an Ethernal account to interact with the smart contract through a UI. Ethernal is like Etherscan but for a custom network.

https://docs.eridianalpha.com/ethereum-dev/useful-tools/ethernal

make ethernal

4. Testing

4.1. Tests (Fork)

make test-fork
make test-fork-v
make test-fork-summary

4.2. Coverage (Fork)

make coverage
make coverage-report

5. Deployment

Deploys AavePM and all modules to the Anvil chain specified in the .env file.

ChainCommand
Anvilmake deploy anvil
Base Sepoliamake deploy base-sepolia
Base Mainnetmake deploy base-mainnet

6. Upgrades

Upgrade the contract to a new logic implementation while maintaining the same proxy address. This also redeploys all modules and updates their contract addresses on AavePM.

ChainCommand
Anvilmake upgrade anvil
Base Sepoliamake upgrade base-sepolia
Base Mainnetmake upgrade base-mainnet

7. Interactions

Interactions are defined in ./script/Interactions.s.sol

If DEPLOYED_CONTRACT_ADDRESS is set in the .env file, that contract address will be used for interactions. If that variable is not set, the latest deployment on the specified chain will be used.

7.1. Grant Role

Grant a role to an address. Requires the caller to be an admin of the role being granted. Input value 1 as a role e.g. MANAGER_ROLE. Input value 2 as an address e.g. 0x123.... Combined input value e.g. MANAGER_ROLE,0x123....

ChainCommand
Anvilmake grantRole anvil
Base Sepoliamake grantRole base-sepolia
Base Mainnetmake grantRole base-mainnet

7.2. Revoke Role

Revoke a role from an address. Requires the caller to be an admin of the role being revoked. Input value 1 as a role e.g. MANAGER_ROLE. Input value 2 as an address e.g. 0x123.... Combined input value e.g. MANAGER_ROLE,0x123....

ChainCommand
Anvilmake revokeRole anvil
Base Sepoliamake revokeRole base-sepolia
Base Mainnetmake revokeRole base-mainnet

7.3. Fund contract with ETH

Input value in ETH e.g. 0.15.

ChainCommand
Anvilmake send-ETH anvil
Base Mainnetmake send-ETH base-mainnet

7.4. Update Health Factor Target

Input value to 2 decimal places e.g. 225 for a Health Factor target of 2.25.

ChainCommand
Anvilmake update-hft anvil
Base Mainnetmake update-hft base-mainnet

7.5. Update Slippage Tolerance

Input value to 2 decimal places e.g. 200 for a Slippage Tolerance of 0.5%.

ChainCommand
Anvilmake update-st anvil
Base Mainnetmake update-st base-mainnet

7.6. Rebalance Aave Position

Rebalances the Aave position to maintain the desired Health Factor target. REBALANCE_HFT_BUFFER is a constant in the module that determines if a rebalance is required.

ChainCommand
Anvilmake rebalance anvil
Base Mainnetmake rebalance base-mainnet

7.7. Reinvest collateral

Reinvests any collateral above the Health Factor target. REINVEST_HFT_BUFFER is a constant in the module that determines if a reinvest is required.

ChainCommand
Anvilmake reinvest anvil
Base Mainnetmake reinvest base-mainnet

7.8. Supply from contract balance to Aave

Supplies any ETH, WETH, wstETH, or USDC in the contract to Aave.

ChainCommand
Anvilmake supply anvil
Base Mainnetmake supply base-mainnet

7.9. Repay USDC from contract balance

Repay any USDC debt in the contract to repay Aave position debt.

ChainCommand
Anvilmake repay anvil
Base Mainnetmake repay base-mainnet

7.10. Close Position

Close the Aave position by repaying all debt and withdrawing all collateral. Input value as an owner address. e.g. 0x123....

ChainCommand
Anvilmake closePosition anvil
Base Mainnetmake closePosition base-mainnet

7.11. Withdraw wstETH to owner

Withdraw wstETH collateral from the Aave position to the specified owner. Input value 1 in ETH e.g. 0.15. Input value 2 as an owner address e.g. 0x123.... Combined input value e.g. 0.15,0x123....

ChainCommand
Anvilmake withdrawWstETH anvil
Base Mainnetmake withdrawWstETH base-mainnet

7.12. Withdraw Token to owner

Withdraw the specified token from the contract to the specified owner. Input value 1 in token identifier e.g. USDC. Input value 2 as an owner address e.g. 0x123.... Combined input value e.g. USDC,0x123....

ChainCommand
Anvilmake withdrawToken anvil
Base Mainnetmake withdrawToken base-mainnet

7.13. Borrow USDC and send it to an owner

Borrow USDC from Aave and withdraw to the specified owner. Input value 1 in USDC e.g. 200 for $200 USDC. Input value 2 as an owner address e.g. 0x123.... Combined input value e.g. 200,0x123....

ChainCommand
Anvilmake borrowUSDC anvil
Base Mainnetmake borrowUSDC base-mainnet

7.14. Get Contract Balance

Input value as token identifier e.g. USDC.

ChainCommand
Anvilmake getContractBalance anvil
Base Mainnetmake getContractBalance base-mainnet

7.15. Get Aave Account Data

Returns the Aave account data for the contract.

ChainCommand
Anvilmake getAaveAccountData anvil
Base Mainnetmake getAaveAccountData base-mainnet

8. Build and Deploy Documentation

Instructions on how to build and deploy the documentation book are detailed here: https://docs.eridianalpha.com/ethereum-dev/foundry-notes/docs-and-github-pages

9. License

MIT