What happened?

Beginning at roughly 11:30 AM UTC+8 on April 18, 2021, a flash crash affected the ETH/USDC market on Perpetual Protocol. Following a period of high volatility on both centralized and decentralized markets, we saw a period of instability across all exchanges as the price of ETH dropped significantly.

What resulted was a cascade of liquidations of large and highly levered positions — the price reached a low of nearly $870 USD before recovering back to the market price.

Price of ETH/USDC perpetual on Binance during the same period, with a low of $1900.

Perpetual Protocol Team Response

The team takes flash crashes very seriously and had already begun rolling out updates after the previous BTC flash crash at the end of February.

However, due to the nature of how smart contracts are developed, the updates were not yet deployed to mainnet due to undergoing audits by our third party auditors. It is extremely unfortunate that the audits were completed on the Friday just prior to this latest incident.

The team will always strive to ensure that all code is audited, tested and very well thought through to ensure that exploits and edge cases are caught and handled before deployment to a live environment. However, we also understand the need to move faster in deploying critical updates and will work harder in the future to ensure that we find the right balance between being thorough in our engineering and nimble in our deployments.

Below is an updated list of all of the changes we have planned.

Key takeaway

The Perpetual Protocol team is committed to minimizing risk of all kinds, including the risk of flash crashes. We will implement any measure we believe can help to avoid or mitigate flash crashes.

However, no exchange can honestly promise 100% resistance to flash crashes. This is especially true of a DEX, where trading occurs 24/7 with no possibility of halt or shutdown.

As such, we are currently talking with insurance providers to obtain coverage for traders affected by future flash crashes, if and when they occur.

A series of changes intended to reduce the frequency and severity of flash crashes is outlined below. If you have further questions about these measures, please come to our Discord to discuss — https://discord.perp.fi/

Changes planned

Growing the userbase
A key cause of flash crashes is lack of traders. If more traders are on the platform, a dump in price will be quickly bought up, halting a crash before it becomes severe.

We will redouble our efforts to bring in more traders and ensure there is more liquidity in the system, as well as more eyes on the exchange to notice crashes and start buying earlier, stemming a further flood of liquidations.

Related: We will also be working hard on increasing UI responsiveness — details below.

Partial Liquidation Mechanism
Previously, when an open position was liquidated, 100% of the trader’s margin would be removed, with 1.25% going to keepers and any remainder going to the exchange insurance fund.

After this update (to be rolled out in the next week), liquidations will be flexible, leaving a significant portion of trader’s margin intact in most cases.

Assuming a timely liquidation occurs, 25% of the position’s PnL will be realized and a corresponding portion of the position notional and margin will be liquidated, leaving the remaining position untouched. If liquidation is too slow and margin ratio falls to 2.5% or less, total liquidation will occur.

Example:

Definitions
margin ratio: (margin + unrealized PnL) / positionNotional
liquidation penalty: 2.5% of positionNotional
//1.25% to keeper; 1.25% to insurance fund
Initial conditions
positionNotional = 1000
leverage = 2x
margin = 500
PnL = - 440
margin ratio: (500 - 440)/ 1000 = 0.06
Post-liquidation
assume positionNotional liquidated = 300 //actual amount will depend on x*y=k curve
liquidation penalty: 300*0.025 = 7.5
margin: 500 - (440*0.25) - 7.5 = 382.5
margin ratio: (382.5 - 440*0.75) / (1000 - 300) = 0.075

Margin Ratio Calculation Update
Margin ratio was previously calculated using mark price and unrealized PnL (link for details).

An update has been made to add a divergence protection mechanism to this calculation. If the mark price diverges from the index price by more than 10%, index price will be used to calculate the margin ratio.

Condition for margin ratio calculation using index price:(mark price - index price) / index price > 10% //absolute value is used

Using index (ie. oracle) prices for margin ratio calculation will prevent liquidations when mark and index prices diverge substantially.

However, this comes with trade-offs. If the oracle stops updating, both traders and the exchange are exposed to considerable risk. In addition, legitimate liquidations may fail to occur in certain cases, increasing risk to the exchange.

Personal Cap Increases
Personal caps (per address) on maximum open position size per trading pair will be increased substantially to give large traders and market makers more headroom to open large positions during strong price action and help stabilize the market. Overall caps on total open interest will remain in place to secure the exchange.

Decentralization for front end UI
In the coming weeks the team will create an open repository on Github with code for creating a web front end for Perpetual Protocol. This will allow anyone to launch a web based interface for Perpetual Protocol, giving users many possible options for trading and managing their positions.

UI Responsiveness
Our efforts to optimize and boost reliability of the servers running perp.exchange have slowed somewhat as we add more trading pairs and features. However, it is clear that we can improve in this area and we will renew our efforts to optimize and increase performance, as well as ensure servers have sufficient resources to handle spikes in demand.

Stop orders
Although they are unlikely to reduce or remove the risk of flash crashes, setting stop orders will allow traders to prevent losses. Limit, stop and other advanced order functionality are currently in closed beta and are expected to launch within a few weeks.

Community Compensation Proposal

A compensation proposal has been made by a community member on the governance forum. Please post your thoughts and discuss here.

Decentralized perpetual contract for every asset