Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement alternative black swan response methods #2499

Merged
merged 99 commits into from Sep 29, 2021
Merged

Conversation

abitmore
Copy link
Member

@abitmore abitmore commented Aug 17, 2021

PR for #2467.

1. Main feature: black swan response methods - different behaviors when a black swan event occurs, configurable by bitAsset owners

  • global_settlement (the default method)
    All debt positions are closed, all or some collateral is moved to a global-settlement fund.
    Debt asset holders can claim collateral via force-settlement.
    It is not allowed to create new debt positions when the fund is not empty.
  • no_settlement aka "Global Settlement Protection"
    No debt position is closed, and the derived settlement price is dynamically capped at the collateral ratio of the debt position with the least collateral ratio so that all debt positions are able to pay off their debt when being margin called or force-settled.
    Able to adjust existing debt positions or create new debt positions.
  • individual_settlement_to_fund
    Only the undercollateralized debt positions are closed and their collateral is moved to a fund which can be claimed via force-settlement. The derived settlement price is capped at the fund's collateral ratio so that remaining debt positions will not be margin called or force-settled at a worse price.
    Able to adjust existing debt positions or create new debt positions.
  • individual_settlement_to_order
    Only the undercollateralized debt positions are closed and their collateral is moved to a limit order on the order book which can be bought. The derived settlement price is NOT capped, which means remaining debt positions could be margin called at a worse price.
    Able to adjust existing debt positions or create new debt positions.

2. Additional features

  • Fix a bug that some non-UIA asset issuer permission bits (e.g. witness_fed_asset) can be configured on UIA via asset_update_operation
  • Able to close debt positions even when there is no sufficient price feeds
  • Allow updating an existing debt position or creating a new debt position if to trigger a margin call and the debt position is not fully filled but the remaining debt position's CR is higher than ICR

3. API changes

  • The return value of asset_settle_operation is now a new type extendable_operation_result
     struct extendable_operation_result_dtl
     {
        optional<flat_set<account_id_type>> impacted_accounts;
        optional<flat_set<object_id_type>>  new_objects;
        optional<flat_set<object_id_type>>  updated_objects;
        optional<flat_set<object_id_type>>  removed_objects;
        optional<vector<asset>>             paid;
        optional<vector<asset>>             received;
        optional<vector<asset>>             fees;
     };
     using extendable_operation_result = extension<extendable_operation_result_dtl>;
    

Tasks:

  • test cases
    • hard fork protection - unable to set the new bit or the new extension before hard fork, nor able to propose
    • can not set non-UIA asset issuer permission bits on UIA (additional feature No. 1)
    • can not set the new bit in flags
    • can not apply the new bit or the new extension to UIA or PM
    • when the issuer permission is forfeited, unable to update BSRM unless there is no supply
    • Able to close debt positions even when no sufficient price feeds (additional feature No. 2)
    • Allow partial fill on call update if triggers margin call and new CR > ICR (additional feature No. 3) (test case: force_settle_match_tests/tcr_test_hf2481_call_settle)
    • no settlement
      • no GS when price drops
      • ICR and MCR check with real price
      • force settle (call order is maker) at capped price, and price updates after filled
        • cancel too-small taker settle order during matching
        • updating price may trigger matching and filling of other limit orders
      • margin call (call order is maker) at capped price, and price updates after filled
        • cancel too-small taker limit order during matching
        • updating price may trigger matching and filling of other limit orders
      • call order is taker
        • force settle (call order is taker) at capped price, and price updates after filled
        • margin call (call order is taker) at capped price, and price updates after filled
        • limit orders always take precedence over force settlements -- after every call-settle match, check call-limit match
      • when the least collateralized debt position is manually updated
        • update current feed price
        • may trigger matching and filling of other limit orders
        • it is always allowed to increase CR if not to increase debt amount (new CR can still be <MSSR)
      • when the least collateralized debt position is manually closed
        • update current feed price
        • may trigger matching and filling of other limit orders
    • individual settlement to fund
      • individually settle when price drops
        • after settled the undercollateralized debt positions, match the rest (margin calls) with maker limit orders (note: force-settlements should have been matched and filled before individual settlements)
      • margin call at capped price
      • ICR and MCR check with real price
      • check for black swan with real price
      • if fund is not empty, able to force-settle even when no price feed or disable_force_settle flag is set
      • force settlements match with the fund first, and capped price updates after filled
        • the operation fails if the amount to settle is too small
        • may trigger matching and filling of limit orders after price update
      • if disable_force_settle flag is set, cancel the remaining force-settle order after emptied the fund
      • check total supply of both debt asset and collateral debt
    • individual settlement to order
      • individually settle when price drops
        • after settled the undercollateralized debt positions, match the rest (margin calls) with maker limit orders (note: force-settlements should have been matched and filled before individual settlements)
      • matching taker limit order with the settled debt order
      • cancel the remaining force-settle orders on expiration when no debt position exists
      • check total supply of both debt asset and collateral debt
    • updating BSRM
      • able to update when not yet settled and would not settle (globally or individually)
      • unable to update when already settled (globally or individually)
      • no_settlement -> GS
      • no_settlement -> individual settlement to fund
      • no_settlement -> individual settlement to order
    • manually GS via asset_global_settle_operation
      • no_settlement -> GS
      • individual settlement to fund -> GS
      • individual settlement to order -> GS

@abitmore abitmore added this to In Development in Protocol Upgrade Release (6.0.0) via automation Aug 17, 2021
@abitmore abitmore linked an issue Aug 17, 2021 that may be closed by this pull request
17 tasks
@abitmore abitmore marked this pull request as ready for review September 24, 2021 22:43
@abitmore abitmore moved this from In Development to In Testing in Protocol Upgrade Release (6.0.0) Sep 24, 2021
@sonarcloud
Copy link

sonarcloud bot commented Sep 29, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 26 Code Smells

98.7% 98.7% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Alternative black swan response methods
1 participant