A self-deployed DeFi strategy for Leveraged Reborrowing (borrow-supply loop) of a single supported asset (such as USDC) on Aave to maximize yield.
Cross-asset loops are not (yet?) supported.
All funds are fully controlled by the contract owner, as provided to the constructor at deployment.
All values are immutable, contract is only accesible to owner, with the exception of claimRewardsToOwner
which can be called by anyone.
Supported networks:
- Ethereum
- Avalanche
- Polygon
Use at your own risk
Run test on a mainnet fork with Hardhat:
npm install
npm run build
npm run test
npm run test:avax
npm run test:poly
- Clone and initialize the repo:
git clone
- create a .config.json file in root with keys as shown below
npm install
npm run build
- Enter your infura/alchemy endpoint in
hardhat.config.ts
undernetworks.eth.url
- Create a new temporary address with a mnemonic generator and import the private key to metamask
- Send enough ETH for deployment to the temp address
npm run deploy eth
and follow the prompts- The deploy script will take care of everything, after deployment send any leftover funds back and burn the temp private keys
- A backup is created under
./deployments
just in case - The contract is ready to be used by the owner
- To add custom abi to etherscan, use the ABI in
deployments/*/artifacts/contracts/AaveLoop.sol/AaveLoop.json
{
"NODE_URL_ETH": "",
"NODE_URL_POLY": "",
"NODE_URL_AVAX": "",
"coinmarketcapKey": "",
"ETHERSCAN_ETH": "",
"ETHERSCAN_POLY": "",
"ETHERSCAN_AVAX": ""
}
- Owner owns the contract and the funds inside. Can enter, exit and withdraw.
It's recommended to take the ABI created during deployment and upload it as private custom ABI to Etherscan and this way we can easily use Etherscan's read/write interface without publishing the contract source. (pass false at contract deployment to skip source upload).
- Call
getPositionData
orgetLiquidity
to monitor liquidity decrease over time. - If
healthFactor < 1e18
orliquidity = 0
the position will be liquidated! it is recommended not to go below0.5%-1%
of the principal.
If exitPosition
fails due to hittin gas limit, exit can be done manually:
- Using a lower number in iterations. Partial exits are supported, will de-leverage but stay in position
- Using multiple manual rollback transactions
- The owner of the contract can also execute an arbitrary transaction using
emergencyFunctionCall
oremergencyFunctionDelegateCall
. Check the tests. - By sending more of the asset to the contract before running
exitPosition
again, this will reduce the number of exit iterations