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 Audit Wrapper #464

Closed patrickdugan closed 2 years ago

patrickdugan commented 2 years ago

We're going to apply the following dictums:

If there are 0 liquidated orders unfilled by settlement then the settlement can be done as-is, because all insufficient sums would be already liquidated, and losses have already been deducted from traders' available capital, there be must exactly as much value to be paid out to positive PNL holders in full.

If there are liquidations, the volume-weighted average price of the liquidations vs. the settlement price the net sign of the orders will tell you the total loss to the system. If we have individually liquidated orders then there's the risk that long liquidations and short liquidations could both be weighing down on the system. If we group liquidations to an average price where it would be break-even for the system* to get them filled, we can always have just one size that is pending liquidation, and the orders won't hang. Updating liquidations will be a separate ticket.

So e.g. Settlement is 10k, avg. price of sell-liquidation orders that are left unfilled is 13k, what % of the total open interest at-settlement are those contracts? Let's say they were 10%, that's a roughly 23% loss on 10% of the contracts, or 2.3% total. How many units is that? How many units are in the insurance fund? If there aren't enough units to cover the bill, then the remainder will go to a bail-in, or socialization of loss, in other words +PNLs will be paid somewhat less than 100%.

Then we would apply payments, either reading from a data-structure that the settlement algo returns, or simply by looping through and applying a coefficient of 1 (first case) or or less than 1 to each payment, while also removing the realized loss from all -PNL addresses, such that the total of the debits and credits * coefficient = 0.

patrickdugan commented 2 years ago

We ended up going with a modified structure.