Detailed mechanism of global settlement (black swan) and reviving of bitAssets

in #bitshares6 years ago (edited)

Maybe they are the most complex parts of BitShares. We don't want to see global settlement happen on popular bitAssets, but we should know how it exactly works. In this post I will try to explain the whole process of these two events.

Many thanks to @abit for some of the details I was also missing before.

This post reflects the mechanisms of current network consensus (version 2.0.171105a), and some of them may change in future hardforks.

1. Triggering Global Settlement

a. How is it triggered?

Currently there are 3 ways to trigger global settlement on bitAssets.

1. asset_global_settle_operation

This operation is for asset issuers to trigger the global settlement manually. I'll skip the details about it here.

2. Margin position having collateral ratio below 1 [1]

This is the most known black swan condition. When settlement price of the asset drops, collateral ratio of open margin positions will also decrease. If the collateral ratio of least collateralized margin position drops below 1, and there are no bid orders having price above debt / collateral of that position, global settlement will be triggered. In this situation, the global settlement price will be debt / collateral of the triggering least collateralized margin position.

For example, we have a margin position with debt of 100 bitUSD and collateral of 200 BTS. If the settlement price of bitUSD drop below 0.5 bitUSD/BTS, and the highest bid of the exchange market is also below 0.5 bitUSD/BTS, global settlement will be triggered on bitUSD asset, with global settlement price of 0.5 bitUSD/BTS.

3. Margin call order matched at market price below collateral ratio of 1 [2]

The margin-called positions (those having collateral ratio below maintenance collateral ratio(MCR, usually 1.75)) will be sold on market with the price of settlement price / maximum short squeeze ratio(MSSR, usually 1.1). Because of this, the call order could be executed below settlement price.
The margin call order will only execute below call price debt / collateral * MCR and above the limit settlement price / MSSR. More details about margin call executions could be found in documents[7].

There could be a situation in which the call order has lowest execute price below 1 collateral ratio (debt / collateral). If there are any matching bid order which could lead to the call order execute below 1 collateral ratio, global settlement will be triggered. In this situation, the global settlement price will be current settlement price of the asset.

For example, with most common MCR(1.75) and MSSR(1.1), we have a margin position with debt of 100 bitUSD and collateral of 200 BTS. The settlement price of bitUSD is 0.528 bitUSD/BTS, below the position's call price 100 / 200 * 1.75 = 0.875 bitUSD/BTS, so the call order is put on the market with lowest possible execution price of 0.528 / 1.1 = 0.48 bitUSD/BTS, which is in turn below the collateral ratio 1 price of the position 100 / 200 = 0.5 bitUSD/BTS. As the margin positions cannot trade below that price (or the peg is lost), so if there are any buy orders with price between 0.48 and 0.5, global settlement will be triggered, with global settlement price of 0.528 bitUSD/BTS.

b. What will happen?[3]

1. All margin positions will be closed at global settlement price

For all positions, use the collateral to buy the debt at global settlement price. The bought debt is returned to the blockchain and destroyed, effectively closing the position; the paid collateral will be put into settlement fund; the remaining collateral will be returned to the owner of the position[4].

2. Global instant settle will be enabled

All of the existing asset will not be affected. Instead, the owner could choose to settle the asset at the global settlement price instantly without 24h delay, returning the asset to the blockchain and destroying them, and get the corresponding value from the settlement fund. This is not a forced operation.

For example, when bitUSD enter global settlement state with global settlement price and current feed price of 0.5 bitUSD/BTS, there are 2 margin positions:

AccountCollateralDebtCall priceCollateral ratio
bob200 BTS100 bitUSD0.5 bitUSD/BTS1.0
alice150 BTS50 bitUSD0.3333 bitUSD/BTS1.5

During the process of entering global settlement, alice will use 100 BTS of the collateral to buy 50 bitUSD at 0.5 bitUSD/BTS, and the remaining 50 BTS will be returned to alice, while bob will use all of the collateral to buy his debt, getting nothing back. The settlement fund will receive 300 BTS and will be used to settle the circulating 150 bitUSD.

3. Normal bitAsset functions will be disabled

The asset could still be freely traded at the exchange or send to others, but borrowing will be disabled. The asset is not pegged anymore at this state. Witnesses could still provide price feeds.

2. Reviving from Global Settlement

After the last hardfork, BSIP18 is activated and bitAssets in global settlement could be revived to restore it's complete function. This works by converting the current supply to new margin positions while satisfying all bitAsset requirements.

a. How to revive bitAsset?

There are 3 ways to revive a bitAsset.

1. All existing bitAsset is settled [5]

When the settlement price is changed on feed update, if the bitAsset has valid feed and current supply of the asset is 0, the asset will be revived.

2. Settlement fund could satisfy collateral ratio requirement [5]

When the settlement price is changed on feed update, if the bitAsset has valid feed and the new settlement price is above global settlement price * MCR (actual calculation: settlement price > current supply / settlement fund * MCR), the asset will be revived. The blockchain will create a new margin position with the issuer of the bitAsset as the owner, current supply as the debt and settlement fund as the collateral.

