The Graph API
Aave Flash Loans
This project creates a liquidation bot that monitors aave loans for unhealthy ones and efficiently liquidates them to keep the aave protocol healthy. Identifying loans that would be profitable to liquidate is a challenging one as the costs involved are volatile including gas costs and swaps between the collateral asset and borrowed asset.
How It's Made
This project is composed of two distinct parts, the first is the monitor which watches for unhealthy loans and triggers a liquidation.The second is the liquidator which is responsible for all of the transactions involved with liquidating the loan. Monitor: A node.js app that queries theGraph to get all loan information. It then calculates which are unhealthy and their bonus payment, and then estimates costs & profits. Costs include retrieving current gas prices using gasnow.org, and calculating the optimal swap path & price via uniswap for converting the bonus payout in the collateral back to the token used for the flashloan. If profitable initiate a liquidation by calling the custom built Liquidator solidity contract. Liquidator Solidity Contract: Initiates an aave flash loan for the tokens needed to liquidate the unhealthy loan, liquidates the loan, then uses uniswap to swap collateral tokens back to tokens used for the flash loan (via the path provided by the monitor). Then pays back the flash loan & sends the profit back to the owner's address. Takeaways My biggest accomplishment was making this bot capable of liquidating any token pair on Aave. This meant dynamically calculating swap paths for uniswap. The algorithm for calculating paths was fairly challenging to create and where I spent most of my time. Also, this was my first time building a solidity contract and it was surprisingly straight forward.