mirror of
https://github.com/lux-apps/papers.git
synced 2026-10-30 18:15:21 +00:00
Restructured from flat .tex/.pdf files into per-paper subdirectories. Added Antje Worring as co-author on all papers. Synced PDFs to pdfs/ for download site.
99 lines
3.4 KiB
TeX
99 lines
3.4 KiB
TeX
\section{Liquidation Engine}
|
|
|
|
|
|
\subsection{Liquidation Threshold Calculation}
|
|
|
|
A position becomes liquidatable when:
|
|
|
|
\begin{equation}
|
|
\text{Margin Ratio} = \frac{C - L_{\text{unrealized}} - F_{\text{accrued}}}{S} < M_{\text{maintenance}}
|
|
\end{equation}
|
|
|
|
where $L_{\text{unrealized}}$ is unrealized loss, $F_{\text{accrued}}$ is accrued funding, and $M_{\text{maintenance}}$ is maintenance margin ratio.
|
|
|
|
\begin{algorithm}
|
|
\caption{Multi-Tier Liquidation Process}
|
|
\begin{algorithmic}[1]
|
|
\STATE \textbf{function} liquidatePosition($\text{account}$, $\text{position}$)
|
|
\STATE $\text{marginRatio} \gets \text{calculateMarginRatio}(\text{position})$
|
|
\IF{$\text{marginRatio} \geq \text{maintenanceMargin}$}
|
|
\RETURN $\text{NotLiquidatable}$
|
|
\ENDIF
|
|
\STATE $\text{liquidationSize} \gets \text{position.size}$
|
|
\IF{$\text{position.size} > \text{partialLiquidationThreshold}$}
|
|
\STATE $\text{liquidationSize} \gets \text{position.size} \cdot \text{partialLiquidationRatio}$
|
|
\ENDIF
|
|
\STATE $\text{liquidationPrice} \gets \text{calculateLiquidationPrice}(\text{position})$
|
|
\STATE $\text{penalty} \gets \text{liquidationSize} \cdot \text{liquidationFee}$
|
|
\STATE $\text{remainingCollateral} \gets \text{position.collateral} - \text{penalty}$
|
|
\IF{$\text{remainingCollateral} < 0$}
|
|
\STATE $\text{insuranceFund} \gets \text{insuranceFund} + \text{remainingCollateral}$
|
|
\ENDIF
|
|
\STATE $\text{closePosition}(\text{position}, \text{liquidationSize}, \text{liquidationPrice})$
|
|
\STATE $\text{distributePenalty}(\text{penalty}, \text{liquidator}, \text{insuranceFund})$
|
|
\RETURN $\text{LiquidationSuccess}$
|
|
\end{algorithmic}
|
|
\end{algorithm}
|
|
|
|
\subsection{Automated Liquidation Bots}
|
|
|
|
Our keeper network ensures timely liquidations:
|
|
|
|
\begin{lstlisting}[caption={Liquidation Bot Implementation}]
|
|
contract LiquidationBot {
|
|
struct LiquidationCandidate {
|
|
address account;
|
|
bytes32 positionKey;
|
|
uint256 marginRatio;
|
|
uint256 expectedProfit;
|
|
}
|
|
|
|
function scanPositions() external view returns (LiquidationCandidate[] memory) {
|
|
LiquidationCandidate[] memory candidates;
|
|
uint256 count = 0;
|
|
|
|
for (uint256 i = 0; i < vault.positionKeysLength(); i++) {
|
|
bytes32 key = vault.positionKeys(i);
|
|
Position memory pos = vault.getPosition(key);
|
|
uint256 marginRatio = calculateMarginRatio(pos);
|
|
|
|
if (marginRatio < vault.maintenanceMargin()) {
|
|
candidates[count++] = LiquidationCandidate({
|
|
account: pos.account,
|
|
positionKey: key,
|
|
marginRatio: marginRatio,
|
|
expectedProfit: calculateLiquidationProfit(pos)
|
|
});
|
|
}
|
|
}
|
|
|
|
// Sort by profitability
|
|
return sortByProfit(candidates);
|
|
}
|
|
}
|
|
\end{lstlisting}
|
|
|
|
\subsection{Insurance Fund Mechanism}
|
|
|
|
The insurance fund absorbs losses from underwater positions:
|
|
|
|
\begin{equation}
|
|
\Delta I_t = \sum_{i \in L_t} \max(0, -C_i) + \alpha \cdot F_{\text{collected}}
|
|
\end{equation}
|
|
|
|
where $L_t$ is set of liquidated positions at time $t$, and $\alpha$ is insurance fund allocation ratio.
|
|
|
|
\subsection{Partial vs Full Liquidation}
|
|
|
|
Partial liquidation reduces cascade risk:
|
|
|
|
\begin{equation}
|
|
S_{\text{liquidate}} = \begin{cases}
|
|
S & \text{if } S < T_{\text{partial}} \\
|
|
\max(T_{\text{min}}, S \cdot r_{\text{partial}}) & \text{otherwise}
|
|
\end{cases}
|
|
\end{equation}
|
|
|
|
where $T_{\text{partial}} = \$100,000$, $T_{\text{min}} = \$10,000$, and $r_{\text{partial}} = 0.25$.
|
|
|