The liquidator bot will be composed of different modules that will be responsible for different tasks.
This module will be responsible for collecting the data from the events emitted by the smart contract and storing it in a Redis cache.
The collector will store only open positions.
This module will be responsible for validating the open positions and marking them for liquidation.
The LiquidationChecker will use the liquidatable function from the smart contract to check if the position is liquidatable.
If a position is liquidatable, the liquidator will mark the position for liquidation in the Redis queue. Then the module will notify the executor to liquidate the position.
The executor will be pending for new liquidable positions in the Redis queue.
When a new liquidable position is found, the executor will call the liquidate function from the smart contract to liquidate the position.
Each module is a node.js application.
We will use docker compose to run all the modules and Redis.
- Install docker and docker-compose
- Set the environment variables in the
.env
file - Run
docker-compose build
to build the images - Run
docker-compose up
to run the modules
- Install node.js, docker, redis and pnpm
- Run
pnpm install
- Set the environment variables in the
.env
file for each module - Set redis to run in localhost. You can do this by running
docker run -p 6379:6379 redis
or installing redis in your machine. - You can test the modules separately by running
pnpm dev
in each module
RPC_URLS
: Comma separated list of RPC urlsREDIS_PASSWORD
: Redis passwordREDIS_HOST
: Redis hostMULTICALL_BATCH_SIZE
: Number of calls to make in a single multicall requestFORK_RPC_URL
: RPC url to use for forkingPRIVATE_KEYS_1
: Comma separated list of private keys for the first accountPRIVATE_KEYS_2
: Comma separated list of private keys for the second accountRPC_FIRST_PROBABILITY
: Probability of using the first RPC url in LiquidationChecker modulePOSITIONS_PER_RUN_*
: Number of positions to check in each cron runWORKERS_AMOUNT_*
: Number of workers to run in parallel for each cron jobCRON_SCHEDULE_*
: Cron schedule for each cron job
- add the address and deploy block of the market smart contract in the
constants.ts
file in thecollector
module - add the address of the market smart contract in the
constants.ts
file in theliquidationChecker
module - add the configuration for the market in the
config.ts
file in theliquidationChecker
module - create a new
liquidationChecker
intance in the docker-compose file