The basics of liquidation bots

I don’t understand liquidation bots, but I want to.

So I set out to figure out how they work.

I quickly found this medium article:

Creating a liquidation script for Aave DeFi protocol
And got liquidated to test it

I wanted to get a high level idea of how they work. After a little reading, this is what I understand so far. The basic algorithm looks like this:

  1. Watch a lot of vaults on Aave or Maker until you find one where the health of it goes below 1 (debt value > collateral value)
  2. Take a flashloan in the debt asset to liquidate the vault
  3. Collect the collateral at my ETH address
  4. Convert the collateral into the debt asset
  5. Pay off the flash loan

Conceptually, it’s that simple.

Practically, the difficulty lives in the execution.

First, write the bot that listens to vaults. Making this performant enough to be competitive with others will be a challenge.

Next, write the smart contract to handle the flashloan and repo work: borrow, collect, swap, repay, profit. This is actually straightforwardish.

After that, having your gas strategy dialed in to get your transaction through without being front-run is another amorphous challenge.

Without any experience yet, my guess is that getting the transaction through is probably quite difficult. At this point in time, lots of people know about this profit making strategy.

So even if you know the strategy and are capable of executing on it, as time goes on, it will get more and more difficult to spot a vulnerable loan and execute the liquidation before someone else does.

That being said, I think I’m going to get to work writing code and try to do something like this.

Show Comments