code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/0002-STTL-settlement_at_expiry_with_dp.feature (about)

     1  Feature: Test settlement at expiry with decimal places for asset and market (different)
     2  
     3    Background:
     4      Given time is updated to "2019-11-30T00:00:00Z"
     5      And the average block duration is "1"
     6  
     7      And the following assets are registered:
     8        | id  | decimal places |
     9        | ETH | 5              |
    10  
    11      And the oracle spec for settlement data filtering data from "0xCAFECAFE" named "ethDec20Oracle":
    12        | property         | type         | binding         |
    13        | prices.ETH.value | TYPE_INTEGER | settlement data |
    14  
    15      And the oracle spec for trading termination filtering data from "0xCAFECAFE" named "ethDec20Oracle":
    16        | property           | type         | binding             |
    17        | trading.terminated | TYPE_BOOLEAN | trading termination |
    18  
    19      And the oracle spec for settlement data filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
    20        | property         | type         | binding         |
    21        | prices.ETH.value | TYPE_INTEGER | settlement data |
    22  
    23      And the oracle spec for trading termination filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
    24        | property           | type         | binding             |
    25        | trading.terminated | TYPE_BOOLEAN | trading termination |
    26  
    27      And the following network parameters are set:
    28        | name                                         | value |
    29        | market.auction.minimumDuration               | 1     |
    30        | network.markPriceUpdateMaximumFrequency      | 0s    |
    31        | market.liquidity.successorLaunchWindowLength | 1s    |
    32        | limits.markets.maxPeggedOrders               | 4     |
    33  
    34      And the settlement data decimals for the oracle named "ethDec20Oracle" is given in "2" decimal places
    35      And the settlement data decimals for the oracle named "ethDec21Oracle" is given in "1" decimal places
    36  
    37      And the fees configuration named "fees-config-1":
    38        | maker fee | infrastructure fee |
    39        | 0.005     | 0.02               |
    40      And the price monitoring named "price-monitoring-1":
    41        | horizon | probability | auction extension |
    42        | 1       | 0.99        | 300               |
    43      And the simple risk model named "simple-risk-model-1":
    44        | long | short | max move up | min move down | probability of trading |
    45        | 0.2  | 0.1   | 10000000    | -10000000     | 0.1                    |
    46  
    47      And the markets:
    48        | id        | quote name | asset | risk model                  | margin calculator         | auction duration | fees          | price monitoring   | data source config | decimal places | linear slippage factor | quadratic slippage factor | sla params      |
    49        | ETH/DEC19 | ETH        | ETH   | default-simple-risk-model-3 | default-margin-calculator | 1                | default-none  | default-none       | ethDec20Oracle     | 3              | 0.25                   | 0                         | default-futures | 
    50        | ETH/DEC21 | ETH        | ETH   | simple-risk-model-1         | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | ethDec21Oracle     | 2              | 0.25                   | 0                         | default-futures |
    51  
    52    Scenario: Order cannot be placed once the market is expired (0002-STTL-001)
    53      Given the parties deposit on asset's general account the following amount:
    54        | party  | asset | amount      |
    55        | party1 | ETH   | 10000000000 |
    56        | aux1   | ETH   | 10000000000 |
    57        | aux2   | ETH   | 10000000000 |
    58        | lpprov | ETH   | 10000000000 |
    59  
    60      When the parties submit the following liquidity provision:
    61        | id  | party  | market id | commitment amount | fee | lp type    |
    62        | lp1 | lpprov | ETH/DEC19 | 900000000         | 0.1 | submission |
    63        | lp1 | lpprov | ETH/DEC19 | 900000000         | 0.1 | submission |
    64      And the parties place the following pegged iceberg orders:
    65        | party  | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    66        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50         | 100    |
    67        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50         | 100    |
    68      When the parties place the following orders:
    69        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
    70        | aux1  | ETH/DEC19 | buy  | 1      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    71        | aux2  | ETH/DEC19 | sell | 1      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
    72        | aux1  | ETH/DEC19 | buy  | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
    73        | aux2  | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
    74  
    75      Then the market data for the market "ETH/DEC19" should be:
    76        | target stake | supplied stake |
    77        | 110000000    | 900000000      |
    78      Then the opening auction period ends for market "ETH/DEC19"
    79      And the mark price should be "1000000" for the market "ETH/DEC19"
    80  
    81      When the oracles broadcast data signed with "0xCAFECAFE":
    82        | name               | value |
    83        | trading.terminated | true  |
    84      And time is updated to "2020-01-01T01:01:01Z"
    85      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC19"
    86      Then the oracles broadcast data signed with "0xCAFECAFE":
    87        | name             | value |
    88        | prices.ETH.value | 4200  |
    89      Then time is updated to "2020-01-01T01:01:02Z"
    90  
    91      When the parties place the following orders:
    92        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference | error                         |
    93        | party1 | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-7     | OrderError: Invalid Market ID |
    94  
    95    @SLABug
    96    Scenario: Settlement happened when market is being closed - no loss socialisation needed - no insurance taken (0002-STTL-002, 0002-STTL-007, 0005-COLL-002, 0015-INSR-002)
    97      Given the initial insurance pool balance is "1000000000" for all the markets
    98      Given the parties deposit on asset's general account the following amount:
    99        | party    | asset | amount         |
   100        | party1   | ETH   | 1000000000     |
   101        | party2   | ETH   | 100000000      |
   102        | party3   | ETH   | 500000000      |
   103        | aux1     | ETH   | 10000000000    |
   104        | aux2     | ETH   | 10000000000    |
   105        | party-lp | ETH   | 10000000000000 |
   106  
   107      And the cumulated balance for all accounts should be worth "10023600000000"
   108  
   109      And the parties submit the following liquidity provision:
   110        | id  | party    | market id | commitment amount | fee | lp type    |
   111        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | submission |
   112        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | amendment  |
   113        | lp2 | party-lp | ETH/DEC21 | 3000000000000     | 0   | submission |
   114        | lp2 | party-lp | ETH/DEC21 | 3000000000000     | 0   | amendment  |
   115      And the parties place the following pegged iceberg orders:
   116        | party   | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   117        | party-lp | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   118        | party-lp | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   119        | party-lp | ETH/DEC21 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   120        | party-lp | ETH/DEC21 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   121   
   122      When the parties place the following orders:
   123        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   124        | aux1  | ETH/DEC19 | buy  | 2      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   125        | aux2  | ETH/DEC19 | sell | 2      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   126        | aux1  | ETH/DEC19 | buy  | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   127        | aux2  | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   128  
   129      # Other market
   130      And the parties place the following orders:
   131        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   132        | aux1  | ETH/DEC21 | buy  | 2      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   133        | aux2  | ETH/DEC21 | sell | 2      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   134        | aux1  | ETH/DEC21 | buy  | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   135        | aux2  | ETH/DEC21 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   136  
   137      Then the market data for the market "ETH/DEC19" should be:
   138        | target stake | supplied stake |
   139        | 110000000    | 3000000000000  |
   140  
   141      Then the market data for the market "ETH/DEC21" should be:
   142        | target stake | supplied stake |
   143        | 2000000000   | 3000000000000  |
   144  
   145      When the network moves ahead "2" blocks
   146      Then the mark price should be "1000000" for the market "ETH/DEC19"
   147  
   148      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   149      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
   150  
   151      And the market state should be "STATE_ACTIVE" for the market "ETH/DEC19"
   152      And the market state should be "STATE_ACTIVE" for the market "ETH/DEC21"
   153  
   154      Then the network moves ahead "2" blocks
   155  
   156      # The market considered here ("ETH/DEC19") relies on "0xCAFECAFE" oracle, checking that broadcasting events from "0xCAFECAFE1" should have no effect on it apart from insurance pool transfer
   157      And the oracles broadcast data signed with "0xCAFECAFE1":
   158        | name               | value |
   159        | trading.terminated | true  |
   160  
   161      And the network moves ahead "2" blocks
   162  
   163      Then the market state should be "STATE_ACTIVE" for the market "ETH/DEC19"
   164      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC21"
   165  
   166      When the oracles broadcast data signed with "0xCAFECAFE1":
   167        | name             | value  |
   168        | prices.ETH.value | 200000 |
   169  
   170      And the network moves ahead "2" blocks
   171  
   172      Then the market state should be "STATE_ACTIVE" for the market "ETH/DEC19"
   173  
   174      When the parties place the following orders with ticks:
   175        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   176        | party1 | ETH/DEC19 | sell | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   177        | party2 | ETH/DEC19 | buy  | 1      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   178        | party3 | ETH/DEC19 | buy  | 1      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-3     |
   179  
   180      And the following trades should be executed:
   181        | buyer  | price   | size | seller |
   182        | party2 | 1000000 | 1    | party1 |
   183        | party3 | 1000000 | 1    | party1 |
   184  
   185      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
   186      And the cumulated balance for all accounts should be worth "10023600000000"
   187  
   188      # Close positions by aux parties
   189      When the parties place the following orders:
   190        | party | market id | side | volume | price   | resulting trades | type       | tif     |
   191        | aux1  | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC |
   192        | aux2  | ETH/DEC19 | buy  | 1      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC |
   193  
   194  
   195      Then the parties should have the following profit and loss:
   196        | party  | volume | unrealised pnl | realised pnl |
   197        | party1 | -2     | 0              | 0            |
   198        | party2 | 1      | 0              | 0            |
   199        | party3 | 1      | 0              | 0            |
   200  
   201      When the oracles broadcast data signed with "0xCAFECAFE":
   202        | name               | value |
   203        | trading.terminated | true  |
   204  
   205      # Order can't be placed after oracle data is received (expecting party positions to remain unchanged)
   206      When the parties place the following orders:
   207        | party  | market id | side | volume | price   | resulting trades | type       | tif     | error               |
   208        | party3 | ETH/DEC19 | buy  | 1      | 2000000 | 0                | TYPE_LIMIT | TIF_GTC | trading not allowed |
   209  
   210      And time is updated to "2020-01-01T01:01:01Z"
   211  
   212      Then the parties should have the following profit and loss:
   213        | party  | volume | unrealised pnl | realised pnl |
   214        | party1 | -2     | 0              | 0            |
   215        | party2 | 1      | 0              | 0            |
   216        | party3 | 1      | 0              | 0            |
   217  
   218      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC19"
   219      Then the oracles broadcast data signed with "0xCAFECAFE":
   220        | name             | value |
   221        | prices.ETH.value | 4200  |
   222  
   223      When the network moves ahead "1" blocks
   224      And time is updated to "2020-01-01T01:01:02Z"
   225  
   226      Then the parties place the following orders:
   227        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference | error                         |
   228        | party1 | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     | OrderError: Invalid Market ID |
   229  
   230      And the parties should have the following account balances:
   231        | party  | asset | market id | margin | general    |
   232        | party1 | ETH   | ETH/DEC19 | 0      | 1191600000 |
   233        | party2 | ETH   | ETH/DEC19 | 0      | 4200000    |
   234        | party3 | ETH   | ETH/DEC19 | 0      | 404200000  |
   235  
   236      When the network moves ahead "2" blocks
   237      Then the cumulated balance for all accounts should be worth "10023600000000"
   238      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   239      And the global insurance pool balance should be "2000000000" for the asset "ETH"
   240      And the insurance pool balance should be "0" for the market "ETH/DEC21"
   241  
   242  
   243    Scenario: Same as above, but the other market already terminated before the end of scenario, expecting 0 balances in per market insurance pools - all should go to per asset insurance pool (0002-STTL-additional-tests, 0005-COLL-002, 0015-INSR-002, 0032-PRIM-018)
   244  
   245      Given the initial insurance pool balance is "1000000000" for all the markets
   246      Given the parties deposit on asset's general account the following amount:
   247        | party    | asset | amount         |
   248        | party1   | ETH   | 1000000000     |
   249        | party2   | ETH   | 100000000      |
   250        | party3   | ETH   | 500000000      |
   251        | aux1     | ETH   | 10000000000    |
   252        | aux2     | ETH   | 10000000000    |
   253        | party-lp | ETH   | 10000000000000 |
   254        | lpprov   | ETH   | 10000000000000 |
   255  
   256      And the cumulated balance for all accounts should be worth "20023600000000"
   257  
   258      And the parties submit the following liquidity provision:
   259        | id  | party    | market id | commitment amount | fee | lp type    |
   260        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | submission |
   261        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | amendment  |
   262        | lp2 | lpprov   | ETH/DEC21 | 3000000000000     | 0   | submission |
   263        | lp2 | lpprov   | ETH/DEC21 | 3000000000000     | 0   | amendment  |
   264      And the parties place the following pegged iceberg orders:
   265        | party    | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   266        | party-lp | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   267        | party-lp | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   268        | lpprov   | ETH/DEC21 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   269        | lpprov   | ETH/DEC21 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   270   
   271      When the parties place the following orders:
   272        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   273        | aux1  | ETH/DEC19 | buy  | 1      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   274        | aux2  | ETH/DEC19 | sell | 1      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   275        | aux1  | ETH/DEC19 | buy  | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   276        | aux2  | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   277  
   278      # Other market
   279      And the parties place the following orders:
   280        | party | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   281        | aux1  | ETH/DEC21 | buy  | 1      | 99900  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   282        | aux2  | ETH/DEC21 | sell | 1      | 100100 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   283        | aux1  | ETH/DEC21 | buy  | 1      | 100000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   284        | aux2  | ETH/DEC21 | sell | 1      | 100000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   285  
   286      Then the market data for the market "ETH/DEC19" should be:
   287        | target stake | supplied stake |
   288        | 110000000    | 3000000000000  |
   289      Then the market data for the market "ETH/DEC21" should be:
   290        | target stake | supplied stake |
   291        | 200000000    | 3000000000000  |
   292      Then the opening auction period ends for market "ETH/DEC19"
   293      And the mark price should be "1000000" for the market "ETH/DEC19"
   294  
   295      Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   296      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
   297      And the market state should be "STATE_ACTIVE" for the market "ETH/DEC19"
   298      And the market state should be "STATE_ACTIVE" for the market "ETH/DEC21"
   299  
   300      Then the parties place the following orders:
   301        | party | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   302        | aux2  | ETH/DEC21 | buy  | 1      | 100000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   303        | aux1  | ETH/DEC21 | sell | 1      | 100000 | 1                | TYPE_LIMIT | TIF_GTC | ref-3     |
   304  
   305      And the market data for the market "ETH/DEC21" should be:
   306        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest | best static bid price | static mid price | best static offer price |
   307        | 100000     | TRADING_MODE_CONTINUOUS | 1       | 90001     | 110000    | 200000000    | 3000000000000  | 0             | 99900                 | 100000           | 100100                  |
   308  
   309      Then the network moves ahead "2" blocks
   310  
   311      # The market considered here ("ETH/DEC19") relies on "0xCAFECAFE" oracle, checking that broadcasting events from "0xCAFECAFE1" should have no effect on it apart from insurance pool transfer
   312      And the oracles broadcast data signed with "0xCAFECAFE1":
   313        | name               | value |
   314        | trading.terminated | true  |
   315  
   316      And the network moves ahead "2" blocks
   317  
   318      Then the market state should be "STATE_ACTIVE" for the market "ETH/DEC19"
   319      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC21"
   320  
   321      And the insurance pool balance should be "1000000000" for the market "ETH/DEC21"
   322      And the insurance pool balance should be "1000000000" for the market "ETH/DEC19"
   323      And the global insurance pool balance should be "0" for the asset "ETH"
   324  
   325      When the oracles broadcast data signed with "0xCAFECAFE1":
   326        | name             | value |
   327        | prices.ETH.value | 70000 |
   328  
   329      # settlement price is 70000 which is outside price monitoring bounds, and this will not trigger auction
   330      And the trading mode should be "TRADING_MODE_NO_TRADING" for the market "ETH/DEC21"
   331      Then the market state should be "STATE_SETTLED" for the market "ETH/DEC21"
   332      And the network moves ahead "6" blocks
   333      And the insurance pool balance should be "0" for the market "ETH/DEC21"
   334      And the insurance pool balance should be "1000000000" for the market "ETH/DEC19"
   335      And the global insurance pool balance should be "1000000000" for the asset "ETH"
   336  
   337      Then the market state should be "STATE_ACTIVE" for the market "ETH/DEC19"
   338  
   339  
   340      When the parties place the following orders:
   341        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   342        | party1 | ETH/DEC19 | sell | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   343        | party2 | ETH/DEC19 | buy  | 1      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   344        | party3 | ETH/DEC19 | buy  | 1      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-3     |
   345  
   346      And the cumulated balance for all accounts should be worth "20023600000000"
   347  
   348      # Close positions by aux parties
   349      When the parties place the following orders with ticks:
   350        | party | market id | side | volume | price   | resulting trades | type       | tif     |
   351        | aux1  | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC |
   352        | aux2  | ETH/DEC19 | buy  | 1      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC |
   353  
   354      When the oracles broadcast data signed with "0xCAFECAFE":
   355        | name               | value |
   356        | trading.terminated | true  |
   357  
   358      And time is updated to "2020-01-01T01:01:01Z"
   359  
   360      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC19"
   361      Then the oracles broadcast data signed with "0xCAFECAFE":
   362        | name             | value |
   363        | prices.ETH.value | 4200  |
   364  
   365      Then time is updated to "2020-01-01T01:01:02Z"
   366  
   367      Then the parties place the following orders:
   368        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference | error                         |
   369        | party1 | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     | OrderError: Invalid Market ID |
   370  
   371      And the parties should have the following account balances:
   372        | party  | asset | market id | margin | general    |
   373        | party1 | ETH   | ETH/DEC19 | 0      | 1191600000 |
   374        | party2 | ETH   | ETH/DEC19 | 0      | 4200000    |
   375        | party3 | ETH   | ETH/DEC19 | 0      | 404200000  |
   376  
   377      When the network moves ahead "2" blocks
   378      Then the cumulated balance for all accounts should be worth "20023600000000"
   379      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   380      And the insurance pool balance should be "0" for the market "ETH/DEC21"
   381      And the global insurance pool balance should be "2000000000" for the asset "ETH"
   382  
   383    @SLABug
   384    Scenario: Settlement happened when market is being closed - no loss socialisation needed - insurance covers losses (0002-STTL-008)
   385      Given the initial insurance pool balance is "100000000" for all the markets
   386      Given the parties deposit on asset's general account the following amount:
   387        | party    | asset | amount         |
   388        | party1   | ETH   | 1000000000     |
   389        | party2   | ETH   | 100000000      |
   390        | aux1     | ETH   | 10000000000    |
   391        | aux2     | ETH   | 10000000000    |
   392        | party-lp | ETH   | 10000000000000 |
   393      And the parties submit the following liquidity provision:
   394        | id  | party    | market id | commitment amount | fee | lp type    |
   395        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | submission |
   396        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | amendment  |
   397        | lp2 | party-lp | ETH/DEC21 | 3000000000000     | 0   | submission |
   398        | lp2 | party-lp | ETH/DEC21 | 3000000000000     | 0   | amendment  |
   399      And the parties place the following pegged iceberg orders:
   400        | party    | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   401        | party-lp | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   402        | party-lp | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   403        | party-lp | ETH/DEC21 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   404        | party-lp | ETH/DEC21 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   405  
   406      When the parties place the following orders:
   407        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   408        | aux1  | ETH/DEC19 | buy  | 1      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   409        | aux2  | ETH/DEC19 | sell | 1      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   410        | aux1  | ETH/DEC19 | buy  | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   411        | aux2  | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   412  
   413      # Other market
   414      And the parties place the following orders:
   415        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   416        | aux1  | ETH/DEC21 | buy  | 1      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   417        | aux2  | ETH/DEC21 | sell | 1      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   418        | aux1  | ETH/DEC21 | buy  | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   419        | aux2  | ETH/DEC21 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   420  
   421      When the network moves ahead "2" blocks
   422  
   423      Then the mark price should be "1000000" for the market "ETH/DEC19"
   424  
   425      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   426      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
   427  
   428      When the parties place the following orders:
   429        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   430        | party1 | ETH/DEC19 | sell | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   431        | party2 | ETH/DEC19 | buy  | 2      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   432  
   433      Then the parties should have the following account balances:
   434        | party  | asset | market id | margin   | general   |
   435        | party1 | ETH   | ETH/DEC19 | 24000000 | 976000000 |
   436        | party2 | ETH   | ETH/DEC19 | 26400000 | 73600000  |
   437  
   438      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
   439      And the cumulated balance for all accounts should be worth "10021300000000"
   440  
   441      # Close positions by aux parties
   442      When the parties place the following orders with ticks:
   443        | party | market id | side | volume | price   | resulting trades | type       | tif     |
   444        | aux1  | ETH/DEC19 | sell | 1      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC |
   445        | aux2  | ETH/DEC19 | buy  | 1      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC |
   446  
   447      When the oracles broadcast data signed with "0xCAFECAFE":
   448        | name               | value |
   449        | trading.terminated | true  |
   450      And time is updated to "2020-01-01T01:01:01Z"
   451      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC19"
   452      Then the oracles broadcast data signed with "0xCAFECAFE":
   453        | name             | value |
   454        | prices.ETH.value | 4200  |
   455      Then time is updated to "2020-01-01T01:01:02Z"
   456  
   457      And the parties should have the following account balances:
   458        | party  | asset | market id | margin | general    |
   459        | party1 | ETH   | ETH/DEC19 | 0      | 1191600000 |
   460        | party2 | ETH   | ETH/DEC19 | 0      | 0          |
   461  
   462      When the network moves ahead "2" blocks
   463      And the cumulated balance for all accounts should be worth "10021300000000"
   464      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   465      # 916 were taken from the insurance pool to cover the losses of party 2, the remaining is moved to the global insurance account
   466      And the global insurance pool balance should be "8400000" for the asset "ETH"
   467      And the insurance pool balance should be "100000000" for the market "ETH/DEC21"
   468  
   469    @SLABug
   470    Scenario: Settlement happened when market is being closed - loss socialisation in action - insurance doesn't cover all losses (0002-STTL-009)
   471      Given the initial insurance pool balance is "50000000" for all the markets
   472      Given the parties deposit on asset's general account the following amount:
   473        | party    | asset | amount         |
   474        | party1   | ETH   | 1000000000     |
   475        | party2   | ETH   | 100000000      |
   476        | aux1     | ETH   | 100000000000   |
   477        | aux2     | ETH   | 100000000000   |
   478        | party-lp | ETH   | 10000000000000 |
   479      And the cumulated balance for all accounts should be worth "10201200000000"
   480  
   481      And the parties submit the following liquidity provision:
   482        | id  | party    | market id | commitment amount | fee | lp type    |
   483        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | submission |
   484        | lp1 | party-lp | ETH/DEC19 | 3000000000000     | 0   | amendment  |
   485        | lp2 | party-lp | ETH/DEC21 | 3000000000000     | 0   | submission |
   486        | lp2 | party-lp | ETH/DEC21 | 3000000000000     | 0   | amendment  |
   487      And the parties place the following pegged iceberg orders:
   488        | party    | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   489        | party-lp | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   490        | party-lp | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   491        | party-lp | ETH/DEC21 | 2         | 1                    | buy  | BID              | 50         | 10000  |
   492        | party-lp | ETH/DEC21 | 2         | 1                    | sell | ASK              | 50         | 10000  |
   493  
   494      When the parties place the following orders:
   495        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   496        | aux1  | ETH/DEC19 | buy  | 1      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   497        | aux2  | ETH/DEC19 | sell | 1      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   498        | aux1  | ETH/DEC19 | buy  | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   499        | aux2  | ETH/DEC19 | sell | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   500  
   501      # Other market
   502      And the parties place the following orders:
   503        | party | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   504        | aux1  | ETH/DEC21 | buy  | 1      | 999000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   505        | aux2  | ETH/DEC21 | sell | 1      | 1001000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   506        | aux1  | ETH/DEC21 | buy  | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   507        | aux2  | ETH/DEC21 | sell | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   508  
   509      When the network moves ahead "2" blocks
   510  
   511      Then the mark price should be "1000000" for the market "ETH/DEC19"
   512  
   513      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   514      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
   515  
   516      When the parties place the following orders with ticks:
   517        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   518        | party1 | ETH/DEC19 | sell | 2      | 1000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   519        | party2 | ETH/DEC19 | buy  | 2      | 1000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   520      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
   521      And the cumulated balance for all accounts should be worth "10201200000000"
   522  
   523      When the oracles broadcast data signed with "0xCAFECAFE":
   524        | name               | value |
   525        | trading.terminated | true  |
   526  
   527      And time is updated to "2020-01-01T01:01:01Z"
   528      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC19"
   529      When the oracles broadcast data signed with "0xCAFECAFE":
   530        | name             | value |
   531        | prices.ETH.value | 4200  |
   532      And time is updated to "2020-01-01T01:01:02Z"
   533  
   534  
   535      # 416 missing, but party1 & aux1 get a haircut of 209 each due to flooring
   536      And the parties should have the following account balances:
   537        | party  | asset | market id | margin | general    |
   538        | party1 | ETH   | ETH/DEC19 | 0      | 1170800001 |
   539        | party2 | ETH   | ETH/DEC19 | 0      | 0          |
   540      And the cumulated balance for all accounts should be worth "10201200000000"
   541      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   542      # 500 were taken from the insurance pool to cover the losses of party 2, still not enough to cover losses of (1000-42)*2 for party2
   543      And the global insurance pool balance should be "0" for the asset "ETH"
   544      And the insurance pool balance should be "50000000" for the market "ETH/DEC21"
   545  
   546    Scenario: Settlement happened when market is being closed whilst being suspended (due to protective auction) - loss socialisation in action - insurance doesn't covers all losses (0002-STTL-004, 0002-STTL-009)
   547  
   548      Given the initial insurance pool balance is "50000000" for all the markets
   549      Given the parties deposit on asset's general account the following amount:
   550        | party    | asset | amount         |
   551        | party1   | ETH   | 1000000000     |
   552        | party2   | ETH   | 100000000      |
   553        | aux1     | ETH   | 100000000000   |
   554        | aux2     | ETH   | 100000000000   |
   555        | party-lp | ETH   | 10000000000000 |
   556      And the cumulated balance for all accounts should be worth "10201200000000"
   557  
   558      And the parties submit the following liquidity provision:
   559        | id  | party    | market id | commitment amount | fee | lp type    |
   560        | lp1 | party-lp | ETH/DEC21 | 3000000000000     | 0   | submission |
   561        | lp1 | party-lp | ETH/DEC21 | 3000000000000     | 0   | amendment  |
   562      And the parties place the following pegged iceberg orders:
   563        | party    | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
   564        | party-lp | ETH/DEC21 | 2         | 1                    | buy  | BID              | 50         | 1000   |
   565        | party-lp | ETH/DEC21 | 2         | 1                    | sell | ASK              | 50         | 1000   |
   566  
   567      When the parties place the following orders:
   568        | party | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   569        | aux1  | ETH/DEC21 | buy  | 1      | 89000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   570        | aux2  | ETH/DEC21 | sell | 1      | 111000 | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   571        | aux1  | ETH/DEC21 | buy  | 2      | 100000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   572        | aux2  | ETH/DEC21 | sell | 2      | 100000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   573      Then the opening auction period ends for market "ETH/DEC21"
   574      And the mark price should be "100000" for the market "ETH/DEC21"
   575  
   576      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
   577  
   578      When the parties place the following orders with ticks:
   579        | party  | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   580        | party1 | ETH/DEC21 | sell | 1      | 100000 | 0                | TYPE_LIMIT | TIF_GTC | ref-5     |
   581        | party2 | ETH/DEC21 | buy  | 1      | 100000 | 1                | TYPE_LIMIT | TIF_GTC | ref-6     |
   582  
   583      And the mark price should be "100000" for the market "ETH/DEC21"
   584  
   585      Then the parties should have the following profit and loss:
   586        | party  | volume | unrealised pnl | realised pnl |
   587        | party1 | -1     | 0              | 0            |
   588        | party2 | 1      | 0              | 0            |
   589  
   590      And then the network moves ahead "10" blocks
   591  
   592      When the parties place the following orders with ticks:
   593        | party  | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   594        | party1 | ETH/DEC21 | sell | 1      | 110100 | 0                | TYPE_LIMIT | TIF_GTC | ref-7     |
   595        | party2 | ETH/DEC21 | buy  | 1      | 110100 | 0                | TYPE_LIMIT | TIF_GTC | ref-8     |
   596  
   597      And the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC21"
   598      And the market state should be "STATE_SUSPENDED" for the market "ETH/DEC21"
   599  
   600      And then the network moves ahead "10" blocks
   601  
   602      When the oracles broadcast data signed with "0xCAFECAFE1":
   603        | name               | value |
   604        | trading.terminated | true  |
   605  
   606      And then the network moves ahead "1" blocks
   607  
   608      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC21"
   609  
   610      And then the network moves ahead "400" blocks
   611  
   612      Then the parties should have the following profit and loss:
   613        | party  | volume | unrealised pnl | realised pnl |
   614        | party1 | -1     | 0              | 0            |
   615        | party2 | 1      | 0              | 0            |
   616  
   617      And then the network moves ahead "10" blocks
   618  
   619      When the oracles broadcast data signed with "0xCAFECAFE1":
   620        | name             | value |
   621        | prices.ETH.value | 8000  |
   622  
   623      And then the network moves ahead "10" blocks
   624  
   625      # Check that party positions and overall account balances are the same as before auction start (accounting for a settlement transfer of 200 from party2 to party1)
   626      Then the parties should have the following profit and loss:
   627        | party  | volume | unrealised pnl | realised pnl |
   628        | party1 | -1     | 0              | 20000000     |
   629        | party2 | 1      | 0              | -20000000    |
   630  
   631      And the parties should have the following account balances:
   632        | party  | asset | market id | margin | general    |
   633        | party1 | ETH   | ETH/DEC21 | 0      | 1020500000 |
   634        | party2 | ETH   | ETH/DEC21 | 0      | 77500000   |
   635  
   636      And the cumulated balance for all accounts should be worth "10201200000000"
   637      And the insurance pool balance should be "0" for the market "ETH/DEC21"
   638      And the global insurance pool balance should be "50000000" for the asset "ETH"
   639      And the insurance pool balance should be "50000000" for the market "ETH/DEC19"
   640  
   641  
   642