This project is an advanced Liquidator contract, built on top of Morpho Compound Mainnet and Morpho AaveV2 Mainnet.
This is not a competitive liquidation bot, but a liquidation bot that can be used to liquidate a large amount of collateral in a single transaction, without any funds needed other than gas fees.
You can use it at your own risks, or use it as a baseline and improve it.
The first version of the Liquidator contract uses a MakerDAO Flash loan of DAI, a supply/borrow on Compound or Aave, and a swap on Uniswap V3.
Installing dependencies:
nvm install && nvm use && yarnBuilding contracts:
yarn compileRunning tests:
yarn testTo deploy liquidator contracts, you must set the environements variables in a .env file:
PRIVATE_KEY: the private key of the account that will deploy the contracts.PROTOCOLS: The underlying protocols to use for the liquidator (comma separated list, aave and/or compound).ALCHEMY_KEY: the Alchemy key to connect to the Ethereum network.
And then run:
yarn deploy:contractsTo run a liquidation check, you just have to set the right environment variables, extracted from the .env.example file:
PRIVATE_KEY: the private key of the account that will be used to send the transactions. If not provided, you'll run the bot in read only mode. Your address must be an allowed liquidator of the flash liquidator contract. The two example addresses in the.env.examplefile are the ones of Morpho Labs.ALCHEMY_KEY: the Alchemy key to connect to the Ethereum network.LIQUIDATOR_ADDRESSES: a comma separated list of the liquidator contract addresses to use. Only used if you use the--flashoption.PROFITABLE_THRESHOLD: the liquidation threshold to use (in USD).BATCH_SIZE: The number of parallel queries sent to the Ethereum network.PROTOCOLS: The underlying protocols to use (comma separated list).DELAY: The delay between two liquidations check. If not provided, the bot will run only once.
Then, you can just run:
yarn run:botWithout the --flash option, the bot will use your wallet to liquidate without using any contract. In this case, you need to have
the funds to liquidate the user. Else, the script will throw an error.
yarn run:bot --flashIn order to use flash liquidation, you have to deploy the contracts first, and then set the LIQUIDATOR_ADDRESSES environment variable.
The script can throw an error and stop execution in some case, specially if you have a blockchain provider error, if you have not enough funds to send any transaction, or if you have not enough funds to liquidate the user with EOA mode.
To deploy the liquidation bot on AWS Lambda, you have to use the AWS SAM cli and Docker, and then running
sam build && sam deploy --guidedYou can customize the deployment by editing the template.yaml file.