For example, bitUSD is in global settlement state, having global settlement price of 0.5 bitUSD/BTS, with current supply of 100 USD and 200 BTS in settlement fund. If the settlement price from price feed goes above 100 / 200 * 1.75 = 0.875 bitUSD/BTS, bitUSD will be revived, and committee_account will have a new margin position with 100 bitUSD debt and 200 BTS collateral.

3. Collateral bids could cover the supply of the asset [6]

BSIP-0018 introduced a new operation bid_collateral_operation. As reviving requires creating new margin positions, this operation allows everyone to "bid" additional collateral to create new margin positions.

To bid additional collateral, the bidder will indicate how much debt he is willing to take, and how much additional collateral he will add to the margin position. This operation is not present in GUI wallet right now, but can be done by using bid_collateral command in CLI wallet or constructing the operation manually.

On every blockchain maintenance (currently every hour), the blockchain will check if the sum of debt of all bids would cover the current asset supply. If it's true, the blockchain will sort the bids with higher additional collateral / debt price in top, then create new margin positions for the bids until all current supply is covered. Each margin position will have debt as in the bid and collateral equals debt of the bid * global settlement price + additional collateral of the bid. During the creation process, if any of the new margin position have collateral ratio below MCR, the revive process is failed.

Here is an example of how it actually works.

bitUSD is in the global settlement state with current supply of 100 bitUSD and 200 BTS in settlement fund. The global settlement price is 0.5 bitUSD/BTS, and settlement from price feed is 0.75 bitUSD/BTS.
The bids before the maintenance are:

AccountDebt to takeAdditional collateralAdditional collateral / debt
alice25 bitUSD100 BTS4
bob50 bitUSD25 BTS0.5
charlie50 bitUSD50 BTS1
dave100 bitUSD1 BTS0.01

On the blockchain maintenance, the sum of debt from all bids are over the current supply (125 > 100). The blockchain will sort the bids with order alice - charlie - bob - dave.

  1. alice will be assigned a new margin position with 25 bitUSD as debt and 25 / 0.5 + 100 = 150 BTS as collateral, in which 25 / 0.5 = 50 BTS is taken from the settlement fund, leaving 150 BTS behind, and 75 bitUSD remaining to be covered.
  2. charlie will be assigned a new margin position with 50 bitUSD as debt and 50 / 0.5 + 50 = 150 BTS as collateral, in which 50 / 0.5 = 100 BTS is taken from the settlement fund, leaving 50 BTS behind, and 25 bitUSD remaining to be covered.
  3. bob will be assigned a new margin position with remaining 25 bitUSD as debt and 25 / 0.5 + 25 = 75 BTS as collateral, in which 25 / 0.5 = 50 BTS is taken from the remaining settlement fund.

The whole supply is converted to margin positions at this point, so dave's bid is automatically cancelled.
The resulting margin positions are:

AccountCollateralDebtCall priceCollateral ratio
bob75 BTS25 bitUSD0.5833 bitUSD/BTS2.25
charlie150 BTS50 bitUSD0.5833 bitUSD/BTS2.25
alice150 BTS25 bitUSD0.2917 bitUSD/BTS4.5

All of the margin positions have collateral ratio above 1.75, so the bitUSD is successfully revived.

b. What will happen after the bitAsset revives?

After the revive, all functions of the bitAsset will restore to normal - Anyone can borrow new assets into existence, settlement will have 24 hours delay, and most importantly, the asset will be pegged again. And everyone will be happy.

References

For those who want to take a look at the bitshares-core source code, here are the corresponding locations:
[1]: https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/db_update.cpp#L200-L255
[2]: https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/db_market.cpp#L522-L609
[3]: https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/db_market.cpp#L43-L93
[4]: https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/db_market.cpp#L427-L480
[5]: https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/asset_evaluator.cpp#L558-L589
[6]: https://github.com/bitshares/bitshares-core/blob/master/libraries/chain/db_maint.cpp#L719-L767

The margin call mechanics page article on bitshares docs site is a good read if you want to know more about how margin call is handled.
[7]: http://docs.bitshares.org/user/dex-margin-mechanics.html

Feedback

There could still be some details I'm not getting right or missing, or not expressed clearly, especially the reviving part. Please let me know in the comments, and I'll try to update this post or answer if possible.

Hope this post clears up some points about the global settlement and reviving mechanism of BitShares platform. And many thanks for reading my first steemit post!

Sort:  

Uf, its complicated ((
But thanks for info!

Thanks for taking the time to write this up!

This post helped a lot!

Congratulations @haruka! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You got your First payout

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Congratulations @haruka! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

You got your First payout

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - The results, the winners and the prizes

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Looks like it happened. bitUSD has been called.

Congratulations @haruka! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @haruka! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

SteemitBoard Ranking update - A better rich list comparator
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.28
TRX 0.11
JST 0.034
BTC 66038.71
ETH 3178.89
USDT 1.00
SBD 4.05