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
.envfile - Run
docker-compose buildto build the images - Run
docker-compose upto run the modules
- Install node.js, docker, redis and pnpm
- Run
pnpm install - Set the environment variables in the
.envfile for each module - Set redis to run in localhost. You can do this by running
docker run -p 6379:6379 redisor installing redis in your machine. - You can test the modules separately by running
pnpm devin 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
The liquidator supports multiple factory and state contract configurations:
-
Original Factory:
0xC35093f76fF3D31Af27A893CDcec585F1899eE54- State Contract:
0x10575a9C8F36F9F42D7DB71Ef179eD9BEf8Df238 - Markets: All existing markets including v2 variants (BTC/USD, ETH/USD, SOL/USD, etc.)
- State Contract:
-
Gambling Factory:
0x5e6613da86099c264ef9cd56c142506bbf642825- State Contract:
0x6fecbf42b2dcf4bfd3c1c60dcd956247f4abd35e - Markets: "Double or Nothing"
- State Contract:
Each market is associated with a specific factory, and the liquidation checker automatically uses the correct state contract based on the market's factory address.
Run pnpm run add-market and follow the prompts; the helper updates all required files automatically and will ask you to select which factory the market belongs to.
If you prefer to do it manually:
- add the address, deploy block, and factory address of the market smart contract in the
constants.tsfile in thecollectormodule - add the configuration for the market in the
config.tsfile in theliquidationCheckermodule, including the factory address - create a new
liquidationCheckerinstance in the docker-compose file