# Trading Mechanics

## Liquidation                        &#x20;

The price at which liquidation occurs is a function of asset qty \[Q], avg entry price \[E], collateral \[C], closing + funding fees \[F], and a slippage risk factor \[f] (1% for non-Forex assets and 0.3% for Forex assets) which accounts for a built-in safety net to protect the protocol from losses on a position exceeding collateral.&#x20;

Allowed losses \[A] on a position at which point the position is liquidated are determined by:&#x20;

$$
A =C- (F+fQE)
$$

Likewise, the liquidation price \[L] is calculated as follows:

$$
L=\begin{cases} E-\frac{A}{Q} &\text{if } LONG \ E+\frac{A}{Q} &\text{if } SHORT\end{cases}
$$

If liquidated, the trader will be returned a portion of their collateral based on the slippage \[S] which represents the difference between $$L$$ and the price at which the position actually gets liquidated. The collateral returned $$C\_R$$ to the trader is:

$$
C\_R = Q(fE-S)
$$

For example, assume a BTC/USD Long trade of qty 1.25 $BTC using $1000 collateral. The avg entry price is 16,000 and total closing fees are $20.  The corresponding liquidation price is 15,376; however, due to rapid price decline near liquidation price, the position isn't forced closed until a price of 15,350 resulting in a slippage of 26.00.  In this case, a total of $167.50 would be returned to the trader.

Notice in the example above, a slippage of up to $$fE=160.00$$ could be absorbed without the protocol (CLP Vault) suffering any losses.\
\
Besides the Crust team's liquidation wallet, it is also possible for anybody to trigger a liquidation. However, currently 100% of the liquidations goes to the CLP vault as a reward for providing the liquidity.

## Open Interest Limits

Open Interest (OI) limits for both Longs and Shorts are established to protect the protocol from total OI exceeding TVL (in this case CLP backed liquidity).  These limits, for each tradable asset, are based on a percentage of TVL at both the user and asset level.  The starting default rates are shown in the table below.  These rates may change in the future as risk profiles vary by asset.

<table data-view="cards"><thead><tr><th>Asset</th><th>Per User (long/short)</th><th>Per Asset (long/short)</th></tr></thead><tbody><tr><td>WBTC/USD</td><td>1.0%/1.0%</td><td>15.0%/15.0%</td></tr><tr><td>WETH/USD</td><td>0.75%/0.75%</td><td>15.0%/15.0%</td></tr><tr><td>DOGE/USD</td><td>0.25%/0.25%</td><td>2.5%/2.5%</td></tr><tr><td>SHIB/USD</td><td>0.25%/0.25%</td><td>2.5%/2.5%</td></tr><tr><td>EUR/USD</td><td>1.0%/1.0%</td><td>10.0%/10.0%</td></tr><tr><td>USDT MCAP</td><td>0.5%/0.5%</td><td>5.0%/5.0%</td></tr></tbody></table>

## Funding Rate

A funding rate $$R$$ is put in place for each side of each asset to incentivize traders to keep the total position size from diverging significantly with traders total collateral, thus providing further risk mitigation measures for the protocol. Funding rate is dynamically updated for each asset every funding interval (1 hour) and calculated as follows:

$$
R=k\left(\dfrac{Open Position Size}{Open CollateralSize}\right)
$$

$$k$$ is a parameter that is a function of each assets historical volatility and is updated regularly as market conditions change.&#x20;

The funding fees $$F\_f$$ are paid out upon closing the position.  They are calculated based on ones position size $$P$$ at the start of each funding interval and how many hours $$t$$ the position has been opened, rounded up.

$$
F\_f=\sum\_{i=1}^tP\_iR\_i
$$
