BlockPo / BlockPo-to-Tradelayer

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

Bail-ins/Insurance Payouts #241

Closed patrickdugan closed 2 years ago

patrickdugan commented 4 years ago

In the settlement function in TradeLayer.ccp, after the clearing algo has made a series of targeted adjustments, a secondary logic will look at the number of liquidated contract orders that are unfilled, the average entry of each open position, a secondarily calculated PNL, and compare. If there's a PNL discrepancy that's a flag for unit tests, pending such investigations into any issues in the clearing algo the secondary logic would impose consensus, which saves the protocol from any technical debt that may be left behind.

1) Block 2) Parsing loop 3) Settlement block is checked, if so go to clearing functions 4) TallyMap is updated in a large series of writes 5) function checking # of liquidated contracts 6) compare result to open interest 7) logic check each individual position 8) determine if we are seeing a) clearing algo is correct, no shortfall, b) clearing algo may have been incorrect but there is no shortfall, c) clearing algo is returning a semi-distributed bail-in based on deficits, there are liquidation orders unfilled, n% of OI at settlement is busted 9) calculate the total damage in the event of c 10) check insurance fund balance, if sufficient, then distribute it so that each settlement is = to what 7) calculated 11) if insufficient balance, apply what is available then bail-in the PNL of winning positions to equalize the damage so that every PNL is penalized by the same %. 12) unit test of the mathematical consistency

santos177 commented 4 years ago

working in settlement_work branch

patrickdugan commented 2 years ago

This should be covered by more recent work Sergei did pending testing. This framework here referenced is obsoleted anyway.