Announcing the Open-Source Liquidation Bot for Vesu

Announcing the Open-Source Liquidation Bot for Vesu

We're thrilled to announce that we've developed a fully open-source liquidation bot for Vesu, the Starknet modular lending protocol. You can check it out and use it on GitHub.

The Short Story

With the volatility observed in the market at the beginning of August 2024, a few positions on Vesu came close to liquidation, and some even had to be liquidated. As long-term partners with Vesu, we wanted to keep the protocol and its users safe by monitoring and processing the liquidations on the positions at risk to avoid bad debt. However, we realized that no open-source code was available to do so, and the barrier to entry for anyone to keep the protocol safe was too high.

That's why we decided to build the first open-source liquidation bot for Vesu, allowing anyone to run it and keep the protocol safe. It's also a great building block for anyone who wants to build a more performant bot for anything MEV-related on Starknet. It is now ready to be used, and we'll keep adding improvements to it, including new lending protocols and overall support for our long-term partners in keeping their users safe. We also welcome anyone to contribute and bring improvements to this great piece of software.

How It Works

Here's a high-level overview of how the liquidation bot works:

  1. The indexer retrieves all open positions on Vesu from the protocol's creation to the current state using Apibara. It sends it to the monitoring service, which stores these positions locally, so once the bot is launched, it doesn't have to re-index the positions.
  2. The bot gets the oracle price on-chain thanks to the Pragma API, which is an indexing service built to get the Pragma on-chain prices off-chain.
  3. The bot then checks the health factor of each position, which is the risk-adjusted collateral divided by the liabilities:
  1. If the health factor is less than one, it means that the liabilities are bigger than the risk-adjusted collateral, so we can liquidate the position. Vesu supports full liquidation on the current pools, which means we can liquidate the full position.
  2. The monitoring service uses Ekubo's flash loans to borrow the debt asset. It then repays the debt discounted by the liquidation factor, receives the collateral in exchange, swaps the collateral for the debt asset, repays Ekubo, and pockets the extra debt asset left.

And that's it. The liquidation contract is under audit, and should be production ready in the following weeks, ready for you to use in production. We welcome contributions, issues, and comments on this repository. Feel free to contact us if you need help setting this up.r

Another important point: we've added functionality for partial liquidations. This feature is useful if you want to reuse this bot on other protocols or if new pools on Vesu are created with partial liquidation support.

The process is identical, but after computing the health factor, the monitoring service determines how much to liquidate. It uses an equation specific to Vesu's liquidation process. We aim to restore the health factor to 1.001 (slightly above 1). We then account for the liquidation effect on both sides:

  • The numerator (risk-adjusted collateral) after liquidation is: collateral minus the liquidated amount, multiplied by the LLTV.
  • The liabilities become: debt minus the amount liquidated.

We then develop and isolate L to get the amount to liquidate:

Finally, the bot executes the flash swap and repays only the amount needed to bring the position back to an acceptable health factor.

We hope this bot will be useful to many of you, and we're excited to see what the community will build on top of it.


Join the conversation! Follow Pragma on Twitter for updates, and connect with our community on Telegram.
Be part of the DeFi future 🧩