BlockPo / BlockPo-to-Tradelayer

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

Insurance Fund #471

Closed patrickdugan closed 1 year ago

patrickdugan commented 2 years ago

The Insurance Fund is a singleton of its own Class, and has a few key properties and methods:

Properties:

0) The Maybe Cache - a vector of SP balances for each id that are held in abeyonce pending the resolution of the scenario in ticket #470-1)

1) Balance in SP#1 - obviously!

2) Balance in SP2-N - less obvious can be added for an upgrade that activates the Donate_tx so I can fund this from the core position, when the fund is pretty good. Also we want to add support for all the various Smart Properties to be able to accrue as both a direct transfer and a buyback. We have code for the buyback, need to add support for direct transfer.

3) Balance in short contract positions that are collateralized by 1, this has to be accounted for in the Register to thread these into any clearing audit flow we run later (same as the rest)

Methods:

1) AddTo - passes a balance in, debits from Tallymap

We can use this in xTrade to detect matches with liquidation orders, apply the logic in Ticket #470-1) and thus pass some margin in. We can also use this to add a Liquidation Fee for liq. orders that have been matched by other traders, thus the traders get some money back but the insurance fund profits from the less volatile incidence of liquidations, this fee also creates a penalty for wash-trading with high leverage and an angle to liquidation one side (crash trading). Bears mentioning that we ought to factor fee logic in tradelayer.cpp to its own fees.cpp file, perhaps next year.

2) PayOut - passes a smart contract id and a loss value, if it has insufficient balance this function will payout what is available.

3) RebalanceBook - this inserts orders into the orderbook based on a math function that asks: how many contracts do you need to sell at each tick to keep the asset value of the fund 50/50 between long ALL and sLTC (or short contract positions, technically) - we'll use this when we add the AMM aspect of the Insurance Fund

patrickdugan commented 2 years ago

This is somewhat completed by Sergei but needs testing to call it closed.