Skip to content

Latest commit

 

History

History
326 lines (238 loc) · 13.3 KB

README.md

File metadata and controls

326 lines (238 loc) · 13.3 KB

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

Function Restrictions Description
upgradeToAndCall OWNER_ROLE Upgrade the contract.
updateContractAddress OWNER_ROLE Update the specified contract address.
updateTokenAddress OWNER_ROLE Update the specified token address.
updateUniswapV3Pool OWNER_ROLE Update the specified Uniswap V3 pool.
updateManagerDailyInvocationLimit OWNER_ROLE Update the daily invocation limit for the manager role.

1.1.2. Manager Functions

Function Restrictions Description
rebalance MANAGER_ROLE Rebalance the Aave position to the desired Health Factor.
reinvest MANAGER_ROLE Reinvest the Aave position to the desired Health Factor target.
deleverage MANAGER_ROLE Deleverage the Aave position by paying back all reinvested debt.
aaveSupplyFromContractBalance MANAGER_ROLE Supply all the collateral from the contract balance to Aave.
aaveRepayUSDCFromContractBalance MANAGER_ROLE Repay Aave position debt using all the USDC from the contract balance.
withdrawTokensFromContractBalance MANAGER_ROLE Withdraw all the specified tokens from the contract to the specified owner.
aaveBorrowAndWithdrawUSDC MANAGER_ROLE Borrow USDC from Aave and withdraw to the specified owner.
aaveWithdrawWstETH MANAGER_ROLE Withdraw wstETH collateral from the Aave position to the specified owner.
aaveClosePosition MANAGER_ROLE Close the Aave position by repaying all debt and withdrawing all collateral to the specified owner.
updateHealthFactorTarget MANAGER_ROLE Set the desired Health Factor target.
updateSlippageTolerance MANAGER_ROLE Set the slippage tolerance for Uniswap V3 swaps.
rescueEth MANAGER_ROLE Rescue ETH from the contract to the specified owner.
delegateCallHelper MANAGER_ROLE Execute 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.

Chain Command
Anvil make deploy anvil
Base Sepolia make deploy base-sepolia
Base Mainnet make 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.

Chain Command
Anvil make upgrade anvil
Base Sepolia make upgrade base-sepolia
Base Mainnet make 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....

Chain Command
Anvil make grantRole anvil
Base Sepolia make grantRole base-sepolia
Base Mainnet make 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....

Chain Command
Anvil make revokeRole anvil
Base Sepolia make revokeRole base-sepolia
Base Mainnet make revokeRole base-mainnet

7.3. Fund contract with ETH

Input value in ETH e.g. 0.15.

Chain Command
Anvil make send-ETH anvil
Base Mainnet make 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.

Chain Command
Anvil make update-hft anvil
Base Mainnet make 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%.

Chain Command
Anvil make update-st anvil
Base Mainnet make 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.

Chain Command
Anvil make rebalance anvil
Base Mainnet make 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.

Chain Command
Anvil make reinvest anvil
Base Mainnet make reinvest base-mainnet

7.8. Supply from contract balance to Aave

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

Chain Command
Anvil make supply anvil
Base Mainnet make supply base-mainnet

7.9. Repay USDC from contract balance

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

Chain Command
Anvil make repay anvil
Base Mainnet make 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....

Chain Command
Anvil make closePosition anvil
Base Mainnet make 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....

Chain Command
Anvil make withdrawWstETH anvil
Base Mainnet make 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....

Chain Command
Anvil make withdrawToken anvil
Base Mainnet make 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....

Chain Command
Anvil make borrowUSDC anvil
Base Mainnet make borrowUSDC base-mainnet

7.14. Get Contract Balance

Input value as token identifier e.g. USDC.

Chain Command
Anvil make getContractBalance anvil
Base Mainnet make getContractBalance base-mainnet

7.15. Get Aave Account Data

Returns the Aave account data for the contract.

Chain Command
Anvil make getAaveAccountData anvil
Base Mainnet make 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