BlockPo / BlockPo-to-Tradelayer

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

Isolate Off-sides Channel Trades #449

Open patrickdugan opened 3 years ago

patrickdugan commented 3 years ago

If a trade is made in a Trade Channel and kept unpublished, the market will move, someone can then publish their signed trade to confirm on a block where the mark price is above/below (short/long position) the maintenance margin threshold. Then the trade should be isolated from the general clearing of that contract. Instead the trade should book-out at the mark price. The trade cannot be included in the Path_Elef vector or otherwise passed for clearing in any way, that would potentially create bugs.

If we don't do this people can raise insurance funds by dropping trades that are past the bankruptcy price of a leveraged self-trade.

If the mark price or last price is past the maint. margin, this triggers. If it's beyond the liquidation price then the trade must book-out with the total liquidation of the losing party to the winning party, if it's a self-trade they just lost a basis point plus miner fees.

patrickdugan commented 2 years ago

We need to go into Dex.cpp and modify the logic in the function that handles instant-type channel trades, and create a function for settling the trade for all the initial margin to the winner, and that's it. We make an if() and then pass it to that function if it's out of bounds.

patrickdugan commented 1 year ago

Ok barring the complicated solution to the problem that is more forgiving to L2 users facing uncooperative counterparties during volatility, we'll do a simple solution.

The simple solution is to invalidate trade channel contract trades if, when the trade is published, mark_price is > the maint. margin threshold of the seller, or < the maint. margin threshold of the buyer.

That's it.

Maintenance margin threshold in this case means, the liquidation price, where the protocol begins to incrementally liquidate contracts.