An open-source implementation of a simple liquidation bot for Revert Lend. This bot is designed to perform liquidations and also to serve as an example implementation for developers interested in building similar tools.
This bot monitors active positions on the Revert Lend protocol and executes liquidations when certain conditions are met. It uses a combination of WebSocket connections and periodic checks to stay updated on the state of the positions and the market.
Key features:
- WebSocket Monitoring: Listens to real-time events from the Uniswap contracts to update positions as their underlying value changes.
- Periodic Position Checks: Regularly checks all positions at set intervals.
- Flashloan Liquidations: Executes liquidations using flashloans, requiring no upfront capital in the asset being liquidated.
- Non-Flashloan Liquidations: Optionally supports liquidations without flashloans if the liquidator holds the necessary USDC and has approved the V3Vault contract.
Revert Lend contract is currently deployed on Arbitrum only:
- Node.js (v14 or higher)
- npm (v6 or higher)
- An Ethereum-compatible wallet with sufficient ETH on Arbitrum
- Access to Arbitrum RPC endpoints (both HTTP and WebSocket)
-
Clone the Repository
git clone https://github.com/revert-finance/liquidator-js.git cd liquidator-js
-
Install Dependencies
npm install
-
Create a
.env
FileBefore running the script, create a
.env
file in the root directory with the following configurations:PRIVATE_KEY_LIQUIDATOR=your_private_key_here RPC_URL_ARBITRUM=your_arbitrum_rpc_url_here WS_RPC_URL_ARBITRUM=your_arbitrum_websocket_url_here NETWORK=arbitrum
-
Optional: Non-Flashloan Liquidations
To enable non-flashloan liquidations:
-
Deposit the required amount of USDC into your liquidator account.
-
Approve the V3Vault contract to spend your USDC.
// Example approval script (ensure to customize token addresses and amounts) const USDC_CONTRACT = new ethers.Contract(USDC_ADDRESS, IERC20_ABI, signer); await USDC_CONTRACT.approve(V3_VAULT_ADDRESS, ethers.constants.MaxUint256);
-
Start the bot by running:
node index.js
The bot maintains an internal cache of active positions by:
- Loading all active positions on startup.
- Listening to events (
Add
,Remove
,Borrow
,Repay
,WithdrawCollateral
,IncreaseLiquidity
) to update positions in real-time.
Positions are checked for liquidation opportunities in two ways:
- Event-Driven Checks: When swap events on monitored uniswap pools are detected via WebSocket, the bot checks the affected positions immediately.
- Periodic Checks: Every 15 minutes, the bot performs a full scan of all positions to ensure no opportunities are missed with the swap events strategy.
When a position is eligible for liquidation:
- The bot estimates the liquidation value and prepares the necessary swap data using the Uniswap Universal Router.
- Flashloan Liquidations: The bot uses a flashloan to perform the liquidation without needing upfront USDC.
- Non-Flashloan Liquidations: If enabled, the bot can perform liquidations using its own USDC balance.
A few options can be configured in the index.js
file:
positionLogInterval
: Interval for logging low collateral factors (default is every 1 minute).enableNonFlashloanLiquidation
: Set totrue
to enable non-flashloan liquidations (default isfalse
).CHECK_INTERVAL
: Interval for periodic position checks (default is every 15 minutes).
- Gas Fees: Ensure your liquidator account has enough ETH on Arbitrum to cover gas fees.
- Security: Keep your private keys secure. Do not share or commit them to version control.
- Dependencies: The bot relies on several external services (e.g., RPC providers). Ensure your connections are reliable.
- Revert Lend Documentation: Docs
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License.
Disclaimer: Use this bot responsibly and at your own risk. The maintainers are not responsible for any financial losses incurred.