How to Manage Liquidation Risks with WatchTower
Using LiquidationMonitor to navigate volatile markets
In DeFi, one of the most exciting innovations is borrowing/lending: you can borrow instantly from a lending platform (such as AAVE, MakerDAO, and Solend) with super low fees, thanks to the efficiency of DeFi.
A major challenge here is that because the market is so volatile, your collateral value may drop quickly (even to a level below the value of your loan), and your collateral may be liquidated before you can repay your loan.
How to avoid being liquidated? WatchTower offers a LiquidationMonitor
that tracks the real-time Loan-to-Value Ratio (LTV) for any borrow position in a lending protocol, and alerts borrowers before their LTV can ever cross the liquidation threshold.
Users can configure a LTV safety ratio lower than the liquidation threshold, so that they will be notified by WatchTower much earlier than a liquidation can ever happen. For example:
WatchTower Alert! Bitcoin price dropped by 5% in the last hour. Your collateral on Solend is under risk to be liquidated (current LTV is 80%, liquidation happens at 85%). Pay your loan asap.
In the rest of this article, we describe how WatchTower LiquidationMonitor works, and show in particular how it monitors LTV ratios in real time.
Users can configure a LTV safety ratio lower than the liquidation threshold, so that they will be notified by WatchTower much earlier than a liquidation can ever happen. For example:
WatchTower Alert! Bitcoin price dropped by 5% in the last hour. Your collateral on Solend is under risk to be liquidated (current LTV is 80%, liquidation happens at 85%). Pay your loan asap.
In the rest of this article, we describe how WatchTower LiquidationMonitor works, and show in particular how it monitors LTV ratios in real time.
A few take-away messages:
WatchTower monitors Loan-to-Value Ratio (LTV) changes in real-time for any borrowed position on a lending protocol
WatchTower calculates LTV precisely based on real-time on-chain protocol-specific states and token prices
WatchTower supports multiple protocols on Solana already (Solend, Hedge and Hubble) and can be easily customized for other lending protocols and other chains
How does LiquidationMonitor work?
Although liquidation is a general concept, it is often implemented differently on different protocols with different parameters (e.g., loan fees, token pools, and thresholds).
LiquidationMonitor works by directly inspecting the on-chain states of each lending protocol. It calculates LTV of each borrowed position by decoding the account data. For instance, on Solend, each user’s borrowed positions correspond to an obligation account:
/// Lending market obligation state
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Obligation {
/// Version of the struct
pub version: u8,
/// Last update to collateral, liquidity, or their market values
pub last_update: LastUpdate,
/// Lending market address
pub lending_market: Pubkey,
/// Owner authority which can borrow liquidity
pub owner: Pubkey,
/// Deposited collateral for the obligation, unique by deposit reserve address
pub deposits: Vec<ObligationCollateral>,
/// Borrowed liquidity for the obligation, unique by borrow reserve address
pub borrows: Vec<ObligationLiquidity>,
/// Market value of deposits
pub deposited_value: Decimal,
/// Market value of borrows
pub borrowed_value: Decimal,
/// The maximum borrow value at the weighted average loan to value ratio
pub allowed_borrow_value: Decimal,
/// The dangerous borrow value at the weighted average liquidation threshold
pub unhealthy_borrow_value: Decimal,
}
From the obligation account’s data, we can decode its owner
, lending_market
, and all the deposits
and borrows
as well as their corresponding market value (deposited_value
and borrowed_value
).
Figure 2 shows a screenshot of WatchTower’s public dashboard on liquidation risks:
For example, for obligation account 3pAo, we can decode that its real-time deposited_value
is $4999.5003579 and borrowed_value
is $0. The LTV is 0% and hence its status is marked SAFE.
Consider the obligation account 7Xg2, its deposited_value
is $0.0069655917 and borrowed_value
is $0.0056941795. The LTV is 81% and its status is marked LIQUIDATE, because the liquidation threshold is 80% on the lending market 4UpD.
Consider another the obligation account 9Ecs in the above, its LTV is deposited_value/borrowed_value=$0.6167810228/0.8211451061=0.75
. Its status is marked RISK, because it is within 5% close to the liquidation threshold 80%. WatchTower will alert the account owner 6r8r when an obligation status turns into RISK.
To ensure the calculated LTV is accurate, LiquidationMonitor also tracks real-time changes to the account states by inspecting every transaction in the lending protocol, e.g., when a price oracle refresh transaction happens, or a borrow transaction or a loan repay transaction occurs on a user account, the LTV will be updated correspondingly.
How to use LiquidationMonitor?
LiquidationMonitor allows users to specify one or more borrow accounts on the supported lending protocols (e.g., Solend, Hedge and Hubble).
To create a LiquidationMonitor, click “Add bot”:
Configure the bot to monitor one or more accounts addresses:
Once the bot is setup, it will be running 7x24 and generating alerts:
About Sec3 (formerly Soteria)
sec3 is a security research firm that prepares Solana projects for millions of users. sec3’s Launch Audit is a rigorous, researcher-led code examination that investigates and certifies mainnet-grade smart contracts; sec3’s continuous auditing software platform, X-ray, integrates with Github to progressively scan pull requests, helping projects fortify code before deployment; and sec3’s post-deployment security solution, WatchTower, ensures funds stay safe. sec3 is building technology-based scalable solutions for Web3 projects to ensure protocols stay safe as they scale.
To learn more about sec3, please visit
https://www.sec3.dev