BlockPo / BlockPo-to-Tradelayer

Incubation Repo for the TradeLayer protocol, 0.2.0
http://www.tradelayer.org
Other
8 stars 8 forks source link

Settlement: Consolidated VWAP Liquidation Order #470

Closed patrickdugan closed 2 years ago

patrickdugan commented 2 years ago

Liquidated orders have a liquidation price and a bankruptcy price. Because these are different, there is a conundrum around doing an insurance-fund-free architecture, there is a possibility for different outcomes, and in some of these some kind of overflow cache is needed:

1) there are orders that trigger a liquidation for mark price being lower than the maint. margin threshold, but, above the bankruptcy price (where all margin is lost), if these users fill their liquidations with standing orders they may recover some fragment of their margin. If there are not enough orders on the book, we take a VWAP of the liquidation prices and bankruptcy prices for these orders. If mark price is worse than the VWAP liquidation price, then the VWAP of liquidation orders is where the standing order shall be inserted at the mark price to effect the settlement;

 a) the market goes down further, mark price is now worse than the VWAP of bankruptcy prices, socialize, move consolidation VWAP liquidation wall of doom order to the new mark price

 b) the market doesn't keep going down, or before it does, the liquidation order is partially or fully filled, this fill is special because of the identity of the order has this red flag for being a Liquidation, the difference between that fill price and the VWAP bankruptcy price for the order is effectively a trade profit for the "Insurance Fund" or lacking the existence of one, it must be accounted for by either returning the bits of left-over margin to all those liquidated traders, or cached somewhere in the astral plane (e.g. a proto insurance fund).

2) there are orders that trigger liquidations and the mark price has moved through the bankruptcy VWAP price, here we socialize right away and move the Wall of Doom down to the mark price, and so on, truly the most brutal outcome

3) Liquidations occur, they are are a better avg. liquidation price than the mark price, as note above, they will be moved to the mark price. But if the liq. price vwap is worse than the mark price that block (how could it be? seems unlikely given the causative relationship here, but to be totally covered) then the wall of doom will hang at that VWAP price instead of the mark price.

4) If there are both long and short liquidations in the same block somehow (again, seems impossible or at least unlikely, but to be sure) they will cancel each other out.