BlockPo / BlockPo-to-Tradelayer

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

Refactor xTrade to Prioritize Liquidations then Stops #448

Closed patrickdugan closed 2 years ago

patrickdugan commented 3 years ago

Right now we have the classic prioritization of matches by a rough timestamp based on when the tx entered the mempool of TradeLayer nodes. Nevermind that there is fuzziness in that mechanism, which nodes' timestamps count? Can node disagree of who matched as a maker? We should test the edge case of conflicting consensus around matching... that's another ticket.

Assuming the old way is reasonably containable for consensus issues, the priority must be Liquidation orders, then Stop Loss orders, that act like market orders, executing really at an in-the-money limit order, placed at the bankruptcy price of the order in the case of a Liquidation. In the case of a Stop Loss, it should be placed 1% higher or lower than the stop price. There should be liquidity in the on-chain orderbook from market making that tries to fish for these kinds of orders, if not it can exacerbate the systemic risk of unfilled liquidation orders.

A Liquidation order is sort of like a Stop Loss in terms of being triggered by the mark price moving above or below some threshold. In the case of the stop loss that threshold is defined by the user, in the case of the Liquidation it is the maintainence margin threshold where unrealized losses leave the address under the maintenance margin threshold in terms of net-equity value.

Why this feature is important: assuring that this market order flow goes first in priority and therefore being able to market make to some depth with reasonably stale orders, is a healthy component of a derivative market that stays solvent. This is why the liquidity reward exists really, in addition to the rebate favoring makers in on-chain matched trades, it is to deter manipulation, reward capital that reinforces the system, and creates a time-value to that liquidity from the good arbitrage trades they can catch. It also dovetails really nicely with the Graph Default Swaps we have planned, people will be able to sell these with leverage and underwrite the solvency of the contracts. The idea is that nobody will come buy these GDS and get a huge profit because the GDS sellers are generally quoting on the on-chain books for ALL/sLTC and the contracts, and liquidated swaps and futures get bought up by them, they quickly hedge by shorting some on a centralized exchange, or if it's BTC/USD flow they can arb it in that general liquidity complex.

patrickdugan commented 2 years ago

We ended up doing liquidation a bit differently so this is effectively closed.