Skip to content

crisog/morpho-liquidator

Repository files navigation

Morpho logo

Morpho Liquidator 🤖

Liquidation Bot designed for Morpho Blue


Getting Started

  1. Install the dependencies
yarn install

For CI:

yarn install --frozen-lockfile
  1. Configure the environment variables
ETH_RPC_URL=https://ethereum-public.nodies.app
BASE_RPC_URL=https://base-public.nodies.app
SEPOLIA_RPC_URL=https://sepolia-public.nodies.app

ETH_WALLET_PRIVATE_KEY=<YOUR_NON_PRODUCTION_PRIVATE_KEY>

❗❗❗ IMPORTANT: Do not use production/mainnet private keys in your .env ❗❗❗

  1. Configure the bot's settings on our index file.
const config: BotConfig = {
  chainId: 1, // Ethereum Mainnet
  cronSchedule: "*/10 * * * * *", // Runs every 10 seconds
  timeZone: "America/Los_Angeles",
  maxSlippage: 50, // this is scaled by 10000, so 50 is 0.5%
  maxImpact: 2, // this is scaled by 100, so 2 is 2%
  swapFromToken: USDC_TOKEN_MAINNET,
  swapToToken: USDC_TOKEN_MAINNET,
  minProfit: 500, // in USD
};
  1. Run the bot 🤖
yarn start

Features

  • Fetches whitelisted markets from Morpho API
  • Fetches liquidatable positions from Morpho API
  • Swaps configurable asset to obtain loan tokens
  • Checks existing allowances before approving tokens
  • Liquidates profitable positions in Morpho Blue
  • Swaps liquidated collateral tokens for configurable asset
  • Flashbots Provider integration ⚡️🤖
  • Periodical execution via cron job
  • Chain, swap slippage and swap max impact are configurable

Considerations

  • This bot supports the following networks: Ethereum Mainnet, Ethereum Sepolia and Base Mainnet
  • This bot has been tested on Sepolia, you can track the bot interactions here.
  • This bot only executes full liquidations, but it can be modified to use a different strategy (i.e. partial liquidations)
  • This bot can run in Sepolia, however, the swaps won't be executed because ParaSwap is not available on Sepolia. It will only fully liquidate the position; and it will not sell the seized collateral or calculate profits.
  • The scripts used to deploy the contracts (oracle, tokens) and send the supply collateral/borrow transactions can be found here.

Roadmap

  • Integrate a new indexer for positions morpho-markets
  • Smart contracts executed liquidation w/ flash loans
  • Add support for AWS Secrets Manager to pull private keys from it
  • Reth Extension (ExEx) for live tracking of liquidatable positions as indexer

Credits

Morpho's liquidation bot example was a valuable reference for developing this bot, along with Morpho's docs.

About

Morpho Blue Liquidator Bot

Resources

License

Stars

Watchers

Forks