Tutorial: Liquidation Bot
Introduction
Liquidation Bots improve the overall health of the protocol by deleveraging users approaching bankruptcy.
The liquidation in the protocol is a liability transfer mechanism from the selected liquidatee (user in liquidation territory) to the liquidator (the user running the Liquidation Bot).
Liquidators inherit the liabilities they liquidate and receive an asset at a discount for doing so. In order to participate, liquidators must have even collateral in their account in order to satisfy the initial margin requirements for the transferred positions.
For more information on our liquidation system, please read Liquidations.
Getting Started
Step 1: Understand liquidation mechanics
Liquidations transfer liability from the liquidated account to the liquidator.
Step 2: Choose a reference implementation
The canonical implementations in keeper-bots-v2 are:
src/bots/liquidator.tssrc/bots/liquidatorDerisk.ts(derisk helper)
Step 3: Prepare the environment
Follow the base keeper setup first:
Liquidator bots require collateral. Make sure the wallet is funded and has USDC deposited.
Step 4: Run and tune
Run the liquidator bot via your keeper-bots-v2 config and monitor:
- RPC latency / timeouts
- Competing liquidators
- Position risk and exposure
Step 5: Iterate and harden
Common improvements include:
- Filtering markets or subaccounts
- Using derisk strategies
- Adding guardrails for exposure and max size
Advanced
If you’re interested to make the liquidator bot run better, you can make edits to the above to improve its efficiency. In particular, you can:
-
Sort users in an efficient data structure based on their liquidation price;
-
Monitor the market’s price to determine when to run liquidation checks / RPC checks.
We encourage the community to build out stronger liquidations engines and bots to secure our Insurance Fund and user collateral. If interested to chat or have any questions, please reach out to us on Discord or Twitter !