Market depth

This estimation determines how much mrgnlend liquidators could offlay based on available liquidity. Today, only Solana liquidity is considered. In the future, additional defi and cefi ecosystems will be included. Price impact bands are calculated based on a series of smoothing functions, focused on being conservative when liquidity estimates are trending upwards and quickly responsive when liquidity estimates are trending down. This calculation is done per asset.
A few steps are involved:

Historical data time window

Overall, risk engines primarily rely on 90-day historical data, leveraging and

Liquidatory profitability threshold

A profitable sliippage threshold
is set based on the liquidator fee mrgnlend awards liquidators for their service,
. Today,
is fixed at 2.5%, but will likely be dynamic in the future to further improve liquidator incentives.
ht=I(s,f)h_{t} = I(s,f)
the amount of liquidity bought or sold
slippage from the sale or purchase

Conservative smoothing

A number of moving averages are calculated over a spectrum of time windows. Every combination of the following is calculated:

Moving averages used

  • Simple moving average (SMA)
  • Exponential moving average (EMA)
  • Triangular moving average (TMA)

Rolling time windows used

  • 1D
  • 7D
  • 14D
  • 28D
The minimum of the above averages is taken for a conservative perspective over each time window. This allows smooth- ing algorithms to mitigate noise in the data but continue to be sensitive to lower thresholds of liquidator capacity further in the past (e.g. SMA), during intermediary points of history (e.g. TMA), and more recently (e.g. EMA):
MA1(k)=min(SMA28d(k),EMA28d(k),TMA28d(k)),\text{MA}_1(k) = \min(\text{SMA}_{\text{28d}}(k), \text{EMA}_{\text{28d}}(k), \text{TMA}_{\text{28d}}(k)),
k={ht,,htw}k = \{h_t, \ldots, h_{t-w}\}
is the full rolling window used.

Double smoothing application

The data is smoothed again, and mean and median are calculated over an additional array of rolling time windows:
  • 6H
  • 12H
  • 1D
  • 2D

Variability discounting

Both the rolling mean and median are then discounted by a factor based on the variability of the data, as a further conservative measure. The discount factor is based off of the coefficient of variation and can be expressed as the following:
df28d=10.05×(CVmin(CV)max(CV)min(CV)),df_{\text{28d}} = 1 - 0.05 \times \left(\frac{\text{CV} - \min(\text{CV})}{\max(\text{CV}) - \min(\text{CV})}\right),
CV=σ28d,tSMA28d(k), σ28d,t=128i=t27t(xiμ28d,t)2\text{CV} = \frac{\sigma_{28d, t}}{\text{SMA}_{28d}(k)}, \text{ } \sigma_{28d, t} = \sqrt{\frac{1}{28}\sum_{i=t-27}^{t}(x_i - \mu_{28d, t})^2}\\
The discount factor adjusts the values in the dataset based on their relative variability. Smaller values of the discount factor indicate higher variability and lower significance, while larger values indicate lower variability and higher significance.
The minimum of the mean and median is taken, then discounted.
MA3(m)=min(MA2(m))df28d\text{MA}_3(m) = min(\text{MA}_2(m)) \cdot df_{\text{28d}}

Threshold stabilization

This discounted minimum is then rounded to the nearest
USD-valued range so as to translate the data into actionable risk parameters that can be factored into on-chain protocol updates that should happen relatively infrequently. Finally,
L=rMA3(m)r+0.5\text{L} = r \cdot \lfloor \frac{\text{MA}_3(m)}{r} + 0.5 \rfloor
The mode of
is taken of the last
days to arrive at a more stable persepctive on profitability threshold. Currently,
is 3 days.